:root {
  --accent: #4de3ff;
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b1026;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
}

#hud {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}

#score {
  font-size: clamp(30px, 6.5vw, 46px);
  font-weight: 900;
  color: #fff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(0,0,0,0.35), 0 4px 18px rgba(0,0,0,0.45);
  letter-spacing: 1px;
}
#score.bump { animation: scoreBump 0.28s ease-out; }
@keyframes scoreBump {
  0% { transform: scale(1); }
  35% { transform: scale(1.22); color: var(--accent); }
  100% { transform: scale(1); }
}

#btnMute {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 12;
  appearance: none;
  border: 1px solid rgba(255,255,255,0.22);
  background: rgba(10,12,24,0.35);
  backdrop-filter: blur(6px);
  border-radius: 12px;
  width: 42px;
  height: 42px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#btnMute:active { transform: scale(0.92); }

/* ---- overlays --------------------------------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: radial-gradient(ellipse at center, rgba(4,6,16,0.25), rgba(4,6,16,0.68));
  z-index: 10;
}
.overlay.hidden { display: none; }

.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 30px 34px 28px;
  border-radius: 26px;
  background: rgba(10,13,28,0.55);
  border: 1px solid rgba(255,255,255,0.14);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 30px 80px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.08);
  animation: panelIn 0.45s cubic-bezier(0.18, 1.25, 0.4, 1);
  max-width: min(92vw, 420px);
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(26px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.overlay h1 {
  margin: 0;
  font-size: clamp(34px, 9vw, 56px);
  font-weight: 900;
  letter-spacing: 3px;
  color: #fff;
  text-shadow:
    0 3px 0 rgba(0,0,0,0.35),
    0 0 34px color-mix(in srgb, var(--accent) 55%, transparent);
  animation: titleFloat 2.6s ease-in-out infinite;
}
@keyframes titleFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.tagline {
  margin: 0;
  color: rgba(255,255,255,0.82);
  font-size: clamp(14px, 3.4vw, 17px);
  max-width: 320px;
}

.start-best {
  min-height: 20px;
  color: var(--accent);
  font-weight: 800;
  font-size: clamp(13px, 3.2vw, 16px);
  letter-spacing: 1px;
}

.instructions {
  margin: 2px 0 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: rgba(255,255,255,0.85);
  font-size: clamp(12px, 3vw, 14px);
}

.instr-row .key {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 8px;
  background: rgba(255,255,255,0.13);
  border: 1px solid rgba(255,255,255,0.28);
  box-shadow: 0 2px 0 rgba(255,255,255,0.10) inset, 0 2px 3px rgba(0,0,0,0.35);
  font-weight: 700;
  letter-spacing: 0.5px;
  margin: 0 2px;
}

.primary-btn {
  appearance: none;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 16px 48px;
  font-size: clamp(16px, 4vw, 20px);
  font-weight: 900;
  letter-spacing: 2px;
  border-radius: 999px;
  color: #0b1026;
  background: var(--accent);
  box-shadow:
    0 8px 26px color-mix(in srgb, var(--accent) 45%, transparent),
    inset 0 -3px 0 rgba(0,0,0,0.18),
    inset 0 1px 0 rgba(255,255,255,0.5);
  transition: transform 0.08s ease;
  min-height: 48px;
  min-width: 48px;
  animation: btnPulse 1.8s ease-in-out infinite;
}
@keyframes btnPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}
.primary-btn:active { transform: scale(0.94); animation: none; }

.final-score {
  font-size: clamp(52px, 15vw, 88px);
  font-weight: 900;
  color: #fff;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 4px 0 rgba(0,0,0,0.3), 0 8px 30px rgba(0,0,0,0.4);
}

.go-label {
  margin: 0;
  font-size: clamp(11px, 2.8vw, 13px);
  font-weight: 800;
  letter-spacing: 3px;
  color: rgba(255,255,255,0.6);
}

.high-score-row {
  color: var(--accent);
  font-weight: 800;
  font-size: clamp(14px, 3.6vw, 18px);
  letter-spacing: 0.5px;
  min-height: 22px;
}
.high-score-row.new-best { animation: bestGlow 1.1s ease-in-out infinite; }
@keyframes bestGlow {
  0%, 100% { text-shadow: 0 0 6px color-mix(in srgb, var(--accent) 60%, transparent); transform: scale(1); }
  50% { text-shadow: 0 0 22px var(--accent); transform: scale(1.08); }
}

/* ---- touch controls ---------------------------------------------------- */
#controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 18px;
  z-index: 5;
  pointer-events: none;
}
#controls > * { pointer-events: auto; }

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

.ctrl-btn {
  appearance: none;
  border: none;
  outline: none;
  cursor: pointer;
  width: 58px;
  height: 58px;
  border-radius: 18px;
  background: rgba(10,12,24,0.35);
  border: 1px solid rgba(255,255,255,0.26);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 4px 14px rgba(0,0,0,0.3);
  color: #fff;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  transition: transform 0.08s ease, background 0.08s ease;
}
.ctrl-btn:active { transform: scale(0.88); background: rgba(255,255,255,0.24); }

#btnJump {
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background: var(--accent);
  color: #0b1026;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1px;
  border: none;
  box-shadow:
    0 8px 26px color-mix(in srgb, var(--accent) 50%, transparent),
    inset 0 -4px 0 rgba(0,0,0,0.18),
    inset 0 1px 0 rgba(255,255,255,0.5);
}
#btnJump:active { transform: scale(0.88); }

@media (min-width: 900px) {
  #controls { display: none; }
}
