/* ============================================================
   US States Atlas — design system.
   "Civic blueprint / census report" aesthetic — distinct from this
   account's other comparison sites (tarot's Bauhaus look, the
   calendar's antique observatory look, country-atlas's GIS/National
   Geographic look). Navy (Side A) / brick red (Side B) on cream,
   like an official government report with a technical-schematic
   edge (fitting the tile-grid map's honestly-schematic nature).
   ============================================================ */
:root {
  --paper: #f6f2e9;
  --panel: #ffffff;
  --panel-alt: #ede6d3;
  --ink: #1c2430;
  --ink-dim: #5c6470;
  --line: #cfc6ae;

  --side-a: #1d3557;
  --side-a-soft: #dde6ef;
  --side-b: #9c2b2b;
  --side-b-soft: #f3dcdc;
  --gold: #b0863c;

  --party-d: #1d3557;
  --party-r: #9c2b2b;
  --party-i: #7a7256;
  --party-split: #6d5a8f;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", monospace;

  --radius: 3px;
  --shadow: 0 2px 8px rgba(28, 36, 48, 0.12);
}

:root[data-theme="dark"] {
  --paper: #12161c;
  --panel: #1a2029;
  --panel-alt: #151a22;
  --ink: #eae6da;
  --ink-dim: #93998f4d;
  --ink-dim: #98a0aa;
  --line: #303945;
  --side-a: #5b8fc9;
  --side-a-soft: #1b2a3b;
  --side-b: #d3716b;
  --side-b-soft: #35201d;
  --gold: #cfa84f;
  --party-d: #5b8fc9;
  --party-r: #d3716b;
  --party-i: #b3a876;
  --party-split: #9a86c4;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12161c;
    --panel: #1a2029;
    --panel-alt: #151a22;
    --ink: #eae6da;
    --ink-dim: #98a0aa;
    --line: #303945;
    --side-a: #5b8fc9;
    --side-a-soft: #1b2a3b;
    --side-b: #d3716b;
    --side-b-soft: #35201d;
    --gold: #cfa84f;
    --party-d: #5b8fc9;
    --party-r: #d3716b;
    --party-i: #b3a876;
    --party-split: #9a86c4;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
}

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 2px solid var(--ink);
}
.topbar-inner {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px; max-width: 1200px; margin: 0 auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 600;
  font-size: 1.15rem; color: var(--ink); text-decoration: none; white-space: nowrap;
}
.brand .glyph { width: 24px; height: 24px; }
.site-nav { display: flex; gap: 18px; margin-left: 24px; }
.site-nav a {
  font-family: var(--font-mono); font-size: 0.78rem; color: var(--ink-dim); text-decoration: none;
  padding-bottom: 2px; border-bottom: 2px solid transparent;
}
.site-nav a:hover { color: var(--ink); }
.site-nav a.active { color: var(--ink); border-bottom-color: var(--gold); }
.theme-toggle {
  margin-left: auto; background: transparent; border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--radius); padding: 6px 10px; font-family: var(--font-mono);
  font-size: 0.72rem; cursor: pointer;
}
@media (max-width: 640px) { .site-nav { display: none; } }

.hero { padding: 36px 0 8px; text-align: center; }
.hero .eyebrow {
  font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--gold); margin-bottom: 8px;
}
.hero h1 { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.7rem, 4.2vw, 2.5rem); margin: 0; }
.hero p { color: var(--ink-dim); max-width: 60ch; margin: 10px auto 0; font-size: 0.94rem; }

.selector-row {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: stretch; margin: 26px 0;
}
@media (max-width: 720px) { .selector-row { grid-template-columns: 1fr; } .vs-badge { display: none; } }

.state-panel {
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.state-panel.side-a { border-color: var(--side-a); }
.state-panel.side-b { border-color: var(--side-b); }
.panel-side-label {
  font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; margin-bottom: 8px;
}
.side-a .panel-side-label { color: var(--side-a); }
.side-b .panel-side-label { color: var(--side-b); }

.state-panel select {
  width: 100%; background: var(--panel-alt); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); padding: 8px 10px; font-family: var(--font-body); font-size: 0.92rem; margin-bottom: 12px;
}

