:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #1d1d27;
  --muted: #5d5f6e;
  --line: #dcdbe3;
  --accent: #4b2fa6;
  --accent-ink: #ffffff;
  --accent-soft: #ece8fb;
  --good: #1b7f4b;
  --good-soft: #e3f4ea;
  --bad: #b3261e;
  --bad-soft: #fbe7e5;
  --warn-soft: #fff4d6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 40, .06), 0 4px 16px rgba(20, 20, 40, .06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14141b; --surface: #1e1e28; --ink: #ececf2; --muted: #a4a5b5; --line: #34343f;
    --accent: #9d86ff; --accent-ink: #14141b; --accent-soft: #2b2547;
    --good: #5fd394; --good-soft: #17301f; --bad: #ff8a80; --bad-soft: #3a1c1a; --warn-soft: #3a3115;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14141b; --surface: #1e1e28; --ink: #ececf2; --muted: #a4a5b5; --line: #34343f;
  --accent: #9d86ff; --accent-ink: #14141b; --accent-soft: #2b2547;
  --good: #5fd394; --good-soft: #17301f; --bad: #ff8a80; --bad-soft: #3a1c1a; --warn-soft: #3a3115;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.5; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); letter-spacing: -.02em; }
h2 { font-size: 1.4rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; max-width: 980px; margin: 0 auto; }
.brand { font-weight: 800; text-decoration: none; color: var(--ink); display: flex; align-items: center; gap: 8px; font-size: 1.1rem; }
.logo { background: var(--accent); color: var(--accent-ink); width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.tag { font-size: .7rem; font-weight: 700; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 99px; }
.progress { height: 4px; background: var(--line); max-width: 980px; margin: 0 auto; border-radius: 4px; overflow: hidden; }
#progressBar { height: 100%; width: 0; background: var(--accent); transition: width .25s; }

main { max-width: 980px; margin: 0 auto; padding: 16px; outline: none; min-height: 60vh; }
.narrow { max-width: 640px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.hero { padding: 32px 0 8px; }
.hero p.lead { font-size: 1.15rem; color: var(--muted); max-width: 600px; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 24px 0; }
.feature { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.feature b { display: block; margin-bottom: 2px; }

.btn { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 10px; padding: 12px 18px; font: inherit; font-weight: 600; cursor: pointer; transition: transform .05s, background .15s, border-color .15s; }
@media (hover: hover) { .btn:hover { border-color: var(--accent); } }
button, a { -webkit-tap-highlight-color: transparent; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.big { padding: 16px 26px; font-size: 1.1rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 6px 10px; font-size: .85rem; }
.link { background: none; border: none; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; padding: 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }

input[type=text], select { font: inherit; padding: 14px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); width: 100%; font-size: 1.15rem; }
input[type=text]:focus, select:focus, .btn:focus-visible, .opt:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.searchwrap { position: relative; }
.suggest { list-style: none; margin: 4px 0 0; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); position: absolute; left: 0; right: 0; z-index: 5; max-height: 280px; overflow: auto; box-shadow: var(--shadow); }
.suggest li button { width: 100%; text-align: start; background: none; border: none; padding: 10px 12px; font: inherit; color: var(--ink); cursor: pointer; border-radius: 8px; }
.suggest li button:focus { background: var(--accent-soft); }
@media (hover: hover) { .suggest li button:hover { background: var(--accent-soft); } }
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; margin: 12px 0; }
.choice { text-align: start; }
.choice small { display: block; font-weight: 400; color: var(--muted); }
.notice { background: var(--warn-soft); border-radius: 10px; padding: 12px 14px; margin: 12px 0; }
.ok { background: var(--good-soft); border-radius: 10px; padding: 12px 14px; }

/* quiz */
.qtopic { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 700; color: var(--accent); }
.qtext { font-size: clamp(1.3rem, 3.2vw, 1.75rem); font-weight: 700; margin: 6px 0 12px; letter-spacing: -.01em; }
.opts { display: grid; gap: 8px; margin: 18px 0 12px; }
.opt { display: flex; align-items: center; gap: 12px; width: 100%; text-align: start; padding: 14px 16px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); font: inherit; font-size: 1.05rem; color: var(--ink); cursor: pointer; }
@media (hover: hover) { .opt:hover { border-color: var(--accent); } }
.opt:active { transform: scale(.99); }
.opt[aria-pressed=true] { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.opt .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.importance { display: flex; align-items: center; gap: 8px; margin: 8px 0 4px; cursor: pointer; user-select: none; }
.importance input { width: 20px; height: 20px; accent-color: var(--accent); }
details.help { margin-top: 10px; color: var(--muted); }
details.help summary { cursor: pointer; color: var(--accent); }
.qnav { display: flex; justify-content: space-between; margin-top: 16px; gap: 8px; }
.kbd { font-size: .75rem; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip { border: 2px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 99px; padding: 8px 14px; font: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.chip[aria-pressed=true] { border-color: var(--bad); background: var(--bad-soft); }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* results */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab { background: none; border: none; padding: 12px 14px; font: inherit; font-weight: 700; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tab[aria-selected=true] { color: var(--ink); border-color: var(--accent); }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px; font-weight: 700; font-size: .9rem; }
.status.good { background: var(--good-soft); color: var(--good); }
.status.bad { background: var(--bad-soft); color: var(--bad); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: none; background: var(--surface); color: var(--ink); padding: 8px 14px; font: inherit; cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

.ranklist { list-style: none; padding: 0; margin: 0; }
.rank { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 6px; background: var(--surface); }
.rank.dragging { opacity: .5; }
.rank.drop-target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.rank .num { font-weight: 800; font-size: 1.3rem; text-align: center; border: 2px solid var(--ink); border-radius: 6px; height: 40px; display: grid; place-items: center; }
.rank .who { min-width: 0; }
.rank .name { font-weight: 700; }
.rank .party { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.badge { font-size: .7rem; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: inherit; }
.badge.last { background: var(--bad-soft); color: var(--bad); }
.meter { height: 6px; background: var(--line); border-radius: 6px; margin-top: 6px; overflow: hidden; max-width: 260px; }
.meter i { display: block; height: 100%; border-radius: 6px; }
.moves { display: flex; flex-direction: column; gap: 2px; }
.moves button { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 6px; width: 34px; height: 26px; cursor: pointer; font-size: .8rem; }
.moves button:disabled { opacity: .3; }
.why { grid-column: 2 / 4; font-size: .85rem; }
.why summary { cursor: pointer; color: var(--accent); }
.why ul { margin: 6px 0; padding-inline-start: 18px; }
.agree { color: var(--good); }
.disagree { color: var(--bad); }

/* ballot paper replica */
.ballot { background: #fff; color: #111; border: 2px solid #111; border-radius: 4px; padding: 16px; font-family: Arial, Helvetica, sans-serif; }
.ballot h3 { text-align: center; font-size: 1rem; text-transform: uppercase; margin: 0; }
.ballot .sub { text-align: center; font-size: .8rem; margin-bottom: 10px; }
.ballot .instr { font-size: .78rem; text-align: center; border-top: 1px solid #111; border-bottom: 1px solid #111; padding: 6px; margin-bottom: 12px; }
.b-row { display: grid; grid-template-columns: 52px 1fr; gap: 12px; align-items: center; padding: 6px 0; border-bottom: 1px dotted #999; }
.box { width: 46px; height: 46px; border: 2px solid #111; display: grid; place-items: center; font-family: "Comic Sans MS", "Segoe Print", cursive; font-size: 1.6rem; font-weight: 700; color: #1a3fbf; background: #fff; }
.box.empty { color: transparent; }
.b-name { font-weight: 700; text-transform: uppercase; font-size: .95rem; }
.b-name .given { text-transform: none; }
.b-party { font-size: .8rem; }
.lc { overflow-x: auto; }
.lc-grid { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0; }
.lc-cand > div { min-width: 0; overflow-wrap: break-word; }
.lc-col { border-right: 1px solid #111; }
.lc-col:last-child { border-right: none; }
.lc-atl { display: flex; flex-direction: column; align-items: center; justify-content: space-between; text-align: center; height: 150px; gap: 4px; padding: 6px 6px 10px; border-bottom: 4px solid #111; }
.lc-btl { padding: 8px; }
.lc-letter { font-weight: 800; }
.lc-gname { font-size: .66rem; font-weight: 700; text-transform: uppercase; line-height: 1.25; max-height: 5em; overflow: hidden; }
.lc-line { grid-column: 1 / -1; border-top: 4px solid #111; margin: 0; }
.lc-btl { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; }
.lc-cand { display: grid; grid-template-columns: 32px 1fr; gap: 6px; align-items: center; font-size: .72rem; }
.lc-cand .box { width: 30px; height: 30px; font-size: 1.1rem; }
.lc-cand b { text-transform: uppercase; display: block; }
.lc-label { font-size: .7rem; text-align: center; font-weight: 700; padding: 4px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 20px; }
table.matrix { border-collapse: collapse; width: 100%; font-size: .85rem; }
table.matrix th, table.matrix td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: center; }
table.matrix th:first-child, table.matrix td:first-child { text-align: start; }
.pos { font-weight: 700; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; z-index: 50; }

.foot { max-width: 980px; margin: 24px auto; padding: 16px; font-size: .8rem; color: var(--muted); border-top: 1px solid var(--line); }

.print-only { display: none; }
@media print {
  @page { margin: 12mm; }
  body { background: #fff; color: #000; }
  .no-print, .topbar, .foot, .tabs, .actions, .moves, .why, .progress, .controls { display: none !important; }
  .print-only { display: block; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: none; padding: 0; }
  .ballot { break-inside: avoid; margin-bottom: 10mm; }
  .tabpanel { display: block !important; }
  .tabpanel.rankpanel { display: none !important; }
  .lc-grid { grid-auto-columns: minmax(0, 1fr); min-width: 0; }
  .lc { font-size: 7pt; padding: 6px; }
  .lc .lc-gname, .lc .lc-cand { font-size: 6.5pt; }
  .lc .lc-btl { padding: 3px; }
  .lc .box { width: 24px; height: 24px; font-size: 13pt; }
  .lc .lc-cand { grid-template-columns: 26px 1fr; }
  .lc .lc-atl { height: 80px; padding: 3px; }
  .ballot.la { max-width: 120mm; }
}

/* --- UX sweep additions --- */
.tops { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin-top: 4px; }
.tops > div { display: flex; flex-direction: column; gap: 2px; background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.tops b { font-size: 1.05rem; }
@media (max-width: 760px) { .ballotcol { order: -1; } }
.review { padding: 16px; margin-bottom: 10px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { border: 2px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 99px; padding: 7px 12px; font: inherit; font-size: .9rem; cursor: pointer; }
.pill[aria-pressed=true] { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.star { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 99px; padding: 4px 10px; font: inherit; font-size: .8rem; cursor: pointer; filter: grayscale(1); }
.star[aria-pressed=true] { filter: none; color: var(--ink); border-color: #d39e00; background: var(--warn-soft); font-weight: 700; }
.donate { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.btn.coffee { background: #ffdd00; color: #1d1d1d; border-color: #ffdd00; text-decoration: none; }
.foot .coffee-link { font-weight: 700; }
.importance { align-items: flex-start; }
.importance input { margin-top: 2px; flex: none; }
.qnav { flex-wrap: wrap; }
@media (hover: none) { .kbd { display: none; } }
@media (max-width: 520px) {
  .actions { display: grid; grid-template-columns: 1fr 1fr; }
  .actions .btn { padding: 10px 8px; font-size: .9rem; text-align: center; }
  .status { font-size: .8rem; padding: 4px 10px; }
}
.hero.home { padding: 12vh 0 8vh; display: flex; flex-direction: column; gap: 14px; }
.hero.home h1 { font-size: clamp(2.4rem, 7vw, 4rem); margin: 0; }
.hero.home .lead { margin: 0; }
.hero.home p.small { margin: 0; }

/* Languages */
.topbar nav { display: flex; align-items: center; gap: 12px; }
.langsel { width: auto; max-width: 140px; padding: 6px 8px; font: inherit; font-size: .9rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.langs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.langbtn { font: inherit; font-size: .9rem; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.langbtn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
@media (hover: hover) { .langbtn:hover { border-color: var(--accent); } }
.transnote { max-width: 600px; }
.opt .kbd { margin-inline-start: auto; }
[dir="rtl"] .ballot, [dir="rtl"] .lc-grid { direction: ltr; }
[dir="rtl"] .ballot .instr, [dir="rtl"] .ballot .sub { direction: rtl; }
.topbar { gap: 8px; }
.topbar nav .link { white-space: nowrap; }
@media (max-width: 480px) {
  .topbar .tag { display: none; }
  .langsel { max-width: 110px; font-size: .85rem; padding: 5px 6px; }
}
