:root {
  --bg: #fdf8ef;
  --surface: #ffffff;
  --ink: #1d1b2c;
  --muted: #5f5b72;
  --line: #e7e1d3;
  --brand: #5b3fd1;
  --brand-ink: #ffffff;
  --brand-soft: #ece7ff;
  --warn: #ffe0b2;
  --warn-ink: #7a4100;
  --danger: #c62828;
  --radius: 16px;
  --shadow: 0 2px 0 rgba(29, 27, 44, 0.06), 0 8px 24px rgba(29, 27, 44, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

[hidden] { display: none !important; }

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-weight: 700;
  border: 2px solid var(--brand);
  background: var(--brand);
  color: var(--brand-ink);
  border-radius: 999px;
  padding: 10px 18px;
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.08); }
.btn:focus-visible, input:focus-visible, .tab:focus-visible { outline: 3px solid #ffb300; outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
.btn.ghost { background: var(--surface); color: var(--brand); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.warn { background: var(--warn); border-color: var(--warn); color: var(--warn-ink); }
.btn.small { padding: 6px 14px; min-height: 36px; font-size: 14px; }
.btn.tiny { padding: 4px 10px; min-height: 36px; min-width: 36px; font-size: 14px; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 24px; color: var(--brand); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.tabs { display: flex; gap: 6px; background: var(--brand-soft); padding: 4px; border-radius: 999px; }
.tab {
  font: inherit; font-weight: 700; font-size: 18px;
  border: 0; border-radius: 999px; padding: 8px 20px; min-height: 44px;
  background: transparent; color: var(--brand); cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--brand); color: var(--brand-ink); }
.tab:disabled { cursor: not-allowed; }

.banner { margin: 0; padding: 10px 24px; background: var(--warn); color: var(--warn-ink); font-weight: 600; }

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr);
  gap: 24px;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.wheel-area { display: flex; flex-direction: column; align-items: center; gap: 16px; min-width: 0; }

.wheel-wrap { position: relative; width: min(100%, 70vh, 620px); aspect-ratio: 1; }
#wheel {
  width: 100%; height: 100%; display: block;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 0 10px var(--brand), 0 12px 40px rgba(91, 63, 209, 0.3);
}
.pointer {
  position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0; z-index: 2;
  border-left: 22px solid transparent; border-right: 22px solid transparent;
  border-top: 44px solid #ff3d00;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.25));
}
.wheel-empty {
  position: absolute; inset: 0; margin: 0;
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 20%; font-size: 22px; font-weight: 700; color: var(--muted);
}

.btn.spin {
  font-size: 32px; letter-spacing: 2px;
  padding: 16px 56px; min-height: 72px;
  background: #ff3d00; border-color: #ff3d00;
  box-shadow: 0 6px 0 #b32b00;
}
.btn.spin:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 #b32b00; }

.cooldown { text-align: center; }
.cooldown h2 { font-size: 15px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-weight: 600; color: var(--muted); }

/* ---------- side panels ---------- */

.side { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel h2 { font-size: 20px; margin-bottom: 12px; }
.count { font-size: 15px; font-weight: 500; color: var(--muted); }

.add-form { display: flex; gap: 8px; }
.add-form input, .dialog-body input[type="text"], .dialog-body input[type="password"] {
  flex: 1; min-width: 0;
  font: inherit; font-size: 17px;
  padding: 10px 14px; min-height: 44px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
.form-msg { min-height: 1.4em; margin: 6px 2px; color: var(--muted); font-size: 14px; }

.roster { list-style: none; margin: 0; padding: 0; max-height: 52vh; overflow-y: auto; }
.student { display: flex; align-items: center; gap: 6px; padding: 6px 2px; border-bottom: 1px solid var(--line); }
.student:last-child { border-bottom: 0; }
.student-name { flex: 1; min-width: 0; font-weight: 600; font-size: 17px; overflow-wrap: anywhere; }
.student.absent .student-name { color: var(--muted); text-decoration: line-through; }
.picks { font-size: 14px; color: var(--muted); white-space: nowrap; }
.tag { font-size: 13px; background: var(--warn); color: var(--warn-ink); border-radius: 999px; padding: 2px 8px; }
.empty { color: var(--muted); padding: 8px 2px; list-style: none; }
.locked-note { color: var(--muted); font-size: 14px; margin: 10px 0 0; }

.history { margin: 0; padding-left: 22px; }
.history li { padding: 4px 0; font-weight: 600; }
.history li.empty { padding-left: 0; margin-left: -22px; font-weight: 400; }
.history .when { color: var(--muted); font-weight: 400; font-size: 14px; margin-left: 8px; }

/* ---------- winner ---------- */

.winner {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(29, 27, 44, 0.55);
}
.winner-card {
  background: var(--surface); border-radius: 28px; padding: 40px 48px; text-align: center;
  max-width: 92vw; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: pop 0.45s cubic-bezier(.2, 1.6, .4, 1);
}
.winner-label { margin: 0; font-size: 22px; color: var(--muted); font-weight: 600; }
.winner-name { margin: 12px 0 28px; font-size: clamp(48px, 10vw, 110px); font-weight: 800; color: var(--brand); line-height: 1.05; overflow-wrap: anywhere; }
.winner-card .btn { font-size: 22px; padding: 12px 36px; }

@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .winner-card { animation: none; } }

/* ---------- dialogs ---------- */

dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(520px, calc(100vw - 32px));
  color: var(--ink); background: var(--surface); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(29, 27, 44, 0.5); }
.dialog-body { padding: 24px; display: flex; flex-direction: column; gap: 10px; max-height: 85vh; overflow-y: auto; }
.dialog-body h2 { font-size: 22px; }
.dialog-body h3 { font-size: 16px; margin-top: 10px; }
.dialog-body label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 8px; }
.privacy { margin: 12px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--brand-soft); font-size: 14px; }

/* ---------- small screens ---------- */

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; gap: 16px; }
  .topbar { padding: 10px 16px; }
  .topbar-actions { margin-left: 0; }
  .wheel-wrap { width: min(100%, 60vh); }
  .btn.spin { font-size: 26px; padding: 12px 40px; min-height: 60px; }
  .roster { max-height: none; }
}