.state-card { display: flex; gap: 12px; align-items: center; }
.state-card .abbr-badge {
  font-family: var(--font-mono); font-weight: 700; font-size: 1.1rem;
  width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.side-a .abbr-badge { background: var(--side-a); }
.side-b .abbr-badge { background: var(--side-b); }
.state-card h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.2rem; margin: 0 0 4px; }
.state-card .basics { font-size: 0.82rem; color: var(--ink-dim); display: grid; gap: 2px; }
.state-card .basics b { color: var(--ink); font-weight: 600; }

.vs-badge {
  align-self: center; font-family: var(--font-display); font-weight: 700; font-size: 1.05rem;
  color: var(--ink-dim); width: 42px; height: 42px; border-radius: 50%; border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center; background: var(--panel);
}

/* ---------- Map mode toggle ---------- */
.map-mode-toggle {
  display: flex; justify-content: center; gap: 2px; margin: 0 auto 14px; width: fit-content;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.map-mode-btn {
  background: var(--panel); border: none; color: var(--ink-dim); cursor: pointer;
  font-family: var(--font-mono); font-size: 0.74rem; padding: 8px 16px;
}
.map-mode-btn.active { background: var(--ink); color: var(--paper); }
:root[data-theme="dark"] .map-mode-btn.active { background: var(--gold); color: #12161c; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .map-mode-btn.active { background: var(--gold); color: #12161c; }
}

/* ---------- Tile grid map ---------- */
.map-section { margin: 30px 0; }
.map-hint { font-size: 0.85rem; color: var(--ink-dim); margin-bottom: 12px; text-align: center; max-width: 760px; margin-left: auto; margin-right: auto; }
.map-hint b { color: var(--ink); }
.map-hint code { font-family: var(--font-mono); font-size: 0.85em; }
.tile-grid {
  display: grid; gap: 3px; max-width: 720px; margin: 0 auto;
  grid-template-columns: repeat(12, 1fr);
}
.tile-grid[hidden], .geo-map[hidden] { display: none; }
.tile {
  aspect-ratio: 1; background: var(--panel-alt); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700; color: var(--ink-dim);
  border-radius: 2px; transition: transform 0.1s ease;
  position: relative;
}
.tile:hover { transform: scale(1.08); z-index: 5; border-color: var(--ink); color: var(--ink); }
.tile.is-a { background: var(--side-a); color: #fff; border-color: var(--side-a); }
.tile.is-b { background: var(--side-b); color: #fff; border-color: var(--side-b); }
.tile.is-a.is-b { background: linear-gradient(135deg, var(--side-a) 50%, var(--side-b) 50%); }
.map-caption { text-align: center; font-size: 0.74rem; color: var(--ink-dim); margin-top: 10px; }

/* ---------- Geographic map ---------- */
.geo-map { max-width: 800px; margin: 0 auto; }
.geo-svg { width: 100%; height: auto; display: block; }
.geo-state {
  fill: var(--panel-alt); stroke: var(--line); stroke-width: 1; cursor: pointer;
  transition: fill 0.12s ease;
}
.geo-state:hover { fill: var(--line); }
.geo-state.is-a { fill: var(--side-a); }
.geo-state.is-b { fill: var(--side-b); }
.geo-error { text-align: center; color: var(--ink-dim); font-size: 0.85rem; padding: 30px 0; }

/* ---------- Government page: layer toggle ---------- */
.layer-toggle {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; margin: 0 auto 24px; width: fit-content;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.layer-btn {
  background: var(--panel); border: none; color: var(--ink-dim); cursor: pointer;
  font-family: var(--font-mono); font-size: 0.76rem; padding: 10px 18px;
}
.layer-btn.active { background: var(--ink); color: var(--paper); }
:root[data-theme="dark"] .layer-btn.active { background: var(--gold); color: #12161c; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .layer-btn.active { background: var(--gold); color: #12161c; }
}

/* ---------- Government page: summary stat cards ---------- */
.gov-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 26px;
}
.gov-stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-align: center;
}
.gov-stat .n { font-family: var(--font-display); font-weight: 700; font-size: 1.6rem; }
.gov-stat .lbl { font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-dim); margin-top: 4px; }
.gov-stat .n.r { color: var(--party-r); }
.gov-stat .n.d { color: var(--party-d); }
.gov-stat .n.i { color: var(--party-i); }

/* ---------- Government page: party legend ---------- */
.party-legend {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; margin-bottom: 16px;
  font-family: var(--font-mono); font-size: 0.76rem; color: var(--ink-dim);
}
.party-legend .swatch { display: inline-flex; align-items: center; gap: 6px; }
.party-legend .dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ---------- Government page: state detail panel ---------- */
.state-detail {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 24px; margin: 28px 0 40px; min-height: 60px;
}
.state-detail-hint { color: var(--ink-dim); font-size: 0.88rem; text-align: center; margin: 0; }
.state-detail h2 { font-family: var(--font-display); font-size: 1.3rem; margin: 0 0 12px; }
.state-detail .detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 24px; }
.state-detail .detail-row { font-size: 0.9rem; }
.state-detail .detail-row .k { color: var(--ink-dim); font-family: var(--font-mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; display: block; margin-bottom: 2px; }
.state-detail .detail-row a { color: var(--gold); text-decoration: underline; }
.state-detail .house-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin-top: 6px; border: 1px solid var(--line); }
.state-detail .house-bar .r { background: var(--party-r); }
.state-detail .house-bar .d { background: var(--party-d); }

