/* ============================================================
   VIDEO — Concept B: "Strip"
   The page is one viewport tall and never scrolls: nav on top, the stage on
   the left (player + title, month/year on the bottom row), and a strip of
   every video fixed down the right edge, top to bottom behind the nav, that
   scrolls on its own (the wheel is forwarded to it from anywhere on the page). Tweakable
   values live on .video-b and are overridden inline on <body> by tweaks.js;
   switches are attributes on <html>. Phones stay one screen too, with the strip
   as a carousel along the bottom.
   ============================================================ */

.video-b {
  --s-strip-w: 122px;         /* strip width */
  --s-strip-gap: 2px;
  --s-rest: 0.5;              /* opacity of strip pictures that aren't selected */
  --s-needle: 52vh;           /* where the needle sits */
  --s-player-w: 58%;          /* player width within the stage */
  --s-title: clamp(32px, 4.6vw, 76px);
  --s-title-track: -0.111em;  /* about -8.4px at the 76px desktop size; scales down with the title */
  --s-title-weight: 400;
  --s-title-lines: 1;         /* lines of title the layout reserves room for; longer titles overflow */
  --s-bar-bg: color-mix(in srgb, var(--primary) 22%, var(--secondary));
  --s-text: var(--text-s);
  --s-track: 0.08em;
  --s-stage-pad: 20px;        /* inner padding of the stage */
  --s-change: 800ms;          /* fade / crossfade length for the picture and the text */
  --s-cur-lift: 14px;         /* hover label: gap above the pointer */

  /* the page itself: one screen, nothing scrolls but the strip */
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.video-b .nav.top { flex: none; }

.s {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  font-size: var(--s-text);
  letter-spacing: var(--s-track);
}
.s-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--s-strip-w);
  align-items: stretch;
  height: 100%;
}
/* the phone scroller's wrappers (see Responsive); no boxes of their own on desktop */
.s-track, .s-pin { display: contents; }
.s-mark { display: none; }

/* ---- Stage: the block (player + title) centred ---- */
.s-stage {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  padding: var(--s-stage-pad) var(--margin);
  box-sizing: border-box;
}
.s-block {
  width: var(--s-player-w);
  min-width: 0;
  align-self: center;
  align-self: safe center;
  /* the title hangs off the player (absolute), and this reserves a fixed amount of room
     for it, so the player sits in the same place however many lines the title takes */
  padding-bottom: calc(var(--s-title) * (0.65 + var(--s-title-lines)));
}
.s-figwrap { position: relative; }
html[data-valign="top"] .s-block { align-self: start; }
html[data-valign="bottom"] .s-block { align-self: end; }
.s-player { width: 100%; }

/* the poster stack: one still per video, all loaded up front; .is-on shows one.
   Change = instant: a plain toggle. fade: the stack dips for --s-change.
   crossfade (default): the new still fades in on top of the old one (no dip). */
.s-posters {
  position: absolute;
  inset: 0;
  z-index: 0;                 /* keeps the crossfade's climbing z-indexes under the Play label */
  transition: opacity var(--s-change) cubic-bezier(0.2, 0.7, 0.2, 1);
}
.s-posters.is-out { opacity: 0; }
html[data-change="instant"] .s-posters { transition: none; }
.s-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
  transition: transform 420ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
