@font-face {
  font-family: 'ch-screen';
  src: url('assets/fonts/ch-screen.woff2') format('woff2'),
       url('assets/fonts/ch-screen.woff') format('woff'),
       url('assets/fonts/ch-screen.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: 'MagdaCleanMono-Regular';
  src: url('assets/fonts/MagdaCleanMono-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: block;
}

:root {
  --bg: #000;
  --text-ui: #cfcfcf;
  --text-primary: #fff;
  --tint-active: rgba(0, 0, 0, 0.3);
  --tint-adjacent: rgba(0, 0, 0, 0.6);
  --ui-size-mobile: 11px;
  --headline-size-mobile: 35px;
  --ui-size-desktop: 16px;
  --headline-size-desktop: 57px;
}

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

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text-ui);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body {
  font-family: 'ch-screen', system-ui, sans-serif;
  font-size: var(--ui-size-mobile);
  line-height: 1.018;
  text-transform: lowercase;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.headline {
  font-family: 'MagdaCleanMono-Regular', monospace;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* ── title card ── */

#title-card {
  position: fixed;
  top: 40px;
  left: 12px;
  right: 75px;
  z-index: 100;
  font-family: 'MagdaCleanMono-Regular', monospace;
  font-size: var(--headline-size-mobile);
  line-height: 1;
  color: var(--text-ui);
  pointer-events: none;
  text-transform: lowercase;
}

#title-card .tc-line {
  display: block;
  margin-top: 0.1em;
}

#title-card .tc-word {
  opacity: 0;
  display: inline;
  animation: tc-word-in 1ms linear forwards;
}

#title-card .tc-word.visible {
  opacity: 1;
}

@keyframes tc-word-in {
  to { opacity: 1; }
}

#title-card.tc-mini {
  top: 45px;
  font-family: 'ch-screen', system-ui, sans-serif;
  font-size: var(--ui-size-mobile);
  line-height: 1.018;
  transition: color 420ms ease;
}

@media (min-width: 768px) and (min-height: 500px) {
  #title-card.tc-mini {
    top: 65px;
    font-size: var(--ui-size-desktop);
    line-height: 1.042;
  }
}

@media (min-width: 768px) and (min-height: 500px) {
  #title-card {
    top: 60px;
    left: 16px;
    right: 170px;
    font-size: var(--headline-size-desktop);
  }
}

/* ── svg title overrides ── */

#title-card.tc-override {
  color: var(--text-ui);
}

#title-card.tc-override-l {
  top: 60px;
  left: 12px;
  right: max(25vw, 149px);
  bottom: auto;
  text-align: left;
}

@media (min-width: 768px) and (min-height: 500px) {
  #title-card.tc-override-l {
    left: 16px;
    right: max(25vw, 245px);
  }
}

#title-card.tc-override-c {
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

#title-card.tc-override .tc-svg-wrap {
  width: 95vw;
  max-height: 95vh;
  display: block;
}

#title-card.tc-override-l .tc-svg-wrap {
  width: auto;
  max-width: 80vw;
  max-height: 80vh;
}

@media (min-width: 768px) and (min-height: 500px) {
  #title-card.tc-override-c .tc-svg-wrap {
    width: 85vw;
    max-height: 75vh;
  }

  #title-card.tc-override-l .tc-svg-wrap {
    max-width: 50vw;
    max-height: 45vh;
  }
}

#title-card.tc-override .tc-svg-wrap svg {
  width: 100%;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  display: block;
}

/* force single-color SVGs to inherit the wrapper color (overrides
   presentation attributes like fill="black" per CSS spec) */
#title-card.tc-override .tc-svg-wrap svg,
#title-card.tc-override .tc-svg-wrap svg * {
  fill: currentColor;
}

#title-card.tc-override .tc-credit {
  margin-top: 30px;
  font-family: 'ch-screen', system-ui, sans-serif;
  font-size: var(--ui-size-mobile);
  line-height: 1.018;
  text-transform: lowercase;
}

@media (min-width: 768px) and (min-height: 500px) {
  #title-card.tc-override .tc-credit {
    margin-top: 40px;
    font-size: var(--ui-size-desktop);
    line-height: 1.042;
  }
}

/* ── eyebrow bar ── */

