/* story.css — scrollytelling article ("A reform effect — or a size gradient?")
 *
 * Design system adapted from the De Correspondent piece (omvangskloof.html):
 * Libre Franklin (body) + PT Serif (display), warm chalk paper, fade-in sections,
 * info-cards, viz-panels that bleed wider than the text column.
 *
 * Palette is LOCKED to the narrative wording: treated (below 5,000) = red,
 * control (above) = blue, threshold line = neutral dark dashed. This file is
 * the ONLY stylesheet index.html loads, so it also carries the explorer
 * control + chart styles (ported from style.css) for the "try it yourself"
 * finale, restyled with these tokens.
 */

:root {
  --bg: #FBF6EE;
  --surface: #F3ECE0;
  --grid: #E2D9C9;
  --text: #221F1C;
  --text-muted: #6E665B;
  --text-caption: #76695C;

  /* data roles (locked) */
  --treated: #C0392B;   /* below threshold (DC brick red) */
  --control: #1F6F8B;   /* above threshold (teal-blue) */
  --threshold: #7A7266; /* the 5,000 line: neutral taupe, dashed */
  --accent: #C0392B;    /* DC brick red, for emphasis / rules (= treated) */
  --accent-2: #B0791A;  /* ochre, for placebo / secondary series */
  --curve: #221F1C;     /* the smooth size-gradient curve (= ink) */

  --card-treated: #F4DAD2;
  --card-control: #D4E4EA;

  --font: 'Libre Franklin', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: 'PT Serif', Georgia, "Times New Roman", serif;
  --radius: 2px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

.container { max-width: 680px; margin: 0 auto; padding: 60px 20px 80px; }

/* ── Header / typography ─────────────────────────────────────────────────── */
.kicker {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 18px;
}
h1::before {
  content: ''; display: block;
  width: 48px; height: 4px; background: var(--accent); margin-bottom: 20px;
}
h1 {
  font-family: var(--font-display);
  font-size: 34px; font-weight: 700; line-height: 1.2; margin-bottom: 14px;
}
.subtitle {
  font-family: var(--font-display); font-style: italic;
  font-size: 18px; color: var(--text-muted); margin-bottom: 40px; line-height: 1.5;
}
h2 {
  font-family: var(--font-display);
  font-size: 23px; font-weight: 700; line-height: 1.35; margin: 8px 0 14px;
}
.eyebrow {
  font-size: 12px; font-weight: 700; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 6px;
}
p {
  font-family: var(--font-display);
  font-size: 18px; margin-bottom: 18px; line-height: 1.75;
}
p.small { font-size: 15px; color: var(--text-muted); }
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid currentColor; }
a:hover { color: var(--text); }
em { font-style: italic; }
strong { font-weight: 700; }
.num {
  font-family: var(--font); font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.num.muted { color: var(--text-muted); }

/* ── Scroll reveal ───────────────────────────────────────────────────────── */
.section {
  margin-bottom: 16px;
  opacity: 0; transform: translateY(36px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}
.section.visible { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .section { opacity: 1; transform: none; transition: none; }
}

/* ── Viz panels (bleed wider than the text column on desktop) ────────────── */
.viz-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px 24px 18px;
  margin: 30px -20px;
  position: relative;
}
@media (min-width: 860px) {
  .viz-panel { margin-left: -120px; margin-right: -120px; }
}
.viz-panel .panel-head {
  font-family: var(--font); font-size: 13px; font-weight: 700;
  letter-spacing: 0.03em; color: var(--text); margin-bottom: 2px;
}
.viz-panel .panel-stat {
  font-family: var(--font-display); font-size: 22px; font-weight: 700;
  font-variant-numeric: tabular-nums; margin: 2px 0 10px; color: var(--text);
}
.viz-panel svg { display: block; width: 100%; height: 360px; overflow: visible; }
.viz-panel.tall svg { height: 460px; }
.caption {
  font-family: var(--font); font-size: 12.5px; color: var(--text-caption);
  margin-top: 10px; line-height: 1.5;
}

/* ── Legend ──────────────────────────────────────────────────────────────── */
.legend { display: flex; gap: 18px; margin: 4px 0 12px; font-family: var(--font); font-size: 13px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.ldot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.lbar { width: 16px; height: 3px; display: inline-block; border-radius: 2px; }

/* ── Info-card / stat cards ──────────────────────────────────────────────── */
.infocard {
  background: var(--surface); border-left: 3px solid var(--accent);
  padding: 16px 20px; margin: 24px 0;
  font-family: var(--font); font-size: 15.5px; line-height: 1.65;
}
.infocard strong { font-weight: 700; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; }
.card { border-radius: var(--radius); padding: 14px; text-align: center; }
.card.treated { background: var(--card-treated); }
.card.control { background: var(--card-control); }
.card.main { background: var(--text); color: var(--bg); }
.card-label { font-family: var(--font); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.7; margin-bottom: 2px; }
.card-num { font-family: var(--font); font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── Step buttons (hypothesis / placebo toggles inside a panel) ──────────── */
.step-buttons { display: flex; gap: 8px; margin: 2px 0 14px; flex-wrap: wrap; }
.step-btn {
  font-family: var(--font); font-size: 13px; font-weight: 600;
  padding: 6px 14px; border: 2px solid var(--text); border-radius: var(--radius);
  background: transparent; color: var(--text); cursor: pointer; transition: all 0.15s;
}
.step-btn.active { background: var(--text); color: var(--bg); }
.step-btn:hover:not(.active) { border-color: var(--accent); color: var(--accent); }

/* the uncontrolled/controlled toggle on the size-control graphic (own class so
   wireStepButtons, which targets .step-btn + data-mode, leaves it alone) */
.ctrl-toggle-row { display: flex; gap: 8px; margin: 2px 0 12px; flex-wrap: wrap; }
.ctrl-toggle {
  font-family: var(--font); font-size: 13px; font-weight: 600;
  padding: 6px 14px; border: 2px solid var(--text); border-radius: var(--radius);
  background: transparent; color: var(--text); cursor: pointer; transition: all 0.15s;
}
.ctrl-toggle.active { background: var(--text); color: var(--bg); }
.ctrl-toggle:hover:not(.active) { border-color: var(--accent); color: var(--accent); }

/* drag slider for the interactive (non-scrolljack) anomaly charts */
.slider-row { display: flex; align-items: center; gap: 12px; margin: 2px 0 12px; flex-wrap: wrap; }
.chart-slider { flex: 1 1 200px; min-width: 160px; accent-color: var(--accent); cursor: pointer; height: 22px; }
.slider-val { font-family: var(--font); font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.sweep-gap { margin-top: 18px; }

/* ── Anomaly list ───────────────────────────────────────────────────────── */
.anomaly-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-family: var(--font); font-weight: 700; font-size: 14px;
  margin-right: 8px; vertical-align: middle;
}

/* ── Source / footer ─────────────────────────────────────────────────────── */
.source {
  font-family: var(--font); font-size: 13px; color: var(--text-caption);
  margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--grid); line-height: 1.6;
}
.source a { color: var(--text); }

/* Inline citations: subtler dotted underline, jump to the References list. */
.cite { border-bottom: 1px dotted currentColor; }
.ci-note { font-weight: 400; color: var(--text-muted); font-size: 0.7em; }

/* Scroll-scrubbed panels: the graphic pins while its tall section scrolls past,
   and the chart's state is driven by scroll progress (see renderScrub). */
.scrolly { position: relative; }
.scrolly-graphic { position: sticky; top: 6vh; }
/* The pinned graphic reads as a floating card via a soft shadow. (No fade scrim:
   it dimmed text that was still being read.) */
.scrolly-graphic .viz-panel { box-shadow: 0 4px 22px rgba(45, 45, 45, 0.09); }
/* The pinned chart is sized to the viewport (not a fixed 360px) so its bottom
   stays in the top ~55% of the screen, leaving a clear reading gap below for the
   step text. Without this, on a short window the card fills the screen and the
   step text scrolls up behind it. */
.scrolly-graphic .viz-panel svg { height: clamp(200px, 34vh, 330px); }
/* Short (but wide) desktop/laptop windows: shrink the pinned chart further and
   drop its legend so the card bottom clears the step-reading zone. The min-width
   guard leaves phones on their own (max-width: 700px) rules. */
@media (min-width: 701px) and (max-height: 700px) {
  .scrolly-graphic .viz-panel svg { height: clamp(170px, 30vh, 240px); }
  .scrolly-graphic .legend { display: none; }
}
.scrolly-spacer { height: 200vh; pointer-events: none; }
.scrolly-prose { padding: 30vh 0 55vh; }   /* scroll room for the RD → gradient transition */
.scrolly-steps { padding-bottom: 10vh; }
/* Step height is kept at/under the reading zone (viewport minus the pinned
   chart) so the next step's text enters as the previous one leaves: no empty
   white gap below the chart. */
.scrolly-step { min-height: 42vh; padding-top: 2vh; }
.scrolly-step:last-child { min-height: 30vh; }
.scrolly-step.did-dwell { min-height: 22vh; padding-top: 0; }   /* empty: briefly holds the DID state after the chart pins */
.scrub-annot { font-family: var(--font); font-size: 12px; font-weight: 700; fill: var(--text-muted); }
.scrub-annot.scrub-n { font-weight: 400; font-size: 11px; }

/* Dual sticky graphic: scrubbed binscatter (top) + companion sweep chart
   (bottom) with a moving position dot. Compact heights so both pin in view. */
.scrolly-graphic.dual .viz-panel { margin-top: 0; margin-bottom: 0; }
.scrolly-graphic.dual .viz-panel.sweep { margin-top: 12px; padding-top: 16px; }
.scrolly-graphic.dual .viz-panel svg { height: 228px; }
.scrolly-graphic.dual .viz-panel.sweep svg { height: 150px; }
.scrub-pos { fill: var(--accent); stroke: #fff; stroke-width: 1.5; }
.scrub-guide { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; }
.dot-key { color: var(--accent); font-weight: 600; }
.references {
  font-family: var(--font); font-size: 13px; color: var(--text-caption);
  margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--grid); line-height: 1.6;
}
.references h2 {
  font-family: var(--font); font-size: 13px; font-weight: 700; letter-spacing: 0.5px;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 14px;
}
.ref-list { list-style: none; padding-left: 0; margin: 0; }
.ref-list li { padding-left: 1.5em; text-indent: -1.5em; margin-bottom: 12px; }
.references a { color: var(--accent); word-break: break-word; }

/* ═══════════════════════════════════════════════════════════════════════════
   SVG chart element classes — shared by the story panels (story.js) and the
   embedded explorer (explorer.js). Palette locked: below=treated red,
   above=control blue, threshold neutral dashed.
   ═══════════════════════════════════════════════════════════════════════════ */
.bin-dot { stroke: none; }
.bin-dot.below { fill: var(--treated); }
.bin-dot.above { fill: var(--control); }
.hline.below { stroke: var(--treated); }
.hline.above { stroke: var(--control); }
.hline { stroke-width: 2.5; }
.hline.faint { stroke-width: 1.5; stroke-dasharray: 4 3; opacity: 0.4; }
.threshold-line { stroke: var(--threshold); stroke-width: 1.2; stroke-dasharray: 3 3; }
.gap-arrow { stroke: var(--text); stroke-width: 1.3; fill: none; }
.gap-ci-band { fill: rgba(45, 45, 45, 0.14); stroke: rgba(45, 45, 45, 0.34); stroke-width: 0.5; }
.gap-label { font-family: var(--font); font-size: 11px; fill: var(--text); }

.gradient-curve { fill: none; stroke: var(--curve); stroke-width: 2.6; }
.disc-fit { stroke-width: 2.8; fill: none; }
.disc-fit.below { stroke: var(--treated); }
.disc-fit.above { stroke: var(--control); }
.jump-connector { stroke: var(--text); stroke-width: 1.8; fill: none; }
.jump-label { font-family: var(--font); font-size: 12px; fill: var(--text); font-variant-numeric: tabular-nums; }
.rd-reported { font-family: var(--font); font-size: 12px; color: var(--text-muted); }

/* generic series for the anomaly panels */
.series-line { fill: none; stroke: var(--text); stroke-width: 2.2; }
.series-band { fill: rgba(45, 45, 45, 0.12); stroke: none; }
.zero-line { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 2 3; }
.dot-real { fill: var(--accent); }
.dot-placebo { fill: var(--control); }
.lollipop-stem { stroke: var(--grid); stroke-width: 2; }
.ci-whisker { stroke: rgba(45, 45, 45, 0.55); stroke-width: 1.4; }
.ols-line { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 4; fill: none; }
.point-highlight { stroke: var(--accent); stroke-width: 2; fill: #fff; }

.axis path, .axis line { stroke: #cfcabf; }
.axis text { fill: var(--text-muted); font-family: var(--font); font-size: 10.5px; }
.axis-title { fill: var(--text-muted); font-family: var(--font); font-size: 11px; }
.facet-label { font-family: var(--font); font-size: 12px; font-weight: 700; fill: var(--text); }

.chart-tip {
  position: fixed; pointer-events: none; z-index: 50;
  background: var(--text); color: var(--bg);
  font-family: var(--font); font-size: 12px; padding: 5px 8px; border-radius: var(--radius);
  font-variant-numeric: tabular-nums; opacity: 0; transition: opacity 0.1s; white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Explorer controls + facet (finale "try it yourself"). Ported from style.css
   and restyled with the story tokens so the embedded explorer looks native.
   ═══════════════════════════════════════════════════════════════════════════ */
#controls { display: block; margin: 8px 0 18px; }
#controls fieldset { border: 1px solid var(--grid); padding: 10px 14px 8px; background: var(--surface); margin: 0 0 12px; border-radius: var(--radius); }
#controls legend { font-family: var(--font); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); padding: 0 6px; }
#controls fieldset label { font-family: var(--font); display: inline-flex; align-items: center; gap: 6px; font-size: 14px; margin-right: 12px; }
.muted { color: var(--text-muted); font-size: 12px; }

#view-fieldset.segmented label {
  border: 1px solid var(--grid); border-radius: var(--radius);
  padding: 4px 10px; background: #fff; cursor: pointer; transition: background 0.12s, border-color 0.12s, color 0.12s;
}
#view-fieldset.segmented label:has(input:checked) { background: var(--text); border-color: var(--text); color: #fff; }
#view-fieldset.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));   /* Estimator + threshold on row 1; bandwidth + size-trend on row 2 */
  gap: 14px 22px; align-items: start;
  padding: 12px 16px; background: var(--surface); border: 1px solid var(--grid); border-radius: var(--radius);
}
.control-grid > label { font-family: var(--font); display: flex; flex-direction: column; gap: 4px; font-size: 13px; min-width: 0; }
.control-grid > label > span:first-child { color: var(--text-muted); text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.05em; }
.control-grid select, .control-grid input[type=range] { width: 100%; font-size: 14px; padding: 3px 4px; box-sizing: border-box; }
.control-grid output { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text); margin-top: 2px; }
.lp-toggle > span:last-child { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; }
@media (max-width: 520px) { .control-grid { grid-template-columns: 1fr; } }

#charts { display: block; margin-bottom: 14px; }
.facet { background: var(--surface); border: 1px solid var(--grid); border-radius: var(--radius); padding: 14px 18px 16px; }
.facet.single svg { height: 460px; width: 100%; display: block; overflow: visible; }
.facet-title { font-family: var(--font); font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.facet-title .weight-note { color: var(--text-muted); font-weight: 400; font-size: 12px; }
.facet-status { font-family: var(--font); color: var(--text-muted); font-size: 13px; min-height: 18px; }
.facet-headline { font-family: var(--font-display); font-size: 22px; margin: 2px 0 8px; color: var(--text); font-variant-numeric: tabular-nums; }
.facet-headline .est-num { font-weight: 700; }
.facet.disabled svg { opacity: 0.25; }

#caption { font-family: var(--font); margin-top: 6px; font-size: 13px; color: var(--text); }
#caption #caption-text { font-family: var(--font); margin: 0 0 4px; font-size: 13.5px; }
#caption #diagnostics { font-family: var(--font); margin: 0; color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ── Mobile (≤700px): the pinned graphics must share the screen with the
   scrolling text, so size them to ~half the viewport (vh-based) and scale type
   down. The two stacked dual charts (Anomaly 2 & 3) are kept especially
   compact so chart + chart + a line of text all fit. ─────────────────────── */
@media (max-width: 700px) {
  .container { padding: 30px 16px 64px; }
  h1 { font-size: 26px; }
  .subtitle { font-size: 16px; margin-bottom: 26px; }
  h2 { font-size: 20px; }
  .section p { font-size: 16px; }

  .viz-panel { margin: 18px -16px; padding: 14px 16px 14px; border-radius: 0; }
  .viz-panel .panel-head { font-size: 12px; }
  .viz-panel .panel-stat { font-size: 16px; }
  .viz-panel svg { height: 300px; }
  .viz-panel.tall svg { height: 340px; }

  /* sticky scrollytelling graphics: pin near the top, take ~half the screen.
     svh (small viewport height) is stable as the mobile URL bar shows/hides,
     so the charts don't resize/redraw mid-scroll; vh is the fallback. */
  .scrolly-graphic { top: 0.4rem; }
  .scrolly-graphic .viz-panel svg { height: 36vh; height: 36svh; max-height: 300px; }
  /* the red/blue is already spelled out in the lead-in text, so drop the legend
     on mobile to give the step text more room (Pim: "het plaatje zit in de weg"). */
  .scrolly-graphic .legend { display: none; }

  /* dual graphics: two charts share the viewport, so keep each compact. */
  .scrolly-graphic.dual .viz-panel svg { height: 24vh; height: 24svh; max-height: 195px; }
  .scrolly-graphic.dual .viz-panel.sweep svg { height: 16vh; height: 16svh; max-height: 135px; }
  .scrolly-graphic.dual .viz-panel.sweep { margin-top: 8px; padding-top: 10px; }
  .caption { font-size: 11.5px; }

  /* embedded explorer chart is not pinned; keep it modest. */
  .facet.single svg { height: 320px; }
}
