:root {
  --bg: #0d1117;
  --bg2: #131a24;
  --panel: #161f2c;
  --line: #243041;
  --ink: #e8edf4;
  --muted: #8b98ab;
  --brass: #e8b04b;
  --brass-2: #f5cf83;
  --good: #4fd18b;
  --bad: #ff6b6b;
  --info: #6cb4ff;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #1b2638 0%, transparent 60%), var(--bg);
  color: var(--ink); font: 16px/1.5 var(--sans); min-height: 100vh;
  display: flex; flex-direction: column;
}
main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 16px; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }

/* top bar */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px;
  border-bottom: 1px solid var(--line); background: rgba(13,17,23,.8); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5; }
.brand { display: flex; gap: 10px; align-items: center; color: var(--ink); text-decoration: none;
  font: 600 20px var(--serif); letter-spacing: .3px; }
.brand svg { width: 28px; height: 28px; color: var(--brass); }
.brand b { color: var(--brass); font-weight: 600; }
.me { display: flex; gap: 10px; align-items: center; font-size: 14px; }
.me-name { font-weight: 600; }
.me-level { color: var(--muted); }
.me-score { background: var(--brass); color: #1a1205; font-weight: 700; padding: 3px 10px; border-radius: 99px;
  font-variant-numeric: tabular-nums; }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--bg2); padding: 10px 18px; border-radius: 10px;
  transition: transform .08s, background .15s, border-color .15s; }
