/* ═══════════════════════════════════════════════════════════════════════
   CRET2 — THEME TOKENS (single source of truth; nothing below invents a hue)
   ───────────────────────────────────────────────────────────────────────
   PALETTE — the only four hues in the product (exact values):
     --brand       #0081C9   rgb(  0, 129, 201)   deep blue      → primary brand:
                   brand mark, links, active/selected states, UI indicators
     --brand-soft  #5BC0F8   rgb( 91, 192, 248)   light blue     → secondary/highlight:
                   secondary buttons, hover fills, selected items, step highlights
     --brand-pale  #86E5FF   rgb(134, 229, 255)   pale cyan      → subtle surface:
                   panel backgrounds, table stripes, info banners, disabled fills
     --accent      #FFC93C   rgb(255, 201, 60)    golden yellow  → accent/attention:
                   badges, warnings, key metrics, CTA highlights, focus accents

   Everything else is a shade/tint of those four hues or a near-black /
   near-white neutral. Contrast anchors (full table in PALETTE-REPORT.md):
     ink on white 16:1 · ink on soft 7.9:1 · ink on pale 11.2:1 · ink on accent 10.4:1
     white on brand-strong 5.05:1 · white on brand 4.21:1 (large text only)
     brand-strong on white 5.05:1 · accent-ink on white 5.38:1 · muted on white 7.5:1
   ═══════════════════════════════════════════════════════════════════════ */
