/* ------------------------------------------------------------------ base */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body.deck {
  /* Paper studio. The deck sits on the site's warm paper system instead of a
     dark stage, so remap the shell's surface tokens locally and let every rule
     below flip together; no component keeps a dark assumption. */
  --stage: var(--paper);
  --stage-raised: var(--paper-raised);
  --stage-ink: var(--ink);
  --stage-muted: var(--ink-soft);
  --stage-line: var(--line);
  --stage-line-strong: var(--line-strong);

  /* The raw course accent is made for dots and washes, not for type: it is
     only ~2.2:1 on paper. Type, focus rings and thin indicators use this
     darkened mix, which keeps the course hue at AA contrast. */
  --deck-accent-ink: var(--ink);
  --deck-accent-ink: color-mix(in srgb, var(--deck-accent) 62%, var(--ink));
  --deck-accent-wash: color-mix(in srgb, var(--deck-accent) 13%, transparent);

  --deck-ink-wash: rgba(22, 20, 15, 0.05);

  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--stage);
  color: var(--stage-ink);
  color-scheme: light;
  font-family: var(--font-deck, "Noto Sans SC", system-ui, sans-serif);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

body.deck::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(1100px 520px at 78% -12%, color-mix(in srgb, var(--deck-accent) 11%, transparent), transparent 62%),
    radial-gradient(900px 500px at -8% 80%, rgba(184, 69, 43, 0.06), transparent 60%);
}

h1,
h2,
h3,
p {
  margin: 0;
}

/* [hidden] must win over component display rules (flex/grid) below. */
[hidden] {
  display: none !important;
}

button {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.deck-skip {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: var(--z-skip);
  background: var(--stage-ink);
  color: var(--stage);
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  text-decoration: none;
}

.deck-skip:focus {
  left: 16px;
}

:focus-visible {
  outline: 2px solid var(--deck-accent-ink);
  outline-offset: 3px;
  border-radius: var(--radius-inline);
}

::selection {
  background: color-mix(in srgb, var(--deck-accent) 32%, transparent);
  color: var(--stage-ink);
}

.deck-shell {
  position: relative;
  z-index: 1;
  width: min(1440px, 100% - 48px);
  margin-inline: auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-block: clamp(20px, 4vh, 44px) 40px;
}

/* The top bar adds its own height above the shell; trim the shell's top padding
   so the cover's start control keeps its old distance from the fold. */
body.deck[data-deck-nav] .deck-shell {
  padding-top: clamp(10px, 1.8vh, 20px);
}

/* --------------------------------------------------------------- top bar */
/* Leaving must be possible before a course starts. The cover is a long reading
   page (its outline column collapses under the main column below 1080px), so
   the way back lives in a sticky bar at the very top instead of at the bottom
   of the outline. Hidden while a course plays: the control bar's exit control
   leads there, and the two must not compete.

   Sticky, not fixed: it takes its own space in the flow, so it never covers the
   cover title, and it stays reachable after the user scrolls the cover. */

.deck-topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  backdrop-filter: blur(14px);
  background: color-mix(in srgb, var(--stage) 86%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--stage-line) 70%, transparent);
}

@media (prefers-reduced-transparency: reduce) {
  .deck-topbar {
    backdrop-filter: none;
    background: var(--stage);
  }
}

.deck-topbar__inner {
  display: flex;
  align-items: center;
  width: min(1440px, 100% - 48px);
  min-height: 56px;
  margin-inline: auto;
}

.deck-topbar__back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 16px 0 14px;
  border: 1px solid var(--stage-line);
  border-radius: var(--radius-pill);
  background: var(--stage-raised);
  color: var(--stage-ink);
  font-size: 13.5px;
  text-decoration: none;
  transition:
    background 150ms var(--ease, ease),
    border-color 150ms var(--ease, ease);
}

.deck-topbar__back:hover {
  background: var(--deck-ink-wash);
  border-color: var(--stage-line-strong);
}

/* ------------------------------------------------------------- clip preview */
/* Shown only when the admin preview opened the page with ?preview=<screen-id>.
   It floats over the classroom, above the stage but below the drawers, and is
   the one route back to the clip settings without leaving the preview. */

