:root {
  /* Palette harmonised with the story (story.css): same data reds/blues, warm surface. */
  --red: #C44D3F;
  --blue: #2D5F7C;
  --ink: #2D2D2D;
  --muted: #6B6B6B;
  --bg: #FAFAF8;
  --surface: #F0EDE8;
  --hairline: #E3E0DB;
  --grid: #E3E0DB;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Cambria, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body { font-family: var(--sans); max-width: 1240px; margin: 0 auto; padding: 28px 24px 64px; line-height: 1.45; }

header h1 { font-family: var(--serif); font-size: 28px; margin: 0 0 6px; font-weight: 600; }
header .lede { color: var(--muted); max-width: 820px; margin: 0 0 28px; }

/* Controls */
#controls { display: block; margin-bottom: 28px; }
#controls fieldset { border: 1px solid var(--hairline); padding: 10px 14px 8px; background: var(--surface); margin: 0 0 14px; }
#controls legend { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 0 6px; }
#controls fieldset label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; margin-right: 12px; }
.muted { color: var(--muted); font-size: 12px; }

/* View toggle: radios styled as a segmented control. */
#view-fieldset.segmented label {
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 4px 10px;
  background: #fff;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
#view-fieldset.segmented label:has(input:checked) {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
#view-fieldset.segmented input { position: absolute; opacity: 0; pointer-events: none; }

/* Single row: estimator · population threshold · bandwidth · size-trend.
   Weighted columns keep the estimator dropdown wide enough for its full
   option text; minmax(0,…) lets the sliders shrink instead of overflowing. */
.control-grid {
  display: grid;
  grid-template-columns:
    minmax(190px, 1.3fr)   /* estimator    */
    minmax(150px, 1fr)     /* threshold    */
    minmax(150px, 1fr)     /* bandwidth    */
    minmax(130px, 0.9fr);  /* size-trend   */
  gap: 12px 20px;
  align-items: start;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--hairline);
}
.control-grid > label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; min-width: 0; }
.control-grid > label > span:first-child { color: var(--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(--ink); margin-top: 2px; }
.lp-toggle > span:last-child { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; }
.lp-toggle input { vertical-align: middle; }

/* Narrow screens: let the row reflow to two columns rather than overflow. */
@media (max-width: 720px) {
  .control-grid { grid-template-columns: 1fr 1fr; }
}

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

/* SVG element styles applied via JS classes */
.bin-dot { stroke: none; }
.bin-dot.below { fill: var(--red); }
.bin-dot.above { fill: var(--blue); }
.hline.below { stroke: var(--red); }
.hline.above { stroke: var(--blue); }
.hline { stroke-width: 2; }
.hline.faint { stroke-width: 1.5; stroke-dasharray: 4 3; opacity: 0.35; }
.threshold-line { stroke: #999; stroke-width: 1; stroke-dasharray: 2 2; }

/* Size-gradient view: one smooth curve through the bins. */
.gradient-curve { fill: none; stroke: #1a1a1a; stroke-width: 2.2; opacity: 0.9; }

/* Discontinuity view: a local line on each side + the jump connector. */
.disc-fit { stroke-width: 2.4; fill: none; }
.disc-fit.below { stroke: var(--red); }
.disc-fit.above { stroke: var(--blue); }
.jump-connector { stroke: #333; stroke-width: 1.6; fill: none; }
.jump-label { font-family: var(--serif); font-size: 12px; fill: #1a1a1a; font-variant-numeric: tabular-nums; }
.rd-reported { font-family: var(--sans); font-size: 12px; color: var(--muted); }
.gap-arrow { stroke: #333; stroke-width: 1.2; fill: none; }
.gap-ci-band { fill: rgba(80, 80, 80, 0.18); stroke: rgba(80, 80, 80, 0.4); stroke-width: 0.5; }
.gap-label { font-family: var(--serif); font-size: 10.5px; fill: #1a1a1a; }
.axis path, .axis line { stroke: var(--hairline); }
.axis text { fill: var(--muted); font-size: 10px; }
.axis-title { fill: var(--muted); font-size: 10.5px; }

/* Caption */
#caption { margin-top: 6px; font-size: 13px; color: var(--ink); max-width: 1080px; }
#caption #caption-text { margin: 0 0 4px; }
#caption #diagnostics { margin: 0; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

footer { margin-top: 36px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--hairline); padding-top: 12px; }
footer a { color: var(--muted); }

input:disabled + span, label:has(input:disabled) { color: var(--muted); cursor: not-allowed; }
