/* ==========================================================================
   The Wetware Manual
   Light theme = brightfield (an H&E-stained slide: hematoxylin ink, eosin pink)
   Dark theme  = fluorescence (DAPI blue, GFP green, mCherry red on black)
   ========================================================================== */

:root {
  --bg: #f5f1f4;
  --bg-elev: #fffdfe;
  --bg-sunk: #ece5ea;
  --stage-bg: #fbf8fa;
  --ink: #1e1730;
  --ink-2: #51476a;
  --ink-3: #857b97;
  --line: #e1d7df;
  --line-2: #cdc0cb;
  --accent: #b52f62;          /* eosin */
  --accent-ink: #ffffff;
  --accent-soft: rgba(181, 47, 98, 0.12);
  --hl: rgba(181, 47, 98, 0.13);
  --shadow: 0 1px 2px rgba(40, 20, 50, 0.06), 0 6px 24px rgba(40, 20, 50, 0.07);

  /* stains / fluorophores (one hue family per role, both themes) */
  --c-blue: #3747b5;    /* hematoxylin / DAPI */
  --c-green: #1b8456;   /* GFP */
  --c-red: #c2392a;     /* mCherry / true red (distinct from the eosin accent) */
  --c-amber: #a8660f;   /* YFP / DAB */
  --c-violet: #7438aa;  /* Cy5 */
  --c-cyan: #0b7887;    /* CFP */
  --tint: 0.14;         /* fill alpha for organelle bodies */
  --glow: none;
  --glow-soft: none;
  --cap-bg: rgba(30, 23, 48, 0.86);
  --cap-ink: #fbf7ff;

  --font-display: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-text: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Atkinson Hyperlegible Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --header-h: 58px;
  --player-h: 74px;
  --radius: 12px;
  --gutter: 20px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #05070b;
    --bg-elev: #0c1119;
    --bg-sunk: #080b11;
    --stage-bg: #020409;
    --ink: #e5eaf3;
    --ink-2: #a2adc2;
    --ink-3: #6b768d;
    --line: #19202d;
    --line-2: #273041;
    --accent: #ff5c8a;
    --accent-ink: #1a0610;
    --accent-soft: rgba(255, 92, 138, 0.14);
    --hl: rgba(255, 92, 138, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
    --c-blue: #6f8cff;
    --c-green: #3fe08e;
    --c-red: #ff6a55;
    --c-amber: #ffc24d;
    --c-violet: #c084ff;
    --c-cyan: #4cd9e8;
    --tint: 0.11;
    --glow: url(#glow);
    --glow-soft: url(#glow-soft);
    --cap-bg: rgba(2, 4, 9, 0.84);
    --cap-ink: #eef2fa;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #05070b;
  --bg-elev: #0c1119;
  --bg-sunk: #080b11;
  --stage-bg: #020409;
  --ink: #e5eaf3;
  --ink-2: #a2adc2;
  --ink-3: #6b768d;
  --line: #19202d;
  --line-2: #273041;
  --accent: #ff5c8a;
  --accent-ink: #1a0610;
  --accent-soft: rgba(255, 92, 138, 0.14);
  --hl: rgba(255, 92, 138, 0.16);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  --c-blue: #6f8cff;
  --c-green: #3fe08e;
  --c-red: #ff6a55;
  --c-amber: #ffc24d;
  --c-violet: #c084ff;
  --c-cyan: #4cd9e8;
  --tint: 0.11;
  --glow: url(#glow);
  --glow-soft: url(#glow-soft);
  --cap-bg: rgba(2, 4, 9, 0.84);
  --cap-ink: #eef2fa;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, select, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.fill-ink2 { fill: var(--ink-2); }

.app { min-height: 100%; }

/* ---------- header ---------- */
.ww-top {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 30;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding-inline: var(--gutter);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none; flex: none;
}
.brand-mark { width: 30px; height: 30px; }
.bm-cell { fill: color-mix(in srgb, var(--c-red) 16%, transparent); stroke: var(--c-red); stroke-width: 1.4; }
.bm-nuc { fill: var(--c-blue); opacity: .9; filter: var(--glow-soft); }
.bm-dot { fill: var(--c-green); }
.brand-name { font-family: var(--font-display); font-size: 21px; letter-spacing: -0.01em; white-space: nowrap; font-variation-settings: "opsz" 36; }
.brand-name em { font-style: italic; }

.rail {
  flex: 1 1 auto; min-width: 0;
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  padding-block: 6px;
  mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
}
.rail::-webkit-scrollbar { display: none; }
.rail-btn {
  flex: none; display: flex; align-items: baseline; gap: 7px;
  border: 1px solid transparent; background: none; border-radius: 999px;
  padding: 5px 11px 6px; color: var(--ink-2);
  font-family: var(--font-mono); font-size: 12.5px; white-space: nowrap;
}
.rail-btn .n { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.rail-btn:hover { color: var(--ink); background: var(--bg-sunk); }
.rail-btn[aria-current="true"] { color: var(--ink); border-color: var(--line-2); background: var(--bg-elev); }
.rail-btn[aria-current="true"] .n { color: var(--accent); }
.rail-btn .done { width: 6px; height: 6px; border-radius: 50%; background: var(--c-green); align-self: center; opacity: 0; }
.rail-btn.visited .done { opacity: .8; }

.rail-select-wrap { display: none; flex: 1; min-width: 0; }
.rail-select {
  width: 100%; height: 36px; border-radius: 999px; border: 1px solid var(--line-2);
  background: var(--bg-elev); padding-inline: 12px; font-family: var(--font-mono); font-size: 13px;
}

.ask-open {
  flex: none; display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 14px 0 11px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--bg-elev); color: var(--ink);
  font-size: 13.5px; font-weight: 600;
}
.ask-open:hover { border-color: var(--accent); }
.ask-open svg { width: 19px; height: 19px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ask-open svg .qd { fill: var(--accent); stroke: none; }

/* ---------- main layout ---------- */
.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 27vw, 400px);
  gap: 22px;
  padding-inline: var(--gutter);
  padding-block: 18px calc(var(--player-h) + 22px + env(safe-area-inset-bottom, 0px));
  max-width: 1680px;
  margin-inline: auto;
}
.theater { min-width: 0; display: flex; flex-direction: column; gap: 14px; }

.stage-wrap {
  --chrome: calc(var(--header-h) + var(--player-h) + 190px);
  position: relative;
  width: min(100%, calc((100dvh - var(--chrome)) * 1.6));
  min-width: min(100%, 520px);
  aspect-ratio: 16 / 10;
  margin-inline: auto;
  border-radius: 16px;
  background: var(--stage-bg);
  border: 1px solid var(--line);
  overflow: hidden;
  box-shadow: var(--shadow);
  isolation: isolate;
  container-type: size; /* the title card and captions size their text to the stage (cqw/cqh) */
}
.stage { position: absolute; inset: 0; container-type: size; }
.stage > svg, .stage > canvas, .panel > svg, .panel > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.panel { position: absolute; inset: 0; opacity: 0; visibility: hidden; transition: opacity .6s ease, visibility 0s linear .6s, transform .8s cubic-bezier(.2,.7,.2,1); transform: scale(.985); }
.panel.on { opacity: 1; visibility: visible; transform: none; transition: opacity .6s ease, visibility 0s, transform .8s cubic-bezier(.2,.7,.2,1); }
.stage-wrap:fullscreen { width: 100vw; height: 100vh; aspect-ratio: auto; border-radius: 0; border: 0; }
.stage-wrap:fullscreen .stage { inset: 0; }

.stage-expand {
  position: absolute; right: 10px; top: 10px; z-index: 8;
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-elev) 80%, transparent); color: var(--ink-2);
  display: grid; place-items: center; opacity: 0; transition: opacity .2s;
}
.stage-wrap:hover .stage-expand, .stage-expand:focus-visible { opacity: 1; }
.stage-expand svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* title card */
.titlecard {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: clamp(14px, 5%, 44px);
  background: linear-gradient(180deg, color-mix(in srgb, var(--stage-bg) 55%, transparent) 0%, color-mix(in srgb, var(--stage-bg) 82%, transparent) 58%, var(--stage-bg) 100%);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .9s ease, visibility 0s linear .9s;
}
.titlecard.on { opacity: 1; visibility: visible; transition: opacity .5s ease, visibility 0s; }
.titlecard.hero { justify-content: center; align-items: flex-start; background: linear-gradient(90deg, color-mix(in srgb, var(--stage-bg) 94%, transparent) 0%, color-mix(in srgb, var(--stage-bg) 86%, transparent) 38%, color-mix(in srgb, var(--stage-bg) 30%, transparent) 64%, transparent 82%); pointer-events: auto; }
.tc-line { display: flex; align-items: baseline; gap: 14px; font-family: var(--font-mono); color: var(--ink-2); font-size: clamp(11px, 1.8cqw, 14px); letter-spacing: .02em; }
.tc-num { font-family: var(--font-display); font-size: clamp(28px, min(7cqw, 11cqh), 64px); line-height: .9; color: var(--accent); font-variant-numeric: lining-nums; font-variation-settings: "opsz" 72; }
.tc-title { font-family: var(--font-display); font-style: italic; font-weight: 400; font-size: clamp(24px, min(7.6cqw, 12cqh), 76px); line-height: .98; letter-spacing: -0.02em; margin: 6px 0 8px; text-wrap: balance; font-variation-settings: "opsz" 72; }
.tc-sub { margin: 0; color: var(--ink-2); font-size: clamp(12.5px, min(2.1cqw, 3.9cqh), 18px); max-width: 44ch; }
.hero .tc-title { font-size: clamp(26px, min(9.6cqw, 14cqh), 92px); margin-top: 0; }
.hero .tc-sub { max-width: 40ch; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: clamp(10px, 3.2cqh, 26px); pointer-events: auto; }
.hero-meta { margin-top: 12px; font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-3); }
/* short stages (phones, short laptop windows): a more compact opening card */
@container (max-height: 400px) {
  .hero .btn.big { height: 40px; padding: 0 18px; font-size: 14.5px; }
  .hero-meta { display: none; }
}
@container (max-height: 260px) {
  .hero .tc-sub { max-width: none; }
  .hero-actions { gap: 8px; }
  .hero .btn.big { height: 36px; padding: 0 14px; font-size: 13.5px; }
}
@container (max-height: 200px) {
  .hero .tc-line { display: none; }
}

/* captions */
.captions {
  position: absolute; left: 50%; bottom: 14px; z-index: 6; transform: translateX(-50%);
  max-width: min(92%, 760px); width: max-content;
  padding: 8px 14px 9px; border-radius: 10px;
  background: var(--cap-bg); color: var(--cap-ink);
  font-size: clamp(13px, 2cqw, 17.5px); line-height: 1.4; text-align: center; text-wrap: balance;
  opacity: 0; transition: opacity .25s;
  pointer-events: none;
}
.cc-on .captions.has-text { opacity: 1; }

/* continue + up next */
.continue-pill {
  position: absolute; right: 14px; bottom: 14px; z-index: 7;
  display: flex; align-items: center; gap: 6px;
  height: 38px; padding: 0 12px 0 16px; border-radius: 999px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 14px;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent);
  animation: pulse 2.4s ease-in-out infinite;
}
.continue-pill svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.cc-on .continue-pill { bottom: auto; top: 14px; right: 54px; }
@keyframes pulse { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-2px); } }