.deck-preview {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  max-width: calc(100vw - 24px);
  padding: 8px 10px 8px 14px;
  border: 1px solid var(--stage-line-strong);
  border-radius: var(--radius-stage);
  background: var(--stage-raised);
  box-shadow: var(--shadow-card);
  color: var(--stage-ink);
  font-size: 13px;
  line-height: 1.4;
}

.deck-preview[hidden] {
  display: none;
}

.deck-preview__text {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  margin: 0;
}

.deck-preview__tag {
  flex: none;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--deck-accent-wash);
  color: var(--deck-accent-ink);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
}

.deck-preview__label {
  min-width: 0;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck-preview__hint {
  color: var(--stage-muted);
  font-size: 12px;
  white-space: nowrap;
}

.deck-preview__actions {
  display: flex;
  flex: none;
  gap: 8px;
}

.deck-preview__button {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--stage-line);
  border-radius: var(--radius-pill);
  background: var(--stage);
  color: var(--stage-ink);
  font: inherit;
  font-size: 12.5px;
  text-decoration: none;
  cursor: pointer;
  transition:
    background 150ms var(--ease, ease),
    border-color 150ms var(--ease, ease);
}

.deck-preview__button:hover {
  background: var(--deck-ink-wash);
  border-color: var(--stage-line-strong);
}

.deck-preview__button:focus-visible {
  outline: 2px solid var(--deck-accent-ink);
  outline-offset: 2px;
}

/* Short windows: the sticky bar costs the cover height, so tighten the cover
 * rhythm and keep the start control above the fold. The bar itself keeps its
 * 56px so the control looks the same at every size. */
@media (max-height: 800px) {
  body.deck[data-deck-nav] .cover__inner {
    padding-top: 4px;
  }

  body.deck[data-deck-nav] .cover__actions {
    margin-top: 20px;
  }
}

/* 720p-class windows (1280x720 at 150% display scaling) need the headline one
 * step smaller as well. */
@media (max-height: 760px) {
  body.deck[data-deck-nav] .cover__title {
    font-size: clamp(30px, 4vw, 52px);
  }
}

/* ----------------------------------------------------------------- cover */

.cover__inner {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: clamp(28px, 5vw, 80px);
  align-items: start;
  padding-block: clamp(12px, 3vh, 40px);
}

.cover__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--stage-muted);
  margin-bottom: 20px;
}

.cover__title {
  font-size: clamp(36px, 4.6vw, 62px);
  line-height: 1.1;
  letter-spacing: -0.04em;
  font-weight: 700;
  text-wrap: balance;
}

.cover__subtitle {
  margin-top: 14px;
  font-size: clamp(17px, 1.9vw, 21px);
  color: var(--deck-accent-ink);
  font-weight: 600;
}

.cover__summary {
  margin-top: 20px;
  max-width: 40em;
  font-size: 16px;
  line-height: 1.8;
  color: var(--stage-muted);
}

.cover__block {
  margin-top: 30px;
}

.cover__label,
.complete__label {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--stage-muted);
  margin-bottom: 12px;
}

.cover__outcomes {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 9px;
}

.cover__outcomes li {
  position: relative;
  padding-left: 22px;
  font-size: 15.5px;
  color: var(--stage-ink);
}

.cover__outcomes li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.62em;
  width: 10px;
  height: 2px;
  background: var(--deck-accent-ink);
}

.cover__prereq {
  font-size: 15px;
  color: var(--stage-muted);
}

.cover__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 34px;
}

.cover__hint {
  margin-top: 14px;
  font-size: 13.5px;
  color: var(--deck-accent-ink);
}

.cover__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 38px;
  margin-top: 38px;
  padding-top: 22px;
  border-top: 1px solid var(--stage-line);
}

.cover__meta dt {
  font-family: var(--font-mono, monospace);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--stage-muted);
  margin-bottom: 2px;
}

.cover__meta dd {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
}

/* outline */

.cover__aside {
  border: 1px solid var(--stage-line);
  border-radius: var(--radius-poster);
  padding: clamp(18px, 2.4vw, 28px);
  background: var(--stage-raised);
  box-shadow: var(--shadow-card);
}

