/* story.css — shared typography, layout and chart styles (tokens match the R prototypes). */

/* Steven Ponce type system (personal-website R/utils/fonts.R): Big Shoulders for titles,
   DM Sans for text and chart labels, JetBrains Mono for captions. Self-hosted, latin subset, SIL OFL 1.1. */
@font-face { font-family: "Big Shoulders"; font-weight: 700; font-display: swap; src: url("../fonts/big-shoulders-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Big Shoulders"; font-weight: 800; font-display: swap; src: url("../fonts/big-shoulders-latin-800-normal.woff2") format("woff2"); }
@font-face { font-family: "DM Sans"; font-weight: 400; font-display: swap; src: url("../fonts/dm-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "DM Sans"; font-weight: 600; font-display: swap; src: url("../fonts/dm-sans-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "DM Sans"; font-weight: 700; font-display: swap; src: url("../fonts/dm-sans-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 400; font-display: swap; src: url("../fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2"); }

:root {
  --paper: #f4f1ea;
  --ink: #2b2b2b;
  --muted: #6f6a63;
  --grid: #e2ddd2;
  --note-bg: #ebe6db;
  --focus: #2f3e50;
  --pad: 28px;
  --font-title: "Big Shoulders", "Arial Narrow", sans-serif;
  --font-text: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-caption: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0; color: var(--ink); background: var(--paper);
  font-family: var(--font-text);
  font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.story { max-width: 1200px; margin: 0 auto; padding: 32px var(--pad) 64px; }

.story-header { margin-bottom: 40px; }
.story-header h1 { font-family: var(--font-title); font-weight: 800; font-size: 3.1rem; line-height: 1.02; margin: 0 0 10px; }
.byline { font-size: 0.9rem; color: var(--muted); margin: 10px 0 0; }
.story-dek { font-size: 1.15rem; color: var(--muted); margin: 0; max-width: 46em; }

.chapter { margin: 0 0 72px; }
.eyebrow { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.chart-title { font-family: var(--font-title); font-weight: 800; font-size: 2.15rem; line-height: 1.05; margin: 0 0 8px; }
.chart-subtitle { font-size: 1.1rem; color: var(--muted); margin: 0 0 20px; max-width: 52em; }

/* view switch: two explicit views, no morph */
.view-switch { display: inline-flex; gap: 10px; margin: 0 0 16px; }
.view-switch button {
  font: inherit; font-size: 0.95rem; padding: 5px 11px; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--muted); background: var(--paper); color: var(--muted);
}
.view-switch button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }

/* key: top-to-bottom stack order; each item toggles a highlight */
.key { display: grid; grid-template-columns: repeat(6, max-content); column-gap: 28px; row-gap: 6px; margin: 0 0 14px; }
.key-item {
  font: inherit; font-size: 0.92rem; color: var(--ink); background: none; border: 0; padding: 2px 4px 2px 0;
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer; border-radius: 3px;
}
.key-item .swatch { width: 13px; height: 13px; border: 1px solid; display: inline-block; }
.key-item[aria-pressed="true"] { font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

/* limitation note: fixed, above the chart, never a footnote */
.limitation {
  border-left: 3px solid var(--ink); padding: 2px 0 2px 12px; margin: 0 0 8px;
  font-size: 0.95rem; color: var(--ink); max-width: 46em;
}

.chart { position: relative; margin: 0; width: 100%; }
.chart svg { display: block; overflow: visible; font-family: inherit; }
.chart .seg { cursor: pointer; }
.chart .seg:focus { outline: none; stroke: var(--focus); stroke-width: 2.5px; }
.chart .seg-label { font-size: 14px; pointer-events: none; }
.chart .total { font-size: 17px; font-weight: 700; fill: var(--ink); }
.chart .axis-note { font-size: 13px; fill: var(--muted); }
.chart .period-label { font-size: 16px; font-weight: 700; fill: var(--ink); }
.chart .period-sub { font-size: 13.5px; fill: var(--muted); }

.tooltip {
  position: absolute; z-index: 5; max-width: 280px; pointer-events: none;
  background: #fff; border: 1px solid var(--grid); border-radius: 4px; padding: 8px 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); font-size: 0.85rem; line-height: 1.35;
}
.tooltip p { margin: 0 0 2px; }
.tooltip .tooltip-title { font-weight: 700; margin-bottom: 4px; }
.tooltip .tooltip-detail { color: var(--muted); font-size: 0.78rem; margin-top: 6px; }

.caption { font-family: var(--font-caption); font-size: 0.74rem; line-height: 1.6; color: var(--muted); margin: 18px 0 12px; max-width: 78em; }

/* accessible data tables */
.data-table { margin: 6px 0; font-size: 0.85rem; }
.data-table summary { cursor: pointer; color: var(--ink); font-weight: 600; padding: 4px 0; }
.table-scroll { overflow-x: auto; margin-top: 6px; }
.data-table table { border-collapse: collapse; min-width: 100%; }
.data-table caption { text-align: left; color: var(--muted); padding: 0 0 6px; }
.data-table th, .data-table td { padding: 4px 10px 4px 0; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
.data-table thead th { font-weight: 600; border-bottom: 1px solid var(--muted); }
.data-table tbody th { font-weight: 400; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Chapter 2 */
.key-list { display: flex; flex-direction: column; gap: 2px; margin-left: 150px; }
.key-item.static { cursor: default; padding: 0; }
.key-item .swatch.round { border-radius: 50%; width: 14px; height: 14px; }
#ch2 .chart .size-label { font-size: 16px; font-weight: 700; fill: var(--ink); }
#ch2 .chart .unk-label { font-size: 15px; fill: var(--muted); }
#ch2 .chart .rev-label { font-size: 16px; font-weight: 700; fill: #722F37; pointer-events: none; }
#ch2 .chart .rev-label.inside { fill: #ffffff; }
#ch2 .caption + .caption { margin-top: 0; }

/* shared pill controls (Chapters 3-4) */
.controls { display: flex; flex-wrap: wrap; gap: 10px 28px; margin: 0 0 14px; }
.control-group { display: flex; flex-direction: column; gap: 6px; }
.control-label { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.pill-group { display: flex; flex-wrap: wrap; gap: 6px; }
.pill-group button {
  font: inherit; font-size: 0.88rem; padding: 4px 10px; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--muted); background: var(--paper); color: var(--muted);
}
.pill-group button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }

/* Chapter 3 */
.size-key { display: flex; align-items: center; gap: 14px; font-size: 0.85rem; color: var(--muted); margin: 4px 0 6px 50px; }
.size-key-item { display: inline-flex; align-items: center; gap: 4px; }
#ch3 .chart .panel-title { font-size: 14.5px; font-weight: 700; fill: var(--ink); }
#ch3 .chart .grid { stroke: var(--grid); stroke-width: 1; }
#ch3 .chart .boundary { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
#ch3 .chart .boundary-label { font-size: 12px; fill: var(--muted); }
#ch3 .chart .tick { font-size: 12.5px; fill: var(--muted); }
#ch3 .chart .axis-title { font-size: 14px; fill: var(--muted); }
#ch3 .chart circle.mark { cursor: pointer; }
#ch3 .chart circle.mark:focus { outline: none; stroke: var(--ink); stroke-width: 2px; }
.strip-block { margin-top: 26px; }
.strip-title { font-family: var(--font-title); font-weight: 700; font-size: 1.45rem; line-height: 1.1; margin: 0 0 4px; }
.strip-risk { font-size: 0.98rem; margin: 0 0 10px; color: var(--ink); }
.strip-note { font-size: 0.85rem; color: var(--muted); margin: 6px 0 0; max-width: 60em; }
#ch3 .chart .strip-size { font-size: 13px; fill: var(--ink); }
#ch3 .chart .strip-n { fill: var(--muted); }
#ch3 .chart .lollipop { stroke: var(--grid); stroke-width: 3; }
#ch3 .chart .strip-label { font-size: 15px; fill: var(--ink); }
.tooltip .tooltip-detail { white-space: pre-line; }

.control-note { font-size: 0.85rem; color: var(--muted); margin: 0 0 12px; max-width: 52em; }
.control-group .control-note { margin: 2px 0 0; }

/* Chapter 4 */
.limitation.compact { border-left: 2px solid var(--muted); font-size: 0.9rem; padding-left: 10px; max-width: 62em; margin-bottom: 16px; }
.ch4-body { display: grid; grid-template-columns: minmax(0, 1fr) 210px; gap: 28px; align-items: start; }
#ch4 .chart .col-head { font-size: 13px; fill: var(--muted); }
#ch4 .chart .grid { stroke: var(--grid); stroke-width: 1; }
#ch4 .chart .sep { stroke: var(--grid); stroke-width: 1; }
#ch4 .chart .zero { stroke: var(--muted); stroke-width: 1.2; }
#ch4 .chart .zero-label, #ch4 .chart .dir-label { font-size: 12.5px; fill: var(--muted); }
#ch4 .chart .tick { font-size: 13px; fill: var(--muted); }
#ch4 .chart .axis-title { font-size: 13.5px; fill: var(--muted); }
#ch4 .chart .cut-name { font-size: 15px; font-weight: 700; fill: var(--ink); }
#ch4 .chart .group-line { font-size: 13px; fill: var(--muted); }
#ch4 .chart .est-pp { font-size: 16px; font-weight: 700; fill: var(--ink); }
#ch4 .chart .est-ci { font-size: 13.5px; fill: var(--muted); }
#ch4 .chart .interval { cursor: pointer; }
#ch4 .chart .interval .ci { stroke: #2f3e50; stroke-linecap: round; }
#ch4 .chart .interval .pt { fill: #2f3e50; }
#ch4 .chart .interval:focus { outline: none; }
#ch4 .chart .interval:focus .hit { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 2 2; }
.overlap h3 { font-family: var(--font-title); font-weight: 700; font-size: 1.25rem; margin: 30px 0 8px; line-height: 1.1; }
.overlap table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.overlap th, .overlap td { padding: 7px 8px; text-align: left; border-bottom: 1px solid var(--grid); }
.overlap thead th { font-weight: 600; color: var(--muted); font-size: 0.8rem; }
.overlap tbody th { font-weight: 400; }
.overlap .num { text-align: right; font-variant-numeric: tabular-nums; }
.overlap tr.within { background: var(--note-bg); }
.overlap tr.within td { font-weight: 700; }
.overlap-note { font-family: var(--font-caption); font-size: 0.7rem; line-height: 1.55; color: var(--muted); margin: 8px 0 0; }
.interval-note { font-size: 0.85rem; color: var(--muted); margin: 10px 0 0; max-width: 60em; }

/* story in four findings: restrained editorial summary (no cards, no KPI numbers) */
.findings { border-top: 1px solid var(--ink); border-bottom: 1px solid var(--grid); padding: 18px 0 20px; margin: 0 0 56px; }
.findings-title { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink); margin: 0 0 14px; }
.findings-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 40px; }
.findings-list li p { margin: 0; font-size: 1rem; line-height: 1.5; }
.findings-list .finding-label { font-family: var(--font-title); font-weight: 700; font-size: 1.2rem; line-height: 1.1; margin-bottom: 4px; }
.findings-note { font-family: var(--font-caption); font-size: 0.72rem; color: var(--muted); margin: 16px 0 0; }

/* story prose: bridge, conclusion, references */
.bridge { font-size: 1.15rem; line-height: 1.5; max-width: 40em; margin: 0 0 28px; color: var(--ink); }
.conclusion { margin: 0 0 56px; max-width: 46em; }
.conclusion h2, .references h2 { font-family: var(--font-title); font-weight: 800; font-size: 2.15rem; line-height: 1.05; margin: 0 0 12px; }
.conclusion p { font-size: 1.15rem; line-height: 1.55; margin: 0 0 14px; }
.references { border-top: 1px solid var(--grid); padding-top: 28px; max-width: 64em; }
.references h3 { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin: 22px 0 8px; }
.references ol { margin: 0; padding-left: 1.6em; }
.references li { font-size: 0.92rem; line-height: 1.5; margin: 0 0 10px; }
.references .ref-use { display: block; color: var(--muted); font-size: 0.85rem; }
.references a { color: var(--ink); text-underline-offset: 2px; word-break: break-word; }
.references .note { font-size: 0.85rem; color: var(--muted); }
.site-footer { font-family: var(--font-caption); font-size: 0.72rem; color: var(--muted); margin-top: 36px; }
.site-footer a { color: var(--muted); }

.chapter-pending .pending-note { color: var(--muted); margin: 0; }
.load-error { color: #722F37; font-weight: 600; }

button:focus-visible, summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

@media (max-width: 640px) {
  :root { --pad: 14px; }
  .story { padding-top: 22px; }
  .story-header h1 { font-size: 2.3rem; }
  .story-dek { font-size: 1rem; }
  .chart-title { font-size: 1.75rem; }
  .bridge, .conclusion p { font-size: 1.02rem; }
  .findings-list { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .findings-list li p { font-size: 0.95rem; }
  .conclusion h2, .references h2 { font-size: 1.75rem; }
  .chart-subtitle { font-size: 0.98rem; }
  .key { grid-template-columns: repeat(2, max-content); grid-auto-flow: column; grid-template-rows: repeat(3, auto); column-gap: 36px; }
  .limitation { font-size: 0.88rem; }
  .chart .seg-label { font-size: 13px; }
  .chart .total { font-size: 15px; }
  .chart .period-label { font-size: 14px; }
  .chart .period-sub { font-size: 12px; }
  .key-list { margin-left: 0; }
  #ch2 .chart .size-label { font-size: 15px; }
  #ch2 .chart .unk-label { font-size: 13.5px; }
  #ch2 .chart .rev-label { font-size: 15px; }
  .size-key { margin-left: 48px; }
  #ch3 .chart .panel-title { font-size: 14px; }
  #ch3 .chart .strip-label { font-size: 14px; }
  #ch3 .chart .strip-size { font-size: 12px; }
  .pill-group button { font-size: 0.84rem; padding: 4px 8px; }
  .ch4-body { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .limitation.compact { font-size: 0.84rem; }
  #ch4 .chart .cut-name { font-size: 14px; }
  #ch4 .chart .group-line { font-size: 12px; }
  #ch4 .chart .est-pp { font-size: 14.5px; }
  #ch4 .chart .est-ci { font-size: 12px; }
  #ch4 .chart .dir-label, #ch4 .chart .zero-label { font-size: 11.5px; }
  .overlap h3 { margin-top: 18px; }
}
