/* Tokens. Chart roles come from the validated reference palette; the dark
   values are their own steps, checked against the dark surface. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --ink-1: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #6f6d68;
  --tick: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --wash: rgba(11, 11, 11, 0.04);
  --link: #1c5cab;
  --focus: #2a78d6;
  --series-nyc: #2a78d6;
  --series-nys: #eb6834;
  --series-fed: #1baf7a;
  --meter-fill: #2a78d6;
  --meter-track: #cde2fb;
  --tooltip-bg: #0b0b0b;
  --tooltip-ink: #ffffff;
  --tooltip-ink-2: #c3c2b7;

  --display: "Young Serif", Georgia, serif;
  --sans: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 12px;
  --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --ink-1: #ffffff;
    --ink-2: #c3c2b7;
    --ink-muted: #a3a197;
    --tick: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --wash: rgba(255, 255, 255, 0.05);
    --link: #86b6ef;
    --focus: #6da7ec;
    --series-nyc: #3987e5;
    --series-nys: #d95926;
    --series-fed: #199e70;
    --meter-fill: #3987e5;
    --meter-track: #184f95;
    --tooltip-bg: #ffffff;
    --tooltip-ink: #0b0b0b;
    --tooltip-ink-2: #52514e;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --ink-1: #ffffff;
  --ink-2: #c3c2b7;
  --ink-muted: #a3a197;
  --tick: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --wash: rgba(255, 255, 255, 0.05);
  --link: #86b6ef;
  --focus: #6da7ec;
  --series-nyc: #3987e5;
  --series-nys: #d95926;
  --series-fed: #199e70;
  --meter-fill: #3987e5;
  --meter-track: #184f95;
  --tooltip-bg: #ffffff;
  --tooltip-ink: #0b0b0b;
  --tooltip-ink-2: #52514e;
}

/* Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink-1);
  font: 400 16px/1.55 var(--sans);
  overflow-x: hidden;
}
a { color: var(--link); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { margin: 0; font-weight: 400; }
h2 { font-family: var(--display); font-size: 1.35rem; line-height: 1.25; }
h3 { font-size: 1rem; font-weight: 700; margin: 1.5rem 0 0.5rem; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: var(--gutter); top: 8px; background: var(--surface-1); padding: 8px 12px; z-index: 10; }

.masthead, main, .site-footer { max-width: 1200px; margin: 0 auto; padding: 0 var(--gutter); }

/* Masthead */
.masthead { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 16px; padding-bottom: 16px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink-1); text-decoration: none; font-weight: 700; }
.brand img { border-radius: 20%; }
.masthead nav { display: flex; gap: 20px; flex-wrap: wrap; }
.masthead nav a { color: var(--ink-2); text-decoration: none; font-size: 0.95rem; }
.masthead nav a:hover { color: var(--ink-1); text-decoration: underline; }

/* Intro */
.intro { padding: 32px 0 24px; max-width: 760px; }
.eyebrow { color: var(--ink-2); font-size: 0.85rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 12px; }
h1 { font-family: var(--display); font-size: clamp(2rem, 5vw, 3.1rem); line-height: 1.1; margin-bottom: 16px; }
.lede { font-size: 1.15rem; color: var(--ink-1); margin-bottom: 12px; }
.note { color: var(--ink-2); font-size: 0.95rem; }

/* Filters: one row above everything they scope */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px;
  padding: 16px 0; margin-bottom: 8px;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; border: 0; padding: 0; margin: 0; }
