*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 var(--type-body)/1.55 var(--f-sans); font-optical-sizing: auto; }
a { color: var(--model); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
h1, h2, h3 { font-family: var(--f-serif); font-weight: 560; letter-spacing: -.012em; margin: 0; }
p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: var(--space-4); top: -100px; z-index: 50; background: var(--text); color: var(--surface); padding: var(--space-2) var(--space-4); border-radius: var(--radius-1); }
.skip:focus { top: var(--space-2); }

/* Bottom bar: brand, chapters, steps of the current chapter, notes. The stage keeps the whole screen above it. */
.topbar {
  position: fixed; inset: auto 0 0 0; height: var(--bar-h); z-index: 30;
  display: flex; align-items: center; gap: var(--space-4); padding: 0 clamp(var(--space-3), 2.5vw, var(--space-6));
  /* Opaque instead of a live blur: a backdrop blur over moving scenes repaints every frame on weaker GPUs. */
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.brand { font: 600 1rem/1 var(--f-serif); white-space: nowrap; color: var(--text); text-decoration: none; }
.brand span { color: var(--you); }
.chapnav { display: flex; align-items: center; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.chapnav button {
  min-width: 32px; height: 32px; border: 0; background: none; border-radius: var(--radius-pill); cursor: pointer;
  font: 600 .78rem/1 var(--f-sans); color: var(--text-faint); font-variant-numeric: tabular-nums;
  transition: background var(--dur-1), color var(--dur-1);
}
.chapnav button:not(.is-draft) { color: var(--text); }
.chapnav button:hover { background: var(--surface-sunk); color: var(--text); }
.chapnav button[aria-current="step"] { background: var(--text); color: var(--surface); }
.steps { display: flex; align-items: center; gap: 6px; margin-left: auto; }
/* Notes sits next to the step dots, centred in the bar, clear of the bottom-right corner. */
.notes-toggle { margin-right: auto; }
/* Docked controls stay on one or two rows so the scene keeps most of the stage. */
.beat.is-try.is-active .card .toggle .n { display: none; }
.beat.is-try.is-active .card .toggle { min-height: 40px; padding: 0 var(--space-2); }
.steps button { width: 22px; height: 32px; border: 0; padding: 0; background: none; cursor: pointer; display: grid; place-items: center; }
.steps button::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); transition: background var(--dur-2), transform var(--dur-2); }
.steps button.is-done::before { background: var(--text-muted); }
.steps button[aria-current="step"]::before { background: var(--you); transform: scale(1.4); }
.notes-toggle { min-height: 36px; padding: 0 var(--space-3); border-radius: var(--radius-pill); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font: 600 .85rem/1 var(--f-sans); cursor: pointer; white-space: nowrap; }
.notes-toggle[aria-pressed="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }
.hint { font: 500 var(--type-label)/1.2 var(--f-sans); color: var(--text-faint); white-space: nowrap; }
.progress { position: absolute; left: 0; top: -1px; height: 2px; width: 100%; transform-origin: left; transform: scaleX(0); background: var(--you); }
.controls-bar { display: flex; align-items: center; gap: 6px; }
.pbtn {
  min-width: 40px; height: 36px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-pill); background: var(--surface); color: var(--text);
  font: 600 .85rem/1 var(--f-sans); cursor: pointer; white-space: nowrap; transition: background var(--dur-1), color var(--dur-1);
}
.pbtn:hover { background: var(--surface-sunk); }
.pbtn.is-primary { background: var(--text); color: var(--surface); border-color: var(--text); }
.pbtn.is-primary:hover { background: var(--c-ink-600); }
.pbtn:disabled { opacity: .4; cursor: default; }
.pbtn svg { width: 15px; height: 15px; fill: currentColor; flex: none; }
@media (max-width: 1440px) { .hint { display: none; } }
@media (max-width: 899px) {
  .brand, .steps { display: none; }
  .chapnav { flex: 1 1 auto; min-width: 0; }
  .chapnav button { min-width: 28px; }
  .notes-toggle { margin-right: 0; }
  .pbtn .lbl { display: none; }
}
.pbtn.is-try { border-color: var(--you); color: var(--you-strong); }
.pbtn.is-try[aria-pressed="true"] { background: var(--you); color: var(--surface); }
.pbtn[hidden] { display: none; }
/* Try it: the docked controls fade in and the scene above makes room smoothly instead of jumping. */
.scene { transition: bottom 340ms var(--ease-in-out); }
.beat.is-try.is-active .card { animation: dock-in 260ms var(--ease-out) both; }
@keyframes dock-in { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%); } }
body.notes-open .beat.is-try.is-active .card { animation: none; }

