:root {
  --navy: #061d3f;
  --navy-deep: #03132c;
  --navy-soft: #1a3257;
  --navy-tint: #e6e9f0;
  --cream: #f4f1e8;
  --cream-warm: #faf6ec;
  --paper: #ffffff;
  --ink: #15171c;
  --ink-soft: #545a67;
  --ink-faint: #8b8f9a;
  --line: #e3ddcd;
  --line-strong: #c8c1ad;
  --restore: #061d3f;
  --flip-bg: #061d3f;
  --flip-ink: #ffffff;
  --accent-red: #a3261c;
  --accent-green: #1c7a36;
  --gold: #b08c3f;
  --shadow-sm: 0 1px 0 rgba(6, 29, 63, 0.04);
  --shadow-md: 0 6px 24px rgba(6, 29, 63, 0.08);
  --shadow-lg: 0 18px 48px rgba(6, 29, 63, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --max-width: 1480px;
  --font-serif: "DM Serif Display", "Iowan Old Style", "Charter", "Georgia", serif;
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
}

body {
  background-image:
    radial-gradient(1200px 600px at 15% -10%, rgba(6, 29, 63, 0.06), transparent 60%),
    radial-gradient(900px 500px at 110% 0%, rgba(176, 140, 63, 0.06), transparent 60%);
  background-attachment: fixed;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Topbar / brand ---------- */

.topbar {
  position: relative;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.topbar-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 22px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  flex-wrap: wrap;
}
.topbar-rule {
  height: 4px;
  background: linear-gradient(90deg, var(--navy) 0%, var(--navy) 65%, var(--gold) 65%, var(--gold) 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 18px;
  color: inherit;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-logo {
  height: 56px;
  width: auto;
  display: block;
}
.brand-divider {
  width: 1px;
  height: 44px;
  background: var(--line-strong);
}
.brand-product {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1;
}
.brand-eyebrow {
  font-size: 10.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--navy);
  font-weight: 700;
  margin-bottom: 4px;
}
.brand-title {
  font-family: var(--font-serif);
  font-size: 32px;
  line-height: 0.95;
  color: var(--ink);
  letter-spacing: -0.01em;
  font-weight: 400;
}

.credibility {
  margin: 0;
  max-width: 420px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.55;
  text-align: right;
}
.credibility strong {
  color: var(--navy);
  font-weight: 700;
}

@media (max-width: 720px) {
  .topbar-inner { padding: 18px 18px; gap: 14px; }
  .brand-logo { height: 44px; }
  .brand-title { font-size: 26px; }
  .credibility { text-align: left; max-width: none; font-size: 12.5px; }
}

/* ---------- Mode switch (Constituency / National) ---------- */

.mode-switch {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.mode-switch-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 10px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.mode-switch-label {
  font-size: 10.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
}
.mode-switch-pills {
  display: inline-flex;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.mode-pill {
  appearance: none;
  background: transparent;
  border: none;
  padding: 7px 18px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  cursor: pointer;
  border-radius: 999px;
  transition: background 0.16s ease, color 0.16s ease;
}
.mode-pill:hover:not(.is-active) { color: var(--navy); }
.mode-pill.is-active {
  background: var(--navy);
  color: #fff;
  box-shadow: 0 2px 6px rgba(6, 29, 63, 0.2);
}
.mode-switch-hint {
  margin: 0;
  font-size: 12px;
  color: var(--ink-faint);
}

.mode-link {
  appearance: none;
  background: transparent;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--gold);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.mode-link:hover { color: #fff; text-decoration-thickness: 2px; }
.calc-empty .mode-link { color: var(--navy); }
.calc-empty .mode-link:hover { color: var(--accent-red); }

/* ---------- Swing panel (compact) ---------- */

.swing-panel {
  background: var(--navy);
  color: #fff;
  position: relative;
  overflow: hidden;
}
.swing-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(800px 400px at 90% -20%, rgba(176, 140, 63, 0.18), transparent 60%),
    radial-gradient(600px 300px at -5% 120%, rgba(255, 255, 255, 0.08), transparent 60%);
  pointer-events: none;
}
.swing-inner {
  position: relative;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 12px 28px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.swing-summary {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 18px;
  flex-shrink: 0;
}
/* Region / Seat name stat takes the left side and ellipsis-truncates if very
   long; the rest of the stats and the Reset button sit to its right. */
.swing-stat-name {
  flex: 1 1 auto;
  min-width: 0;
}
.swing-stat-name .swing-stat-value {
  font-family: var(--font-serif);
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.swing-stat { display: inline-flex; flex-direction: column; gap: 0; line-height: 1.1; }
.swing-stat-label {
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
  font-weight: 600;
}
.swing-stat-value {
  font-family: var(--font-serif);
  font-size: 17px;
  color: #fff;
  font-variant-numeric: tabular-nums;
}
.swing-reset {
  appearance: none;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 11px;
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.14s ease, color 0.14s ease, background 0.14s ease, box-shadow 0.14s ease;
  white-space: nowrap;
}
.swing-reset:hover {
  background: var(--accent-red);
  border-color: var(--accent-red);
  color: #fff;
  box-shadow: 0 4px 14px rgba(163, 38, 28, 0.4);
}

.swing-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1.1fr) minmax(180px, 1.1fr) auto minmax(0, 2fr) auto;
  gap: 12px;
  align-items: center;
}
.swing-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.swing-label {
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
  font-weight: 600;
}
.swing-field select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius-sm);
  padding: 7px 30px 7px 10px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='white' opacity='0.7'><path d='M3 6l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
}
.swing-field select:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(176, 140, 63, 0.3); }
.swing-field select option,
.swing-field select optgroup { background: var(--paper); color: var(--ink); }
.swing-arrow {
  font-family: var(--font-serif);
  font-size: 18px;
  color: var(--gold);
  align-self: end;
  padding-bottom: 4px;
}

.swing-slider-wrap {
  align-self: end;
  padding-bottom: 2px;
}
.swing-slider-wrap input[type="range"] { width: 100%; height: 24px; }
.swing-slider-wrap input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 3px;
}
.swing-slider-wrap input[type="range"]::-moz-range-track {
  height: 5px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 3px;
}
.swing-slider-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px; height: 20px;
  background: var(--gold);
  border: 2px solid var(--navy-deep);
  border-radius: 50%;
  margin-top: -8px;
  box-shadow: 0 0 0 1px var(--gold), 0 4px 12px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}
