/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f1efe9;
  --surface-glass: rgba(255, 255, 255, 0.86);
  --border: rgba(23, 32, 51, 0.1);
  --border-strong: rgba(23, 32, 51, 0.2);
  --text: #172033;
  --text-2: #4a5468;
  --text-3: #687183;
  --brand: #1b3768;
  --accent: #1b3768;
  --accent-ink: #1d4a8f;
  --accent-soft: #e7edf7;
  --accent-2: #13897a;
  --accent-2-ink: #0e6f63;
  --accent-2-soft: #dff2ee;
  --on-accent: #ffffff;
  --grid: #e3e1da;
  --baseline: #c2c4c2;
  --good: #0f7a2c;
  --good-soft: #e3f3e6;
  --warn: #8f5c00;
  --warn-soft: #fbf1db;
  --bad: #b8302f;
  --bad-soft: #fbe7e6;
  --neutral-soft: #ebe9e3;
  --series-in: #2a6fbd;
  --series-out: #e0703a;
  --series-property: #9a9a94;
  --series-overhead: #c98a6c;
  --grade-a: #0f7a2c;
  --grade-b: #3d8f3a;
  --grade-c: #a06a00;
  --grade-d: #c4581f;
  --grade-f: #c0302f;
  --shadow: 0 1px 2px rgba(23, 32, 51, 0.05), 0 6px 20px rgba(23, 32, 51, 0.06);
  --shadow-lift: 0 2px 4px rgba(23, 32, 51, 0.06), 0 12px 32px rgba(23, 32, 51, 0.11);
  --radius: 14px;
  --radius-sm: 9px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Source Serif 4", Georgia, "Times New Roman", serif;
  --topbar-h: 66px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b1424;
    --surface: #111c2f;
    --surface-2: #18253b;
    --surface-glass: rgba(17, 28, 47, 0.82);
    --border: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.17);
    --text: #eef2f8;
    --text-2: #b6c0d0;
    --text-3: #8a96a8;
    --brand: #24467f;
    --accent: #5b8fe0;
    --accent-ink: #9cbcf0;
    --accent-soft: #172a47;
    --accent-2: #3cc4b4;
    --accent-2-ink: #6fd8ca;
    --accent-2-soft: #0f2e2c;
    --on-accent: #0b1424;
    --grid: #1f2c42;
    --baseline: #3a4a63;
    --good: #4cc26a;
    --good-soft: #13301f;
    --warn: #e5a83a;
    --warn-soft: #33290f;
    --bad: #f07171;
    --bad-soft: #3a1c22;
    --neutral-soft: #1c283c;
    --series-in: #5b8fe0;
    --series-out: #e07a45;
    --series-property: #7d8799;
    --series-overhead: #b07a60;
    --grade-a: #3fb560;
    --grade-b: #7dbf5c;
    --grade-c: #d99a2b;
    --grade-d: #e57c45;
    --grade-f: #e35d5d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.18);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.4), 0 14px 32px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1424;
  --surface: #111c2f;
  --surface-2: #18253b;
  --surface-glass: rgba(17, 28, 47, 0.82);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.17);
  --text: #eef2f8;
  --text-2: #b6c0d0;
  --text-3: #8a96a8;
  --brand: #24467f;
  --accent: #5b8fe0;
  --accent-ink: #9cbcf0;
  --accent-soft: #172a47;
  --accent-2: #3cc4b4;
  --accent-2-ink: #6fd8ca;
  --accent-2-soft: #0f2e2c;
  --on-accent: #0b1424;
  --grid: #1f2c42;
  --baseline: #3a4a63;
  --good: #4cc26a;
  --good-soft: #13301f;
  --warn: #e5a83a;
  --warn-soft: #33290f;
  --bad: #f07171;
  --bad-soft: #3a1c22;
  --neutral-soft: #1c283c;
  --series-in: #5b8fe0;
  --series-out: #e07a45;
  --series-property: #7d8799;
  --series-overhead: #b07a60;
  --grade-a: #3fb560;
  --grade-b: #7dbf5c;
  --grade-c: #d99a2b;
  --grade-d: #e57c45;
  --grade-f: #e35d5d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.18);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.4), 0 14px 32px rgba(0, 0, 0, 0.3);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