/* Player (owner decisions D16/D17): one full-screen stage above the bar. Keys, clicker or the Next button advance
   one step; each change runs as a fixed sequence (text out, picture plays at its designed pace, text in), so two
   texts are never on screen together. Nothing scrolls. */
html, body { height: 100%; }
body { overflow: hidden; }
#story { position: fixed; inset: 0 0 var(--bar-h) 0; overflow: hidden; transition: opacity 190ms var(--ease-out); }
#story.is-dipping { opacity: 0; }
.chapter { position: absolute; inset: 0; visibility: hidden; opacity: 0; background: var(--bg); }
.chapter.is-current { visibility: visible; opacity: 1; }
.stage { position: absolute; inset: 0; overflow: hidden; --dock-h: 0px; }
.scene {
  position: absolute; top: clamp(14px, 3svh, 32px);
  bottom: calc(max(var(--band-h), var(--dock-h)) + 1svh);
  left: max(4vw, calc(50vw - 85svh)); right: max(4vw, calc(50vw - 85svh));
}
.beats { position: absolute; left: 0; top: 0; width: 0; height: 0; }
/* Caption band: one line per step, like a subtitle, in the lower part of the stage. */
.say {
  position: absolute; z-index: 5; left: 50%; bottom: 0; transform: translateX(-50%);
  height: var(--band-h); width: min(92vw, 1100px); margin: 0;
  display: grid; align-content: center; justify-items: center; text-align: center;
  font: 450 var(--type-caption)/1.18 var(--f-serif); letter-spacing: -.01em; text-wrap: balance;
  color: var(--text); will-change: opacity, transform; pointer-events: none;
}
.say[hidden] { display: none; }
.say .kicker { display: block; margin-bottom: .45em; font-size: var(--type-label); }
.say .title { display: block; font: 560 calc(var(--type-caption) * 1.35)/1.04 var(--f-serif); letter-spacing: -.02em; }
.say .sub { display: block; margin-top: .4em; font-size: var(--type-caption-sub); color: var(--text-muted); }
.say.is-long .title { font-size: calc(var(--type-caption) * 1.12); }
/* The opening title owns the whole stage for the first step; the scene starts only after it has gone. */
.say.is-hero { top: 0; bottom: 0; height: auto; padding: 0 6vw; gap: .2em; }
.say.is-hero .title { font-size: var(--type-hero); line-height: .98; max-width: 14ch; text-wrap: balance; }
.say.is-hero .sub { max-width: 32ch; }

