:root {
  --bg1: #1d2733; --bg2: #0f151c; --ink: #eef3f7; --mute: #9fb0c0; --panel: rgba(16, 24, 33, 0.9);
  --line: rgba(159, 211, 224, 0.22); --accent: #8fe3ff; --good: #5ee6a8; --close: #ffc857; --miss: #ff6b6b; --gold: #ffd166;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: radial-gradient(ellipse at 50% 40%, var(--bg1) 0%, #16202a 55%, var(--bg2) 100%);
  color: var(--ink); font: 15px/1.4 Manrope, system-ui, -apple-system, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
[hidden] { display: none !important; }
.screen { position: fixed; inset: 0; z-index: 20; padding: calc(16px + var(--sat)) 16px calc(16px + var(--sab)); }
.center { display: flex; align-items: center; justify-content: center; }
.dim { background: rgba(8, 12, 16, 0.6); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 24px; width: min(440px, 100%); max-height: 100%; overflow: auto; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.45); backdrop-filter: blur(8px); }
.panel.small { width: min(380px, 100%); font-size: 14px; text-align: left; }
.panel.small h2 { text-align: center; }
#title { background: linear-gradient(180deg, rgba(15,21,28,0) 30%, rgba(15,21,28,.75) 100%); align-items: flex-end; }
#title .panel { background: rgba(16,24,33,.72); margin-bottom: 4vh; }
h1 { font-size: 44px; font-weight: 800; letter-spacing: -0.02em; margin: 0; }
h2 { margin: 0 0 12px; font-size: 24px; }
.tag { color: var(--accent); font-weight: 600; margin: 4px 0 2px; font-size: 18px; }
.sub { color: var(--mute); margin: 0 0 16px; }
a { color: var(--accent); }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.btn { font: inherit; font-weight: 600; color: var(--ink); background: rgba(255,255,255,.07); border: 1px solid var(--line); border-radius: 12px; min-height: 44px; min-width: 44px; padding: 8px 16px; cursor: pointer; touch-action: manipulation; }
.btn:hover { background: rgba(255,255,255,.13); }
.btn:focus-visible, .tray:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: linear-gradient(180deg, #57c7e8, #2b8fb3); border-color: transparent; color: #04121a; }
.btn.primary:disabled { background: rgba(255,255,255,.08); color: var(--mute); cursor: default; }
.btn.big { font-size: 20px; padding: 12px 48px; }
.btn.icon { padding: 8px 12px; }
.spinner { width: 56px; height: 56px; border-radius: 50%; border: 6px solid #dfe5ea; border-top-color: transparent; animation: spin 1s linear infinite; margin-right: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
#loading { flex-direction: row; color: var(--mute); }

.levels { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; text-align: left; }
.levels button { width: 100%; text-align: left; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.levels small { display: block; color: var(--mute); font-weight: 400; }
.levels .st { color: var(--gold); white-space: nowrap; letter-spacing: 2px; }
.levels button:disabled { opacity: .45; cursor: default; }

/* HUD */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud .top { position: absolute; top: calc(10px + var(--sat)); left: calc(10px + var(--sal)); right: calc(10px + var(--sar)); display: flex; gap: 8px; align-items: flex-start; }
#hud button, #hud .prompt, #hud .reveal { pointer-events: auto; }
.prompt { flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 8px 14px; text-align: center; }
.prompt .meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--mute); }
.ptext { font-size: 20px; font-weight: 800; line-height: 1.2; }
.pnote { font-size: 12px; color: var(--close); min-height: 0; }
.pnote:empty { display: none; }
.stats { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; min-width: 70px; text-align: right; }
.stats .lbl { font-size: 10px; color: var(--mute); display: block; text-transform: uppercase; letter-spacing: .06em; }
.stats b { font-size: 18px; }
.reveal { position: absolute; left: 50%; transform: translateX(-50%); top: calc(96px + var(--sat)); width: min(520px, calc(100% - 20px)); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; animation: pop .22s ease-out; }
.reveal.low { top: auto; bottom: calc(var(--sab) + 196px); }
@media (min-width: 700px) { .reveal.low { bottom: calc(var(--sab) + 120px); } }
.reveal .vrow { grid-column: 1; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.reveal #rVerdict { font-size: 20px; }
.reveal .pts { color: var(--gold); font-weight: 800; }
.reveal .rnote { grid-column: 1; color: var(--close); font-size: 13px; font-weight: 600; }
.reveal .rnote:empty { display: none; }
.reveal .rrule { grid-column: 1; color: var(--ink); font-size: 14px; }
.reveal #btnNext { grid-column: 2; grid-row: 1 / span 3; }
.v3 { color: var(--good); } .v2 { color: var(--good); } .v1 { color: var(--close); } .v0 { color: var(--miss); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -8px); } }
.bottom { position: absolute; left: calc(10px + var(--sal)); right: calc(10px + var(--sar)); bottom: calc(10px + var(--sab)); display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
.views { display: flex; flex-direction: column; gap: 6px; pointer-events: auto; }
.views .btn { padding: 6px 10px; min-width: 64px; font-size: 13px; background: var(--panel); }
.views .btn:disabled { opacity: .35; }
.tray { pointer-events: auto; touch-action: none; width: 84px; height: 84px; border-radius: 50%; border: 2px dashed rgba(223,229,234,.5); background: rgba(16,24,33,.85); display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--mute); font: 600 11px Manrope, sans-serif; cursor: grab; padding: 0; }
.tray svg { width: 44px; height: 44px; }
.tray.lifted svg { opacity: .25; }
.tray.used svg { opacity: .3; }
.actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; pointer-events: auto; }
.btn.mode { font-size: 13px; background: var(--panel); }
.btn.mode[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); }
.btn.listen { font-size: 18px; padding: 12px 18px; min-width: 104px; min-height: 52px; }
.grab { position: fixed; left: 0; top: 0; width: 64px; height: 64px; border-radius: 50%; z-index: 12; touch-action: none; cursor: grab; border: 2px solid rgba(255,209,102,.55); box-shadow: 0 0 0 6px rgba(255,209,102,.12); }
.hint { position: absolute; left: 50%; bottom: calc(110px + var(--sab)); transform: translateX(-50%); background: rgba(255,209,102,.95); color: #1b1404; padding: 8px 14px; border-radius: 12px; font-weight: 700; max-width: calc(100% - 20px); text-align: center; }
.hint.bob { animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translate(-50%, -8px); } }
#floats { position: fixed; inset: 0; pointer-events: none; z-index: 13; }
.float { position: absolute; font-weight: 800; font-size: 22px; color: var(--gold); text-shadow: 0 2px 8px rgba(0,0,0,.6); animation: floatUp 1s ease-out forwards; transform: translate(-50%, -50%); }
@keyframes floatUp { to { opacity: 0; transform: translate(-50%, -160%); } }
.stars { font-size: 40px; color: var(--gold); letter-spacing: 6px; }
.big-num { font-size: 26px; font-weight: 800; margin: 6px 0; }
.misses { text-align: left; font-size: 13px; color: var(--mute); padding-left: 18px; max-height: 32vh; overflow: auto; }
.misses b { color: var(--ink); }
.bars { list-style: none; padding: 0; text-align: left; }
.bars li { margin: 6px 0; font-size: 13px; }
.bars .bar { height: 8px; background: rgba(255,255,255,.08); border-radius: 4px; overflow: hidden; }
.bars .bar i { display: block; height: 100%; background: var(--accent); }
@media (max-width: 480px) {
  .ptext { font-size: 17px; }
  .stats b { font-size: 15px; }
  .reveal { top: calc(88px + var(--sat)); }
  .reveal #rVerdict { font-size: 17px; }
  .rrule { font-size: 13px; }
  .btn.listen { min-width: 92px; }
}
@media (prefers-reduced-motion: reduce) { .float, .reveal, .hint.bob, .spinner { animation: none; } }
