:root {
  --bg: #07051a;
  --ink: #f4f1ff;
  --dim: #a59fcf;
  --glass: rgba(24, 18, 64, .55);
  --edge: rgba(190, 170, 255, .22);
  --prism: linear-gradient(90deg, #ff3d6e, #ffb21e, #27e39a, #38e8ff, #3f86ff, #b45cff, #ff3d6e);
  --display: 'Unbounded', ui-rounded, system-ui, -apple-system, sans-serif;
  --body: ui-rounded, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: var(--body);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: none;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }

/* ---------- Aurora background ---------- */
#aurora { position: fixed; inset: 0; overflow: hidden; pointer-events: none;
  background: radial-gradient(120% 80% at 50% 120%, #1b0f4a 0%, #0b0726 45%, #05031a 100%); }
#aurora i { position: absolute; width: 90vmax; height: 90vmax; border-radius: 50%; opacity: .38; will-change: transform; }
#aurora i:nth-child(1) { left: -40vmax; top: -30vmax; background: radial-gradient(closest-side, #6a2cff, transparent); animation: drift1 26s ease-in-out infinite alternate; }
#aurora i:nth-child(2) { right: -45vmax; top: 10vmax; background: radial-gradient(closest-side, #ff2d7a, transparent); opacity: .22; animation: drift2 32s ease-in-out infinite alternate; }
#aurora i:nth-child(3) { left: -20vmax; bottom: -55vmax; background: radial-gradient(closest-side, #00d0ff, transparent); opacity: .22; animation: drift3 38s ease-in-out infinite alternate; }
@keyframes drift1 { to { transform: translate(25vmax, 20vmax) scale(1.2); } }
@keyframes drift2 { to { transform: translate(-20vmax, 25vmax) scale(.85); } }
@keyframes drift3 { to { transform: translate(30vmax, -15vmax) scale(1.15); } }
body.danger #aurora i:nth-child(2) { opacity: .5; }

#app { position: fixed; inset: 0; height: 100dvh; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; left: 0; right: 0; top: 0;
  max-width: 520px; margin: 0 auto;
  padding: calc(var(--sat) + 10px) 14px 6px;
  display: grid; grid-template-columns: 1fr auto auto auto; gap: 10px; align-items: center;
  pointer-events: none; opacity: 0; transition: opacity .4s;
}
body.playing #hud, body.playing #controls { opacity: 1; }
#hud > * { pointer-events: auto; }
.stat label, .next label, .stats label {
  display: block; font: 600 9px/1 var(--display); letter-spacing: .22em; text-transform: uppercase; color: var(--dim);
}
.stat span { display: block; font: 800 26px/1.15 var(--display); letter-spacing: -.02em; font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(170, 140, 255, .55); }
.stat.lvl { text-align: center; padding: 0 6px; }
.stat.lvl span { font-size: 22px; background: var(--prism); background-size: 300% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: prismShift 8s linear infinite; }
.next { text-align: center; }
#next { width: 54px; height: 54px; display: block; margin-top: 3px; border-radius: 12px;
  background: var(--glass); box-shadow: inset 0 0 0 1px var(--edge); }
.icon-btn { width: 42px; height: 42px; border-radius: 14px; background: var(--glass); box-shadow: inset 0 0 0 1px var(--edge); display: grid; place-items: center; }
.icon-btn svg { width: 20px; height: 20px; fill: var(--ink); }
.icon-btn:active { transform: scale(.92); }

/* ---------- Controls ---------- */
#controls {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 520px; margin: 0 auto;
  padding: 8px 14px calc(var(--sab) + 12px);
  display: grid; grid-template-columns: 58px 1fr 58px; gap: 12px; align-items: center;
  opacity: 0; transition: opacity .4s;
}
.tilt-btn {
  height: 58px; border-radius: 20px; background: var(--glass); box-shadow: inset 0 0 0 1px var(--edge);
  display: grid; place-items: center; opacity: .4; transition: opacity .2s, transform .1s, box-shadow .3s;
}
.tilt-btn svg { width: 26px; height: 26px; fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.tilt-btn:active { transform: scale(.9); }
body.tilt-ready .tilt-btn { opacity: 1; animation: tiltPulse 1.1s ease-in-out infinite; }
@keyframes tiltPulse {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(255,255,255,.7), 0 0 18px rgba(120, 220, 255, .45); }
  50% { box-shadow: inset 0 0 0 2px rgba(255,255,255,.95), 0 0 34px rgba(255, 110, 200, .75); }
}
#meter { position: relative; height: 22px; border-radius: 11px; background: rgba(10, 6, 34, .7); box-shadow: inset 0 0 0 1px var(--edge); overflow: hidden; }
#meterFill { position: absolute; inset: 0; width: 0%; background: var(--prism); background-size: 200% 100%; animation: prismShift 4s linear infinite; transition: width .35s cubic-bezier(.2,.9,.3,1.2); border-radius: 11px; box-shadow: 0 0 16px rgba(255,255,255,.35); }
#meterLabel { position: absolute; inset: 0; display: grid; place-items: center; font: 800 10px/1 var(--display); letter-spacing: .4em; color: rgba(255,255,255,.85); text-shadow: 0 1px 4px rgba(0,0,0,.6); }
body.tilt-ready #meterLabel { animation: blink .6s steps(2) infinite; }
@keyframes blink { 50% { opacity: .4; } }
@keyframes prismShift { to { background-position: 200% 0; } }

/* ---------- Hint ---------- */
.hint { position: absolute; left: 50%; top: 34%; transform: translateX(-50%);
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; width: min(94vw, 460px);
  pointer-events: none; opacity: 0; transition: opacity .6s; }