.field > span, .field > legend { font-size: 0.8rem; font-weight: 600; color: var(--ink-2); padding: 0; }
.field select, .field input[type="search"] {
  height: 40px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-1);
  max-width: 100%;
}
.field select { padding-right: 32px; }
.field-search { flex: 1 1 220px; }
.field-search input { width: 100%; }
.segmented { flex-direction: row; flex-wrap: wrap; align-items: center; }
.segmented legend { width: 100%; margin-bottom: 4px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: inline-flex; align-items: center; height: 40px; padding: 0 14px;
  border: 1px solid var(--border); background: var(--surface-1); font-size: 0.95rem; cursor: pointer;
}
.segmented label:first-of-type span { border-radius: 8px 0 0 8px; }
.segmented label:last-of-type span { border-radius: 0 8px 8px 0; border-left: 0; }
.segmented input:checked + span { background: var(--ink-1); color: var(--page); border-color: var(--ink-1); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* KPI row */
.kpis { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 12px; margin: 16px 0 24px; }
.hero, .tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.tile-label { font-size: 0.85rem; color: var(--ink-2); font-weight: 600; }
.hero-value { font-size: clamp(2.6rem, 6vw, 3.5rem); font-weight: 700; line-height: 1.05; margin: 6px 0; letter-spacing: -0.01em; }
.tile-value { font-size: 1.75rem; font-weight: 600; line-height: 1.2; margin-top: 6px; }
.tile-sub { font-size: 0.85rem; color: var(--ink-2); margin-top: 6px; }

/* Chart cards */
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card { margin: 0; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; min-width: 0; }
.card-wide { grid-column: 1 / -1; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.card-sub { color: var(--ink-2); font-size: 0.9rem; margin-top: 2px; }
.table-toggle {
  flex: none; height: 32px; padding: 0 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: transparent; font-size: 0.85rem; font-weight: 600; color: var(--ink-2);
}
.table-toggle:hover { background: var(--wash); color: var(--ink-1); }
.table-toggle[aria-pressed="true"] { background: var(--ink-1); color: var(--page); border-color: var(--ink-1); }
.card figcaption { color: var(--ink-2); font-size: 0.85rem; margin-top: 12px; }
.card figcaption:empty { display: none; }
.plot { width: 100%; min-height: 40px; }
.empty { color: var(--ink-2); padding: 24px 0; }

.viz-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 8px; font-size: 0.85rem; color: var(--ink-2); }
.viz-legend[hidden] { display: none; }
.viz-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.viz-legend-swatch { width: 12px; height: 12px; border-radius: 3px; }

/* SVG chart chrome */
.viz { display: block; overflow: visible; font-family: var(--sans); }
.viz-gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.viz-baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.viz-tick { fill: var(--tick); font-size: 12px; font-variant-numeric: tabular-nums; }
.viz-tick-group { fill: var(--ink-2); font-weight: 600; }
.viz-label { fill: var(--ink-1); font-size: 14px; }
.viz-value { fill: var(--ink-2); font-size: 13px; font-weight: 600; }
.viz-hit { fill: transparent; }
.viz-mark { outline: none; cursor: default; }
.viz-mark.is-hover .viz-hit, .viz-mark:focus-visible .viz-hit { fill: var(--wash); }
.viz-mark:focus-visible .viz-hit { stroke: var(--focus); stroke-width: 2; }

.viz-tooltip {
  position: absolute; z-index: 20; pointer-events: none; max-width: min(360px, calc(100vw - 16px));
  background: var(--tooltip-bg); color: var(--tooltip-ink); border-radius: 8px; padding: 10px 12px;
  font-size: 0.85rem; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}
.viz-tooltip-title { color: var(--tooltip-ink-2); margin-bottom: 4px; }
.viz-tooltip-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.viz-tooltip-row strong { font-variant-numeric: tabular-nums; }
.viz-tooltip-row span:last-child { color: var(--tooltip-ink-2); white-space: nowrap; }
.viz-tooltip-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
thead th { font-size: 0.8rem; color: var(--ink-2); font-weight: 600; border-bottom-color: var(--axis); white-space: nowrap; }
tbody th { font-weight: 600; }
.num, .viz-table td { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.viz-table th:not(:first-child) { text-align: right; }
.nowrap { white-space: nowrap; }
.cell-sub { display: block; color: var(--ink-2); font-size: 0.8rem; margin-top: 2px; }

/* Programs */
.programs, .awards, .methodology { margin-top: 48px; }
.section-lede { color: var(--ink-2); margin-top: 4px; }
.program-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
@media (max-width: 1000px) { .program-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .program-grid { grid-template-columns: minmax(0, 1fr); } }
.program .tile-label { font-weight: 400; color: var(--ink-1); min-height: 3em; }
.meter { height: 8px; border-radius: 4px; background: var(--meter-track); margin-top: 10px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--meter-fill); border-radius: 4px; }

/* Awards table */
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px 24px; flex-wrap: wrap; margin-bottom: 12px; }
.downloads { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.downloads button, .more {
  height: 36px; padding: 0 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-1); font-size: 0.9rem; font-weight: 600;
}
.downloads button:hover, .more:hover { background: var(--wash); }
.downloads a { font-size: 0.9rem; font-weight: 600; }
.award-table { background: var(--surface-1); border-radius: var(--radius); }
.award-table thead button { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; text-decoration: underline; text-decoration-color: var(--axis); text-underline-offset: 3px; }
.award-table thead button[data-dir="desc"]::after { content: " ↓"; }
.award-table thead button[data-dir="asc"]::after { content: " ↑"; }
.award-table td:nth-child(4) { min-width: 240px; }
.more { display: block; margin: 16px auto 0; }

/* Methodology */
.method-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px 40px; }
.methodology p, .methodology li { color: var(--ink-1); max-width: 68ch; }
.methodology ul { padding-left: 1.2rem; margin: 0; }
.methodology li { margin-bottom: 8px; }
.source-table { margin-bottom: 12px; }
.fine { color: var(--ink-2) !important; font-size: 0.85rem; margin-top: 16px; }

.site-footer { margin-top: 64px; padding-top: 24px; padding-bottom: 40px; border-top: 1px solid var(--border); color: var(--ink-2); font-size: 0.9rem; }
.noscript { max-width: 1200px; margin: 16px auto; padding: 0 var(--gutter); }

/* Narrow screens */
@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { grid-column: 1 / -1; }
  .cards, .method-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .field:not(.field-search):not(.segmented) { flex: 1 1 calc(50% - 8px); }
  .field select { width: 100%; }
  .card { padding: 16px; }
  /* The award table becomes stacked rows so nothing scrolls sideways. */
  .award-table thead { position: absolute; left: -9999px; }
  .award-table, .award-table tbody, .award-table tr, .award-table td { display: block; width: 100%; }
  .award-table tr { padding: 12px 0; border-bottom: 1px solid var(--grid); }
  .award-table td { display: grid; grid-template-columns: 7.5em minmax(0, 1fr); column-gap: 8px; border: 0; padding: 2px 12px; text-align: left; white-space: normal; }
  .award-table td::before { content: attr(data-label); color: var(--ink-2); font-size: 0.8rem; font-weight: 600; padding-top: 2px; }
  .award-table td:nth-child(4) { display: block; min-width: 0; }
  .award-table td:nth-child(4)::before { display: block; }
  .award-table td.empty { display: block; }
  .award-table td.empty::before { content: none; }
}

@media (forced-colors: active) {
  .viz path, .viz rect:not(.viz-hit) { forced-color-adjust: none; }
}
@media print {
  .table-toggle, .downloads, .more { display: none; }
}
