:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6e69;
  --axis: #c3c2b7;
  --grid: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --prevention: #2a78d6;
  --relief: #eb6834;
  --rough: #6250d6;
  --support: #1baf7a;
  --context: #a3a29b;
  --up: #b3261e;      /* more households homeless = worse */
  --down: #006300;
  --zero: #eceae4;
  --focus: #2a78d6;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9a998f;
    --axis: #383835;
    --grid: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --prevention: #3987e5;
    --relief: #d95926;
    --rough: #9085e9;
    --support: #199e70;
    --context: #6b6a64;
    --up: #f28b82;
    --down: #0ca30c;
    --zero: #2c2c2a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --ink: #f0efec; --ink-2: #c3c2b7;
  --muted: #9a998f; --axis: #383835; --grid: #2c2c2a; --border: rgba(255,255,255,.10); --accent: #3987e5;
  --prevention: #3987e5; --relief: #d95926; --rough: #9085e9; --support: #199e70; --context: #6b6a64;
  --up: #f28b82; --down: #0ca30c; --zero: #2c2c2a; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px; z-index: 10; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.header-inner { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; padding-top: 16px; padding-bottom: 8px; flex-wrap: wrap; }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h1 a { color: inherit; text-decoration: none; }
.tagline { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; }
.updated { font-size: 12.5px; color: var(--ink-2); text-align: right; }
.updated b { color: var(--ink); font-weight: 600; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 10px 12px; color: var(--ink-2); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; font-weight: 500; font-size: 14.5px; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

main { padding-top: 20px; padding-bottom: 40px; min-height: 60vh; }
.loading { color: var(--ink-2); padding: 40px 0; }
h2 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.01em; }
h3 { font-size: 16px; margin: 0 0 2px; }
.lede { color: var(--ink-2); margin: 0 0 16px; max-width: 70ch; }
.section { margin-top: 28px; }
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.note { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card h3 + .sub { margin: 0 0 10px; color: var(--ink-2); font-size: 13px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 860px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }

/* headline */
.headline { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
.headline .hero { font-size: 52px; font-weight: 650; line-height: 1; letter-spacing: -0.02em; margin: 6px 0 8px; }
.headline .hero-label { color: var(--ink-2); font-size: 14px; }
.summary-card { margin-top: 16px; }
.summary-card p.summary { margin: 6px 0 0; color: var(--ink); font-size: 15.5px; line-height: 1.6; }
.headline-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 2fr); gap: 24px; align-items: start; }
@media (max-width: 860px) { .headline-grid { grid-template-columns: minmax(0, 1fr); } }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.tile .label { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 26px; font-weight: 600; margin-top: 2px; }
.tile .delta { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.delta .up { color: var(--up); font-weight: 600; }
.delta .down { color: var(--down); font-weight: 600; }
.delta .flat { color: var(--ink-2); font-weight: 600; }

/* controls */
.controls { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: end; margin: 0 0 12px; }
.control { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--ink-2); }
select, input[type="search"], input[type="text"] {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--axis); border-radius: 8px; padding: 7px 10px; min-width: 0; max-width: 100%;
}
.seg { display: inline-flex; border: 1px solid var(--axis); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 13.5px; background: var(--surface); color: var(--ink-2); border: 0; padding: 7px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--axis); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.btn { font: inherit; font-size: 13.5px; background: var(--surface); color: var(--ink); border: 1px solid var(--axis); border-radius: 8px; padding: 7px 12px; cursor: pointer; text-decoration: none; display: inline-flex; gap: 6px; align-items: center; }
.btn:hover { background: var(--surface-2); }

/* legend */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin: 0 0 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* charts */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11.5px; font-family: inherit; }
.chart .axis path { display: none; }
.chart .axis line { stroke: var(--grid); }
.chart .baseline { stroke: var(--axis); }
.chart .val { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hover-band { fill: var(--ink); opacity: 0.05; }
.empty { color: var(--muted); font-size: 13px; padding: 24px 0; text-align: center; }

/* tooltip */
.tooltip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 6px 24px rgba(0,0,0,.14); max-width: 280px; }
.tooltip .t-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tooltip .t-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip .t-row b { font-variant-numeric: tabular-nums; }