a { color: var(--accent-ink); }
a:hover { color: var(--accent-2-ink); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1, h2 { font-family: var(--font-display); font-weight: 700; color: var(--text); }
h1 { font-size: 34px; letter-spacing: -0.015em; }
h2 { font-size: 20px; letter-spacing: -0.005em; }
h3 { font-size: 15px; }
p { margin: 0 0 12px; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 2000; border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.skip-link:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-2-soft); color: var(--text); }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 28px;
  height: var(--topbar-h); padding: 3px 24px 0;
  background: var(--surface-glass);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
/* Navy-to-teal strip along the top edge. */
.topbar::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--brand), var(--accent-2));
}
.brand { display: flex; align-items: center; gap: 11px; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand:hover { color: var(--text); }
.brand-mark { flex: none; border-radius: 9px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 21px; letter-spacing: -0.01em; color: var(--text); }
.brand-name span { color: var(--accent-2); }
.brand-tag { font-size: 11.5px; font-weight: 500; color: var(--text-3); letter-spacing: 0.02em; margin-top: 2px; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; align-self: stretch; align-items: stretch; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  position: relative; display: flex; align-items: center;
  padding: 0 13px; color: var(--text-2); text-decoration: none; font-weight: 500; font-size: 14.5px; white-space: nowrap;
}
.nav a::after {
  content: ""; position: absolute; left: 13px; right: 13px; bottom: -1px; height: 2.5px; border-radius: 2px 2px 0 0;
  background: var(--accent-2); transform: scaleX(0); transition: transform 0.2s ease;
}
.nav a:hover { color: var(--text); }
.nav a:hover::after { transform: scaleX(0.4); }
.nav a.active { color: var(--text); font-weight: 600; }
.nav a.active::after { transform: scaleX(1); }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); cursor: pointer; color: var(--text-2);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.icon-btn:hover { color: var(--accent-2-ink); border-color: var(--accent-2); background: var(--accent-2-soft); }
/* Theme toggle shows the theme you would switch to. */
#theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] #theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] #theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-toggle .i-sun { display: block; }
  :root:not([data-theme="light"]) #theme-toggle .i-moon { display: none; }
}
.demo-banner {
  padding: 8px 24px; font-size: 13px; color: var(--text-2);
  background: var(--warn-soft); border-bottom: 1px solid var(--border);
}
.demo-banner::before {
  content: "i"; margin-right: 10px; vertical-align: -4px; display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  font: italic 700 12px/1 var(--font-display); color: var(--warn-soft); background: var(--warn);
}
.demo-banner strong { color: var(--text); }

/* ---------- Footer ---------- */
.site-footer { background: var(--surface); border-top: 1px solid var(--border); color: var(--text-2); font-size: 14px; }
[data-view="map"] .site-footer { display: none; }
.footer-inner { max-width: 1180px; margin: 0 auto; padding: 40px 20px 28px; display: grid; grid-template-columns: 1.6fr 1fr 1.2fr; gap: 32px; }
.footer-brand p { margin: 8px 0 10px; max-width: 360px; }
.site-footer h2 { font: 600 12px/1.2 var(--font); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); margin-bottom: 12px; }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.site-footer a { color: var(--text-2); text-decoration: none; }
.site-footer a:hover { color: var(--accent-2-ink); text-decoration: underline; }
.footer-base {
  max-width: 1180px; margin: 0 auto; padding: 16px 20px 24px; border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--text-3);
}

