/* ════════════════════════════════════════════════════════════════════
   THE CLAWFILES — STORY LAYER (/story/ scrollytelling)
   Requires atlas.css. The spine is ONE svg (story-spine.njk) whose
   layer groups fade per chapter via [data-state] on .st-spine.
   All motion CSS-driven; IntersectionObserver only swaps data-state
   and .is-in classes. Reduced-motion collapses to static states.
   ════════════════════════════════════════════════════════════════════ */

/* ── reading progress (pure CSS scroll-driven; silently absent if unsupported) ── */
@supports (animation-timeline: scroll()) {
  .st-progress {
    position: fixed;
    top: 0; left: 0;
    height: 2px;
    width: 100%;
    background: var(--atlas-accent);
    transform-origin: 0 50%;
    transform: scaleX(0);
    z-index: 80;
    animation: st-progress linear both;
    animation-timeline: scroll(root);
  }
  @keyframes st-progress { to { transform: scaleX(1); } }
}

/* ── page grid ─────────────────────────────────────────────────────── */
.st-wrap {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--gut);
  display: grid;
  grid-template-columns: minmax(0, 6fr) minmax(0, 5fr);
  gap: clamp(1.5rem, 4vw, 4rem);
  align-items: start;
}
.st-col { min-width: 0; }

/* ── the sticky spine panel ────────────────────────────────────────── */
.st-spine {
  position: sticky;
  top: 4.75rem;
  height: calc(100dvh - 5.75rem);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--atlas-glass-edge);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(120% 70% at 50% 100%, rgba(224, 74, 66, 0.06), transparent 60%),
    var(--atlas-ink-1);
  box-shadow: var(--atlas-glass-hi), var(--atlas-shadow);
  overflow: clip;
}
.st-spine-svg { flex: 1; width: 100%; height: 100%; display: block; }
.st-spine-caption {
  border-top: 1px solid var(--atlas-line);
  padding: 0.7rem 1rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--paper-mute);
  min-height: 2.6rem;
  display: flex;
  align-items: center;
}
.st-spine-caption span { display: none; }
/* caption text swaps with state via the selectors below */

