:root {
  --ink: #12202A; --paper: #F4F3EE; --ember: #F86102; --mist: #98CAC1;
  --line: rgba(244, 243, 238, 0.16); --lift: rgba(244, 243, 238, 0.06);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --head: "Sofia Sans Extra Condensed", "IBM Plex Sans", sans-serif;
  /* the heights of everything that is not the picture: the picture takes the rest of the window */
  --bar: 52px; --transport: 60px; --below: 100px; --pad: 16px; --trim: 25px;
}
* { box-sizing: border-box; }
html { background: var(--ink); color-scheme: dark; }
body { margin: 0; font: 400 16px/1.5 var(--sans); color: var(--paper); background: var(--ink); }
p, h2, ol { margin: 0; padding: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ember); outline-offset: 3px; }

.bar { display: flex; align-items: center; gap: 24px; height: var(--bar); padding: 0 var(--pad); border-bottom: 1px solid var(--line); }
.mark { font: 800 26px/1 var(--head); letter-spacing: 0.02em; text-transform: uppercase; white-space: nowrap; }
.eps { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 12px; }
.ep { min-width: 0; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#ep-count { font: 500 12px/1 var(--mono); color: var(--ember); margin-right: 12px; }
#ep-channel { font: 500 12px/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--mist); margin-right: 12px; }
.bar-actions { display: flex; align-items: center; gap: 16px; }

.ghost, .solid {
  border-radius: 4px; padding: 8px 16px; font: 500 14px/1.2 var(--sans); white-space: nowrap;
  transition: transform 200ms var(--ease), opacity 200ms var(--ease);
}
.ghost { background: transparent; border: 1px solid var(--line); }
.ghost:hover { border-color: var(--paper); }
.ghost[aria-pressed="true"] { border-color: var(--ember); color: var(--ember); }
.solid { background: var(--ember); color: var(--ink); border: 1px solid var(--ember); font-weight: 600; min-width: 76px; }
.solid:hover { opacity: 0.88; }
.ghost:active, .solid:active { transform: scale(0.97); }
.step { padding: 4px 12px; font: 500 22px/1 var(--sans); }
/* Flat / 3D / Styles: one joined row of buttons, the set that is playing marked */
.sets { display: flex; }
.sets[hidden] { display: none; }
.sets .ghost { border-radius: 0; padding: 8px 12px; margin-left: -1px; }
.sets .ghost:first-child { border-radius: 4px 0 0 4px; margin-left: 0; }
.sets .ghost:last-child { border-radius: 0 4px 4px 0; }
.sets .ghost[aria-pressed="true"], .sets .ghost:hover { position: relative; z-index: 1; }

.switch { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.track { width: 36px; height: 20px; border-radius: 10px; border: 1px solid var(--line); position: relative; }
.track::after {
  content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--mist); transition: transform 250ms var(--ease);
}
.switch input:checked + .track { border-color: var(--ember); }
.switch input:checked + .track::after { transform: translateX(16px); background: var(--ember); }
.switch input:focus-visible + .track { outline: 2px solid var(--ember); outline-offset: 3px; }

/* The picture is as large as the window allows: full width, or as tall as what is left under the bar. */
main {
  --rest: calc(100dvh - var(--bar) - var(--transport) - var(--below) - 13px);
  --fw: max(320px, min(100vw - 2 * var(--pad), var(--rest) * 16 / 9));
  width: var(--fw); margin: 12px auto 0;
}
main:has(.frame[data-layout="side"]) { --fw: max(320px, min(100vw - 2 * var(--pad), var(--rest) * 32 / 9 + 16px)); }
html.fill { --bar: 0px; --below: 0px; --pad: 0px; --trim: 0px; }
html.fill .bar, html.fill .below, html.fill footer { display: none; }
html.fill main { margin-top: 0; --rest: calc(100dvh - var(--transport)); }
html.fill .transport { padding: 10px 12px; }

/* ---- the frame: illustration fills it, the video rides in the corner ---- */
.frame { position: relative; aspect-ratio: 16 / 9; background: #000; border: 1px solid var(--line); overflow: hidden; }
.stagewrap, .video { position: absolute; inset: 0; }
.stagewrap { cursor: pointer; }
.video { transform-origin: 100% 0; transition: transform 500ms var(--ease); z-index: 2; background: #000; }
.video iframe { width: 100%; height: 100%; display: block; border: 0; }
.frame[data-cue="on"] .video { transform: translate(-1.6%, 2.8%) scale(0.25); outline: 4px solid var(--ink); }
.idle { display: none; }

/* a click on the picture plays or pauses, and says which */
.tap {
  position: absolute; left: 50%; top: 50%; width: 88px; height: 88px; margin: -44px 0 0 -44px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(18, 32, 42, 0.78); border: 1px solid var(--line);
  font: 600 13px/1 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: var(--paper);
  opacity: 0; pointer-events: none; z-index: 3;
}
.tap.show { animation: tap 520ms var(--ease); }
@keyframes tap { 0% { opacity: 0; transform: scale(0.86); } 25% { opacity: 1; transform: none; } 100% { opacity: 0; transform: scale(1.08); } }

/* ---- side by side: video left, illustration right ---- */
.frame[data-layout="side"] { aspect-ratio: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; background: none; border: 0; overflow: visible; }
.frame[data-layout="side"] .stagewrap, .frame[data-layout="side"] .video { position: relative; inset: auto; aspect-ratio: 16 / 9; transform: none; outline: 0; border: 1px solid var(--line); }
.frame[data-layout="side"] .stagewrap { order: 2; }
.frame[data-layout="side"] .idle {
  display: flex; flex-direction: column; justify-content: center; gap: 8px; position: absolute; inset: 0; padding: 8%;
}
.idle-k { font: 500 12px/1 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ember); }
.idle-t { font: 800 clamp(24px, 3.4vw, 44px)/1.02 var(--head); text-wrap: balance; }
.frame[data-layout="side"] #stage { position: absolute; inset: 0; }
/* On a desk the two panels are not twins: two 16:9 panels of one size leave half a 16:9 window empty. The picture is as
   tall as the window allows; the video, the sliders and the moments stand in a column beside it and fill its height. */
@media (min-width: 861px) {
  main:has(.frame[data-layout="side"]) {
    --avail: calc(100vw - 2 * var(--pad)); --col: clamp(320px, 24vw, 560px);
    --sh: max(180px, min(100dvh - var(--bar) - var(--transport) - var(--trim), (var(--avail) - 16px - var(--col)) * 9 / 16));
    --sw: calc(var(--sh) * 16 / 9); --lw: min(var(--avail) - 16px - var(--sw), var(--sw) * 0.62);
    width: calc(var(--sw) + 16px + var(--lw));
    display: grid; column-gap: 16px; grid-template-columns: var(--lw) var(--sw);
    grid-template-rows: calc(var(--lw) * 9 / 16) calc(var(--sh) - var(--lw) * 9 / 16) var(--transport);
    grid-template-areas: "video stage" "below stage" "transport transport";
  }
  .frame[data-layout="side"] { display: contents; }
  .frame[data-layout="side"] .video { grid-area: video; }
  .frame[data-layout="side"] .stagewrap { grid-area: stage; }
  main:has(.frame[data-layout="side"]) .transport { grid-area: transport; }
  main:has(.frame[data-layout="side"]) .below { grid-area: below; flex-direction: column; gap: 10px; height: auto; min-height: 0; padding: 12px 0 0; }
  main:has(.frame[data-layout="side"]) .explore { flex: 0 0 auto; max-width: none; flex-wrap: wrap; padding: 10px 12px; }
  main:has(.frame[data-layout="side"]) .explore-ctl { flex: 1; flex-wrap: wrap; }
  main:has(.frame[data-layout="side"]) .ctl { flex: 1; grid-template-columns: minmax(90px, 1fr) 8ch; }
  main:has(.frame[data-layout="side"]) .moments { flex-direction: column; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scroll-snap-type: none; }
  main:has(.frame[data-layout="side"]) .moments li { flex: 0 0 auto; }
  /* filling the screen keeps the column: the picture is already as large as it can be beside a video */
  html.fill main:has(.frame[data-layout="side"]) { margin-top: calc((100dvh - var(--sh) - var(--transport)) / 2); }
  html.fill main:has(.frame[data-layout="side"]) .below { display: flex; padding: 12px 0 0 12px; }
}
@media (prefers-reduced-motion: reduce) { .video { transition: none; } .tap.show { animation: none; } }

/* ---- transport: click or drag anywhere on the rail ---- */
.transport { display: flex; align-items: center; gap: 16px; height: var(--transport); }
.clock { font: 400 14px/1 var(--mono); color: var(--mist); white-space: nowrap; }
.rail { position: relative; flex: 1; height: 36px; background: var(--lift); border: 1px solid var(--line); cursor: pointer; touch-action: none; }
.rail-cues span { position: absolute; top: 0; bottom: 0; min-width: 3px; background: var(--ember); pointer-events: none; }
.rail-cues i { position: absolute; top: 0; height: 6px; width: 1px; background: var(--paper); opacity: 0.45; pointer-events: none; }
.rail-head { position: absolute; top: -5px; bottom: -5px; width: 3px; margin-left: -1px; background: var(--paper); left: 0; pointer-events: none; }
.rail-tip {
  position: absolute; bottom: calc(100% + 10px); transform: translateX(-50%); padding: 6px 10px; white-space: nowrap;
  background: var(--paper); color: var(--ink); font: 500 13px/1 var(--mono); border-radius: 3px; pointer-events: none; z-index: 4;
}
.rail-tip[hidden] { display: none; }
.rail input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.rail:has(input:focus-visible) { outline: 2px solid var(--ember); outline-offset: 3px; }

/* ---- a lesson (a manifest with `lesson`): no video box, Back beside Next, and a question for the class under the rail ---- */
.frame[data-lesson] .video, html.lesson .eps .step, html.lesson .switch, html.lesson #layout { display: none; }
html.lesson #next { background: var(--ember); color: var(--ink); border-color: var(--ember); font-weight: 600; min-width: 96px; }
html.lesson #back:disabled { opacity: 0.35; cursor: default; }
html.lesson main { --ask: 44px; --rest: calc(100dvh - var(--bar) - var(--transport) - var(--below) - var(--ask) - 13px); }
.ask { display: flex; align-items: center; gap: 12px; height: var(--ask); padding-bottom: 8px; font-size: 18px; line-height: 1.15; overflow: hidden; }
.ask[hidden], .ask span[hidden] { display: none; }
.ask span { font: 500 12px/1 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ember); white-space: nowrap; }
.ask b { font-weight: 500; text-wrap: balance; }
html.fill .ask, html.turn .ask { display: none; }
@media (max-width: 720px) { html.lesson main { --ask: auto; } .ask { flex-wrap: wrap; gap: 4px 12px; min-height: 44px; font-size: 16px; } }

/* ---- below the picture: sliders for a running simulation, then the moments as a strip that follows the video ---- */
.below { display: flex; align-items: stretch; gap: 16px; height: var(--below); padding-bottom: 12px; }
.explore { display: flex; align-items: center; gap: 12px; flex: 0 1 auto; max-width: 52%; padding: 0 12px; border: 1px solid var(--ember); }
.explore[hidden] { display: none; }
.explore-k { font: 500 12px/1 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ember); white-space: nowrap; }
.explore-ctl { display: flex; gap: 16px; min-width: 0; }
.ctl { display: grid; grid-template-columns: minmax(90px, 200px) 8ch; grid-template-rows: auto auto; align-items: center; column-gap: 10px; font-size: 13px; line-height: 1.2; }
.ctl input { grid-column: 1; grid-row: 2; width: 100%; }
.ctl output { grid-column: 2; grid-row: 2; font: 400 13px/1 var(--mono); color: var(--mist); }
input[type="range"] { accent-color: var(--ember); }

