/* ─── Tanks-specific overrides ─── */
/* All variables (--bg, --surface, --border, --accent, --danger, --good, --text, --muted) */
/* are inherited from ../style.css — do NOT redefine them here */
:root {
  --hud-h: 44px;
}

/* ─── Page layout ─── */
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ─── Canvas wrap ─── */
#canvasWrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: none;  /* shown when game starts */
}

#canvasWrap canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#terrainCanvas { z-index: 0; }
#entityCanvas  { z-index: 1; }

/* ─── HUD strip ─── */
#hud {
  height: var(--hud-h);
  background: rgba(0, 0, 0, 0.6);
  border-bottom: 1px solid var(--border);
  display: none;  /* shown when game starts */
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 11px;
  z-index: 10;
}

#hud.active {
  display: flex;
}

#hudLeft   { color: var(--muted); }
#hudCenter { color: #ffd700; font-size: 17px; font-weight: 700; }
#hudRight  { color: var(--muted); font-size: 11px; }

/* ─── Map selector grid ─── */
.map-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.map-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  min-height: 44px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.map-btn:hover {
  border-color: var(--accent);
}

.map-btn.active {
  border-color: var(--accent);
  background: rgba(79, 195, 247, 0.12);
}

.map-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ─── Overview button ─── */
#overviewBtn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 20;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

#overviewBtn:hover {
  background: rgba(79, 195, 247, 0.3);
}

#overviewBtn.active {
  background: rgba(79, 195, 247, 0.5);
}

/* ─── Start button disabled state ─── */
#startBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ─── Touch target sizing ─── */
@media (pointer: coarse) {
  .map-btn {
    min-height: 48px;
    font-size: 1rem;
  }
}

/* ─── Lobby card ─── */
.lobby-card {
  max-width: 480px;
  width: 90vw;
  max-height: 90dvh;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ─── Mobile: lobby overlay scrolls vertically so full card is reachable ─── */
@media (pointer: coarse), (max-width: 600px) {
  /* Allow the overlay to scroll so tall lobby content is reachable */
  #lobbyOverlay {
    align-items: flex-start;
    overflow-y: auto;
    padding: 16px 0 24px;
  }

  /* Tighter card padding on small screens */
  .overlay-card {
    padding: 20px 16px;
  }

  /* Compact lobby card — full height but scrollable if needed */
  .lobby-card {
    width: 94vw;
    max-height: none; /* overlay itself scrolls */
  }

  /* Smaller logo + title to save vertical space */
  .lobby-card .logo { font-size: 2rem; }
  .lobby-card h1    { font-size: 1.3rem; margin: 4px 0 2px; }

  /* Tighter map grid on narrow screens */
  .map-grid {
    gap: 6px;
    margin-bottom: 10px;
  }

  .map-btn {
    padding: 10px 10px;
    font-size: 0.85rem;
  }

  /* Compact toggle rows */
  .toggle-row {
    padding: 6px 0;
    font-size: 0.9rem;
  }

  /* Reduce player list max height */
  .player-list {
    max-height: 120px;
  }

  /* Compact weapon toggles label */
  .weapon-toggles .toggle-row {
    font-size: 0.82rem;
  }
}

/* ─── Name input ─── */
.name-input {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 12px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  box-sizing: border-box;
}
.name-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ─── Player list ─── */
.player-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  max-height: 200px;
  overflow-y: auto;
}
.player-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
}
.player-color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}
.player-host-badge {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
}

/* ─── Lobby settings ─── */
.lobby-settings {
  margin-bottom: 16px;
}
.settings-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─── Toggle button ─── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}
.toggle-btn {
  padding: 6px 18px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.toggle-btn.active {
  border-color: var(--good);
  background: rgba(102, 187, 106, 0.15);
  color: var(--good);
}
.weapon-toggles {
  margin-top: 0.5rem;
  text-align: left;
}
.weapon-toggles .toggle-row {
  font-size: 0.85rem;
}

/* ─── Countdown overlay ─── */
.countdown-number {
  font-size: 120px;
  font-weight: 900;
  color: #ffd700;
  text-shadow: 0 0 40px rgba(255, 215, 0, 0.5);
  animation: countdownPulse 1s ease-in-out infinite;
}
@keyframes countdownPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.8; }
}

/* ─── Game Over overlay ─── */
.winner-text {
  font-size: 1.5rem;
  color: var(--accent);
  margin: 16px 0;
}