/* ── SVG element styles ────────────────────────────────────────────── */
.st-ly { opacity: 0; transition: opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1); }
.st-stratum { fill: none; stroke: rgba(247, 242, 232, 0.09); stroke-width: 1; }
.st-rainlines line { stroke: rgba(247, 242, 232, 0.30); stroke-width: 1.4; stroke-linecap: round; }
.st-pine path { fill: rgba(247, 242, 232, 0.22); }
.st-pine rect { fill: rgba(247, 242, 232, 0.30); }
.st-stump { fill: rgba(247, 242, 232, 0.28); }
.st-house path { fill: none; stroke: rgba(247, 242, 232, 0.55); stroke-width: 1.6; stroke-linejoin: round; }
.st-well { stroke: rgba(247, 242, 232, 0.28); stroke-width: 1.4; stroke-dasharray: 2 5; }
.st-svglabel { font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; fill: #ff8f88; }
.st-svglabel-lens { font-size: 12px; }
.st-svglabel-sub { font-family: var(--mono); font-size: 9px; letter-spacing: 0.1em; fill: rgba(247, 242, 232, 0.55); }
.st-stamp circle { fill: rgba(224, 74, 66, 0.07); stroke: var(--atlas-accent-dim); stroke-width: 1.2; stroke-dasharray: 3 3; }
.st-stamp text { font-family: var(--mono); font-size: 8.6px; letter-spacing: 0.12em; fill: #ff8f88; }
.st-pit { fill: rgba(6, 5, 4, 0.82); stroke: rgba(224, 74, 66, 0.35); stroke-width: 1.2; }
.st-truck rect { fill: rgba(247, 242, 232, 0.35); }
.st-truck circle { fill: var(--atlas-ink-0); stroke: rgba(247, 242, 232, 0.4); stroke-width: 1; }
.st-panel rect { fill: rgba(224, 74, 66, 0.16); stroke: rgba(224, 74, 66, 0.5); stroke-width: 1.2; }
.st-panel line { stroke: rgba(247, 242, 232, 0.4); stroke-width: 2; }
.st-newhouse path { fill: rgba(224, 74, 66, 0.12); stroke: #ff8f88; stroke-width: 1.4; stroke-linejoin: round; }
.st-strawpipe { fill: rgba(224, 74, 66, 0.10); stroke: var(--atlas-accent); stroke-width: 1.6; }
.st-strawflow line { stroke: var(--atlas-accent); stroke-width: 3; stroke-dasharray: 6 10; }
.st-bar-track { fill: rgba(247, 242, 232, 0.08); }
.st-bar-fill { fill: var(--atlas-accent); }
.st-bar-mid { fill: rgba(247, 242, 232, 0.35); }
.st-barnum { font-family: var(--mono); font-size: 9.5px; fill: rgba(247, 242, 232, 0.8); }
.st-moneyarc { fill: none; stroke: var(--atlas-accent); stroke-width: 1.6; stroke-dasharray: 7 9; }
.st-moneydot { fill: var(--atlas-accent); }
.st-dot { fill: var(--atlas-accent); }
.st-tapring { fill: none; stroke: var(--atlas-accent-dim); stroke-width: 1.4; }
.st-order rect { fill: rgba(224, 74, 66, 0.12); stroke: #ff8f88; stroke-width: 1.3; }
.st-order text { font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; fill: var(--paper); }

/* ── state machine: which layers are on per chapter ────────────────── */
/* base: nothing extra. every state lists its visible layers. */
.st-spine[data-state="tank"]      #ly-rain,
.st-spine[data-state="tank"]      #ly-forest,
.st-spine[data-state="pass"]      #ly-forest,
.st-spine[data-state="pass"]      #ly-stamps,
.st-spine[data-state="acre-timber"] #ly-stumps,
.st-spine[data-state="acre-sand"]   #ly-stumps,
.st-spine[data-state="acre-sand"]   #ly-pit,
.st-spine[data-state="acre-solar"]  #ly-pit,
.st-spine[data-state="acre-solar"]  #ly-solar,
.st-spine[data-state="acre-homes"]  #ly-pit,
.st-spine[data-state="acre-homes"]  #ly-endgame,
.st-spine[data-state="straw"]     #ly-straw,
.st-spine[data-state="referees"]  #ly-stamps,
.st-spine[data-state="referees"]  #ly-pit,
.st-spine[data-state="money"]     #ly-money,
.st-spine[data-state="money"]     #ly-pit,
.st-spine[data-state="downstream"] #ly-stumps,
.st-spine[data-state="downstream"] #ly-pit,
.st-spine[data-state="downstream"] #ly-contam,
.st-spine[data-state="turn"]      #ly-pit,
.st-spine[data-state="turn"]      #ly-turn,
.st-spine[data-state="files"]     #ly-rain,
.st-spine[data-state="files"]     #ly-forest {
  opacity: 1;
}
.st-spine[data-state="pass"] #ly-forest { opacity: 0.45; }
.st-spine[data-state="acre-timber"] #ly-forest { opacity: 0.12; }

/* caption per state */
.st-spine[data-state="tank"]        .st-cap-tank,
.st-spine[data-state="pass"]        .st-cap-pass,
.st-spine[data-state="acre-timber"] .st-cap-acre,
.st-spine[data-state="acre-sand"]   .st-cap-acre,
.st-spine[data-state="acre-solar"]  .st-cap-acre,
.st-spine[data-state="acre-homes"]  .st-cap-acre,
.st-spine[data-state="straw"]       .st-cap-straw,
.st-spine[data-state="referees"]    .st-cap-referees,
.st-spine[data-state="money"]       .st-cap-money,
.st-spine[data-state="downstream"]  .st-cap-downstream,
.st-spine[data-state="turn"]        .st-cap-turn,
.st-spine[data-state="files"]       .st-cap-files { display: inline; }

/* ── spine micro-motion (all reduced-motion gated) ─────────────────── */
@media (prefers-reduced-motion: no-preference) {
  .st-spine[data-state="tank"] .st-rainlines,
  .st-spine[data-state="files"] .st-rainlines { animation: st-rain 1.8s linear infinite; }
  .st-spine[data-state="straw"] .st-strawflow line { animation: st-updash 1.1s linear infinite; }
  .st-spine[data-state="money"] .st-moneyarc { animation: st-dash 1.6s linear infinite; }
  .st-spine[data-state="downstream"] .st-tapring { animation: st-ring 2.6s ease-out infinite; }
  .st-spine[data-state="turn"] .st-order { animation: st-stamp 0.5s cubic-bezier(0.16, 1, 0.3, 1) both; }
  .st-spine[data-state="turn"] .st-order-2 { animation-delay: 0.18s; }
  .st-spine[data-state="turn"] .st-order-3 { animation-delay: 0.36s; }
}
@keyframes st-rain   { to { transform: translateY(14px); } }
@keyframes st-updash { to { stroke-dashoffset: 32; } }
@keyframes st-dash   { to { stroke-dashoffset: -32; } }
@keyframes st-ring   { 0% { transform: scale(1); opacity: 0.9; } 100% { transform: scale(2.1); opacity: 0; } }
@keyframes st-stamp  { from { transform: translateY(-14px) scale(1.25); opacity: 0; } }
.st-order { transform-box: fill-box; transform-origin: center; }
.st-tapring { transform-box: fill-box; transform-origin: center; }

/* ── chapters ──────────────────────────────────────────────────────── */
.st-chapter {
  min-height: 88dvh;
  padding: clamp(3rem, 9vh, 6rem) 0;
  border-bottom: 1px solid var(--atlas-line-soft);
}
.st-chapter:last-of-type { border-bottom: 0; }
.st-num {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  color: #ff8f88;
  display: block;
  margin-bottom: 0.7rem;
}
.st-h2 {
  font-family: var(--serif);
  font-size: clamp(1.9rem, 1.2rem + 2.6vw, 3.1rem);
  line-height: 1.05;
  letter-spacing: -0.015em;
  color: var(--paper);
  margin: 0 0 1.1rem;
  text-wrap: balance;
}
.st-prose p {
  font-size: 1.02rem;
  line-height: 1.72;
  color: var(--paper-2);
  margin: 0 0 1.1rem;
  max-width: 38rem;
}
.st-prose strong { color: var(--paper); }
.st-lede-p {
  font-size: 1.14rem !important;
  color: var(--paper) !important;
}

/* ── citation chips + per-chapter sources ──────────────────────────── */
.st-cite {
  display: inline-block;
  vertical-align: super;
  font-family: var(--mono);
  font-size: 0.62rem;
  line-height: 1;
  color: #ff8f88;
  border: 1px solid var(--atlas-accent-dim);
  border-radius: var(--radius-pill);
  padding: 0.1rem 0.4rem;
  margin-left: 0.15rem;
  text-decoration: none;
  white-space: nowrap;
}
.st-cite:hover { background: var(--atlas-accent-wash); color: var(--paper); }
.st-sources {
  margin-top: 1.4rem;
  border: 1px solid var(--atlas-line);
  border-radius: var(--radius-md);
  background: var(--atlas-ink-2);
  max-width: 38rem;
}
.st-sources summary {
  cursor: pointer;
  list-style: none;
  padding: 0.75rem 1rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--paper-mute);
}
.st-sources summary::-webkit-details-marker { display: none; }
.st-sources summary::before { content: "▸ "; color: #ff8f88; }
.st-sources[open] summary::before { content: "▾ "; }
.st-sources ol {
  margin: 0;
  padding: 0 1.2rem 1rem 2.4rem;
}
.st-sources li {
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--paper-2);
  padding: 0.25rem 0;
}
.st-sources li .sgrade {
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-mute);
  border: 1px solid var(--atlas-line);
  border-radius: var(--radius-pill);
  padding: 0.06rem 0.45rem;
  margin-left: 0.4rem;
  white-space: nowrap;
}
.st-sources li .sgrade.g-doc { color: #8fd6a0; border-color: rgba(143, 214, 160, 0.35); }
.st-sources li .sgrade.g-est { border-style: dashed; }

/* ── in-flow figures ───────────────────────────────────────────────── */
.st-figure {
  margin: 1.6rem 0;
  border: 1px solid var(--atlas-line);
  border-radius: var(--radius-md);
  background: var(--atlas-ink-2);
  padding: 1.1rem 1.2rem;
  max-width: 38rem;
}
.st-figure figcaption {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--paper-mute);
  margin-bottom: 0.8rem;
}

/* stat callout */
.st-stat {
  border-left: 3px solid var(--atlas-accent);
  padding: 0.4rem 0 0.4rem 1.1rem;
  margin: 1.4rem 0;
  max-width: 38rem;
}
.st-stat b {
  display: block;
  font-family: var(--mono);
  font-weight: 500;
  font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.2rem);
  color: var(--paper);
  letter-spacing: -0.01em;
}
.st-stat span { font-size: 0.9rem; color: var(--paper-mute); line-height: 1.5; }

