:root {
  --bg: #0b1020;
  --panel: rgba(14, 20, 40, 0.86);
  --panel-solid: #121a33;
  --line: rgba(153, 246, 228, 0.18);
  --text: #eef3ff;
  --muted: #9aa8c8;
  --teal: #5eead4;
  --teal-deep: #0f766e;
  --pink: #f472b6;
  --display: 'Unbounded', 'Arial Black', sans-serif;
  --body: 'Figtree', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--body); }
canvas#game { position: fixed; inset: 0; display: block; }
button { font-family: var(--body); color: inherit; }
button:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

/* ---------- setup ---------- */
.setup { position: fixed; inset: 0; display: flex; align-items: center; justify-content: flex-end; padding: 24px; background: linear-gradient(90deg, rgba(11, 16, 32, 0) 30%, rgba(11, 16, 32, 0.7) 58%); }
.setup[hidden] { display: none; }
.panel { width: min(520px, 100%); max-height: 100%; overflow-y: auto; padding: 22px 24px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover, .back:focus-visible { color: var(--text); }
h1 { margin: 2px 0 0; font-family: var(--display); font-weight: 800; font-size: 54px; line-height: 1; letter-spacing: -0.02em; }
h1 span { color: var(--teal); }
.tagline { margin: 0 0 4px; color: var(--muted); font-size: 16px; }
.panel h2 { margin: 8px 0 0; font-size: 12px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.preset { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; border-radius: 12px; border: 2px solid transparent; background: rgba(255, 255, 255, 0.05); text-align: left; cursor: pointer; min-width: 0; }
.preset:hover { background: rgba(255, 255, 255, 0.09); }
.preset[aria-pressed="true"] { border-color: var(--teal); background: rgba(94, 234, 212, 0.1); }
.preset b { font-family: var(--display); font-weight: 700; font-size: 14px; }
.preset span { font-size: 13px; color: var(--teal); font-variant-numeric: tabular-nums; }
.preset small { font-size: 12.5px; color: var(--muted); line-height: 1.3; }
.custom { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stepper { display: grid; grid-template-columns: 30px 1fr 30px; grid-template-rows: auto auto; align-items: center; padding: 6px 8px 8px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); }
.stepper span { grid-column: 1 / -1; font-size: 12px; color: var(--muted); text-align: center; }
.stepper b { text-align: center; font-family: var(--display); font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; }
.stepper button { height: 30px; border: 0; border-radius: 8px; background: rgba(255, 255, 255, 0.08); font-size: 18px; cursor: pointer; }
.stepper button:hover { background: rgba(255, 255, 255, 0.16); }
.toggle { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); }
.toggle button { min-height: 36px; border: 0; border-radius: 9px; background: none; color: var(--muted); font-size: 15px; font-weight: 600; cursor: pointer; }
.toggle button[aria-pressed="true"] { background: var(--teal); color: #032622; }
.bottom { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: end; }
.scores ol { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 3px; font-variant-numeric: tabular-nums; }
.scores li { display: grid; grid-template-columns: 18px auto 1fr; gap: 8px; align-items: baseline; font-size: 14px; }
.scores li span { color: var(--muted); }
.scores li small { color: var(--muted); }
.scores li.none { display: block; color: var(--muted); }
.go { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 140px; min-height: 64px; padding: 0 22px; border: 0; border-radius: 14px; background: var(--teal); color: #032622; font-family: var(--display); font-weight: 800; font-size: 22px; cursor: pointer; box-shadow: 0 4px 0 var(--teal-deep); }
.go small { font-family: var(--body); font-size: 12px; font-weight: 700; opacity: 0.7; }
.go:hover { filter: brightness(1.06); }
.keys { margin: 4px 0 0; font-size: 13px; line-height: 1.5; color: var(--muted); }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; }
.hud[hidden] { display: none; }
.left { position: absolute; left: 22px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 10px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
.label { font-size: 11px; font-weight: 700; letter-spacing: 0.16em; color: var(--muted); }
.meter { display: grid; grid-template-rows: repeat(var(--rows, 12), 1fr); gap: 3px; height: min(60vh, 420px); width: 22px; }
.meter i { border-radius: 4px; background: rgba(255, 255, 255, 0.06); }
.meter i.on { background: var(--c); box-shadow: 0 0 8px var(--c); }
.right { position: absolute; right: 22px; top: 22px; width: 230px; display: flex; flex-direction: column; gap: 8px; }
.stat { padding: 8px 14px 10px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); display: flex; flex-direction: column; }
.stat span { font-size: 11px; font-weight: 700; letter-spacing: 0.16em; color: var(--muted); }
.stat b { font-family: var(--display); font-weight: 700; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat.big b { font-size: 32px; color: var(--teal); }
.row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.row .stat { padding: 8px 10px 10px; }
.row .stat b { font-size: 18px; }
.hint { margin: 0; padding: 0 4px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* ---------- overlays ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(11, 16, 32, 0.55); }
.screen[hidden] { display: none; }
.card { width: min(92vw, 400px); padding: 22px 26px; border-radius: 18px; background: var(--panel-solid); border: 1px solid var(--line); text-align: center; display: flex; flex-direction: column; gap: 8px; }
.card h2 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 30px; }
.card p { margin: 0; color: var(--muted); }
.card .final { font-family: var(--display); font-weight: 800; font-size: 44px; color: var(--teal); font-variant-numeric: tabular-nums; }
.card .rank { color: var(--pink); font-weight: 700; min-height: 1.2em; }
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.actions .go { flex-direction: row; justify-content: space-between; min-height: 52px; font-size: 18px; }
.actions button:not(.go) { display: flex; justify-content: space-between; align-items: center; min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); font-size: 16px; font-weight: 600; cursor: pointer; }
.actions button small { color: var(--muted); font-size: 13px; }

@media (max-width: 860px) {
  .setup { justify-content: center; background: rgba(11, 16, 32, 0.55); padding: 14px; }
  .custom { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .right { width: 170px; right: 12px; top: 12px; }
  .left { left: 10px; }
  .hint { display: none; }
}
@media (max-width: 520px) { .presets { grid-template-columns: minmax(0, 1fr); } h1 { font-size: 42px; } .bottom { grid-template-columns: minmax(0, 1fr); } }
