:root {
  --bg: #f5f2ec;
  --surface: #ffffff;
  --ink: #17181c;
  --muted: #5d6170;
  --line: #e3ded4;
  --primary: #2346c4;
  --primary-ink: #ffffff;
  --primary-hover: #1a37a3;
  --voted: #1d7f52;
  --voted-bg: #e5f4ec;
  --danger: #b42318;
  --danger-hover: #8f1c13;
  --yellow: #ffd43b;
  --yellow-deep: #f2b705;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.06), 0 4px 16px rgba(20, 20, 30, 0.06);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; line-height: 1.5; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* ---------- header ---------- */
.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 36px 0 28px;
}
.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 5.5vw, 3.6rem);
  line-height: 1.02;
  letter-spacing: -0.035em;
  font-weight: 800;
}
.hero h1 .dash { color: var(--primary); }
.tagline {
  margin: 10px 0 22px;
  font-size: clamp(1.02rem, 2.2vw, 1.3rem);
  color: var(--muted);
  max-width: 34ch;
}
.qr {
  margin: 0;
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 12px 8px;
  text-align: center;
  box-shadow: var(--shadow);
}
.qr-code { width: 168px; height: 168px; }
.qr-code svg { width: 100%; height: 100%; display: block; }
.qr figcaption { font-size: 0.8rem; color: var(--muted); margin-top: 6px; max-width: 168px; word-break: break-all; }
.qr figcaption strong { display: block; color: var(--ink); font-size: 0.85rem; word-break: normal; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  background: var(--surface);
  font-weight: 650;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.05s;
  text-decoration: none;
  color: var(--ink);
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 40%, transparent); outline-offset: 2px; }
.btn:disabled { cursor: not-allowed; opacity: 0.6; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.big { font-size: 1.08rem; padding: 14px 26px; min-height: 52px; }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.danger.solid:hover:not(:disabled) { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn.ghost { border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { border-color: var(--ink); }
.btn.voted, .btn.voted:disabled { background: var(--voted-bg); border-color: var(--voted); color: var(--voted); opacity: 1; }

.spinner {
  width: 1em; height: 1em; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- status / banners ---------- */
.conn {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #fdecea;
  color: var(--danger);
  font-weight: 600;
  font-size: 0.95rem;
}
.loading {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 80px 0; color: var(--muted); font-size: 1.1rem;
}

/* ---------- waiting screen ---------- */
.waiting {
  background: var(--yellow);
  border: 3px solid var(--yellow-deep);
  border-radius: 22px;
  padding: clamp(36px, 7vw, 80px) clamp(22px, 5vw, 64px);
  text-align: center;
  margin-bottom: 48px;
}
.waiting .icon { font-size: clamp(2.6rem, 7vw, 4rem); line-height: 1; margin-bottom: 12px; }
.waiting h2 {
  margin: 0 0 12px;
  font-size: clamp(1.7rem, 5vw, 3rem);
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-weight: 800;
}
.waiting p { margin: 0 auto; max-width: 46ch; font-size: clamp(1rem, 2.4vw, 1.2rem); }
.waiting .pulse {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 22px;
  font-weight: 650; font-size: 0.95rem;
  background: rgba(255, 255, 255, 0.55); padding: 6px 14px; border-radius: 999px;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; display: inline-block; }
.pulse .dot { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ---------- board ---------- */
.board-head {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 14px;
  border-top: 2px solid var(--ink); padding-top: 14px; margin-bottom: 18px;
}
.board-head h2 { margin: 0; font-size: 1.35rem; letter-spacing: -0.01em; }
.board-head .count { color: var(--muted); }
.board-head .live { margin-left: auto; font-size: 0.85rem; color: var(--voted); display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }

.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
  padding-bottom: 56px;
}
.card {
  position: relative;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card.top { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary), var(--shadow); }
.rank {
  font-size: 0.78rem; font-weight: 800; letter-spacing: 0.04em;
  color: var(--muted); margin-bottom: 4px;
}
.card.top .rank { color: var(--primary); }
.card h3 { margin: 0 0 6px; font-size: 1.18rem; line-height: 1.25; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.card .desc { margin: 0 0 12px; color: #33353d; white-space: pre-wrap; overflow-wrap: anywhere; flex: 1; }
.card .meta { font-size: 0.88rem; color: var(--muted); margin-bottom: 14px; overflow-wrap: anywhere; }
.card .meta strong { color: var(--ink); font-weight: 650; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px dashed var(--line); padding-top: 12px; }
.votes { display: flex; align-items: baseline; gap: 6px; }
.votes .num { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.votes .lbl { color: var(--muted); font-size: 0.9rem; }

.empty {
  text-align: center; padding: 56px 20px 72px;
  border: 2px dashed var(--line); border-radius: 20px; background: rgba(255, 255, 255, 0.5);
  margin-bottom: 56px;
}
.empty .icon { font-size: 2.6rem; }
.empty h3 { margin: 8px 0 6px; font-size: 1.35rem; }
.empty p { margin: 0 auto 18px; color: var(--muted); max-width: 40ch; }

/* ---------- dialogs ---------- */
dialog {
  border: none; border-radius: 18px; padding: 0;
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  color: var(--ink);
}
dialog::backdrop { background: rgba(15, 16, 22, 0.55); }
.dlg { padding: 24px; }
.dlg h2 { margin: 0 0 4px; font-size: 1.45rem; letter-spacing: -0.02em; }
.dlg .sub { margin: 0 0 18px; color: var(--muted); }
.field { margin-bottom: 14px; }
.field label { display: flex; justify-content: space-between; font-weight: 650; margin-bottom: 6px; }
.field label .ctr { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.field input, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1.5px solid var(--line); background: #fff; font-size: 1rem;
}
.field textarea { min-height: 120px; resize: vertical; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
.field.invalid input, .field.invalid textarea { border-color: var(--danger); }
.field .err { color: var(--danger); font-size: 0.85rem; margin-top: 4px; }
.form-error { background: #fdecea; color: var(--danger); padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; font-weight: 600; }
.actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.warn-box { background: #fdecea; border-left: 4px solid var(--danger); padding: 12px 14px; border-radius: 8px; margin: 12px 0 4px; }

/* ---------- toasts ---------- */
#toasts {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  z-index: 1000; pointer-events: none; width: min(92vw, 460px);
}
.toast {
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px;
  font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  opacity: 0; transform: translateY(8px); transition: opacity 0.25s, transform 0.25s;
  text-align: center;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok { background: var(--voted); }
.toast.error { background: var(--danger); }

/* ---------- admin ---------- */
.admin-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 22px 0 10px; flex-wrap: wrap; }
.admin-top .brand { font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; }
.admin-top .brand span { color: var(--muted); font-weight: 600; }
.admin-top .links { display: flex; gap: 8px; flex-wrap: wrap; }
.login {
  max-width: 400px; margin: 10vh auto 40px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 20px; padding: 28px; box-shadow: var(--shadow);
}
.login h1 { margin: 0 0 4px; font-size: 1.7rem; letter-spacing: -0.02em; }
.login p { margin: 0 0 18px; color: var(--muted); }
.login .btn { width: 100%; }

.status-panel {
  display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 20px 22px; margin: 10px 0 24px; box-shadow: var(--shadow);
}
.status-panel .label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.pill { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.35rem; letter-spacing: -0.01em; }
.pill.open { color: var(--voted); }
.pill.stopped { color: #946200; }
.status-panel .hint { color: var(--muted); font-size: 0.92rem; margin-top: 2px; }
.status-panel .stats { color: var(--muted); font-size: 0.92rem; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .wrap { padding: 0 14px; }
  .hero { flex-direction: column; align-items: stretch; padding: 24px 0 18px; gap: 18px; }
  .hero .btn.big { width: 100%; }
  .qr { display: flex; align-items: center; gap: 12px; padding: 10px; text-align: left; }
  .qr-code { width: 92px; height: 92px; flex: 0 0 auto; }
  .qr figcaption { margin: 0; max-width: none; }
  .board { grid-template-columns: 1fr; gap: 12px; }
  .card-foot { flex-wrap: wrap; }
  .card-foot .btn { flex: 1 1 auto; }
  .board-head .live { margin-left: 0; width: 100%; }
  .status-panel .controls, .status-panel .controls .btn { width: 100%; }
  .dlg { padding: 20px 18px; }
  .actions .btn { flex: 1 1 auto; }
}
@media (min-width: 1400px) {
  .wrap { max-width: 1360px; }
  .qr-code { width: 200px; height: 200px; }
  .qr figcaption { max-width: 200px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
