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

body {
  overflow: hidden;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#gameContainer {
  width: 100vw;
  height: 100vh;
  position: relative;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* HUD */
#hud {
  position: absolute;
  top: 16px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 0 48px 0 8px;
  flex-wrap: wrap;
  pointer-events: none;
  z-index: 10;
}

.hud-item {
  background: rgba(0,0,0,0.65);
  padding: 6px 16px;
  border-radius: 16px;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  border: 1px solid rgba(255,255,255,0.15);
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* Streak counter */
.hud-streak {
  color: #fbbf24;
  font-size: 18px;
  animation: streakPulse 0.5s ease-in-out infinite;
}
@keyframes streakPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* Best Distance Progress Bar */
#bestDistBar {
  position: absolute;
  top: 52px;
  left: 12px;
  right: 70px;
  z-index: 12;
  pointer-events: none;
}
.best-dist-track {
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  position: relative;
  overflow: visible;
}
.best-dist-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff69b4, #ffd700);
  border-radius: 3px;
  transition: width 0.3s ease;
  max-width: 100%;
}
.best-dist-label {
  position: absolute;
  right: 0;
  top: -16px;
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  white-space: nowrap;
}

/* Mission Bar */
#missionBar {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.5);
  padding: 4px 14px;
  border-radius: 12px;
  color: #fbbf24;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
  border: 1px solid rgba(251,191,36,0.2);
}

#missionBar.mission-done {
  color: #22cc44;
  border-color: rgba(34,204,68,0.3);
}

#missionProg {
  margin-left: 6px;
  opacity: 0.7;
}

/* Pause button — larger touch target */
.hud-pause {
  position: absolute;
  right: 12px;
  top: 0;
  background: rgba(0,0,0,0.65);
  padding: 10px 16px;
  border-radius: 16px;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  pointer-events: auto;
  border: 1px solid rgba(255,255,255,0.2);
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hud-pause:active {
  background: rgba(255,255,255,0.2);
}

/* Lane Indicator */
#laneIndicator {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  pointer-events: none;
  z-index: 10;
}

.lane-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  border: 1px solid rgba(255,255,255,0.3);
  transition: background 0.15s, transform 0.15s;
}

.lane-dot.lane-active {
  background: rgba(255,255,255,0.8);
  transform: scale(1.3);
}

/* Combo Display */
#gateEffect {
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 15;
}

#gateEffectText {
  font-size: 52px;
  font-weight: 900;
  text-shadow: 0 0 20px rgba(255,255,255,0.4), 0 3px 8px rgba(0,0,0,0.6);
}

@keyframes gatePopIn {
  0% { transform: scale(0.3); opacity: 0; }
  20% { transform: scale(1.3); opacity: 1; }
  40% { transform: scale(1); }
  80% { opacity: 1; }
  100% { transform: scale(1) translateY(-40px); opacity: 0; }
}

/* Powerup Status Bar */
#powerupBar {
  position: absolute;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  pointer-events: none;
  z-index: 10;
}

.powerup-slot {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0,0,0,0.5);
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.15);
}

.pw-icon { font-size: 18px; }

.pw-timer {
  width: 50px;
  height: 6px;
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
  overflow: hidden;
}

.pw-timer-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.2s;
}

#pw-magnet-fill { background: #3b82f6; }
#pw-shield-fill { background: #10b981; }

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  z-index: 20;
}

.overlay-box {
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  border: 1px solid #2a2a4a;
  border-radius: 20px;
  padding: 32px 40px;
  text-align: center;
  max-width: 400px;
  width: 90%;
}

/* Game Logo */
.game-logo {
  font-size: 36px;
  font-weight: 900;
  background: linear-gradient(135deg, #fbbf24, #f472b6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

.subtitle {
  color: #9ca3af;
  margin-bottom: 12px;
  font-size: 15px;
}

.high-score-line {
  color: #fbbf24;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
}

.overlay-box h1 {
  font-size: 28px;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #fbbf24, #f472b6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.overlay-box p {
  color: #a0a0b0;
  margin-bottom: 12px;
  font-size: 14px;
}

.controls-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
  color: #777;
  font-size: 13px;
}

/* Device-aware controls */
.ctrl-desktop { display: none; }
.ctrl-mobile { display: block; }
@media (hover: hover) and (pointer: fine) {
  .ctrl-desktop { display: block; }
  .ctrl-mobile { display: none; }
}

.overlay-box button {
  display: block;
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #fbbf24, #f472b6);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
  margin-bottom: 8px;
}

.overlay-box button:last-child { margin-bottom: 0; }

.overlay-box button:hover { transform: scale(1.03); }
.overlay-box button:active { transform: scale(0.97); }

.btn-secondary {
  background: rgba(255,255,255,0.08) !important;
  border: 1px solid rgba(255,255,255,0.2) !important;
  font-size: 14px !important;
}

.btn-secondary:hover { background: rgba(255,255,255,0.15) !important; }

.tap-hint {
  color: #6b7280;
  font-size: 12px;
  margin: -4px 0 8px;
}

/* Game Over Stats */
.go-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 14px;
}

.go-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.go-label {
  color: #9ca3af;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 2px;
}

.go-value {
  color: #fff;
  font-size: 28px;
  font-weight: 800;
}

.go-formula {
  color: #9ca3af;
  font-size: 10px;
  font-weight: 400;
}