#eyebrow {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  padding: 12px 12px 0;
  pointer-events: none;
  color: var(--text-ui);
  font-family: 'ch-screen', system-ui, sans-serif;
  background: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

#eyebrow-seq {
  flex-shrink: 0;
}

#eyebrow-slug {
  margin-left: 15px;
  flex-shrink: 0;
  margin-right: auto;
}

#eyebrow-timecode {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-variant-numeric: tabular-nums;
}

#eyebrow-issue {
  flex-shrink: 0;
  margin-left: auto;
  text-align: right;
  white-space: nowrap;
}

#eyebrow.is-printing #eyebrow-seq,
#eyebrow.is-printing #eyebrow-slug,
#eyebrow.is-printing #eyebrow-timecode,
#eyebrow.is-printing #eyebrow-issue {
  opacity: 0;
  transition: opacity 80ms linear;
}

#eyebrow.is-printing #eyebrow-seq.is-visible,
#eyebrow.is-printing #eyebrow-slug.is-visible,
#eyebrow.is-printing #eyebrow-timecode.is-visible,
#eyebrow.is-printing #eyebrow-issue.is-visible {
  opacity: 1;
}

#logo-bug {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 99;
  width: 134px;
  pointer-events: none;
}

#logo-bug-text {
  position: relative;
  z-index: 1;
  padding: 12px 12px 0 0;
  text-align: right;
  font-size: inherit;
  line-height: 1;
}

#logo-bug video {
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  aspect-ratio: 1.39;
  object-fit: contain;
  mix-blend-mode: screen;
  background: transparent;
  opacity: 0.95;
}

@media (min-width: 768px) and (min-height: 500px) {
  #eyebrow {
    padding: 16px 16px 0;
  }

  #logo-bug {
    width: 245px;
  }

  #logo-bug-text {
    padding: 16px 16px 0 0;
  }

  #eyebrow-slug {
    margin-left: 40px;
  }
}

img,
video {
  max-width: 100%;
  display: block;
}

/* ── link-out button ── */

#link-out {
  position: fixed;
  left: 50%;
  bottom: 12vh;
  transform: translateX(-50%);
  z-index: 101;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 3px;
  border: 1px solid #f5f5f5;
  border-radius: 12px;
  background: transparent;
  color: #f5f5f5;
  font-family: 'ch-screen', system-ui, sans-serif;
  font-size: var(--ui-size-mobile);
  line-height: 1.018;
  text-transform: lowercase;
  text-decoration: none;
  white-space: nowrap;
}

#link-out[hidden] {
  display: none;
}

#link-out .link-out-arrow {
  display: inline-flex;
  width: 0.65em;
  height: 0.65em;
  transform: translateY(-1px);
}

#link-out .link-out-arrow svg {
  width: 100%;
  height: 100%;
  display: block;
}

#link-out .link-out-arrow svg,
#link-out .link-out-arrow svg * {
  fill: currentColor;
}

@media (min-width: 768px) and (min-height: 500px) {
  #link-out {
    bottom: 8vh;
    padding: 6px 14px 4px;
    border-width: 2px;
    border-radius: 20px;
    font-size: var(--ui-size-desktop);
    line-height: 1.042;
    gap: 8px;
  }
}

#stack {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateY(0);
  transition: transform 420ms cubic-bezier(.22, .61, .36, 1);
  will-change: transform;
}

#stack.no-transition,
#stack.no-transition .slide::after {
  transition: none;
}

.slide {
  --aspect-w: 16;
  --aspect-h: 9;
  width: min(100vw, calc(100vh * var(--aspect-w) / var(--aspect-h)));
  aspect-ratio: var(--aspect-w) / var(--aspect-h);
  flex-shrink: 0;
  position: relative;
  background: var(--bg);
}

.slide video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: var(--bg);
}

/* HLS renders on the active slide and the slide currently leaving view,
   so the outgoing video fades to black during the transform transition. */
.slide:not(.is-active):not(.is-leaving) .slide-hls {
  display: none;
}

.slide::after {
  content: '';
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 1;
  pointer-events: none;
  transition: opacity 420ms ease;
}

.slide.is-active::after {
  opacity: var(--drag-fade, 0);
}