.moments {
  flex: 1; min-width: 0; list-style: none; display: flex; gap: 8px; overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x proximity; scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.moments li { flex: 0 0 clamp(190px, 21vw, 300px); scroll-snap-align: center; }
.moment {
  position: relative; display: block; width: 100%; height: 100%; text-align: left; padding: 6px 12px; overflow: hidden;
  background: transparent; border: 1px solid var(--line); border-radius: 0; opacity: 0.62;
  transition: opacity 300ms var(--ease), border-color 300ms var(--ease), background 300ms var(--ease);
}
.moment:hover { opacity: 1; border-color: var(--paper); }
.moment[data-up="true"] { opacity: 1; }
.moment[aria-current="true"] { opacity: 1; border-color: var(--ember); background: var(--lift); }
.moment time { display: block; font: 500 12px/1 var(--mono); color: var(--ember); }
.moment b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font: 800 21px/1.04 var(--head); letter-spacing: 0.01em; margin-top: 6px; }
.moment i { position: absolute; left: 0; bottom: 0; height: 3px; width: calc(var(--p, 0) * 100%); background: var(--ember); }

footer { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 16px var(--pad); border-top: 1px solid var(--line); font-size: 13px; }
footer a { color: var(--mist); text-decoration: none; }
footer a:hover { color: var(--paper); text-decoration: underline; }
.credit { color: var(--mist); flex: 1 1 320px; }
.keys { font: 400 12px/1.6 var(--mono); color: var(--mist); }

