/* ════════════════════════════════════════════════════════════════════
   THE REEL ON THE PAGE.

   The home page opens as a broadcast: a 16:9 stage pinned inside a tall
   track while the page scrolls through it, then the site follows. The
   whole page is one timeline, driven by reel.js; the transport bar at the
   bottom and the chapter rail on the left belong to that timeline.

   The stage is sized in `--u`, one hundredth of its width, so the reel is
   the same picture on a phone, on a desktop and in the 1920×1080 MP4 the
   renderer captures (it opens the page with ?render=1, which hides
   everything but the stage).
   ════════════════════════════════════════════════════════════════════ */

:root {
  --r-paper: #EFEAE0;
  --r-ink:   #0B0D14;
  --r-blue:  #7C88FF;
  --r-lime:  #C8FF3D;
  --tpH: 52px;
  --hudH: 64px;
}
body { padding-bottom: var(--tpH); }
/* every in-page link is a seek on the timeline, so the browser's own smooth
   scroll would only fight the playhead */
html { scroll-behavior: auto !important; }
.rmono { font-family: var(--font-m); font-weight: 500; letter-spacing: .06em; text-transform: uppercase; }
.rdefs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ── The pinned stage ──────────────────────────────────────────────── */
.reel { position: relative; }
.reel__track { position: relative; height: 200vh; }
.reel__sticky {
  position: sticky; top: var(--hudH);
  height: calc(100vh - var(--hudH) - var(--tpH));
  display: grid; place-items: center;
  background: #07080C;
  overflow: hidden;
}
/* Landscape: the picture covers the space between header and transport,
   giving up a sliver top and bottom, so it is the page, not a box in it.
   Portrait: it fits the width instead, so nothing that matters is cropped. */
.stage {
  position: relative;
  width: max(100%, calc((100vh - var(--hudH) - var(--tpH)) * 16 / 9));
  aspect-ratio: 16 / 9;
  --u: calc(max(100vw, (100vh - var(--hudH) - var(--tpH)) * 16 / 9) / 100);
  /* how much of the picture is hidden top and bottom when it covers */
  --crop: max(0px, calc((100vw * 9 / 16 - (100vh - var(--hudH) - var(--tpH))) / 2));
  flex: 0 0 auto;
  overflow: hidden;
  background: var(--r-ink);
  color: var(--r-paper);
  --fg: var(--r-paper);
  cursor: pointer;
}
.stage[data-bg='paper'] { --fg: var(--r-ink); }
.stage .fx, .stage .top { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage .top { pointer-events: none; z-index: 3; }
.rscan {
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, .09) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply; opacity: .8;
}
.rvig { position: absolute; inset: 0; z-index: 4; pointer-events: none; background: radial-gradient(ellipse at center, transparent 58%, rgba(0, 0, 0, .34) 100%); }

.rhud { position: absolute; inset: 0; z-index: 5; pointer-events: none; color: var(--fg); font-size: calc(var(--u) * 1.05); letter-spacing: .1em; }
.rhud__c { position: absolute; width: calc(var(--u) * 1.6); height: calc(var(--u) * 1.6); border: 1px solid currentColor; opacity: .7; }
.rhud__c--tl { left: calc(var(--u) * 1.3); top: calc(var(--u) * 1.3 + var(--crop)); border-right: 0; border-bottom: 0; }
.rhud__c--tr { right: calc(var(--u) * 1.3); top: calc(var(--u) * 1.3 + var(--crop)); border-left: 0; border-bottom: 0; }
.rhud__c--bl { left: calc(var(--u) * 1.3); bottom: calc(var(--u) * 1.3 + var(--crop)); border-right: 0; border-top: 0; }
.rhud__c--br { right: calc(var(--u) * 1.3); bottom: calc(var(--u) * 1.3 + var(--crop)); border-left: 0; border-top: 0; }
.rhud__tl, .rhud__tr, .rhud__bl, .rhud__br { position: absolute; white-space: nowrap; }
.rhud__tl { left: calc(var(--u) * 3.2); top: calc(var(--u) * 2.1 + var(--crop)); }
.rhud__tr { right: calc(var(--u) * 3.2); top: calc(var(--u) * 2.1 + var(--crop)); }
.rhud__bl { left: calc(var(--u) * 3.2); bottom: calc(var(--u) * 2.1 + var(--crop)); font-variant-numeric: tabular-nums; }
.rhud__br { right: calc(var(--u) * 3.2); bottom: calc(var(--u) * 2.1 + var(--crop)); }
.rhud__tr b { font-weight: 500; letter-spacing: -.02em; }