/* ---------- Layout ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 36px 20px 72px; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 24px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.page-head p { margin: 8px 0 0; color: var(--text-2); max-width: 680px; font-size: 15.5px; }
.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)); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  min-width: 0;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head p { margin: 4px 0 0; font-size: 13px; color: var(--text-2); }
.eyebrow { font-size: 11.5px; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; color: var(--accent-2-ink); }

/* ---------- Controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field .label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.input, .select {
  height: 38px; padding: 0 12px; width: 100%;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background-color: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:hover, .select:hover { border-color: color-mix(in srgb, var(--accent-2) 45%, var(--border-strong)); }
.input:focus, .select:focus { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-2) 22%, transparent); }
.select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%23898781' stroke-width='1.6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer;
  font-weight: 600; text-decoration: none; color: var(--text); white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--accent-2); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.btn-primary:hover { background: var(--brand); border-color: var(--brand); color: #fff; filter: brightness(1.15); }
.segmented { display: flex; box-sizing: border-box; height: 38px; padding: 3px; background: var(--surface-2); border-radius: var(--radius-sm); gap: 2px; }
.segmented button { flex: 1; border: 0; background: transparent; padding: 0 10px; white-space: nowrap; border-radius: calc(var(--radius-sm) - 2px); cursor: pointer; font: inherit; font-weight: 500; color: var(--text-2); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--accent-2-ink); font-weight: 600; box-shadow: var(--shadow); }
/* Two-option toggles get a thumb that slides to the pressed button. */
.segmented:has(> button:nth-child(2):last-child) { position: relative; isolation: isolate; }
.segmented:has(> button:nth-child(2):last-child)::before {
  content: ""; position: absolute; z-index: -1; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 4px);
  border-radius: calc(var(--radius-sm) - 2px); background: var(--surface); box-shadow: var(--shadow);
}
.segmented:has(> button:nth-child(2):last-child[aria-pressed="true"])::before { transform: translateX(calc(100% + 2px)); }
.segmented:has(> button:nth-child(2):last-child) button[aria-pressed="true"] { background: transparent; box-shadow: none; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.toolbar .field { min-width: 160px; flex: 1; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent-2); }