/* overlay open: active tinted 0.3; in portrait, adjacent tinted 0.6 */
body.overlay-open:not(.is-dragging) .slide.is-active::after {
  opacity: 0.3;
}

/* TOC → first video: hold the active slide's veil at full black while the
   eyebrow prints in. _enterProgramFromToc removes intro-print after the
   1s hold; the veil then fades 1 → 0 over 420ms, revealing the video. */
body.intro-print .slide.is-active::after {
  opacity: 1;
}

/* Drag gesture in progress: suppress stack + overlay transitions so the
   active slide tracks the finger 1:1. The body class is removed on
   release; the natural 420ms transitions then handle commit/snap-back. */
body.is-dragging #stack,
body.is-dragging .slide::after {
  transition: none;
}

@media (orientation: portrait) {
  body.overlay-open .slide:not(.is-active)::after {
    opacity: 0.6;
  }
}

@media (min-width: 768px) and (min-height: 500px) {
  body {
    font-size: var(--ui-size-desktop);
    line-height: 1.042;
  }
}

/* ── overlay ── */

body.overlay-open #title-card.tc-mini {
  color: #fff;
}

#title-card .tc-description {
  margin-top: 1em;
  max-width: 148px;
  color: #fff;
  font-family: 'ch-screen', system-ui, sans-serif;
  font-size: var(--ui-size-mobile);
  line-height: 1.018;
  text-transform: lowercase;
  white-space: normal;
  opacity: 0;
  transition: opacity 420ms ease;
}

body.overlay-open #title-card .tc-description {
  opacity: 1;
}

@media (min-width: 768px) and (min-height: 500px) {
  #title-card .tc-description {
    max-width: 232px;
    font-size: var(--ui-size-desktop);
    line-height: 1.042;
  }
}

/* Inline pill links inside the overlay description. Markdown-style
   [label](url) renders as an outlined pill matching the #link-out style. */
#title-card .desc-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 1px;
  margin: 2px 0;
  border: 1px solid currentColor;
  border-radius: 10px;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
  vertical-align: baseline;
  /* #title-card sets pointer-events: none so the title doesn't block taps
     on the video underneath. Re-enable it on the pill so the link is
     clickable (and only the pill is — the surrounding text stays inert). */
  pointer-events: auto;
  cursor: pointer;
  /* Lift the whole pill so its visual baseline matches the surrounding text. */
  transform: translateY(-1px);
}

#title-card .desc-link .desc-link-label {
  /* Optical nudge to vertically center the small mobile type in the pill.
     Removed at desktop sizing where the larger glyphs align without it. */
  transform: translateY(1px);
}

#title-card .desc-link .desc-link-arrow {
  display: inline-flex;
  width: 0.65em;
  height: 0.65em;
  transform: translateY(-1px);
}

#title-card .desc-link .desc-link-arrow svg {
  width: 100%;
  height: 100%;
  display: block;
}

#title-card .desc-link .desc-link-arrow svg,
#title-card .desc-link .desc-link-arrow svg * {
  fill: currentColor;
}

@media (min-width: 768px) and (min-height: 500px) {
  #title-card .desc-link {
    padding: 4px 10px 2px;
    border-width: 2px;
    border-radius: 16px;
    gap: 8px;
  }

  #title-card .desc-link .desc-link-label {
    transform: none;
  }
}

#overlay-nav {
  position: fixed;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 15px;
  pointer-events: none;
  right: 20px;
  bottom: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 420ms ease, visibility 0s linear 420ms;
}

body.overlay-open #overlay-nav,
body.controls-visible #overlay-nav,
body.toc-mode #overlay-nav {
  opacity: 1;
  visibility: visible;
  transition: opacity 420ms ease, visibility 0s linear 0s;
}

/* When the TOC is fading to black for a video transition, fade the control
   stack alongside it (the body still has toc-mode during this window, so
   without this rule the controls would stay fully visible until toc-mode
   is removed at the 500ms boundary, then snap-fade afterward). */
body.toc-leaving #overlay-nav {
  opacity: 0;
  visibility: hidden;
  transition: opacity 500ms ease, visibility 0s linear 500ms;
}

#overlay-nav button {
  width: 33px;
  height: 33px;
  border: none;
  background: transparent;
  color: var(--text-ui);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  pointer-events: none;
  -webkit-tap-highlight-color: transparent;
}