.swing-slider-wrap input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px;
  background: var(--gold);
  border: 2px solid var(--navy-deep);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--gold), 0 4px 12px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}
.swing-value-group {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  align-self: end;
  padding-bottom: 2px;
  min-width: 120px;
  line-height: 1;
}
.swing-value {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 400;
  color: var(--gold);
  letter-spacing: -0.01em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.swing-value-abs {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.62);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-top: 2px;
}

@media (max-width: 960px) {
  .swing-summary { width: 100%; justify-content: space-between; align-self: stretch; }
  .swing-controls {
    grid-template-columns: 1fr 1fr;
    gap: 10px 12px;
  }
  .swing-arrow { display: none; }
  .swing-slider-wrap { grid-column: 1 / -1; padding-bottom: 0; align-self: stretch; }
  .swing-value-group { grid-column: 1 / -1; flex-direction: row; align-items: baseline; gap: 10px; justify-content: flex-start; min-width: 0; }
  .swing-value { font-size: 20px; }
}

/* The two top strips are mutually exclusive: National mode shows the regional
   swing strip; Constituency mode shows the seat-level strip. The calc panel
   below also swaps: region-level aggregate in National, per-seat in Constituency. */
body.mode-national #seat-swing-panel { display: none; }
body.mode-constituency #swing-panel { display: none; }
/* The seat strip only makes sense once a constituency has been picked. */
body:not(.has-seat) #seat-swing-panel { display: none; }
/* Once a seat is picked the postcode/name search lives behind the "Pick
   different" button in the strip; no need to keep duplicating it above the map. */
body.has-seat .map-toolbar { display: none; }
/* The Pick-different button is only meaningful once a seat is loaded. */
body:not(.has-seat) #seat-picker-toggle { display: none; }

/* Inline seat-picker reveal inside the seat strip. */
.seat-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 14px;
  margin: 0 0 -2px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-sm);
}
.seat-picker[hidden] { display: none; }
.seat-picker-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.seat-picker-label {
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
  font-weight: 600;
}
.seat-picker-field input {
  appearance: none;
  background: #fffdf7;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  color: var(--ink);
  font-family: inherit;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
.seat-picker-field input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(176, 140, 63, 0.3);
}