/* ---------- Hemicycle seat chart (Congress & Government page) ---------- */
.hemicycle-wrap { max-width: 780px; margin: 0 auto; }
.hemicycle-svg { width: 100%; height: auto; display: block; }
.seat { cursor: pointer; stroke: var(--paper); stroke-width: 1; transition: transform 0.1s ease; transform-box: fill-box; transform-origin: center; }
.seat:hover { transform: scale(1.25); }
.seat.party-r { fill: var(--party-r); }
.seat.party-d { fill: var(--party-d); }
.seat.party-i { fill: var(--party-i); }
.seat.party-split { fill: var(--party-split); }
.seat.party-none { fill: var(--line); }
.seat.selected { stroke: var(--ink); stroke-width: 2.5; }

/* ---------- Scale strip ---------- */
.scale-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: 20px 0 32px;
}
.scale-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.scale-card .label {
  font-family: var(--font-mono); font-size: 0.64rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold); margin-bottom: 6px;
}
.scale-card .value { font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; }
.scale-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin-top: 8px; border: 1px solid var(--line); }
.scale-bar .a { background: var(--side-a); }
.scale-bar .b { background: var(--side-b); }

/* ---------- Comparison table ---------- */
.compare-section { margin: 20px 0 48px; }
.compare-section h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.4rem; margin: 0 0 16px; }
table.compare-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.compare-table tr { border-bottom: 1px solid var(--line); }
.compare-table td { padding: 12px 10px; vertical-align: top; }
.compare-table td.val { font-family: var(--font-mono); font-size: 0.95rem; width: 37%; white-space: normal; overflow-wrap: break-word; }
.compare-table td.val.a { color: var(--side-a); text-align: right; }
.compare-table td.val.b { color: var(--side-b); text-align: left; }
.compare-table td.val a { color: inherit; text-decoration: underline; text-decoration-color: currentColor; text-underline-offset: 2px; opacity: 0.9; }
.compare-table td.val a:hover { opacity: 1; }
.compare-table td.lbl { text-align: center; font-size: 0.8rem; color: var(--ink-dim); width: 26%; }
.compare-table td.lbl .name { color: var(--ink); font-weight: 600; display: block; }
.compare-table tr.section-row td {
  border-bottom: none; padding: 22px 10px 6px;
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--gold);
}
.compare-table tr.section-row:first-child td { padding-top: 4px; }
.compare-bar { display: flex; height: 5px; margin-top: 6px; border-radius: 3px; overflow: hidden; }
.compare-bar .a { background: var(--side-a); }
.compare-bar .b { background: var(--side-b); }

footer { text-align: center; padding: 30px 20px 50px; color: var(--ink-dim); font-size: 0.76rem; }
footer a { color: var(--gold); }

@media (max-width: 640px) {
  .tile { font-size: 0.6rem; }
  .compare-table td.lbl { font-size: 0.72rem; }
  .compare-table td.val { font-size: 0.8rem; }
}