body.overlay-open #overlay-nav button,
body.controls-visible #overlay-nav button,
body.toc-mode #overlay-nav button {
  pointer-events: auto;
}

body.toc-leaving #overlay-nav button,
body.toc-mode #overlay-toc {
  pointer-events: none;
}

#overlay-nav button svg {
  width: 100%;
  height: 100%;
  display: block;
}

#overlay-nav button svg,
#overlay-nav button svg * {
  fill: currentColor;
  pointer-events: none;
}

#overlay-nav button svg g {
  mix-blend-mode: normal;
}

#overlay-play-pause .nav-icon,
#overlay-mute .nav-icon {
  display: none;
  width: 100%;
  height: 100%;
}

#overlay-play-pause[data-state="playing"] .nav-pause { display: block; }
#overlay-play-pause[data-state="paused"] .nav-play { display: block; }
#overlay-mute[data-state="unmuted"] .nav-mute-off { display: block; }
#overlay-mute[data-state="muted"] .nav-mute-on { display: block; }

@media (min-width: 768px) and (min-height: 500px) {
  #overlay-nav {
    gap: 16px;
    right: 40px;
    bottom: 40px;
  }

  #overlay-nav button {
    width: 46px;
    height: 46px;
  }
}

/* Mobile landscape — enforce mobile sizing on the mini title / description /
   centered SVG titles even when viewport width exceeds the desktop breakpoint.
   Placed last so it wins by source order over any desktop @media above. */
@media (orientation: landscape) and (max-height: 500px) {
  #title-card.tc-mini {
    top: 45px;
    left: 60px;
    right: auto;
    max-width: 200px;
    font-size: var(--ui-size-mobile);
    line-height: 1.018;
  }

  #title-card .tc-description {
    max-width: 148px;
    font-size: var(--ui-size-mobile);
    line-height: 1.018;
  }

  #title-card .desc-link {
    padding: 3px 8px 1px;
    border-width: 1px;
    border-radius: 10px;
    gap: 6px;
  }

  #title-card.tc-override-c .tc-svg-wrap {
    width: 60vw;
    max-height: 60vh;
  }

  #title-card.tc-override-l .tc-svg-wrap {
    max-width: 50vw;
    max-height: 50vh;
  }

  #title-card.tc-override .tc-credit {
    margin-top: 30px;
    font-size: var(--ui-size-mobile);
    line-height: 1.018;
  }

  #eyebrow {
    padding: 12px 60px 0;
  }

  #title-card {
    left: 60px;
    right: 202px;
  }

  #title-card.tc-override-l {
    left: 60px;
    right: max(25vw, 197px);
  }

  #logo-bug {
    right: 48px;
  }

  #overlay-nav {
    right: 60px;
  }

  #cover-title {
    left: 60px;
  }

  #cover-eyebrows {
    right: 60px;
  }

  #cover-logo {
    right: 60px;
  }

  #cover-contributors {
    left: 60px;
    right: 60px;
  }

  #cover-play {
    right: 60px;
  }
}

/* ── cover ── */

body.cover-mode #eyebrow,
body.cover-mode #logo-bug,
body.cover-mode #title-card,
body.cover-mode #overlay-nav,
body.cover-mode #link-out {
  display: none !important;
}

body.cover-mode.intro-print #eyebrow {
  display: flex !important;
}

body.intro-print #eyebrow {
  z-index: 1010;
}

#cover {
  position: relative;
  width: 100vw;
  height: 100vh;
  aspect-ratio: auto;
  --aspect-w: initial;
  --aspect-h: initial;
  background: #000;
  opacity: 1;
  transition: opacity 500ms ease;
}

body.on-cover-slide #eyebrow,
body.on-cover-slide #title-card,
body.on-cover-slide #link-out,
body.on-cover-slide #logo-bug,
body.on-cover-slide #overlay-nav { display: none !important; }

#cover.is-exiting {
  opacity: 0;
  pointer-events: none;
}

#cover-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 75% 50%;
  display: block;
  opacity: 1;
  transition: opacity 500ms ease;
}

#cover.is-fading #cover-video {
  opacity: 0;
}

