:root {
  --bg: #0b0b0f; --surface: #16161d; --surface-2: #1f1f29; --line: #2a2a38;
  --text: #f4f1fa; --muted: #a39fb3; --glow: #22163f;
  --primary: #8152f2; --primary-hi: #a78bfa; --primary-dim: #3b2a66; --on-primary: #ffffff;
  --accent: #f5c542; --accent-dim: #6b5520; --on-accent: #1b1404;
  --danger: #f05252; --danger-dim: #5c1d1d; --correct: #f5c542; --correct-dim: #6b5520;
  --radius: 16px; --display: "Unbounded", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, var(--glow) 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text); font: 16px/1.45 Inter, system-ui, -apple-system, sans-serif;
  min-height: 100dvh; -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
a { color: var(--primary-hi); }
button, input { font: inherit; color: inherit; }
.wrap { max-width: 640px; margin: 0 auto; padding: 8px 16px calc(32px + env(safe-area-inset-bottom)); }

.topbar { max-width: 640px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; padding: calc(12px + env(safe-area-inset-top)) 16px 8px; }
.brand { font-family: var(--display); font-weight: 800; letter-spacing: .04em; color: var(--text); text-decoration: none; font-size: 18px; }
.brand span { color: var(--accent); margin-left: 4px; }
.chip { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 14px; color: var(--muted); }
.chip b { color: var(--accent); }

h1, h2 { font-family: var(--display); font-weight: 800; margin: 16px 0 12px; line-height: 1.15; }
h1 { font-size: clamp(26px, 7vw, 36px); }
h2 { font-size: 20px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 0; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 52px; padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-weight: 700; cursor: pointer; text-decoration: none;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:focus-visible, .key:focus-visible, .answer:focus-visible { outline: 3px solid var(--primary-hi); outline-offset: 2px; }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: transparent; box-shadow: 0 8px 30px -10px var(--primary); font-family: var(--display); letter-spacing: .03em; min-height: 60px; font-size: 18px; }
.btn.gold { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger-dim); }
.btn.small { min-height: 44px; width: auto; padding: 8px 14px; font-size: 14px; }
.link { background: none; border: none; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 12px; min-height: 44px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

/* who */
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.players .btn { min-height: 72px; font-size: 18px; }

/* pin */
.dots { display: flex; justify-content: center; gap: 16px; margin: 24px 0; }
.dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--primary-hi); }
.dots i.on { background: var(--primary-hi); box-shadow: 0 0 12px var(--primary); }
.dots.shake { animation: shake .35s; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 320px; margin: 0 auto; }
.key { min-height: 64px; border-radius: 50%; aspect-ratio: 1; background: var(--surface); border: 1px solid var(--line); font-size: 24px; font-weight: 600; cursor: pointer; }
.key:active { background: var(--primary-dim); }
.key.blank { visibility: hidden; }
.msg { min-height: 24px; text-align: center; font-weight: 600; }
.msg.err { color: var(--danger); }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* home */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { text-align: center; }
.stat b { display: block; font-family: var(--display); font-size: 28px; color: var(--accent); }
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.cat { min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; padding: 8px; }
.cat[aria-pressed="true"] { border-color: var(--primary-hi); background: var(--primary-dim); }

/* quiz */
.qhead { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-weight: 600; margin-top: 8px; }
.qhead .score { color: var(--accent); }
.timer { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 12px 0 16px; }
.timer > i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-hi)); transform-origin: left; }
.timer.low > i { background: var(--danger); }
.cover { display: block; width: min(260px, 70vw); aspect-ratio: 1; object-fit: cover; margin: 0 auto 16px; border-radius: 12px; box-shadow: 0 12px 40px -12px #000, 0 0 0 1px var(--line); }
.question { font-size: clamp(20px, 5.4vw, 24px); font-weight: 700; margin: 0 0 16px; }
.answers { display: grid; gap: 10px; }
.answer { text-align: left; min-height: 56px; padding: 12px 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 17px; transition: border-color .15s, background .15s; }
.answer:disabled { cursor: default; }
.answer.correct { border-color: var(--correct); background: var(--correct-dim); color: var(--text); }
.answer.correct::after { content: " ✓"; }
.answer.wrong::after { content: " ✗"; }
.answer.wrong { border-color: var(--danger); background: var(--danger-dim); }
.answer.dim { opacity: .5; }
.feedback { margin-top: 16px; }
.verdict { font-family: var(--display); font-size: 20px; }
.verdict.good { color: var(--correct); }
.verdict.bad { color: var(--danger); }
.dyk { color: var(--muted); }
.dyk b { color: var(--primary-hi); }

/* summary */
.big { font-family: var(--display); font-size: clamp(48px, 16vw, 72px); color: var(--accent); text-shadow: 0 0 30px color-mix(in srgb, var(--accent) 35%, transparent); margin: 8px 0; }
.unlocks { display: grid; gap: 10px; }
.unlock { display: flex; gap: 12px; align-items: center; border-color: var(--accent); opacity: 0; animation: pop .5s cubic-bezier(.2,1.6,.4,1) forwards; }
@keyframes pop { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: none; } }