.outline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1px;
  /* Long-form courses can have 30+ screens: keep the cover in one viewport and
     let the outline scroll instead of pushing the start button off-screen. */
  max-height: min(56dvh, 620px);
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding-right: 4px;
}

.outline__item {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 12px;
  align-items: start;
  width: 100%;
  padding: 12px 10px;
  border: 0;
  border-radius: var(--radius-mini);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 160ms var(--ease, ease);
}

.outline__item:hover {
  background: var(--deck-ink-wash);
}

.outline__item[aria-current="step"] {
  background: var(--deck-accent-wash);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--deck-accent) 30%, transparent);
}

.outline__num {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  color: var(--stage-muted);
  padding-top: 3px;
}

.outline__text {
  min-width: 0;
}

.outline__title {
  display: block;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}

.outline__summary {
  display: block;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--stage-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.outline__time {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  color: var(--stage-muted);
  padding-top: 3px;
}

/* ----------------------------------------------------------------- stage */

.stage-wrap {
  display: grid;
  gap: 18px;
}

.stage {
  position: relative;
  /* Width is capped by the viewport height so the control bar always stays
     above the fold; the player then keeps its own 16:9 box. */
  width: min(100%, calc((100dvh - 250px) * 16 / 9));
  aspect-ratio: 16 / 9;
  margin-inline: auto;
  background: var(--stage);
  border-radius: var(--radius-stage);
  overflow: hidden;
  box-shadow:
    0 0 0 1px var(--stage-line-strong),
    0 30px 64px -48px rgba(22, 20, 15, 0.55);
}

.stage__canvas {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  /* Corner and repeating watermarks size themselves in cqw so their design-pixel
   * sizes scale with the 16:9 canvas, not with the whole stage area. */
  container-type: inline-size;
}

.stage hyperframes-player {
  display: block;
  width: 100%;
  height: 100%;
  /* The player paints its own light scene iframe; keep the host transparent so
     no black default ever peeks through the paper stage. */
  background: transparent;
  --hfp-width: 100%;
}

.stage__veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: var(--stage);
  color: var(--stage-muted);
  font-size: 13.5px;
  transition: opacity 200ms var(--ease, ease);
}

.stage__veil--loading {
  z-index: 3;
}

.stage__veil--transition {
  z-index: 2;
  opacity: 0;
  pointer-events: none;
}

.stage__veil--transition.is-visible {
  opacity: 1;
}

.stage__veil[hidden] {
  display: none;
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--stage-line);
  border-top-color: var(--deck-accent-ink);
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* deck bar */

.deck-bar {
  display: grid;
  gap: 12px;
  padding: 16px clamp(14px, 2vw, 22px);
  border: 1px solid var(--stage-line);
  border-radius: var(--radius-stage);
  background: var(--stage-raised);
  box-shadow: var(--shadow-card);
}

.chapter__counter {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--deck-accent-ink);
}

.chapter__kicker {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--stage-muted);
  margin-top: 2px;
}

.chapter__title {
  font-size: clamp(20px, 2.2vw, 26px);
  letter-spacing: -0.02em;
  margin-top: 4px;
}

.chapter__summary {
  font-size: 14px;
  color: var(--stage-muted);
  margin-top: 4px;
  max-width: 60em;
}

.progress {
  height: 2px;
  background: var(--stage-line);
  border-radius: 2px;
  overflow: hidden;
}

.progress__fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--deck-accent-ink);
  transition: width 320ms var(--ease, ease);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.control {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--stage-line);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--stage-ink);
  font-size: 13.5px;
  cursor: pointer;
  transition:
    background 150ms var(--ease, ease),
    border-color 150ms var(--ease, ease),
    opacity 150ms var(--ease, ease);
}

.control:hover:not(:disabled) {
  background: var(--deck-ink-wash);
  border-color: var(--stage-line-strong);
}

.control:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.control--primary {
  background: var(--stage-ink);
  border-color: var(--stage-ink);
  color: var(--stage);
  font-weight: 600;
  min-width: 106px;
  justify-content: center;
}

.control--primary:hover:not(:disabled) {
  background: var(--deck-accent-ink);
  border-color: var(--deck-accent-ink);
  color: var(--stage);
}

.control__icon {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 6px 0 6px 10px;
  border-color: transparent transparent transparent currentColor;
}

