/* Matches the project page: cream paper, deep red accent, DM Serif headings.
   Numbers stay in the sans face. */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  color-scheme: light;
  --bg: #FDF8F0;
  --surface: #FFFFFF;
  --surface2: #F5EDE0;
  --ink: #1A0A00;
  --ink2: #5C4033;
  --ink3: #8A6A5A;
  --accent: #B91C1C;
  --border: rgba(90,20,10,0.12);
  --grid: #EEE6DA;
  --axis: #C9BBAA;
  /* chart series (validated: categorical slots 1 and 2) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --up: #9c2a12;
  --down: #006300;
  --serif: 'DM Serif Display', Georgia, serif;
  --sans: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--sans); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.55; overflow-x: hidden; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; border-radius: 4px; }

.top { border-bottom: 1px solid var(--border); background: rgba(253,248,240,0.95); }
.top-inner { max-width: 1240px; margin: 0 auto; padding: 1.1rem 1.5rem; display: flex; align-items: center; gap: 1.25rem; }
.back { font-size: 0.85rem; color: var(--ink2); text-decoration: none; border: 1px solid var(--border); border-radius: 999px; padding: 0.35rem 0.9rem; white-space: nowrap; }
.back:hover { color: var(--accent); border-color: var(--accent); }
h1 { font-family: var(--serif); font-weight: 400; font-size: 1.6rem; line-height: 1.15; }
.sub { font-size: 0.85rem; color: var(--ink2); }

main { max-width: 1240px; margin: 0 auto; padding: 1.25rem 1.5rem 3rem; }

.filters { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1rem; }
.filter { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.filter.grow { flex: 1; min-width: 260px; }
.filter label { font-size: 0.78rem; font-weight: 500; color: var(--ink2); }
.filter output { color: var(--ink); font-weight: 700; }
select { font: inherit; font-size: 0.92rem; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.7rem; max-width: 100%; }
.timeline { display: flex; align-items: center; gap: 0.6rem; }
.timeline input { flex: 1; accent-color: var(--accent); min-width: 0; }
.play { width: 38px; height: 38px; flex-shrink: 0; border-radius: 50%; border: none; background: var(--accent); color: #fff; font-size: 0.9rem; cursor: pointer; }
.play:hover { background: #991616; }

.grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 1rem; margin-bottom: 1rem; align-items: start; }
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.lower { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 1rem; margin-bottom: 1.5rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1.1rem 1.2rem; min-width: 0; }
.card h2 { font-family: var(--serif); font-weight: 400; font-size: 1.2rem; line-height: 1.25; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 0.5rem; flex-wrap: wrap; }
.card-sub { font-size: 0.82rem; color: var(--ink3); margin-top: 0.15rem; }
.link-btn { background: none; border: none; color: var(--accent); font: inherit; font-size: 0.85rem; font-weight: 500; cursor: pointer; padding: 0.2rem 0; white-space: nowrap; }

.map-wrap { position: relative; }
#map { width: 100%; height: auto; display: block; }
#map .state { stroke: #fff; stroke-width: 1; cursor: pointer; transition: opacity 0.15s; }
#map .state:hover, #map .state:focus { stroke: var(--ink); stroke-width: 1.5; outline: none; }
#map .state.selected { stroke: var(--ink); stroke-width: 2.5; }
#map .state.nodata { fill: #EFE9E0; }
.legend { display: flex; align-items: flex-end; gap: 2px; margin-top: 0.5rem; flex-wrap: wrap; }
.legend .swatch { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 34px; max-width: 70px; }
.legend .swatch span:first-child { height: 10px; border-radius: 2px; }
.legend .swatch span:last-child { font-size: 0.7rem; color: var(--ink3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hint { font-size: 0.8rem; color: var(--ink3); margin-top: 0.6rem; }

.table-wrap { margin-top: 0.75rem; max-height: 320px; overflow: auto; border-top: 1px solid var(--grid); }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th { position: sticky; top: 0; background: var(--surface); text-align: left; }
th button { background: none; border: none; font: inherit; font-weight: 700; color: var(--ink2); cursor: pointer; padding: 0.5rem 0.25rem; }
td { padding: 0.35rem 0.25rem; border-top: 1px solid var(--grid); }
td:last-child, th:last-child { text-align: right; font-variant-numeric: tabular-nums; }

.detail { display: flex; flex-direction: column; }
.eyebrow { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
#detail-name { font-size: 1.7rem; margin-bottom: 0.75rem; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.tile { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 0.7rem 0.8rem; }
.tile .value { font-size: 1.45rem; font-weight: 700; line-height: 1.15; letter-spacing: -0.01em; }
.tile .label { font-size: 0.78rem; color: var(--ink2); line-height: 1.3; margin-top: 0.15rem; }
.tile .delta { font-size: 0.78rem; font-weight: 700; margin-top: 0.25rem; }
.tile .delta.up { color: var(--up); }
.tile .delta.down { color: var(--down); }
.tile .delta.flat { color: var(--ink3); }
.tile .est { font-size: 0.7rem; color: var(--ink3); font-style: italic; }
.note { font-size: 0.8rem; color: var(--ink3); margin-top: auto; padding-top: 0.75rem; }

.chart { position: relative; width: 100%; height: 260px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis text { fill: var(--ink3); font-size: 11px; font-family: var(--sans); font-variant-numeric: tabular-nums; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .forecast-line { fill: none; stroke-width: 2; stroke-dasharray: 5 4; stroke-linecap: round; }
.chart .marker { stroke: var(--ink); stroke-width: 1; opacity: 0.35; }
.chart .crosshair { stroke: var(--ink2); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .label { font-size: 11.5px; font-weight: 700; font-family: var(--sans); }
.key { display: flex; gap: 0.9rem; flex-wrap: wrap; font-size: 0.8rem; color: var(--ink2); }
.key span { display: inline-flex; align-items: center; gap: 0.35rem; white-space: nowrap; }
.key i { display: inline-block; width: 16px; height: 0; border-top: 2px solid; }
.key i.dashed { border-top-style: dashed; }
.forecast { font-size: 0.85rem; color: var(--ink2); margin-top: 0.5rem; }

.maker { margin-top: 0.85rem; }
.maker-row { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.88rem; margin-bottom: 0.3rem; }
.maker-row b { font-variant-numeric: tabular-nums; }
.maker-bar { height: 10px; background: var(--surface2); border-radius: 5px; overflow: hidden; }
.maker-bar span { display: block; height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }

.facts .facts-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin: 0.9rem 0; }
.facts h3 { font-size: 0.85rem; font-weight: 700; margin-bottom: 0.35rem; }
.facts ul { padding-left: 1rem; font-size: 0.86rem; color: var(--ink2); }
.facts li { margin-bottom: 0.25rem; }

.sources { font-size: 0.8rem; color: var(--ink2); display: grid; gap: 0.5rem; max-width: 900px; }
.sources code { font-size: 0.78rem; background: var(--surface2); padding: 0.05rem 0.3rem; border-radius: 4px; }

.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 20px rgba(26,10,0,0.14); padding: 0.55rem 0.7rem; font-size: 0.8rem; min-width: 150px; max-width: 240px; }
.tooltip .tt-title { font-weight: 700; margin-bottom: 0.25rem; }
.tooltip .tt-row { display: flex; align-items: center; gap: 0.45rem; }
.tooltip .tt-row b { font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.tooltip .tt-row span { color: var(--ink2); }
.tooltip .tt-key { width: 12px; border-top: 2px solid; }
.tooltip .tt-key.dashed { border-top-style: dashed; }
.tooltip .tt-note { color: var(--ink3); font-style: italic; margin-top: 0.2rem; }

.loading main { opacity: 0.5; }

@media (max-width: 980px) {
  .grid, .charts, .lower { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .top-inner { flex-direction: column; align-items: flex-start; gap: 0.6rem; padding: 0.9rem 1rem; }
  main { padding: 1rem 1rem 2.5rem; }
  .filter, .filter.grow { flex: 1 1 100%; }
  .facts .facts-grid { grid-template-columns: 1fr; }
  .chart { height: 220px; }
  .tile .value { font-size: 1.25rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
