/* Static pages (towns, regions, rankings, methodology) built by 05_build_pages.R.
   Same palette and logo as the map app (css/styles.css); light by default,
   dark when the app's theme setting is dark. */

:root {
  --bg: #ffffff;
  --card: #f5f7f9;
  --line: #e2e6eb;
  --text: #1c2024;
  --muted: #5f6b7a;
  --accent: #00796b;
  --accent-hover: #00695c;
  --t1: #009688;
  --t2: #ab47bc;
  --t0: #e3e7ec;
  --t0-line: #ffffff;
  --map-on: #e53935;
  --t1-fg: #00796b;
  --t2-fg: #8e24aa;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #10141a;
  --card: #1a2029;
  --line: #2a323d;
  --text: #f2f4f7;
  --muted: #a3adbb;
  --accent: #4fd6c8;
  --accent-hover: #7fe3d8;
  --t0: #2a313b;
  --t0-line: #10141a;
  --map-on: #ff5a4f;
  --t1-fg: #4fd6c8;
  --t2-fg: #d68be4;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
h1, h2 { font-family: Poppins, system-ui, sans-serif; font-weight: 600; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: clamp(28px, 5vw, 40px); margin: 8px 0 12px; }
h2 { font-size: 20px; margin: 32px 0 12px; }
.wrap { max-width: 1080px; margin: 0 auto; padding-inline: 20px; }
main.wrap { padding-block: 8px 48px; }

/* header / footer */
.site-head { border-bottom: 1px solid var(--line); }
.site-head .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; padding-block: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text);
  font: 600 20px/1 Poppins, system-ui, sans-serif; }
.brand:hover { color: var(--text); }
.logo { width: 34px; height: auto; }
.logo-body { fill: var(--t1-fg); }
.logo-chimney { fill: var(--t2-fg); }
.logo-roof { fill: none; stroke: var(--t2-fg); stroke-width: 12; stroke-linecap: round; stroke-linejoin: round; }
.site-nav { display: flex; align-items: center; gap: 6px 18px; flex-wrap: wrap; font-size: 15px; }
.site-nav a:not(.btn) { color: var(--text); text-decoration: none; }
.site-nav a:not(.btn):hover { color: var(--accent); }
.site-foot { border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; padding-block: 16px 32px; }
.site-foot a { color: var(--muted); }

.btn { display: inline-block; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line);
  text-decoration: none; color: var(--text); font-weight: 600; font-size: 15px; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: #00796b; border-color: #00796b; color: #fff; }
.btn-primary:hover { background: #00695c; border-color: #00695c; color: #fff; }

.crumbs { font-size: 14px; color: var(--muted); margin-top: 20px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a { color: var(--muted); }
.lede { font-size: 18px; max-width: 760px; }
.note { color: var(--muted); font-size: 14px; }
.cta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin: 20px 0 8px; }
.cta span { color: var(--muted); font-size: 15px; }

/* town page */
.town-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 8px 40px; }
@media (max-width: 820px) { .town-grid { grid-template-columns: minmax(0, 1fr); } }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat span { display: block; font-size: 13px; color: var(--muted); }
.stat b { display: block; font-size: 20px; line-height: 1.3; overflow-wrap: anywhere; }
.stat b i { font-style: normal; font-size: 14px; color: var(--muted); font-weight: 400; }
.stat small { display: block; font-size: 13px; color: var(--muted); }
.mini { list-style: none; padding: 0; margin: 0; columns: 2; column-gap: 16px; }
.mini li { break-inside: avoid; padding: 4px 0; }
.mini small { display: block; color: var(--muted); font-size: 13px; }
.more { margin-top: 16px; border-top: 1px solid var(--line); }

/* SVG maps */
.map-fig { margin: 24px 0 0; }
.map-fig.wide { max-width: 760px; }
.map-fig figcaption { color: var(--muted); font-size: 13px; margin-top: 6px; }
.townmap { display: block; width: 100%; height: auto; max-height: 520px; }
.townmap path { stroke: var(--t0-line); stroke-width: .8; stroke-linejoin: round; }
.townmap path.t0 { fill: var(--t0); }
.townmap path.t1 { fill: var(--t1); }
.townmap path.t2 { fill: var(--t2); }
.townmap path.off { fill: var(--t0); opacity: .55; }
.townmap.has-on path:not(.on) { fill-opacity: .45; }
.townmap path.on { stroke: var(--map-on); stroke-width: 2.5; }
.townmap a:hover path { opacity: .75; }
.townmap .labels text { font-size: 12px; text-anchor: middle; fill: var(--text); paint-order: stroke;
  stroke: var(--bg); stroke-width: 3px; pointer-events: none; }