.control--primary[data-state="playing"] .control__icon {
  width: 10px;
  height: 11px;
  border: 0;
  background:
    linear-gradient(currentColor, currentColor) left / 3.5px 100% no-repeat,
    linear-gradient(currentColor, currentColor) right / 3.5px 100% no-repeat;
}

.control--icon {
  width: 40px;
  padding: 0;
  justify-content: center;
  font-size: 15px;
}

/* The transcript icon is drawn with CSS: a paper page with two text lines.
   DESIGN.md allows text glyphs and CSS shapes only, no icon library and no
   decorative SVG, so this stays a border plus a rule with a box-shadow. */
.icon-doc {
  position: relative;
  display: inline-block;
  width: 12px;
  height: 15px;
  border: 1.5px solid currentColor;
  border-radius: 2px;
}

.icon-doc::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 2px;
  right: 2px;
  height: 1.5px;
  background: currentColor;
  box-shadow: 0 4px 0 currentColor;
}

/* Caption and voice toggles: aria-pressed is the only state signal, so the
 * off state also reads visually. Both are mute-switch semantics, not roles. */
.control--cc {
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.control--cc[aria-pressed="false"],
.control--sound[aria-pressed="false"] {
  opacity: 0.5;
}

.control--cc[aria-pressed="false"]:hover,
.control--sound[aria-pressed="false"]:hover {
  opacity: 1;
}

/* Leave-the-course pill: same geometry as the other controls, but tinted with
   the course accent so it reads as a different verb from prev/play/next.
   It is an <a>, so it must not inherit the browser's link underline. */
.control--exit {
  color: var(--deck-accent-ink);
  border-color: var(--deck-accent-ink);
  text-decoration: none;
}

.control--exit:hover:not(:disabled) {
  background: color-mix(in srgb, var(--deck-accent) 12%, transparent);
  border-color: var(--deck-accent-ink);
  color: var(--deck-accent-ink);
}

.control__sep {
  width: 1px;
  height: 22px;
  background: var(--stage-line);
  margin-inline: 4px;
}

.control--skip {
  font-weight: 600;
}

.clock {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  color: var(--stage-muted);
}

/* Scene scrubber: a thin timeline that grows into a normal range control on
 * hover/focus. The filled part is driven by --seek-progress from the deck. */
.seek {
  appearance: none;
  -webkit-appearance: none;
  flex: 1 1 auto;
  width: clamp(72px, 9vw, 120px);
  min-width: 0;
  height: 22px;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.seek::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--deck-accent-ink) 0 var(--seek-progress, 0%),
    var(--stage-line) var(--seek-progress, 0%) 100%
  );
}

.seek::-moz-range-track {
  height: 3px;
  border-radius: 999px;
  background: var(--stage-line);
}

.seek::-moz-range-progress {
  height: 3px;
  border-radius: 999px;
  background: var(--deck-accent-ink);
}

.seek::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -4.5px;
  border: 2px solid var(--stage-raised);
  border-radius: 50%;
  background: var(--deck-accent-ink);
  opacity: 0;
  transition: opacity 120ms var(--ease, ease);
}

.seek::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 2px solid var(--stage-raised);
  border-radius: 50%;
  background: var(--deck-accent-ink);
  opacity: 0;
  transition: opacity 120ms var(--ease, ease);
}

.seek:hover::-webkit-slider-thumb,
.seek:focus-visible::-webkit-slider-thumb,
.seek:active::-webkit-slider-thumb {
  opacity: 1;
}

.seek:hover::-moz-range-thumb,
.seek:focus-visible::-moz-range-thumb,
.seek:active::-moz-range-thumb {
  opacity: 1;
}

.seek:focus-visible {
  outline: 2px solid var(--deck-accent-ink);
  outline-offset: 2px;
  border-radius: var(--radius-pill);
}

.deck-hint {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  color: var(--stage-muted);
  text-align: center;
}

.stage-wrap.is-ended .chapter__summary::after {
  content: " · 这一屏讲完了，按下一屏继续";
  color: var(--deck-accent-ink);
}

/* Continuous courses advance themselves like a video; the manual hint would lie. */
body[data-deck-mode="continuous"] .stage-wrap.is-ended .chapter__summary::after {
  content: "";
}

