/* ── Reset ──────────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

:root {
  --hud-font: 'Press Start 2P', monospace;
  --hud-color: #ff4444;
  --hud-glow: 0 0 8px #ff0000, 0 0 20px #ff000066;
  --ammo-color: #ffcc00;
  --ammo-glow: 0 0 8px #ffaa00, 0 0 20px #ffaa0066;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: var(--hud-font);
  cursor: auto;
}

canvas {
  display: block;
}

/* ── Blocker / Start Screen ────────────────────────── */
#blocker {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: pointer;
}

#blocker.hidden {
  display: none;
}

#blocker-inner {
  text-align: center;
  color: #fff;
}

#blocker-inner h1 {
  font-size: 4rem;
  color: var(--hud-color);
  text-shadow: var(--hud-glow);
  letter-spacing: 0.15em;
  margin-bottom: 1.5rem;
  animation: pulse 1.5s ease-in-out infinite;
}

#start-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: center;
  margin-bottom: 2rem;
  pointer-events: auto;
  /* Ensure clickable */
}

#player-name-input {
  background: rgba(0, 0, 0, 0.8);
  border: 2px solid #555;
  color: #fff;
  font-family: var(--hud-font);
  font-size: 1rem;
  padding: 10px;
  text-align: center;
  text-transform: uppercase;
  width: 250px;
  outline: none;
}

#player-name-input:focus {
  border-color: var(--hud-color);
  box-shadow: 0 0 10px var(--hud-color);
}

#start-btn {
  background: var(--hud-color);
  color: #000;
  border: none;
  font-family: var(--hud-font);
  font-size: 1.2rem;
  padding: 15px 40px;
  cursor: pointer;
  text-transform: uppercase;
  transition: transform 0.1s;
}

#start-btn:hover {
  transform: scale(1.05);
  background: #ff6666;
}

#start-btn:active {
  transform: scale(0.95);
}

#blocker-inner p {
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: #ccc;
}

.controls-hint {
  font-size: 0.6rem !important;
  color: #888 !important;
  margin-top: 1rem !important;
}

.warning-text {
  font-size: 0.7rem;
  color: #ffaa00;
  margin-top: 1.5rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  animation: pulse 2s infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.7;
    transform: scale(1.04);
  }
}

/* ── HUD ───────────────────────────────────────────── */
#hud {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 1.2rem 2rem;
  pointer-events: none;
  z-index: 100;
  /* Increased z-index */
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
}

/* ── Specific HUD Layout ───────────────────────────── */
#hud-top-left {
  position: fixed;
  top: 60px;
  /* Moved down to clear Highscore */
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}

#hud-bottom-right {
  position: fixed;
  bottom: 110px;
  /* Moved up to clear Ammo */
  right: 20px;
  z-index: 200;
  pointer-events: none;
  text-align: right;
}

.hud-text,
.hud-text-small {
  color: #ffffff;
  text-shadow: 0 0 8px #ffffff, 0 0 20px #ffffff66;
  font-family: var(--hud-font);
  font-weight: bold;
  display: block;
}

.hud-text {
  font-size: 1.5rem;
  letter-spacing: 2px;
}

.hud-text-small {
  font-size: 0.8rem;
  /* Matches Highscore size */
  letter-spacing: 1px;
}

/* Level Bar */
#hud-level-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#hud-level-bar-container {
  width: 100px;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid #666;
}

#hud-level-bar {
  width: 0%;
  height: 100%;
  background: #00ccff;
  /* Cyan */
  box-shadow: 0 0 4px #00ccff;
  transition: width 0.3s ease-out;
}

#hud-stats {
  display: flex;
  gap: 3rem;
}

#hud-health,
#hud-ammo,
#hud-balance,
#hud-exp,
#hud-level,
#hud-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud-label {
  font-size: 0.55rem;
  color: #999;
  letter-spacing: 0.2em;
  margin-bottom: 0.3rem;
}

#hud-health-val {
  font-size: 2.2rem;
  color: var(--hud-color);
  text-shadow: var(--hud-glow);
}

#hud-balance-val {
  font-size: 2.2rem;
  color: #00ff66;
  text-shadow: 0 0 8px #00ff00, 0 0 20px #00ff0066;
}

#hud-exp-val,
#hud-level-val,
#hud-stage-val {
  display: none;
}

.xp-bar-container {
  width: 120px;
  height: 10px;
  /* Slightly larger */
  background: rgba(255, 255, 255, 0.2);
  /* More visible background */
  border: 1px solid #666;
  /* Lighter border */
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  position: relative;
  /* Ensure z-index works if needed */
}

.xp-bar {
  width: 0%;
  height: 100%;
  background: #00ccff;
  box-shadow: 0 0 8px #00ccff;
  transition: width 0.3s ease-out;
}

#hud-middle {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0.8rem;
}

#hud-ammo-val {
  font-size: 2.2rem;
  color: var(--ammo-color);
  text-shadow: var(--ammo-glow);
}

/* ── Crosshair ─────────────────────────────────────── */
#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.4rem;
  font-family: monospace;
  pointer-events: none;
  z-index: 50;
  text-shadow: 0 0 4px rgba(255, 255, 255, 0.6);
}

/* ── Weapon Overlay ────────────────────────────────── */
#weapon-container {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 256px;
  height: 256px;
  pointer-events: none;
  z-index: 40;
  image-rendering: pixelated;
}

#weapon-canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

#muzzle-flash {
  position: absolute;
  top: -40px;
  left: 50%;
  transform: translateX(-50%);
  width: 128px;
  height: 128px;
  image-rendering: pixelated;
  opacity: 0;
  transition: opacity 0.04s;
}

#muzzle-flash.active {
  opacity: 1;
}

