:root {
  --bg: #f4efe7;
  --surface: #fffdf9;
  --surface-2: #efe8dc;
  --line: #e0d6c7;
  --ink: #1e1a17;
  --ink-2: #5d554c;
  --ink-3: #8d847a;
  --accent: #b8452f;
  --accent-ink: #fff;
  --ok: #2f7d4f;
  --warn: #c98a1b;
  --font-display: 'Cabinet Grotesk', 'Satoshi', system-ui, sans-serif;
  --font-body: 'Satoshi', system-ui, -apple-system, sans-serif;
  --r: 14px;
  --shadow: 0 1px 2px rgba(30,26,23,.04), 0 8px 24px -12px rgba(30,26,23,.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums lining-nums;
}
h1, h2, h3 { margin: 0; font-family: var(--font-body); }
h2 { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
a { color: var(--accent); }
small { font-weight: 500; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; gap: 18px; align-items: center; justify-content: space-between;
  padding: 18px 28px; background: var(--ink); color: #f6efe6;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 40px; height: 40px; color: #f6efe6; }
.brand-title { font-family: var(--font-display); font-weight: 800; font-size: 24px; line-height: 1.05; letter-spacing: -.02em; }
.brand-sub { font-size: 13px; color: #c9beb0; }
.topbar-controls { display: flex; gap: 22px; align-items: flex-end; flex-wrap: wrap; min-width: 0; max-width: 100%; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: #c9beb0; font-weight: 500; min-width: 0; max-width: 100%; }
.topbar select {
  font: inherit; font-size: 14px; color: var(--ink); background: #fffdf9; border: 1px solid transparent;
  border-radius: 10px; padding: 8px 12px; min-width: 260px; max-width: 100%;
}
.segmented { display: inline-flex; background: #2d2824; border-radius: 10px; padding: 3px; gap: 3px; }
.segmented button {
  font: inherit; font-size: 14px; font-weight: 700; color: #c9beb0; background: transparent; border: 0;
  border-radius: 8px; padding: 6px 12px; cursor: pointer; display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15;
}
.segmented button small { font-size: 10.5px; font-weight: 500; opacity: .75; }
.segmented button.on { background: var(--accent); color: #fff; }
.segmented button.on small { opacity: .9; }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(380px, 520px) minmax(0, 1fr);
  gap: 22px; padding: 22px 28px 60px; max-width: 1560px; margin: 0 auto;
}
.controls, .dashboard { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.card {
  min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hint { margin: 0 0 14px; color: var(--ink-2); font-size: 13.5px; }
.badge { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--ink); color: #fff; white-space: nowrap; }
.badge.soft { background: var(--surface-2); color: var(--ink-2); }
.badge.bad { background: var(--accent); }
.badge.ok { background: var(--ok); }
.btn {
  font: inherit; font-size: 13px; font-weight: 700; border-radius: 9px; padding: 7px 12px; cursor: pointer; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
}
.btn:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 4px 8px; font-size: 12px; color: var(--ink-3); border-color: transparent; }
.btn.tiny:hover { color: var(--accent); background: transparent; }

/* ---------- list rows ---------- */
.list-row {
  display: grid; grid-template-columns: 10px 1fr 158px 72px 26px; gap: 10px; align-items: center;
  padding: 9px 0; border-top: 1px solid var(--line);
}
.list-row:first-child { border-top: 0; }
.swatch { width: 10px; height: 34px; border-radius: 4px; }
.list-name { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.list-name input[type=text] {
  font: inherit; font-weight: 700; font-size: 14px; border: 0; background: transparent; padding: 0; color: var(--ink); width: 100%;
  border-bottom: 1px dashed transparent;
}
.list-name input[type=text]:focus { outline: 0; border-bottom-color: var(--ink-3); }
.list-name input[type=range] { width: 100%; }
.list-row select {
  font: inherit; font-size: 12.5px; font-weight: 500; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--surface); color: var(--ink); max-width: 100%;
}
.pct-input {
  font: inherit; font-size: 15px; font-weight: 700; width: 78px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; text-align: right; background: var(--surface); color: var(--ink);
}
.list-row.excluded .list-name input[type=text] { color: var(--ink-3); }
.tag { font-size: 11px; color: var(--ink-3); font-weight: 500; }

input[type=range] { accent-color: var(--accent); height: 22px; margin: 0; }

/* ---------- coalitions ---------- */
.coal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.coal {
  border: 1px solid var(--line); border-left-width: 5px; border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; background: var(--surface);
}
.coal .coal-name { font-size: 12px; color: var(--ink-3); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.coal input {
  font: inherit; font-weight: 700; font-size: 15px; border: 0; border-bottom: 1px dashed var(--line); background: transparent; padding: 2px 0; color: var(--ink); width: 100%;
}
.coal input:focus { outline: 0; border-bottom-color: var(--ink-3); }
.coal .coal-meta { font-size: 12.5px; color: var(--ink-2); }

/* ---------- candidate section ---------- */
.cand-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.cand-tabs button {
  font: inherit; font-size: 13px; font-weight: 700; border-radius: 999px; padding: 6px 12px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
}
.cand-tabs button.civico { border-color: #e7c9a1; }
.cand-tabs button.politico { border-color: #b9c3e3; }
.cand-tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.cand-profile { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; background: var(--surface-2); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.cand-avatar {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-display); font-weight: 800; font-size: 18px; color: #fff;
}
.cand-profile .type { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.cand-profile .type.civico { color: #a0641c; }
.cand-profile .type.politico { color: #2f4b9e; }
.cand-profile .name { font-weight: 700; font-size: 16px; }
.cand-profile .desc { font-size: 13px; color: var(--ink-2); }
.check { display: flex; gap: 8px; align-items: center; font-size: 13.5px; margin: 6px 0 12px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.params { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
.param { display: flex; flex-direction: column; gap: 2px; }
.param .p-head { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-2); gap: 8px; }
.param .p-head b { white-space: nowrap; }
.param .p-head b { color: var(--ink); font-size: 13px; }
.param input[type=range] { width: 100%; }

/* ---------- runoff controls ---------- */
.runoff-row { border-top: 1px solid var(--line); padding: 10px 0; display: grid; grid-template-columns: 1fr; gap: 8px; }
.runoff-row:first-child { border-top: 0; }
.runoff-row .rr-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.runoff-row .rr-head .who { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.rr-head select { font: inherit; font-size: 12.5px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; background: var(--surface); color: var(--ink); }
.rr-sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; }

/* ---------- flow table ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 11.5px; color: var(--ink-3); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
th:first-child, td:first-child { text-align: left; }
.flow th, .flow td { padding: 5px 4px; }
.flow th { font-size: 10.5px; letter-spacing: .02em; }
.flow input { width: 46px; font: inherit; font-size: 12.5px; text-align: right; border: 1px solid var(--line); border-radius: 6px; padding: 3px 4px; background: var(--surface); color: var(--ink); }
.flow input.locked { background: var(--surface-2); }
.flow td.diag { color: var(--ink-3); font-weight: 700; }
.flow td.rowhead { font-weight: 700; color: var(--ink); font-size: 12.5px; }

/* ---------- outcome banner ---------- */
.outcome {
  border-radius: var(--r); padding: 20px 22px; color: #fff; background: var(--ink); display: flex; flex-direction: column; gap: 16px; box-shadow: var(--shadow);
}
.outcome.first { background: linear-gradient(120deg, #1e1a17, #3a2a24); }
.outcome.runoff { background: linear-gradient(120deg, #1e1a17, #1f2a44); }
.outcome .kicker { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: #c9beb0; font-weight: 700; }
.outcome .headline { font-family: var(--font-display); font-weight: 800; font-size: 28px; letter-spacing: -.02em; line-height: 1.1; margin-top: 4px; }
.outcome .sub { color: #ddd2c4; font-size: 14px; margin-top: 6px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi { background: rgba(255,255,255,.08); border-radius: 10px; padding: 10px 14px; min-width: 0; }
.kpi .k { font-size: 11px; color: #c9beb0; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .v { font-family: var(--font-display); font-size: 26px; font-weight: 800; line-height: 1.1; }
.kpi .d { font-size: 12px; color: #ddd2c4; }

/* ---------- mayor bars ---------- */
.mayor-bars { display: flex; flex-direction: column; gap: 9px; margin-bottom: 14px; }
.mbar { display: grid; grid-template-columns: 190px 1fr 70px; gap: 12px; align-items: center; }
.mbar .who { font-weight: 700; font-size: 14px; display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.mbar .who span { font-size: 11.5px; color: var(--ink-3); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mbar .track { height: 26px; background: var(--surface-2); border-radius: 6px; position: relative; overflow: hidden; }
.mbar .fill { height: 100%; border-radius: 6px; transition: width .25s ease; }
.mbar .fill.thin { min-width: 2px; }
.mbar .val { font-weight: 800; font-family: var(--font-display); font-size: 20px; text-align: right; }
.mbar .track::after { content: ""; position: absolute; top: 0; bottom: 0; left: var(--thr, 50%); width: 2px; background: var(--ink); opacity: .55; }
.gauge-wrap { margin-top: 6px; }
.gauge { position: relative; height: 12px; background: var(--surface-2); border-radius: 999px; overflow: visible; }
.gauge .seg { position: absolute; top: 0; height: 100%; }
.gauge .seg:first-child { border-radius: 999px 0 0 999px; }
.gauge .marker { position: absolute; top: -4px; width: 2px; height: 20px; background: var(--ink); }
.gauge .marker.soft { opacity: .3; }
.gauge-labels { display: flex; justify-content: space-between; position: relative; font-size: 11px; color: var(--ink-3); margin-top: 6px; }
.gauge-labels .mark40 { position: absolute; left: 40%; transform: translateX(-50%); }
.gauge-labels .mark50 { position: absolute; left: 50%; transform: translateX(-50%); }

/* ---------- hemicycle ---------- */
.hemicycle { width: 100%; height: auto; display: block; margin: 4px auto 6px; max-width: 640px; }
.hemicycle circle { transition: fill .2s ease; }
.hemicycle .center-num { font-family: var(--font-display); font-weight: 800; font-size: 44px; fill: var(--ink); }
.hemicycle .center-lab { font-size: 13px; fill: var(--ink-3); font-weight: 700; }
.hemicycle .maj-line { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 4 4; opacity: .6; }
.hemicycle .maj-lab { font-size: 11px; fill: var(--ink-2); font-weight: 700; }
.seat-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; font-size: 12.5px; margin-bottom: 12px; }
.seat-legend span { display: inline-flex; gap: 6px; align-items: center; }
table.seats td.b { font-weight: 800; }
table.seats tr.group td { background: var(--surface-2); font-weight: 700; }
table.seats tr.cand td { color: var(--ink-2); font-style: normal; }
table.seats td.dim { color: var(--ink-3); }

/* ---------- runoff view ---------- */
.rv-heads { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 12px; }
.rv-head { border-radius: 10px; padding: 12px 14px; color: #fff; }
.rv-head .n { font-weight: 700; font-size: 15px; }
.rv-head .p { font-family: var(--font-display); font-size: 34px; font-weight: 800; line-height: 1; margin-top: 4px; }
.rv-head .s { font-size: 12px; opacity: .85; margin-top: 4px; }
.rv-bar { height: 22px; border-radius: 6px; overflow: hidden; display: flex; margin-bottom: 12px; position: relative; }
.rv-bar::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--ink); }
.rv-empty { color: var(--ink-2); font-size: 14px; padding: 8px 0; }
.rv-empty b { color: var(--ink); }

/* ---------- compare ---------- */
table.compare td.res { font-weight: 700; }
table.compare .pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.pill.first { background: #e6d4cf; color: #7a2f22; }
.pill.runoff { background: #d6dcec; color: #24365e; }
.pill.win { background: #d3e8da; color: #1f5a37; }
table.compare tr.on td { background: var(--surface-2); }
table.compare td.t { text-align: left; }
.type-chip { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 1px 6px; border-radius: 4px; margin-left: 6px; }
.type-chip.civico { background: #f3e2c8; color: #8a5414; }
.type-chip.politico { background: #dde3f5; color: #2f4b9e; }

.notes ul { margin: 0; padding-left: 18px; font-size: 13.5px; color: var(--ink-2); display: flex; flex-direction: column; gap: 8px; }
.notes strong { color: var(--ink); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .dashboard { order: -1; }
}
@media (max-width: 640px) {
  .topbar, .layout { padding-left: 14px; padding-right: 14px; }
  .topbar-controls, .field { width: 100%; }
  .topbar select { min-width: 0; width: 100%; }
  .seats th:nth-child(3), .seats td:nth-child(3) { display: none; }
  .seats td:first-child, th { white-space: normal; }
  .compare th:nth-child(2), .compare td:nth-child(2), .compare th:nth-child(5), .compare td:nth-child(5), .compare th:nth-child(6), .compare td:nth-child(6) { display: none; }
  #runoff-view th:nth-child(5), #runoff-view td:nth-child(5), #runoff-view th:nth-child(6), #runoff-view td:nth-child(6) { display: none; }
  .compare td { white-space: normal; }
  .compare th:nth-child(8), .compare td:nth-child(8), .compare th:nth-child(3), .compare td:nth-child(3) { display: none; }
  .compare th, .compare td { padding: 6px 4px; font-size: 12px; }
  .compare .pill { display: block; margin: 2px 0; text-align: center; font-size: 11px; }
  .compare .type-chip { display: inline-block; margin: 3px 0 0; }
  .compare td.t:first-child { white-space: nowrap; }
  .compare td.t:first-child .cname { display: block; }
  .seats td:first-child { min-width: 150px; }
  .seats th, .seats td, .compare th, .compare td { padding: 6px 6px; font-size: 12.5px; }
  .list-row { grid-template-columns: 8px 1fr 70px 24px; }
  .list-row select { grid-column: 2 / span 3; }
  .coal-grid, .params, .rr-sliders { grid-template-columns: 1fr; }
  .outcome { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .mbar { grid-template-columns: 120px 1fr 60px; }
  .outcome .headline { font-size: 24px; }
}