/* leaderboard */
.lb { width: 100%; border-collapse: collapse; }
.lb th { text-align: left; color: var(--muted); font-size: 13px; font-weight: 600; padding: 8px; }
.lb td { padding: 12px 8px; border-top: 1px solid var(--line); }
.lb tr[data-id] { cursor: pointer; }
.lb tr.me td { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.lb .pts { color: var(--accent); font-weight: 700; }
.lb .num { text-align: right; white-space: nowrap; }

/* badges */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.badge { border-radius: 14px; padding: 14px 12px; border: 1px solid var(--primary-dim); background: color-mix(in srgb, var(--primary-dim) 40%, transparent); color: var(--muted); }
.badge .ico { font-size: 26px; filter: grayscale(1); opacity: .5; }
.badge .nm { font-weight: 700; margin: 6px 0 2px; }
.badge .ds { font-size: 13px; }
.badge.earned { border-color: var(--accent); background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 18%, transparent), color-mix(in srgb, var(--accent) 4%, transparent)); color: var(--text); box-shadow: 0 0 24px -8px color-mix(in srgb, var(--accent) 60%, transparent); }
.badge.earned .ico { filter: none; opacity: 1; }
.badge.earned .nm { color: var(--accent); }

/* admin */
.field { display: grid; gap: 6px; }
.field input { min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); font-size: 16px; }
.plist { display: grid; gap: 8px; }
.plist .card { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.plist .card > span { flex: 1 1 120px; font-weight: 700; }

.toasts { position: fixed; left: 0; right: 0; bottom: calc(16px + env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; max-width: 480px; }
.toast.err { border-color: var(--danger); }
.spinner { text-align: center; color: var(--muted); padding: 48px 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition: none !important; }
  .unlock { opacity: 1; }
}

/* easy mode */
.toggle { display: flex; gap: 14px; align-items: center; cursor: pointer; }
.toggle input { width: 26px; height: 26px; accent-color: var(--primary); flex: none; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--primary-dim); color: var(--text); vertical-align: 1px; }

/* leaderboard tabs */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px; margin-bottom: 12px; }
.tab { min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 700; cursor: pointer; }
.tab[aria-selected="true"] { background: var(--primary-dim); color: var(--text); }
.lb tr.unranked td { opacity: .55; }
.lb .sub { font-size: 12px; color: var(--muted); }

/* appearance settings */
.topbar .right { display: flex; gap: 8px; align-items: center; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 20px; cursor: pointer; }
dialog.settings { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; width: min(420px, calc(100vw - 32px)); }
dialog.settings::backdrop { background: rgb(0 0 0 / .55); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--surface-2); border-radius: 12px; padding: 4px; }
.seg button { min-height: 44px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 700; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }
.swatches { display: flex; gap: 8px; align-items: center; }
.swatches i { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); }

/* personal best */
.best-banner { font-family: var(--display); font-size: 22px; color: var(--accent); margin: 16px 0 0; animation: pop .6s cubic-bezier(.2,1.6,.4,1) both; }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti i { position: absolute; top: -16px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate(var(--drift), 105vh) rotate(var(--spin)); opacity: .9; } }

/* invites */
.invite-link { width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-size: 14px; }
.badge .prog { height: 6px; border-radius: 99px; background: var(--surface-2); margin-top: 10px; overflow: hidden; }
.badge .prog span { display: block; height: 100%; border-radius: inherit; background: var(--primary); }
.badge .prog-n { font-size: 12px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.badge.hidden-secret .nm { color: var(--primary-hi); }
.badge.hidden-secret { border-style: dashed; }