:root {
  /* 1 — palette (exact values, never change) */
  --brand: #0081C9;
  --brand-soft: #5BC0F8;
  --brand-pale: #86E5FF;
  --accent: #FFC93C;

  /* 2 — derived shades & tints (same hues, adjusted for AA) */
  --brand-strong: #0074B4;    /* brand darkened: white 5.05:1 / on white 5.05:1 */
  --brand-deep: #005E93;      /* hover + active fill: white 6.95:1 */
  --brand-soft-deep: #2E9FE4; /* pressed soft fill: ink 5.48:1 */
  --accent-ink: #8A6400;      /* accent as text/border: on white 5.38:1 */
  --accent-wash: #FFF2D2;     /* accent tint surface: ink 14.39:1 */
  --surface-soft: #E4F4FF;    /* pale-cyan tint surface: ink 14.24:1 */

  /* 3 — neutrals (near-black / near-white, blue cast = derived from brand) */
  --ink: #0D2430;
  --muted: #3E5866;
  --bg: #F2FAFE;
  --surface: #FFFFFF;
  --line: #C7DCE8;        /* decorative separators (no 3:1 duty) */
  --line-strong: #3E6E8A; /* control borders: white 5.52:1, pale 3.86:1 */

  /* 4 — semantic roles */
  --text: var(--ink);
  --text-muted: var(--muted);
  --fill-primary: var(--brand-strong);
  --fill-primary-hover: var(--brand-deep);
  --fill-secondary: var(--brand-soft);
  --fill-secondary-hover: var(--brand-soft-deep);
  --fill-info: var(--brand-pale);
  --fill-warning: var(--accent);
  --fill-disabled: var(--brand-pale);
  --focus-accent: var(--accent);
  --focus-edge: var(--ink);
  --focus-ring: 0 0 0 2px var(--focus-accent), 0 0 0 4px var(--focus-edge);

  /* 5 — theme-crossing roles (a value each theme answers differently) */
  --on-bright: var(--ink);         /* text on --brand-soft / --accent fills */
  --link-hover: var(--brand-deep); /* link text on hover */
  --edge-primary: transparent;     /* edge that identifies a primary fill */
  --inverse-surface: var(--ink);   /* toasts: lifted off the page */
  --inverse-text: #FFFFFF;
  --shadow: rgba(13, 36, 48, .2);

  /* 6 — legacy token names, mapped to the new system
        (--line and --muted keep their names; values replaced above) */
  --green: var(--brand-strong); /* legacy name (old green) → primary brand */

  color-scheme: light;
  font-family: Inter, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* ═══════════════════════════════════════════════════════════════════════
   DARK THEME — the default (set as data-theme="dark" in the markup).
   Same token names and the same roles, re-answered for a dark surface.
   Palette: #5003C0 base surface · #AB03A9 primary · #FF467A highlight ·
            #FFD51E accent, plus darker/lighter shades of the same hues.

   Why two derived values exist:
     · #5003C0 (L 0.106) and #AB03A9 (L 0.116) are almost the same
       luminance, so a magenta primary button is invisible against the page
       without an edge  →  --edge-primary #C7B2FF (5.31:1 on the page).
     · #5003C0 is already bright, so panels cannot go lighter and stay
       distinct  →  panels sit darker at #3A0191 and wells darker still at
       #2A0170 (the "more dark" the surfaces need).

   Contrast anchors (full table in PALETTE-REPORT.md):
     ink on page 9.93:1 · ink on panel 13.18:1 · ink on well 15.71:1
     muted on page 5.91:1 · links 5.91:1 · accent as text 6.99:1
     white on primary 6.33:1 · dark text on highlight 5.70:1 · on accent 13.14:1
   ═══════════════════════════════════════════════════════════════════════ */
:root[data-theme="dark"] {
  /* surfaces — the given purple is the page, deeper shades carry the layers */
  --brand: #C9A8FF;      /* brand hue lightened so it reads on dark (4.98:1) */
  --brand-pale: #3A0191; /* panels, banners, stripes, disabled fills */
  --bg: #5003C0;         /* the palette's base surface (exact value) */
  --surface: #2A0170;    /* field/code wells */
  --surface-soft: #3A0191;

  /* text */
  --ink: #FFFFFF;
  --muted: #CFC0F5;
  --text: var(--ink);
  --text-muted: var(--muted);

  /* lines */
  --line: #7B45E0;
  --line-strong: #C7B2FF;

  /* the given hues in their dark-theme roles */
  --brand-soft: #FF467A;      /* highlight fills — carries dark text */
  --brand-soft-deep: #FF6B95; /* pressed/hover highlight */
  --accent: #FFD51E;          /* accent/attention fills */
  --accent-ink: #FFD51E;      /* accent as text/border (6.99:1 on the page) */
  --accent-wash: #4A0F3C;     /* invalid field tint */

  /* derived shades of the primary/highlight hues */
  --brand-strong: #D6BCFF;    /* links + brand text (5.91:1 on the page) */
  --brand-deep: #C704C4;      /* primary hover fill (white 4.95:1) */
  --fill-primary: #AB03A9;
  --fill-primary-hover: var(--brand-deep);
  --fill-secondary: var(--brand-soft);
  --fill-secondary-hover: var(--brand-soft-deep);
  --fill-info: var(--brand-pale);
  --fill-warning: var(--accent);
  --fill-disabled: #2A0170;

  /* theme-crossing roles */
  --on-bright: #2A0413;       /* text on highlight/accent fills */
  --link-hover: #FFFFFF;
  --edge-primary: #C7B2FF;    /* identifies a primary fill on the purple page */
  --inverse-surface: #2A0170;
  --inverse-text: #FFFFFF;
  --shadow: rgba(0, 0, 0, .5);

  /* focus: yellow reads on the page, the white edge covers pink buttons */
  --focus-accent: var(--accent);
  --focus-edge: #FFFFFF;
  --focus-ring: 0 0 0 2px var(--focus-accent), 0 0 0 4px var(--focus-edge);

  --green: var(--brand-strong);

  color-scheme: dark;
}

/* Dark-only control rendering: the native checkbox paints a neutral grey that
   reads muddy on the purple, so dark draws its own box. Light keeps the
   native control exactly as before. */
:root[data-theme="dark"] input[type="checkbox"] {
  appearance: none;
  display: inline-grid;
  place-content: center;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: .25rem;
}
:root[data-theme="dark"] input[type="checkbox"]::before {
  content: "";
  width: .58rem;
  height: .58rem;
  background: #FFFFFF; /* white check on the magenta fill: 6.33:1 */
  transform: scale(0);
  transition: transform .12s ease-out;
  clip-path: polygon(14% 44%, 0 58%, 42% 100%, 100% 18%, 84% 4%, 41% 70%);
}
:root[data-theme="dark"] input[type="checkbox"]:checked {
  background: var(--fill-primary);
  border-color: var(--edge-primary);
}
:root[data-theme="dark"] input[type="checkbox"]:checked::before { transform: scale(1); }
:root[data-theme="dark"] input[type="checkbox"]:active { background: var(--brand-deep); }
:root[data-theme="dark"] input[type="checkbox"]:disabled {
  background: var(--fill-disabled);
  border-color: var(--line);
}

/* ═══════════════════════════════════════════════════════════════════════
   BASE — shared by home.html · settings.html · configure.html · quiz.html
   ═══════════════════════════════════════════════════════════════════════ */
* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 40px 20px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

main {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

h1 { font-size: 1.5rem; margin: 0 0 20px; }
h1 span { color: var(--brand); } /* 24px display text: 4.21:1 ≥ 3:1 large-text AA */

a { color: var(--brand-strong); } /* 5.05:1 on white */
a:hover { color: var(--link-hover); }

::placeholder { color: var(--muted); opacity: 1; } /* 7.52:1 on white */

[hidden] { display: none !important; }

/* ── shared controls ─────────────────────────────────────────────── */
button {
  font: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
}

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}

input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--fill-primary); /* checked fill takes the primary, white check */
  border-radius: .25rem;
  cursor: pointer;
}
input[type="checkbox"]:active { accent-color: var(--brand-deep); }

