/* ============================================================
   HOW IT WORKS — storyboard page
   Builds on marvis.css + pages.css tokens. Light/paper theme.
   Three live tweak axes (set on <body>):
     data-svg-style   geometric | soft
     data-motion      static | targeted | expressive
     data-scene-layout alternate | lateral | centered
   ============================================================ */

/* ---------- page hero ---------- */
.htw-hero { padding-top: clamp(40px, 6vw, 72px); padding-bottom: clamp(28px, 4vw, 44px); }
.htw-hero .crumb { margin-bottom: 22px; }
.htw-hero h1 {
  font-size: clamp(2.1rem, 4.6vw, 3.6rem);
  letter-spacing: -0.03em;
  line-height: 1.02;
  max-width: 17ch;
}
.htw-hero h1 .hi-ital { letter-spacing: -0.02em; }
.htw-hero .lede {
  margin-top: 20px;
  max-width: 60ch;
  font-size: clamp(1.0625rem, 1.5vw, 1.3125rem);
  line-height: 1.5;
  color: var(--marvis-mute);
}
.htw-hero .lede strong { color: var(--marvis-deep); font-weight: 600; }

/* a slim progress rail showing the 6 beats */
.htw-beats {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-top: 32px;
  font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.06em; color: var(--marvis-mute);
}
.htw-beats .beat {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--marvis-mute);
}
.htw-beats .beat .n {
  width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--marvis-line);
  background: var(--paper);
  font-size: 10px; font-weight: 600; color: var(--marvis-mid);
}
.htw-beats .beat:hover { color: var(--accent); text-decoration: none; }
.htw-beats .beat:hover .n { border-color: var(--accent); color: var(--accent); }
.htw-beats .sep { color: var(--marvis-line-strong); }
@media (max-width: 600px) { .htw-beats { display: none; } }

/* ============================================================
   SCENES
   ============================================================ */
.htw-storyboard { padding-bottom: 24px; }

.htw-scene {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(28px, 5vw, 72px);
  align-items: center;
  padding: clamp(44px, 6.5vw, 88px) 0;
  border-top: 1px solid var(--marvis-line);
  position: relative;
}
.htw-scene:first-child { border-top: 0; }

/* the two columns */
.htw-scene__viz {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--marvis-line);
  border-radius: var(--r-lg);
  padding: clamp(22px, 3vw, 40px);
  display: flex; align-items: center; justify-content: center;
  min-height: 280px;
  transition: border-color .2s ease;
}
.htw-scene:hover .htw-scene__viz { border-color: var(--marvis-line-strong); }
.htw-scene__viz svg { width: 100%; height: auto; max-width: 460px; }

.htw-scene__copy { display: flex; flex-direction: column; gap: 22px; max-width: 30rem; }
.htw-scene__eyebrow {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--font-mono); font-size: 12px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent);
}
.htw-scene__eyebrow .num {
  font-family: var(--font-display); font-weight: 700;
  font-size: 15px; letter-spacing: 0;
  color: var(--accent);
}
.htw-scene__eyebrow::after { content: ""; flex: 1; height: 1px; background: var(--marvis-line); max-width: 64px; }
.htw-scene__h {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  line-height: 1.12; letter-spacing: -0.025em;
  color: var(--marvis-deep);
  text-wrap: balance;
}
.htw-scene__lede { font-size: clamp(1rem, 1.35vw, 1.1875rem); line-height: 1.55; color: var(--marvis-base); }
.htw-scene__body { font-size: 0.9375rem; line-height: 1.6; color: var(--marvis-mute); }
.htw-scene__body code,
.htw-scene__lede code {
  font-family: var(--font-mono); font-size: 0.85em; font-weight: 500;
  background: var(--accent-tint); color: var(--accent);
  padding: 1px 6px; border-radius: 4px;
}
.htw-scene__copy .hi-ital { font-size: 1.02em; }

/* a small caption strip under viz (real text label of the diagram) */
.htw-scene__caption {
  position: absolute; left: clamp(22px,3vw,40px); bottom: 14px;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.04em;
  color: var(--marvis-mute);
}