/* narrow: the two panels stack, video first, the picture under it */
@media (max-width: 860px) {
  .frame[data-layout="side"] { grid-template-columns: 1fr; }
  main:has(.frame[data-layout="side"]) { --fw: calc(100vw - 2 * var(--pad)); }
}
/* a phone held upright: two short header rows, video, picture, one row of controls, the rail, then the strip */
@media (max-width: 720px) {
  :root { --pad: 12px; }
  .bar { flex-wrap: wrap; height: auto; gap: 8px 12px; padding: 8px var(--pad); }
  .mark { flex: 1; font-size: 22px; }
  #layout { display: none; }                        /* a corner video would be thumbnail-size here */
  .solid { min-width: 64px; }
  .eps { order: 3; flex-basis: 100%; justify-content: space-between; gap: 8px; }
  .ghost, .solid { min-height: 44px; }
  .step { min-width: 44px; }
  main { --fw: calc(100vw - 2 * var(--pad)); margin-top: 10px; }
  .frame[data-layout="side"] { gap: 10px; }
  .transport { flex-wrap: wrap; height: auto; gap: 10px 12px; padding: 10px 0 12px; }
  #next { margin-left: auto; }
  .rail { order: 5; flex-basis: 100%; height: 44px; }
  .below { flex-direction: column; height: auto; }
  .explore { max-width: none; padding: 10px 12px; flex-wrap: wrap; }
  .explore-ctl { flex-wrap: wrap; }
  .moments { min-height: 84px; }
  .moments li { flex-basis: 62vw; }
  .keys { display: none; }
}
/* a phone on its side: the picture takes the whole screen, as it does on a desk; the strip waits below the fold */
@media (max-height: 520px) and (orientation: landscape) {
  :root { --bar: 0px; --transport: 48px; --below: 0px; --pad: 0px; }
  .bar, .keys { display: none; }
  main { margin-top: 0; width: 100%; --rest: calc(100dvh - var(--transport)); --fw: max(320px, min(100vw, var(--rest) * 16 / 9)); }
  .frame { width: var(--fw); margin: 0 auto; }      /* the picture is as tall as the screen; the rail runs the full width under it */
  .ghost, .solid { min-height: 36px; }
  .transport { flex-wrap: nowrap; height: var(--transport); padding: 0 12px; gap: 12px; }
  .rail { order: 0; flex: 1 1 0; height: 32px; }
  #next { margin-left: 0; }
  html.no-fs #fill { display: none; }               /* nothing left to hide where a page cannot go fullscreen */
  .below { height: 104px; padding: 12px; }
}
/* the same for a phone held upright with rotation locked: "Bigger" turns the player a quarter turn */
html.turn { overflow: hidden; --transport: 48px; }
html.turn .bar, html.turn .below, html.turn footer { display: none; }
html.turn main {
  --rest: calc(100vw - var(--transport)); --fw: min(100dvh, var(--rest) * 16 / 9);
  position: fixed; z-index: 10; left: 100vw; top: calc((100dvh - var(--fw)) / 2); margin: 0;
  transform-origin: 0 0; transform: rotate(90deg); background: var(--ink);
}
html.turn .ghost, html.turn .solid { min-height: 36px; }
html.turn .transport { flex-wrap: nowrap; height: var(--transport); padding: 0; gap: 12px; }
html.turn .rail { order: 0; flex: 1 1 0; height: 32px; }
html.turn #next { margin-left: 0; }