/* ── shared interactive states (default · hover · focus · active ·
      disabled · invalid · loading · empty — every page inherits these) ── */
button:hover:not(:disabled) { background: var(--fill-secondary); }
button:active:not(:disabled) { transform: translateY(1px); }

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid transparent; /* shows in forced-colors mode */
  outline-offset: 2px;
  box-shadow: var(--focus-ring); /* yellow accent ring edged in near-black */
}

input:hover:not(:disabled):not(:focus),
select:hover:not(:disabled):not(:focus),
textarea:hover:not(:disabled):not(:focus) { border-color: var(--brand); }

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  background: var(--fill-disabled);
  border-color: var(--line-strong);
  color: var(--muted); /* 5.25:1 on the pale fill */
}

button.loading { cursor: progress; }

/* error / invalid: accent-tinted field + near-black border + accent banner */
.is-error,
[aria-invalid="true"] {
  background: var(--accent-wash) !important;
  border-color: var(--accent-ink) !important;
  border-width: 2px;
}

/* empty states keep their space so the layout never jumps */
#status, #error, #link, #message { min-height: 1.4em; }

/* ── loading spinner ────────────────────────────────────────────── */
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  animation: spin .8s linear infinite;
  display: none;
}
button.loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── theme switch (every page, top of the content column) ─────────
   A switch, not a label swap: the text stays "Chế độ tối" and
   aria-checked / .is-on report whether dark is on. Dark is the default. */
.theme-bar {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 .7rem;
}
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .45rem .9rem;
  font-size: .78rem;
  font-weight: 600;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}
