/* ============================================================
   Design tokens
   ============================================================ */
:root {
  --color-navy: #1b2a4a;
  --color-navy-light: #2f4370;
  --color-brick: #a83232;
  --color-brick-light: #c25a5a;
  --color-cream: #faf6ee;
  --color-cream-dark: #f0e9d8;
  --color-gold: #b8922f;
  --color-ink: #22262f;
  --color-muted: #6b6f76;
  --color-line: #ddd4bf;

  /* Colorblind-safe sequential scale (navy -> gold), used for any magnitude encoding */
  --scale-1: #1b2a4a;
  --scale-2: #3f5478;
  --scale-3: #6b7f8f;
  --scale-4: #9a9270;
  --scale-5: #b8922f;

  --font-serif: "Source Serif 4", Georgia, serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.75rem;
  --space-4: 3rem;
  --space-5: 5rem;

  --radius: 6px;
  --transition-smooth: 500ms cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* ============================================================
   Base
   ============================================================ */
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

h1,
h2,
h3 {
  font-family: var(--font-serif);
  color: var(--color-navy);
  margin: 0 0 var(--space-2);
  font-weight: 600;
}

h1 {
  font-size: clamp(2rem, 4vw, 2.75rem);
  line-height: 1.15;
}

h2 {
  font-size: clamp(1.4rem, 2.5vw, 1.8rem);
}

h3 {
  font-size: 1.1rem;
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--color-ink);
}

p {
  margin: 0 0 var(--space-2);
}

a {
  color: var(--color-brick);
}

a:hover {
  color: var(--color-navy);
}

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--space-3);
}

/* ============================================================
   Star-motif divider — subtle, not kitsch
   ============================================================ */
.star-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  margin: var(--space-4) 0;
  color: var(--color-line);
}

.star-divider::before,
.star-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--color-line);
}

.star-divider svg {
  width: 12px;
  height: 12px;
  fill: var(--color-gold);
  flex-shrink: 0;
}

/* ============================================================
   Site nav / tabs
   ============================================================ */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 25;
  background: var(--color-cream);
  border-bottom: 1px solid var(--color-line);
}

.site-nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: var(--space-1);
  padding-bottom: var(--space-1);
}

.site-wordmark {
  font-family: var(--font-serif);
  font-weight: 600;
  color: var(--color-navy);
  font-size: 1.1rem;
}

.site-tabs {
  display: flex;
  gap: 0.25em;
}

.site-tab {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5em 1em;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
  transition: background var(--transition-smooth), color var(--transition-smooth);
}

.site-tab:hover {
  color: var(--color-navy);
}

.site-tab.active {
  background: var(--color-navy);
  color: #fff;
}

.tab-panel[hidden] {
  display: none !important;
}

/* ============================================================
   Hero / intro section
   ============================================================ */
.hero {
  padding: var(--space-5) 0 var(--space-4);
  text-align: left;
}

.hero .dek {
  font-family: var(--font-serif);
  font-size: 1.2rem;
  color: var(--color-navy-light);
  max-width: 60ch;
}

.intro-copy {
  max-width: 68ch;
  font-size: 1.05rem;
  color: var(--color-ink);
}

.intro-copy p {
  margin-bottom: var(--space-2);
}

.ground-rules {
  background: var(--color-cream-dark);
  border-left: 3px solid var(--color-gold);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-top: var(--space-3);
}

.ground-rules h3 {
  margin-top: 0;
}

.ground-rules ul {
  margin: 0;
  padding-left: 1.2em;
}

.ground-rules li {
  margin-bottom: 0.4em;
}

/* ============================================================
   Controls panel
   ============================================================ */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-end;
  background: #fff;
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}

.control-field {
  display: flex;
  flex-direction: column;
  gap: 0.35em;
  min-width: 200px;
}

.control-field label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  font-weight: 600;
}

.control-field select,
.control-field input[type="number"] {
  width: 100%;
  max-width: 100%;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  padding: 0.55em 0.7em;
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  background: var(--color-cream);
  color: var(--color-ink);
}

.control-field select:focus,
.control-field input[type="number"]:focus {
  outline: 2px solid var(--color-gold);
  outline-offset: 1px;
}

.control-field input[readonly] {
  background: var(--color-cream-dark);
  color: var(--color-muted);
  cursor: not-allowed;
}

.view-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  overflow: hidden;
}