/* ---------- the first-visit walkthrough of the Flat / 3D / Styles switch (player/tour.js) ---------- */
/* the dim has holes cut in it (clip-path): the switch, and in the steps the picture; the block lets only the switch be pressed */
html.touring { overflow: hidden; }
.tour { position: fixed; inset: 0; z-index: 100; }
.tour-dim, .tour-block { position: absolute; inset: 0; }
.tour-dim { background: rgba(6, 12, 16, 0.8); pointer-events: none; animation: tour-in 260ms var(--ease) both; }
.tour-ring { position: absolute; border: 2px solid var(--ember); border-radius: 8px; pointer-events: none; animation: tour-pulse 1.8s ease-out infinite; }
.tour-ring[hidden], .tour-tip[hidden] { display: none; }
.tour-card { position: absolute; background: var(--paper); color: var(--ink); border-radius: 6px; padding: 16px 18px 14px; box-shadow: 0 14px 44px rgba(0, 0, 0, 0.5); animation: tour-card 320ms var(--ease) both; }
.tour-tip { position: absolute; top: -6px; width: 14px; height: 14px; background: var(--paper); transform: rotate(45deg); border-radius: 2px; }
.tour-k { font: 500 12px/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: rgba(18, 32, 42, 0.66); }
.tour-card h2 { margin: 8px 0 6px; font: 800 30px/1 var(--head); letter-spacing: 0.02em; text-transform: uppercase; text-wrap: balance; }
.tour-b { font-size: 15px; line-height: 1.45; }
.tour-n { margin-top: 6px; font-size: 13px; line-height: 1.4; color: rgba(18, 32, 42, 0.72); }
.tour-go { display: flex; align-items: center; gap: 6px 16px; flex-wrap: wrap; margin-top: 14px; }
.tour-card .solid { background: var(--ember); color: var(--ink); border-color: var(--ember); font-weight: 600; }
.tour-card .solid:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.tour-card :focus-visible { outline-color: var(--ink); }
.tour-skip, .tour-link { background: none; border: 0; padding: 8px 6px; min-height: 36px; font: 500 14px/1 var(--sans); color: rgba(18, 32, 42, 0.72); text-decoration: underline; text-underline-offset: 3px; }
.tour-skip:hover, .tour-link:hover { color: var(--ink); }
.tour-skip[hidden], .tour-link[hidden] { display: none; }
@keyframes tour-in { from { opacity: 0; } }
@keyframes tour-card { from { opacity: 0; transform: translateY(-6px); } }
@keyframes tour-pulse { from { box-shadow: 0 0 0 0 rgba(248, 97, 2, 0.6); } to { box-shadow: 0 0 0 14px rgba(248, 97, 2, 0); } }
@media (max-width: 720px) { .tour-skip, .tour-link { min-height: 44px; } .tour-card h2 { font-size: 26px; } }
@media (prefers-reduced-motion: reduce) { .tour-dim, .tour-card, .tour-ring { animation: none; } }
