:root {
  --bg: #ffffff;
  --bg-alt: #f7f7f7;
  --text-body: #3c3c3c;
  --text-secondary: #6e6e6e;
  --text-muted: #8c8c8c;
  --link: #4c6c9b;
  --border: #e5e5e5;
  --gridline: #e7e7e7;
  --axis: #b9b9b9;
  --accent: #4c6c9b;
  --series-closed: #4c6c9b;   /* dusty steel blue */
  --series-open: #b87f35;     /* muted ochre */
  --series-tertiary: #4c8c6e; /* soft green, reserved */
  --series-quaternary: #b13f64; /* muted red, reserved */
  --font-serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --bg-alt: #1b1f24;
    --text-body: #d8d8d5;
    --text-secondary: #a3a39c;
    --text-muted: #82827c;
    --link: #7ea3d1;
    --border: #2c3038;
    --gridline: #2a2e35;
    --axis: #454b54;
    --accent: #7ea3d1;
    --series-closed: #7ea3d1;
    --series-open: #d1a05f;
    --series-tertiary: #7ab598;
    --series-quaternary: #d1728c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-body);
  font-family: var(--font-serif);
  line-height: 1.55;
}

a { color: var(--link); }

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 24px 100px;
  display: grid;
  grid-template-columns: 190px minmax(0, 700px);
  gap: 56px;
  align-items: start;
}

@media (max-width: 880px) {
  .page { grid-template-columns: 1fr; }
  .toc { position: static; order: -1; }
}

/* ---- Sidebar TOC ---- */
.toc {
  position: sticky;
  top: 32px;
  font-family: var(--font-sans);
}
.toc-title {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.toc-link {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 5px 0;
  border-left: 2px solid transparent;
  padding-left: 10px;
  margin-left: -11px;
}
.toc-link:hover { color: var(--text-body); }
.toc-link.active {
  color: var(--text-body);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* ---- Content / editorial ---- */
.content { min-width: 0; }

.hero { margin-bottom: 8px; }
.eyebrow {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 10px;
}
h1 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 2rem;
  line-height: 1.25;
  margin: 0 0 16px;
}
.byline {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin: 0 0 8px;
}

h2 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.4rem;
  margin: 44px 0 14px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
h3 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.1rem;
  margin: 30px 0 10px;
}
section p { margin: 0 0 14px; color: var(--text-body); }
section p code { font-family: ui-monospace, monospace; font-size: 0.85em; color: var(--text-secondary); }
.disclaimer { font-size: 0.8rem; color: var(--text-muted); font-family: var(--font-sans); }

/* ---- Viz block (Grapher-style chart card) ---- */
.viz-block {
  margin: 22px 0 8px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.viz-header { padding: 18px 20px 4px; }
.viz-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.15rem;
  margin: 0 0 4px;
}
.viz-subtitle {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 12px;
}

.viz-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px 10px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-sans);
}
.view-tabs { display: flex; gap: 4px; }
.view-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 4px 8px 6px;
  cursor: pointer;
}
.view-tab.active { color: var(--text-body); border-bottom-color: var(--accent); font-weight: 600; }
.view-tab:hover:not(.active) { color: var(--text-body); }

.icon-row { display: flex; gap: 4px; }
.icon-btn {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.75rem;
  border-radius: 2px;
  cursor: pointer;
}
.icon-btn:hover { color: var(--text-body); border-color: var(--axis); }

.viz-body { padding: 12px 20px 4px; }
.view-pane[hidden] { display: none; }

#chart-container svg { display: block; width: 100%; height: auto; font-family: var(--font-sans); }
.axis-label { fill: var(--text-secondary); font-size: 11px; }
.tick-label { fill: var(--text-muted); font-size: 10px; }
.gridline { stroke: var(--gridline); stroke-width: 1; }
.axis-line { stroke: var(--axis); stroke-width: 1; }
.point-label { fill: var(--text-secondary); font-size: 10px; pointer-events: none; }
.callout-label { font-size: 10px; font-weight: 600; pointer-events: none; }
.point { stroke: var(--bg); stroke-width: 1.25; cursor: pointer; }
.empty-note {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 40px 0;
  text-align: center;
}
.chart-legend {
  display: flex; gap: 18px; padding: 6px 2px 14px;
  font-family: var(--font-sans); font-size: 0.78rem; color: var(--text-secondary);
}
.legend-swatch { width: 9px; height: 9px; display: inline-block; margin-right: 5px; border-radius: 1px; }
.legend-line {
  width: 14px;
  height: 0;
  display: inline-block;
  margin-right: 5px;
  border-top: 1.5px dashed;
  vertical-align: middle;
}

/* ---- Sources strip ---- */
.sources-strip {
  border-top: 1px solid var(--border);
  padding: 10px 20px;
  font-family: var(--font-sans);
}
.sources-strip summary {
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
}
.sources-strip summary::-webkit-details-marker { display: none; }
.sources-strip summary::before { content: "\25B8  "; }
.sources-strip[open] summary::before { content: "\25BE  "; }
.sources-content { padding: 10px 0 2px; font-size: 0.8rem; color: var(--text-secondary); }
.sources-content p { margin: 0 0 8px; }
.sources-content code { font-family: ui-monospace, monospace; }

/* ---- Controls ---- */
.controls { font-family: var(--font-sans); margin-bottom: 24px; }
.controls-header { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.text-btn {
  background: none; border: none;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--link);
  cursor: pointer;
  padding: 2px 0;
}
.text-btn:hover { text-decoration: underline; }

.sliders {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px 28px;
}
.slider-row label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.slider-row .value { color: var(--text-body); font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 2px;
  background: var(--axis);
  border-radius: 1px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
  cursor: pointer;
  margin-top: 0;
}
input[type="range"]::-moz-range-track { height: 2px; background: var(--axis); border-radius: 1px; }
input[type="range"]::-moz-range-thumb {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
  cursor: pointer;
}

/* ---- Filter row ---- */
.filter-row {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--font-sans);
  margin-bottom: 10px;
}
.filter-label { font-size: 0.8rem; color: var(--text-secondary); }
.segmented { display: inline-flex; border: 1px solid var(--border); }
.segmented button {
  border: none; background: none;
  padding: 5px 12px;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--bg-alt); color: var(--text-body); font-weight: 600; }
.skipped-note { font-size: 0.75rem; color: var(--text-muted); }

/* ---- Table (plain OWID data-table look) ---- */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.82rem;
}
th, td {
  text-align: right;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
th:first-child, td:first-child, th:nth-child(2), td:nth-child(2) {
  text-align: left;
  font-variant-numeric: normal;
}
th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--axis);
}
th.sorted { color: var(--text-body); }
th.sorted::after { content: " \25BE"; }
th.sorted.asc::after { content: " \25B4"; }
tbody tr:hover { background: var(--bg-alt); }

/* ---- Tooltip ---- */
.tooltip {
  position: fixed;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 10px 12px;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--text-body);
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  pointer-events: none;
  max-width: 260px;
  z-index: 10;
}
.tooltip .t-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 12px; color: var(--text-secondary); }
.tooltip .t-row b { color: var(--text-body); font-weight: 600; }