/* seat map (Carver ERC 3 of 6) */
.st-seatmap { display: flex; gap: 0.55rem; align-items: center; }
.st-seat {
  width: 34px; height: 34px;
  border-radius: 7px;
  border: 1.4px solid var(--atlas-line);
  background: transparent;
}
.st-seat.is-industry { background: var(--atlas-accent-wash); border-color: var(--atlas-accent); }
.st-seatmap-key { font-size: 0.78rem; color: var(--paper-mute); margin-left: 0.5rem; }

/* timeline rail (The Turn) */
.st-timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.st-timeline::before {
  content: "";
  position: absolute;
  left: 7px; top: 6px; bottom: 6px;
  width: 2px;
  background: linear-gradient(180deg, var(--atlas-line), var(--atlas-accent));
}
.st-timeline li { position: relative; padding: 0 0 1.15rem 2rem; }
.st-timeline li::before {
  content: "";
  position: absolute;
  left: 2px; top: 4px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--atlas-ink-0);
  border: 2px solid var(--atlas-accent);
}
.st-timeline .tdate {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ff8f88;
  display: block;
}
.st-timeline .ttext { font-size: 0.93rem; color: var(--paper-2); line-height: 1.55; }

/* acre strip (4 mini stages) */
.st-acre-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; }
.st-acre-cell {
  border: 1px solid var(--atlas-line);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.5rem 0.5rem;
  text-align: center;
}
.st-acre-cell svg { width: 100%; height: 44px; display: block; margin-bottom: 0.4rem; }
.st-acre-cell b {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--paper);
}
.st-acre-cell span { display: block; font-size: 0.7rem; color: var(--paper-mute); margin-top: 0.15rem; }