.theme-toggle::before { /* state dot */
  content: "";
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.theme-toggle:hover:not(:disabled) {
  background: var(--surface-soft);
  border-color: var(--brand);
  color: var(--ink);
}
.theme-toggle.is-on {
  background: var(--brand-pale);
  color: var(--ink);
}
.theme-toggle.is-on::before { background: var(--accent); }

/* ═══════════════════════════════════════════════════════════════════════
   PAGE — home.html
   ═══════════════════════════════════════════════════════════════════════ */
.home-actions { align-items: center; gap: .5rem; }
.settings-open {
  padding: .45rem .9rem;
  font-size: .78rem;
  border: 1px solid var(--line-strong);
  color: var(--text);
}
.settings-open:hover:not(:disabled) { background: var(--surface-soft); }
.settings-dialog {
  width: min(32rem, calc(100% - 2rem));
  min-height: 12rem;
  max-height: calc(100% - 2rem);
  padding: 1.25rem;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 40px var(--shadow);
}
.settings-dialog::backdrop { background: rgba(0, 0, 0, .65); }
.settings-dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.settings-dialog-header h2 { margin: 0; font-size: 1.1rem; }
.settings-close { width: 2.5rem; height: 2.5rem; flex: none; font-size: 1.5rem; line-height: 1; }
.settings-close:hover:not(:disabled) { background: var(--surface-soft); }
.settings-body { margin-top: 1rem; }
.settings-body label { margin: 0 0 .5rem; }
#questionCount { width: 100%; padding: .7rem .8rem; }
.settings-hint { color: var(--muted); font-size: .85rem; line-height: 1.4; margin: .5rem 0; }
.settings-hint:empty { display: none; }
.settings-reset {
  margin-top: .75rem;
  padding: .6rem 1rem;
  color: var(--text);
  border: 1px solid var(--line-strong);
}
.settings-reset:hover:not(:disabled) { background: var(--surface-soft); }

#input {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  padding: 14px;
  font-size: 1rem;
  border-radius: 12px;
}
#reference {
  width: 100%;
  margin-top: 12px;
  padding: 12px 14px;
  font-size: 0.95rem;
  border-radius: 12px;
}

#learn {
  margin-top: 16px;
  padding: 12px 40px;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--fill-primary);
  border: 1px solid var(--edge-primary);
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
#learn:hover:not(:disabled) { background: var(--fill-primary-hover); }
#learn:active:not(:disabled) { background: var(--brand-deep); }
/* loading keeps the brand fill so the spinner (white) stays visible */
#learn.loading,
#learn.loading:disabled {
  background: var(--fill-primary);
  color: #fff;
}
#learn:disabled:not(.loading) {
  background: var(--fill-disabled);
  border: 1px solid var(--line-strong);
  color: var(--muted);
}

#addFiles.secondary {
  margin-top: 12px;
  padding: 8px 18px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--on-bright);
  background: var(--fill-secondary);
  border: 1px solid var(--line-strong);
}
#addFiles.secondary:hover:not(:disabled) {
  background: var(--fill-secondary-hover);
  border-color: var(--brand);
}
#addFiles.secondary:active:not(:disabled) { background: var(--brand-soft-deep); }

ul#attachments {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* long file names ellipsize, never overflow */
  gap: 8px;
}
ul#attachments[hidden] { display: none; } /* empty state collapses cleanly */

li.attachment {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
}
li.attachment .tag {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--accent); /* badges → accent */
  color: var(--on-bright);   /* 10.4:1 light / 13.1:1 dark */
  border: 1px solid var(--accent-ink);
}
li.attachment .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
li.attachment .size { flex: none; color: var(--muted); font-size: 0.8rem; }
li.attachment .remove {
  flex: none;
  margin: 0;
  padding: 0 8px;
  font-size: 1.1rem;
  line-height: 1.5;
  border: 0;
  border-radius: 999px;
  color: var(--accent-ink); /* 5.38:1 on white */
  background: transparent;
}
li.attachment .remove:hover:not(:disabled) {
  background: var(--accent);
  color: var(--on-bright); /* 10.4:1 light / 13.1:1 dark */
}

#status {
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.95rem;
}
#status:not(:empty) { /* loading / progress → info banner */
  background: var(--fill-info);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 10px;
  border-left: 4px solid var(--brand);
}

#error {
  margin-top: 6px;
  color: var(--ink);
  font-size: 0.95rem;
}
#error:not(:empty) { /* error state → attention banner */
  background: var(--fill-warning);
  color: var(--on-bright);
  padding: 10px 14px;
  border-radius: 10px;
  border-left: 4px solid var(--accent-ink);
}

#link { margin-top: 18px; }
#link:not(:empty) { /* success state → CTA panel */
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 12px 16px;
}
#link a {
  color: var(--brand-strong); /* 5.05:1 on white */
  font-size: 1.15rem;
  font-weight: 600;
  word-break: break-all;
}
#link a:hover { color: var(--link-hover); }

/* ═══════════════════════════════════════════════════════════════════════
   PAGE — settings.html
   ═══════════════════════════════════════════════════════════════════════ */
