/* Layout: a lab bench — one large specimen on the left, its controls on the right, the rest of the cast in a tray below. */
:root {
  --bg: #e8ebf1;
  --surface: #f7f8fb;
  --fg: #171a21;
  --muted: #586071;
  --line: #cfd4de;
  --control-line: #7c8496;
  --accent: #3451d1;
  --accent-fg: #ffffff;
  --code-key: #3451d1;
  --code-string: #1d7a4f;
  --code-number: #b4541a;
  --font-display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1116; --surface: #181b23; --fg: #e6e9f0; --muted: #959cad; --line: #2b303c; --control-line: #646b7e; --accent: #8fa3ff; --accent-fg: #0f1116;
    --code-key: #8fa3ff; --code-string: #7fd6a4; --code-number: #f0a56b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1116; --surface: #181b23; --fg: #e6e9f0; --muted: #959cad; --line: #2b303c; --control-line: #646b7e; --accent: #8fa3ff; --accent-fg: #0f1116;
  --code-key: #8fa3ff; --code-string: #7fd6a4; --code-number: #f0a56b;
  color-scheme: dark;
}

/* Anchors and focused controls stop below whatever is pinned at the top: the jump links, or the viewer on phones. */
html { background: var(--bg); padding-block: env(safe-area-inset-top, 0px) env(safe-area-inset-bottom, 0px); scroll-padding-top: 64px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 28px 48px;
}
.wrap { max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }

header { display: flex; flex-direction: column; gap: 6px; }
h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2rem, 5vw, 3rem);
  letter-spacing: -0.03em;
  margin: 0;
  text-wrap: balance;
}
header p { margin: 0; color: var(--muted); font-size: 16px; line-height: 1.4; }

