:root {
  --bg: #f6f5f8;
  --surface: #ffffff;
  --surface-2: #faf9fb;
  --border: #e7e4ec;
  --text: #1d1a24;
  --muted: #6b6578;
  --faint: #9a94a6;
  --accent: #c2185b;
  --accent-soft: #fce4ef;
  --accent-ink: #8e0e42;
  --ok: #157347;
  --ok-soft: #e3f4ea;
  --warn: #9a5b00;
  --warn-soft: #fff2d6;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --info-soft: #ebe9f5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(29, 26, 36, .05), 0 4px 16px rgba(29, 26, 36, .04);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 600; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; height: 60px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 800; letter-spacing: .02em;
}
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; margin-top: -2px; }
.nav { display: flex; gap: 2px; margin-left: 12px; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 550;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav .count {
  margin-left: 6px; padding: 0 6px; border-radius: 10px; font-size: 11px;
  background: var(--warn-soft); color: var(--warn); font-weight: 700;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.updated { font-size: 12px; color: var(--muted); text-align: right; line-height: 1.3; }

/* ---------- layout ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 28px 24px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.grid { display: grid; gap: 16px; }
.grid.posts { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.split { display: grid; grid-template-columns: 380px 1fr; gap: 20px; align-items: start; }
.split > * { min-width: 0; }
.board .item > * { min-width: 0; }
@media (max-width: 980px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .split .sticky { position: static; }
}

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.sticky { position: sticky; top: 80px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--surface-2); border-color: #d6d1de; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn.danger { color: var(--bad); }
.ico { display: inline-flex; flex: none; }
.ico svg { width: 16px; height: 16px; }
.spin svg { animation: spin 1s linear infinite; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

input, select, textarea {
  font: inherit; color: var(--text);
  height: 38px; padding: 0 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface);
  outline: none; transition: border-color .12s, box-shadow .12s;
}
textarea { height: auto; padding: 10px 12px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: grid; gap: 6px; font-weight: 600; font-size: 13px; }
label.field span.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.search { position: relative; }
.search input { padding-left: 34px; width: 240px; }
.search svg { position: absolute; left: 11px; top: 11px; width: 16px; height: 16px; color: var(--faint); }

/* ---------- badges / chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--info-soft); color: var(--muted);
}
.badge.counted { background: var(--ok-soft); color: var(--ok); }
.badge.ambiguous { background: var(--warn-soft); color: var(--warn); }
.badge.invalid, .badge.deleted { background: var(--bad-soft); color: var(--bad); }
.badge.duplicate, .badge.late, .badge.reply { background: var(--info-soft); color: var(--muted); }
.badge.region { background: var(--accent-soft); color: var(--accent-ink); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px;
  border-radius: 16px; border: 1px solid var(--border); background: var(--surface);
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.chip b { font-weight: 700; color: var(--text); }
.chip:hover { border-color: #d6d1de; }
.chip.active { background: var(--text); border-color: var(--text); color: #fff; }
.chip.active b { color: #fff; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 750; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.attention .value { color: var(--warn); }

/* ---------- post cards ---------- */
.post-card { display: flex; flex-direction: column; color: inherit; transition: border-color .12s, transform .12s; }
.post-card:hover { text-decoration: none; border-color: #d6c4d4; transform: translateY(-1px); }
.post-card .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 16px 18px 10px; }
.post-card .meta { display: flex; gap: 14px; padding: 0 18px 12px; color: var(--muted); font-size: 12.5px; }
.post-card .meta b { color: var(--text); }
.podium { border-top: 1px solid var(--border); padding: 10px 18px 14px; display: grid; gap: 8px; }
.podium .row { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 10px; }
.medal { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 800; color: #fff; }
.medal.r1 { background: #d4a017; } .medal.r2 { background: #9aa3ad; } .medal.r3 { background: #b87333; }
.post-card .footer { margin-top: auto; border-top: 1px solid var(--border); padding: 10px 18px; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.empty-note { color: var(--faint); font-size: 13px; padding: 4px 0; }

/* ---------- leaderboard ---------- */
.board { padding: 6px 8px 10px; }
.board .item { display: grid; grid-template-columns: 28px 1fr 44px; gap: 10px; align-items: center; padding: 7px 12px; border-radius: 9px; }
.board .item:hover { background: var(--surface-2); }
.board .rank { font-weight: 700; color: var(--faint); text-align: center; font-variant-numeric: tabular-nums; }
.board .item.top3 .rank { color: var(--accent); }
.board .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .sub { font-size: 11.5px; color: var(--muted); }
.bar { height: 6px; border-radius: 4px; background: var(--surface-2); margin-top: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--accent); opacity: .85; }
.board .votes { font-size: 16px; font-weight: 750; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr.row-ambiguous td { background: #fffbf0; }
.comment-text { max-width: 420px; word-wrap: break-word; }
.user { font-weight: 600; }
.vote-for { font-weight: 600; }
.review-cell { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.review-cell select { height: 30px; font-size: 12.5px; max-width: 220px; }
.override-note { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent-ink); border-bottom-color: var(--accent); }

/* ---------- misc ---------- */
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius); border: 1px solid; margin-bottom: 20px; }
.notice.warn { background: var(--warn-soft); border-color: #f3d28f; color: #5c3a00; }
.notice.bad { background: var(--bad-soft); border-color: #f5b5ae; color: #6d150e; }
.notice.ok { background: var(--ok-soft); border-color: #a8dbbd; color: #0c4a2b; }
.notice .btn { margin-left: auto; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.copy-box { display: flex; gap: 8px; }
.copy-box input { flex: 1; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.candidate-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 16px; max-height: 360px; overflow: auto; padding: 8px; border: 1px solid var(--border); border-radius: 9px; }
.candidate-pick label { display: flex; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.candidate-pick label:hover { background: var(--surface-2); }
.candidate-pick input { height: auto; }
.region-head { grid-column: 1 / -1; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 8px 6px 2px; }

.toast-host { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18); font-weight: 550; animation: rise .18s ease-out; }
.toast.bad { background: var(--bad); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.skeleton { background: linear-gradient(90deg, #eeecf1 25%, #f6f5f8 50%, #eeecf1 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: 44px; min-width: 200px; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,.12); }
.menu-pop .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-pop button, .menu-pop a { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; font: inherit; color: var(--text); border-radius: 7px; cursor: pointer; }
.menu-pop button:hover, .menu-pop a:hover { background: var(--surface-2); text-decoration: none; }
.avatar { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--accent-soft); color: var(--accent-ink); font-weight: 750; cursor: pointer; font: inherit; font-weight: 700; }

dialog { border: none; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 24px 64px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(29, 26, 36, .45); }
dialog .card-head { border-bottom: 1px solid var(--border); }
dialog .body { padding: 18px 20px; display: grid; gap: 14px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ---------- auth pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(1000px 500px at 10% -10%, #fbe3ee 0%, transparent 60%),
  radial-gradient(800px 500px at 110% 110%, #ece6f7 0%, transparent 60%), var(--bg); }
.auth-card { width: min(400px, 100%); padding: 32px; }
.auth-card .brand { margin-bottom: 24px; }
.auth-card form { display: grid; gap: 14px; margin-top: 20px; }
.auth-card input { width: 100%; height: 42px; }
.auth-card .btn { height: 42px; width: 100%; }
.error { color: var(--bad); font-size: 13px; font-weight: 550; }

@media (max-width: 720px) {
  .topbar { padding: 8px 14px 0; gap: 8px; height: auto; flex-wrap: wrap; }
  .nav { order: 3; width: 100%; margin: 0 -4px; overflow-x: auto; padding-bottom: 6px; }
  .updated { display: none; }
  main { padding: 20px 14px 48px; }
  .search input { width: 100%; }
  .btn .label-long { display: none; }
}
