/* CODR landing — Story scaffold (L8): step rail 01–08 + eight stacked scenes in two groups.
   Requires tokens/base/primitives/navbar. Scene visuals are filled in by L9.1–L9.8.
   No scroll trapping: no scroll-snap, no overflow:hidden on the page or scene containers, wheel/touch untouched.
   Nothing animates here, so reduced motion is already "static stacked scenes". Direction stays LTR in every language.
   Step numbers come from CSS counters (the markup carries no digits). */

:root { --rail-h: 3.75rem; }
@media (min-width: 960px) { :root { --rail-h: 0px; } }

.story {
  padding: var(--section-y) clamp(1rem, 4vw, 4.5rem);
  border-top: 1px solid var(--line);
}
.story__inner { max-width: 90rem; margin-inline: auto; }
.story__head { margin-bottom: var(--space-6); }

.story__layout { display: grid; gap: var(--space-4); }
@media (min-width: 960px) {
  .story__layout { grid-template-columns: 15rem minmax(0, 1fr); gap: var(--space-8); align-items: start; }
}

/* ============ Step rail ============ */
.story-rail {
  position: sticky;
  top: var(--header-h);
  z-index: 40;
  margin-inline: calc(-1 * clamp(1rem, 4vw, 4.5rem));
  padding: var(--space-2) clamp(1rem, 4vw, 4.5rem);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;                         /* mobile: the strip scrolls sideways, never the page */
  scrollbar-width: thin;
}
.story-rail ol { display: flex; gap: var(--space-2); counter-reset: step; }
.story-rail__item {
  counter-increment: step;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--muted);
  text-decoration: none;
}
.story-rail__n {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  flex: none;
  width: var(--tap-min);
  height: var(--tap-min);
  font: 600 0.8125rem/1 var(--font-mono);
  color: var(--petrol);
  background: var(--paper);
  border: 1px solid var(--petrol);
  border-radius: var(--radius-0);
}
.story-rail__n::before { content: counter(step, decimal-leading-zero); }
.story-rail__t {                            /* mobile: number only; the title stays in the accessible name */
  position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
}
.story-rail__item.is-past .story-rail__n { color: #FFFFFF; background: var(--petrol); }
.story-rail__item[aria-current="step"] .story-rail__n { color: var(--ink); background: var(--orange); border-color: var(--orange); }
@media (hover: hover) {
  .story-rail__item:hover .story-rail__n { background: var(--concrete); }
  .story-rail__item.is-past:hover .story-rail__n { background: var(--p9); }
  .story-rail__item[aria-current="step"]:hover .story-rail__n { background: var(--orange); }
}

@media (min-width: 960px) {
  .story-rail {
    top: calc(var(--header-h) + var(--space-5));
    z-index: auto;
    margin: 0;
    padding: 0;
    background: none;
    border: 0;
    overflow: visible;
  }
  .story-rail ol { display: grid; gap: 0; position: relative; }
  /* vertical track + progress fill (scaleY driven by --story-progress, set by js/story.js) */
  .story-rail ol::before,
  .story-rail ol::after {
    content: '';
    position: absolute;
    top: calc(var(--tap-min) / 2);
    bottom: calc(var(--tap-min) / 2);
    left: calc(var(--tap-min) / 2 - 1px);
    width: 2px;
  }
  .story-rail ol::before { background: var(--concrete); }
  .story-rail ol::after { background: var(--petrol); transform-origin: top; transform: scaleY(var(--story-progress, 0)); }
  .story-rail li { padding-block: var(--space-2); }
  .story-rail__t {
    position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; white-space: normal;
    font: 700 0.9375rem/1.25 var(--font-display);
  }
  .story-rail__item[aria-current="step"] .story-rail__t,
  .story-rail__item.is-past .story-rail__t { color: var(--petrol); }
}

/* ============ Groups and scenes ============ */
.story__scenes { counter-reset: scene; min-width: 0; }
/* The sticky rail lives in the same grid row as the scenes. To keep it pinned under the header (instead of riding up
   beneath it) while the LAST scene is current, that scene must be at least as tall as the rail (8 steps × 60px = 480px)
   plus its offset: 31rem. A real scene with a visual is taller than this anyway; it only matters for short placeholders. */
@media (min-width: 960px) { .story-group:last-child .scene:last-child { min-height: 31rem; } }
.story-group { scroll-margin-top: calc(var(--header-h) + var(--rail-h)); }
.story-group + .story-group { margin-top: var(--space-6); }   /* + scene padding = the same ≈64px rhythm as between scenes */
.story-group__label { margin-bottom: var(--space-5); }

.scene {
  counter-increment: scene;
  display: grid;
  gap: var(--space-5);
  padding: var(--space-6) 0;
  border-top: 1px solid var(--line-soft);
  scroll-margin-top: calc(var(--header-h) + var(--rail-h) + var(--space-3));
}
/* The first scene of a group sits directly under the group label (no extra rule + padding above it) */
.story-group__label + .scene { padding-top: 0; border-top: 0; }

@media (min-width: 1200px) {
  .scene { grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); gap: var(--space-7); align-items: start; }
  /* Copy aligns with the top of its visual and stays in view while a tall visual scrolls past */
  .scene__copy { position: sticky; top: calc(var(--header-h) + var(--rail-h) + var(--space-5)); align-self: start; }
}

.scene__num {
  display: grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  font: 700 1.125rem/1 var(--font-mono);
  color: var(--ink);
  background: var(--orange);
}
.scene__num::before { content: counter(scene, decimal-leading-zero); }
.scene.is-active .scene__num { box-shadow: 4px 4px 0 var(--petrol); }   /* flat offset, no motion */
.scene__title {
  margin-top: var(--space-4);
  font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.25rem);
  letter-spacing: var(--tracking-tight);
}
.scene__lead { max-width: 34rem; margin-top: var(--space-3); font-size: 1.125rem; color: var(--ink-2); }

/* Empty stage: the geometric slot L9.x fills with each scene's product visual */
.scene__stage {
  position: relative;
  display: grid;
  place-content: center;
  min-height: 16rem;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: var(--grid-size) var(--grid-size);
  border: var(--border);
  box-shadow: var(--shadow-flat);
}
.scene__stage::before {
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  width: var(--notch-size);
  height: var(--notch-size);
  border: var(--notch-weight) solid var(--notch-color);
  border-right: 0;
  border-bottom: 0;
  pointer-events: none;
}