/* ─── Waiting message ─── */
#waitingMsg {
  font-style: italic;
}

/* ─── Weapon HUD bar ─── */
.weapon-hud {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  gap: 4px;
  padding: 6px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.weapon-hud.hidden { display: none; }

.weapon-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 10px;
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  min-width: 48px;
  transition: border-color 0.15s, background 0.15s;
  opacity: 0.5;
}
.weapon-slot.has-ammo { opacity: 1; }
.weapon-slot.active {
  border-color: var(--accent);
  background: rgba(79, 195, 247, 0.2);
  opacity: 1;
}
.weapon-key {
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 2px;
}
.weapon-icon { font-size: 20px; }
.weapon-ammo {
  font-size: 11px;
  color: var(--accent);
  font-weight: 700;
  margin-top: 2px;
}
.weapon-slot:not(.has-ammo) .weapon-ammo { color: var(--muted); }

/* ─── Scoreboard card ─── */
.scoreboard-card {
  max-width: 600px;
  width: 92vw;
  max-height: 90dvh;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ─── Scoreboard table ─── */
.scoreboard-section {
  margin: 16px 0;
  overflow-x: auto;
}
.scoreboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.scoreboard-table th {
  padding: 8px 10px;
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}
.scoreboard-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.scoreboard-table .total-col {
  text-align: right;
  font-weight: 700;
  color: var(--accent);
}
.scoreboard-table .rank-1 { color: #ffd700; }
.scoreboard-table .rank-2 { color: #c0c0c0; }
.scoreboard-table .rank-3 { color: #cd7f32; }
.scoreboard-row .player-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}
.scoreboard-row .player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.scoreboard-row.winner-row {
  background: rgba(255, 215, 0, 0.08);
}

/* ─── Fun Stats ─── */
.fun-stats-section {
  margin: 16px 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.fun-stats-title {
  font-size: 1rem;
  margin-bottom: 10px;
  color: var(--text);
}
.fun-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
@media (max-width: 480px) {
  .fun-stats-grid { grid-template-columns: 1fr; }
}
.fun-stat-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.fun-stat-icon {
  font-size: 24px;
  flex-shrink: 0;
}
.fun-stat-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.fun-stat-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
}
.fun-stat-player {
  font-size: 0.75rem;
  color: var(--text);
}
.fun-stat-value {
  font-size: 0.7rem;
  color: var(--muted);
}

/* ─── Audio Controls ─── */
#sfxBtn, #musicBtn, #skipBtn {
  position: fixed;
  top: 8px;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  color: #fff;
  font-size: 0.85rem;
  padding: 4px 8px;
  cursor: pointer;
  transition: background 0.2s;
  height: auto; width: auto;
  line-height: normal;
}
#sfxBtn { right: 8px; }
#sfxVolSlider { right: 68px; }
#musicBtn { right: 140px; }
#musicVolSlider { right: 220px; }
#skipBtn { right: 290px; }
#sfxBtn:hover, #musicBtn:hover, #skipBtn:hover { background: rgba(255,255,255,0.15); }

.audio-slider {
  position: fixed;
  top: 12px;
  z-index: 1000;
  width: 60px;
  height: 20px;
  cursor: pointer;
  accent-color: #4caf50;
}

/* ─── Mobile: compact audio controls ─── */
@media (pointer: coarse), (max-width: 600px) {
  /* Hide volume sliders on touch (no room, not usable) */
  #sfxVolSlider, #musicVolSlider { display: none; }

  /* Reposition audio buttons to fit small screen */
  #sfxBtn   { right: 8px; }
  #musicBtn { right: 72px; }
  #skipBtn  { right: 136px; }

  /* Smaller font for audio buttons */
  #sfxBtn, #musicBtn, #skipBtn {
    font-size: 0.75rem;
    padding: 4px 6px;
  }
}

/* ─── Game Timer ─── */
.game-timer {
  position: fixed;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  color: #fff;
  font-size: 1.2rem;
  font-family: monospace;
  padding: 4px 14px;
  letter-spacing: 1px;
}
.game-timer.warning { color: #ff4444; animation: timerPulse 1s infinite; }
@keyframes timerPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ─── Rankings ─── */
.rankings-filters {
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-bottom: 12px;
}
.rank-filter {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); padding: 4px 10px; cursor: pointer; font-size: 0.8rem;
}
.rank-filter.active { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-secondary {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 8px 20px; cursor: pointer; font-size: 0.95rem;
  margin-top: 8px; transition: background 0.2s;
}
.btn-secondary:hover { background: var(--bg); }

/* ─── Kill Feed ─── */
.kill-feed {
  position: absolute;
  top: 50px;
  right: 10px;
  width: 230px;
  z-index: 50;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kill-entry {
  background: rgba(0, 0, 0, 0.7);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text);
  animation: killFadeIn 0.3s ease-out;
  transition: opacity 0.5s;
}

.kill-entry .killer { color: var(--accent); font-weight: 600; }
.kill-entry .victim { color: #ef5350; font-weight: 600; }

@keyframes killFadeIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ─── Mobile Controls ─── */
.mobile-controls {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 60;
  display: none;
}

.mobile-controls > * {
  pointer-events: auto;
}

/* Show on touch devices when activated via JS */
.mobile-controls.active {
  display: block;
}

/* ─── Virtual D-Pad ─── */
.mobile-dpad {
  position: absolute;
  bottom: 75px;
  left: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.dpad-middle {
  display: flex;
  gap: 3px;
}

.dpad-btn {
  width: 52px;
  height: 52px;
  background: rgba(0, 0, 0, 0.65);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dpad-btn:active, .dpad-btn.pressed {
  background: rgba(79, 195, 247, 0.5);
  border-color: var(--accent);
  color: #fff;
}

/* ─── Aim Slider (custom touch track) — bottom-right area ─── */
.mobile-aim {
  position: absolute;
  right: 95px;
  bottom: 75px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.aim-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.aim-track {
  width: 36px;
  height: 150px;
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid var(--border);
  border-radius: 6px;
  position: relative;
  touch-action: none;
}

.aim-thumb {
  position: absolute;
  left: 2px;
  right: 2px;
  height: 26px;
  background: var(--accent);
  border-radius: 4px;
  cursor: pointer;
  bottom: 25%; /* default: 45° mapped to track */
}

.aim-value {
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}

/* ─── Fire Button — bottom-right ─── */
.mobile-fire-btn {
  position: absolute;
  bottom: 130px;
  right: 10px;
  width: 75px;
  height: 75px;
  background: linear-gradient(145deg, #ef5350, #c62828);
  border: 3px solid #ff8a80;
  border-radius: 50%;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 4px 12px rgba(239, 83, 80, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-fire-btn:active, .mobile-fire-btn.pressed {
  transform: scale(0.92);
  background: linear-gradient(145deg, #ff7043, #e64a19);
  box-shadow: 0 2px 6px rgba(239, 83, 80, 0.6);
}

/* ─── Mobile Weapon Bar — bottom-center ─── */
.mobile-weapon-bar {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 5px;
  background: rgba(0, 0, 0, 0.75);
  padding: 6px 8px;
  border-radius: 10px;
}

.mobile-weapon-slot {
  width: 44px;
  height: 44px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  color: var(--text);
}

.mobile-weapon-slot.active {
  border-color: var(--accent);
  background: rgba(79, 195, 247, 0.2);
}

.mobile-weapon-slot.disabled {
  opacity: 0.4;
}

.mobile-ammo {
  font-size: 9px;
  color: var(--muted);
  margin-top: 1px;
}

/* Hide desktop weapon HUD when mobile controls are active */
.mobile-controls.active ~ .weapon-hud {
  display: none !important;
}

/* ─── Responsive adjustments for smaller phones ─── */
@media (max-height: 500px) {
  .mobile-dpad { bottom: 55px; }
  .mobile-aim { bottom: 55px; }
  .mobile-fire-btn { bottom: 100px; width: 65px; height: 65px; font-size: 11px; }
  .mobile-weapon-bar { bottom: 3px; }
  .mobile-weapon-slot { width: 38px; height: 38px; font-size: 16px; }
  .aim-track { height: 110px; }
  .dpad-btn { width: 44px; height: 44px; font-size: 16px; }
}

@media (max-height: 400px) {
  .mobile-dpad { bottom: 45px; }
  .mobile-aim { bottom: 45px; right: 85px; }
  .mobile-fire-btn { bottom: 85px; width: 60px; height: 60px; right: 8px; }
  .mobile-weapon-bar { bottom: 2px; padding: 4px 6px; }
  .mobile-weapon-slot { width: 34px; height: 34px; font-size: 14px; }
  .aim-track { height: 90px; width: 32px; }
  .dpad-btn { width: 40px; height: 40px; font-size: 14px; }
}
