:root {
  --bg-1: #05070f;
  --bg-2: #0a0f1f;
  --bg-3: #131c33;
  --cyan: #22d3ee;
  --cyan-bright: #7dfcff;
  --blue: #3b82f6;
  --purple: #a855f7;
  --magenta: #e879f9;
  --orange: #fb923c;
  --white: #f4feff;
  --danger: #f43f5e;
  --panel: rgba(10, 16, 32, 0.72);
  --panel-border: rgba(125, 252, 255, 0.18);
  --font-display: 'Orbitron', 'Segoe UI', sans-serif;
  --font-ui: 'Rajdhani', 'Segoe UI', sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  background: var(--bg-1);
  color: var(--white);
}

.app {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 100svh;
  max-width: 1000px;
  margin: 0 auto;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(34, 211, 238, 0.10) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 110%, rgba(168, 85, 247, 0.10) 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-3) 0%, var(--bg-2) 45%, var(--bg-1) 100%);
}

/* Subtle animated grid + drifting particles behind everything */
.app::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(125, 252, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(125, 252, 255, 0.05) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(ellipse at 50% 40%, black 0%, transparent 75%);
  pointer-events: none;
  z-index: 0;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
.screen[hidden] { display: none !important; }

/* ============ MENU ============ */
#menu-screen { text-align: center; padding: 24px; }

.menu-bg-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(2px 2px at 15% 20%, rgba(125,252,255,.8), transparent),
    radial-gradient(2px 2px at 80% 15%, rgba(232,121,249,.7), transparent),
    radial-gradient(1.5px 1.5px at 65% 75%, rgba(168,85,247,.7), transparent),
    radial-gradient(2px 2px at 30% 85%, rgba(34,211,238,.7), transparent),
    radial-gradient(1.5px 1.5px at 90% 60%, rgba(125,252,255,.6), transparent);
  animation: drift 14s ease-in-out infinite alternate;
}
@keyframes drift {
  from { transform: translateY(0) scale(1); }
  to   { transform: translateY(-14px) scale(1.03); }
}

.menu-card { position: relative; z-index: 1; }

.brand {
  font-family: var(--font-ui);
  font-weight: 700;
  letter-spacing: 0.4em;
  font-size: 13px;
  color: var(--cyan);
  opacity: 0.85;
  margin-bottom: 10px;
}

.logo {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(40px, 11vw, 76px);
  letter-spacing: 0.03em;
  line-height: 1;
  background: linear-gradient(135deg, var(--cyan-bright), var(--cyan) 40%, var(--purple) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 24px rgba(34, 211, 238, 0.45));
  margin: 0 0 10px;
}

.tagline {
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: 0.25em;
  font-size: clamp(12px, 3vw, 16px);
  color: #a9e9f2;
  margin-bottom: 40px;
}

.btn {
  font-family: var(--font-ui);
  font-weight: 700;
  letter-spacing: 0.08em;
  border-radius: 14px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(0.96); }

.btn-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 220px;
  padding: 18px 40px;
  font-size: 22px;
  color: #04141a;
  background: linear-gradient(135deg, var(--cyan-bright), var(--cyan));
  box-shadow: 0 0 0 1px rgba(125,252,255,.5) inset, 0 10px 30px rgba(34,211,238,.35), 0 0 40px rgba(34,211,238,.25);
}
.btn-play:hover { box-shadow: 0 0 0 1px rgba(125,252,255,.7) inset, 0 12px 34px rgba(34,211,238,.5), 0 0 55px rgba(34,211,238,.4); }
.btn-play.btn-small { min-width: 160px; padding: 12px 22px; font-size: 16px; }

.btn-ghost {
  padding: 12px 20px;
  font-size: 14px;
  color: var(--cyan-bright);
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(125, 252, 255, 0.35);
}
.btn-ghost:hover { background: rgba(34, 211, 238, 0.16); }

.btn-text {
  padding: 8px 12px;
  font-size: 14px;
  color: #8fb3c2;
}
.btn-text:hover { color: var(--cyan-bright); }

.best-score-line {
  font-family: var(--font-ui);
  font-size: 15px;
  color: #cdeff5;
  margin: 22px 0 18px;
  letter-spacing: .02em;
}
.best-score-line span { font-weight: 700; color: var(--cyan-bright); }