.new-record {
  color: #fbbf24;
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 12px;
  animation: recordPulse 0.8s ease-in-out infinite alternate;
}

.mission-result {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
}

@keyframes recordPulse {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

/* Leaderboard */
.go-leaderboard, .lb-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 14px;
}

.lb-row {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  gap: 10px;
}

.lb-rank {
  width: 28px;
  font-size: 16px;
  color: #fbbf24;
  font-weight: 700;
  text-align: center;
  flex-shrink: 0;
}

.lb-name {
  flex: 1;
  color: #d1d5db;
  font-size: 14px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  color: #f59e0b;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}

.lb-box {
  max-width: 440px;
}

/* Death Flash */
#deathFlash {
  position: absolute;
  inset: 0;
  background: rgba(220, 38, 38, 0.4);
  z-index: 18;
  pointer-events: none;
  animation: deathFade 0.5s ease-out forwards;
}

@keyframes deathFade {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* Countdown */
#countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
  pointer-events: none;
}

#countdownNum {
  font-size: 120px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 40px rgba(251,191,36,0.6), 0 4px 12px rgba(0,0,0,0.8);
  animation: countPop 0.8s ease-out forwards;
}

@keyframes countPop {
  0% { transform: scale(2); opacity: 0; }
  30% { transform: scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: scale(0.8); opacity: 0; }
}

/* Loading */
.loading-bar {
  width: 200px;
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  margin: 12px auto;
  overflow: hidden;
}

.loading-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #fbbf24, #f472b6);
  border-radius: 4px;
  transition: width 0.3s;
}

/* Nickname Input */
.nickname-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.nickname-label {
  color: #9ca3af;
  font-size: 14px;
  white-space: nowrap;
}

.nickname-input {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  padding: 8px 12px;
  color: #fff;
  font-size: 15px;
  outline: none;
  width: 140px;
  font-family: inherit;
}

.nickname-input:focus {
  border-color: #f59e0b;
  background: rgba(255,255,255,0.12);
}

.nickname-input::placeholder {
  color: #6b7280;
}

/* Mobile */
@media (max-width: 768px) {
  .hud-item { font-size: 13px; padding: 5px 10px; }
  #hud { top: max(16px, env(safe-area-inset-top, 16px)); }
  .hud-pause { font-size: 18px; padding: 8px 12px; }
  .overlay-box { padding: 24px 24px; }
  .game-logo { font-size: 28px; }
  .overlay-box h1 { font-size: 22px; }
  #gateEffectText { font-size: 42px; }
  .go-value { font-size: 22px; }
  .go-stats { gap: 16px; }
  #laneIndicator { bottom: max(24px, env(safe-area-inset-bottom, 24px)); }
}

/* Tutorial Overlay */
#tutorial {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 22;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: tutFadeOut 6s ease-in forwards;
}

.tut-row {
  background: rgba(0,0,0,0.75);
  padding: 8px 18px;
  border-radius: 10px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  border: 1px solid rgba(255,255,255,0.15);
}

.tut-icon { font-size: 20px; flex-shrink: 0; }

.tut-fade {
  text-align: center;
  color: rgba(255,255,255,0.4);
  font-size: 12px;
  margin-top: 4px;
}

@keyframes tutFadeOut {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* Landscape Warning */
#landscapeWarn {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.landscape-msg {
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  text-align: center;
}

@media (orientation: landscape) and (max-height: 500px) {
  #landscapeWarn { display: flex; }
}

/* Gem fly animation */
@keyframes gemFlyToHud {
  0% { transform: scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: scale(0.3); opacity: 0; }
}

/* Revive Screen */
.revive-box { text-align: center; }
.revive-desc { font-size: 16px; color: #ccc; margin: 8px 0; }
.revive-countdown {
  font-size: 48px; font-weight: 900; color: #ff69b4;
  margin: 12px 0;
  animation: revivePulse 1s ease-in-out infinite;
}
@keyframes revivePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}
.btn-revive {
  background: linear-gradient(135deg, #ff69b4, #ff1493);
  color: #fff; font-size: 18px; font-weight: 700;
  padding: 12px 32px; border: none; border-radius: 12px;
  cursor: pointer; margin-bottom: 8px;
  box-shadow: 0 4px 15px rgba(255,105,180,0.4);
}

/* Achievement Screen */
.ach-box { max-height: 80vh; overflow-y: auto; }
.ach-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.ach-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 10px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
}
.ach-item.unlocked {
  background: rgba(255,215,0,0.12);
  border-color: rgba(255,215,0,0.3);
}
.ach-icon { font-size: 28px; flex-shrink: 0; }
.ach-info { flex: 1; }
.ach-name { font-weight: 700; font-size: 14px; color: #fff; }
.ach-desc { font-size: 12px; color: #aaa; margin-top: 2px; }
.ach-item.unlocked .ach-desc { color: #ffd700; }

/* Achievement Toast */
.ach-toast {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.85); color: #ffd700;
  padding: 10px 20px; border-radius: 12px; font-size: 14px; font-weight: 700;
  z-index: 35; pointer-events: none;
  border: 1px solid rgba(255,215,0,0.3);
  animation: achToastAnim 3s ease-in-out forwards;
}
@keyframes achToastAnim {
  0% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  10% { opacity: 1; transform: translateX(-50%) translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}