/* ── The transport ─────────────────────────────────────────────────── */
.transport {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 120;
  height: var(--tpH);
  display: flex; align-items: center; gap: 14px;
  padding: 0 max(16px, calc((100vw - var(--wrap)) / 2));
  background: rgba(7, 8, 12, .88);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid rgba(239, 234, 224, .12);
  color: var(--r-paper);
  font-size: 11px;
}
.transport__btn {
  appearance: none; cursor: pointer;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid rgba(239, 234, 224, .35);
  background: transparent; color: var(--r-paper);
  font: inherit; letter-spacing: .08em; text-transform: uppercase;
  transition: background-color .2s, color .2s, border-color .2s;
  white-space: nowrap;
}
.transport__btn:hover { background: var(--r-paper); color: var(--r-ink); border-color: var(--r-paper); }
.transport__btn:active { transform: scale(.96); transition: none; }
.transport__btn--play { background: var(--r-blue); border-color: var(--r-blue); color: var(--r-ink); min-width: 78px; text-align: center; }
.transport__btn--play:hover { background: var(--r-paper); border-color: var(--r-paper); }
#muteBtn.is-off { border-color: var(--r-lime); color: var(--r-lime); }
#muteBtn.is-pulse { animation: rpulse 1.4s ease-in-out infinite; }
@keyframes rpulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(200, 255, 61, .55); } 60% { box-shadow: 0 0 0 9px rgba(200, 255, 61, 0); } }
.transport__tc { font-variant-numeric: tabular-nums; white-space: nowrap; opacity: .85; }
.transport__wave { width: 180px; height: 28px; flex: 0 0 auto; }
.transport__label {
  appearance: none; cursor: pointer; border: 0; background: transparent; padding: 6px 8px; margin: 0 -8px;
  font: inherit; letter-spacing: inherit; text-transform: inherit; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto; min-width: 0; color: var(--r-lime);
  border-radius: 6px;
}
.transport__label::after { content: ' ▾'; opacity: .6; }
.transport__label:hover { background: rgba(239, 234, 224, .08); }
.transport__prog {
  position: relative; flex: 0 0 160px; height: 18px; cursor: pointer; touch-action: none;
  background: linear-gradient(rgba(239, 234, 224, .18), rgba(239, 234, 224, .18)) center / 100% 3px no-repeat;
}
.transport__prog i { position: absolute; left: 0; right: 0; top: 50%; height: 3px; margin-top: -1.5px; background: var(--r-blue); transform-origin: left; transform: scaleX(0); }
.transport__prog:hover i, .transport__prog:active i { height: 5px; margin-top: -2.5px; }
.transport__ticks { position: absolute; inset: 0; pointer-events: none; }
.transport__ticks i { position: absolute; top: 50%; width: 1px; height: 7px; margin-top: -3.5px; background: rgba(239, 234, 224, .45); transform: none; }
.transport__prog:focus-visible { outline: 2px solid var(--r-lime); outline-offset: 2px; }
.transport__pct { font-variant-numeric: tabular-nums; opacity: .85; }
.transport__btn--skip { opacity: .8; }
html[data-playing] .transport__btn--play { background: transparent; color: var(--r-paper); border-color: rgba(239, 234, 224, .35); }
@media (max-width: 900px) {
  .transport { gap: 10px; font-size: 10px; }
  .transport__wave, .transport__pct { display: none; }
  .transport__prog { flex: 1 1 auto; }
  .transport__label { flex: 0 1 auto; max-width: 34vw; }
}
@media (max-width: 560px) {
  .transport { gap: 8px; padding: 0 12px; }
  .transport__tc { display: none; }
  .transport__btn { padding: 6px 9px; font-size: 9.5px; }
  .transport__btn--play { min-width: 62px; }
  .transport__btn--skip { display: none; }
  .transport__label { max-width: 30vw; padding: 6px 4px; margin: 0; }
}

/* ── The chapter rail ──────────────────────────────────────────────── */
.rail {
  position: fixed; left: 14px; top: 50%; z-index: 110;
  transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 2px;
  font-size: 9.5px; letter-spacing: .08em;
  mix-blend-mode: difference; color: #fff;
  opacity: .45; transition: opacity .25s;
}
.rail:hover { opacity: 1; }
.rail button {
  appearance: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  padding: 2px 4px; border: 0; background: transparent; color: inherit;
  font: inherit; letter-spacing: inherit; text-transform: uppercase;
  opacity: .5; transition: opacity .2s;
}
.rail button:hover, .rail button.is-on { opacity: 1; }
.rail button i { width: 14px; height: 1px; background: currentColor; transition: width .2s; }
.rail button.is-on i { width: 26px; }
.rail button span { max-width: 0; overflow: hidden; white-space: nowrap; transition: max-width .3s; }
.rail:hover button span, .rail button.is-on span { max-width: 160px; }
.rail button b { font-weight: 500; opacity: .7; }
@media (max-width: 1180px) { .rail { display: none; } }

