/* scenes/story.css: "One run", the scroll story (agent S).
   Base = the stacked layout (no JS, phones, reduced motion, fallbacks): six cards, each a
   rendered still of its beat. The pinned layout (≥ 800 px, JS, motion allowed) turns the rig
   into ~6 screens of scroll with one sticky full-bleed screen; story.js scrubs the scene. */

/* ------------------------------------------------------------------ shared + stacked (base) */
.story { position: relative; }
.story-rig { position: relative; }
.story-sticky {
  max-width: var(--wrap);
  margin: 0 auto;
  padding: var(--space) var(--gutter) 0;
}
/* S2: the section head lives inside the rig. Stacked, it heads the cards as any section head;
   pinned, it sits in the first frame of the scene (no empty intro screen before the story). */
.story-head-wrap .section-head { margin-bottom: clamp(2rem, 4vw, 3.4rem); }
.story-screen, .story-rail { display: none; }

.story .story-beats { display: grid; gap: clamp(3.2rem, 7vw, 6.5rem); counter-reset: none; }
.story .story-beat {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: clamp(1.6rem, 4vw, 4.5rem);
  align-items: center;
  min-height: 0;
  padding: 0;
  border: 0;
}
.story .story-beat::before { content: none; }
.story .story-beat:nth-child(even) .story-shot { order: 2; }
.story-shot { aspect-ratio: 16 / 10; border: 1px solid var(--hair); margin: 0; }
.story-shot::after {                              /* hairline corner ticks, as .scene--framed */
  content: ""; position: absolute; inset: -1px; pointer-events: none; z-index: 3; --tk: 12px;
  background:
    linear-gradient(var(--tick), var(--tick)) left top / var(--tk) 1px no-repeat,
    linear-gradient(var(--tick), var(--tick)) left top / 1px var(--tk) no-repeat,
    linear-gradient(var(--tick), var(--tick)) right top / var(--tk) 1px no-repeat,
    linear-gradient(var(--tick), var(--tick)) right top / 1px var(--tk) no-repeat,
    linear-gradient(var(--tick), var(--tick)) left bottom / var(--tk) 1px no-repeat,
    linear-gradient(var(--tick), var(--tick)) left bottom / 1px var(--tk) no-repeat,
    linear-gradient(var(--tick), var(--tick)) right bottom / var(--tk) 1px no-repeat,
    linear-gradient(var(--tick), var(--tick)) right bottom / 1px var(--tk) no-repeat;
}
.story-shot > .scene-poster { filter: none; }
.story-canvas { position: absolute; inset: 0; z-index: 0; transition: opacity 260ms ease; }
.story-shot > .story-canvas { z-index: 2; }       /* over the still once the loop runs */
.story-shot[data-state="live"] > .scene-poster { opacity: 0; }

.story .story-step { color: var(--amber); display: flex; align-items: center; gap: 0; }
.story-step .sep { margin: 0 0.55em; }
.story-num { font-weight: 700; }
.story .story-beat h3 { margin-top: 0.9rem; font-size: clamp(2rem, 4.2vw, 3.4rem); line-height: 0.94; }
.story .story-beat .story-copy > p:not(.hud) {
  margin-top: 1.1rem; max-width: 28rem; color: var(--ink-2); font-size: clamp(1.04rem, 1.3vw, 1.14rem); line-height: 1.6;
}

@media (max-width: 799px) {
  .story .story-beats { gap: 3.4rem; }
  .story .story-beat { grid-template-columns: 1fr; gap: 1.3rem; }
  .story .story-beat:nth-child(even) .story-shot { order: 0; }
  .story-shot { aspect-ratio: 4 / 3; }
}