label { display: block; font-weight: 600; margin: 18px 0 6px; }

.hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.85rem;
  margin-left: 8px;
}

#endpoint, #api_key, #model, #thinking_effort,
#frontend, #backend, #image_endpoint, #image_api_key, #image_model {
  width: 100%;
  padding: 11px 12px;
  font-size: 1rem;
  border-radius: 10px;
}

#save {
  margin-top: 22px;
  padding: 11px 36px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--fill-primary);
  border: 1px solid var(--edge-primary);
}
#save:hover:not(:disabled) { background: var(--fill-primary-hover); }
#save:active:not(:disabled) { background: var(--brand-deep); }
#save:disabled {
  background: var(--fill-disabled);
  border: 1px solid var(--line-strong);
  color: var(--muted);
}

#message { margin-top: 16px; font-size: 0.95rem; }
#message.ok:not(:empty) {
  background: var(--fill-info);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 10px;
  border-left: 4px solid var(--brand-strong);
}
#message.fail:not(:empty) {
  background: var(--fill-warning);
  color: var(--on-bright);
  padding: 10px 14px;
  border-radius: 10px;
  border-left: 4px solid var(--accent-ink);
}
/* kept for any inline use */
.ok { color: var(--brand-strong); }
.fail { color: var(--accent-ink); }

/* ═══════════════════════════════════════════════════════════════════════
   PAGE — configure.html
   ═══════════════════════════════════════════════════════════════════════ */
#frontend, #backend { width: 100%; }
main:has(#frontend) { max-width: 820px; } /* configure keeps its 820px column */

#material_template, #quiz_template, #interactive_template {
  width: 100%;
  padding: 12px;
  font-size: 0.92rem;
  font-family: ui-monospace, Consolas, monospace;
  border-radius: 10px;
  resize: vertical;
  line-height: 1.5;
}

.step {
  margin-top: 26px;
  padding: 18px;
  background: var(--brand-pale); /* panels → subtle surface */
  border: 1px solid var(--line-strong);
  border-radius: 14px;
}
.step h2 { font-size: 1.05rem; margin: 0 0 4px; }
.step .note {
  color: var(--muted); /* 5.25:1 on the pale panel */
  font-size: 0.85rem;
  margin-bottom: 10px;
  line-height: 1.5;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 12px;
  font-weight: 600;
}
.toggle label { margin: 0; cursor: pointer; }

/* step/progress highlight: the numbered step heading carries the accent */
.step h2 {
  display: flex;
  align-items: center;
  gap: 10px;
}
.step h2::before {
  content: "";
  width: .65rem;
  height: .65rem;
  border-radius: 50%;
  background: var(--brand-soft);
  border: 1px solid var(--line-strong);
  flex: none;
}

/* ═══════════════════════════════════════════════════════════════════════
   PAGE — quiz.html
   ═══════════════════════════════════════════════════════════════════════ */
body > div, body > p, body > textarea {
  width: 100%;
  max-width: 820px;
  margin-left: auto;
  margin-right: auto;
}
body > div {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
body > p {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 18px auto 6px;
}
body > textarea {
  display: block; /* block so the auto margins centre the column */
  padding: 12px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.5;
  border-radius: 10px;
  resize: vertical;
}

#pasteButton, #copyButton {
  padding: 10px 22px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--on-bright);
  background: var(--fill-secondary);
  border: 1px solid var(--line-strong);
}
#pasteButton:hover:not(:disabled), #copyButton:hover:not(:disabled) {
  background: var(--fill-secondary-hover);
  border-color: var(--brand);
}
#pasteButton:active:not(:disabled), #copyButton:active:not(:disabled) {
  background: var(--brand-soft-deep);
}

#parseButton {
  padding: 10px 28px;
  font-size: 0.95rem;
  color: #fff;
  background: var(--fill-primary);
  border: 1px solid var(--edge-primary);
}
#parseButton:hover:not(:disabled) { background: var(--fill-primary-hover); }
#parseButton:active:not(:disabled) { background: var(--brand-deep); }
#parseButton:disabled {
  background: var(--fill-disabled);
  border: 1px solid var(--line-strong);
  color: var(--muted);
}