.upnext {
  position: absolute; inset: 0; z-index: 9;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--stage-bg) 82%, transparent);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.upnext-card { text-align: center; padding: 20px; max-width: 520px; }
.upnext-k { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-3); letter-spacing: .06em; text-transform: uppercase; }
.upnext-title { font-family: var(--font-display); font-style: italic; font-size: clamp(22px, min(5.6cqw, 9cqh), 48px); line-height: 1.05; margin: 8px 0 6px; }
.upnext-alias { font-family: var(--font-mono); color: var(--accent); font-size: 14px; }
.upnext-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.upnext-ring { width: 18px; height: 18px; transform: rotate(-90deg); }
.upnext-ring circle { fill: none; stroke: currentColor; stroke-width: 3; }

/* ---------- deck ---------- */
.deck {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  gap: 14px;
  align-items: start;
  width: min(100%, calc((100dvh - var(--header-h) - var(--player-h) - 190px) * 1.6));
  min-width: min(100%, 520px);
  margin-inline: auto;
}
.deck.no-controls { grid-template-columns: 1fr; }
.notes { display: grid; gap: 8px; }
.notes:empty { display: none; }
.ww-note { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; align-items: baseline; font-size: 14px; line-height: 1.45; color: var(--ink-2); }
.note-k { font-family: var(--font-mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--c-cyan); white-space: nowrap; }
.ww-note.warn .note-k { color: var(--c-amber); }
.ww-note p { margin: 0; color: var(--ink); }
.ww-note.warn p { color: var(--ink-2); }
.controls { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; justify-content: flex-end; min-height: 0; }
.controls:empty { display: none; }
.panel-deck { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; justify-content: flex-end; width: 100%; }
.controls .ctl-label { font-family: var(--font-mono); font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); }
.controls .ctl-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; width: 100%; }
.controls .ctl-readout { font-family: var(--font-mono); font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.controls .ctl-readout b { color: var(--ink); font-weight: 600; }

/* shared buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--bg-elev); color: var(--ink);
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
  transition: border-color .15s, background .15s, color .15s;
}
.btn:hover { border-color: var(--ink-3); }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.big { height: 46px; padding: 0 22px; font-size: 15.5px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: default; }
.btn .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.seg-btns { display: inline-flex; border: 1px solid var(--line-2); border-radius: 999px; overflow: hidden; }
.seg-btns .btn { border: 0; border-radius: 0; height: 32px; }
.seg-btns .btn + .btn { border-left: 1px solid var(--line-2); }
.range { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.range input[type="range"] { accent-color: var(--accent); width: 150px; }

/* ---------- transcript ---------- */
.script {
  position: sticky;
  top: calc(var(--header-h) + 18px);
  align-self: start;
  max-height: calc(100dvh - var(--header-h) - var(--player-h) - 40px);
  overflow-y: auto;
  scrollbar-width: thin;
  padding-right: 4px;
}
.sc-head { padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.sc-line { display: flex; gap: 10px; align-items: baseline; font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-3); }
.sc-line .n { color: var(--accent); }
.sc-title { font-family: var(--font-display); font-style: italic; font-weight: 400; font-size: 32px; line-height: 1.05; margin: 6px 0 4px; letter-spacing: -0.01em; font-variation-settings: "opsz" 60; }
.sc-sub { margin: 0; color: var(--ink-2); font-size: 14px; }
.beats { list-style: none; margin: 0; padding: 0; }
.ww-beat { padding: 10px 8px 12px; margin-inline: -8px; border-radius: 10px; cursor: pointer; }
.ww-beat:hover { background: var(--bg-sunk); }
.beat-k { display: flex; justify-content: space-between; align-items: center; font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-3); margin-bottom: 3px; font-variant-numeric: tabular-nums; }
.beat-k .try { color: var(--c-green); letter-spacing: .04em; text-transform: uppercase; font-size: 10.5px; border: 1px solid color-mix(in srgb, var(--c-green) 40%, transparent); border-radius: 999px; padding: 0 7px; }
.ww-beat p { margin: 0; font-size: 15.5px; line-height: 1.6; color: var(--ink-2); }
.ww-beat .s { border-radius: 4px; transition: background .25s, color .25s; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.ww-beat.current .beat-k { color: var(--accent); }
.ww-beat.current p { color: var(--ink); }
.ww-beat.current .s.now { background: var(--hl); color: var(--ink); }
.ww-beat.past p { color: var(--ink-2); }
.sc-foot { display: flex; justify-content: space-between; gap: 10px; padding-block: 14px 6px; border-top: 1px solid var(--line); margin-top: 8px; }
.sc-foot .btn { max-width: 48%; overflow: hidden; text-overflow: ellipsis; }

/* ---------- player ---------- */
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 18px;
  min-height: var(--player-h);
  padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.pl-buttons { display: flex; align-items: center; gap: 4px; }
.pl-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink);
}
.pl-btn:hover { background: var(--bg-sunk); }
.pl-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pl-btn svg .fillpath { fill: currentColor; stroke: none; }
.pl-btn.play { width: 48px; height: 48px; background: var(--ink); color: var(--bg); }
.pl-btn.play:hover { background: var(--accent); color: var(--accent-ink); }
.pl-btn.play svg { width: 24px; height: 24px; }
.pl-btn.play .i-pause { display: none; }
.playing .pl-btn.play .i-pause { display: block; }
.playing .pl-btn.play .i-play { display: none; }
.pl-btn.play.hold { background: var(--accent); color: var(--accent-ink); }
.pl-btn.small { width: 34px; height: 34px; }
.pl-btn.small svg { width: 20px; height: 20px; }
.pl-btn .i-mute { display: none; }
.muted .pl-btn .i-mute { display: block; }
.muted .pl-btn .i-vol { display: none; }