.btn:hover { border-color: #3a4a60; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brass); color: #1a1205; border-color: var(--brass); font-weight: 700; }
.btn.primary:hover { background: var(--brass-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

/* welcome */
.hero { max-width: 680px; margin: 8vh auto 0; }
.eyebrow { color: var(--brass); text-transform: uppercase; letter-spacing: .18em; font-size: 12px; font-weight: 600; }
.hero h1 { font: 500 clamp(34px, 6vw, 56px)/1.08 var(--serif); margin: 10px 0 18px; }
.hero h1 em { color: var(--brass); }
.lede { color: var(--muted); font-size: 18px; }
.name-form { margin-top: 32px; }
.name-form label { display: block; font-weight: 600; margin-bottom: 8px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row input { flex: 1; min-width: 200px; }
.err { color: var(--bad); min-height: 1.5em; }
.field, .row input, .play input[type=text] {
  background: var(--bg); border: 1px solid var(--line); color: var(--ink);
  padding: 12px 14px; border-radius: 10px; outline: none; }
.row input:focus, .play input:focus { border-color: var(--brass); }

/* panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.grid-home { display: grid; gap: 16px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 900px) {
  .grid-home { grid-template-columns: 360px 1fr; }
  .grid-home .picker { grid-row: span 2; grid-column: 2; grid-row-start: 1; }
}
h2 { font: 500 22px var(--serif); margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* stats */
.stats { display: flex; gap: 18px; align-items: center; }
.level-ring { --p: 0; width: 96px; height: 96px; flex: none; border-radius: 50%; display: grid; place-content: center;
  text-align: center; background: conic-gradient(var(--brass) calc(var(--p) * 1%), var(--line) 0);
  position: relative; }
.level-ring::before { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--panel); }
.level-ring span, .level-ring small { position: relative; }
.level-ring span { font: 600 32px/1 var(--serif); }
.level-ring small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }
.stats-body { flex: 1; min-width: 0; }
.bar { height: 6px; background: var(--line); border-radius: 9px; overflow: hidden; margin: 6px 0; }
.bar div { height: 100%; width: 0; background: var(--brass); transition: width .5s; }
.kv { list-style: none; padding: 0; margin: 12px 0 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.kv li { display: flex; flex-direction: column; }
.kv b { font-size: 20px; font-variant-numeric: tabular-nums; }
.kv span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }

/* picker */
.picker-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.diff { display: flex; gap: 6px; }
.diff button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); font-weight: 700; }
.diff button[aria-checked=true] { background: var(--brass); color: #1a1205; border-color: var(--brass); }
.diff button:disabled { opacity: .35; }
.types { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.type-card { text-align: left; border: 1px solid var(--line); background: var(--bg2); border-radius: 12px; padding: 16px;
  display: flex; flex-direction: column; gap: 6px; transition: border-color .15s, transform .15s; }
.type-card:hover { border-color: var(--brass); transform: translateY(-2px); }
.type-card .icon { font-size: 26px; }
.type-card h3 { margin: 0; font: 600 17px var(--serif); }
.type-card p { margin: 0; color: var(--muted); font-size: 14px; }
.type-card .count { color: var(--brass); font-size: 12px; font-weight: 600; margin-top: auto; }

/* tabs & achievements */
.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tab { background: none; border: 0; padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--ink); border-color: var(--brass); }
.ach-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); max-height: 440px; overflow: auto; }
.ach { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--bg2); opacity: .45; filter: grayscale(1); }
.ach.got { opacity: 1; filter: none; }
.ach.got.gold { border-color: #b48a32; }
.ach.got.legend { border-color: #b77bff; box-shadow: 0 0 0 1px #b77bff55 inset; }
.ach .ai { font-size: 22px; }
.ach b { display: block; font-size: 14px; }
.ach small { color: var(--muted); font-size: 12px; line-height: 1.3; display: block; }
.lb { list-style: none; padding: 0; margin: 0; max-height: 440px; overflow: auto; }
.lb li { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; padding: 8px 6px; border-bottom: 1px solid var(--line); align-items: center; }
.lb li.me { background: #e8b04b14; }
.lb .rk { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.lb li:nth-child(-n+3) .rk { color: var(--brass); font-weight: 700; }
.lb .nm small { color: var(--muted); }
.lb .sc { font-weight: 700; font-variant-numeric: tabular-nums; }

/* play */
.play-head, .play-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 12px; }
.play-meta { display: flex; gap: 10px; align-items: center; font: 600 18px var(--serif); }
.pips { color: var(--brass); letter-spacing: 2px; font-size: 14px; }
.timer { font: 600 18px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.play { min-height: 380px; display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; padding: 28px 18px; }
.prompt { font: 500 22px var(--serif); margin: 0; }
.sub { color: var(--muted); margin: -8px 0 0; max-width: 560px; }
.answer-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; width: 100%; max-width: 520px; }
.answer-row input { flex: 1; min-width: 160px; font-size: 18px; }
.hint { background: #6cb4ff14; border: 1px solid #6cb4ff44; color: #bfe0ff; padding: 10px 14px; border-radius: 10px; max-width: 560px; }
.msg { min-height: 1.5em; color: var(--bad); }

.terms { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.term { min-width: 64px; padding: 14px 10px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line);
  font: 600 22px var(--mono); font-variant-numeric: tabular-nums; }
.term.q { border-style: dashed; border-color: var(--brass); color: var(--brass); }

.cipher { font: 600 clamp(22px, 4.5vw, 36px) var(--mono); letter-spacing: .2em; color: var(--brass-2);
  background: var(--bg); border: 1px solid var(--line); padding: 18px 22px; border-radius: 12px; word-break: break-word; }
.method { font-weight: 700; color: var(--brass); text-transform: uppercase; letter-spacing: .12em; font-size: 13px; }

/* code breaker */
.code-board { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 440px; }
.code-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 6px 10px; border-radius: 10px; background: var(--bg2); }
.pegs { display: flex; gap: 6px; }
.peg { width: 34px; height: 34px; border-radius: 50%; border: 2px solid #0007; display: grid; place-content: center;
  font: 700 12px var(--mono); color: #0009; }
.peg.empty { background: var(--bg); border: 2px dashed var(--line); color: var(--muted); }
.fb { display: flex; gap: 10px; font: 600 14px var(--mono); }
.fb .ex { color: var(--good); }
.fb .cl { color: var(--brass); }
.palette { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.palette .peg { width: 42px; height: 42px; cursor: pointer; }
.slots .peg { width: 44px; height: 44px; cursor: pointer; }
.c0 { background: #ff6b6b; } .c1 { background: #ffd166; } .c2 { background: #4fd18b; } .c3 { background: #6cb4ff; }
.c4 { background: #c38bff; } .c5 { background: #ff9f5a; } .c6 { background: #f2f2f2; } .c7 { background: #5ce1e6; }

/* target */
.target-num { font: 600 64px/1 var(--serif); color: var(--brass); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.chip { min-width: 52px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); font: 700 20px var(--mono); }
.chip.op { color: var(--brass); min-width: 44px; }

/* lights */
.lights { display: grid; gap: 6px; }
.light { width: min(13vw, 64px); height: min(13vw, 64px); border-radius: 12px; border: 1px solid var(--line); background: #0b0f15; transition: background .12s, box-shadow .12s; }
.light.on { background: var(--brass); box-shadow: 0 0 18px #e8b04b88; border-color: var(--brass-2); }

/* result */
.result h3 { font: 500 32px var(--serif); margin: 0; }
.result.win h3 { color: var(--good); }
.result.lose h3 { color: var(--bad); }
.points { font: 700 48px var(--serif); color: var(--brass); }
.reveal { font-family: var(--mono); background: var(--bg); padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); }
.new-ach { display: flex; flex-direction: column; gap: 8px; }
.new-ach div { background: #e8b04b18; border: 1px solid #e8b04b55; padding: 8px 14px; border-radius: 10px; }

/* toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 10px; z-index: 20; max-width: min(360px, calc(100vw - 32px)); }
.toast { background: var(--panel); border: 1px solid var(--brass); border-radius: 12px; padding: 12px 16px; box-shadow: 0 10px 30px #0008;
  animation: pop .35s cubic-bezier(.2,1.4,.4,1); }
.toast.err { border-color: var(--bad); }
.toast b { display: block; color: var(--brass); }
@keyframes pop { from { transform: translateY(20px) scale(.9); opacity: 0; } }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 18px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (max-width: 560px) {
  .me-level { display: none; }
  .me-name { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar { padding: 12px 16px; }
}