/* The viewer (stage or cast) stays put while the controls scroll beside it, or under it on phones. */
.studio {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  --viewer-top: 16px;
}
/* The dock is the sticky part; its page-colored padding hides what scrolls past the viewer's rounded corners. */
.viewer-dock { position: sticky; top: var(--viewer-top); z-index: 5; }
.viewer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
}
.view-body { position: relative; aspect-ratio: 4 / 3; max-height: calc(100dvh - 2 * var(--viewer-top) - 2px); }
.stage, .cast { position: absolute; inset: 0; }
.stage canvas { display: block; width: 100%; height: 100%; cursor: pointer; touch-action: manipulation; }
/* Inset, so the viewer's rounded clip doesn't cut the ring off. */
.stage canvas:focus-visible { outline-offset: -6px; border-radius: 16px; }
.stage-meta {
  position: absolute; left: 18px; right: 18px; bottom: 14px;
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  pointer-events: none;
}
.stage-name { font-family: var(--font-display); font-weight: 700; font-size: 1.4rem; letter-spacing: -0.02em; }
.icon-btn {
  position: absolute; top: 12px; display: grid; place-items: center; width: 40px; height: 40px; padding: 0;
  background: var(--surface); color: var(--fg); border: 1px solid var(--control-line); border-radius: 10px; cursor: pointer;
}
.icon-btn:hover { border-color: var(--fg); }
.icon-btn svg { grid-area: 1 / 1; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stage-back { left: 12px; }
.stage-copy { right: 12px; }
.stage-copy .icon-done, .stage-copy .icon-failed, .stage-copy[data-state] .icon-copy { display: none; }
.stage-copy[data-state="done"] .icon-done, .stage-copy[data-state="failed"] .icon-failed { display: block; }
.stage-copy[data-state="done"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.stage-mood { font-family: var(--font-mono); font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.cast {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 8px; padding: 12px;
}
.member {
  position: relative; min-width: 0; min-height: 0; padding: 0;
  background: var(--bg); border: 1px solid transparent; border-radius: 12px;
  cursor: pointer; overflow: hidden;
}
.member:hover { border-color: var(--line); }
.member[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.member canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.member strong {
  position: absolute; left: 8px; bottom: 6px;
  font-family: var(--font-display); font-size: 13px; font-weight: 600; pointer-events: none;
}

/* On phones: one column, the viewer pinned to the top and shorter, the cast as a tight grid of faces. */
@media (max-width: 860px) {
  .studio { grid-template-columns: minmax(0, 1fr); --viewer-top: env(safe-area-inset-top, 0px); }
  .viewer-dock { background: var(--bg); padding-bottom: 8px; }
  .viewer { box-shadow: 0 8px 18px -12px rgba(20, 24, 40, .35); }
  .view-body { aspect-ratio: 16 / 10; max-height: 40dvh; }
  .cast { gap: 4px; padding: 6px; }
  .member strong { display: none; }
}

.panel { display: flex; flex-direction: column; gap: 24px; min-width: 0; }

.jump {
  position: sticky; top: 0; z-index: 4;
  display: flex; gap: 6px; flex-wrap: wrap;
  padding-block: 8px; margin-block: -8px; background: var(--bg);
}
.jump a {
  padding: 6px 12px; border: 1px solid var(--control-line); border-radius: 999px; background: var(--surface);
  color: var(--fg); text-decoration: none; font-family: var(--font-display); font-weight: 600; font-size: 14px;
}
.jump a:hover { border-color: var(--muted); }
@media (max-width: 860px) {
  .jump { position: static; }
  /* Below the pinned viewer: the 16:10 body (at most 40% of the screen), its border and the dock padding. */
  html { scroll-padding-top: calc(env(safe-area-inset-top, 0px) + min(40dvh, (100vw - 32px) * 10 / 16) + 30px); }
}
.section { display: flex; flex-direction: column; gap: 16px; }
.section + .section { border-top: 1px solid var(--line); padding-top: 22px; }
.section h2 {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 0;
  font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; letter-spacing: -0.02em;
}
.section .hint { margin: -10px 0 0; font-size: 13px; color: var(--muted); }
.group { display: flex; flex-direction: column; gap: 10px; }
.label {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted);
}
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

button, input[type="text"] { font: inherit; color: inherit; }
/* Every group of choice buttons shares one grid, so all the sections line up. */
.choices { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 480px) { .choices { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.chip {
  background: var(--surface);
  border: 1px solid var(--control-line);
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
  text-align: left;
  transition: background-color .15s, border-color .15s, color .15s;
}
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }

.swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
  transition: box-shadow .15s, transform .15s;
}
.swatch:hover { transform: scale(1.08); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--fg); }
.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

.name-row input {
  flex: 1 1 140px; min-width: 0;
  background: var(--surface); border: 1px solid var(--control-line); border-radius: 10px;
  padding: 9px 12px; font-family: var(--font-mono); font-size: 14px;
}
.btn {
  background: var(--fg); color: var(--bg); border: 0; border-radius: 10px;
  padding: 10px 14px; cursor: pointer; font-weight: 700;
}

.load-config { display: flex; flex-direction: column; gap: 10px; }
.load-config summary { cursor: pointer; padding-block: 6px; }
.load-config[open] summary { margin-bottom: 4px; }
.load-config textarea {
  box-sizing: border-box; width: 100%; min-width: 0; resize: vertical;
  background: var(--surface); color: var(--fg); border: 1px solid var(--control-line); border-radius: 10px;
  padding: 9px 12px; font-family: var(--font-mono); font-size: 12px;
}
.config-editor { min-width: 0; }
.config-status { font-size: 13px; color: var(--muted); }
.trait-sliders { display: grid; gap: 10px; }
.trait { display: grid; grid-template-columns: 92px minmax(0, 1fr); align-items: center; gap: 2px 12px; }
.trait label { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.trait input[type="range"] { width: 100%; min-width: 0; accent-color: var(--accent); }
.trait output { grid-column: 2; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
dl.traits { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
dl.traits dt { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
dl.traits dd { margin: 0; font-variant-numeric: tabular-nums; }

.notes { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; border-top: 1px solid var(--line); padding-top: 22px; }
.notes h3 { margin: 0 0 6px; font-family: var(--font-display); font-size: 1rem; }
.notes p { margin: 0; color: var(--muted); line-height: 1.55; max-width: 60ch; }