.menu-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.input-hint { margin-top: 28px; font-size: 12px; letter-spacing: .15em; color: #5f7f8c; }

/* ============ COUNTDOWN ============ */
.modal-screen {
  background: rgba(4, 6, 13, 0.72);
  backdrop-filter: blur(6px);
  z-index: 20;
}
.countdown-number {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(90px, 30vw, 180px);
  color: var(--cyan-bright);
  text-shadow: 0 0 50px rgba(34,211,238,.7);
  animation: countPulse .55s ease-out;
}
@keyframes countPulse {
  from { transform: scale(0.4); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ============ GAMEPLAY ============ */
#play-screen { align-items: stretch; justify-content: stretch; }

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.hud {
  position: absolute;
  top: calc(14px + var(--safe-top));
  left: 14px;
  right: 14px;
  bottom: calc(14px + var(--safe-bottom));
  z-index: 5;
  font-family: var(--font-ui);
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.hud[hidden] { display: none !important; }

.hud-row { display: flex; justify-content: space-between; align-items: flex-start; }

.hud-block { display: flex; flex-direction: column; line-height: 1.1; min-width: 64px; }
.hud-bottom .hud-block:last-child { text-align: right; align-items: flex-end; }

.hud-label {
  font-size: 11px;
  letter-spacing: .18em;
  color: #7fb3c0;
  font-weight: 600;
}
.hud-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--white);
  text-shadow: 0 0 12px rgba(125,252,255,.25);
  font-variant-numeric: tabular-nums;
}
.hud-combo {
  color: var(--orange);
  transition: transform .15s ease, color .15s ease;
}
.hud-combo.hud-combo-hot {
  color: #ffb545;
  text-shadow: 0 0 16px rgba(255,140,20,.7);
  animation: comboPop .28s ease;
}
@keyframes comboPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.hud-controls { display: flex; gap: 8px; pointer-events: auto; }
.icon-btn {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.14);
  font-size: 16px;
}
.icon-btn[hidden] { display: none !important; }
.icon-btn:hover { background: rgba(255,255,255,.12); }

.delta-best {
  position: absolute;
  top: 76px;
  left: 0; right: 0;
  text-align: center;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .05em;
  color: var(--cyan-bright);
  text-shadow: 0 0 10px rgba(34,211,238,.5);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .2s ease, transform .2s ease;
}
.delta-best.show { opacity: 1; transform: translateY(0); }
.delta-best[hidden] { display: none; }

.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  overflow: hidden;
}

/* Floating +score popup / miss text spawned by JS */
.fx-pop {
  position: absolute;
  font-family: var(--font-ui);
  font-weight: 700;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  animation: popFloat 0.75s ease-out forwards;
  text-shadow: 0 0 10px currentColor;
}
@keyframes popFloat {
  0%   { opacity: 0; transform: translate(-50%, -40%) scale(0.7); }
  15%  { opacity: 1; transform: translate(-50%, -55%) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -140%) scale(1); }
}

.fx-milestone {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(28px, 8vw, 54px);
  letter-spacing: .04em;
  color: #ffb545;
  text-shadow: 0 0 30px rgba(255,140,20,.8);
  animation: milestonePop 0.9s cubic-bezier(.2,1.4,.4,1) forwards;
  pointer-events: none;
}
@keyframes milestonePop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(-6deg); }
  25%  { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(2deg); }
  40%  { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1.05); }
}

.screen-shake { animation: shake .28s linear; }
@keyframes shake {
  0%,100% { transform: translate(0,0); }
  20% { transform: translate(-6px,3px); }
  40% { transform: translate(5px,-4px); }
  60% { transform: translate(-4px,-2px); }
  80% { transform: translate(3px,4px); }
}

.flash-hit { animation: flashCyan .18s ease-out; }
@keyframes flashCyan {
  0% { background: rgba(34,211,238,.16); }
  100% { background: transparent; }
}
.flash-miss { animation: flashRed .22s ease-out; }
@keyframes flashRed {
  0% { background: rgba(244,63,94,.20); }
  100% { background: transparent; }
}

/* ============ PAUSE ============ */
#pause-screen .modal-card { text-align: center; }
#pause-screen h2 {
  font-family: var(--font-display);
  font-size: 26px;
  margin-bottom: 24px;
  letter-spacing: .06em;
}
#pause-screen .btn { display: block; width: 100%; margin: 0 auto 12px; }

/* ============ RESULT ============ */
#result-screen { padding: 20px; overflow-y: auto; }
.result-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
  padding: 28px 22px calc(24px + var(--safe-bottom));
}

.result-badge {
  display: inline-block;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .12em;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255,181,69,.12);
  border: 1px solid rgba(255,181,69,.5);
  color: #ffcf7a;
  margin-bottom: 14px;
}
.result-badge[hidden] { display: none; }

.result-title {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: .1em;
  font-size: 18px;
  color: #8fd8e8;
  margin-bottom: 6px;
}

.result-score {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(44px, 14vw, 64px);
  color: var(--white);
  text-shadow: 0 0 30px rgba(34,211,238,.5);
  margin-bottom: 18px;
  font-variant-numeric: tabular-nums;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.result-stat {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
  padding: 10px 6px;
}
.result-stat span {
  display: block;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 19px;
  color: var(--cyan-bright);
}
.result-stat label { font-size: 10px; letter-spacing: .1em; color: #7fa2ad; }

.result-best { font-size: 13px; color: #9fc3cd; margin-bottom: 4px; }
.result-best span { font-weight: 700; color: var(--white); }

.result-rank {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  color: var(--magenta);
  margin-bottom: 10px;
}
.result-rank[hidden] { display: none; }

.ad-slot {
  min-height: 0;
  margin: 6px 0;
}
.ad-slot:not(:empty) { min-height: 90px; margin: 14px 0; }

.nickname-form {
  display: flex;
  gap: 8px;
  margin: 16px 0 6px;
}
.nickname-form input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.16);
  color: var(--white);
  font-family: var(--font-ui);
  font-size: 15px;
}
.nickname-form input:focus { outline: 2px solid var(--cyan); border-color: transparent; }
.nickname-form input::placeholder { color: #6d8891; }

.save-status {
  min-height: 18px;
  font-size: 13px;
  font-weight: 600;
  color: #8fe0a3;
  margin-bottom: 8px;
}
.save-status.is-error { color: var(--danger); }

.beat-me {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  color: #9fc3cd;
  margin: 10px 0 14px;
}

.result-actions { display: flex; flex-direction: column; gap: 10px; }