.pl-mid { min-width: 0; display: grid; gap: 7px; }
.pl-label { display: flex; gap: 10px; align-items: baseline; min-width: 0; font-size: 13px; }
.pl-ch { font-family: var(--font-mono); color: var(--accent); white-space: nowrap; flex: none; }
.pl-beat { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.segs { display: flex; gap: 3px; height: 16px; align-items: center; }
.ww-seg { position: relative; height: 6px; flex-basis: 0; border: 0; padding: 0; border-radius: 3px; background: var(--line-2); overflow: hidden; transition: height .15s; }
.ww-seg::after { content: ""; position: absolute; inset: -6px 0; }
.ww-seg:hover { height: 10px; }
.ww-seg i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--ink); border-radius: inherit; }
.ww-seg.done i { width: 100%; background: var(--ink-3); }
.ww-seg.cur i { background: var(--accent); }
.ww-seg.try::before { content: ""; position: absolute; right: 2px; top: 50%; width: 4px; height: 4px; margin-top: -2px; border-radius: 50%; background: var(--c-green); z-index: 1; }
.pl-right { display: flex; align-items: center; gap: 6px; }
.pl-time { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 86px; text-align: right; margin-right: 4px; }
.pl-chip { height: 30px; min-width: 42px; padding: 0 9px; border-radius: 8px; border: 1px solid var(--line-2); background: transparent; font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-2); }
.pl-chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.pl-chip:hover { border-color: var(--ink-3); }

