/* Electoral Atlas — dependency-free styles.
   Behaviour-first: layout serves the comparison task; dark mode follows the OS;
   contrast >= 4.5:1 on text in both schemes; touch targets >= 44px. */

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --ink: #1a1d21;
  --ink-muted: #57606a;
  --accent: #0969da;
  --accent-ink: #ffffff;
  --good: #116329;
  --good-bg: #dafbe1;
  --line: #d0d7de;
  --bar-track: #eaeef2;
  --party-lib: #d0332c;
  --party-con: #2650a3;
  --party-ndp: #e8703a;
  --party-bloc: #33a0ce;
  --party-grn: #2e9e4f;
  --party-ppc: #7b5399;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --ink: #e6edf3;
    --ink-muted: #8b949e;
    --accent: #4493f8;
    --accent-ink: #0d1117;
    --good-bg: #0f2417;
    --line: #30363d;
    --bar-track: #21262d;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
}
.wrap { max-width: 60rem; margin-inline: auto; padding-inline: 1rem; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

.site-header { padding: 1.5rem 0 .25rem; }
.site-header h1 { margin: 0; font-size: 1.45rem; letter-spacing: -.01em; }
.tagline { margin: .15rem 0 0; color: var(--ink-muted); }

/* Tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-top: 1rem; }
.tabs button {
  appearance: none; background: none; border: none; cursor: pointer;
  font: inherit; color: var(--ink-muted); padding: .7rem 1rem; min-height: 44px;
  border-bottom: 3px solid transparent;
}
.tabs button[aria-selected="true"] {
  color: var(--ink); font-weight: 600; border-bottom-color: var(--accent);
}
.tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

main { padding-block: 1.25rem 3rem; }
h2 { font-size: 1.12rem; margin: 1.75rem 0 .5rem; }
a { color: var(--accent); }
code { background: var(--bar-track); padding: .08em .35em; border-radius: 4px; font-size: .88em; }
.muted { color: var(--ink-muted); }
.summary-line { font-weight: 600; }

/* Overview metric cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: .75rem; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: .85rem 1rem;
}
.card .big { font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; }
.card .lbl { color: var(--ink-muted); font-size: .86rem; }
.findings li { margin-block: .55rem; }

/* Search combobox */
.searchbar { position: relative; max-width: 34rem; margin-block: 1rem; }
.searchbar label { display: block; font-weight: 600; margin-bottom: .35rem; }
.searchbar input {
  width: 100%; min-height: 44px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: .5rem .75rem;
}
.searchbar input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#search-listbox {
  position: absolute; z-index: 10; left: 0; right: 0; top: 100%;
  margin: .25rem 0 0; padding: .25rem; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14); max-height: 19rem; overflow-y: auto;
}
#search-listbox li {
  padding: .5rem .65rem; min-height: 44px; display: flex;
  justify-content: space-between; gap: .75rem; align-items: center;
  border-radius: 6px; cursor: pointer;
}
#search-listbox li:hover { background: var(--bar-track); }
#search-listbox li[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
#search-listbox .prov { color: var(--ink-muted); font-size: .85rem; }
#search-listbox li[aria-selected="true"] .prov { color: inherit; opacity: .8; }

.empty-state { color: var(--ink-muted); padding: 2rem 0; }

/* Focal riding */
.focal-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 1rem 1.15rem; margin-top: 1.25rem;
}
.focal-card h2 { margin: 0 0 .15rem; }
.focal-card .muted { margin-top: 0; }
.sharebars { display: grid; gap: .3rem; margin-top: .75rem; }
.share-row { display: grid; grid-template-columns: 6.5rem 1fr 3.2rem; gap: .6rem; align-items: center; }
.share-row .pname { font-size: .9rem; color: var(--ink-muted); }
.share-row .pval { font-variant-numeric: tabular-nums; text-align: right; font-size: .9rem; }
.bar { height: 10px; border-radius: 5px; background: var(--bar-track); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 5px; }

