:root {
  color-scheme: dark;
  --ink: #f4f7f5;
  --muted: #9fb1b3;
  --quiet: #82989b;
  --bg: #06141d;
  --bg-deep: #031018;
  --surface: #0b202b;
  --surface-raised: #102a36;
  --line: #26404a;
  --line-soft: rgba(159, 177, 179, .16);
  --mint: #5fd0a5;
  --mint-dark: #163f38;
  --cyan: #66b8c4;
  --amber: #e9c86c;
  --danger: #f18a91;
  --radius: 12px;
  --content: 1380px;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg-deep);
  color: var(--ink);
  font-family: Aptos, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.5;
}
a { color: inherit; }
button, input, select { font: inherit; }
button, select, input { color: var(--ink); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid rgba(95, 208, 165, .48);
  outline-offset: 2px;
}
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 100; padding: 10px 14px; background: white; color: #06141d; transform: translateY(-150%); }
.skip-link:focus { transform: none; }

.site-header {
  min-height: 76px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  width: min(var(--content), calc(100% - 48px));
  margin: auto;
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; width: max-content; }
.brand-mark { width: 31px; height: 31px; border: 7px solid var(--mint); border-top-color: var(--cyan); border-radius: 50%; position: relative; }
.brand-mark::after { content: ""; position: absolute; width: 7px; height: 7px; background: var(--ink); border-radius: 50%; inset: 5px; }
.brand strong, .brand small { display: block; line-height: 1.05; }
.brand strong { font-size: .98rem; letter-spacing: -.02em; }
.brand small { color: var(--muted); text-transform: uppercase; font-size: .62rem; letter-spacing: .22em; margin-top: 4px; }
.site-header nav { display: flex; gap: 28px; }
.site-header nav a { color: var(--muted); text-decoration: none; font-size: .82rem; font-weight: 650; }
.site-header nav a:hover { color: var(--ink); }
.source-pill { justify-self: end; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .74rem; }
.source-pill span { width: 7px; height: 7px; background: var(--mint); border-radius: 50%; box-shadow: 0 0 0 4px rgba(95, 208, 165, .1); }
.header-tools { justify-self: end; display: flex; align-items: center; gap: 12px; }

main { width: min(var(--content), calc(100% - 48px)); margin: 0 auto; }
.intro { display: grid; grid-template-columns: 1.45fr .55fr; gap: 64px; align-items: end; padding: 64px 0 34px; }
.kicker, .section-label { margin: 0 0 8px; color: var(--mint); text-transform: uppercase; letter-spacing: .15em; font-size: .68rem; font-weight: 800; }
.intro h1 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; font-size: clamp(3rem, 7vw, 6.6rem); line-height: .86; letter-spacing: -.06em; margin: 0; max-width: 880px; }
.lede { color: var(--muted); max-width: 760px; font-size: 1.04rem; margin: 22px 0 0; }
.boundary-note { border-top: 1px solid var(--line); padding-top: 16px; }
.boundary-note strong, .boundary-note span { display: block; }
.boundary-note strong { font-size: .86rem; }
.boundary-note span { color: var(--muted); font-size: .77rem; margin-top: 6px; }