#seat-picker-toggle[aria-expanded="true"] {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--navy-deep);
}

@media (max-width: 560px) {
  .seat-picker { grid-template-columns: 1fr; padding: 10px; }
  .seat-picker-field input { font-size: 16px; padding: 10px 12px; }
}
body.mode-national #calc,
body.mode-national #calc-empty { display: none; }
body.mode-constituency #region-calc { display: none; }
/* The postcode/constituency search is for picking a single seat - hide it in national mode. */
body.mode-national .map-toolbar { display: none; }

.region-result-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 18px 22px;
}
@media (max-width: 560px) {
  .region-result-card { display: none; }
}
.region-result-card .result-value {
  font-family: var(--font-serif);
  font-size: 44px;
  line-height: 1;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}
.region-result-card .result-margin {
  font-size: 13px;
  color: var(--ink-soft);
}


/* Empty-state for the seat swing strip before a seat is picked. */
.seat-swing-empty {
  position: relative;
  color: rgba(255, 255, 255, 0.78);
  font-size: 13.5px;
  text-align: center;
  padding: 6px 0 4px;
}
.seat-swing-panel .swing-inner { gap: 8px; }
.seat-swing-panel .swing-summary {
  align-self: stretch;
  width: 100%;
  justify-content: space-between;
}
/* Seat strip has only one dropdown (Move from), so override the national grid. */
.seat-swing-panel .swing-controls {
  grid-template-columns: minmax(200px, 1.4fr) auto minmax(0, 2fr) auto;
}
/* Desktop: once a seat is loaded, the navy strip is redundant - Pick/Reset
   buttons move into the calc card via placeSeatControls() in app.js. */
@media (min-width: 561px) {
  body.has-seat .seat-swing-panel { display: none; }
  .calc-header-actions {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    flex-wrap: nowrap;
    flex-shrink: 0;
  }
  /* Re-tint the moved buttons for the cream card background. */
  .calc-header-actions .swing-reset {
    color: var(--navy);
    border-color: var(--navy);
    background: var(--paper);
    padding: 9px 16px;
    font-size: 12px;
  }
  .calc-header-actions .swing-reset:hover {
    background: var(--navy);
    color: #fff;
  }
  /* The moved seat-picker now lives inside .calc with a cream background. */
  .calc > .seat-picker {
    background: var(--paper);
    border-color: var(--line);
    margin: 0 0 18px;
  }
  .calc > .seat-picker .seat-picker-label { color: var(--ink-faint); }
  .calc > .seat-picker .seat-picker-field input {
    border-color: var(--line);
    background: #fff;
  }
}
/* On desktop the national-mode panel hides the raw slider + percent/votes
   readout - users drive swings via the bar-chart handles below. Mobile keeps
   the slider for tap accuracy. The arrow has nothing to point at once the
   slider is gone, so drop it too. */
@media (min-width: 561px) {
  .swing-panel:not(.seat-swing-panel) .swing-controls {
    grid-template-columns: minmax(180px, 1.1fr);
  }
  .swing-panel:not(.seat-swing-panel) .swing-slider-wrap,
  .swing-panel:not(.seat-swing-panel) .swing-value-group,
  .swing-panel:not(.seat-swing-panel) .swing-arrow,
  .swing-panel:not(.seat-swing-panel) .swing-field:has(#swing-source) {
    display: none;
  }
}
@media (max-width: 960px) {
  .seat-swing-panel .swing-controls { grid-template-columns: 1fr; }
}

/* ---------- Layout ---------- */

.layout {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 28px 56px;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 22px;
  align-items: stretch;
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; padding: 18px 18px 40px; }
  .credibility { text-align: left; max-width: none; }
}

.map-panel, .calc-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.map-panel {
  display: flex;
  flex-direction: column;
}
.calc-panel {
  padding: 0;
}

/* ---------- Search / toolbar ---------- */

.map-toolbar {
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fffefb 0%, var(--paper) 100%);
}
.search {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.search-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.search-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--navy);
  font-weight: 600;
}
.search-field input {
  appearance: none;
  background: #fffdf7;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--ink);
  font-family: inherit;
  transition: border-color 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}
