:root {
  --bg: #0d0716;
  --fg: #f4f2ff;
  --dim: rgba(244, 242, 255, 0.55);
  --accent: #c38bff;
  --hot: #ff5c8a;
  --gold: #ffd25a;
  --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);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  left: 0; right: 0;
  top: calc(var(--sat) + 12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s;
}
body.play #hud, body.paused #hud { opacity: 1; }

#score {
  font-size: clamp(40px, 11vw, 64px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 24px rgba(195, 139, 255, .45);
}
#score.bump { animation: bump .18s ease-out; }
@keyframes bump { 0% { transform: scale(1.25); } 100% { transform: scale(1); } }

#best {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .18em;
  color: var(--dim);
}

#combo {
  margin-top: 10px;
  min-height: 26px;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: .08em;
  color: var(--bg);
  background: var(--accent);
  opacity: 0;
  transform: scale(.6);
  transition: opacity .15s, transform .15s, background .2s;
}
#combo.on { opacity: 1; transform: scale(1); }
#combo.pop { animation: pop .3s cubic-bezier(.2, 1.8, .4, 1); }
@keyframes pop { 0% { transform: scale(1.6); } 100% { transform: scale(1); } }

/* ---------- sound button ---------- */
.ui-btn {
  position: absolute;
  z-index: 5;
  top: calc(var(--sat) + 10px);
  right: calc(var(--sar) + 10px);
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  color: var(--fg);
  cursor: pointer;
  touch-action: manipulation;
  outline: none;
}
.ui-btn:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.ui-btn .cross { display: none; }
.ui-btn.muted .wave { display: none; }
.ui-btn.muted .cross { display: inline; }
.ui-btn.muted { color: var(--dim); }

/* ---------- screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  padding: calc(var(--sat) + 16px) calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s, visibility 0s .25s;
}
.screen.show { opacity: 1; visibility: visible; transition: opacity .25s; }

.cta {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .28em;
  color: var(--fg);
  animation: blink 1.2s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: .35; } }

/* menu */
#menu { justify-content: space-between; }
.logo {
  margin-top: 6vh;
  font-size: clamp(44px, 15vw, 88px);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1;
  text-shadow: 0 0 30px rgba(195, 139, 255, .4);
}
.logo span { color: var(--accent); }
.hint {
  margin-top: 10px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .14em;
  color: var(--dim);
  text-transform: uppercase;
}
#menu > h1 + .hint { flex: 1; }
.menu-foot { margin-bottom: 6vh; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.menu-best { font-size: 12px; font-weight: 700; letter-spacing: .2em; color: var(--dim); min-height: 1em; }

/* game over */
#over { justify-content: center; background: radial-gradient(ellipse at center, rgba(10, 9, 24, .72), rgba(10, 9, 24, .9)); }
.panel { display: flex; flex-direction: column; align-items: center; text-align: center; }
#over.show .panel { animation: rise .35s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes rise { 0% { transform: translateY(24px) scale(.9); opacity: 0; } 100% { transform: none; opacity: 1; } }
.over-tag { font-size: 14px; font-weight: 800; letter-spacing: .3em; color: var(--hot); }
.over-score {
  margin: 6px 0 2px;
  font-size: clamp(84px, 28vw, 150px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.over-best { font-size: 13px; font-weight: 700; letter-spacing: .2em; color: var(--dim); }
.over-stats { margin-top: 18px; font-size: 13px; font-weight: 600; letter-spacing: .1em; color: var(--dim); }
#retry { margin-top: 36px; visibility: hidden; }
#over.ready #retry { visibility: visible; }

/* new record — its own screen */
#over.record { background: radial-gradient(ellipse at center, rgba(60, 38, 0, .55), rgba(10, 9, 24, .9)); }
#over.record .over-tag {
  font-size: clamp(26px, 8vw, 40px);
  letter-spacing: .08em;
  color: var(--gold);
  text-shadow: 0 0 22px rgba(255, 210, 90, .6);
  animation: shine 1s ease-in-out infinite alternate;
}
#over.record .over-score {
  background: linear-gradient(180deg, #fff6d0, var(--gold) 55%, #ff9d2e);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 24px rgba(255, 190, 60, .45));
}
#over.record .over-best { color: var(--gold); opacity: .8; }
@keyframes shine { from { transform: scale(1); } to { transform: scale(1.06); } }

#paused { justify-content: center; background: rgba(10, 9, 24, .6); }

@media (prefers-reduced-motion: reduce) {
  .cta, #over.record .over-tag { animation: none; }
}