/* appendix */
.st-appendix { max-width: 44rem; }
.st-appendix h2 { font-family: var(--serif); color: var(--paper); }
.st-appendix ol { padding-left: 1.3rem; }
.st-appendix li { font-size: 0.88rem; color: var(--paper-2); line-height: 1.65; padding: 0.3rem 0; }

/* reveal */
@media (prefers-reduced-motion: no-preference) {
  .st-chapter > * { opacity: 0; transform: translateY(16px); transition: opacity 0.7s cubic-bezier(0.16,1,0.3,1), transform 0.7s cubic-bezier(0.16,1,0.3,1); }
  .st-chapter.is-in > * { opacity: 1; transform: none; }
  .st-chapter.is-in > *:nth-child(2) { transition-delay: 0.06s; }
  .st-chapter.is-in > *:nth-child(3) { transition-delay: 0.12s; }
  .st-chapter.is-in > *:nth-child(4) { transition-delay: 0.18s; }
  .st-chapter.is-in > *:nth-child(n+5) { transition-delay: 0.24s; }
}

/* ── mobile collapse ───────────────────────────────────────────────── */
@media (max-width: 900px) {
  .st-wrap { grid-template-columns: 1fr; }
  .st-spine {
    position: sticky;
    top: 3.4rem;
    height: 34dvh;
    z-index: 5;
    order: -1;
  }
  .st-spine-caption { min-height: 2.2rem; padding: 0.45rem 0.8rem; }
  .st-chapter { min-height: 0; padding: 2.4rem 0; }
  .st-acre-strip { grid-template-columns: repeat(2, 1fr); }
}
