:root {
  color-scheme: light;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-soft: #f8f9fc;
  --text: #172033;
  --muted: #667085;
  --border: #dce2eb;
  --border-strong: #b8c2d1;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #c0362c;
  --danger-dark: #a42b23;
  --danger-soft: #fff3f2;
  --focus: #f59e0b;
  --shadow: 0 12px 32px rgba(35, 48, 75, 0.08);
  --header-bg: #0f2655;
  --header-text: #ffffff;
  --header-border: rgba(255, 255, 255, 0.14);
  --header-eyebrow: #8db2ff;
  --header-muted: #cbd9f6;
  --control-bg: #ffffff;
  --control-placeholder: #778197;
  --search-icon: #667085;
  --button-hover: #f2f5f9;
  --button-hover-border: #8996aa;
  --button-quiet-text: #344054;
  --panel-shadow: 0 4px 18px rgba(35, 48, 75, 0.05);
  --panel-hover-border: #b9c7df;
  --selected-border: #91afe8;
  --row-hover: rgba(37, 99, 235, 0.055);
  --arrow: #7a8aa5;
  --action-text: #475467;
  --action-hover-border: #cfe0ff;
  --danger-hover-border: #f2c2bd;
  --detail-text: #263248;
  --detail-bg: #f8fafc;
  --empty-bg: rgba(255, 255, 255, 0.72);
  --dialog-bg: #ffffff;
  --dialog-shadow: 0 30px 90px rgba(5, 15, 35, 0.32);
  --backdrop: rgba(11, 18, 32, 0.58);
  --icon-muted: #667085;
  --notice-error-text: #8b251f;
  --notice-error-border: #efbbb6;
  --warning-text: #7a4c09;
  --warning-bg: #fff8e7;
  --warning-border: #f0d591;
  --toast-bg: #19243a;
  --toast-error-bg: #8f241e;
  --radius: 14px;
  font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, -apple-system, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080d15;
  --surface: #0d1521;
  --surface-soft: #111c2b;
  --text: #edf3fb;
  --muted: #9aa9bd;
  --border: #26354a;
  --border-strong: #3d506b;
  --accent: #3da6f5;
  --accent-dark: #1688df;
  --accent-soft: #14283d;
  --danger: #f07180;
  --danger-dark: #df4f61;
  --danger-soft: #351c27;
  --focus: #f6c453;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
  --header-bg: #0c1624;
  --header-text: #f5f8fc;
  --header-border: #27384f;
  --header-eyebrow: #73bfff;
  --header-muted: #a9bad0;
  --control-bg: #111d2c;
  --control-placeholder: #8798ae;
  --search-icon: #91a3b9;
  --button-hover: #172438;
  --button-hover-border: #516680;
  --button-quiet-text: #dce6f3;
  --panel-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
  --panel-hover-border: #3d526d;
  --selected-border: #3d9deb;
  --row-hover: rgba(61, 166, 245, 0.1);
  --arrow: #8799b0;
  --action-text: #b6c4d6;
  --action-hover-border: #315474;
  --danger-hover-border: #714050;
  --detail-text: #dce6f3;
  --detail-bg: #070c13;
  --empty-bg: rgba(17, 28, 43, 0.72);
  --dialog-bg: #0e1724;
  --dialog-shadow: 0 30px 90px rgba(0, 0, 0, 0.58);
  --backdrop: rgba(2, 6, 12, 0.76);
  --icon-muted: #9aa9bd;
  --notice-error-text: #ffc0c8;
  --notice-error-border: #75404d;
  --warning-text: #f6d48c;
  --warning-bg: #302715;
  --warning-border: #6d5828;
  --toast-bg: #17263a;
  --toast-error-bg: #74313e;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

button,
label[for],
input[type="file"] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-header {
  color: var(--header-text);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
}

.header-inner,
.main-content {
  width: min(1200px, calc(100% - 40px));
  margin: 0 auto;
}

.header-inner {
  min-height: 174px;
  padding: 34px 0 30px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 32px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.65rem, 4vw, 2.25rem);
  line-height: 1.25;
  letter-spacing: 0.02em;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--header-eyebrow);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.tagline {
  margin: 7px 0 0;
  color: var(--header-muted);
  font-size: 0.94rem;
}