/* ---------- ask panel ---------- */
.ask-panel {
  position: fixed; z-index: 60;
  right: 16px; top: calc(var(--header-h) + 12px); bottom: calc(var(--player-h) + 12px);
  width: min(440px, calc(100vw - 32px));
  display: flex; flex-direction: column;
  background: var(--bg-elev); border: 1px solid var(--line-2); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(10, 5, 20, 0.28);
  overflow: hidden;
}
.ask-head { display: flex; justify-content: space-between; gap: 12px; padding: 16px 16px 12px; border-bottom: 1px solid var(--line); }
.ask-head h2 { margin: 0; font-family: var(--font-display); font-style: italic; font-weight: 400; font-size: 24px; line-height: 1.1; }
.ask-ctx { margin: 4px 0 0; font-family: var(--font-mono); font-size: 12px; color: var(--ink-3); }
.icon-btn { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--ink-2); }
.icon-btn:hover { background: var(--bg-sunk); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.ask-body { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 14px; }
.ask-suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.ask-suggest button { border: 1px solid var(--line-2); background: var(--bg); border-radius: 12px; padding: 7px 11px; font-size: 13px; line-height: 1.35; text-align: left; color: var(--ink); }
.ask-suggest button:hover { border-color: var(--accent); }
.ask-log { display: flex; flex-direction: column; gap: 14px; }
.msg { font-size: 14.5px; line-height: 1.55; }
.msg.q { align-self: flex-end; max-width: 88%; background: var(--bg-sunk); border-radius: 14px 14px 4px 14px; padding: 8px 12px; }
.msg.a { color: var(--ink); }
.msg.a p { margin: 0 0 8px; }
.msg.a ul { margin: 0 0 8px; padding-left: 20px; }
.msg.a li { margin: 2px 0; }
.msg.a .thinking { color: var(--ink-3); font-style: italic; }
.msg-tools { display: flex; gap: 8px; margin-top: 2px; }
.msg-tools button { border: 0; background: none; padding: 0; font-size: 12.5px; color: var(--ink-3); text-decoration: underline; text-underline-offset: 2px; }
.msg-tools button:hover { color: var(--accent); }
.ask-form { border-top: 1px solid var(--line); padding: 12px 16px 14px; display: grid; gap: 8px; }
.ask-form textarea { width: 100%; resize: none; border: 1px solid var(--line-2); border-radius: 12px; background: var(--bg); padding: 9px 12px; font-size: 14.5px; line-height: 1.45; }
.ask-form textarea:focus { outline: none; border-color: var(--accent); }
.ask-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.ask-note { flex: 1; font-size: 12px; color: var(--ink-3); }
.ask-panel.unavailable .ask-form { display: none; }

/* ---------- about dialog ---------- */
.about-open svg { stroke: var(--ink-2); }
.about-open svg .qd { fill: var(--ink-2); }
.about {
  width: min(640px, calc(100vw - 32px)); max-height: min(86vh, 920px);
  padding: 0; border: 1px solid var(--line-2); border-radius: 16px;
  background: var(--bg-elev); color: var(--ink);
  box-shadow: 0 20px 60px rgba(10, 5, 20, 0.28);
}
.about[open] { display: flex; flex-direction: column; }
.about::backdrop { background: rgba(10, 5, 20, 0.45); }
.about-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.about-head h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 26px; line-height: 1.1; }
.about-body { overflow-y: auto; padding: 4px 18px 20px; font-size: 14.5px; line-height: 1.55; }
.about-body h3 { margin: 20px 0 6px; font-family: var(--font-mono); font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.about-body p { margin: 0 0 10px; }
.about-body a { color: var(--accent); text-underline-offset: 2px; }
.about-note { color: var(--ink-2); }
.about-sources { margin: 0; padding-left: 18px; font-size: 13.5px; }
.about-sources li { margin: 4px 0; }
.about-foot { margin-top: 20px !important; font-family: var(--font-mono); font-size: 12.5px; }
.noscript { position: fixed; inset: auto 16px 16px; margin: 0; padding: 12px 16px; border-radius: 12px; background: var(--bg-elev); border: 1px solid var(--line-2); }

/* ---------- shared stage typography (SVG + HTML overlays) ---------- */
.stage text, .panel text { font-family: var(--font-text); fill: var(--ink); }
.t-label { font-size: 17px; fill: var(--ink); }
.t-small { font-size: 14px; fill: var(--ink-2); }
.t-tiny { font-size: 12px; fill: var(--ink-3); }
.t-mono { font-family: var(--font-mono) !important; }
.t-display { font-family: var(--font-display) !important; font-style: italic; }
.t-big { font-size: 34px; }
.t-muted { fill: var(--ink-2); }
.t-accent { fill: var(--accent); }
.ln { stroke: var(--ink-2); stroke-width: 1.4; fill: none; }
.ln-faint { stroke: var(--line-2); stroke-width: 1; fill: none; }
.glow { filter: var(--glow); }
.glow-soft { filter: var(--glow-soft); }

.halo { paint-order: stroke; stroke: var(--stage-bg); stroke-width: 4px; stroke-linejoin: round; }
.stage-tag { position:absolute; left: 2.2%; top: 3%; z-index: 2; pointer-events:none; opacity:0; transform: translateY(-4px); transition: opacity .5s, transform .5s; max-width: 60%; }
.stage-tag.on { opacity:1; transform:none; }
.stage-tag .k { font-family: var(--font-mono); font-size: clamp(9px,1.25cqw,12.5px); letter-spacing:.1em; text-transform: uppercase; color: var(--ink-2); display:block; }
.stage-tag .v { font-family: var(--font-display); font-style: italic; font-size: clamp(16px,3.1cqw,32px); line-height:1.05; color: var(--ink); text-shadow: 0 0 8px var(--stage-bg), 0 0 2px var(--stage-bg); }
.stage-inset { position:absolute; z-index: 3; width: 34%; opacity:0; transform: translateY(8px) scale(.98); transition: opacity .5s, transform .5s; pointer-events:none; padding: 8px 10px 6px; }
.stage-inset.on { opacity: 1; transform: none; }
.stage-inset .k { font-family: var(--font-mono); font-size: clamp(8.5px,1.1cqw,11px); letter-spacing:.08em; text-transform:uppercase; color: var(--ink-3); }
.stage-inset .cap { font-size: clamp(10px,1.35cqw,13.5px); color: var(--ink-2); margin-top: 2px; line-height:1.35; }
.stage-inset svg { display:block; width:100%; height:auto; }
.ov { position: absolute; pointer-events: none; }
.ov-card {
  position: absolute; pointer-events: auto;
  background: color-mix(in srgb, var(--bg-elev) 90%, transparent);
  border: 1px solid var(--line-2); border-radius: 12px;
  padding: 10px 13px; box-shadow: var(--shadow);
  font-size: 13.5px; line-height: 1.45; color: var(--ink);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.ov-card h4 { margin: 0 0 3px; font-family: var(--font-display); font-style: italic; font-weight: 500; font-size: 19px; }
.ov-card .k { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .main { grid-template-columns: minmax(0, 1fr); }
  .script { position: static; max-height: none; overflow: visible; padding-right: 0; }
  .stage-wrap, .deck { width: 100%; min-width: 0; }
  .stage-wrap { --chrome: 0px; }
}
@media (max-width: 860px) {
  .rail { display: none; }
  .rail-select-wrap { display: block; }
  .ask-open span { display: none; }
  .ask-open { padding: 0 9px; }
  .deck { grid-template-columns: 1fr; }
  .controls { justify-content: flex-start; }
  .controls .ctl-row, .panel-deck { justify-content: flex-start; }
  .pl-right .pl-time { display: none; }
}
@media (max-width: 620px) {
  :root { --gutter: 16px; --player-h: 64px; }
  .brand-name { display: none; }
  .ww-top { gap: 10px; }
  .main { gap: 14px; padding-top: 12px; }
  .stage-wrap { border-radius: 12px; }
  .player { gap: 10px; }
  .pl-right #muteBtn { display: none; }
  .pl-chip { min-width: 36px; padding: 0 6px; }
  .pl-label .pl-beat { display: none; }
  .pl-btn { width: 34px; height: 34px; }
  .pl-btn.play { width: 44px; height: 44px; }
  .ask-panel { left: 8px; right: 8px; width: auto; top: auto; bottom: calc(var(--player-h) + 8px); height: min(76vh, 640px); }
  .captions { bottom: 8px; font-size: 13px; padding: 6px 10px; }
  .sc-title { font-size: 28px; }
}

/* local screenshot mode */
.shot .ww-top, .shot .script, .shot .player { display: none !important; }
.shot .main { display: block; padding: 0; max-width: none; }
.shot .theater { gap: 8px; }
.shot .stage-wrap { width: 100vw; min-width: 0; border-radius: 0; border: 0; box-shadow: none; }
.shot .deck { width: 100vw; min-width: 0; padding: 0 16px 10px; }

/* Phone-sized stage: overlay cards shrink so they don't bury the diagram underneath. */
@container (max-width: 520px) {
  .panel .ov-card { font-size: 8.5px !important; line-height: 1.3 !important; padding: 4px 6px !important; border-radius: 7px !important; }
  .panel .ov-card * { font-size: 1em !important; line-height: 1.3 !important; }
  .panel .ov-card [class*="big"], .panel .ov-card h4 { font-size: 1.3em !important; }
  .stage-tag .k { font-size: 7.5px !important; }
  .stage-tag .v { font-size: 13px !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .2s !important; }
}

/* Landscape phones with a notch: keep content clear of the side safe areas (viewport-fit=cover). */
.ww-top, .main, .player {
  padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
}