.control-deck { border: 1px solid var(--line); background: var(--surface); padding: 20px; border-radius: var(--radius); }
.control-heading, .section-topline, .surface-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.control-heading h2, .section-topline h2, .surface-heading h2 { margin: 0; line-height: 1.1; letter-spacing: -.025em; }
.control-heading h2 { font-size: 1.3rem; }
.control-actions, .form-actions, .commercial-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; border-radius: 8px; border: 1px solid var(--line); padding: 9px 14px; cursor: pointer; text-decoration: none; font-weight: 750; font-size: .78rem; }
.button.primary { background: var(--mint); color: #06201b; border-color: var(--mint); }
.button.primary:hover { background: #79dbb7; }
.button.ghost { background: transparent; color: var(--ink); }
.button.ghost:hover { border-color: var(--muted); }
.button:disabled { opacity: .5; cursor: wait; }
.filter-grid { display: grid; grid-template-columns: .65fr .7fr 1.8fr 1fr .85fr .8fr 1.35fr; gap: 10px; margin-top: 18px; }
.wide-field { min-width: 0; }
.monitor-head { display: flex; justify-content: space-between; align-items: end; gap: 48px; padding: 34px 0 22px; }
.monitor-head h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 4vw, 3.6rem); font-weight: 500; letter-spacing: -.045em; line-height: 1; }
.monitor-head > p { max-width: 620px; margin: 0; color: var(--muted); font-size: .84rem; }
.comparison-controls { display: grid; grid-template-columns: .62fr 1.45fr auto; gap: 20px; align-items: end; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line-soft); }
.comparison-controls h3 { margin: 0; font-size: 1rem; }
.comparison-filter-grid { display: grid; grid-template-columns: .7fr .8fr 1.2fr; gap: 10px; }
.axis-switch { display: flex; min-height: 44px; align-items: center; gap: 4px; margin: 0; padding: 3px; border: 1px solid var(--line); border-radius: 8px; }
.axis-switch legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.axis-switch label { display: flex; align-items: center; gap: 6px; min-height: 36px; padding: 7px 10px; color: var(--muted); border-radius: 6px; white-space: nowrap; cursor: pointer; }
.axis-switch label:has(input:checked) { background: var(--mint-dark); color: var(--ink); }
.axis-switch input { width: 14px; min-height: auto; accent-color: var(--mint); }
label { display: grid; gap: 6px; color: var(--muted); font-size: .68rem; font-weight: 750; letter-spacing: .02em; }
select, input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #071923;
  padding: 9px 11px;
  font-size: .78rem;
}
select:hover, input:hover { border-color: #42606b; }
.microcopy, .section-subtitle { color: var(--muted); font-size: .74rem; }
.microcopy { margin: 11px 0 0; }
.status-message { margin: 14px 0 34px; min-height: 24px; color: var(--muted); font-size: .76rem; }
.status-message.error { color: var(--danger); }
.status-message.success { color: var(--mint); }

.section-topline { padding-bottom: 16px; border-bottom: 1px solid var(--line-soft); }
.section-topline h2 { font-size: clamp(1.55rem, 3vw, 2.45rem); }
.section-subtitle { margin: 6px 0 0; }
.updated-at { color: var(--muted); text-align: right; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .7rem; padding-top: 24px; }
.metric-strip { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 18px 0; background: var(--surface); }
.metric { padding: 16px 18px; border-right: 1px solid var(--line); min-width: 0; }
.metric:last-child { border-right: 0; }
.metric-label { color: var(--quiet); text-transform: uppercase; letter-spacing: .1em; font-size: .61rem; font-weight: 800; }
.metric-value { margin-top: 5px; font-size: clamp(1.2rem, 2.4vw, 2rem); font-weight: 780; letter-spacing: -.035em; overflow-wrap: anywhere; }
.metric-detail { color: var(--muted); font-size: .7rem; margin-top: 2px; }
.results-grid { display: grid; grid-template-columns: minmax(330px, .72fr) minmax(0, 1.55fr); gap: 18px; }
.analysis-grid { display: grid; grid-template-columns: minmax(0, 2.15fr) minmax(290px, .85fr); gap: 14px; align-items: stretch; }
.chart-surface { min-width: 0; }
.analysis-panel { padding: 20px; }
.text-button { min-height: 44px; padding: 0 8px; border: 0; background: transparent; color: var(--mint); font: inherit; font-size: .78rem; font-weight: 800; cursor: pointer; }
.candidate-filter { display: grid; max-height: 285px; overflow: auto; gap: 3px; margin: 14px 0 18px; padding-right: 5px; }
.filter-group-title { margin: 9px 0 3px; color: var(--ink); font-size: .65rem; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.candidate-toggle { grid-template-columns: auto auto 1fr; align-items: center; gap: 8px; min-height: 30px; color: var(--ink-soft); font-size: .73rem; font-weight: 650; cursor: pointer; }
.candidate-toggle input { width: 14px; min-height: auto; accent-color: var(--mint-dark); }
.candidate-toggle i { width: 16px; height: 3px; background: var(--series-color); border-radius: 99px; }
.candidate-toggle i.dashed { background: repeating-linear-gradient(90deg, var(--series-color) 0 4px, transparent 4px 7px); }
.analytics-metrics { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line-soft); border-left: 1px solid var(--line-soft); }
.analysis-stat { display: grid; gap: 3px; min-height: 65px; padding: 11px; border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
.analysis-stat span { color: var(--muted); font-size: .62rem; line-height: 1.2; }
.analysis-stat strong { font-family: Georgia, "Times New Roman", serif; font-size: 1.05rem; font-weight: 500; }
.detail-grid { display: grid; grid-template-columns: .8fr 1.2fr; gap: 14px; margin-top: 14px; }
.ranking-surface, .compare-surface { min-width: 0; }
.surface { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 20px; }
.surface-heading { padding-bottom: 14px; border-bottom: 1px solid var(--line-soft); }
.surface-heading h2, .surface-heading h3 { margin: 0; font-size: 1.08rem; }
.badge { color: var(--mint); border: 1px solid rgba(95, 208, 165, .35); border-radius: 999px; padding: 4px 8px; font-size: .58rem; font-weight: 900; letter-spacing: .12em; }
.badge.amber { color: var(--amber); border-color: rgba(233, 200, 108, .35); }
.badge.neutral { color: var(--muted); border-color: var(--line); }
.model-state { color: var(--amber) !important; font-size: 1rem !important; font-weight: 800; }
.model-warning { color: var(--amber) !important; }
.probability-list { display: grid; gap: 8px; margin: 14px 0; }
.probability-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.probability-row small { grid-column: 1 / -1; color: var(--quiet); }

.rank-row { padding: 15px 0; border-bottom: 1px solid var(--line-soft); }
.rank-row.legally-ineligible { padding-left: 10px; border-left: 3px solid var(--amber); }
.rank-row.legally-ineligible .votes { color: var(--amber); font-weight: 750; }
.legal-note { margin: 4px 0 10px; padding: 10px 12px; border: 1px solid rgba(233, 200, 108, .32); border-radius: 8px; color: var(--ink-soft); background: rgba(233, 200, 108, .07); font-size: .78rem; line-height: 1.5; }
.rank-row:last-child { border-bottom: 0; }
.rank-line { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.rank-number { color: var(--quiet); font-family: Georgia, serif; font-size: 1.05rem; }
.candidate-name { font-weight: 780; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.party { color: var(--muted); font-size: .66rem; margin-top: 1px; }
.rank-pct { font-size: 1.15rem; font-weight: 820; letter-spacing: -.025em; }
.bar { height: 4px; margin: 9px 0 5px 38px; background: #05151e; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--mint); }
.votes { margin-left: 38px; color: var(--quiet); font-size: .65rem; }
.ranking-toggle { width: 100%; margin-top: 16px; }
.chart-heading p { color: var(--muted); font-size: .7rem; margin: 3px 0 0; }
.legend { display: flex; justify-content: flex-end; gap: 8px 12px; flex-wrap: wrap; max-width: 58%; }
.legend-item { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .64rem; }
.legend-line { width: 18px; height: 2px; background: var(--series-color); }
.legend-line.dashed { background: repeating-linear-gradient(90deg, var(--series-color), var(--series-color) 4px, transparent 4px, transparent 7px); }
.chart-wrap { width: 100%; min-height: 345px; overflow: hidden; margin-top: 10px; }
#trendChart { width: 100%; height: auto; min-height: 320px; }
.grid-line { stroke: var(--line-soft); stroke-width: 1; }
.tick-label { fill: var(--quiet); font-size: 14px; }
.candidate-line { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.candidate-dot { stroke: var(--surface); stroke-width: 3; }
.chart-empty { fill: var(--muted); font-size: 18px; }

.compare-surface { margin-top: 0; }
.comparison-content { margin-top: 16px; }
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.compare-card { background: #071923; border: 1px solid var(--line-soft); border-radius: 9px; padding: 16px; }
.compare-card h3 { margin: 0 0 10px; font-size: .85rem; }
.compare-row { display: flex; justify-content: space-between; gap: 16px; padding: 7px 0; color: var(--muted); font-size: .75rem; border-bottom: 1px solid rgba(159,177,179,.08); }
.compare-row strong { color: var(--ink); }
.compare-caption { color: var(--quiet); margin: 12px 0 0; font-size: .68rem; }
.empty-state { color: var(--muted); margin: 8px 0; font-size: .8rem; }

.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.model-content p, .prediction-surface > p { color: var(--muted); font-size: .79rem; }
.model-content strong { color: var(--ink); }
.model-content a { color: var(--mint); font-size: .76rem; font-weight: 750; }
.privacy-dot { color: var(--mint); font-size: .64rem; }
.privacy-dot::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--mint); margin-right: 6px; }
.input-suffix { position: relative; }
.input-suffix span { position: absolute; right: 12px; top: 11px; color: var(--muted); font-size: .8rem; }
.input-suffix input { padding-right: 30px; }

.method-band { display: grid; grid-template-columns: .7fr 1.3fr; gap: 44px; padding: 64px 0; }
.method-band h2 { font-family: Georgia, serif; font-weight: 500; font-size: clamp(2rem, 4vw, 3.6rem); line-height: 1; letter-spacing: -.04em; margin: 0; }
.method-points { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.method-points article { border-top: 1px solid var(--line); padding-top: 14px; }
.method-points span { color: var(--mint); font-family: ui-monospace, monospace; font-size: .64rem; }
.method-points h3 { font-size: .88rem; margin: 16px 0 5px; }
.method-points p { color: var(--muted); font-size: .74rem; margin: 0; }

.commercial-band { display: flex; justify-content: space-between; align-items: center; gap: 32px; background: var(--mint); color: #07221c; padding: 30px; border-radius: var(--radius); }
.commercial-band .section-label { color: #174d40; }
.commercial-band h2 { margin: 0; font-family: Georgia, serif; font-weight: 500; letter-spacing: -.035em; font-size: clamp(1.65rem, 3vw, 2.8rem); }
.commercial-band p { margin: 8px 0 0; color: #204f44; max-width: 720px; font-size: .82rem; }
.button.light { background: #07221c; color: var(--ink); border-color: #07221c; }
.button.outline-light { color: #07221c; border-color: rgba(7,34,28,.5); }

.site-footer { width: min(var(--content), calc(100% - 48px)); margin: 40px auto 0; padding: 28px 0 42px; border-top: 1px solid var(--line-soft); display: grid; grid-template-columns: 1fr auto 1fr; gap: 24px; align-items: center; color: var(--muted); font-size: .7rem; }
.site-footer strong, .site-footer span { display: block; }
.site-footer strong { color: var(--ink); }
.footer-links { display: flex; gap: 18px; }
.site-footer a { text-decoration: none; }
.site-footer > a { justify-self: end; color: var(--mint); }
[hidden] { display: none !important; }

.mode-switch { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.mode-switch button { border: 0; border-radius: 6px; background: transparent; color: var(--muted); padding: 7px 9px; cursor: pointer; font-size: .68rem; font-weight: 800; }
.mode-switch button.active { background: var(--mint); color: #06201b; }
.live-insights { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.remaining-content { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; padding-top: 16px; }
.remaining-number { font-family: Georgia, "Times New Roman", serif; font-size: 2.6rem; color: var(--mint); line-height: 1; }
.remaining-copy strong, .remaining-copy span { display: block; }
.remaining-copy span { color: var(--muted); font-size: .76rem; margin-top: 4px; }
.alert-feed { padding-top: 14px; }
.alert-item { padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.alert-item:last-child { border-bottom: 0; }
.alert-item strong, .alert-item span { display: block; }
.alert-item span { color: var(--muted); font-size: .75rem; margin-top: 3px; }
.studio-surface { margin: 14px 0; }
.studio-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 16px 0 4px; }
.studio-controls label { color: var(--muted); font-size: .7rem; font-weight: 700; }
.studio-controls select { width: 100%; margin-top: 6px; }
#customChart { width: 100%; min-width: 700px; }
body[data-mode="citizen"] .analyst-only { display: none; }

@media (max-width: 1180px) {
  .filter-grid { grid-template-columns: repeat(4, 1fr); }
  .wide-field { grid-column: span 2; }
  .comparison-controls { grid-template-columns: 1fr 2fr; }
  .axis-switch { grid-column: 2; justify-self: start; }
  .intro { grid-template-columns: 1fr .45fr; gap: 30px; }
}
@media (max-width: 900px) {
  .site-header { grid-template-columns: 1fr auto; padding: 10px 0; }
  .site-header nav { display: flex; grid-column: 1 / -1; gap: 20px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: thin; }
  .header-tools { grid-column: 2; grid-row: 1; }
  .monitor-head { align-items: start; flex-direction: column; gap: 16px; }
  .comparison-controls { grid-template-columns: 1fr; }
  .comparison-filter-grid { grid-template-columns: repeat(3, 1fr); }
  .axis-switch { grid-column: auto; }
  .intro, .method-band { grid-template-columns: 1fr; }
  .boundary-note { max-width: 560px; }
  .results-grid, .two-column, .analysis-grid, .detail-grid, .live-insights { grid-template-columns: 1fr; }
  .metric-strip { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .method-points { grid-template-columns: repeat(3, 1fr); }
  .site-footer { grid-template-columns: 1fr; }
  .site-footer > a { justify-self: start; }
}
@media (max-width: 680px) {
  .site-header, main, .site-footer { width: min(100% - 24px, var(--content)); }
  .site-header { min-height: 68px; }
  .source-pill { font-size: 0; }
  .source-pill::after { content: "TSE"; font-size: .68rem; }
  .header-tools { gap: 7px; }
  .intro { padding-top: 42px; }
  .intro h1 { font-size: clamp(3rem, 16vw, 5.2rem); }
  .control-heading, .section-topline, .surface-heading, .commercial-band { flex-direction: column; }
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .wide-field { grid-column: 1 / -1; }
  .comparison-filter-grid { grid-template-columns: 1fr; }
  .axis-switch { width: 100%; flex-wrap: wrap; }
  .candidate-toggle { min-height: 44px; font-size: .82rem; }
  .microcopy, .section-subtitle, .legend-item, .votes, .compare-row, .compare-caption { font-size: .78rem; }
  .updated-at { text-align: left; padding-top: 0; }
  .results-grid { grid-template-columns: minmax(0, 1fr); }
  .chart-wrap { overflow: hidden; min-height: 240px; }
  #trendChart { min-width: 0; width: 100%; min-height: 220px; }
  #trendChart .tick-label { font-size: 40px; }
  #trendChart .chart-empty { font-size: 34px; }
  .legend { justify-content: flex-start; max-width: none; }
  .compare-grid, .method-points { grid-template-columns: 1fr; }
  .commercial-actions { width: 100%; }
  .commercial-actions .button { flex: 1; }
  .footer-links { flex-wrap: wrap; }
  .header-tools { justify-self: end; }
  .studio-controls { grid-template-columns: 1fr; }
  #customChart { min-width: 620px; }
}
@media (max-width: 430px) {
  .filter-grid, .metric-strip { grid-template-columns: 1fr; }
  .metric { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric:last-child { border-bottom: 0; }
  .control-actions, .control-actions .button { width: 100%; }
  .bar, .votes { margin-left: 0; }
  .rank-line { grid-template-columns: 24px minmax(0, 1fr) auto; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