.search-field input:hover { border-color: var(--navy-soft); }
.search-field input:focus {
  outline: none;
  border-color: var(--navy);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(6, 29, 63, 0.12);
}
.search-status {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--ink-soft);
  min-height: 1.1em;
}
.search-status.err { color: var(--accent-red); }

/* ---------- Map ---------- */

#map {
  flex: 1 1 auto;
  min-height: 660px;
  width: 100%;
  background: #eef2f3;
}
@media (max-width: 960px) {
  #map { height: 460px; }
  .map-panel, .calc-panel { position: static; }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-soft);
  background: linear-gradient(180deg, var(--paper) 0%, #fffefb 100%);
}
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-swatch {
  width: 12px; height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.12);
  display: inline-block;
}

/* ---------- Calculator panel ---------- */

.calc-empty {
  padding: 72px 32px;
  text-align: center;
  color: var(--ink-soft);
}
.calc-empty h2 {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 400;
  margin-bottom: 8px;
  color: var(--navy);
  letter-spacing: -0.01em;
}
.calc-empty p { margin: 0; font-size: 14.5px; max-width: 320px; margin-inline: auto; }
.calc-empty-alt {
  margin-top: 18px !important;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 13px !important;
}

.calc { padding: 24px 26px 30px; }

.calc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 18px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
#seat-name,
#region-name {
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 400;
  line-height: 1.1;
  color: var(--navy);
  letter-spacing: -0.015em;
}
.seat-meta {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
/* On desktop the seat strip's "Reset seat" button covers this; mobile keeps
   both since the strip can scroll off-screen while the user is in the calc card. */
.reset-btn { display: none; }
@media (max-width: 560px) {
  .reset-btn { display: inline-block; }
}
.reset-btn {
  appearance: none;
  background: var(--paper);
  border: 1px solid var(--navy);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 12px;
  color: var(--navy);
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.14s ease, color 0.14s ease, background 0.14s ease, box-shadow 0.14s ease;
  white-space: nowrap;
}
.reset-btn:hover {
  background: var(--navy);
  color: #fff;
  box-shadow: 0 4px 12px rgba(6, 29, 63, 0.2);
}

/* ---------- Result card ---------- */

.result-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  background: var(--cream-warm);
  transition: background 0.22s ease, border-color 0.22s ease, color 0.22s ease;
  overflow: hidden;
}
.result-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--navy);
  transition: background 0.22s ease;
}
.result-card.flipped {
  background: var(--flip-bg);
  border-color: var(--flip-bg);
  color: var(--flip-ink);
  animation: flip-flash 0.6s ease;
  box-shadow: var(--shadow-md);
}
.result-card.flipped::before { background: var(--gold); }
.result-card.flipped .result-label  { color: var(--flip-ink); opacity: 0.65; }
.result-card.flipped .result-margin { color: var(--flip-ink); opacity: 0.8; }
.result-card.flipped .result-arrow  { color: var(--flip-ink); opacity: 0.4; }
.result-card.flipped #baseline-winner,
.result-card.flipped #now-winner { color: var(--flip-ink) !important; }
@keyframes flip-flash {
  0%   { filter: brightness(1.5); }
  100% { filter: brightness(1); }
}
.result-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 14px;
  align-items: center;
}
.result-block { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.result-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  font-weight: 600;
}
.result-value {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.005em;
}
.result-margin {
  font-size: 13px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.result-arrow {
  color: var(--ink-faint);
  font-size: 22px;
  font-family: var(--font-serif);
}
/* ---------- Voter pools (vertical bar chart) ---------- */

.pools {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 50px 4px 4px;
  /* Reserve room above the bars for the handle's bubble label without it
     clipping when a bar is at full height. overflow-x: auto forces overflow-y
     to clip too, so the top padding has to be tall enough for the callout. */
  overflow-x: auto;
  scrollbar-width: thin;
}
.pool {
  flex: 1 1 0;
  min-width: 44px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  position: relative;
}
.pool-crown {
  position: absolute;
  left: 50%;
  bottom: calc(var(--h, 0) * 1%);
  width: 22px;
  height: 18px;
  transform: translate(-50%, calc(-100% - 4px));
  color: #d4a015;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.15s ease;
  filter: drop-shadow(0 1px 2px rgba(6, 29, 63, 0.25));
}
.pool-crown svg { display: block; width: 100%; height: 100%; }
.pool.is-leader .pool-crown { opacity: 1; }
/* The Restore Britain bar shows a callout bubble at the top, so lift the
   crown above it on that bar specifically. */
.pool.target .pool-crown { transform: translate(-50%, calc(-100% - 28px)); }
/* Region numbers run to 7 digits, so widen the columns there. */
#region-pools .pool { min-width: 58px; }
.pool-bar {
  position: relative;
  height: 220px;
  width: 100%;
}
.pool-bar-track {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--h, 0) * 1%);
  border-radius: 5px 5px 0 0;
  overflow: hidden;
  background: rgba(6, 29, 63, 0.04);
}
.pool-bar-stripe {
  position: absolute;
  inset: 0;
  background-color: var(--pool-color, var(--ink-faint));
  opacity: 0.18;
  background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.5) 0 4px, transparent 4px 8px);
}