/* -------------------------------------------------------------- complete */

.complete,
.error {
  max-width: 44em;
  min-height: min(76dvh, 720px);
  display: grid;
  align-content: center;
  padding-block: clamp(24px, 6vh, 80px);
}

.complete__eyebrow,
.error__eyebrow {
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--deck-accent-ink);
  margin-bottom: 16px;
}

.complete__title,
.error__title {
  font-size: clamp(30px, 4vw, 46px);
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.complete__lead,
.error__message {
  margin-top: 14px;
  color: var(--stage-muted);
  font-size: 16px;
}

.complete__block {
  margin-top: 34px;
}

.complete__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 12px;
  counter-reset: takeaway;
}

.complete__list li {
  counter-increment: takeaway;
  position: relative;
  padding-left: 34px;
  font-size: 16px;
}

.complete__list li::before {
  content: counter(takeaway, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.1em;
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  color: var(--deck-accent-ink);
}

.complete__actions,
.error__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 34px;
}

.error__code {
  font-family: var(--font-mono, monospace);
  font-size: 11.5px;
  color: var(--stage-muted);
  margin-top: 14px;
}

.error__hint {
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid var(--stage-line);
  border-radius: var(--radius-mini);
  background: var(--stage-raised);
  font-size: 14px;
  color: var(--stage-muted);
}

.error__meta {
  margin-top: 20px;
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  color: var(--stage-muted);
}

/* ------------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 24px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition:
    transform 170ms var(--ease, ease),
    background 170ms var(--ease, ease);
}

.btn:hover {
  transform: translateY(-1px);
}

.btn--primary {
  background: var(--stage-ink);
  border-color: var(--stage-ink);
  color: var(--stage);
}

.btn--primary:hover {
  background: var(--deck-accent-ink);
  border-color: var(--deck-accent-ink);
  color: var(--stage);
}

.btn--ghost {
  border-color: var(--stage-line-strong);
  color: var(--stage-ink);
  background: transparent;
}

.btn--ghost:hover {
  border-color: var(--stage-ink);
  background: var(--stage-raised);
}

/* ------------------------------------------------------------------ drawer */

.drawer {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  display: grid;
  justify-items: end;
}

.drawer[hidden] {
  display: none;
}

.drawer__scrim {
  position: absolute;
  inset: 0;
  background: rgba(22, 20, 15, 0.42);
  opacity: 0;
  transition: opacity 200ms var(--ease, ease);
}

.drawer.is-open .drawer__scrim {
  opacity: 1;
}

.drawer__panel {
  position: relative;
  /* Above the scrim: the scrim is a later sibling and would otherwise swallow
     clicks and wheel events on the panel itself. */
  z-index: 1;
  width: min(560px, 100%);
  height: 100%;
  overflow-y: auto;
  padding: clamp(24px, 3vw, 40px);
  background: var(--stage-raised);
  border-left: 1px solid var(--stage-line);
  box-shadow: -24px 0 60px -42px rgba(22, 20, 15, 0.5);
  transform: translateX(24px);
  opacity: 0;
  transition:
    transform 220ms var(--ease, ease),
    opacity 220ms var(--ease, ease);
}

.drawer.is-open .drawer__panel {
  transform: none;
  opacity: 1;
}

.drawer__head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--stage-line);
}

.drawer__eyebrow {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--deck-accent-ink);
  margin-bottom: 8px;
}

.drawer__title {
  font-size: 24px;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.drawer__meta {
  margin-top: 8px;
  font-family: var(--font-mono, monospace);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--stage-muted);
}

.drawer__close {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--stage-line);
  background: transparent;
  cursor: pointer;
  font-size: 14px;
}

.drawer__close:hover {
  border-color: var(--stage-ink);
  background: var(--deck-ink-wash);
}

.drawer__body {
  padding-block: 22px;
  display: grid;
  gap: 14px;
}

.drawer__body p {
  font-size: 15.5px;
  line-height: 1.85;
  color: color-mix(in srgb, var(--stage-ink) 88%, transparent);
}

.drawer__keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--stage-line);
}

.keyword {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--stage-line);
  color: var(--stage-muted);
}

.drawer__foot {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--stage-line);
  font-size: 12px;
  color: var(--stage-muted);
}