/* weapon firing kick */
#weapon-container.firing {
  animation: weapon-kick 0.15s ease-out;
}

@keyframes weapon-kick {
  0% {
    transform: translateX(-50%) translateY(0);
  }

  30% {
    transform: translateX(-50%) translateY(-18px) scale(1.08);
  }

  100% {
    transform: translateX(-50%) translateY(0);
  }
}

/* ── Game Over ─────────────────────────────────────── */
#game-over {
  position: fixed;
  inset: 0;
  background: rgba(80, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: pointer;
}

#game-over.hidden {
  display: none;
}

#game-over h1 {
  font-size: 4rem;
  color: #ff2222;
  text-shadow: 0 0 30px #ff0000;
  margin-bottom: 1rem;
  animation: pulse 1s ease-in-out infinite;
}

#game-over p {
  font-size: 0.9rem;
  color: #ccc;
}

/* ── Damage Flash ──────────────────────────────────── */
#damage-flash {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 30%, rgba(255, 0, 0, 0.5) 100%);
  pointer-events: none;
  z-index: 45;
  opacity: 0;
  transition: opacity 0.12s;
}

#damage-flash.active {
  opacity: 1;
}

/* ── Minimap ───────────────────────────────────────── */
#minimap-container {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 200px;
  height: 200px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid #444;
  z-index: 60;
}

#minimap-canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

/* ── Highscore ─────────────────────────────────────── */
#highscore {
  position: fixed;
  top: 20px;
  left: 20px;
  color: #fff;
  z-index: 60;
  font-size: 0.8rem;
}

/* ── Shop Overlay ──────────────────────────────────── */
#shop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 15, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  pointer-events: auto;
  cursor: default;
}

#shop-overlay.hidden {
  display: none;
}

#shop-inner {
  text-align: center;
  color: #fff;
  border: 4px solid #444;
  padding: 40px;
  background: #000;
  max-width: 600px;
  pointer-events: auto;
}

#shop-inner h1 {
  color: #00ccff;
  margin-bottom: 30px;
  text-shadow: 0 0 10px #00aaff;
}

#shop-items {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-bottom: 30px;
}

.shop-item {
  border: 2px solid #333;
  padding: 20px;
  width: 200px;
}

.shop-item h3 {
  font-size: 0.8rem;
  margin-bottom: 10px;
}

.shop-item p {
  font-size: 0.5rem;
  color: #888;
  margin-bottom: 15px;
}

.buy-btn {
  background: #222;
  color: #00ff66;
  border: 2px solid #00ff66;
  padding: 10px;
  font-family: var(--hud-font);
  font-size: 0.7rem;
  cursor: pointer;
}

.buy-btn:hover:not(:disabled) {
  background: #00ff66;
  color: #000;
}

.buy#shop-item button:disabled {
  background: #555;
  color: #888;
  cursor: default;
}

/* ── Leaderboard Overlay ── */
#leaderboard-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1500;
  /* Above shop */
}

#leaderboard-inner {
  background: #222;
  border: 4px solid #fff;
  padding: 2rem;
  width: 500px;
  text-align: center;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
}

#leaderboard-inner h1 {
  margin-top: 0;
  color: #ffcc00;
  font-size: 2rem;
  text-shadow: 2px 2px #000;
  border-bottom: 2px solid #555;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
}

#leaderboard-list table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}

#leaderboard-list th,
#leaderboard-list td {
  padding: 0.5rem;
  text-align: left;
  border-bottom: 1px solid #444;
  font-family: 'Courier New', Courier, monospace;
}

#leaderboard-list th {
  color: #888;
  font-size: 0.9rem;
}

#leaderboard-list td {
  color: #fff;
  font-size: 1.1rem;
}

#leaderboard-list .my-rank {
  background: rgba(255, 204, 0, 0.2);
  font-weight: bold;
  color: #ffcc00;
}

/* ── Console ── */
#console-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 50%;
  /* Top half of screen */
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  z-index: 2000;
  border-bottom: 2px solid #555;
}

#console-output {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
  font-family: monospace;
  color: #ccc;
  font-size: 14px;
}

#console-input {
  width: 100%;
  padding: 10px;
  background: #222;
  border: none;
  border-top: 1px solid #555;
  color: #fff;
  font-family: monospace;
  font-size: 16px;
}

.console-msg.error {
  color: #ff5555;
}

.console-msg.success {
  color: #55ff55;
}

.console-msg.info {
  color: #aaa;
}

.buy-btn:disabled {
  border-color: #666;
  color: #666;
  cursor: default;
}

.shop-hint {
  font-size: 0.5rem;
  color: #555;
}

/* ── FORCE HUD STYLES (Fix for visibility issues) ── */
#hud-exp-val,
#hud-level-val,
#hud-stage-val {
  font-size: 1.8rem !important;
  color: #ffffff !important;
  text-shadow: 0 0 8px #ffffff, 0 0 20px #ffffff66 !important;
  display: block;
  margin-top: 0.2rem;
}

/* ── Global Leaderboard ────────────────────────────── */
#global-leaderboard {
  margin-top: 20px;
  border-top: 1px solid #444;
  padding-top: 10px;
  width: 100%;
}

#global-leaderboard h3 {
  font-size: 0.8rem;
  color: #00ccff;
  margin-bottom: 10px;
  text-shadow: 0 0 5px #00ccff;
}

#global-leaderboard table {
  width: 100%;
  text-align: left;
  font-size: 0.7rem;
  color: #aaa;
  border-collapse: collapse;
}

#global-leaderboard td {
  padding: 4px;
  border-bottom: 1px solid #222;
}

#global-leaderboard tr:nth-child(1) td {
  color: #ffd700;
  /* Gold for #1 */
}