/* Intro animation: when the region chart first renders we sweep handles down
   to a plausible Restore-win state. Transitions are scoped to the class so
   subsequent user drags stay snappy. */
.pools.is-intro-anim .pool-bar-track,
.pools.is-intro-anim .pool-bar-fill {
  transition: height 1.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.pools.is-intro-anim .pool-bar-handle,
.pools.is-intro-anim .pool-callout,
.pools.is-intro-anim .pool-crown,
.pools.is-intro-anim .pool-drag-pct {
  transition: bottom 1.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.pool-bar-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--fill, 0) * 1%);
  background: var(--pool-color, var(--navy));
  border-radius: 0 0 0 0;
}
.pool.target .pool-bar-stripe { display: none; }
.pool-bar-handle {
  position: absolute;
  left: 50%;
  /* Handle sits at the top of the fill. The fill is --fill% of the track,
     and the track is --h% of the pool-bar, so absolute % of pool-bar is h*fill/100. */
  bottom: calc(var(--h, 0) * 1% * var(--fill, 0) / 100);
  transform: translate(-50%, 50%);
  width: 18px;
  height: 18px;
  background: var(--navy);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(6, 29, 63, 0.35);
  cursor: ns-resize;
  touch-action: none;
  z-index: 2;
}
.pool-bar-handle:focus { outline: none; box-shadow: 0 0 0 4px rgba(6, 29, 63, 0.22), 0 2px 6px rgba(6, 29, 63, 0.35); }
.pool-bar-handle:active { transform: translate(-50%, 50%) scale(1.12); }

/* Mid-drag badge showing the bar's current value as a share of the chart's
   total (i.e. share of the constituency or region electorate). Only visible
   while the user is actively dragging that pool's handle. */
.pool-drag-pct {
  position: absolute;
  left: 50%;
  bottom: calc(var(--h, 0) * 1% * var(--fill, 0) / 100);
  transform: translate(-50%, calc(-100% - 14px));
  background: var(--navy);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 3px 7px;
  border-radius: 4px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  z-index: 6;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
  box-shadow: 0 2px 6px rgba(6, 29, 63, 0.35);
}
.pool.is-dragging .pool-drag-pct { opacity: 1; }

.pool-callout {
  position: absolute;
  left: 50%;
  bottom: calc(var(--h, 0) * 1% * var(--fill, 0) / 100);
  transform: translate(-50%, calc(-100% - 6px));
  background: var(--navy);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 3px 6px;
  border-radius: 4px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  z-index: 3;
}
.pool-callout::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--navy);
}