body.deck-drawer-open {
  overflow: hidden;
}

/* ------------------------------------------------------------- toc drawer */
/* The directory is the transcript drawer's sibling, not a second drawer
   system: same scrim, same slide, same focus contract. It is narrower, and its
   list scrolls on its own so the header and the hint stay put on long courses. */

.drawer--toc .drawer__panel {
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.drawer--toc .drawer__head,
.drawer--toc .drawer__foot {
  flex: none;
}

.drawer--toc .drawer__head {
  padding: clamp(24px, 3vw, 36px) clamp(20px, 2.4vw, 30px) 16px;
}

.drawer--toc .drawer__foot {
  margin: 0;
  padding: 12px clamp(20px, 2.4vw, 30px) 18px;
}

.toc {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
  list-style: none;
  margin: 0;
  padding: 6px clamp(10px, 1.6vw, 16px) 14px;
  display: grid;
  gap: 2px;
}

.toc__item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: baseline;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-mini);
  background: transparent;
  color: var(--stage-ink);
  text-align: left;
  cursor: pointer;
  transition: background 150ms var(--ease, ease);
}

.toc__item:hover {
  background: var(--deck-ink-wash);
}

.toc__item[aria-current="step"] {
  background: var(--deck-accent-wash);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--deck-accent) 30%, transparent);
}

.toc__num,
.toc__time {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  color: var(--stage-muted);
}

.toc__item[aria-current="step"] .toc__num {
  color: var(--deck-accent-ink);
}

