:root {
  color-scheme: light;
  --page: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --border: #dce2e6;
  --text: #17252c;
  --muted: #65747b;
  --quiet: #89969c;
  --accent: #176b58;
  --accent-soft: #e7f2ee;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--page); }
button, input, select { font: inherit; }
button { color: inherit; }

.topbar { height: 58px; padding: 0 max(24px, calc((100vw - 1440px) / 2)); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: var(--surface); }
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font-size: 11px; font-weight: 700; letter-spacing: .07em; }
.brand-mark { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 5px; background: var(--accent); color: white; font-size: 13px; }
.brand-divider { color: var(--accent); padding: 0 3px; }
.top-meta, .eyebrow, .intro-stats, .step, .micro-note, .range-ends, .footer-top, .graph-footer, .party-actions, .weight-labels { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.top-meta { color: var(--muted); font-size: 9px; letter-spacing: .045em; }
.status-dot { display: inline-block; width: 6px; height: 6px; margin: 0 7px 1px 0; border-radius: 50%; background: #24836b; }

main { width: min(1440px, calc(100% - 48px)); margin: 0 auto; }
.intro { padding: 43px 0 26px; border-bottom: 1px solid var(--border); }
.eyebrow { color: var(--accent); font-size: 9px; letter-spacing: .08em; }
.eyebrow span { color: var(--quiet); }
h1 { margin: 16px 0 10px; font-size: clamp(34px, 4vw, 54px); font-weight: 650; line-height: 1.02; letter-spacing: -.055em; }
h1 em { color: var(--accent); font-style: normal; }
.intro-copy { max-width: 660px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.intro-stats { margin-top: 15px; color: var(--muted); font-size: 9px; letter-spacing: .025em; }

.workspace { display: grid; grid-template-columns: 305px minmax(0, 1fr); gap: 16px; padding: 18px 0 30px; }
.controls, .graph-panel { border: 1px solid var(--border); border-radius: 7px; background: var(--surface); }
.controls { position: sticky; top: 12px; align-self: start; max-height: calc(100vh - 24px); overflow-y: auto; padding: 17px 16px; scrollbar-color: #c4ceca transparent; scrollbar-width: thin; }
.panel-heading, .method-title { display: flex; align-items: center; gap: 9px; }
.step { display: inline-grid; flex: 0 0 21px; width: 21px; height: 21px; place-items: center; border: 1px solid #bfd4cc; border-radius: 50%; color: var(--accent); font-size: 9px; }
h2 { margin: 0; font-size: 13px; font-weight: 650; letter-spacing: -.015em; }
.control-block { margin-top: 19px; }
.party-mode-control { padding: 11px 10px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface-soft); }
.mode-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mode-switch-row + .mode-switch-row { margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--border); }
.mode-switch-row > div > label { font-size: 10px; font-weight: 650; }
.mode-switch-row .micro-note { max-width: 215px; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 7px; margin-bottom: 8px; font-size: 11px; font-weight: 650; }
.muted { color: var(--muted); font: 9px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.search { width: 100%; height: 33px; border: 1px solid var(--border); outline: none; border-radius: 4px; background: var(--surface); color: var(--text); padding: 0 9px; font-size: 11px; }
.search:focus, .sort-row select:focus, .year-selects select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px #176b5817; }
.search::placeholder { color: #98a3a8; }
.sort-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; color: var(--muted); font: 9px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.sort-row select { max-width: 190px; height: 26px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text); padding: 0 6px; font-size: 9px; }
.party-actions { display: flex; align-items: center; justify-content: space-between; gap: 5px; margin: 9px 0; font-size: 8px; }
.text-button { padding: 0; border: 0; background: transparent; color: var(--accent); cursor: pointer; font-size: inherit; text-align: left; }
.text-button:hover { text-decoration: underline; text-underline-offset: 2px; }
.party-list, .category-list { overflow: auto; padding-right: 3px; scrollbar-color: #c4ceca transparent; scrollbar-width: thin; }
.party-list { max-height: 205px; }
.party-option { display: flex; align-items: center; gap: 8px; min-height: 27px; padding: 3px 4px; color: #34464d; font-size: 10px; cursor: pointer; }
.party-option:hover, .category-option:hover { background: #f1f6f4; }
.party-option input, .category-option input { appearance: none; flex: 0 0 13px; width: 13px; height: 13px; margin: 0; border: 1px solid #aab7b7; border-radius: 3px; background: white; cursor: pointer; }
.party-option input:checked, .category-option input:checked { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px white; }
.party-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.micro-note { margin: 7px 0 0; color: var(--quiet); font-size: 8px; line-height: 1.55; }

.timeframe, .topic-filter, .weighting { padding-top: 16px; border-top: 1px solid var(--border); }
.year-selects { display: flex; align-items: end; gap: 8px; }
.year-selects label { display: grid; flex: 1; gap: 5px; color: var(--muted); font: 8px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.year-selects select { width: 100%; height: 31px; border: 1px solid var(--border); border-radius: 4px; outline: none; background: var(--surface); color: var(--text); padding: 0 7px; font: 10px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.year-dash { padding-bottom: 9px; color: var(--quiet); font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.topic-filter details > summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; list-style: none; cursor: pointer; font-size: 11px; font-weight: 650; }
.topic-filter details > summary::-webkit-details-marker { display: none; }
.topic-filter details > summary::before { content: "＋"; color: var(--accent); font: 11px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.topic-filter details[open] > summary::before { content: "−"; }
.topic-filter details > summary span:first-child { margin-right: auto; }
.topic-hint { margin-top: 8px; }
.topic-actions { margin-top: 8px; }
.category-list { max-height: 195px; }
.category-option { display: flex; align-items: center; gap: 7px; min-height: 27px; padding: 3px 4px; color: #34464d; cursor: pointer; }
.category-name { flex: 1; font-size: 9px; line-height: 1.3; }
.category-count { color: var(--quiet); font: 8px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.election-actions { margin: 2px 0 8px; }
.election-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 3px; border-radius: 5px; background: #eef2f1; }
.election-tabs button, .view-switch button { min-height: 28px; padding: 4px 5px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 8px; cursor: pointer; }
.election-tabs button.active, .view-switch button.active { background: #fff; color: var(--accent); box-shadow: 0 1px 3px #142d2415; font-weight: 650; }
.election-list { max-height: 260px; margin-top: 7px; overflow: auto; scrollbar-color: #c4ceca transparent; scrollbar-width: thin; }
.election-option, .election-group-select { display: flex; align-items: center; gap: 7px; min-height: 27px; padding: 3px 5px; color: #34464d; font-size: 9px; cursor: pointer; }
.election-option:hover, .election-group-header:hover { background: #f1f6f4; }
.election-option input, .election-group-select input { appearance: none; flex: 0 0 13px; width: 13px; height: 13px; margin: 0; border: 1px solid #aab7b7; border-radius: 3px; background: white; cursor: pointer; }
.election-option input:checked, .election-group-select input:checked { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px white; }
.election-date { margin-left: auto; color: var(--quiet); font: 8px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.election-group { margin: 2px 0; }
.election-group-header { display: flex; align-items: center; min-height: 30px; border-radius: 4px; }
.election-group-select { flex: 1; font-weight: 600; }
.election-group-count { margin-left: auto; color: var(--muted); font: 8px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.election-expand { width: 27px; height: 25px; margin-right: 3px; border: 0; border-radius: 4px; background: transparent; color: var(--quiet); cursor: pointer; }
.election-expand:hover { background: var(--accent-soft); color: var(--accent); }
.election-group-children { margin-left: 13px; padding-left: 7px; border-left: 1px solid var(--border); }
.election-group-children[hidden] { display: none; }

.analysis-block { margin: 18px; padding: 18px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); }
.analysis-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 15px; }
.analysis-heading p { margin: 6px 0 0 30px; color: var(--muted); font-size: 9px; }
.analysis-actions { display: flex; align-items: center; gap: 9px; }
.export-button { flex: 0 0 auto; min-height: 29px; padding: 4px 9px; border: 1px solid var(--border); border-radius: 4px; background: white; color: var(--accent); font-size: 9px; font-weight: 650; cursor: pointer; }
.export-button:hover, .export-button:focus-visible { border-color: #91b5a8; background: var(--accent-soft); }
.export-button:disabled { cursor: wait; opacity: .6; }
.local-party-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 9px; font-weight: 600; }
.local-party-control select { min-width: 170px; max-width: 250px; height: 31px; padding: 0 8px; border: 1px solid var(--border); border-radius: 4px; background: white; color: var(--text); font-size: 10px; }
.chart-scroll { width: 100%; overflow-x: auto; overflow-y: hidden; }
.chart-scroll svg { display: block; height: 330px; }
.analysis-empty { padding: 38px 12px; color: var(--muted); font-size: 11px; text-align: center; }
.analysis-empty[hidden] { display: none; }
.embedding-quality { min-height: 14px; margin: -5px 0 8px 30px; color: var(--muted); font-size: 8px; }
.embedding-plot-scroll { width: 100%; min-height: 340px; overflow-x: auto; overflow-y: hidden; border-radius: 4px; background: #fff; }
.embedding-plot-scroll svg { display: block; min-width: 100%; }
.embedding-point-label { fill: #26383d; font: 600 10px system-ui, sans-serif; }
.embedding-tooltip { fill: #5d6d72; font: 8px system-ui, sans-serif; }
.embedding-point { stroke: #fff; stroke-width: 2; }
.embedding-grid { stroke: #e7ecea; stroke-width: 1; }
.embedding-axis { stroke: #9caeaa; stroke-width: 1.2; }
.embedding-axis-label { fill: #697a7f; font: 8px system-ui, sans-serif; }
.view-switch { display: inline-flex; gap: 3px; padding: 3px; border: 1px solid var(--border); border-radius: 6px; background: #f6f8f8; }
.view-switch button { min-width: 86px; font-size: 9px; }
.simple-party-controls { display: flex; align-items: center; gap: 15px; margin-bottom: 10px; }
.pair-mark { color: var(--quiet); font-size: 16px; }
.table-scroll { width: 100%; max-height: 680px; overflow: auto; border: 1px solid var(--border); border-radius: 5px; }
.table-scroll:empty { display: none; }
#category-table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; font-size: 9px; }
#category-table th, #category-table td { min-width: 100px; padding: 8px 9px; border-right: 1px solid #e5e9eb; border-bottom: 1px solid #e5e9eb; text-align: center; white-space: nowrap; }
#category-table thead th { position: sticky; top: 0; z-index: 2; background: #f6f8f8; color: #3b4b51; font-weight: 650; }
#category-table th:first-child, #category-table td:first-child { position: sticky; left: 0; z-index: 1; min-width: 150px; background: white; text-align: left; }
#category-table thead th:first-child { z-index: 3; background: #f6f8f8; }
#category-table tbody tr:hover td:first-child { background: #f1f6f4; }
#category-table td { font-variant-numeric: tabular-nums; }
#category-table td.no-data { color: #a2adaf; background: #fbfcfc; }
#category-table td.self-cell { color: var(--accent); background: #e7f2ee; font-weight: 700; }

.weight-labels { display: flex; justify-content: space-between; align-items: center; margin: 11px 0 6px; color: var(--muted); font-size: 8px; }
.weight-labels strong { color: var(--accent); font-weight: 500; font-size: 9px; }
input[type=range] { width: 100%; height: 3px; margin: 7px 0; appearance: none; background: #d4e4de; outline: none; }
input[type=range]::-webkit-slider-thumb { width: 13px; height: 13px; appearance: none; border: 2px solid var(--accent); border-radius: 50%; background: white; cursor: grab; }
input[type=range]::-moz-range-thumb { width: 10px; height: 10px; border: 2px solid var(--accent); border-radius: 50%; background: white; cursor: grab; }
.range-ends { display: flex; justify-content: space-between; margin-top: 5px; color: var(--quiet); font-size: 7px; }
.neutral-control { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.neutral-control label:not(.switch) { font-size: 10px; font-weight: 600; }
.switch { position: relative; flex: 0 0 30px; height: 17px; }
.switch input { width: 0; height: 0; opacity: 0; }
.slider { position: absolute; inset: 0; border: 1px solid #b8c2c3; border-radius: 14px; cursor: pointer; transition: .15s; }
.slider::before { position: absolute; content: ""; width: 9px; height: 9px; left: 3px; top: 3px; border-radius: 50%; background: #9aa7a9; transition: .15s; }
.switch input:checked + .slider { border-color: var(--accent); background: var(--accent-soft); }
.switch input:checked + .slider::before { transform: translateX(13px); background: var(--accent); }
.update-button { display: flex; justify-content: space-between; align-items: center; width: 100%; height: 36px; margin-top: 14px; padding: 0 11px; border: 0; border-radius: 4px; background: var(--accent); color: white; font-size: 10px; font-weight: 650; cursor: pointer; }
.update-button:hover { background: #125543; }
.update-button span { font-size: 15px; }
.share-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 7px; }
.share-button { min-height: 29px; padding: 4px 9px; border: 1px solid var(--border); border-radius: 4px; background: #fff; color: var(--accent); font-size: 9px; font-weight: 650; cursor: pointer; }
.share-button:hover { border-color: #91b5a8; background: var(--accent-soft); }
.share-button span { margin-left: 5px; font-size: 12px; }
#share-status { color: var(--muted); font-size: 8px; }

.graph-panel { min-width: 0; height: auto; min-height: 0; align-self: stretch; display: flex; flex-direction: column; overflow: visible; }
.graph-header { display: flex; justify-content: space-between; gap: 12px; padding: 17px 18px 12px; }
.graph-header p { margin: 6px 0 0 30px; color: var(--muted); font-size: 9px; }
.graph-tools { display: flex; align-items: start; gap: 4px; }
.graph-tools button { min-width: 27px; height: 25px; padding: 0 6px; border: 1px solid var(--border); border-radius: 4px; background: white; color: var(--muted); font: 9px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; cursor: pointer; }
.graph-tools #export-svg { min-width: 54px; color: var(--accent); }
.graph-tools #export-graph-png { min-width: 48px; color: var(--accent); }
.graph-tools button:hover { border-color: #91b5a8; color: var(--accent); }
.canvas-wrap { position: relative; flex: none; height: clamp(520px, 64vh, 760px); min-height: 0; overflow: hidden; border-top: 1px solid var(--border); background-color: #ffffff; background-image: radial-gradient(#f0f3f2 .65px, transparent .65px); background-size: 20px 20px; }
#graph-canvas { display: block; width: 100%; height: 100%; min-height: 0; touch-action: none; cursor: grab; }
#graph-canvas:active { cursor: grabbing; }
.graph-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; color: var(--muted); pointer-events: none; }
.graph-empty[hidden] { display: none; }
.empty-symbol { color: #5d9e87; font-size: 29px; }
.graph-empty strong { color: var(--text); font-size: 12px; font-weight: 600; }
.graph-empty span:last-child { font-size: 9px; }
.graph-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 17px; border-top: 1px solid var(--border); color: var(--muted); font-size: 8px; }
.legend { display: flex; align-items: center; gap: 7px; }
.legend-line { display: inline-block; width: 20px; height: 2px; background: #176b58; }
.legend-negative { height: 0; border-top: 2px dashed #b34339; background: transparent; }
.graph-navigation { color: var(--quiet); }
.tooltip { position: absolute; z-index: 2; max-width: 240px; padding: 9px 11px; border: 1px solid #cfd9d8; border-radius: 5px; background: #ffffff; color: var(--text); font-size: 9px; line-height: 1.5; pointer-events: none; box-shadow: 0 3px 12px #142d2414; }
.tooltip strong { color: var(--accent); font-size: 10px; font-weight: 650; }

.method { display: grid; grid-template-columns: 205px 1fr; gap: 20px; padding: 17px 0 30px; border-top: 1px solid var(--border); }
.method-title { align-items: start; }
.method-title h2 { margin-top: 3px; }
.method > p { max-width: 940px; margin: 0; color: var(--muted); font-size: 9px; line-height: 1.7; }
footer { padding: 19px max(24px, calc((100vw - 1440px) / 2)) 25px; border-top: 1px solid var(--border); background: var(--surface); }
.footer-top { display: flex; justify-content: space-between; color: var(--accent); font-size: 8px; letter-spacing: .08em; }
footer p { max-width: 740px; margin: 12px 0 7px; color: var(--muted); font-size: 9px; line-height: 1.65; }
footer a { color: var(--accent); font-size: 9px; text-underline-offset: 2px; }
footer a:hover { color: #104d40; }

@media (max-width: 980px) {
  main { width: min(100% - 32px, 760px); }
  .workspace { grid-template-columns: 1fr; }
  .controls { position: static; order: 1; max-height: none; overflow: visible; }
  .party-list { max-height: 175px; }
  .category-list { max-height: 190px; }
  .graph-panel { order: 2; }
  .method { grid-template-columns: 1fr; gap: 10px; }
  .analysis-heading { align-items: flex-start; flex-direction: column; }
  .analysis-actions { width: 100%; justify-content: space-between; flex-wrap: wrap; }
  .analysis-heading > .local-party-control { align-self: stretch; }
}
@media (max-width: 560px) {
  .topbar { height: 52px; padding: 0 15px; }
  .top-meta { font-size: 7px; }
  main { width: calc(100% - 26px); }
  .intro { padding: 35px 0 20px; }
  h1 { font-size: 41px; }
  .intro-copy { font-size: 11px; }
  .intro-stats { font-size: 7px; }
  .controls { padding: 14px 12px; }
  .graph-header { padding: 14px 11px 10px; }
  .graph-header p { font-size: 8px; }
  .canvas-wrap, #graph-canvas { min-height: 0; }
  .graph-footer { flex-wrap: wrap; justify-content: flex-start; padding: 9px 10px; font-size: 7px; }
  .graph-tools button { min-width: 24px; }
  .analysis-block { padding: 13px 10px; }
  .local-party-control { align-items: flex-start; flex-direction: column; }
  .local-party-control select { width: 100%; max-width: none; }
  .simple-party-controls { align-items: stretch; flex-direction: column; gap: 8px; }
  .pair-mark { display: none; }
  .view-switch { width: 100%; }
  .view-switch button { flex: 1; }
  .analysis-actions { gap: 7px; }
  #category-table th, #category-table td { min-width: 90px; padding: 7px 6px; }
  footer { padding: 18px 15px 22px; }
}