.pool-label {
  margin-top: 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.pool-name {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pool-current {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 400;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pool.non-voter .pool-current { color: var(--ink-soft); }
.pool-baseline {
  font-size: 9.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* Pin line-height so empty and text baselines occupy identical height -
     otherwise the empty Restore Britain row collapses, the column gets
     shorter, and flex-end alignment pushes its label area down. */
  line-height: 1.2;
  min-height: 1.2em;
}

@media (max-width: 560px) {
  .pools { gap: 8px; }
  .pool { min-width: 62px; }
  #region-pools .pool { min-width: 70px; }
  .pool-current { font-size: 13px; }
  .pool-baseline { font-size: 9px; }
}

.sources-detail { margin-top: 18px; }

/* ---------- Sources list ---------- */

.sources-help {
  margin: 26px 0 14px;
  padding: 12px 14px;
  background: var(--cream-warm);
  border: 1px solid var(--line);
  border-left: 3px solid var(--navy);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.55;
}
.sources-help em { font-style: italic; color: var(--ink); font-weight: 500; }
.sources-help strong { color: var(--navy); font-weight: 700; }

.sources { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 9px; }

.source {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
.source:hover { border-color: var(--line-strong); }
.source.is-target {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--flip-ink);
  box-shadow: 0 4px 14px rgba(6, 29, 63, 0.18);
}
.source.is-target .source-name { color: var(--flip-ink); }
.source.is-target .source-tallies { color: rgba(255, 255, 255, 0.85); }
.source.is-target .source-tallies .current { color: var(--flip-ink); }
.source.non-voter {
  background: var(--cream-warm);
  border-color: var(--line-strong);
  border-style: dashed;
}
.source-swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.18);
}
.source.is-target .source-swatch { border-color: rgba(255,255,255,0.5); }
.source-body { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.source-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 13.5px;
}
.source-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}
.source-name small { font-weight: 400; color: var(--ink-faint); margin-left: 6px; }
.source-tallies {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  font-size: 13px;
  white-space: nowrap;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}
.source-tallies .current { color: var(--ink); font-weight: 700; }
.source-tallies .delta { color: var(--accent-red); font-size: 12px; font-weight: 600; }
.source-tallies .delta.gain { color: var(--accent-green); }
.source-tallies .delta.zero { display: none; }
.source.is-target .source-tallies .delta.gain { color: var(--gold); }
.source input[type="range"] {
  width: 100%;
  margin: 0;
}
.source-foot {
  display: flex;
  justify-content: flex-end;
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: -2px;
}
.source-baseline { font-variant-numeric: tabular-nums; }

.source.target-bucket .source-name small {
  color: rgba(255, 255, 255, 0.65);
  font-weight: 600;
  margin-left: 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}
.source.target-bucket .source-tallies .current { font-size: 17px; font-family: var(--font-serif); font-weight: 400; }

/* ---------- Range slider ---------- */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 22px;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  background: var(--line-strong);
  border-radius: 3px;
}
input[type="range"]::-moz-range-track {
  height: 5px;
  background: var(--line-strong);
  border-radius: 3px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  background: var(--navy);
  border: 2px solid #fff;
  border-radius: 50%;
  margin-top: -7px;
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--navy-soft), 0 2px 4px rgba(6, 29, 63, 0.3);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.1); }
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  background: var(--navy);
  border: 2px solid #fff;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--navy-soft), 0 2px 4px rgba(6, 29, 63, 0.3);
}
input[type="range"]:focus { outline: none; }
input[type="range"]:focus::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(6, 29, 63, 0.18); }
input[type="range"]:disabled::-webkit-slider-thumb { background: var(--ink-faint); cursor: not-allowed; box-shadow: none; }
input[type="range"]:disabled::-moz-range-thumb { background: var(--ink-faint); cursor: not-allowed; box-shadow: none; }

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-faint);
  font-size: 12px;
  margin-top: auto;
}
.site-footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 18px 28px 22px;
  /* Respect iOS home-indicator inset so the footer never clips on mobile. */
  padding-bottom: max(22px, calc(22px + env(safe-area-inset-bottom)));
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 24px;
}
.site-footer p { margin: 0; }
.site-footer-brand {
  color: var(--ink-soft);
  font-weight: 500;
}
.site-footer-brand a {
  color: var(--navy);
  font-weight: 700;
  letter-spacing: 0.01em;
}

@media (max-width: 560px) {
  .site-footer-inner {
    padding: 14px 16px 38px;
    padding-bottom: max(38px, calc(38px + env(safe-area-inset-bottom)));
    flex-direction: column;
    gap: 6px;
  }
  .site-footer { font-size: 11.5px; }
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 29, 63, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
  animation: modal-fade-in 0.16s ease;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--paper);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 28px 28px 22px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: modal-pop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}