/* region cards */
.region-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
@media (max-width: 400px) { .region-grid { grid-template-columns: minmax(0, 1fr); } }
.region-card .rc-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.region-card .rc-total { font-size: 22px; font-weight: 600; }
.region-card .rc-meta { font-size: 12.5px; color: var(--ink-2); margin-bottom: 8px; }
.toplist { list-style: none; padding: 0; margin: 8px 0 0; }
.toplist li { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 6px 8px; align-items: center; padding: 4px 0; font-size: 13.5px; }
.toplist .rank { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.toplist a { color: var(--ink); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toplist a:hover { text-decoration: underline; }
.toplist .num { font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.toplist .bar { grid-column: 2 / 4; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.toplist .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.toplist .chg { font-size: 11.5px; font-weight: 500; margin-left: 6px; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
thead th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--ink-2); font-size: 12.5px; cursor: default; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--ink); }
thead th[aria-sort="descending"]::after { content: " ↓"; }
thead th[aria-sort="ascending"]::after { content: " ↑"; }
tbody tr:hover { background: var(--surface-2); }
td a { color: var(--ink); }
.table-scroll { max-height: 640px; overflow: auto; }
.muted { color: var(--muted); }

/* map */
.map-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr); gap: 16px; }
@media (max-width: 860px) { .map-layout { grid-template-columns: minmax(0, 1fr); } }
.map svg path.la { stroke: var(--surface); stroke-width: 0.5; cursor: pointer; }
.map svg path.la:hover, .map svg path.la.sel { stroke: var(--ink); stroke-width: 1.5; }
.map svg path.la.dim { opacity: 0.25; }
.scale { display: flex; gap: 0; margin-top: 8px; font-size: 11.5px; color: var(--ink-2); flex-wrap: wrap; }
.scale div { flex: 1; min-width: 44px; }
.scale i { display: block; height: 10px; }
.scale div:first-child i { border-radius: 3px 0 0 3px; }
.scale div:last-child i { border-radius: 0 3px 3px 0; }

/* LA profile */
.profile-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.profile-head h2 { font-size: 26px; }
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.la-search { position: relative; width: min(360px, 100%); }
.la-search input { width: 100%; }
.suggest { position: absolute; z-index: 6; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.14); max-height: 300px; overflow: auto; }
.suggest button { display: block; width: 100%; text-align: left; font: inherit; font-size: 14px; background: none; border: 0; padding: 7px 10px; color: var(--ink); cursor: pointer; }
.suggest button:hover, .suggest button.active { background: var(--surface-2); }
.suggest small { color: var(--muted); margin-left: 6px; }

.prose { max-width: 75ch; }
.prose h3 { margin-top: 22px; }
.prose dt { font-weight: 600; margin-top: 10px; }
.prose dd { margin: 2px 0 0; color: var(--ink-2); }

.site-footer { border-top: 1px solid var(--border); padding: 18px 0 28px; font-size: 12.5px; color: var(--ink-2); background: var(--surface); }
.site-footer p { margin: 4px 0; max-width: 100ch; }

@media (max-width: 600px) {
  .site-header { position: static; }
  .updated { text-align: left; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 10px; }
  .tile .value { font-size: 21px; }
  .headline { padding: 14px; }
  .headline .hero { font-size: 44px; }
  .card { padding: 12px; }
}

/* embed mode (?embed=1): only the view itself */
body.embed .site-header, body.embed .site-footer, body.embed .no-embed { display: none !important; }
body.embed main { padding-top: 8px; }
.embed-source { display: none; font-size: 11.5px; color: var(--muted); margin-top: 6px; }
body.embed .embed-source { display: block; }

@media print {
  .site-header .tabs, .controls, .btn { display: none !important; }
  .site-header { position: static; }
}

/* an odd card out at the end of a two-column grid spans the full width */
.grid-2 > .card:last-child:nth-child(odd) { grid-column: 1 / -1; }

/* Regions table: the shaded columns are the ones the measure buttons change */
.region-table thead th { position: static; vertical-align: bottom; }
.region-table th.grp { text-align: left; white-space: normal; padding-top: 10px; padding-bottom: 10px; }
.region-table .grp-label { font-size: 12.5px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.region-table .grp-sub { font-size: 12px; font-weight: 400; color: var(--muted); }
.region-table th.dyn-head { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.region-table th.dyn { background: color-mix(in srgb, var(--accent) 11%, var(--surface)); color: var(--ink); }
.region-table td.dyn { background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.region-table tbody tr:hover td.dyn { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.region-table .edge { border-left: 2px solid var(--axis); }
.region-table .seg button { padding: 5px 10px; font-size: 13px; }
.region-table thead tr:nth-child(2) th { white-space: normal; min-width: 90px; max-width: 170px; }