/* ---------- Map view ---------- */
.map-layout { display: grid; grid-template-columns: 360px 1fr; height: calc(100vh - var(--topbar-h)); }
.has-banner .map-layout { height: calc(100vh - var(--topbar-h) - 37px); }
.map-side {
  overflow-y: auto; padding: 20px; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 18px;
}
.map-side { padding: 24px 22px; }
.map-side h1 { font-size: 27px; line-height: 1.15; margin-top: 8px; }
.map-side .intro { color: var(--text-2); font-size: 14px; margin: 10px 0 0; }
.hero-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
.hero-stats div { padding: 10px 12px; border-radius: var(--radius-sm); background: linear-gradient(160deg, var(--accent-soft), var(--accent-2-soft)); }
.hero-stats strong { display: block; font: 700 21px/1.1 var(--font-display); color: var(--text); font-variant-numeric: tabular-nums; }
.hero-stats span { font-size: 11.5px; color: var(--text-2); }
#map { width: 100%; height: 100%; background: var(--surface-2); }
.map-wrap { position: relative; min-height: 0; }
.legend { display: flex; flex-direction: column; gap: 6px; }
.legend-bar { height: 10px; border-radius: 5px; }
.legend-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); }
.town-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.town-list button {
  width: 100%; display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 10px;
  padding: 8px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; text-align: left;
}
.town-list button:hover { background: var(--surface-2); }
.town-list button.active { background: var(--accent-2-soft); box-shadow: inset 3px 0 0 var(--accent-2); }
.town-list .t-name { font-weight: 600; font-size: 14px; line-height: 1.25; }
.town-list .t-sub { font-size: 12px; color: var(--text-2); }
.town-list .t-val { font-size: 13px; color: var(--text-2); }
.map-card {
  position: absolute; z-index: 600; right: 16px; top: 16px; width: 320px;
  max-width: calc(100% - 32px);
}
.map-card .close { position: absolute; top: 12px; right: 12px; }
.map-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.map-stats div { background: var(--surface-2); border-radius: var(--radius-sm); padding: 9px 11px; }
.map-stats span { display: block; font-size: 11px; color: var(--text-2); }
.map-stats strong { font-size: 15px; }
.leaflet-container { font: inherit; }
.leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--border); }
.leaflet-bar a:hover { background: var(--surface-2); }
.leaflet-container .leaflet-control-attribution.leaflet-control { background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--text-2); }
.leaflet-control-attribution a { color: var(--text-2); }
.leaflet-tooltip { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.nav .short { display: none; }
.leaflet-tooltip { font: 13px/1.35 var(--font); border-radius: 8px; padding: 6px 10px; box-shadow: var(--shadow); }
.leaflet-tooltip-top::before { border-top-color: var(--surface); }

/* ---------- Grade badge ---------- */
.grade {
  display: inline-grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 8px;
  font-weight: 800; font-size: 16px; color: #fff; background: var(--g);
  font-family: var(--font-display); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}
.grade-lg { width: 96px; height: 96px; border-radius: 20px; font-size: 56px; }
.grade-md { width: 52px; height: 52px; border-radius: 12px; font-size: 28px; }
.g-A { --g: var(--grade-a); } .g-B { --g: var(--grade-b); } .g-C { --g: var(--grade-c); }
.g-D { --g: var(--grade-d); } .g-F { --g: var(--grade-f); }
.g-none { --g: var(--text-3); }

/* ---------- Town report ---------- */
.report-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; align-items: end; margin-bottom: 20px; }
.crumbs { font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.crumbs a { color: var(--text-2); }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; color: var(--text-2); font-size: 14px; }
.scorecard { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; margin-bottom: 16px; }
/* Faint wash in the grade color behind the main score. */
.scorecard > .card:first-child { background: linear-gradient(150deg, color-mix(in srgb, var(--g, var(--accent)) 9%, var(--surface)) 0%, var(--surface) 55%); }
.score-main { display: flex; gap: 22px; align-items: center; }
.score-main .score-text { flex: 1; min-width: 0; }
.score-value { font: 700 46px/1.05 var(--font-display); letter-spacing: -0.02em; }
.score-value small { font-size: 16px; color: var(--text-2); font-weight: 500; }
.track { position: relative; height: 10px; background: var(--neutral-soft); border-radius: 5px; overflow: hidden; margin: 8px 0; }
.track > span { position: absolute; inset: 0 auto 0 0; border-radius: 5px; background: var(--g, var(--accent)); }
.basis { font-size: 13px; color: var(--text-2); margin: 8px 0 0; }
.components { display: flex; flex-direction: column; gap: 12px; }
.component-row .top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.component-row .top strong { font-weight: 600; }
.component-row .track { height: 8px; margin: 6px 0 2px; }
.component-row .track > span { background: var(--accent); }
.component-row .track-penalty > span { background: var(--bad); }
.component-row p { font-size: 12.5px; color: var(--text-2); margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; border-top: 3px solid var(--accent-2); }
.tile .k { font-size: 12px; font-weight: 600; color: var(--text-2); }
.tile .v { font: 700 26px/1.2 var(--font-display); margin: 6px 0 2px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.tile .s { font-size: 12px; color: var(--text-3); }
.checklist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.checklist svg { flex: none; margin-top: 1px; }
.checklist .state { margin-left: auto; font-size: 12px; font-weight: 600; white-space: nowrap; }
.yes { color: var(--good); } .no { color: var(--bad); } .unk { color: var(--text-3); }

/* Bars */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 1.1fr) 2fr auto; gap: 12px; align-items: center; font-size: 13.5px; }
.bar-row .lbl { color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar { height: 12px; background: var(--neutral-soft); border-radius: 0 4px 4px 0; position: relative; }
.bar-row .bar > span { position: absolute; inset: 0 auto 0 0; background: var(--c); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .amt { text-align: right; min-width: 92px; }
.bar-row .amt small { color: var(--text-3); margin-left: 4px; }
.key { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--text-2); margin-bottom: 14px; }
.key i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: 6px; vertical-align: -1px; }
.split { display: flex; height: 14px; border-radius: 4px; overflow: hidden; gap: 2px; margin: 4px 0 6px; }
.split span { background: var(--c); }
.callout { background: var(--accent-soft); border-left: 3px solid var(--accent-2); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13.5px; margin-top: 14px; }
.callout-bad { background: var(--bad-soft); color: var(--text); margin: 0 0 14px; }
/* Red flags: surveillance, corporate deals, tax breaks and corporate lobbying. */
.tile-flag { border-color: var(--bad); border-top-color: var(--bad); background: var(--bad-soft); }
.tile-flag .v { color: var(--bad); }
.flag-box { margin-top: 16px; padding: 12px 14px; border: 1px solid var(--bad); border-left-width: 4px; border-radius: var(--radius-sm); background: var(--bad-soft); }
.flag-box h3 { margin: 0 0 4px; font-size: 14px; color: var(--bad); }
.flag-box p { margin: 0 0 10px; }
.flag-box .table-wrap { background: var(--surface); border-radius: 6px; }
.rf-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rf-list li { background: var(--surface); border-radius: 6px; padding: 10px 12px; }
.rf-list .rf-top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 4px; }
.rf-list p { margin: 0 0 4px; overflow-wrap: anywhere; }
.rf-list p:last-child { margin: 0; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 11.5px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-2); background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface-2)); position: sticky; top: 0; }
th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
th button:focus-visible { outline: 2px solid var(--accent); }
td.r, th.r { text-align: right; }
td.wrap { white-space: normal; min-width: 140px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: color-mix(in srgb, var(--accent-2-soft) 60%, transparent); }
td a { font-weight: 600; text-decoration: none; }
td a:hover { text-decoration: underline; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--neutral-soft); color: var(--text-2); }
.pill-in { background: var(--accent-soft); color: var(--accent-ink); }
.pill-verified::before { content: "\2713"; margin-right: 4px; }
.pill-out { background: var(--warn-soft); color: var(--warn); }
.pill-verified { background: var(--good-soft); color: var(--good); vertical-align: middle; }
.pill-influence { background: var(--bad-soft); color: var(--bad); }
.ledger-sum { display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: 13px; color: var(--text-2); margin: 10px 0 0; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 13px; color: var(--text-2); gap: 10px; }