.modal::before {
  content: "";
  position: absolute;
  left: 0; top: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--navy) 0%, var(--navy) 70%, var(--gold) 70%, var(--gold) 100%);
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 400;
  color: var(--navy);
  margin: 6px 0 10px;
  letter-spacing: -0.01em;
}
.modal-body {
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
  margin: 0 0 22px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}
.modal-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(6, 29, 63, 0.22);
}
.modal-btn-ghost { color: var(--ink-soft); }
.modal-btn-ghost:hover {
  border-color: var(--navy);
  color: var(--navy);
  background: var(--cream-warm);
}
.modal-btn-danger {
  background: var(--accent-red);
  border-color: var(--accent-red);
  color: #fff;
}
.modal-btn-danger:hover {
  background: #851d15;
  border-color: #851d15;
  box-shadow: 0 6px 18px rgba(163, 38, 28, 0.4);
}

body.modal-open { overflow: hidden; }

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modal-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Leaflet overrides ---------- */

.leaflet-container {
  background: #eef2f3;
  font-family: inherit;
}
.leaflet-tooltip.seat-tip {
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(6, 29, 63, 0.25);
  letter-spacing: 0.01em;
}
.leaflet-tooltip.seat-tip::before { display: none; }

.leaflet-control-zoom a {
  background: var(--paper) !important;
  color: var(--navy) !important;
  border: 1px solid var(--line) !important;
}
.leaflet-control-zoom a:hover {
  background: var(--cream-warm) !important;
}
.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.85) !important;
  color: var(--ink-faint) !important;
  font-size: 10.5px !important;
}
.leaflet-control-attribution a { color: var(--navy) !important; }

/* ---------- Phone (≤560px) ---------- */
/* Consolidated overrides so the tool stays usable on a portrait phone. The
   guiding rules: form inputs ≥16px font (no iOS zoom on focus), tap targets
   ≥40px, single-column stacks, slightly larger slider thumbs for fingers. */