/* The full text of every step stays in the page for screen readers, the notes panel and search, but off screen. */
.card {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: normal;
  background: var(--card-bg); border-radius: var(--radius-3); padding: var(--space-5) var(--space-5) var(--space-6);
  box-shadow: var(--card-shadow); border: 1px solid var(--line);
}
.card:focus-within, .beat.is-try.is-active .card, body.notes-open .beat.is-active .card { pointer-events: auto; clip-path: none; overflow: auto; width: auto; height: auto; }
.beat:not(.is-try) .card:focus-within { position: fixed; z-index: 25; top: 16px; right: 16px; bottom: calc(var(--bar-h) + 16px); width: min(440px, 92vw); }
/* Try-it steps: only the controls, docked at the bottom of the stage. */
.beat.is-try.is-active .card {
  position: fixed; z-index: 20; left: 50%; bottom: calc(var(--bar-h) + 12px); transform: translateX(-50%);
  width: min(94vw, 1100px); max-height: 42svh; padding: var(--space-3) var(--space-4);
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4);
}
.beat.is-try.is-active .card > p:not(.kicker):not([data-status]):not([data-note]) { display: none; }
.beat.is-try.is-active .card > * + * { margin-top: 0; }
.beat.is-try.is-active .card .toggles { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); }
.beat.is-try.is-active .card .toggles legend { display: none; }
/* Notes panel (button "Notes" or key N): the full text of the current step, for the presenter or for reading on your own. */
body.notes-open .beat.is-active .card {
  position: fixed; z-index: 25; top: 16px; right: 16px; left: auto; bottom: calc(var(--bar-h) + 16px); transform: none;
  width: min(440px, 92vw); max-height: none; display: block; padding: var(--space-5);
  background: var(--surface); box-shadow: 0 24px 60px -20px rgba(23,23,27,.45);
}
body.notes-open .beat.is-active .card > *,
body.notes-open .beat.is-try.is-active .card > p:not(.kicker):not([data-status]):not([data-note]) { display: revert; }
body.notes-open .beat.is-active .card > * + * { margin-top: var(--space-3); }
.card p { font: 400 var(--type-lead)/1.45 var(--f-serif); }
.card p.small { font: 400 var(--type-small)/1.5 var(--f-sans); color: var(--text-muted); }
.card p.src { font: 400 var(--type-label)/1.5 var(--f-sans); color: var(--text-faint); }
.kicker, .card p.kicker { font: 650 var(--type-label)/1.2 var(--f-sans); letter-spacing: .12em; text-transform: uppercase; color: var(--you); }
.card h2 { font-size: var(--type-title); line-height: 1.04; }
.card h1 { font-size: var(--type-title); line-height: 1.02; letter-spacing: -.02em; }
.card h1, .card h2, .card p { overflow-wrap: break-word; hyphens: auto; }
.takeaway { border-left: 3px solid var(--you); padding-left: var(--space-4); }
.takeaway b { font-weight: 650; }
.src { font: 400 var(--type-label)/1.5 var(--f-sans); color: var(--text-faint); }
.src a { color: inherit; }

/* Controls inside cards */
.controls { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.btn {
  min-height: var(--control-h); padding: 0 var(--space-4); border-radius: var(--radius-pill);
  border: 1px solid var(--text); background: var(--surface); color: var(--text);
  font: 600 .92rem/1 var(--f-sans); cursor: pointer; transition: background var(--dur-1), color var(--dur-1), opacity var(--dur-1);
}
.btn:hover { background: var(--surface-sunk); }
.btn.primary { background: var(--text); color: var(--surface); }
.btn.primary:hover { background: var(--c-ink-600); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.toggles { display: grid; gap: var(--space-2); margin: 0; padding: 0; border: 0; }
.toggles legend { font: 650 var(--type-label)/1.2 var(--f-sans); letter-spacing: .1em; text-transform: uppercase; color: var(--text-faint); margin-bottom: var(--space-2); }
.toggle { display: flex; align-items: center; gap: var(--space-3); min-height: var(--control-h); padding: 0 var(--space-3); border-radius: var(--radius-2); cursor: pointer; font: 500 .95rem/1.2 var(--f-sans); }
.toggle:hover { background: var(--surface-sunk); }
.toggle input { width: 20px; height: 20px; accent-color: var(--you); margin: 0; }
.toggle .swatch { width: 14px; height: 14px; border-radius: 3px; flex: none; border: 1px solid var(--line-strong); }
.toggle .swatch.k-app { background: var(--app-soft); }
.toggle .swatch.k-files { background: var(--model-soft); border-color: var(--model); }
.toggle .swatch.k-hist { background: var(--cached-soft); border-color: var(--cached); }
.toggle .swatch.k-you { background: var(--you-soft); border-color: var(--you); }
.toggle .n { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-muted); white-space: nowrap; }
.toggle { flex-wrap: wrap; row-gap: 0; }

/* Draft chapters (not yet built) */
.draft { padding: var(--space-6) clamp(var(--space-4), 8vw, var(--space-9)); display: grid; gap: var(--space-4); justify-items: start; align-content: center; }
.draft .kicker { color: var(--text-faint); }
.draft h2 { font-size: var(--type-title); line-height: 1.05; max-width: 24ch; }
.draft p { font: 400 var(--type-lead)/1.45 var(--f-serif); color: var(--text-muted); max-width: 46ch; }
.draft .badge { justify-self: start; font: 650 var(--type-label)/1 var(--f-sans); letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); border: 1px dashed var(--line-strong); padding: var(--space-2) var(--space-3); border-radius: var(--radius-pill); }

/* The colophon stays in the page for screen readers and search; the player has no scrolled footer to show it in. */
.colophon { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

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