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

html {
  /* Prevent iOS elastic bounce scroll */
  overscroll-behavior: none;
  height: 100%;
}

body {
  background: #0a0a2e;
  color: #fff;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  overflow: hidden;
  /* fill the whole screen including notch areas */
  width: 100vw;
  height: 100vh;
  /* iOS safe area support (Dynamic Island, notch, home indicator) */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  /* Prevent text selection during gameplay */
  user-select: none;
  -webkit-user-select: none;
  /* Prevent pull-to-refresh on mobile */
  overscroll-behavior-y: none;
}

.hidden {
  display: none !important;
}

/* ============================================
   Start Screen
   ============================================ */
#start-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #1a1a4e 0%, #0a0a2e 70%);
  z-index: 100;
  gap: 20px;
  /* Safe area padding so content isn't behind notch */
  padding: calc(20px + env(safe-area-inset-top))
           calc(20px + env(safe-area-inset-right))
           calc(20px + env(safe-area-inset-bottom))
           calc(20px + env(safe-area-inset-left));
}

#start-screen h1 {
  font-size: clamp(36px, 10vw, 64px);
  color: #7fdbff;
  text-shadow: 0 0 30px rgba(127, 219, 255, 0.5);
  letter-spacing: 4px;
}

#name-input {
  width: 280px;
  padding: 12px 20px;
  font-size: 18px;
  border: 2px solid #7fdbff;
  border-radius: 25px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  text-align: center;
  outline: none;
  transition: border-color 0.3s;
}

#name-input:focus {
  border-color: #fff;
}

#name-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

#skin-selector {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 400px;
}

.skin-option {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.2s, border-color 0.2s;
}

.skin-option:hover {
  transform: scale(1.2);
}

.skin-option.selected {
  border-color: #fff;
  transform: scale(1.2);
}

#play-btn, #respawn-btn {
  padding: 14px 50px;
  font-size: 20px;
  font-weight: bold;
  color: #0a0a2e;
  background: #7fdbff;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  transition: background 0.3s, transform 0.2s;
  text-transform: uppercase;
  letter-spacing: 2px;
}

#play-btn:hover, #respawn-btn:hover {
  background: #fff;
  transform: scale(1.05);
}

/* ============================================
   Game Canvas
   ============================================ */
#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  /* Prevent any touch default behaviours on the canvas */
  touch-action: none;
}

/* Death Screen */
#death-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
}

#death-box {
  text-align: center;
  background: rgba(20, 20, 60, 0.95);
  padding: 40px 60px;
  border-radius: 20px;
  border: 2px solid rgba(255, 65, 54, 0.5);
}

#death-box h2 {
  font-size: 36px;
  color: #ff4136;
  margin-bottom: 15px;
}

#death-box p {
  font-size: 20px;
  margin: 8px 0;
  color: #ccc;
}

#death-box span {
  color: #7fdbff;
  font-weight: bold;
}

/* ============================================
   HUD  (respects safe-area for notch / home bar)
   ============================================ */
#hud {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left));
  z-index: 50;
  font-size: 16px;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
}

#hud div {
  margin: 4px 0;
}

/* Minimap */
#minimap-canvas {
  position: fixed;
  bottom: calc(15px + env(safe-area-inset-bottom));
  right: calc(15px + env(safe-area-inset-right));
  z-index: 50;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

/* Leaderboard */
#leaderboard {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  z-index: 50;
  background: rgba(0, 0, 0, 0.5);
  padding: 12px 18px;
  border-radius: 10px;
  min-width: 180px;
}

#leaderboard h3 {
  font-size: 14px;
  color: #7fdbff;
  margin-bottom: 8px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#leaderboard-list {
  list-style: none;
  padding: 0;
  counter-reset: lb;
}

#leaderboard-list li {
  font-size: 13px;
  padding: 3px 0;
  color: #ccc;
  display: flex;
  justify-content: space-between;
}

#leaderboard-list li::before {
  counter-increment: lb;
  content: counter(lb) ".";
  margin-right: 8px;
  color: #888;
}

#leaderboard-list li.me {
  color: #7fdbff;
  font-weight: bold;
}

#leaderboard-list li .lb-length {
  color: #888;
  margin-left: 10px;
}

/* ============================================
   PWA Install Banner
   ============================================ */
#install-banner,
#update-banner {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(20, 20, 60, 0.95);
  border: 1px solid rgba(127, 219, 255, 0.4);
  padding: 12px 20px;
  border-radius: 30px;
  font-size: 14px;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.4s ease;
}

@keyframes slideUp {
  from { transform: translateX(-50%) translateY(80px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0);   opacity: 1; }
}

#install-banner span,
#update-banner span {
  color: #ccc;
}

#install-btn,
#update-btn {
  padding: 6px 18px;
  font-size: 13px;
  font-weight: bold;
  color: #0a0a2e;
  background: #7fdbff;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s;
}

#install-btn:hover,
#update-btn:hover {
  background: #fff;
}

#install-dismiss {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  transition: color 0.2s;
}

#install-dismiss:hover {
  color: #fff;
}

/* ============================================
   Mobile adjustments (phones < 480px)
   ============================================ */
@media (max-width: 480px) {
  #start-screen h1 {
    font-size: 36px;
    letter-spacing: 2px;
  }

  #name-input {
    width: 85vw;
    font-size: 16px;
  }

  #play-btn, #respawn-btn {
    padding: 14px 40px;
    font-size: 18px;
  }

  #leaderboard {
    min-width: 140px;
    padding: 8px 12px;
    font-size: 12px;
  }

  #leaderboard h3 {
    font-size: 12px;
  }

  #hud {
    font-size: 13px;
  }

  #death-box {
    padding: 30px 30px;
    width: 90vw;
  }

  #death-box h2 {
    font-size: 28px;
  }
}

/* ============================================
   PWA standalone mode tweaks
   ============================================ */
@media (display-mode: fullscreen),
       (display-mode: standalone) {
  /* In standalone/fullscreen PWA mode we get extra space back from the browser UI */
  #start-screen {
    /* Keep the safe-area padding — status bar may still be present */
  }
}