/* Twin table */
.twin-table { width: 100%; border-collapse: collapse; margin-top: .75rem; }
.twin-table th, .twin-table td {
  text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.twin-table thead th { color: var(--ink-muted); font-size: .84rem; font-weight: 600; }
.badge {
  display: inline-block; padding: .18rem .55rem; border-radius: 99px;
  font-size: .8rem; font-weight: 600; min-height: 1.6em;
}
.badge.yes { background: var(--good-bg); color: var(--good); }
.badge.no { background: var(--bar-track); color: var(--ink-muted); }
.badge-col { white-space: nowrap; }
.badge-col .badge { margin-right: .25rem; font-size: .72rem; padding: .14rem .4rem; }

.differ-box {
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: .55rem .7rem; margin-block: .6rem;
}
.differ-title { margin: 0 0 .35rem; font-size: .88rem; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.chip {
  background: var(--bar-track); border-radius: 99px;
  padding: .18rem .6rem; font-size: .8rem;
}
.chip.stubborn { background: var(--good-bg); font-weight: 600; }

.provbar { display: flex; gap: .3rem; margin-bottom: .6rem; }
.provbar button {
  flex: 1; font: inherit; font-size: .8rem; cursor: pointer;
  min-height: 32px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-muted);
}
.provbar button.active { background: var(--bar-track); color: var(--ink); font-weight: 600; }

/* Embed mode: map only, full viewport */
body.embed .site-header,
body.embed .tabs,
body.embed .site-footer,
body.embed .small-note,
body.embed #panel-map > p { display: none; }
body.embed main { padding-block: 0; max-width: none; }
body.embed #panel-map[hidden] { display: none; }
body.embed #panel-map:not([hidden]) { display: block; }
body.embed .map-shell { height: 100vh; border-radius: 0; border: none; }
body.embed .map-sidebar { top: .5rem; left: .5rem; bottom: .5rem; }
.sim-cell { font-variant-numeric: tabular-nums; }
.sharebars.mini { grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); }
.sharebars.mini .share-row { grid-template-columns: 3.4rem 1fr 2.6rem; gap: .4rem; }
.sharebars.mini .pname { font-size: .78rem; }
.sharebars.mini .bar { height: 7px; }

/* Weights + sensitivity tables */
.weights-table, .sens-table { width: 100%; border-collapse: collapse; }
.weights-table th, .weights-table td, .sens-table th, .sens-table td {
  padding: .45rem .5rem; border-bottom: 1px solid var(--line); text-align: left;
}
.weights-table td:first-child { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .86em; }
.wbar { height: 9px; border-radius: 5px; background: var(--accent); min-width: 2px; }
.grid-two { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 1rem; }
.panel-box { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .9rem 1rem; }
.panel-box h3 { margin: 0 0 .4rem; font-size: 1rem; }

.table-scroll { overflow-x: auto; }

.site-footer { border-top: 1px solid var(--line); padding: 1.25rem 0 2.5rem; color: var(--ink-muted); font-size: .9rem; }

/* ---------- Map tab ---------- */
.map-shell {
  position: relative;
  height: min(76vh, 760px);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
#map { position: absolute; inset: 0; }
.map-sidebar {
  position: absolute; z-index: 5; top: .75rem; left: .75rem; bottom: .75rem;
  width: min(21rem, calc(100vw - 2rem));
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: .85rem; overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.searchbar.compact { margin-block: 0 .6rem; max-width: none; }
.searchbar.compact input { min-height: 40px; }
.yearbar { display: flex; gap: .35rem; margin-bottom: .6rem; }
.yearbar button {
  flex: 1; font: inherit; font-size: .88rem; cursor: pointer;
  min-height: 36px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-muted);
}
.yearbar button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.map-legend { display: flex; flex-wrap: wrap; gap: .3rem .55rem; margin-bottom: .6rem; font-size: .78rem; }
.legend-chip { display: inline-flex; align-items: center; gap: .28rem; }
.legend-chip .swatch { width: .72rem; height: .72rem; border-radius: 3px; display: inline-block; }
.map-tip {
  display: none; position: absolute; z-index: 6; pointer-events: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 7px;
  padding: .4rem .55rem; font-size: .84rem; line-height: 1.35;
  box-shadow: 0 4px 14px rgba(0,0,0,.18); white-space: nowrap;
}
.focal-name { font-size: 1.05rem; margin: .4rem 0 .1rem; }
.small-note { font-size: .84rem; }
.twin-table.compact td { padding: .45rem .35rem; }
.twin-table.compact { font-size: .86rem; }

/* MapLibre chrome to match theme */
.maplibregl-ctrl-group { background: var(--surface) !important; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line) !important; }
.maplibregl-ctrl-attrib { background: rgba(255,255,255,.82) !important; font-size: .68rem; }

@media (max-width: 640px) {
  .twin-table th:nth-child(1), .twin-table td:nth-child(1) { display: none; }
  .card .big { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: no-preference) {
  #search-listbox, .badge { transition: background-color .12s ease; }
}