#randomizeQuestions { margin: 0; }
body > div label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-weight: 500;
  cursor: pointer;
}

/* error state hook (set by the inline script when parsing fails) */
#outputText.is-error {
  background: var(--accent-wash);
  border-color: var(--accent-ink);
  border-width: 2px;
  color: var(--ink); /* 14.39:1 on the accent wash */
}

/* ═══════════════════════════════════════════════════════════════════════
   LEGACY WORKSPACE SURFACE (static/app.js console: .app-header/#prompt/
   #output …). Kept and re-skinned; scoped under .studio so its element
   rules can never bleed into the four pages above.
   ═══════════════════════════════════════════════════════════════════════ */
.studio button {
  min-height: 2.65rem;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: .4rem;
  padding: .5rem .8rem;
  font-weight: 400;
}
.studio button:hover:not(:disabled) { background: var(--brand-soft); }
.studio button:disabled { opacity: 1; background: var(--fill-disabled); color: var(--muted); }
.studio input, .studio textarea {
  border: 1px solid var(--line);
  border-radius: .4rem;
  background: var(--surface);
}
.studio textarea { resize: vertical; width: 100%; padding: 1rem; line-height: 1.6; }
.studio input { padding: .7rem; width: 100%; min-width: 0; }

.studio .app-header {
  height: 5.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  border-bottom: 1px solid var(--line);
  gap: 1rem;
}
.studio .brand {
  display: flex;
  align-items: center;
  gap: .45rem;
  text-decoration: none;
  color: inherit;
  font-size: 1.3rem;
  white-space: nowrap;
}
.studio .brand strong { font-weight: 450; color: var(--muted); }
.studio .brand-icon {
  background: var(--brand);
  color: #fff;
  border-radius: .5rem;
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  margin-right: .4rem;
  font-weight: 750;
}
.studio .edition { font-size: .56rem; letter-spacing: .15em; margin-left: 1rem; color: var(--muted); }
.studio .header-actions { display: flex; gap: 1.2rem; align-items: center; }
.studio .route { font-size: .75rem; color: var(--muted); }

.studio main {
  display: grid;
  grid-template-columns: clamp(18rem, 25vw, 27rem) minmax(0, 1fr);
  height: calc(100dvh - 5.4rem);
  padding: 1.7rem 2rem;
  gap: 2rem;
  max-width: none;
}
.studio aside {
  display: flex;
  flex-direction: column;
  overflow: auto;
  min-height: 0;
  padding-right: .3rem;
}
.studio .section-heading, .studio .label-row, .studio .field-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.studio .eyebrow { font-size: .64rem; font-weight: 650; letter-spacing: .17em; color: var(--muted); }
.studio .section-heading button { border: 0; font-size: .68rem; padding: .3rem; min-height: 2.2rem; }
.studio h1 {
  font-size: clamp(1.8rem, 2.1vw, 3.1rem);
  line-height: 1.12;
  letter-spacing: -.055em;
  font-weight: 500;
  margin: 1.5rem 0 .8rem;
}
.studio .intro { color: var(--muted); font-size: .82rem; line-height: 1.5; margin-bottom: 1.7rem; }
.studio .label-row { font-size: .8rem; font-weight: 600; margin-bottom: .6rem; }
.studio .label-row button { font-size: .72rem; min-height: 2.2rem; }
.studio #prompt { height: 9rem; min-height: 5rem; max-height: 35vh; font-size: .82rem; }
.studio .field-meta { font-size: .62rem; color: var(--muted); margin: .5rem 0 1.3rem; }
.studio .model-label { font-size: .75rem; display: block; margin-bottom: .5rem; }
.studio #model { font-size: .8rem; }

