:root {
  --bg: #12101f;
  --surface: #1d1a30;
  --surface-2: #27233f;
  --line: #36315a;
  --text: #f4f1ff;
  --muted: #a49fc4;
  --accent: #ffd23f;
  --accent-ink: #1a1500;
  --good: #3ddc97;
  --bad: #ff5d73;
  --radius: 16px;
  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --body: 'DM Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 85% -10%, #3b2a7a55, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #ff5d7322, transparent 60%),
    var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--body);
}

a { color: inherit; }
button, input { font: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 760px; margin: 0 auto; padding: 20px 16px;
}
.brand {
  font: 800 1.5rem/1 var(--display); text-decoration: none; letter-spacing: -0.02em; white-space: nowrap;
}
.brand-mark {
  display: inline-grid; place-items: center; width: 1.4em; height: 1.4em; margin-right: 2px;
  background: var(--accent); color: var(--accent-ink); border-radius: 10px; transform: rotate(-6deg);
}
#nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
#nav a, #nav button {
  background: none; border: 0; color: var(--muted); text-decoration: none; cursor: pointer;
  padding: 8px 12px; border-radius: 999px; font-weight: 500;
}
#nav a:hover, #nav button:hover { color: var(--text); background: var(--surface); }
#nav a.active { color: var(--text); background: var(--surface-2); }

main { max-width: 760px; margin: 0 auto; padding: 8px 16px 64px; }

h1, h2, h3 { font-family: var(--display); letter-spacing: -0.02em; line-height: 1.1; margin: 0 0 12px; }
h1 { font-size: clamp(2rem, 6vw, 3.2rem); font-weight: 800; }
h2 { font-size: 1.5rem; font-weight: 700; }
.muted { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.75rem; font-weight: 700; color: var(--accent); margin-bottom: 8px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
}
.stack > * + * { margin-top: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px;
  padding: 14px 22px; font-weight: 700; cursor: pointer; text-decoration: none;
  box-shadow: 0 4px 0 #b8930f; transition: transform .08s, box-shadow .08s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #b8930f; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: var(--surface-2); color: var(--text); box-shadow: 0 4px 0 #15122a; }
.btn.block { width: 100%; }

/* Auth */
.auth { max-width: 420px; margin: 24px auto 0; }
.tabs { display: flex; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 20px; }
.tabs button {
  flex: 1; background: none; border: 0; color: var(--muted); padding: 10px; border-radius: 9px; cursor: pointer; font-weight: 700;
}
.tabs button.on { background: var(--surface); color: var(--text); }
label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: 6px; color: var(--muted); }
input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.error { color: var(--bad); min-height: 1.5em; font-size: .9rem; }

/* Home */
.hero { padding: 16px 0 28px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.stat b { display: block; font: 800 1.6rem/1.1 var(--display); }
.stat span { color: var(--muted); font-size: .8rem; }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, 1fr); } }

