/*
 * site.css — Shared base styles for Scrolli Labs public pages
 *
 * Used by both the live page (/p/...) and the admin preview iframe.
 * Theme-specific overrides (dia, miranda, claude) load after this.
 */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,wght@0,300;0,400;0,500;1,300;1,400&display=swap');

:root {
  --canvas: #f8f8f8;
  --snow: #fff;
  --fog: #efefef;
  --pebble: #d9d9d9;
  --ash: #7c7c7c;
  --slate: #959595;
  --steel: #aeaeae;
  --graphite: #636363;
  --ink-black: #000;
  --ink-reading: #404040;   /* soft body-text ink (Reuters-style), not pure black */
  --rose-quartz: #c679c4;
  --marigold: #ffb005;
  --signal-blue: #0358f7;
  --hot-pink: #fd02f5;
  --spectrum-red: #fa3d1d;
  --spectrum-gradient: linear-gradient(90deg, #c679c4 0%, #fa3d1d 25%, #ffb005 50%, #e1e1fe 75%, #0358f7 100%);
  --bg: var(--canvas);
  --text: var(--ink-black);
  --muted: var(--graphite);
  --accent: var(--ink-black);
  --card: rgba(255,255,255,.9);
  --font-display: 'DM Sans', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'DM Sans', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-card: 10px;
  --radius-image: 10px;
  --radius-button: 30px;
  --radius-pill: 9999px;
  --shadow-card: rgba(0,0,0,0.08) 0 0 8px 0;
}

/* NOTE (removed): a pair of `--ink-on-map*` constants used to live here, on the
   theory that text over Map2D's basemap tiles needs a mode-independent dark ink
   because tiles are always light. That was wrong, and it caused a regression:
   the map title/sub actually sit inside `.map2d-header`, which already supplies
   a themed `var(--card)` surface — so a fixed dark ink went dark-on-dark in dark
   mode (measured 1.02:1). The general lesson for overlays is that the surface
   must come from a TOKEN the text also follows, never from an assumption about
   what renders behind it. */

/* NIH-188: reader dark mode — an independent override on top of whichever
   theme file (or none, for the default 'dia' case this file itself governs)
   is loaded. `data-mode` is set by a blocking inline script in
   functions/p/[[path]].js, before first paint. Every value here is checked
   against js/brand.js's contrastRatio() at >=4.5:1 for body/caption text and
   >=3:1 for large text/UI (tests/reader-mode-contrast.test.mjs enforces
   this as a regression guard) — --ink-reading in particular is easy to
   forget: it's what .editorial p actually renders with (line ~112 below),
   and no theme file but miranda.css ever overrides it, so this is the ONE
   place that fixes body-copy contrast for the majority of dark-mode pages. */
:root[data-mode="dark"] {
  color-scheme: dark;   /* NIH-197: native controls/scrollbars/iframes follow the article */
  --canvas: #15151a;
  --snow: #1f1f24;
  --fog: #232329;
  --pebble: #35353c;
  --ash: #888785;
  --slate: #85837f;
  --steel: #97958f;
  --graphite: #9b9a97;
  --ink-black: #f2f1ed;
  --ink-reading: #c9c7c2;
  --rose-quartz: #d98ad4;
  --marigold: #ffc247;
  --signal-blue: #4d8dff;
  --hot-pink: #ff5cf6;
  --spectrum-red: #fa3d1d;
  --spectrum-gradient: linear-gradient(90deg, #d98ad4 0%, #fa3d1d 25%, #ffc247 50%, #e1e1fe 75%, #4d8dff 100%);
  --bg: var(--canvas);
  --text: var(--ink-black);
  --muted: var(--graphite);
  --accent: var(--ink-black);
  --card: rgba(31, 31, 36, .85);
  --shadow-card: rgba(0,0,0,.45) 0 0 8px 0;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: auto; } /* Lenis owns smooth scroll when enabled; native smooth conflicts */
/* NIH-197: the ROOT paints the page colour too, not just <body>. Anything that
   makes body transparent (an embed's leaked `body{background:transparent}` did
   exactly this) would otherwise expose the browser's default WHITE canvas under
   a dark article. color-scheme follows the article's mode so native controls,
   scrollbars and iframes agree with it instead of with the reader's OS. */
html { background: var(--bg); color-scheme: light; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

.progress {
  position: fixed; top: 0; left: 0; height: 2px;
  background: var(--spectrum-gradient);
  z-index: 999; transition: width .2s; border-radius: 0 2px 2px 0; width: 0;
}

/* ── Cinematic Intro (Hero) ── */
.cin-intro { position: relative; width: 100%; height: 100vh; overflow: hidden; background: var(--bg); z-index: 10; }
.cin-brand { position: absolute; left: 0; right: 0; text-align: center; font-family: 'DM Sans', sans-serif; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; opacity: 0; z-index: 5; top: 50%; transform: translateY(-50%); font-size: clamp(.85rem, 2vw, 1.25rem); color: var(--text); transition: top .9s cubic-bezier(.4,0,.2,1), transform .9s cubic-bezier(.4,0,.2,1), font-size .9s ease, color .9s ease, opacity .7s ease; }
.cin-brand.settled { top: 1.8rem; transform: translateY(0); font-size: .72rem; color: var(--muted); }
.cin-svg-wrap { position: absolute; top: 0; left: 0; width: 100%; height: 58%; z-index: 1; }
.cin-svg-wrap svg { width: 100%; height: 100%; display: block; }
.cin-text-layer { position: absolute; left: 0; right: 0; top: 58%; height: 32%; z-index: 2; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.cin-line { font-family: var(--font-display); color: var(--ink-black); opacity: 0; position: absolute; text-align: center; max-width: 72vw; line-height: 1.4; letter-spacing: -.02em; }
.cin-l1, .cin-l2 { font-size: clamp(1.3rem, 2.6vw, 1.75rem); font-weight: 300; color: var(--graphite); }
.cin-l3 { font-size: clamp(1.35rem, 2.8vw, 1.9rem); font-weight: 400; color: var(--ink-black); }
.cin-l4 { font-size: clamp(1.2rem, 2.4vw, 1.6rem); font-weight: 300; color: var(--graphite); }
.cin-l5 { font-size: clamp(1.3rem, 2.7vw, 1.85rem); font-weight: 400; color: var(--ink-black); }
.cin-l6 { font-size: clamp(1.45rem, 3.2vw, 2.2rem); font-weight: 500; color: var(--ink-black); letter-spacing: -.03em; }
.cin-title-layer { position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 0 2rem; opacity: 0; pointer-events: none; }
.cin-main-title { font-family: var(--font-display); font-size: clamp(2.6rem, 7vw, 4.5rem); font-weight: 300; color: var(--text); line-height: 1.11; letter-spacing: -.04em; margin-bottom: .8rem; }
.cin-main-title span { color: var(--accent); }
.cin-sub-title { font-family: var(--font-body); font-size: clamp(.9rem, 1.8vw, 1.15rem); color: var(--graphite); font-weight: 400; letter-spacing: -.01em; }
.cin-scroll-cue { position: absolute; bottom: 2rem; left: 0; right: 0; text-align: center; z-index: 6; color: var(--graphite); font-family: var(--font-body); font-size: .78rem; font-weight: 400; display: flex; flex-direction: column; align-items: center; gap: .5rem; opacity: 0; letter-spacing: .02em; }
.cin-scroll-cue .arr { width: 14px; height: 14px; border-right: 2px solid var(--ink-black); border-bottom: 2px solid var(--ink-black); transform: rotate(45deg); animation: bob 2s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: rotate(45deg) translateY(0); } 50% { transform: rotate(45deg) translateY(6px); } }
/* Vestibular safety (WCAG 2.2.2 / prefers-reduced-motion): stop the infinite scroll-cue bob
   for users who ask for reduced motion. Every other animation is already guarded in render.js. */
@media (prefers-reduced-motion: reduce) { .cin-scroll-cue .arr { animation: none; } }

/* ── Print / Save-as-PDF ──────────────────────────────────────────────────────────────────
   Scrollytelling relies on sticky scenes + scroll-driven reveals that don't exist on paper, so
   the default print is a broken mess (overlapping sticky layers, hidden reveal content, huge
   blank scroll tracks, light text on the printer's white). Flatten to a readable, linear article:
   un-stick scenes, reveal everything, hide interactive/animated chrome, force legible colours.
   Real portability + accessibility win (readers save/print/offline). */
@media print {
  html, body { background: #fff !important; color: #111 !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; box-shadow: none !important; text-shadow: none !important; }
  /* Force body text dark — themed/dark sections set light colours that vanish on white. */
  h1, h2, h3, h4, h5, h6, p, li, blockquote, figcaption, .cin-line, .cin-main-title, .cin-brand,
  .editorial, .editorial *, .pullquote, .quote, .quote *, .outro, .outro *, .aside-block, .aside-block *,
  .statrow, .statrow *, .timeline, .timeline * { color: #111 !important; }
  /* Hide interactive / decorative chrome that can't print. */
  #progress, .cin-scroll-cue, .video-cine-toggle, .scroll-cue, .scrolly__resize-grip, [data-print-hide] { display: none !important; }
  /* Canvas scenes rarely rasterise for print — hide, prefer their still fallbacks. */
  canvas { display: none !important; }
  .webgl-fx-fallback { display: block !important; opacity: 1 !important; }
  /* Collapse tall scroll tracks + un-stick scenes so content flows top-to-bottom. */
  .cin-intro, .cin-intro--scroll, .sticky-img, .scrolly, .iso-scrolly, .fullbleed, .fullbleed-sticky { height: auto !important; min-height: 0 !important; }
  .cin-sticky, .sticky-img, .scrolly__graphic, .iss-graphic, .iso-scrolly-graphic { position: static !important; height: auto !important; max-height: none !important; }
  /* Reveal everything the scroll would have unhidden. */
  [data-reveal], [data-reveal-block], .reveal-on [data-reveal-block], .cin-line, .cin-title-layer, .cin-step, .cin-brand, .scrolly__img { opacity: 1 !important; transform: none !important; filter: none !important; visibility: visible !important; }
  /* Legible media + sensible page breaks. */
  img, svg { max-width: 100% !important; height: auto !important; }
  figure, .editorial, .pullquote, .quote, .aside-block, .ds-chart, .statrow, .timeline-event { break-inside: avoid; }
  h1, h2, h3 { break-after: avoid; }
}

/* ── Editorial ── */
.editorial { max-width: 720px; margin: 0 auto; padding: 2.5rem 2rem 3rem; position: relative; z-index: 3; background: var(--canvas); }
.editorial h2 { font-family: var(--font-display); font-size: clamp(2rem, 4vw, 3.125rem); font-weight: 300; margin-bottom: 1.2rem; letter-spacing: -.04em; line-height: 1.18; color: var(--ink-black); }
.editorial p { font-family: var(--font-body); font-size: 1.31rem; line-height: 1.6; color: var(--ink-reading); margin-bottom: 1.4rem; font-weight: 400; }
.editorial .lead { font-size: 1.25rem; font-weight: 300; line-height: 1.4; letter-spacing: -.01em; color: var(--ink-black); }
.editorial .kicker { font-family: var(--font-body); font-size: .75rem; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--graphite); margin-bottom: .8rem; }
.pullquote { border-left: none; padding: 1.25rem 0 1.25rem 1.5rem; margin: 2.5rem 0; font-family: var(--font-display); font-size: clamp(1.25rem, 2.5vw, 1.625rem); font-weight: 300; font-style: normal; color: var(--ink-black); line-height: 1.3; letter-spacing: -.02em; position: relative; }
.pullquote::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--spectrum-gradient); border-radius: 2px; }
.pullquote cite { display: block; font-size: .85rem; font-weight: 500; font-style: normal; color: var(--graphite); margin-top: .75rem; font-family: var(--font-body); letter-spacing: .02em; }
.editorial figure { margin: 2.5rem 0; width: 100%; }
.editorial figure img { width: 100%; height: auto; border-radius: var(--radius-image); display: block; }
.editorial figcaption { font-family: var(--font-body); font-size: .78rem; color: var(--graphite); margin-top: .6rem; font-style: normal; font-weight: 400; }
.editorial .separator { width: 60px; height: 2px; background: var(--spectrum-gradient); margin: 3rem auto; border-radius: 2px; }

/* ── Scrollytelling ── */
/* NOTE: Scrolly/DataScrolly layout + step card styles live in render.js inline CSS.
   site.css only provides viz-panel rules for legacy D3 chart pages. */
.viz-panel { position: fixed; top: 0; left: 0; width: 100%; height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem 2rem 1rem 2rem; z-index: 1; pointer-events: none; background: var(--bg); transform: translateY(100vh); will-change: transform; }

/* VizPanel as rendered by the CURRENT pipeline (render.js): the legacy shell
   above is parked off-screen (translateY(100vh)) and only the old page-init.js
   D3 cinematic ever drove it — which the current renderer does not load. So
   renderVizPanel now emits .viz-panel--static: a normal in-flow, visible card
   with title/sub + an explicit empty state. Legacy pages keep the fixed shell;
   the --static override repositions the card into the page flow. */
.viz-panel--static { position: relative; top: auto; left: auto; width: auto; height: auto; min-height: 46vh; transform: none; pointer-events: auto; padding: 4rem 2rem; justify-content: center; }
.viz-panel--static .viz-header { text-align: center; margin-bottom: 1.25rem; }
.viz-panel--static .viz-title { font-family: var(--font-display, Georgia, serif); font-size: clamp(1.5rem, 3.5vw, 2.25rem); font-weight: 300; letter-spacing: -.02em; }
.viz-panel--static .viz-sub { font-family: var(--font-body); font-size: 1rem; color: var(--graphite, #666); margin-top: .5rem; }
.viz-panel--static .viz-empty { display: flex; flex-direction: column; align-items: center; gap: .35rem; text-align: center; max-width: 460px; margin: 0 auto; color: var(--graphite, #666); }
.viz-panel--static .viz-empty-glyph { width: 34px; height: 34px; opacity: .55; margin-bottom: .25rem; }
.viz-panel--static .viz-empty-title { font-family: var(--font-display, Georgia, serif); font-size: 1.05rem; font-weight: 500; color: var(--ink-black, #000); }
.viz-panel--static .viz-empty-body { font-family: var(--font-body); font-size: .875rem; line-height: 1.5; }

/* ── Outro ── */
.outro { max-width: 720px; margin: 0 auto; padding: 3rem 2rem 6rem; font-family: var(--font-body); position: relative; z-index: 3; background: var(--canvas); }
.outro h2 { font-family: var(--font-display); font-size: clamp(1.5rem, 3vw, 2rem); font-weight: 300; margin-bottom: 1rem; letter-spacing: -.03em; line-height: 1.2; }
.outro p { font-family: var(--font-body); font-size: 1.0625rem; line-height: 1.55; color: var(--ink-black); margin-bottom: 1.2rem; font-weight: 400; }
.outro .final-line { font-family: var(--font-display); font-size: clamp(1.25rem, 2.5vw, 1.5rem); font-weight: 300; color: var(--ink-black); font-style: normal; margin-top: 2.5rem; line-height: 1.3; letter-spacing: -.02em; }
.outro .source-block { margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--fog); font-family: var(--font-body); font-size: .78rem; color: var(--graphite); line-height: 1.65; }

/* ── Page background ── */
#page-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; transition: opacity .8s ease; }
#page-bg-img { width: 100%; height: 100%; object-fit: cover; }

/* ── Progress Nav ── */
.progress-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  height: 3px;
  background: transparent;
  pointer-events: none;
}
.progress-nav-bar {
  height: 100%;
  width: 0;
  background: var(--accent, #c06830);
  transition: width 0.1s linear;
}
.progress-nav-dots {
  position: fixed;
  right: 1.25rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  z-index: 9998;
  pointer-events: auto;
}
.progress-nav-dot {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
}
.progress-nav-dot::after {
  content: '';
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fog, #d0ccc4);
  transition: background 0.2s, transform 0.2s;
  flex-shrink: 0;
}
.progress-nav-dot.is-active::after {
  background: var(--accent, #c06830);
  transform: scale(1.35);
}
.progress-nav-label {
  font-family: var(--font-body, sans-serif);
  font-size: 0.7rem;
  color: var(--graphite, #777);
  white-space: nowrap;
  opacity: 0;
  transform: translateX(4px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.progress-nav-dot:hover .progress-nav-label,
.progress-nav-dot.is-active .progress-nav-label {
  opacity: 1;
  transform: translateX(0);
}
@media (max-width: 640px) {
  .progress-nav-dots { display: none; }
}

/* ── Mobile ── */
@media (max-width: 900px) {
  .cin-main-title { font-size: clamp(1.8rem, 8vw, 2.8rem); }
  .cin-svg-wrap { height: 50%; }
  .cin-text-layer { top: 50%; height: 38%; }
  .cin-line { max-width: 90vw; }
  .editorial { padding: 2.5rem 1.25rem; }
  .editorial p { font-size: 1.02rem; line-height: 1.75; }
  .editorial h2 { font-size: 1.4rem; }
  .pullquote { font-size: 1.05rem; }
  .outro { padding: 3rem 1.25rem 5rem; }
}

/* Render error fallback */
.render-error { max-width: 680px; margin: 4rem auto; padding: 1.5rem 2rem; font-family: var(--font-body, 'DM Sans', system-ui, sans-serif); }
.render-error h1 { font-size: 1.5rem; font-weight: 400; margin-bottom: .75rem; }
.render-error p { color: var(--graphite, #636363); }