.view-toggle button {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 0.6em 1.1em;
  border: none;
  background: #fff;
  color: var(--color-navy);
  cursor: pointer;
  transition: background var(--transition-smooth), color var(--transition-smooth);
}

.view-toggle button.active {
  background: var(--color-navy);
  color: #fff;
}

.scenario-note {
  width: 100%;
  font-size: 0.85rem;
  color: var(--color-brick);
  font-style: italic;
}

/* ============================================================
   Chamber sections
   ============================================================ */
.chamber-section {
  margin-bottom: var(--space-4);
}

.chamber-section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-2);
}

.chamber-section-header .total-badge {
  font-size: 0.85rem;
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}

.chamber-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.chamber-panel {
  background: #fff;
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
  padding: var(--space-2);
}

.chamber-panel h3 {
  text-align: center;
  color: var(--color-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-1);
}

.chamber-panel.current h3 {
  color: var(--color-navy);
}

.chamber-panel.reallocated h3 {
  color: var(--color-brick);
}

.chamber-panel svg {
  width: 100%;
  height: auto;
  display: block;
}

/* seat/hex fill colors driven by JS via inline style using these as reference */
.mark-current {
  fill: var(--color-navy);
}

.mark-reallocated {
  fill: var(--color-brick);
}

.mark-tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--color-ink);
  color: #fff;
  font-size: 0.78rem;
  padding: 0.4em 0.6em;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 150ms ease;
  z-index: 20;
  white-space: nowrap;
}

.mark-tooltip.visible {
  opacity: 1;
}

/* ============================================================
   Methodology footer
   ============================================================ */
.methodology-footer {
  position: sticky;
  bottom: 0;
  background: var(--color-navy);
  color: #d9e0ee;
  font-size: 0.8rem;
  padding: 0.7em var(--space-3);
  border-top: 2px solid var(--color-gold);
  z-index: 30;
}

.methodology-footer strong {
  color: #fff;
}

.methodology-footer a {
  color: var(--color-gold);
}

/* ============================================================
   Site footer
   ============================================================ */
.site-footer {
  padding: var(--space-4) 0 calc(var(--space-4) + 3rem);
  color: var(--color-muted);
  font-size: 0.85rem;
}

/* ============================================================
   Accountability table
   ============================================================ */
.table-scroll {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 70vh;
  background: #fff;
  border: 1px solid var(--color-line);
  border-radius: var(--radius);
}

.members-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.members-table th,
.members-table td {
  padding: 0.55em 0.9em;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--color-line);
}

.members-table thead th {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

/* Keep the Name column visible while scrolling horizontally on narrow
   screens, where the table can't show every column at once. */
.members-table th:first-child,
.members-table td:first-child {
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
}

.members-table thead th:first-child {
  z-index: 2;
}

.members-table tbody tr:hover td:first-child {
  background: var(--color-cream-dark);
}

.members-table thead th:hover {
  color: var(--color-navy);
}

.members-table thead th:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: -2px;
  color: var(--color-navy);
}

.members-table thead th.sorted::after {
  content: " \2193";
  color: var(--color-gold);
}

.members-table thead th.sorted.desc::after {
  content: " \2191";
}

.members-table tbody tr:hover {
  background: var(--color-cream-dark);
}

.members-table tbody tr:last-child td {
  border-bottom: none;
}

.flag-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-gold);
  margin-right: 0.5em;
  vertical-align: middle;
}

.members-table td.flagged {
  color: var(--color-brick);
  font-weight: 600;
}

/* range inputs, used for accountability thresholds */
.control-field input[type="range"] {
  width: 100%;
  accent-color: var(--color-navy);
}

/* ============================================================
   Accessibility utility
   ============================================================ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 860px) {
  .chamber-panels {
    grid-template-columns: 1fr;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .control-field {
    min-width: 0;
  }

  .site-nav-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4em;
    padding-top: var(--space-1);
    padding-bottom: var(--space-1);
  }

  .site-tabs {
    width: 100%;
  }

  .site-tab {
    flex: 1;
  }
}

@media (max-width: 480px) {
  /* Below ~480px the hex map / chamber diagram can't shrink to full width
     without making per-state labels illegible — let the chart keep a legible
     intrinsic size and scroll horizontally instead of squashing text. */
  .chamber-panel {
    overflow-x: auto;
  }

  .chamber-panel svg {
    width: auto;
    min-width: 620px;
  }
}