#cover-layer {
  position: absolute;
  top: env(safe-area-inset-top, 0);
  right: env(safe-area-inset-right, 0);
  bottom: env(safe-area-inset-bottom, 0);
  left: env(safe-area-inset-left, 0);
  pointer-events: none;
  opacity: 1;
  transition: opacity 500ms ease;
}

/* Touch devices only: extra breathing room below the status bar. */
@media (hover: none) and (pointer: coarse) {
  #cover-layer {
    top: calc(env(safe-area-inset-top, 0) + 45px);
  }
}

/* Mobile landscape: extra 10px on top of touch-device offset. */
@media (orientation: landscape) and (max-height: 500px) {
  #cover-layer {
    top: calc(env(safe-area-inset-top, 0) + 30px);
  }
}

#cover.is-fading #cover-layer {
  opacity: 0;
  pointer-events: none;
}

#cover-layer > * {
  pointer-events: auto;
}

/* masthead */
#cover-masthead {
  position: absolute;
  top: 14px;
  left: 0;
  right: 0;
  z-index: 10;
  color: var(--text-ui);
  font-family: 'ch-screen', system-ui, sans-serif;
  font-size: var(--ui-size-mobile);
  line-height: 1.018;
  text-transform: lowercase;
  pointer-events: none;
}

#cover-title {
  position: absolute;
  top: -2px;
  left: 14px;
  font-size: 23px;
  line-height: 0.9;
  letter-spacing: -0.02em;
}

#cover-title-main {
  color: var(--text-primary);
}

#cover-title-sub {
  color: #000;
}

#cover-eyebrows {
  position: absolute;
  top: -2px;
  right: 14px;
  display: flex;
  align-items: flex-start;
  gap: 25px;
}

#cover-slug {
  text-align: left;
}

#cover-issue {
  text-align: right;
}

/* big ch.1 mark */
#cover-logo {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 252px;
  pointer-events: none;
}

#cover-logo svg {
  width: 100%;
  height: auto;
  display: block;
}

/* contributor list — prints word by word like the title card */
#cover-contributors {
  position: absolute;
  top: 86px;
  left: 14px;
  right: 14px;
  font-family: 'MagdaCleanMono-Regular', monospace;
  font-size: var(--headline-size-mobile);
  line-height: 1;
  color: var(--text-ui);
  text-transform: lowercase;
  pointer-events: none;
}

#cover-contributors .tc-line {
  display: block;
  margin-top: 0;
}

#cover-contributors .tc-word {
  opacity: 0;
  display: inline;
  transition: opacity 80ms linear;
}

#cover-contributors .tc-word.visible {
  opacity: 1;
}

/* play button — black pill, bottom-right on mobile */
#cover-play {
  position: absolute;
  right: 13px;
  top: 156px;
  background: #000;
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 8px 16px 7px;
  font-family: 'ch-screen', system-ui, sans-serif;
  font-size: 18px;
  line-height: 1;
  text-transform: lowercase;
  letter-spacing: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cover-play-arrow {
  font-size: 15px;
  line-height: 1;
  display: inline-block;
  transform: translateY(1.5px);
}

@media (min-width: 801px) and (min-height: 500px) {
  #cover-masthead {
    top: 30px;
    font-size: var(--ui-size-desktop);
    line-height: 1.042;
  }

  #cover-title {
    top: -14px;
    left: calc(100% - 800px);
    font-size: 43px;
    line-height: 0.9;
  }

  #cover-eyebrows {
    top: -14px;
    right: 20px;
    gap: 70px;
  }

  #cover-logo {
    top: 14px;
    right: 14px;
    width: 436px;
  }

  #cover-contributors {
    top: 142px;
    left: calc(100% - 800px);
    right: auto;
    font-size: var(--headline-size-desktop);
  }

  #cover-play {
    right: 14px;
    top: 271px;
    padding: 12px 22px 10px;
    font-size: 23px;
    gap: 8px;
  }

  .cover-play-arrow {
    font-size: 20px;
  }
}

/* ── toc ── */

body.toc-mode #eyebrow,
body.toc-mode #logo-bug,
body.toc-mode #title-card,
body.toc-mode #link-out,
body.toc-mode #overlay-play-pause,
body.toc-mode #overlay-mute {
  display: none !important;
}