/* ---------- layout: alternate (default zig-zag) ---------- */
[data-scene-layout="alternate"] .htw-scene:nth-child(even) .htw-scene__viz { order: 2; }
[data-scene-layout="alternate"] .htw-scene:nth-child(even) .htw-scene__copy { order: 1; }

/* ---------- layout: lateral (always viz left) ---------- */
[data-scene-layout="lateral"] .htw-scene__viz { order: 0; }
[data-scene-layout="lateral"] .htw-scene__copy { order: 0; }

/* ---------- layout: centered (stacked) ---------- */
[data-scene-layout="centered"] .htw-scene {
  grid-template-columns: 1fr;
  justify-items: center;
  text-align: center;
  gap: 28px;
}
[data-scene-layout="centered"] .htw-scene__viz { order: 0; width: 100%; max-width: 520px; }
[data-scene-layout="centered"] .htw-scene__copy { order: 0; align-items: center; max-width: 44rem; }
[data-scene-layout="centered"] .htw-scene__eyebrow { justify-content: center; }
[data-scene-layout="centered"] .htw-scene__eyebrow::after { display: none; }

@media (max-width: 880px) {
  .htw-scene { grid-template-columns: 1fr; gap: 28px; padding: 48px 0; }
  .htw-scene .htw-scene__viz { order: 0 !important; }
  .htw-scene .htw-scene__copy { order: 0 !important; max-width: none; }
}

/* ============================================================
   CLOSING
   ============================================================ */
.htw-close {
  text-align: center;
  background: var(--marvis-deep);
  color: var(--cream);
  border-radius: var(--r-lg);
  padding: clamp(40px, 6vw, 72px) clamp(24px, 4vw, 56px);
  position: relative;
  overflow: hidden;
}
.htw-close::after {
  content: ""; position: absolute; right: -120px; top: -120px;
  width: 360px; height: 360px;
  background: radial-gradient(circle, hsl(var(--pir-accent) / 0.40), transparent 62%);
  pointer-events: none;
}
.htw-close__viz { position: relative; z-index: 1; width: 100%; max-width: 132px; margin: 0 auto 26px; }
.htw-close h2 {
  position: relative; z-index: 1;
  font-size: clamp(1.8rem, 3.4vw, 2.75rem);
  letter-spacing: -0.025em; line-height: 1.05;
  color: var(--cream); max-width: 20ch; margin: 0 auto;
}
.htw-close h2 em { font-family: var(--font-serif); font-style: italic; font-weight: 500; color: var(--accent-mute); }
.htw-close p {
  position: relative; z-index: 1;
  margin: 18px auto 0; max-width: 52ch;
  color: rgba(245, 240, 232, 0.78); font-size: clamp(1rem, 1.4vw, 1.125rem); line-height: 1.55;
}
.htw-close p .reassure { color: var(--cream); font-weight: 600; }