.header-controls {
  min-width: min(100%, 650px);
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-control {
  flex: 0 0 auto;
  display: grid;
  gap: 3px;
  color: var(--header-muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.theme-control select {
  min-width: 116px;
  min-height: 46px;
  padding: 8px 34px 8px 11px;
  color: var(--text);
  background: var(--control-bg);
  border: 1px solid var(--header-border);
  border-radius: 10px;
  cursor: pointer;
}

.theme-control select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.search-box {
  position: relative;
  flex: 1;
}

.search-box input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px 10px 42px;
  color: var(--text);
  background: var(--control-bg);
  border: 1px solid var(--header-border);
  border-radius: 10px;
}

.search-box input::placeholder {
  color: var(--control-placeholder);
}

.search-icon {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 16px;
  width: 14px;
  height: 14px;
  border: 2px solid var(--search-icon);
  border-radius: 50%;
  transform: translateY(-58%);
  pointer-events: none;
}

.search-icon::after {
  content: "";
  position: absolute;
  width: 7px;
  height: 2px;
  right: -6px;
  bottom: -3px;
  background: var(--search-icon);
  transform: rotate(45deg);
  border-radius: 1px;
}

.button {
  min-height: 44px;
  padding: 9px 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 700;
  line-height: 1.25;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.button:hover {
  background: var(--button-hover);
  border-color: var(--button-hover-border);
}

.button:active {
  transform: translateY(1px);
}

.button-primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.button-primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.button-quiet {
  color: var(--button-quiet-text);
  background: var(--surface);
}

.button-danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.button-danger:hover {
  background: var(--danger-dark);
  border-color: var(--danger-dark);
}

.header-controls .button-primary {
  min-height: 46px;
  white-space: nowrap;
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.18);
}

.main-content {
  padding: 30px 0 50px;
}

.notice {
  margin-bottom: 18px;
  padding: 12px 15px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.notice-error {
  color: var(--notice-error-text);
  background: var(--danger-soft);
  border-color: var(--notice-error-border);
}

.utility-bar {
  margin-bottom: 16px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.utility-bar h2 {
  margin: 0;
  font-size: 1.15rem;
}

.result-summary {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.prompt-workspace {
  display: grid;
  grid-template-columns: minmax(300px, 34%) minmax(0, 1fr);
  align-items: start;
  gap: 16px;
}

.prompt-sidebar,
.prompt-detail {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--panel-shadow);
}

.prompt-sidebar {
  padding: 16px;
}

.pane-heading {
  padding: 2px 4px 14px;
  border-bottom: 1px solid var(--border);
}

.pane-heading h2 {
  margin: 0;
  font-size: 1.05rem;
}

.pane-label {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.11em;
}

.prompt-list {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.prompt-list-item {
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.prompt-list-item:hover {
  border-color: var(--panel-hover-border);
}

.prompt-list-item.is-selected {
  background: var(--accent-soft);
  border-color: var(--selected-border);
  box-shadow: inset 3px 0 0 var(--accent);
}

.prompt-select {
  width: 100%;
  min-height: 54px;
  padding: 12px 12px 9px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
  text-align: left;
  font-weight: 750;
  line-height: 1.45;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.prompt-select:hover {
  background: var(--row-hover);
}

.prompt-title {
  min-width: 0;
  overflow-wrap: anywhere;
}

.prompt-arrow {
  flex: 0 0 auto;
  color: var(--arrow);
  font-size: 1.5rem;
  font-weight: 400;
  line-height: 1;
}

.prompt-list-item.is-selected .prompt-arrow {
  color: var(--accent);
}

.prompt-actions {
  padding: 0 8px 8px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.text-action {
  min-height: 44px;
  min-width: 0;
  padding: 7px 4px;
  color: var(--action-text);
  font-size: 0.85rem;
  font-weight: 700;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.text-action:hover {
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-color: var(--action-hover-border);
}

.text-action-danger:hover {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger-hover-border);
}

.prompt-detail {
  position: sticky;
  top: 16px;
  min-height: 560px;
  padding: 22px;
}

.detail-header {
  padding-bottom: 17px;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--border);
}

.detail-heading {
  min-width: 0;
}

.detail-heading h2 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: clamp(1.2rem, 2vw, 1.55rem);
  line-height: 1.45;
}

.detail-meta {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.detail-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.detail-body {
  width: 100%;
  max-height: min(66vh, 720px);
  margin: 18px 0 0;
  padding: 20px;
  overflow: auto;
  color: var(--detail-text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  background: var(--detail-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: "Cascadia Mono", Consolas, "Yu Gothic UI", monospace;
  font-size: 0.9rem;
  line-height: 1.75;
  tab-size: 2;
}

.detail-empty {
  min-height: 510px;
  padding: 42px 28px;
  display: grid;
  place-content: center;
  text-align: center;
}

.detail-empty h2 {
  margin: 2px 0 6px;
  font-size: 1.15rem;
}

.detail-empty p:last-child {
  margin: 0;
  color: var(--muted);
}

.empty-state {
  padding: clamp(44px, 8vw, 76px) 22px;
  text-align: center;
  background: var(--empty-bg);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.empty-state h2 {
  margin: 13px 0 5px;
  font-size: 1.15rem;
}

.empty-state p {
  margin: 0 0 18px;
  color: var(--muted);
}

.empty-state-compact {
  margin-top: 12px;
  padding: 36px 16px;
}

.empty-state-compact h2 {
  font-size: 1rem;
}

.empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 1.8rem;
  font-weight: 300;
  background: var(--accent-soft);
  border-radius: 50%;
}

.empty-icon-search {
  position: relative;
}

.empty-icon-search::before {
  content: "";
  width: 16px;
  height: 16px;
  border: 3px solid currentColor;
  border-radius: 50%;
}

.empty-icon-search::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 3px;
  right: 9px;
  bottom: 10px;
  background: currentColor;
  transform: rotate(45deg);
  border-radius: 2px;
}

.privacy-note {
  margin: 18px 4px 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.dialog {
  width: min(720px, calc(100% - 28px));
  max-height: calc(100vh - 32px);
  padding: 0;
  color: var(--text);
  background: var(--dialog-bg);
  border: 0;
  border-radius: 16px;
  box-shadow: var(--dialog-shadow);
}

.dialog::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(2px);
}

.dialog-small {
  width: min(500px, calc(100% - 28px));
}

.dialog form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 32px);
}

.dialog-header {
  padding: 22px 24px 16px;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.eyebrow-danger {
  color: var(--danger);
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--icon-muted);
  font-size: 1.5rem;
  line-height: 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.icon-button:hover {
  color: var(--text);
  background: var(--surface-soft);
  border-color: var(--border);
}

.dialog-body {
  padding: 21px 24px;
  overflow-y: auto;
}

.dialog-body > p:first-child {
  margin-top: 0;
}

.dialog-description {
  margin-bottom: 0;
  color: var(--muted);
}

.field + .field {
  margin-top: 18px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 750;
}

.field label span {
  color: var(--danger);
}

.field input,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  color: var(--text);
  background: var(--control-bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
}

.field textarea {
  min-height: 260px;
  resize: vertical;
  font-family: "Cascadia Mono", Consolas, "Yu Gothic UI", monospace;
  font-size: 0.9rem;
  line-height: 1.65;
  tab-size: 2;
}

.field input[aria-invalid="true"],
.field textarea[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px var(--danger);
}

.field-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.field-meta p,
.field > p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.field-error {
  min-height: 1.25em;
  color: var(--danger) !important;
  font-weight: 700;
}

.secret-warning {
  margin-top: 18px !important;
  padding: 10px 12px;
  color: var(--warning-text) !important;
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: 8px;
}

.dialog-actions {
  padding: 15px 24px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  border-top: 1px solid var(--border);
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 24px;
  max-width: calc(100% - 28px);
  padding: 11px 17px;
  color: #fff;
  text-align: center;
  background: var(--toast-bg);
  border-radius: 9px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
  transform: translateX(-50%);
}

.toast[data-kind="error"] {
  background: var(--toast-error-bg);
}

@media (max-width: 820px) {
  .header-inner {
    min-height: 0;
    padding: 26px 0;
    align-items: stretch;
    flex-direction: column;
    gap: 22px;
  }

  .header-controls {
    min-width: 0;
  }

  .prompt-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .prompt-detail {
    position: static;
    min-height: 0;
    scroll-margin-top: 12px;
  }

  .detail-empty {
    min-height: 260px;
  }
}

@media (max-width: 640px) {
  .header-inner,
  .main-content {
    width: min(100% - 24px, 1200px);
  }

  .header-controls {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .theme-control {
    grid-column: 1 / -1;
  }

  .theme-control select {
    width: 100%;
  }

  .main-content {
    padding-top: 22px;
  }

  .utility-bar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .backup-actions .button {
    flex: 1;
  }

  .prompt-sidebar,
  .prompt-detail {
    padding: 14px;
  }

  .detail-header {
    align-items: stretch;
    flex-direction: column;
  }

  .detail-actions {
    justify-content: flex-start;
  }

  .detail-actions .button {
    flex: 1;
  }

  .detail-body {
    max-height: none;
    padding: 15px;
    font-size: 0.84rem;
  }

  .dialog-header,
  .dialog-body {
    padding-inline: 18px;
  }

  .dialog-actions {
    padding-inline: 18px;
  }
}

@media (max-width: 420px) {
  .header-controls {
    grid-template-columns: 1fr;
  }

  .header-controls .button-primary {
    width: 100%;
  }

  .prompt-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .text-action {
    padding-inline: 2px;
    font-size: 0.82rem;
  }

  .dialog-actions {
    flex-direction: column-reverse;
  }

  .dialog-actions .button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