@media (max-width: 560px) {
  html, body { font-size: 14.5px; }

  /* On mobile, the seat strip at the top already shows the seat name, and the
     pool chart shows the result of any swing. The seat-meta line and the
     real/hypothetical result card are redundant there; hide both. */
  #calc .seat-meta { display: none; }
  #calc #result-card { display: none; }

  /* On mobile, shorten the help text to its first sentence. */
  .sources-help-extra { display: none; }

  /* Topbar: compact logo, divider stays, stack credibility below the brand. */
  .topbar-inner { padding: 14px 16px; gap: 12px; }
  .brand { gap: 12px; }
  .brand-logo { height: 36px; }
  .brand-divider { height: 30px; }
  .brand-title { font-size: 22px; }
  .brand-eyebrow { font-size: 9.5px; letter-spacing: 0.18em; margin-bottom: 3px; }
  .credibility {
    text-align: left;
    max-width: none;
    font-size: 12px;
    width: 100%;
  }
  .topbar-rule { height: 3px; }

  .mode-switch-inner { padding: 8px 14px; gap: 10px; flex-wrap: wrap; }
  .mode-switch-hint { display: none; }
  .mode-pill { padding: 8px 14px; font-size: 13px; }

  /* Swing panel: compact stack. */
  .swing-inner { padding: 12px 14px 14px; gap: 10px; }
  .swing-blurb { font-size: 12.5px; line-height: 1.45; }
  .swing-controls { grid-template-columns: 1fr 1fr; gap: 10px; }
  .swing-field select { font-size: 16px; padding: 10px 32px 10px 12px; }
  .swing-slider-wrap { grid-column: 1 / -1; }
  .swing-slider-wrap input[type="range"] { height: 32px; }
  .swing-slider-wrap input[type="range"]::-webkit-slider-thumb {
    width: 26px; height: 26px; margin-top: -11px;
  }
  .swing-slider-wrap input[type="range"]::-moz-range-thumb {
    width: 26px; height: 26px;
  }
  .swing-value-group {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: baseline;
    gap: 10px;
    justify-content: flex-start;
    min-width: 0;
  }
  .swing-value { text-align: left; font-size: 22px; }
  .swing-value-abs { font-size: 11.5px; margin-top: 0; }
  .swing-summary { gap: 14px; }
  .swing-stat-value { font-size: 16px; }
  .swing-reset { padding: 7px 12px; font-size: 11px; }
  /* When placeResetButton() moves Reset into the Mode strip on mobile, retint
     it for the cream background and push it to the far right. */
  .mode-switch-inner .swing-reset {
    margin-left: auto;
    color: var(--navy);
    border-color: rgba(6, 29, 63, 0.3);
  }
  .mode-switch-inner .swing-reset:hover {
    color: #fff;
    border-color: var(--accent-red);
  }
  /* National-mode mobile: hide the Region/In region/UK-wide stat triad to
     reclaim space; keep the Reset button accessible. */
  .swing-panel:not(.seat-swing-panel) .swing-summary .swing-stat { display: none; }

  /* Layout: single column with wider side gutters so thumbs can scroll past
     the map without the touch landing on the pannable canvas. */
  .layout { padding: 14px 22px 32px; gap: 14px; }
  .map-panel, .calc-panel { border-radius: var(--radius); }

  /* Map toolbar: stack postcode + name search; bump font-size so iOS doesn't zoom. */
  .map-toolbar { padding: 14px 14px 12px; }
  .search { grid-template-columns: 1fr; gap: 10px; }
  .search-field input { font-size: 16px; padding: 12px 14px; }
  #map { height: 380px; }
  /* Mobile: compact the legend to a single row of colour squares; full names
     live in the tap-to-open modal. The container clips any overflow rather
     than wrapping so the strip never grows taller than one row. */
  .legend {
    padding: 10px 14px 12px;
    gap: 8px;
    flex-wrap: nowrap;
    overflow: hidden;
    cursor: pointer;
  }
  .legend .legend-name { display: none; }
  .legend .legend-item { gap: 0; flex-shrink: 0; }
  .legend .legend-swatch { width: 18px; height: 18px; border-radius: 4px; }
  /* The legend-modal variant lives inside the modal body and DOES show names
     and wrap, so the user can read every party. */
  .legend-modal {
    display: flex;
    flex-wrap: wrap;
    gap: 16px 22px;
    overflow: visible;
    cursor: auto;
    padding: 22px 2px 4px;
  }
  .legend-modal .legend-name { display: inline; }
  .legend-modal .legend-item { gap: 10px; }
  .legend-modal .legend-swatch { width: 14px; height: 14px; }

  /* Calc panel. */
  .calc { padding: 18px 16px 22px; }
  .calc-empty { padding: 48px 18px; }
  .calc-empty h2 { font-size: 24px; }
  .calc-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding-bottom: 14px;
    margin-bottom: 16px;
  }
  #seat-name, #region-name { font-size: 26px; }
  .seat-meta { font-size: 12px; line-height: 1.45; }
  .reset-btn { align-self: flex-start; padding: 11px 18px; font-size: 12px; }

  /* Result card: stack the two columns; arrow becomes a downward chevron. */
  .result-card { padding: 16px 16px 14px; }
  .result-row {
    grid-template-columns: 1fr;
    gap: 12px;
    text-align: left;
  }
  .result-arrow {
    display: inline-block;
    transform: rotate(90deg);
    justify-self: start;
    font-size: 18px;
    line-height: 1;
    padding: 2px 0;
  }
  .result-value { font-size: 19px; }
  .result-margin { font-size: 12.5px; }

  /* Source rows: larger touch slider thumb, slightly more vertical breathing room. */
  .sources-help { font-size: 12.5px; padding: 11px 12px; }
  .source { padding: 11px 12px; gap: 10px; }
  .source-head { font-size: 13px; }
  .source input[type="range"] { height: 32px; }
  .source input[type="range"]::-webkit-slider-thumb {
    width: 22px; height: 22px; margin-top: -9px;
  }
  .source input[type="range"]::-moz-range-thumb {
    width: 22px; height: 22px;
  }

  /* Modal: bottom-sheet feel; full-width buttons. */
  .modal-backdrop { padding: 16px; align-items: center; }
  .modal { padding: 22px 20px 18px; max-width: none; }
  .modal-title { font-size: 21px; }
  .modal-body { font-size: 13.5px; margin-bottom: 18px; }
  .modal-actions { flex-direction: column-reverse; gap: 8px; }
  .modal-btn { width: 100%; padding: 13px 16px; font-size: 12.5px; }
}