.townmap .labels text.on { font-weight: 700; font-size: 14px; }
.legend { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-left: 8px; }
.legend .sw:first-child { margin-left: 0; }
.sw.t1 { background: var(--t1); } .sw.t2 { background: var(--t2); } .sw.t0 { background: var(--t0); border: 1px solid var(--line); }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table.towns { border-collapse: separate; border-spacing: 0; width: auto; min-width: 100%; font-size: 15px; font-variant-numeric: tabular-nums; }
.towns th, .towns td { padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
/* rank and town stay put while the other columns scroll */
.towns .rk, .towns .tn { position: sticky; left: 0; z-index: 1; background: var(--bg); }
/* the header row: js/sort-table.js slides it down to stay at the top of the
   window while the table scrolls under it; it paints over the rows */
.towns thead th { position: relative; z-index: 2; will-change: transform; }
.towns thead .rk, .towns thead .tn { z-index: 3; background: var(--card); }
.towns .rk { width: 40px; min-width: 40px; max-width: 40px; text-align: left; color: var(--muted); }
.towns .rk + .tn { left: 40px; }
.towns .tn { box-shadow: inset -1px 0 0 var(--line); }
/* the town column's resize handle (js/sort-table.js) */
.towns th.tn { padding-right: 12px; }
.towns.tn-set .tn { width: var(--tn-w); min-width: var(--tn-w); max-width: var(--tn-w); }
.towns .tn { overflow: hidden; text-overflow: ellipsis; }
.tn-grip { position: absolute; top: 0; right: 0; bottom: 0; width: 10px; cursor: col-resize; touch-action: none; z-index: 2; }
.tn-grip::after { content: ""; position: absolute; top: 20%; bottom: 20%; right: 3px; width: 3px; border-radius: 2px; background: var(--line); }
.tn-grip:hover::after, .tn-dragging .tn-grip::after { background: var(--accent); }
.tn-dragging { cursor: col-resize; user-select: none; }

.towns th:first-child, .towns td:first-child, .towns th[data-sort="text"], .towns td:has(a) { text-align: left; }
.towns tbody tr:last-child td { border-bottom: 0; }
.towns th { background: var(--card); font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.towns th:hover { color: var(--text); }
.towns th[aria-sort="ascending"]::after { content: " ▲"; }
.towns th[aria-sort="descending"]::after { content: " ▼"; }
.towns .wr { white-space: normal; min-width: 14em; text-align: left; } /* station lists */

/* lists of links */
.cards { list-style: none; padding: 0; margin: 16px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.cards a { display: block; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--text); height: 100%; }
.cards a:hover { border-color: var(--accent); }
.cards small { display: block; color: var(--muted); font-size: 13px; }
.az-jump { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 24px 0 0; font-weight: 600; }
.az ul { list-style: none; padding: 0; margin: 0; columns: 4 160px; column-gap: 16px; }
.az li { padding: 2px 0; }
.az h2 { margin-top: 24px; }

.prose { max-width: 760px; }
.prose dt { font-weight: 600; margin-top: 12px; }
.prose dd { margin: 2px 0 0; color: var(--muted); }

/* Column explanations (js/sort-table.js): the tip shown when hovering a header */
.th-tip { position: fixed; z-index: 1000; max-width: 250px; padding: 8px 10px; border-radius: 9px; background: var(--card);
  border: 1px solid var(--line); box-shadow: 0 6px 18px rgba(0, 0, 0, .18); color: var(--text);
  font-size: 12.5px; font-weight: 400; line-height: 1.45; text-align: left; white-space: normal; pointer-events: none; }
.th-tip[hidden] { display: none; }

/* ---------- small "i" with a tip (town card / profile: presidential lean) ---------- */
span.q-wrap { position: relative; display: inline-block; vertical-align: 1px; margin-left: 5px; }
.q-i { display: block; width: 15px; height: 15px; padding: 0; border: 1.3px solid currentColor; border-radius: 50%; background: none;
  color: var(--muted); font: italic 700 10px/1 Georgia, serif; }
.q-i:hover, .q-i:focus-visible { color: var(--text); }
span.q-tip { display: none; position: absolute; z-index: 20; top: calc(100% + 6px); left: -8px; width: 240px; padding: 8px 10px;
  border-radius: 9px; background: var(--card); border: 1px solid var(--line); box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
  color: var(--text); font-size: 12.5px; font-weight: 400; line-height: 1.45; text-align: left; white-space: normal; }
span.q-wrap:hover span.q-tip, .q-i:focus + span.q-tip { display: block; }
/* On a profile tile the tip spans the tile, so it can't run off a phone's screen from either column */
.stat { position: relative; }
.stat span.q-wrap { position: static; }
.stat span.q-tip { left: -1px; right: -1px; width: auto; top: calc(100% + 4px); }