/* The TOC button is only meaningful while the description overlay is open
   on a playing video. Default to hidden everywhere else (controls-visible
   hover state, TOC, cover) and fade in only when body.overlay-open is set.
   Independent of #overlay-nav's own visibility so it never flashes during
   transitions where the parent is briefly visible (e.g. TOC→video). */
#overlay-toc {
  opacity: 0;
  visibility: hidden;
  transition: opacity 420ms ease, visibility 0s linear 420ms;
}

body.overlay-open #overlay-toc,
body.controls-visible:not(.toc-mode) #overlay-toc {
  opacity: 1;
  visibility: visible;
  transition: opacity 420ms ease, visibility 0s linear 0s;
}

/* Fade-to-black on a slide when returning to TOC. Applied to the active
   slide for the duration of the audio/video ramp, then cleared. */
.slide.is-fading-to-toc {
  transition: opacity 500ms ease;
  opacity: 0;
}

#toc {
  position: relative;
  width: 100vw;
  height: 100vh;
  aspect-ratio: auto;
  --aspect-w: initial;
  --aspect-h: initial;
  background: #000;
}

#toc-layer {
  position: absolute;
  top: env(safe-area-inset-top, 0);
  right: env(safe-area-inset-right, 0);
  bottom: env(safe-area-inset-bottom, 0);
  left: env(safe-area-inset-left, 0);
  pointer-events: none;
}

@media (hover: none) and (pointer: coarse) {
  #toc-layer {
    top: calc(env(safe-area-inset-top, 0) + 45px);
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  #toc-layer {
    top: calc(env(safe-area-inset-top, 0) + 30px);
    left: calc(env(safe-area-inset-left, 0) + 60px);
    right: calc(env(safe-area-inset-right, 0) + 60px);
  }
}

#toc-layer > * {
  pointer-events: auto;
}

#toc-masthead {
  position: absolute;
  top: 31px;
  left: 13px;
  z-index: 10;
  pointer-events: none;
}

#toc-title {
  font-family: 'ch-screen', system-ui, sans-serif;
  font-size: 17px;
  line-height: 0.9;
  letter-spacing: -0.02em;
  text-transform: lowercase;
}

#toc-title-main {
  color: var(--text-primary);
}

#toc-title-sub {
  color: var(--text-ui);
}

#toc-description {
  position: absolute;
  top: 85px;
  left: 13px;
  max-width: 148px;
  color: var(--text-ui);
  font-family: 'ch-screen', system-ui, sans-serif;
  font-size: var(--ui-size-mobile);
  line-height: 1.018;
  text-transform: lowercase;
  white-space: normal;
}

#toc-credits {
  position: absolute;
  bottom: 30px;
  left: 13px;
  max-width: 148px;
  color: var(--text-ui);
  font-family: 'ch-screen', system-ui, sans-serif;
  font-size: var(--ui-size-mobile);
  line-height: 1.018;
  text-transform: lowercase;
  white-space: pre-wrap;
}

/* Stack-sizing strategy: container height fills its parent (top:0/bottom:0).
   Each child has its native aspect ratio (per-:nth-child fallback below;
   overridden inline by JS once loadedmetadata fires for full precision).
   Container width is set inline by JS to clientHeight / Σ(h_i/w_i) so the
   summed child heights exactly equal container height with zero gap. */
#toc-loops {
  position: absolute;
  top: 0;
  bottom: 0;
  /* Mobile: shifted left to clear the overlay-nav controls (right:20px, w:33px).
     20 (right margin) + 33 (controls width) + 20 (gap) = 73 from viewport right. */
  right: 73px;
  /* width is set inline by JS; while it's still 0, the children also collapse */
  display: flex;
  flex-direction: column;
  gap: 0;
  pointer-events: none;
  overflow: hidden;
}

#toc-loops video.toc-loop {
  /* Override `.slide video { position: absolute; inset: 0; ... }` (line 411)
     which would otherwise make all 11 loops overlap at full slide size. */
  position: static;
  inset: auto;
  flex: 0 0 auto;
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
  cursor: pointer;
  pointer-events: auto;
  background: #111;
}

/* Per-video aspect-ratio fallback so the layout is stable before metadata
   loads. Source: `mdls` on each MP4. JS overrides inline once each video's
   loadedmetadata fires, so any future re-encode is picked up automatically. */
