:root {
  --bg-0: #070a16;
  --bg-1: #0b1020;
  --panel: #141a30;
  --ink: #eef1ff;
  --ink-dim: #8b93b8;
  --line: #232a47;
  --accent: #00d3ff;
  --shadow: 0 14px 50px rgba(0, 0, 0, 0.55);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; height: 100dvh; overflow: hidden;
  background: var(--bg-0); color: var(--ink); font-family: var(--font);
  user-select: none; -webkit-user-select: none; touch-action: none;
}
body {
  background:
    radial-gradient(120% 70% at 50% -10%, #16224a 0%, rgba(22,34,74,0) 55%),
    radial-gradient(90% 60% at 50% 115%, #1a1140 0%, rgba(26,17,64,0) 60%),
    var(--bg-0);
}
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 560px; margin: 0 auto; padding: env(safe-area-inset-top) 10px env(safe-area-inset-bottom); }

/* header */
#topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 10px 2px 6px; gap: 8px; }
.hub-link { justify-self: start; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; color: var(--ink-dim); }
.hub-link:hover { background: var(--panel); color: var(--ink); }
.hub-link svg { width: 22px; height: 22px; fill: currentColor; }
.scores { display: flex; gap: 8px; }
.score-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 5px 16px; text-align: center; min-width: 78px; }
.score-box .lbl { display: block; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-dim); }
.score-box { position: relative; transition: box-shadow .25s, border-color .25s; }
.score-box .val { display: block; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; transition: color .25s; }
.score-box.best .val { color: var(--accent); }
/* live "in record territory" gold state: current score has met/passed best */
.score-box.record { border-color: rgba(255,210,63,.55); box-shadow: 0 0 18px rgba(255,210,63,.32); }
.score-box.record .val { color: #ffd23f; }
.score-box.record::after {
  content: "👑"; position: absolute; top: -10px; right: -6px; font-size: 15px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); animation: crownPop .3s cubic-bezier(.2,.9,.3,1.4);
}
@keyframes crownPop { from { transform: scale(0) rotate(-25deg); opacity: 0; } }
.topbar-right { justify-self: end; display: flex; gap: 2px; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-dim); cursor: pointer; transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--panel); color: var(--ink); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.ic-off { display: none; }
body.muted .ic-on { display: none; }
body.muted .ic-off { display: block; }

/* stage */
#stage { position: relative; flex: 1 1 auto; min-height: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#toast {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%) translateY(-8px);
  background: var(--ink); color: #11111c; font-weight: 700; font-size: 14px;
  padding: 9px 15px; border-radius: 8px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* overlays */
.scrim { position: fixed; inset: 0; background: rgba(4,6,16,.7); backdrop-filter: blur(7px); display: grid; place-items: center; z-index: 20; padding: 16px; animation: fade .2s ease; }
.scrim[hidden] { display: none; }
.card { width: 100%; max-width: 360px; background: linear-gradient(180deg, var(--panel), var(--bg-1)); border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px; text-align: center; box-shadow: var(--shadow); animation: pop .22s cubic-bezier(.2,.9,.3,1.2); }
.card h2 { margin: 0 0 18px; font-size: 17px; letter-spacing: .12em; text-transform: uppercase; }
.final { display: flex; justify-content: center; gap: 28px; margin-bottom: 8px; }
.final .lbl { display: block; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-dim); }
.final .big { display: block; font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; }
.final .big#final-best { color: var(--accent); }
.newbest { color: #ffd23f; font-weight: 700; margin: 4px 0 0; }
.btn-primary { display: block; width: 100%; margin: 20px 0 10px; border: 0; border-radius: 12px; padding: 15px; font: inherit; font-size: 16px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: #04121a; cursor: pointer; background: linear-gradient(180deg, #38e0ff, #00a7d6); box-shadow: 0 0 24px rgba(0,211,255,.35); transition: transform .06s, filter .15s; }
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:active { transform: scale(.97); }
.btn-ghost { display: inline-block; color: var(--ink-dim); text-decoration: none; font-size: 14px; font-weight: 600; padding: 8px; }
.btn-ghost:hover { color: var(--ink); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.96); } }