/* ── The chapter menu ──────────────────────────────────────────────── */
.chapters {
  position: fixed; left: 50%; bottom: calc(var(--tpH) + 10px); z-index: 121;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 24px)); max-height: min(60vh, 520px); overflow: auto;
  padding: 12px; border-radius: 10px;
  background: rgba(7, 8, 12, .96); color: var(--r-paper);
  border: 1px solid rgba(239, 234, 224, .16);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
  font-size: 10.5px;
  animation: rtoast .25s var(--ease) both;
}
.chapters[hidden] { display: none; }
.chapters__head { margin: 0 0 8px 6px; color: var(--r-lime); }
.chapters__list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; }
.chapters__list button {
  appearance: none; cursor: pointer; border: 0; border-radius: 6px; padding: 8px 8px;
  background: transparent; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; text-align: left;
  display: flex; align-items: center; gap: 8px;
}
.chapters__list button b { font-weight: 500; opacity: .6; }
.chapters__list button i { margin-left: auto; font-style: normal; font-size: 8.5px; opacity: .45; }
.chapters__list button:hover, .chapters__list button.is-on { background: rgba(239, 234, 224, .1); }
.chapters__list button.is-on { color: var(--r-lime); }
@media (max-width: 560px) { .chapters__list { grid-template-columns: 1fr; } }

/* ── Before the picture: a placeholder, not a blank ────────────────── */
.stage__acquiring {
  position: absolute; left: 50%; top: 50%; z-index: 6; transform: translate(-50%, -50%);
  margin: 0; font-size: calc(var(--u) * 1.2); color: var(--r-paper); opacity: .7;
  animation: racq 1.1s steps(2) infinite;
}
@keyframes racq { 50% { opacity: .25; } }
html[data-ready] .stage__acquiring, html[data-render] .stage__acquiring { display: none; }

/* ── The toast ─────────────────────────────────────────────────────── */
.rtoast {
  position: fixed; left: 50%; bottom: calc(var(--tpH) + 16px); z-index: 121;
  transform: translateX(-50%);
  padding: 9px 14px; border-radius: 999px;
  background: rgba(7, 8, 12, .9); color: var(--r-paper);
  border: 1px solid rgba(239, 234, 224, .18);
  font-size: 10.5px; white-space: nowrap;
  max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis;
  animation: rtoast .5s var(--ease) both;
}
.rtoast[hidden] { display: none; }
@keyframes rtoast { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ── Render mode: the renderer wants only the stage, full frame ───── */
html[data-render] .hud, html[data-render] .transport, html[data-render] .rail, html[data-render] .rtoast,
html[data-render] .menu, html[data-render] .player, html[data-render] .toast, html[data-render] .skip,
html[data-render] main > :not(#reel), html[data-render] body::after { display: none !important; }
html[data-render] body { padding: 0; margin: 0; overflow: hidden; background: #000; }
html[data-render] .reel__track { height: 100vh; }
html[data-render] .reel__sticky { position: fixed; inset: 0; height: 100vh; background: #000; }
html[data-render] .stage { width: 100vw; height: 100vh; --u: 1vw; --crop: 0px; cursor: none; }

/* ── Portrait: the picture fits the width, and the programme fills the rest ── */
.reel__programme { display: none; }
@media (orientation: portrait) {
  .reel__sticky { display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; }
  .stage {
    width: min(100%, calc((100vh - var(--hudH) - var(--tpH)) * 16 / 9));
    --u: calc(min(100vw, (100vh - var(--hudH) - var(--tpH)) * 16 / 9) / 100);
    --crop: 0px;
    margin: 0 auto;
  }
  .reel__programme {
    display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0;
    padding: 14px 16px 10px; color: var(--r-paper); font-size: 10px;
    background: linear-gradient(180deg, rgba(239, 234, 224, .04), transparent 40%);
    border-top: 1px solid rgba(239, 234, 224, .1);
  }
  .reel__programme-head { margin: 0 0 8px 4px; color: var(--r-lime); font-size: 9.5px; opacity: .9; }
  .reel__programme-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px 8px; overflow: auto; min-height: 0; }
  .reel__programme-list button {
    appearance: none; cursor: pointer; border: 0; border-radius: 5px; padding: 6px 4px;
    background: transparent; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; text-align: left;
    display: flex; align-items: center; gap: 7px; opacity: .6; white-space: nowrap; overflow: hidden;
  }
  .reel__programme-list button b { font-weight: 500; opacity: .6; }
  .reel__programme-list button i { margin-left: auto; font-style: normal; font-size: 8px; opacity: .5; }
  .reel__programme-list button.is-on { opacity: 1; color: var(--r-lime); background: rgba(239, 234, 224, .08); }
  .reel__programme-list button:active { background: rgba(239, 234, 224, .16); }
  html[data-render] .reel__programme { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .rscan { display: none; }
  #muteBtn.is-pulse { animation: none; }
}
