/* Global Retrowave & Cyberpunk Design System */
:root {
  --bg-primary: #06070a;
  --bg-bezel: #12131c;
  --bg-card: rgba(14, 16, 27, 0.85);
  --border-card: rgba(255, 255, 255, 0.05);
  --border-glow: rgba(0, 229, 255, 0.2);
  --text-main: #e2e8f0;
  --text-muted: #64748b;

  --accent: #ffd600;
  --accent-glow: rgba(255, 214, 0, 0.4);
  --theme-bg-gradient: radial-gradient(circle at center, #110e02 0%, #06070a 100%);

  --font-mono: 'Share Tech Mono', monospace;
  --font-title: 'Orbitron', sans-serif;
  --transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}

body.theme-pikachu {
  --accent: #ffd600;
  --accent-glow: rgba(255, 214, 0, 0.35);
  --theme-bg-gradient: radial-gradient(circle at center, #181504 0%, #06070a 100%);
  --border-glow: rgba(255, 214, 0, 0.2);
}

body.theme-ninja {
  --accent: #00e5ff;
  --accent-glow: rgba(0, 229, 255, 0.45);
  --theme-bg-gradient: radial-gradient(circle at center, #021822 0%, #06070a 100%);
  --border-glow: rgba(0, 229, 255, 0.2);
}

body.theme-dino {
  --accent: #39ff14;
  --accent-glow: rgba(57, 255, 20, 0.35);
  --theme-bg-gradient: radial-gradient(circle at center, #021706 0%, #06070a 100%);
  --border-glow: rgba(57, 255, 20, 0.2);
}

/* Base Styles */
html {
  overflow-x: clip;
  height: -webkit-fill-available;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-mono);
  background: var(--theme-bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 4px;
  overflow-x: clip;
  overflow-y: auto;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  transition: background 0.5s ease;
  /* Prevent pull-to-refresh and zoom gestures */
  touch-action: pan-y;
  position: relative;
}

/* Centered Container */
.arcade-container {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom);
}

/* CRT Scanline, Vignette & Flicker Overlay Effects — only on start screen */

/* LCD Scoreboard Dashboard */
.score-banner {
  background: #090a0f;
  border: 2px solid #1a1c27;
  border-radius: 12px;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.8), 0 4px 20px rgba(0, 0, 0, 0.5);
  width: 100%;
  justify-content: space-around;
  gap: 12px;
}

.score-lcd {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.lcd-label {
  font-family: var(--font-title);
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  color: var(--text-muted);
  font-weight: 800;
}

.lcd-value {
  font-size: 1.6rem;
  color: var(--accent);
  text-shadow: 0 0 10px var(--accent-glow);
  letter-spacing: 0.08em;
  font-weight: 700;
  transition: color 0.4s ease, text-shadow 0.4s ease;
}

.lcd-separator {
  width: 2px;
  height: 30px;
  background: #1a1c27;
}

/* Health Display */
.health-display {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
}

.health-heart {
  font-size: 1.2rem;
  transition: transform 0.2s ease, opacity 0.2s ease;
  filter: drop-shadow(0 0 4px rgba(255, 0, 85, 0.5));
}

.health-heart.lost {
  opacity: 0.2;
  filter: none;
}

.health-heart.gain {
  animation: heartPulse 0.5s ease;
}

@keyframes heartPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

/* CRT Screen Wrapper */
.game-section {
  width: 100%;
}

.game-wrapper {
  position: relative;
  background: #000;
  border-radius: 20px;
  overflow: hidden;
  border: 4px solid var(--bg-bezel);
  box-shadow:
    0 15px 35px rgba(0, 0, 0, 0.7),
    0 0 0 2px #1f2130,
    0 0 20px var(--border-glow);
  aspect-ratio: 800 / 400;
  min-height: 250px;
  transition: border-color 0.4s, box-shadow 0.4s;
  /* Prevent zoom on double-tap and touch gestures */
  touch-action: none;
  -webkit-touch-callout: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  touch-action: none;
}

/* CRT Scanline, Vignette & Flicker Overlay Effects — only on start screen */
.crt-scanlines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    rgba(18, 16, 16, 0) 50%,
    rgba(0, 0, 0, 0.25) 50%
  ), linear-gradient(
    90deg,
    rgba(255, 0, 0, 0.06),
    rgba(0, 255, 0, 0.02),
    rgba(0, 0, 255, 0.06)
  );
  background-size: 100% 4px, 6px 100%;
  z-index: 4;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.crt-scanlines.hidden {
  opacity: 0;
  pointer-events: none;
}

.crt-vignette {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5);
  z-index: 3;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.crt-vignette.hidden {
  opacity: 0;
  pointer-events: none;
}

.crt-screen-glow {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.015);
  animation: crtFlicker 0.15s infinite;
  z-index: 2;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.crt-screen-glow.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Floating Audio Control */
.mute-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(9, 10, 15, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border-radius: 6px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: var(--transition);
}

.mute-btn:hover {
  background: #12131c;
  color: var(--accent);
  border-color: var(--accent);
}

.mute-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Power-up HUD */
.powerup-hud {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(9, 10, 15, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
  min-width: 140px;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.powerup-hud.hidden {
  display: none;
}

.powerup-icon {
  font-size: 1.1rem;
}

.powerup-timer {
  font-family: var(--font-title);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.powerup-progress-bar {
  position: absolute;
  bottom: 0;
  left: 2px;
  right: 2px;
  height: 2px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 1px;
  overflow: hidden;
}

.powerup-progress-fill {
  height: 100%;
  border-radius: 1px;
  transition: width 0.1s linear;
}

.powerup-hud.magnet .powerup-timer { color: #ff0064; }
.powerup-hud.magnet .powerup-progress-fill { background: #ff0064; }
.powerup-hud.shield .powerup-timer { color: #00e5ff; }
.powerup-hud.shield .powerup-progress-fill { background: #00e5ff; }
.powerup-hud.speed .powerup-timer { color: #ffd600; }
.powerup-hud.speed .powerup-progress-fill { background: #ffd600; }

/* Overlays */
.game-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(6, 7, 10, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  transition: opacity 0.3s ease;
}

.game-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-content {
  text-align: center;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.pulse-svg {
  color: var(--accent);
  filter: drop-shadow(0 0 8px var(--accent-glow));
  animation: pulseScale 1.6s infinite ease-in-out;
}

.overlay-content h3 {
  font-family: var(--font-title);
  font-size: 1.1rem;
  letter-spacing: 0.15em;
  color: #fff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.controls-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  max-width: 320px;
  line-height: 1.6;
  letter-spacing: 0.05em;
}

.gameover-title {
  font-family: var(--font-title);
  font-size: 1.8rem;
  font-weight: 900;
  color: #ff0055;
  letter-spacing: 0.12em;
  text-shadow: 0 0 15px rgba(255, 0, 85, 0.5);
  animation: glitch 1s infinite alternate;
}

.score-display {
  display: flex;
  gap: 20px;
  font-family: var(--font-title);
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  margin: 10px 0;
  letter-spacing: 0.08em;
}

.score-display span {
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent-glow);
}

/* Mode Banner */
.mode-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 8;
  pointer-events: none;
  animation: modeBannerIn 0.4s ease, modeBannerOut 0.6s ease 1.8s forwards;
}

.mode-banner.hidden {
  display: none;
}

.mode-text {
  font-family: var(--font-title);
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: 0.15em;
  text-align: center;
  white-space: nowrap;
}

@keyframes modeBannerIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes modeBannerOut {
  0% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.2); }
}

/* Leaderboard in game over */
.lb-section {
  margin: 12px 0;
  width: 100%;
  max-width: 260px;
}

.lb-title {
  font-family: var(--font-title);
  font-size: 0.85rem;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

.lb-entries {
  max-height: 160px;
  overflow-y: auto;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.lb-rank {
  color: var(--text-muted);
  min-width: 24px;
}

.lb-row.lb-mine {
  background: rgba(255, 214, 0, 0.06);
  border-radius: 4px;
}

.lb-row.lb-mine .lb-name {
  color: var(--accent);
}

.lb-name {
  color: #fff;
  font-weight: 700;
  flex: 1;
}

.lb-score {
  color: var(--accent);
  font-family: var(--font-title);
  font-size: 0.8rem;
}

.lb-empty {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 12px 0;
}

/* Milestone notification */
.milestone-notification {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-title);
  font-size: 1.2rem;
  font-weight: 900;
  color: #39ff14;
  text-shadow: 0 0 20px rgba(57, 255, 20, 0.6);
  z-index: 8;
  animation: milestoneIn 0.4s ease, milestoneOut 0.4s ease 1.2s forwards;
  pointer-events: none;
  white-space: nowrap;
}

@keyframes milestoneIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes milestoneOut {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1.2); }
}

/* Buttons */
.retry-btn {
  background: #1b1d2a;
  color: #fff;
  border: 2px solid #2e324a;
  border-radius: 8px;
  font-family: var(--font-title);
  font-weight: 900;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  padding: 12px 28px;
  cursor: pointer;
  box-shadow: 0 4px 0 #0c0d15, 0 10px 20px rgba(0, 0, 0, 0.4);
  transition: transform 0.05s ease, box-shadow 0.05s ease, border-color 0.2s, color 0.2s;
  position: relative;
}

.retry-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.retry-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.retry-btn:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 #000, 0 4px 10px rgba(0, 0, 0, 0.2);
}

.retry-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.retry-btn.secondary {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-muted);
  box-shadow: none;
}

.retry-btn.secondary:hover {
  border-color: var(--text-muted);
  color: var(--text-main);
}

/* Skin Dock */
.skin-dock-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.dock-title {
  font-family: var(--font-title);
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.skin-dock {
  background: #090a0f;
  border: 2px solid #1a1c27;
  border-radius: 12px;
  padding: 8px;
  display: flex;
  gap: 10px;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.8);
}

.dock-card {
  background: #141622;
  border: 1px solid #23273c;
  border-radius: 8px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--text-muted);
  box-shadow: 0 3px 0 #090a10;
  transition: transform 0.05s ease, box-shadow 0.05s ease, color 0.2s, border-color 0.2s;
}

.dock-card:hover {
  color: var(--text-main);
  border-color: #383e5c;
}

.dock-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.dock-card.active {
  background: #1b1d2a;
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(2px);
  box-shadow: 0 1px 0 #000, 0 0 12px var(--accent-glow);
}

.dock-card:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #000;
}

.dock-card svg {
  transition: filter 0.2s;
}

.dock-card.active svg {
  filter: drop-shadow(0 0 6px var(--accent-glow));
}

.dock-name {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
}

/* Animations */
@keyframes crtFlicker {
  0% { opacity: 0.985; }
  50% { opacity: 1; }
  100% { opacity: 0.99; }
}

@keyframes pulseScale {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

@keyframes glitch {
  0% { transform: skew(0deg); }
  10% { transform: skew(-1deg); }
  20% { transform: skew(1.5deg); }
  30% { transform: skew(0deg); }
  100% { transform: skew(0deg); }
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
  body {
    padding: 6px;
    align-items: flex-start;
    padding-top: 8px;
  }
  .arcade-container {
    gap: 14px;
  }
  .score-banner {
    padding: 8px 12px;
    gap: 8px;
  }
  .lcd-value {
    font-size: 1.2rem;
  }
  .health-heart {
    font-size: 1rem;
  }
  .dock-card {
    padding: 10px 14px;
  }
  .dock-name {
    display: none;
  }
  .skin-dock {
    gap: 6px;
  }
  .powerup-hud {
    min-width: 120px;
    padding: 4px 10px;
  }
  .powerup-icon {
    font-size: 0.9rem;
  }
  .powerup-timer {
    font-size: 0.55rem;
  }
  .game-wrapper {
    border-width: 4px;
    border-radius: 12px;
  }
  .controls-hint {
    font-size: 0.65rem;
    line-height: 1.4;
  }
  .overlay-content h3 {
    font-size: 0.9rem;
  }
  .retry-btn {
    padding: 10px 22px;
    font-size: 0.75rem;
  }
}

/* Very small screens (SE, older phones, Instagram with bars) */
@media (max-height: 600px) {
  body {
    padding: 4px;
    align-items: flex-start;
    padding-top: 4px;
  }
  .arcade-container {
    gap: 8px;
  }
  .score-banner {
    padding: 6px 8px;
    gap: 6px;
  }
  .lcd-label {
    font-size: 0.5rem;
  }
  .lcd-value {
    font-size: 1rem;
  }
  .health-heart {
    font-size: 0.85rem;
  }
  .dock-title {
    font-size: 0.5rem;
    margin-bottom: 6px;
  }
  .skin-dock {
    padding: 4px;
    gap: 4px;
  }
  .dock-card {
    padding: 8px 10px;
  }
  .game-wrapper {
    border-width: 3px;
  }
}

/* Landscape mobile */
@media (max-height: 400px) and (orientation: landscape) {
  .score-banner {
    display: none;
  }
  .arcade-container {
    gap: 4px;
    max-width: 100%;
  }
  .skin-dock-container {
    display: none;
  }
  .game-wrapper {
    border-width: 2px;
    border-radius: 4px;
  }
}

/* Fix for Instagram / in-app browsers that break 100vh */
@supports (height: 100dvh) {
  body {
    min-height: 100dvh;
  }
}

/* iOS Safari: force top alignment so centered layout doesn't overflow */
@media (-webkit-touch-callout: none) {
  body {
    align-items: flex-start !important;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  .arcade-container {
    margin-top: env(safe-area-inset-top, 8px);
  }
}

/* Horizontal centering fallback for flexbox on iOS Safari */
.game-wrapper {
  margin: 0 auto;
}