.s-poster.is-on { display: block; }
html[data-change="crossfade"] .s-poster {
  display: block;
  opacity: 0;
  transition:
    opacity var(--s-change) cubic-bezier(0.2, 0.7, 0.2, 1),
    transform 420ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
html[data-change="crossfade"] .s-poster.is-on { opacity: 1; }
.s-player:hover .s-poster.is-on { transform: scale(1.03); }

/* text crossfade: the outgoing text sits on top of the new one, at the width it had,
   and fades out while the new text fades in (video-b.js) */
.s-cross { position: relative; }
.s-cross-cur { display: inline; }
.s-cross-old {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}
.s-needle .s-cross { display: inline-block; }
.s-needle .s-cross-old { right: auto; white-space: nowrap; }
.s-player.is-playing .s-posters,
.s-player.is-playing .gv-play { opacity: 0; pointer-events: none; }
/* instant mode: no easing anywhere on the stage or the strip */
html[data-change="instant"] .s-poster,
html[data-change="instant"] .s-thumb,
html[data-change="instant"] .s-thumb img,
html[data-change="instant"] .s-title { transition: none; }

/* the title bar: grey strip with a dark left edge, like a label on a cover */
.s-bar {
  position: absolute;
  top: 100%;
  left: 0;
  display: inline-flex;
  align-items: flex-start;
  gap: 0.18em;
  margin-top: 0.45em;
  max-width: 100%;
  padding: 0.02em 0.32em 0.1em 0.14em;
  border-left: 0.14em solid var(--primary);
  background: var(--s-bar-bg);
  font-size: var(--s-title);
  font-weight: var(--s-title-weight);
  line-height: 1;
  letter-spacing: var(--s-title-track);
}
html[data-bar="plain"] .s-bar { background: none; border-left: 0; padding-left: 0; }
html[data-bar="outline"] .s-bar { background: none; box-shadow: inset 0 0 0 1px var(--primary); border-left-width: 0.14em; }
.s-title {
  margin: 0;
  font: inherit;
  letter-spacing: inherit;
  text-transform: none;
  min-width: 0;
  overflow-wrap: break-word;
  text-wrap: balance;
  transition:
    opacity var(--s-change) cubic-bezier(0.2, 0.7, 0.2, 1),
    transform var(--s-change) cubic-bezier(0.2, 0.7, 0.2, 1);
}
.s-title.is-out {
  opacity: 0;
  transform: translateY(-0.06em);
}
.s-sup {
  flex: none;
  width: 0.14em;
  height: 0.14em;
  margin-top: 0.1em;
  background: currentColor;
}
/* ---- Strip (its own scroller): fixed to the right edge, the full height of
   the viewport, behind the nav (the layout's second column just keeps its room) -- */
.s-strip {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1;
  width: var(--s-strip-w);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
  gap: var(--s-strip-gap);
  padding: 0;
}
.s-strip::-webkit-scrollbar { display: none; }
.s-thumb {
  appearance: none;
  flex: none;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  margin: 0;
  border: 0;
  background: color-mix(in srgb, var(--primary) 14%, var(--secondary));
  overflow: hidden;
  cursor: pointer;
  opacity: var(--s-rest);
  transition: opacity 180ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
html[data-shape="wide"] .s-thumb { aspect-ratio: 16 / 9; }
html[data-shape="tall"] .s-thumb { aspect-ratio: 4 / 5; }
.s-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1);
  transition: transform 420ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
.s-thumb:hover,
.s-thumb:focus-visible,
.s-thumb.is-active { opacity: 1; outline: none; }
.s-thumb.is-active img { transform: scale(1.06); }
.s-thumb.is-active { box-shadow: inset 0 0 0 1px var(--primary); }

/* the hover label: the title riding just above the pointer,
   white and inverted against whatever is under it (tweak: Hover label) */
.s-cursor {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 70;
  display: none;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25em;
  pointer-events: none;
  white-space: nowrap;
  color: #fff;
  mix-blend-mode: difference;
  transform: translate(var(--s-cur-x, -9999px), var(--s-cur-y, -9999px)) translate(0, calc(-100% - var(--s-cur-lift)));
  will-change: transform;
}
.s-cursor.is-on { display: inline-flex; }
.s-cursor-title {
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
}
.s-cursor-title::before {
  content: "";
  width: 4px;
  height: 4px;
  background: currentColor;
}
html[data-hover="off"] .s-cursor { display: none !important; }

/* the needle: a square and the count, just left of the strip at the pick line */
.s-needle {
  position: fixed;
  right: calc(var(--s-strip-w) + 10px);
  top: var(--s-needle);
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  transform: translateY(-50%);
  pointer-events: none;
  white-space: nowrap;
}
.s-needle-sq {
  width: 4px;
  height: 4px;
  background: currentColor;
}
html[data-select="click"] .s-needle-sq { visibility: hidden; }

/* ---- Responsive ---------------------------------------------------------- */
/* Values here sit on .s (not body) so they beat the panel's inline values on phones.
   Phones keep the one-screen page: nav, then the stage, then the carousel and the
   needle along the bottom. Nothing visibly scrolls: .s is a vertical scroller with
   a snap point per picture, but its screen (.s-pin) is sticky, and video-b.js copies
   the scroll position across to the carousel, so an up/down swipe anywhere moves
   the carousel with the browser's own inertia and snapping. */
@media (max-width: 900px) {
  html:has(> body.video-b) { overscroll-behavior: none; }
  .video-b .nav.top { padding-bottom: 10px; }
  /* .s runs up under the (fixed, click-through) nav so a swipe there counts too */
  html.nav-shrink .video-b .nav-top-spacer { display: none; }
  .s {
    --s-player-w: 100%;
    --s-strip-w: 72px;
    --s-title: clamp(26px, 7vw, 44px);
    --s-title-lines: 2;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: none;  /* no bounce: the sticky screen would bounce with it */
    scroll-snap-type: y mandatory;
    scrollbar-width: none;
  }
  .s::-webkit-scrollbar { display: none; }
  /* the run: one screen plus the carousel's travel (--s-run, set by video-b.js) */
  .s-track {
    display: block;
    position: relative;
    height: calc(100% + var(--s-run, 0px));
  }
  .s-pin {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    height: calc(100% - var(--s-run, 0px));
    box-sizing: border-box;
  }
  html.nav-shrink .s-pin { padding-top: var(--s-nav-h, 0px); }
  /* one snap point per picture, placed by video-b.js */
  .s-mark {
    display: block;
    position: absolute;
    left: 0;
    width: 1px;
    height: 1px;
    scroll-snap-align: start;
    pointer-events: none;
  }
  .s-layout {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  /* the stage is whatever the nav and the carousel leave; the player sits at its top
     and narrows (cqh) on a screen too short to fit it at full width */
  .s-stage {
    height: auto;
    padding: 0 var(--margin);
    grid-template-rows: minmax(0, 1fr);
    container-type: size;
  }
  .s-block {
    width: min(100%, (100cqh - var(--s-title) * (0.65 + var(--s-title-lines))) * 16 / 9);
    align-self: start;
  }
  /* the strip becomes a carousel: full width, snaps a picture to the centre, and the
     needle (square + count) sits under it at the pick point; video-b.js pads the
     ends so the first and last picture can reach the centre */
  .s-strip {
    position: static;
    width: auto;
    height: auto;
    overflow-x: auto;
    overflow-y: hidden;         /* sideways only: no drifting up and down */
    overscroll-behavior-y: auto;  /* an up/down swipe on it passes on to .s */
    flex-direction: row;
    /* room either side so the first and last picture reach the centre. video-b.js sets
       the same value; having it here too means the carousel paints centred, rather
       than starting flush left and jumping across once the script runs */
    padding: 0 max(0px, calc(50% - var(--s-strip-w) / 2));
    scroll-snap-type: x mandatory;
  }
  html[data-select="click"] .s-strip { padding: 0; }
  .s-strip.is-driven { scroll-snap-type: none; }   /* while .s is driving it */
  .s-thumb { flex: 0 0 var(--s-strip-w); width: var(--s-strip-w); scroll-snap-align: center; }
  .s-needle {
    position: static;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    transform: none;
    padding: 6px 0 12px;
  }
  .s-needle-n { order: 2; }
  .s-needle-sq { order: 1; }
}
@media (hover: none) {
  .s-cursor { display: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  .s-posters, .s-poster, .s-thumb, .s-thumb img, .s-title { transition: none !important; }
  .s-thumb.is-active img { transform: none; }
}