.studio .primary {
  background: var(--fill-primary);
  color: #fff;
  width: 100%;
  margin-top: .8rem;
  display: flex;
  justify-content: space-between;
  padding: .8rem 1rem;
}
.studio .primary:hover:not(:disabled) { background: var(--fill-primary-hover); }
.studio .small-note { font-size: .73rem; line-height: 1.5; color: var(--muted); }
.studio .follow-section { border-top: 1px solid var(--line); margin-top: 1.4rem; padding-top: 1.4rem; }
.studio .badge {
  font-size: .55rem;
  letter-spacing: .08em;
  background: var(--accent);
  border: 1px solid var(--accent-ink);
  border-radius: .3rem;
  padding: .35rem .5rem;
  color: var(--on-bright);
}
.studio #followup { height: 5.8rem; font-size: .8rem; }
.studio #follow {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-top: .6rem;
  font-size: .8rem;
}
.studio .aside-footer {
  margin-top: auto;
  padding-top: 1.5rem;
  font-size: .66rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.studio .status-dot { width: .4rem; height: .4rem; background: var(--brand-strong); border-radius: 50%; }

.studio .workspace {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line-strong);
  border-radius: .8rem;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.studio .output-heading {
  padding: 1.4rem 1.6rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.studio h2 { font-size: 1.4rem; letter-spacing: -.04em; font-weight: 500; margin: .35rem 0 0; }
.studio .status-wrap { display: flex; align-items: center; gap: .6rem; }
.studio #status { font-size: .72rem; color: var(--muted); background: none; border: 0; padding: 0; }

.studio .toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: .7rem 1.3rem;
  border-block: 1px solid var(--line);
  background: var(--surface-soft);
}
.studio .tabs, .studio .output-actions { display: flex; gap: .35rem; align-items: center; }
.studio .toolbar button { font-size: .75rem; white-space: nowrap; }
.studio .tabs button { border-color: transparent; }
.studio .tabs .selected {
  background: var(--brand-soft); /* selected item → highlight */
  color: var(--on-bright);
  border-color: var(--line-strong);
}
.studio .accent {
  color: var(--on-bright);
  background: var(--accent);
  border-color: var(--accent-ink);
}
/* presses into the brand so the label stays white in both themes */
.studio .accent:hover:not(:disabled) { background: var(--brand-deep); color: #fff; }
.studio .separator { height: 1.2rem; width: 1px; background: var(--line); margin: 0 .3rem; }

.studio .search-row {
  display: flex;
  gap: .6rem;
  align-items: center;
  padding: .5rem 1.4rem;
  border-bottom: 1px solid var(--line);
}
.studio .search-row input { border: 0; background: transparent; padding: .4rem; font-size: .78rem; }
.studio .search-row > span:first-child { font-size: 1.5rem; color: var(--muted); }
.studio #matches { font-size: .66rem; white-space: nowrap; color: var(--accent-ink); } /* key metric */
.studio .search-row button { border: 0; min-width: 2.4rem; padding: .3rem; }

.studio #output-scroll {
  overflow: auto;
  flex: 1;
  min-height: 0;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: clamp(1rem, 2.5vw, 3.5rem);
}
.studio #empty {
  height: 100%;
  min-height: 16rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.studio .empty-mark {
  font-size: 2.7rem;
  color: var(--ink);
  background: var(--brand-pale);
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 1rem;
  display: grid;
  place-items: center;
}
.studio h3 { font-size: 1.5rem; font-weight: 450; letter-spacing: -.04em; margin: 1.5rem 0 .5rem; }
.studio #empty p { color: var(--muted); line-height: 1.7; font-size: .84rem; }
.studio .empty-hint { display: flex; gap: 1.3rem; font-size: .65rem; color: var(--muted); margin-top: 1.4rem; }

.studio #output {
  font-size: 1rem;
  line-height: 1.8;
  overflow-wrap: anywhere;
  max-width: 110ch;
  margin: auto;
}
.studio #output h1, .studio #output h2, .studio #output h3 {
  line-height: 1.3;
  letter-spacing: -.02em;
  margin: 1.3em 0 .6em;
  font-weight: 600;
}
.studio #output pre {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: .5rem;
  padding: 1.1rem;
  overflow: auto;
  font-size: .85rem;
  line-height: 1.65;
  white-space: pre-wrap;
  tab-size: 4;
}
.studio #output code { font-family: Consolas, monospace; }
.studio #output :not(pre) > code {
  background: var(--brand-pale);
  padding: .15rem .3rem;
  border-radius: .2rem;
}
.studio #output blockquote {
  border-left: 3px solid var(--brand);
  margin-left: 0;
  padding-left: 1rem;
  color: var(--muted);
}
.studio #output table { display: block; overflow: auto; border-collapse: collapse; }
.studio #output td, .studio #output th {
  padding: .5rem .8rem;
  border: 1px solid var(--line);
}
.studio #output tbody tr:nth-child(even) { background: var(--brand-pale); } /* table stripes */
.studio #output a { color: var(--brand-strong); }
.studio #output.raw { white-space: pre-wrap; font-family: Consolas, monospace; font-size: .9rem; }