.hint.show { opacity: 1; }
.hint span { font-size: 12px; padding: 7px 10px; border-radius: 99px; background: rgba(12, 8, 40, .82); box-shadow: inset 0 0 0 1px var(--edge); color: var(--dim); white-space: nowrap; }
.hint b { color: var(--ink); }

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  padding: calc(var(--sat) + 24px) 22px calc(var(--sab) + 24px);
  background: radial-gradient(100% 70% at 50% 40%, rgba(20, 12, 60, .55), rgba(5, 3, 20, .88));
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  opacity: 0; visibility: hidden; transition: opacity .35s, visibility .35s; text-align: center; overflow-y: auto;
  touch-action: pan-y;
}
#menu { background: radial-gradient(100% 70% at 50% 40%, rgba(20, 12, 60, .15), rgba(5, 3, 20, .55)); -webkit-backdrop-filter: none; backdrop-filter: none; }
.screen.show { opacity: 1; visibility: visible; }
.screen h2 { margin: 0; font: 800 24px/1 var(--display); letter-spacing: .08em; text-transform: uppercase; }

.logo h1 { margin: 6px 0 0; font: 900 clamp(40px, 13vw, 76px)/.95 var(--display); letter-spacing: -.03em;
  background: linear-gradient(180deg, #fff 20%, #cbbcff 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 24px rgba(160, 120, 255, .55)); }
.logo h1 span { display: block; background: var(--prism); background-size: 300% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: prismShift 6s linear infinite; }
.logo .tag { margin: 14px 0 0; font: 600 clamp(8px, 2.6vw, 11px)/1 var(--display); letter-spacing: .28em; white-space: nowrap; text-transform: uppercase; color: var(--dim); }
.logo-gems { display: flex; justify-content: center; gap: 6px; height: 52px; }
.logo-gems img { width: 44px; height: 44px; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-9px) rotate(6deg); } }

.menu-buttons { display: flex; flex-direction: column; gap: 12px; width: min(78vw, 300px); }
.btn { height: 56px; border-radius: 18px; font: 800 15px/1 var(--display); letter-spacing: .14em; text-transform: uppercase; transition: transform .1s; }
.btn:active { transform: scale(.96); }
.btn.primary { color: #16082e; background: linear-gradient(180deg, #fff, #d9ccff); box-shadow: 0 8px 30px rgba(170, 130, 255, .55), 0 0 0 2px rgba(255,255,255,.4) inset; position: relative; overflow: hidden; }
.btn.primary::after { content: ''; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.9) 50%, transparent 70%); transform: translateX(-100%); animation: sheen 3.2s ease-in-out infinite; mix-blend-mode: overlay; }
@keyframes sheen { 60%, 100% { transform: translateX(100%); } }
.btn.ghost { background: var(--glass); box-shadow: inset 0 0 0 1px var(--edge); font-size: 12px; height: 48px; }
.best { font: 600 11px/1 var(--display); letter-spacing: .25em; text-transform: uppercase; color: var(--dim); }
.best b { color: var(--ink); font-size: 15px; margin-left: 6px; letter-spacing: 0; }
.toggles { display: flex; gap: 10px; }
.toggle { padding: 10px 14px; border-radius: 99px; background: var(--glass); box-shadow: inset 0 0 0 1px var(--edge); font-size: 13px; color: var(--dim); }
.toggle b { color: var(--ink); margin-left: 4px; }
.toggle.off b { color: #ff6b8e; }

.cards { display: flex; flex-direction: column; gap: 10px; width: min(92vw, 440px); }
.card { display: grid; grid-template-columns: 76px 1fr; gap: 12px; align-items: center; text-align: left; padding: 12px; border-radius: 18px; background: var(--glass); box-shadow: inset 0 0 0 1px var(--edge); }
.card.hot { box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.35), 0 0 24px rgba(180, 92, 255, .35); }
.card p { margin: 0; font-size: 14px; line-height: 1.4; color: #d9d3ff; }
.card b { color: #fff; }
.demo { width: 76px; height: 56px; position: relative; }
.demo canvas { width: 100%; height: 100%; }

.over-kicker { margin: 0; font: 600 11px/1 var(--display); letter-spacing: .32em; text-transform: uppercase; color: var(--dim); }
.final { font: 900 clamp(48px, 15vw, 84px)/1 var(--display); letter-spacing: -.03em; background: linear-gradient(180deg, #fff, #c6b5ff); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 0 26px rgba(170, 130, 255, .6)); font-variant-numeric: tabular-nums; }
.badge { display: none; padding: 8px 16px; border-radius: 99px; font: 800 11px/1 var(--display); letter-spacing: .25em; text-transform: uppercase; color: #16082e; background: var(--prism); background-size: 300% 100%; animation: prismShift 3s linear infinite; }
.badge.show { display: block; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: min(92vw, 420px); }
.stats div { padding: 12px 4px; border-radius: 14px; background: var(--glass); box-shadow: inset 0 0 0 1px var(--edge); }
.stats b { display: block; margin-top: 6px; font: 800 18px/1 var(--display); }

#toast { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(.9); padding: 12px 18px; border-radius: 14px; background: rgba(12, 8, 40, .92); box-shadow: inset 0 0 0 1px var(--edge); font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

#rotate-note { display: none; }
@media (orientation: landscape) and (max-height: 480px) and (pointer: coarse) {
  #rotate-note { display: grid; place-items: center; position: absolute; inset: 0; background: var(--bg); font: 800 16px/1.4 var(--display); z-index: 10; padding: 24px; text-align: center; }
}
@media (max-height: 640px) {
  .screen { gap: 14px; }
  .card { padding: 8px; }
  .card p { font-size: 12.5px; }
}
@media (prefers-reduced-motion: reduce) {
  #aurora i, .logo-gems img, .btn.primary::after { animation: none; }
}