/* Line chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-text { fill: var(--text-3); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; box-shadow: var(--shadow); min-width: 150px;
}
.tooltip .row { display: flex; justify-content: space-between; gap: 12px; }
.tooltip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--c); margin-right: 6px; }

/* Compare */
.compare-pickers { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.compare-table td:first-child { color: var(--text-2); }
.compare-table td { white-space: normal; }
.best { font-weight: 700; color: var(--good); }

/* Prose */
.prose { max-width: 760px; }
.prose h2 { margin: 36px 0 12px; font-size: 23px; }
.prose > p, .prose li { font-size: 15.5px; }
.prose ul { padding-left: 20px; margin: 0 0 12px; }
.prose li { margin-bottom: 6px; }
.prose code, code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
details summary { cursor: pointer; font-weight: 600; }
pre { background: var(--surface-2); padding: 14px; border-radius: var(--radius-sm); overflow-x: auto; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
dl.glossary dt { font-weight: 700; margin-top: 12px; }
dl.glossary dd { margin: 2px 0 0; color: var(--text-2); }
.drop {
  display: block; margin-top: 14px; cursor: pointer;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 24px;
  text-align: center; color: var(--text-2);
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.notice { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 14px; margin-top: 12px; }
.notice.ok { background: var(--good-soft); color: var(--good); }
.notice.err { background: var(--bad-soft); color: var(--bad); }
.empty { padding: 40px 0; text-align: center; color: var(--text-2); }

/* ---------- States ---------- */
.state-stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 8px; }
.state-stats .k { font-size: 12px; font-weight: 600; color: var(--text-2); }
.state-stats .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.state-stats .s { font-size: 12px; color: var(--text-3); }
.state-sub { font-size: 14px; margin: 18px 0 8px; }
.grade-dist { display: flex; height: 22px; border-radius: 6px; overflow: hidden; gap: 2px; }
.grade-dist > span { background: var(--g); color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; min-width: 3px; }
.grade-key { margin-top: 6px; }
.coverage { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13.5px; }
.coverage li { display: grid; grid-template-columns: minmax(0, 1.4fr) 1fr 44px; gap: 10px; align-items: center; }
.cov-bar { height: 8px; background: var(--neutral-soft); border-radius: 4px; overflow: hidden; }
.cov-bar > span { display: block; height: 100%; background: var(--accent); }
.coverage .num { text-align: right; }
.state-links { display: flex; gap: 8px; margin-top: 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .state-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1000px) {
  .scorecard { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .brand-tag { display: none; }
  .footer-inner { grid-template-columns: 1fr 1fr; }
  .footer-brand { grid-column: 1 / -1; }
  .map-layout, .has-banner .map-layout { grid-template-columns: 1fr; grid-template-rows: 55vh auto; height: auto; }
  .map-wrap { order: -1; }
  .map-side { border-right: 0; border-top: 1px solid var(--border); overflow: visible; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .compare-pickers { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  :root { --topbar-h: 58px; }
  .topbar { gap: 6px; padding: 3px 10px 0; }
  .brand-text { display: none; }
  .nav a::after { left: 5px; right: 5px; }
  .nav .long { display: none; }
  .nav .short { display: inline; }
  .nav a { padding: 6px 4px; font-size: 12.5px; }
  .nav { gap: 0; }
  .page { padding: 20px 16px 48px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .state-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .score-main { gap: 16px; }
  .grade-lg { width: 72px; height: 72px; font-size: 42px; border-radius: 16px; }
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-row .bar { grid-column: 1 / -1; grid-row: 2; }
  h1 { font-size: 27px; }
  .map-side h1 { font-size: 24px; }
  .footer-inner { grid-template-columns: 1fr; gap: 24px; }
  .map-card { left: 16px; right: 16px; top: auto; bottom: 16px; width: auto; }
  .demo-banner { padding: 6px 12px; font-size: 12px; }
  .demo-banner::before { margin-right: 6px; }
  .leaflet-container .leaflet-control-attribution { font-size: 9px; }
  th, td { padding: 9px 10px; }
  td.wrap { min-width: 280px; }
  td .pill-verified { display: block; width: fit-content; margin-top: 3px; }
}
@media (prefers-reduced-motion: no-preference) {
  .track > span, .bar-row .bar > span { transition: width 0.4s ease; }
  .track > span, .bar-row .bar > span { transform-origin: left; animation: grow-in 0.6s cubic-bezier(0.2, 0.7, 0.3, 1) both; }
  @keyframes grow-in { from { transform: scaleX(0); } }
  .segmented::before { transition: transform 0.25s cubic-bezier(0.3, 0.7, 0.4, 1); }
  .segmented button { transition: color 0.2s ease; }
  .card, .tile { transition: box-shadow 0.2s ease, transform 0.2s ease; }
  .tile:hover, a.card:hover { box-shadow: var(--shadow-lift); transform: translateY(-2px); }
  main > .page { animation: fade-in 0.25s ease both; }
  @keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}

/* State names on the map */
.state-label { pointer-events: none; }
.state-label span {
  display: block; transform: translate(-50%, -50%); white-space: nowrap;
  font: 700 11px/1 system-ui, sans-serif; letter-spacing: .08em; text-transform: uppercase;
  color: #2b2b27; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 6px #fff;
}
:root[data-theme="dark"] .state-label span { color: #f0f0ea; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 6px #000; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .state-label span { color: #f0f0ea; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 6px #000; }
}

.state-label b { font-weight: inherit; }
.state-label .abbr { display: none; }
.labels-short .state-label .full { display: none; }
.labels-short .state-label .abbr { display: inline; }

/* Keep all destinations visible, including in the narrow in-app preview:
   brand and theme toggle on the first row, the full nav on its own row below. */
@media (max-width: 640px) {
  .topbar { height: auto; min-height: 60px; flex-wrap: wrap; row-gap: 0; padding: 9px 14px 0; }
  .brand-text { display: flex; }
  .brand-name { font-size: 19px; }
  .brand-tag { display: none; }
  .icon-btn#theme-toggle { margin-left: auto; width: 34px; height: 34px; }
  .nav { order: 3; flex: 1 0 100%; justify-content: space-between; overflow: visible; min-width: 0; margin: 2px -4px 0; }
  .nav a { min-height: 40px; display: inline-flex; align-items: center; padding: 0 4px; font-size: 13.5px; }
  .compare-pickers { grid-template-columns: 1fr; }
  .compare-table th:first-child { max-width: 125px; min-width: 110px; }
}
.compare-table th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); white-space: normal; }
.compare-table td, .compare-table thead th:not(:first-child) { min-width: 210px; white-space: normal; }
.compare-table tbody th { text-align: left; font-weight: 500; }
.compare-table .small { font-weight: 400; }
.scroll-cue { margin-top: 16px; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 3px; }

/* ---------- Rankings ---------- */
.toolbar .field-wide { flex: 2; min-width: 200px; }
.toolbar-row { align-items: center; justify-content: flex-start; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--accent-ink); }
.btn-quiet:hover { background: var(--accent-soft); }
/* A bounded scroll area so the sticky header stays in view while reading a long page. */
.table-tall { max-height: min(72vh, 900px); overflow: auto; }
.table-tall th { z-index: 2; }
.rank-table td { vertical-align: top; }
.town-cell { display: flex; gap: 10px; align-items: center; }
.pill-provisional { background: var(--warn-soft); color: var(--warn); vertical-align: middle; }
.row-provisional td { background: color-mix(in srgb, var(--warn-soft) 35%, transparent); }
.peer-cell { font-weight: 600; }
.pager-controls { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.input-page { width: 72px; height: 34px; text-align: center; display: inline-block; }
@media (max-width: 640px) {
  .toolbar .field { min-width: calc(50% - 5px); }
  .toolbar .field-wide { min-width: 100%; }
  .pager { flex-direction: column; align-items: stretch; }
  .pager-controls { justify-content: space-between; }
  /* Keep the town name in view while the measures scroll sideways. */
  .rank-table td:nth-child(2), .rank-table th:nth-child(2) { position: sticky; left: 0; background: var(--surface); z-index: 1; white-space: normal; min-width: 190px; max-width: 220px; }
  .rank-table th:nth-child(2) { background: var(--surface-2); z-index: 3; }
  .rank-table td:first-child, .rank-table th:first-child { display: none; }
}

/* ---------- Peer comparison on the report card ---------- */
.peer-box { margin-top: 14px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--text); }
.peer-box .peer-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.peer-box strong.big { font-size: 20px; color: var(--accent-ink); }
.peer-box p { margin: 4px 0 0; font-size: 13px; color: var(--text-2); }
.peer-scale { position: relative; height: 8px; margin: 10px 0 4px; border-radius: 4px; background: linear-gradient(90deg, var(--grade-f), var(--grade-c), var(--grade-a)); opacity: 0.85; }
.peer-scale i { position: absolute; top: -4px; width: 4px; height: 16px; margin-left: -2px; border-radius: 2px; background: var(--text); box-shadow: 0 0 0 2px var(--surface); }
.peer-ends { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-3); }
.track .peer-tick { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--text); opacity: 0.7; border-radius: 1px; }
.component-row .track { overflow: visible; }
.completeness { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; padding: 0; list-style: none; }
.completeness li { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--neutral-soft); color: var(--text-2); }
.completeness li.ok { background: var(--good-soft); color: var(--good); }
.labels-none .state-label { display: none; }