.toc__name {
  min-width: 0;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.toc__time {
  padding-top: 2px;
}

/* ---------------------------------------------------------------- noscript */

.noscript {
  margin: 24px auto;
  max-width: 44em;
  padding: 18px 20px;
  border: 1px solid var(--stage-line);
  border-radius: var(--radius-mini);
  background: var(--stage-raised);
  font-size: 14px;
  color: var(--stage-muted);
}

/* ------------------------------------------------------ player fills view */
/* The cover and the completion page are reading surfaces: they keep the
 * centered 1440px column. While a course plays, the page becomes the player:
 * the stage takes all height left by the control deck, and the deck spans the
 * full viewport width with no page scroll. */

/* The sticky top bar belongs to the cover reading surface. Playing, loading,
 * completion and error states already carry their own exit control, so the bar
 * must not take 56px from the stage or duplicate that control. */
body.deck[data-deck-state="playing"] .deck-topbar,
body.deck[data-deck-state="loading"] .deck-topbar,
body.deck[data-deck-state="complete"] .deck-topbar,
body.deck[data-deck-state="error"] .deck-topbar {
  display: none;
}

body.deck[data-deck-state="playing"],
body.deck[data-deck-state="loading"] {
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

body.deck[data-deck-state="playing"] .deck-shell,
body.deck[data-deck-state="loading"] .deck-shell {
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

body.deck[data-deck-state="playing"] .stage-wrap,
body.deck[data-deck-state="loading"] .stage-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

body.deck[data-deck-state="playing"] .stage,
body.deck[data-deck-state="loading"] .stage {
  flex: 1;
  min-height: 0;
  width: 100%;
  aspect-ratio: auto;
  margin: 0;
  padding: clamp(6px, 1.2vh, 16px);
  border-radius: 0;
  box-shadow: none;
  display: grid;
  place-items: center;
  container-type: size;
}

body.deck[data-deck-state="playing"] .stage__canvas,
body.deck[data-deck-state="loading"] .stage__canvas {
  /* Fill the height while keeping 16:9: whichever dimension is tighter wins.
   * The cq units need `.stage` as a size container; browsers without them keep
   * the vh-based fallback. */
  width: min(100%, calc((100vh - 220px) * 16 / 9));
  width: min(100%, calc((100dvh - 220px) * 16 / 9));
  width: min(100cqw, calc(100cqh * 16 / 9));
  height: auto;
  aspect-ratio: 16 / 9;
  margin-inline: auto;
  border-radius: var(--radius-stage);
  box-shadow:
    0 0 0 1px var(--stage-line-strong),
    0 24px 60px -40px rgba(22, 20, 15, 0.55);
}

body.deck[data-deck-state="playing"] .deck-bar,
body.deck[data-deck-state="loading"] .deck-bar {
  width: 100%;
  border-radius: 0;
  border-inline: 0;
  border-bottom: 0;
  padding: 10px clamp(14px, 2.4vw, 36px) 12px;
  gap: 8px;
  box-shadow: none;
}

body.deck[data-deck-state="playing"] .chapter,
body.deck[data-deck-state="loading"] .chapter {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 14px;
  row-gap: 2px;
}

body.deck[data-deck-state="playing"] .chapter__counter,
body.deck[data-deck-state="loading"] .chapter__counter,
body.deck[data-deck-state="playing"] .chapter__kicker,
body.deck[data-deck-state="loading"] .chapter__kicker {
  margin: 0;
}

body.deck[data-deck-state="playing"] .chapter__title,
body.deck[data-deck-state="loading"] .chapter__title {
  font-size: clamp(17px, 1.5vw, 21px);
  margin: 0;
}

body.deck[data-deck-state="playing"] .chapter__summary,
body.deck[data-deck-state="loading"] .chapter__summary {
  flex: 1 1 320px;
  min-width: 0;
  margin: 0;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.deck[data-deck-state="playing"] .clock,
body.deck[data-deck-state="loading"] .clock {
  flex: 1 1 260px;
  min-width: 200px;
}

body.deck[data-deck-state="playing"] .deck-hint,
body.deck[data-deck-state="loading"] .deck-hint {
  padding: 0 clamp(14px, 2.4vw, 36px) 6px;
}

body.deck[data-deck-state="playing"] .stage-wrap:fullscreen,
body.deck[data-deck-state="loading"] .stage-wrap:fullscreen {
  background: var(--stage);
}

/* Completion and error are reading surfaces too: keep them vertically
 * centered in the viewport instead of leaving the whole height blank below. */
body.deck[data-deck-state="complete"] .deck-shell,
body.deck[data-deck-state="error"] .deck-shell {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Extra-short viewports: drop the secondary copy so the picture keeps the room. */
@media (max-height: 760px) {
  body.deck[data-deck-state="playing"] .chapter__summary,
  body.deck[data-deck-state="loading"] .chapter__summary,
  body.deck[data-deck-state="playing"] .deck-hint,
  body.deck[data-deck-state="loading"] .deck-hint {
    display: none;
  }
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 1080px) {
  .cover__inner {
    grid-template-columns: 1fr;
    gap: 34px;
  }

  .stage {
    max-height: none;
  }
}

@media (max-width: 700px) {
  .deck-shell {
    width: min(1440px, 100% - 28px);
    padding-top: 16px;
  }

  .deck-topbar__inner {
    width: min(1440px, 100% - 28px);
  }

  .cover__title {
    font-size: 32px;
  }

  .cover__actions .btn {
    flex: 1 1 auto;
  }

  .control__label {
    display: none;
  }

  /* Leaving the course must stay legible as a labelled action on touch. */
  .control--exit .control__label {
    display: inline;
  }

  /* The skip-to-end control is the answer to "I only want the final frame". */
  .control--skip .control__label {
    display: inline;
  }

  .control--primary {
    min-width: 72px;
  }

  .clock {
    margin-left: 0;
    width: 100%;
  }

  .drawer__panel {
    width: 100%;
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  .stage-wrap::before {
    content: "横屏观看动画更清楚；竖屏下建议读讲义。";
    display: block;
    padding: 10px 14px;
    border: 1px solid color-mix(in srgb, var(--deck-accent) 30%, var(--stage-line));
    border-radius: var(--radius-mini);
    background: var(--deck-accent-wash);
    font-size: 13px;
    text-align: center;
  }
}

@media (max-width: 680px) {
  .deck-preview {
    right: 12px;
    justify-content: space-between;
  }

  .deck-preview__hint {
    display: none;
  }
}

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

  .spinner {
    animation: none;
    border-top-color: var(--deck-accent-ink);
  }
}

@media print {
  body.deck {
    background: #fff;
    color: #111;
  }

  .stage-wrap,
  .controls,
  .deck-hint,
  .deck-topbar,
  .deck-preview,
  .deck-skip {
    display: none !important;
  }

  .cover__aside {
    break-before: page;
  }
}