.today { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.big-score { font: 800 2.6rem/1 var(--display); color: var(--accent); }

/* Play */
.play-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.pill { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: .8rem; color: var(--muted); }
.pill.easy { color: var(--good); } .pill.medium { color: var(--accent); } .pill.hard { color: var(--bad); }
.timer { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 20px; }
.timer > div { height: 100%; background: var(--accent); transform-origin: left; }
.timer.low > div { background: var(--bad); }
.question { font: 700 clamp(1.3rem, 4vw, 1.8rem)/1.25 var(--display); margin: 8px 0 24px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .choices { grid-template-columns: 1fr; } }
.choice {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  background: var(--surface); color: var(--text); border: 2px solid var(--line); border-radius: 14px;
  padding: 16px; cursor: pointer; font-weight: 500; transition: border-color .1s, background .1s;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice .key {
  flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--surface-2); font-weight: 700; font-size: .85rem;
}
.choice:disabled { cursor: default; }
.choice.right { border-color: var(--good); background: #3ddc9722; }
.choice.wrong { border-color: var(--bad); background: #ff5d7322; }
.choice.dim { opacity: .45; }
.feedback { margin-top: 20px; display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 52px; }
.feedback .pts { font: 800 1.4rem var(--display); }
.feedback .pts.good { color: var(--good); } .feedback .pts.bad { color: var(--bad); }

/* Tables */
.board { width: 100%; border-collapse: collapse; }
.board th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 0 8px 10px; }
.board td { padding: 12px 8px; border-top: 1px solid var(--line); }
.board .num { text-align: right; font-variant-numeric: tabular-nums; }
.board tr.me td { background: #ffd23f14; }
.board .rank { width: 44px; font: 800 1.1rem var(--display); color: var(--muted); }
.board tr:nth-child(1) .rank { color: var(--accent); }
.board-wrap { overflow-x: auto; }
@media (max-width: 560px) { .hide-sm { display: none; } }

/* Review */
.review-item { border-left: 4px solid var(--line); padding: 4px 0 4px 16px; }
.review-item.got { border-left-color: var(--good); }
.review-item.none { border-left-color: var(--bad); }
.review-item p { margin: 4px 0; }

.center { text-align: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 48px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 0s !important; } }

/* Name-it (rarity) questions */
.small { font-size: .85rem; }
.pill.rarity { color: #c9a7ff; }
.guess { display: flex; gap: 10px; }
.guess input { font-size: 1.15rem; padding: 14px 16px; }
.guess input { flex: 1; min-width: 0; }
.tier { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; background: var(--surface-2); }
.tier.t1 { color: var(--muted); }
.tier.t2 { color: var(--good); background: #3ddc9718; }
.tier.t3 { color: #6cb8ff; background: #6cb8ff18; }
.tier.t4 { color: #c9a7ff; background: #c9a7ff22; }
.feedback .small { margin-top: 4px; }
.answer-list { margin: 8px 0; padding-left: 22px; }
.answer-list li { padding: 3px 0; }
.answer-list li > span:first-child { margin-right: 8px; }
.answer-list li.mine > span:first-child { color: var(--accent); font-weight: 700; }
.answer-list li.mine > span:first-child::after { content: ' ← you'; font-weight: 500; font-size: .8rem; }
details summary { cursor: pointer; }

/* Admin */
.admin-tabs { flex-wrap: wrap; gap: 2px; }
.tabs a { flex: 1; text-align: center; text-decoration: none; color: var(--muted); padding: 10px; border-radius: 9px; font-weight: 700; white-space: nowrap; }
.tabs a.on { background: var(--surface); color: var(--text); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.row.end { justify-content: flex-end; }
#panel > .row:first-child { margin-bottom: 16px; }
label.inline { margin: 0; }
input[type=date], input.narrow { width: auto; }
input.narrow { width: 90px; text-align: right; }
select, textarea {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9rem; resize: vertical; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: .85em; }
.btn.small { padding: 8px 14px; font-size: .85rem; border-radius: 10px; box-shadow: 0 3px 0 #b8930f; }
.btn.small.ghost { box-shadow: 0 3px 0 #15122a; }
.btn.danger { background: #3a1822; color: var(--bad); box-shadow: 0 3px 0 #1e0c12; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 560px) { .grid3 { grid-template-columns: 1fr; } }
.seg { display: flex; gap: 16px; flex-wrap: wrap; }
.seg label, label.check { display: flex; align-items: center; gap: 8px; color: var(--text); margin: 0; }
.seg input, label.check input { width: auto; accent-color: var(--accent); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: .75rem; font-weight: 700; background: var(--surface-2); }
.badge.rarity { color: #c9a7ff; } .badge.choice { color: #6cb8ff; }
.badge.sched { color: var(--accent); } .badge.used { color: var(--muted); } .badge.bank { color: var(--good); }
.q-card { padding: 18px; }
.q-text { font-weight: 700; margin: 10px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.opts { margin: 0; padding-left: 18px; color: var(--muted); }
.opts li.right { color: var(--good); font-weight: 700; }
.swap { position: relative; }
.swap summary { list-style: none; }
.swap summary::-webkit-details-marker { display: none; }
.swap-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 5; width: min(340px, 80vw);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  display: grid; gap: 10px; box-shadow: 0 12px 30px #0008;
}
.warn { color: var(--accent); margin: 0; }
dialog { color: var(--text); max-width: 420px; width: calc(100% - 32px); }
dialog::backdrop { background: #000a; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--good); color: #062014; padding: 10px 18px; border-radius: 999px; font-weight: 700; transition: .2s;
}
.toast.bad { background: var(--bad); color: #2a0008; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Typed-answer rounds */
.question.big { font-size: clamp(1.6rem, 5vw, 2.4rem); margin: 16px 0 28px; }
.misses { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; min-height: 8px; }
.miss { padding: 3px 10px; border-radius: 999px; background: #ff5d7318; color: var(--bad); text-decoration: line-through; font-size: .85rem; }
.locked { font: 700 1.3rem var(--display); margin-bottom: 4px; }
.shake { animation: shake .35s; border-color: var(--bad); }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.warn-card { border-color: #ffd23f55; margin-bottom: 16px; }
.review-item.card { border-left-width: 4px; padding: 18px 20px; }

/* Tiers, final round, share card, head to head */
.tier.t0 { color: var(--bad); background: #ff5d7318; }
.tier.t5 { color: #e0b3ff; background: #b45cff33; }
.final-banner {
  text-align: center; font: 800 .85rem var(--display); letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent-ink); background: linear-gradient(90deg, #ffd23f, #ff9f43); border-radius: 10px; padding: 8px; margin-bottom: 12px;
}
.share pre { margin: 0 0 14px; font: 600 1.05rem/1.6 var(--body); white-space: pre-wrap; }
.h2h th, .h2h td { padding-left: 6px; padding-right: 6px; }
.h2h td .tier { min-width: 44px; text-align: center; }
.everyone { list-style: none; margin: 8px 0; padding: 0; }
.everyone li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); }
.everyone li:first-child { border-top: 0; }
.everyone .who { width: 96px; flex: none; color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; }
.everyone li > span:nth-child(2) { flex: 1; }
.everyone li.mine .who { color: var(--accent); font-weight: 700; }

/* Header, account menu and phone tab bar */
.topbar { padding-top: max(20px, env(safe-area-inset-top)); }
.brand { display: inline-flex; align-items: center; flex: none; }
#account { flex: none; }
.account { position: relative; }
.account summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 10px 4px 4px; border-radius: 999px; color: var(--muted); }
.account summary::-webkit-details-marker { display: none; }
.account summary:hover, .account[open] summary { background: var(--surface); color: var(--text); }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); color: var(--accent); font: 800 .95rem var(--display); }
.account-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; min-width: 200px; display: grid; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; box-shadow: 0 12px 30px #0008;
}
.tabbar { display: none; }

@media (max-width: 640px) {
  .topbar { padding-bottom: 8px; }
  .brand { font-size: 1.35rem; }
  #nav { display: none; }
  .account .who { display: none; }
  .account summary { padding: 2px; }
  .avatar { width: 36px; height: 36px; }

  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); padding: 6px 8px max(8px, env(safe-area-inset-bottom));
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 4px;
    color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 700; border-radius: 12px;
  }
  .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar a.active { color: var(--accent); }
  .tabbar a.active svg { stroke-width: 2.2; }
  body.has-tabbar main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

  main { padding-top: 0; }
  .hero { padding: 8px 0 20px; }
  .card { padding: 18px; }
  .today .btn { flex: 1; padding: 14px 10px; white-space: nowrap; }
  .today > div:last-child { width: 100%; }
  .stats { gap: 10px; }
  .stat { padding: 12px 14px; }
  .question.big { margin: 12px 0 20px; }
  .play-head { flex-wrap: wrap; gap: 6px; }
  .feedback { flex-wrap: wrap; }
  .feedback .btn { width: 100%; }
  .admin-tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .admin-tabs a { flex: none; padding: 10px 12px; }
  .toast { bottom: calc(90px + env(safe-area-inset-bottom)); }
}
#nav { margin-left: auto; }