.studio mark { background: var(--accent); color: var(--on-bright); } /* 10.4:1 light / 13.1:1 dark */
.studio mark.current {
  background: var(--brand-soft);
  color: var(--on-bright);
  outline: 2px solid var(--ink);
}

.studio .output-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .7rem;
  border-top: 1px solid var(--line);
  padding: .7rem 1.4rem;
  font-size: .65rem;
  color: var(--muted);
}
.studio .output-footer label { display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
.studio .output-footer input { width: auto; accent-color: var(--fill-primary); }

.studio #error:not(:empty) {
  background: var(--fill-warning);
  color: var(--on-bright);
  padding: .9rem 1.5rem;
  font-size: .8rem;
  border: 0;
  border-bottom: 1px solid var(--accent-ink);
}

.studio #toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: .8rem 1.4rem;
  background: var(--inverse-surface);
  color: var(--inverse-text);
  box-shadow: 0 4px 20px var(--shadow);
  border-left: 4px solid var(--accent);
  border-radius: .5rem;
  font-size: .85rem;
  z-index: 10;
}

/* ── studio layout breakpoints (unchanged) ───────────────────────── */
@media (min-width: 2200px) {
  .studio main { gap: 2.5rem; padding: 2rem 3rem; }
  .studio #prompt { height: 10rem; }
}
@media (max-width: 1000px) {
  .studio main { padding: 1rem; gap: 1rem; grid-template-columns: 17rem minmax(0, 1fr); }
  .studio .edition { display: none; }
  .studio .toolbar { flex-wrap: wrap; gap: .4rem; padding: .6rem; }
  .studio .output-actions { margin-left: auto; }
  .studio .output-footer { flex-wrap: wrap; }
  .studio .route { display: none; }
}
@media (max-width: 700px) {
  .studio .app-header { height: 4.5rem; padding: 0 1rem; }
  .studio .brand { font-size: 1.1rem; }
  .studio main {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: calc(100dvh - 4.5rem);
    padding: .8rem;
    gap: .8rem;
  }
  .studio aside { overflow: visible; padding: 0; }
  .studio .section-heading { padding: 0 .3rem; }
  .studio h1, .studio .intro, .studio .aside-footer { display: none; }
  .studio #prompt-body { padding: .6rem .3rem; }
  .studio #prompt { height: 6rem; }
  .studio .field-meta { margin-bottom: .7rem; }
  .studio .follow-section { margin: .5rem .3rem 0; padding-top: .7rem; }
  .studio .follow-section .small-note { display: none; }
  .studio #followup { height: 4rem; }
  .studio #follow { margin-top: .3rem; }
  .studio .workspace { height: 78dvh; min-height: 30rem; flex: none; }
  .studio .output-heading { padding: 1rem; }
  .studio #status { font-size: .65rem; }
  .studio .toolbar button { padding: .5rem .6rem; min-height: 2.8rem; }
  .studio .search-row { padding: .3rem .7rem; }
  .studio .output-footer { padding: .6rem .8rem; }
  .studio #txt-status { display: none; }
  .studio .empty-hint { gap: .8rem; }
  .studio #empty h3 { font-size: 1.35rem; }
  .studio .collapsed #prompt-body { display: none; }
  .studio .collapsed .follow-section { margin-bottom: .4rem; }
}
.studio .output-actions { flex-wrap: wrap; }

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
