:root {
  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bg: #0b0f14;
  --bg-elevated: #11161d;
  --panel-bg: rgba(19, 25, 33, 0.78);
  --panel-border: rgba(255, 255, 255, 0.09);
  --ink: #eef2f6;
  --ink-soft: #93a1b0;
  --ink-faint: #5d6b7a;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-hud: 0 8px 28px rgba(0, 0, 0, 0.45), 0 1px 0 rgba(255, 255, 255, 0.04) inset;

  --council: #2A9D8F;
  --assembly: #E9A23B;
  --senate: #7B6CD9;
  --congress: #D6607A;
  --neutral: #4a5568;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-stack);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */

.site-header {
  background: linear-gradient(180deg, #0f141b 0%, #0b0f14 100%);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px 0;
  position: sticky;
  top: 0;
  z-index: 500;
}

.header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.wordmark {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.wordmark-sub {
  font-weight: 400;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.trust-line {
  margin: 0 0 8px;
  font-size: 0.72rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tab-nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding-bottom: 0;
}

.tab {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 9px 8px;
  border-radius: 8px 8px 0 0;
  white-space: nowrap;
  color: var(--ink-faint);
  flex-shrink: 0;
}

.tab-active {
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom: 1px solid var(--bg);
  margin-bottom: -1px;
}

.tab-disabled {
  color: var(--ink-faint);
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.tab-disabled em {
  font-style: normal;
  font-size: 0.56rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 4px;
  border-radius: 999px;
}

/* ---------- Error banner ---------- */

.error-banner {
  background: #3a1416;
  color: #ffb4b4;
  border-bottom: 1px solid #5c2226;
  padding: 10px 16px;
  font-size: 0.85rem;
}

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

.map-section {
  position: relative;
  height: 62vh;
  min-height: 380px;
}

#map {
  position: absolute;
  inset: 0;
  background: #0b0f14;
}

.hud {
  position: absolute;
  z-index: 400;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hud);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: hud-in 0.35s ease both;
}

@keyframes hud-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.hud-top-left {
  top: 12px;
  left: 12px;
  right: 12px;
  padding: 4px;
  display: flex;
  gap: 2px;
}

.seg-btn {
  flex: 1;
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 4px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.seg-btn[data-level="council"].seg-active { background: var(--council); color: #04140f; }
.seg-btn[data-level="assembly"].seg-active { background: var(--assembly); color: #241300; }
.seg-btn[data-level="senate"].seg-active { background: var(--senate); color: #0c0820; }
.seg-btn[data-level="congress"].seg-active { background: var(--congress); color: #260a12; }

.hud-top-right {
  top: 62px;
  right: 12px;
  padding: 8px 10px;
}

.switch-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  user-select: none;
}

.switch {
  position: relative;
  display: inline-block;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.switch-track {
  display: block;
  width: 34px;
  height: 19px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  transition: background 0.2s;
  position: relative;
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #e4e9ef;
  transition: transform 0.2s;
}

.switch input:checked + .switch-track {
  background: #3a9d80;
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(15px);
}

.hud-legend {
  bottom: 40px;
  left: 12px;
  right: 56px;
  padding: 10px 12px;
  font-size: 0.76rem;
  max-height: 34vh;
  overflow-y: auto;
}

.legend-title {
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 6px;
  font-size: 0.78rem;
}

.legend-note {
  color: var(--ink-faint);
  font-size: 0.68rem;
  margin: 0 0 6px;
}

.legend-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.legend-row:first-of-type {
  border-top: none;
}

.legend-swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  margin-right: 6px;
  flex-shrink: 0;
  vertical-align: middle;
}

.legend-district {
  color: var(--ink-soft);
  flex-shrink: 0;
}

.legend-winner {
  flex: 1;
  color: var(--ink);
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-margin {
  color: var(--ink-faint);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.legend-no-contest {
  font-weight: 400;
  font-style: italic;
  color: var(--ink-faint);
}

.map-hint {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  margin: 0;
  font-size: 0.68rem;
  color: var(--ink-faint);
  background: rgba(11, 15, 20, 0.7);
  padding: 3px 10px;
  border-radius: 999px;
  pointer-events: none;
}

/* Leaflet chrome adjustments for the dark theme */
.leaflet-control-attribution {
  background: rgba(11, 15, 20, 0.7) !important;
  color: var(--ink-faint) !important;
  font-size: 0.62rem !important;
}
.leaflet-control-attribution a { color: var(--ink-soft) !important; }
.leaflet-control-zoom a {
  background: var(--panel-bg) !important;
  color: var(--ink) !important;
  border-color: var(--panel-border) !important;
}

/* ---------- Card stack (bottom sheet) ---------- */

.card-stack-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 600;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.card-stack-backdrop.open {
  opacity: 1;
}

.card-stack {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 601;
  max-height: 72vh;
  background: var(--bg-elevated);
  border-top: 1px solid var(--panel-border);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.55);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
}

.card-stack.open {
  transform: translateY(0);
}

.card-stack-handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.card-stack-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.card-stack-close {
  background: rgba(255, 255, 255, 0.07);
  border: none;
  color: var(--ink-soft);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 0.85rem;
  cursor: pointer;
}

.card-stack-body {
  overflow-y: auto;
  padding: 12px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rep-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-left: 4px solid var(--neutral);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  animation: card-in 0.3s ease both;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.rep-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.rep-card-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.level-chip {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.rep-card-office {
  margin: 3px 0 2px;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.rep-card-party {
  margin: 0 0 6px;
  font-size: 0.76rem;
  color: var(--ink-faint);
}

.rep-card-primary-note {
  margin: 6px 0;
  font-size: 0.74rem;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  padding: 6px 8px;
}

.rep-card-cta {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
}

.rep-card-empty {
  color: var(--ink-faint);
  font-size: 0.82rem;
  font-style: italic;
  padding: 4px 2px;
}

/* ---------- List fallback ---------- */

.list-section {
  max-width: 640px;
  margin: 0 auto;
  padding: 22px 16px 40px;
}

.list-section h2 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.section-caption {
  margin: 0 0 16px;
  color: var(--ink-faint);
  font-size: 0.82rem;
}

.seat-group {
  margin-bottom: 16px;
}

.seat-group-heading {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-faint);
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.seat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 6px;
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
}

.seat-row:active {
  background: rgba(255, 255, 255, 0.09);
}

.seat-chip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.seat-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.seat-name {
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seat-office {
  font-size: 0.76rem;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Rep record view (full-screen sliding panel) ---------- */

.rep-view {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: var(--bg);
  transform: translateX(100%);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.rep-view.open {
  transform: translateX(0);
}

.rep-view-topbar {
  flex-shrink: 0;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #0f141b 0%, #0b0f14 100%);
  position: sticky;
  top: 0;
  z-index: 1;
}

.rep-view-back {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
}

.rep-view-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 4px 16px 40px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

.rep-view-header {
  border-left: 4px solid var(--neutral);
  background: var(--panel-bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 14px 0;
}

.rep-view-namerow {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.rep-view-name {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.rep-view-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0 0;
}

.rep-view-office {
  font-size: 0.86rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.rep-view-party-chip {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 2px 9px;
}

.rep-view-term {
  margin: 6px 0 0;
  font-size: 0.76rem;
  color: var(--ink-faint);
  font-style: italic;
}

.rep-view-blurb {
  margin: 8px 0 0;
  font-size: 0.86rem;
  color: var(--ink-soft);
  line-height: 1.45;
}

.rep-view-contact {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.rep-view-contact-link {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 5px 12px;
  text-decoration: none;
}

.rep-view-section {
  margin: 18px 0;
}

.rep-view-section-title {
  margin: 0 0 8px;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink);
}

.rep-view-empty {
  color: var(--ink-faint);
  font-size: 0.84rem;
  font-style: italic;
  margin: 0 0 4px;
}

.rep-view-empty-note {
  color: var(--ink-faint);
  font-size: 0.76rem;
  margin: 0;
}

.rep-view-empty-quiet {
  color: var(--ink-faint);
  font-size: 0.78rem;
  font-style: italic;
  margin: 0;
}

.vote-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.vote-filter-btn {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 5px 11px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.vote-filter-active {
  background: var(--ink);
  color: #0b0f14;
  border-color: var(--ink);
}

.vote-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.vote-row {
  display: flex;
  gap: 10px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.vote-date {
  flex-shrink: 0;
  width: 66px;
  font-size: 0.7rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  padding-top: 2px;
}

.vote-main {
  min-width: 0;
  flex: 1;
}

.vote-title {
  margin: 0 0 6px;
  font-size: 0.84rem;
  color: var(--ink);
  line-height: 1.35;
}

.vote-subrow {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.vote-pill {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 9px;
  border-radius: 999px;
}

.pos-yea {
  background: rgba(79, 195, 121, 0.18);
  color: #8be6a6;
}

.pos-nay {
  background: rgba(214, 96, 122, 0.2);
  color: #ff9fb3;
}

.pos-neutral {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink-soft);
}

.vote-result {
  font-size: 0.72rem;
  color: var(--ink-faint);
}

.vote-link, .sponsor-link {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
  margin-left: auto;
}

.show-more-btn {
  display: block;
  margin: 10px auto 0;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
}

.sponsor-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sponsor-row {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.sponsor-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 4px;
}

.sponsor-title {
  margin: 0;
  font-size: 0.84rem;
  color: var(--ink);
  line-height: 1.35;
}

.sponsor-status {
  flex-shrink: 0;
  font-size: 0.64rem;
  font-weight: 700;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

.rep-view-freshness {
  margin: 20px 0 4px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.freshness-line {
  margin: 0 0 2px;
  font-size: 0.76rem;
  color: var(--ink-soft);
}

.freshness-asof {
  margin: 0;
  font-size: 0.68rem;
  color: var(--ink-faint);
}

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

.site-footer {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px 32px;
  font-size: 0.72rem;
  color: var(--ink-faint);
  text-align: center;
}

/* ---------- Small-screen tuning ---------- */

@media (max-width: 380px) {
  .seg-btn {
    font-size: 0.66rem;
    padding: 8px 2px;
  }
  .hud-top-right {
    top: 58px;
  }
}