/* install block reused from site vocabulary, dark-on-dark */
.htw-install {
  position: relative; z-index: 1;
  margin: 30px auto 0; max-width: 560px;
  display: flex; flex-direction: column; gap: 10px;
}
.htw-install__row {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,0.28);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: var(--r-card);
  padding: 12px 14px;
  font-family: var(--font-mono); font-size: 13px;
  color: rgba(245, 240, 232, 0.92);
  text-align: left;
}
.htw-install__row .tag {
  flex: 0 0 auto;
  font-size: 9.5px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent-mute); font-weight: 600;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(245, 240, 232, 0.06);
}
.htw-install__row code { flex: 1; color: var(--cream); overflow-x: auto; white-space: nowrap; background: transparent; }
.htw-install__row .prompt { color: var(--accent-mute); }
.htw-install__row .str { color: #7BB59A; }
.htw-install__copy {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 7px;
  border: 0; cursor: pointer;
  background: rgba(255,255,255,0.10); color: rgba(245,240,232,0.75);
  display: inline-flex; align-items: center; justify-content: center;
}
.htw-install__copy:hover { background: rgba(255,255,255,0.2); color: #fff; }
.htw-install__copy.is-copied { color: var(--state-full); }

.htw-close__cta { position: relative; z-index: 1; display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 28px; }
.htw-close .btn--outline { color: var(--cream); border-color: rgba(255,255,255,0.28); }
.htw-close .btn--outline:hover { background: #fff; color: var(--marvis-deep); border-color: #fff; }

/* ============================================================
   SVG — shared element styling + soft / geometric tweak
   ============================================================ */
.htw-scene__viz svg text {
  font-family: var(--font-mono);
  fill: var(--marvis-mid);
}
.htw-scene__viz svg .lbl { font-size: 11px; }
.htw-scene__viz svg .lbl--accent { fill: var(--accent); font-weight: 600; }
.htw-scene__viz svg .lbl--green { fill: var(--green); font-weight: 600; }
.htw-scene__viz svg .lbl--light { fill: #F2ECDF; }
.htw-scene__viz svg .lbl--strong { fill: var(--marvis-deep); font-weight: 600; }

/* soft style: rounder joins + softened corners on tagged shapes */
[data-svg-style="soft"] .htw-scene__viz svg * {
  stroke-linecap: round;
  stroke-linejoin: round;
}
[data-svg-style="soft"] .htw-scene__viz svg [data-soft] { rx: 11px; ry: 11px; }
[data-svg-style="soft"] .htw-scene__viz svg [data-soft-sm] { rx: 6px; ry: 6px; }
[data-svg-style="soft"] .htw-scene__viz { border-radius: 22px; }
[data-svg-style="soft"] .htw-close__viz svg * { stroke-linecap: round; stroke-linejoin: round; }

/* ============================================================
   ENTRANCE — scene reveal (gated by motion + JS)
   ============================================================ */
body.htw-anim:not([data-motion="static"]) .htw-scene__viz,
body.htw-anim:not([data-motion="static"]) .htw-scene__copy > * {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity .6s cubic-bezier(0.2,0,0,1), transform .6s cubic-bezier(0.2,0,0,1);
}
body.htw-anim .htw-scene.is-in .htw-scene__viz { opacity: 1; transform: none; }
body.htw-anim .htw-scene.is-in .htw-scene__copy > * { opacity: 1; transform: none; }
/* stagger copy children */
body.htw-anim .htw-scene.is-in .htw-scene__copy > *:nth-child(1) { transition-delay: .04s; }
body.htw-anim .htw-scene.is-in .htw-scene__copy > *:nth-child(2) { transition-delay: .10s; }
body.htw-anim .htw-scene.is-in .htw-scene__copy > *:nth-child(3) { transition-delay: .16s; }
body.htw-anim .htw-scene.is-in .htw-scene__copy > *:nth-child(4) { transition-delay: .22s; }
body.htw-anim .htw-scene.is-in .htw-scene__viz { transition-delay: .08s; }

/* ============================================================
   SVG ANIMATIONS — only when motion enabled & scene in view
   Each scene's animated parts carry .anim-* classes.
   ============================================================ */
@media (prefers-reduced-motion: no-preference) {

  /* ---- ONE-SHOT reveals: every SVG settles into a clean resting
     state, so a paused frame never looks broken. Replays on re-enter. ---- */

  /* fade in once (labels, marks) */
  body:not([data-motion="static"]) .htw-scene.is-in .a-fade {
    animation: htw-fade .7s ease both;
  }
  /* memory leaving once -> ends invisible */
  body:not([data-motion="static"]) .htw-scene.is-in .a-leave {
    animation: htw-leave 1.5s ease both;
    transform-box: fill-box;
  }
  /* pop in once (nodes, badges) */
  body:not([data-motion="static"]) .htw-scene.is-in .a-pop {
    animation: htw-pop .55s cubic-bezier(0.34,1.56,0.64,1) both;
    transform-box: fill-box; transform-origin: center;
  }
  /* draw a connector once */
  body:not([data-motion="static"]) .htw-scene.is-in .a-draw {
    stroke-dasharray: var(--dash, 300);
    stroke-dashoffset: var(--dash, 300);
    animation: htw-draw 1.1s cubic-bezier(0.2,0,0,1) both;
  }
  /* a traveller crosses once, then disappears (garnish only) */
  body:not([data-motion="static"]) .htw-scene.is-in .a-travel {
    animation: htw-travel 1.7s cubic-bezier(0.4,0,0.2,1) both;
    transform-box: fill-box;
  }
  /* slide up into place once */
  body:not([data-motion="static"]) .htw-scene.is-in .a-rise {
    animation: htw-rise .8s cubic-bezier(0.2,0,0,1) both;
    transform-box: fill-box;
  }
  /* slide in from the left once (stray arrow meeting the guard) */
  body:not([data-motion="static"]) .htw-scene.is-in .a-slide {
    animation: htw-slide 1.1s cubic-bezier(0.2,0,0,1) both;
    transform-box: fill-box;
  }

  /* staggered starts */
  .htw-scene.is-in .d1 { animation-delay: .15s; }
  .htw-scene.is-in .d2 { animation-delay: .40s; }
  .htw-scene.is-in .d3 { animation-delay: .65s; }
  .htw-scene.is-in .d4 { animation-delay: .90s; }
  .htw-scene.is-in .d5 { animation-delay: 1.15s; }

  @keyframes htw-fade   { from { opacity: 0; } to { opacity: 1; } }
  @keyframes htw-leave  { 0%,28% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-12px); } }
  @keyframes htw-pop    { from { transform: scale(0); } to { transform: scale(1); } }
  @keyframes htw-draw   { to { stroke-dashoffset: 0; } }
  @keyframes htw-travel { 0% { transform: translate(0,0); opacity: 0; } 16% { opacity: 1; } 82% { opacity: 1; } 100% { transform: var(--travel-to, translate(120px,0)); opacity: 0; } }
  @keyframes htw-rise   { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
  @keyframes htw-slide  { from { transform: translateX(-34px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

  /* ---- gentle, ALWAYS-sensible ambient loops (never read as broken) ---- */
  body:not([data-motion="static"]) .htw-scene.is-in .a-blink { animation: htw-blink 1.1s steps(1) infinite; }
  body:not([data-motion="static"]) .htw-scene.is-in .a-flicker { animation: htw-flicker 2.6s ease-in-out infinite; }
  body:not([data-motion="static"]) .htw-scene.is-in .a-ring,
  body:not([data-motion="static"]) .htw-close__viz .a-ring { animation: htw-ring 2.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
  @keyframes htw-blink { 50% { opacity: 0; } }
  @keyframes htw-flicker { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
  @keyframes htw-ring  { 0%,100% { opacity: .3; transform: scale(.94); } 50% { opacity: .8; transform: scale(1.08); } }
  /* sonar ping emanating from Marvis' antenna (scene 3) */
  body:not([data-motion="static"]) .htw-scene.is-in .a-sonar { animation: htw-sonar 2.4s ease-out infinite; transform-box: fill-box; transform-origin: center; }
  body:not([data-motion="static"]) .htw-scene.is-in .a-sonar.d2 { animation-delay: 1.2s; }
  @keyframes htw-sonar { 0% { opacity: .85; transform: scale(.5); } 100% { opacity: 0; transform: scale(4); } }

  /* expressive: add a slow float to the main subject group */
  body[data-motion="expressive"] .htw-scene.is-in .float-grp {
    animation: htw-float 5.5s ease-in-out infinite;
    transform-box: fill-box; transform-origin: center;
  }
  @keyframes htw-float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
}

/* ============================================================
   TWEAKS PANEL — section spacing inside the shared .tweaks shell
   ============================================================ */
.tweaks__note {
  font-size: 11px; line-height: 1.45; color: var(--marvis-mute);
  border-top: 1px dashed var(--marvis-line); padding-top: 12px;
}