#toc-loops video.toc-loop:nth-child(1)  { aspect-ratio: 720 / 1280; }
#toc-loops video.toc-loop:nth-child(2)  { aspect-ratio: 720 / 1282; }
#toc-loops video.toc-loop:nth-child(3)  { aspect-ratio: 720 / 960; }
#toc-loops video.toc-loop:nth-child(4)  { aspect-ratio: 720 / 960; }
#toc-loops video.toc-loop:nth-child(5)  { aspect-ratio: 720 / 960; }
#toc-loops video.toc-loop:nth-child(6)  { aspect-ratio: 720 / 1280; }
#toc-loops video.toc-loop:nth-child(7)  { aspect-ratio: 720 / 1280; }
#toc-loops video.toc-loop:nth-child(8)  { aspect-ratio: 720 / 1280; }
#toc-loops video.toc-loop:nth-child(9)  { aspect-ratio: 720 / 956; }
#toc-loops video.toc-loop:nth-child(10) { aspect-ratio: 720 / 1280; }
#toc-loops video.toc-loop:nth-child(11) { aspect-ratio: 720 / 1280; }

/* Desktop type sizes for the TOC. Gated on min-height: 800px so short
   desktop windows fall back to mobile-sized type, preventing the credits
   from colliding with the description in the middle of the layer. */
@media (min-width: 768px) and (min-height: 800px) {
  #toc-masthead {
    top: 34px;
    left: 34px;
  }

  #toc-title {
    font-size: 32px;
  }

  #toc-description {
    top: 131px;
    left: 34px;
    max-width: 232px;
    font-size: var(--ui-size-desktop);
    line-height: 1.042;
  }

  #toc-credits {
    bottom: 34px;
    left: 34px;
    max-width: 232px;
    font-size: var(--ui-size-desktop);
    line-height: 1.042;
  }
}

/* Loop column position — centered on any desktop-width window regardless
   of height. Independent of the type-size breakpoint above. */
@media (min-width: 768px) and (min-height: 500px) {
  #toc-loops {
    top: 0;
    bottom: 0;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
  }
}

/* Portrait windows (iPhone primarily): bottom-align the loop column with
   the credits text block at bottom:30 so the column doesn't run off the
   bottom of the viewport. JS recomputes the column width from the new
   reduced height (h/Σ(h/w)) automatically. */
@media (orientation: portrait) {
  #toc-loops {
    bottom: 30px;
  }
}

/* Short landscape windows (mobile landscape and short desktop landscape)
   put the credits as a second column to the right of the description
   instead of bottom-anchored. Gap between columns matches the outer left
   margin (13px). Placed after the desktop tall rule so source order wins
   at the boundary if both fire. */
@media (orientation: landscape) and (max-height: 800px) {
  #toc-credits {
    top: 85px;
    bottom: auto;
    /* outer margin (13) + description max-width (148) + gap (26 = 2 × outer margin) = 187 */
    left: calc(13px + 148px + 26px);
  }
}

/* Staged reveal — title fades in first, then loops cascade top-to-bottom
   while description + credits fade in alongside. CSS transitions with
   per-element transition-delay run on the compositor (so stagger timing
   stays smooth under HLS-decode load, per cross-browser feedback) and
   interpolate cleanly if the user clicks a loop mid-reveal. */
#toc-title,
#toc-description,
#toc-credits,
#toc-loops video.toc-loop {
  opacity: 0;
  transition: opacity 300ms ease;
}

body.toc-revealed #toc-title {
  opacity: 1;
}

body.toc-revealed #toc-description,
body.toc-revealed #toc-credits {
  opacity: 1;
  transition-duration: 500ms;
  transition-delay: 300ms;
}

body.toc-revealed #toc-loops video.toc-loop {
  opacity: 1;
  transition-delay: calc(var(--i) * 60ms + 300ms);
}

/* Departure — fade everything to black before goTo'ing into a video. */
body.toc-leaving #toc-title,
body.toc-leaving #toc-description,
body.toc-leaving #toc-credits,
body.toc-leaving #toc-loops video.toc-loop {
  opacity: 0;
  transition-duration: 500ms;
  transition-delay: 0ms;
}

@media (hover: hover) {
  #toc-loops video.toc-loop:hover {
    opacity: 0.85;
  }
}
