:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b2230;
  --muted: #5f6b7c;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --accent-soft: #e7ecff;
  --good: #2b8a3e;
  --good-soft: #e3f6e8;
  --warn: #b35c00;
  --warn-soft: #fff1dc;
  --bad: #c92a2a;
  --bad-soft: #ffe8e8;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #181c24;
    --surface-2: #20252f;
    --border: #2d3340;
    --text: #e6e9ef;
    --muted: #9aa4b5;
    --accent: #7c95ff;
    --accent-text: #0f1218;
    --accent-soft: #232c4d;
    --good: #69db7c;
    --good-soft: #1b3324;
    --warn: #ffc078;
    --warn-soft: #3a2a14;
    --bad: #ff8787;
    --bad-soft: #3d1d1d;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.wrap { max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; }
.wrap.wide { max-width: 1000px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); letter-spacing: 0.01em; }
.brand span { color: var(--accent); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }

button, .btn {
  font: inherit; font-weight: 600; font-size: 0.95rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 9px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px;
}
button:hover, .btn:hover { background: var(--surface-2); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.05); }
button.danger { color: var(--bad); }
button.ghost { border-color: transparent; background: transparent; }
button.sm { padding: 4px 10px; min-height: 32px; font-size: 0.85rem; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

label.field { display: block; font-weight: 600; font-size: 0.9rem; }
label.field > span.hint { font-weight: 400; color: var(--muted); }
input[type="text"], input[type="password"], input[type="datetime-local"], input:not([type]), textarea, select {
  font: inherit; width: 100%; margin-top: 4px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text);
  font-weight: 400;
}
textarea { min-height: 120px; resize: vertical; }
select { width: auto; margin-top: 0; padding: 6px 8px; }
label.check { display: flex; gap: 8px; align-items: center; font-size: 0.95rem; }

.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.notice { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); margin-bottom: 16px; }
.notice.good { background: var(--good-soft); }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }

table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Ballot ---------- */
.rank-list { list-style: none; margin: 0; padding: 0; min-height: 56px; border-radius: 10px; }
.rank-list.empty-target { border: 2px dashed var(--border); padding: 6px 6px 0; }
.empty-hint { list-style: none; text-align: center; color: var(--muted); font-size: 0.9rem; padding: 10px 0 16px; }
.rank-list.empty-target .rank-item ~ .empty-hint, .rank-list .rank-item ~ .empty-hint { display: none; }
.rank-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 8px 8px 10px; margin-bottom: 8px; user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
.rank-item .pos {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 0.9rem;
}
.rank-item.unranked .pos { background: var(--surface-2); color: var(--muted); }
.rank-item.unranked .label { color: var(--muted); }
.divider {
  list-style: none; display: flex; align-items: center; gap: 10px; margin: 14px 0 12px;
  color: var(--muted); font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.divider::before, .divider::after { content: ""; flex: 1; border-top: 2px dashed var(--border); }
.divider span { flex: none; max-width: 70%; text-align: center; }
.rank-item .label { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 500; }
.rank-item select { flex: none; }
.rank-item .handle {
  flex: none; width: 40px; height: 40px; display: grid; place-items: center; cursor: grab;
  color: var(--muted); border-radius: 8px; touch-action: none; font-size: 20px; line-height: 1;
}
.rank-item .handle:active { cursor: grabbing; }
.rank-item.sortable-ghost { opacity: 0.35; }
.rank-item.sortable-chosen { box-shadow: 0 6px 24px rgb(0 0 0 / 18%); border-color: var(--accent); }
.rank-item.flash { animation: flash 0.6s ease; }
@keyframes flash { from { background: var(--accent-soft); } to { background: var(--surface); } }
.section-label { font-size: 0.8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 18px 0 8px; }
.sticky-submit { padding: 4px 0 12px; }
.sticky-submit button { width: 100%; justify-content: center; min-height: 48px; font-size: 1rem; }

/* ---------- Results ---------- */
.winner {
  display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 12px;
  background: var(--accent-soft); margin-bottom: 16px;
}
.winner .trophy { font-size: 28px; }
.winner .name { font-size: 1.3rem; font-weight: 700; }
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 30%) 1fr auto; gap: 10px; align-items: center; font-size: 0.92rem; }
.bar-row .track { background: var(--surface-2); border-radius: 6px; height: 22px; overflow: hidden; }
.bar-row .fill { background: var(--accent); height: 100%; border-radius: 6px; min-width: 2px; }
.bar-row.out .fill { background: var(--muted); opacity: 0.5; }
.bar-row .val { font-variant-numeric: tabular-nums; min-width: 2.5em; text-align: right; }
.bar-row .name { overflow-wrap: anywhere; }
.round { margin-bottom: 16px; }
.round h4 { margin: 0 0 8px; font-size: 0.9rem; }
.ranking-list { margin: 0 0 16px; padding-left: 1.6em; }
.ranking-list li { margin: 2px 0; }
.matrix td.win { color: var(--good); font-weight: 700; }
.matrix td.lose { color: var(--muted); }
.matrix td.self { background: var(--surface-2); }
details { margin-top: 12px; }
details > summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.method-desc { font-size: 0.9rem; color: var(--muted); margin-bottom: 12px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { min-height: 34px; padding: 5px 11px; font-size: 0.85rem; }
.tabs button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600;
  box-shadow: var(--shadow); z-index: 100; max-width: calc(100% - 32px);
}
.hidden { display: none !important; }
.voter-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 640px) {
  .voters-table .hide-sm { display: none; }
}
/* Room under the last item so a choice can be dropped below the "not ranked" line. */
#ballot.partial { padding-bottom: 56px; }