/* ------------------------------------------------------------------ pinned */
@media (min-width: 800px) and (prefers-reduced-motion: no-preference) {
  .js .story:not(.story--static) .story-rig { height: 640vh; margin-top: 0; }
  .js .story:not(.story--static) .story-sticky {
    position: sticky; top: 0;
    height: 100vh; height: 100dvh;
    max-width: none; margin: 0; padding: 0;
    overflow: hidden;
  }
  .js .story:not(.story--static) .story-screen {
    display: block; position: absolute; inset: 0;
    background: none;
    border: 0;
  }
  .js .story:not(.story--static) .story-screen::before { display: none; }   /* no loading scan line full-bleed */
  /* Q: the board and its fog end where the sticky screen ends; feather the canvas at the top and
     bottom so the pinned scene never shows a hard edge as it scrolls in and out. */
  .js .story:not(.story--static) .story-screen > .story-canvas {
    -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 9%, #000 91%, transparent 100%);
    mask-image: linear-gradient(180deg, transparent 0, #000 9%, #000 91%, transparent 100%);
  }

  /* S2: the section head in the first pinned frame, top of the copy column; it steps aside
     once the story moves past beat 1 (the beat copy then has the column to itself) */
  .js .story:not(.story--static) .story-head-wrap {
    position: absolute; z-index: 4; pointer-events: none;
    left: max(var(--gutter), calc((100vw - 1560px) / 2 + var(--gutter)));
    top: calc(var(--head-h) + clamp(1.4rem, 5vh, 3.2rem));
    width: min(34vw, 32rem);
    transition: opacity 600ms ease, transform 900ms var(--ease-out);
  }
  .js .story:not(.story--static) .story-head-wrap .section-head { margin: 0; }
  .js .story:not(.story--static) .story-head-wrap h2 { font-size: clamp(2.6rem, 5vw, 4.4rem); line-height: 0.92; text-shadow: 0 2px 30px rgba(var(--void-rgb), 0.85); }
  .js .story:not(.story--static) .story-head-wrap .section-lede { font-size: clamp(0.98rem, 1.15vw, 1.08rem); max-width: 27rem; margin-top: 0.9rem; text-shadow: 0 1px 16px rgba(var(--void-rgb), 0.95); }
  .js .story:not(.story--static)[data-beat]:not([data-beat="1"]) .story-head-wrap { opacity: 0; transform: translateY(-24px); }
  /* beat 1's copy sits lower, under the head */
  .js .story:not(.story--static) .story-beat:first-child { top: auto; bottom: clamp(5.5rem, 16vh, 9.5rem); transform: none; }
  .js .story:not(.story--static) .story-beat:first-child h3 { font-size: clamp(2rem, 3.4vw, 3.2rem); }

  /* the copy column over the scene */
  .js .story:not(.story--static) .story-scrim {
    position: absolute; inset: 0; z-index: 2; pointer-events: none;
    /* Q: fade the scrim in at the screen's top and bottom edges, so the rig never shows a hard
       dark band while it scrolls in and out of the pin (the top 10% sits under the header). */
    -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 10%, #000 90%, transparent 100%);
    mask-image: linear-gradient(180deg, transparent 0, #000 10%, #000 90%, transparent 100%);
    background:
      linear-gradient(90deg, rgba(var(--void-rgb), 0.82) 0%, rgba(var(--void-rgb), 0.5) 22%, rgba(var(--void-rgb), 0) 42%),
      linear-gradient(180deg, rgba(var(--void-rgb), 0.55) 0%, rgba(var(--void-rgb), 0) 16%, rgba(var(--void-rgb), 0) 80%, rgba(var(--void-rgb), 0.6) 100%);
  }
  .js .story:not(.story--static) .story-beats {
    position: absolute; z-index: 4;
    left: max(var(--gutter), calc((100vw - 1560px) / 2 + var(--gutter)));
    top: 0; bottom: 0;
    width: min(31vw, 30rem);
    display: block;
    pointer-events: none;
  }
  .js .story:not(.story--static) .story-beat {
    position: absolute; left: 0; right: 0; top: 52%;
    display: block;
    transform: translateY(-50%);
  }
  .js .story:not(.story--static) .story-shot { display: none; }
  .js .story:not(.story--static) .story-copy > * {
    opacity: 0;
    transform: translateY(26px);
    transition: opacity 500ms ease, transform 900ms var(--ease-out);
  }
  .js .story:not(.story--static) .story-beat.is-past .story-copy > * { transform: translateY(-22px); }
  .js .story:not(.story--static) .story-beat.is-active .story-copy > * { opacity: 1; transform: none; transition: opacity 700ms ease, transform 1000ms var(--ease-out); }
  .js .story:not(.story--static) .story-beat.is-active .story-copy > :nth-child(2) { transition-delay: 70ms; }
  .js .story:not(.story--static) .story-beat.is-active .story-copy > :nth-child(3) { transition-delay: 140ms; }
  .js .story:not(.story--static) .story-beat h3 { font-size: clamp(2.6rem, 4.6vw, 4.6rem); text-shadow: 0 2px 30px rgba(var(--void-rgb), 0.85); }
  .js .story:not(.story--static) .story-copy > p:not(.hud) { text-shadow: 0 1px 16px rgba(var(--void-rgb), 0.95); color: rgba(var(--ink-rgb), 0.82); }
  /* until the scene is up (and when JS never arms the copy), show the first beat */
  .js .story:not(.story--static):not([data-beat]) .story-beat:first-child .story-copy > * { opacity: 1; transform: none; }

  /* big ghost index behind the copy */
  .js .story:not(.story--static) .story-ghost {
    position: absolute; z-index: 1; pointer-events: none;
    left: max(calc(var(--gutter) - 1.2vw), calc((100vw - 1560px) / 2 + var(--gutter) - 1.2vw));
    top: 50%; transform: translateY(-58%);
    font-family: var(--font-display); font-weight: 700; line-height: 0.8;
    font-size: min(46vh, 30vw); letter-spacing: -0.02em;
    color: transparent;
    -webkit-text-stroke: 1px rgba(var(--star-rgb), 0.11);
  }
  .js .story:not(.story--static) .story-ghost span {
    position: absolute; left: 0; top: 0;
    opacity: 0; transform: translateY(0.08em);
    transition: opacity 700ms ease, transform 1200ms var(--ease-out);
  }
  .story[data-beat="1"] .story-ghost span:nth-child(1), .story[data-beat="2"] .story-ghost span:nth-child(2),
  .story[data-beat="3"] .story-ghost span:nth-child(3), .story[data-beat="4"] .story-ghost span:nth-child(4),
  .story[data-beat="5"] .story-ghost span:nth-child(5), .story[data-beat="6"] .story-ghost span:nth-child(6) {
    opacity: 1; transform: none;
  }

  /* corner brackets on the screen */
  .js .story:not(.story--static) .story-frame { position: absolute; z-index: 3; pointer-events: none; inset: calc(var(--head-h) + 0.75rem) var(--gutter) 1.4rem; }
  .story-frame span { position: absolute; width: 20px; height: 20px; border: 0 solid var(--tick); }
  .story-frame span:nth-child(1) { left: 0; top: 0; border-left-width: 1px; border-top-width: 1px; }
  .story-frame span:nth-child(2) { right: 0; top: 0; border-right-width: 1px; border-top-width: 1px; }
  .story-frame span:nth-child(3) { left: 0; bottom: 0; border-left-width: 1px; border-bottom-width: 1px; }
  .story-frame span:nth-child(4) { right: 0; bottom: 0; border-right-width: 1px; border-bottom-width: 1px; }

  /* HUD readout, top right */
  .js .story:not(.story--static) .story-readout {
    position: absolute; z-index: 3;
    top: calc(var(--head-h) + 2rem);
    right: calc(var(--gutter) + 2rem);
    display: flex; gap: clamp(1.6rem, 3vw, 3rem);
    opacity: 0; transition: opacity 800ms ease;
  }
  .story--live .story-readout { opacity: 1 !important; }
  .story-readout > div { display: flex; flex-direction: column; align-items: flex-end; gap: 0.35rem; }
  .story-readout dt { font-size: 0.64rem; color: rgba(var(--star-rgb), 0.6); }
  .story-readout dd {
    display: flex; align-items: baseline; gap: 0.6rem;
    font-family: var(--font-display); font-weight: 700; font-size: 2.1rem; line-height: 1; letter-spacing: 0.02em;
    color: var(--ink); font-variant-numeric: tabular-nums;
  }
  .story-readout em {
    font-style: normal; font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.16em;
    color: var(--magenta); padding: 0.25rem 0.45rem; border: 1px solid rgba(var(--monster-rgb), 0.6);
    text-shadow: 0 0 10px rgba(var(--monster-rgb), 0.7);
  }
  .story--endless .story-readout > div:first-child dd > span { color: var(--magenta); text-shadow: 0 0 22px rgba(var(--monster-rgb), 0.55); }

  /* the rail: six segments along the bottom, each filling as its beat plays */
  .js .story:not(.story--static) .story-rail {
    display: block; position: absolute; z-index: 5;
    left: calc(var(--gutter) + 2rem); right: calc(var(--gutter) + 2rem); bottom: 2.6rem;
  }
  .story-rail ol { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.6rem; }
  .story-rail li { --i: 0; }
  .story-rail li:nth-child(2) { --i: 1; } .story-rail li:nth-child(3) { --i: 2; } .story-rail li:nth-child(4) { --i: 3; }
  .story-rail li:nth-child(5) { --i: 4; } .story-rail li:nth-child(6) { --i: 5; }
  .story-rail a {
    position: relative; display: flex; align-items: baseline; gap: 0.6rem;
    padding: 0.85rem 0 0.2rem;
    text-decoration: none; color: rgba(var(--ink-rgb), 0.5);
    font-size: 0.74rem; letter-spacing: 0.12em; text-transform: uppercase;
    transition: color var(--t-micro) ease;
  }
  .story-rail a::before, .story-rail a::after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px; }
  .story-rail a::before { background: rgba(var(--star-rgb), 0.2); }
  .story-rail a::after {
    background: var(--amber); box-shadow: 0 0 10px rgba(var(--machine-rgb), 0.8);
    transform-origin: left center;
    transform: scaleX(clamp(0, calc(var(--t, 0) - var(--i)), 1));
  }
  .story-rail a .hud { font-size: 0.64rem; color: rgba(var(--star-rgb), 0.5); }
  .story-rail b { font-weight: 600; }
  .story-rail a:hover, .story-rail a[aria-current] { color: var(--ink); }
  .story-rail a[aria-current] .hud { color: var(--amber); }
}

/* ------------------------------------------------------------------ narrower desktops */
@media (min-width: 800px) and (max-width: 1100px) and (prefers-reduced-motion: no-preference) {
  .js .story:not(.story--static) .story-beats { width: 38vw; }
  .js .story:not(.story--static) .story-readout { gap: 1.4rem; }
  .js .story:not(.story--static) .story-readout dd { font-size: 1.6rem; }
  .story-rail b { display: none; }
}
