/* ============================================================
   RETRO ARCADE STYLES – PAC-MAN INSPIRED
   ============================================================ */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  background: #0a0e1a;
  background-image: radial-gradient(circle at 20% 30%, #1a2a4a 0%, #0a1220 80%);
  color: #fff;
  font-family: "Courier New", monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  user-select: none;
  padding: max(env(safe-area-inset-top), 12px)
    max(env(safe-area-inset-right), 12px) max(env(safe-area-inset-bottom), 12px)
    max(env(safe-area-inset-left), 12px);
}

/* ---- Overlays (retro panels) ---- */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: max(env(safe-area-inset-top), 20px)
    max(env(safe-area-inset-right), 20px) max(env(safe-area-inset-bottom), 20px)
    max(env(safe-area-inset-left), 20px);
}
.overlay .arcade-panel {
  background: #0a1220;
  border: 4px solid #f0c040;
  border-radius: 24px;
  padding: 40px 50px;
  max-width: 600px;
  width: 90%;
  box-shadow:
    0 0 40px rgba(240, 192, 64, 0.3),
    inset 0 0 20px rgba(240, 192, 64, 0.05);
}
.overlay h1 {
  text-shadow:
    4px 4px 0 #000,
    0 0 30px currentColor;
}

/* ---- HUD (Score panel) ---- */
.hud-container {
  display: flex;
  flex-wrap: wrap; /* allow wrapping on small screens */
  justify-content: space-between;
  align-items: center;
  gap: 8px 16px; /* row gap, column gap */
  background: #0a1220;
  border: 2px solid #f0c040;
  border-radius: 12px;
  padding: 8px 16px;
  margin-bottom: 12px;
  width: min(630px, 95vw);
  max-width: 95vw;
  box-shadow:
    0 0 20px rgba(240, 192, 64, 0.15),
    inset 0 0 10px rgba(240, 192, 64, 0.05);
  font-size: clamp(0.8rem, 2.5vw, 1.2rem);
}
.hud-label {
  color: #8a9aaa;
  font-size: 0.7em;
  letter-spacing: 1px;
  margin-right: 2px;
}
.hud-value {
  font-weight: bold;
  color: #f0c040;
  margin-right: 12px;
}
.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
}
.status-idle {
  color: #8f8;
}
.status-gameover {
  color: #f44;
}
.status-win {
  color: #ff0;
}

/* ---- Game Container ---- */
.game-container {
  position: relative;
  display: inline-block;
  background: #0a1220;
  padding: clamp(6px, 1.5vw, 12px);
  border-radius: 16px;
  box-shadow:
    0 0 40px rgba(0, 150, 255, 0.2),
    0 0 80px rgba(0, 150, 255, 0.05);
  width: min(630px, 95vw);
  max-width: 95vw;
  border: 2px solid #2a4a6a;
}
.game-border {
  position: relative; /* needed for absolute positioning of power‑up overlay */
  border: 4px solid #f0c040;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: inset 0 0 30px rgba(240, 192, 64, 0.1);
}
#gameCanvas {
  display: block;
  margin: 0 auto;
  image-rendering: pixelated;
  background: #0a1220;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
}

/* ---- Power‑up Overlay (absolutely positioned inside game-border) ---- */
#powerupOverlay {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  min-width: 100px;
  max-width: 180px;
}
.powerup-item {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 6px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: clamp(11px, 1.8vw, 14px);
  color: #fff;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
  pointer-events: auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.powerup-item .icon {
  font-size: 1.2em;
  line-height: 1;
}
.powerup-item .label {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex: 1;
}
.powerup-item .timer {
  font-variant-numeric: tabular-nums;
  min-width: 28px;
  text-align: right;
  font-weight: bold;
  color: #ffd700;
}
.powerup-item.speed .label {
  color: #4dd0e1;
}
.powerup-item.barrier .label {
  color: #ffd700;
}
.powerup-item.slow .label {
  color: #64b5f6;
}
.powerup-item.toxic .label {
  color: #81c784;
}
.powerup-item.entering {
  opacity: 0;
  transform: translateY(-10px);
}
.powerup-item.entered {
  opacity: 1;
  transform: translateY(0);
}
.powerup-item.exiting {
  opacity: 0;
  transform: translateY(-10px);
}

/* ---- Boss Health Bar (overlay, independent) ---- */
#bossHealthBar {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  background: rgba(0, 0, 0, 0.8);
  border: 2px solid #ff3333;
  border-radius: 8px;
  padding: 8px 16px;
  min-width: 160px;
  display: none; /* hidden by default; shown via JS in Level 3 */
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: 0 0 20px rgba(255, 0, 0, 0.3);
  pointer-events: none;
}

.boss-health-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: clamp(12px, 2vw, 16px);
  font-weight: bold;
  color: #ff4444;
  text-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
}

.boss-icon {
  font-size: clamp(16px, 2.5vw, 24px);
}

.boss-health-track {
  width: 100%;
  height: clamp(8px, 1.5vw, 14px);
  background: #2a1a1a;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #442222;
}

.boss-health-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff0000, #ff4444);
  border-radius: 3px;
  transition: width 0.3s ease;
  box-shadow: 0 0 10px rgba(255, 0, 0, 0.4);
}

.boss-health-text {
  font-size: clamp(10px, 1.2vw, 14px);
  color: #ff8888;
  font-weight: bold;
}

/* ---- Boss Intro Animation ---- */
@keyframes bossIntroPulse {
  0% {
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.05);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

/* ---- Controls (retro buttons) ---- */
.controls-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 12px;
  gap: 4px;
}
.controls-row {
  display: flex;
  gap: 8px;
}
.control-btn {
  width: clamp(40px, 10vw, 48px);
  height: clamp(40px, 10vw, 48px);
  font-weight: bold;
  font-size: clamp(1rem, 4vw, 1.2rem);
  background: #1a2a4a;
  color: #f0c040;
  border: 2px solid #f0c040;
  border-radius: 8px;
  text-shadow: 0 0 8px rgba(240, 192, 64, 0.3);
  transition: all 0.15s;
  touch-action: manipulation;
}
.control-btn:hover {
  background: #2a3a5a;
  box-shadow: 0 0 20px rgba(240, 192, 64, 0.3);
}
.control-btn:active {
  transform: scale(0.95);
}

.game-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
  flex-wrap: wrap;
}

/* ---- Retro Buttons (general) ---- */
.btn-arcade {
  background: #0a1220;
  color: #f0c040;
  border: 2px solid #f0c040;
  border-radius: 12px;
  font-family: "Courier New", monospace;
  font-weight: bold;
  text-shadow: 0 0 10px rgba(240, 192, 64, 0.3);
  transition: all 0.2s;
  padding: 10px 24px;
  touch-action: manipulation;
}
.btn-arcade:hover {
  background: #1a2a4a;
  box-shadow: 0 0 30px rgba(240, 192, 64, 0.3);
  color: #fff;
}
.btn-arcade:active {
  transform: scale(0.95);
}
.btn-arcade-sm {
  composes: btn-arcade;
  padding: 6px 16px;
  font-size: 0.9rem;
}
.btn-arcade-lg {
  composes: btn-arcade;
  padding: 14px 32px;
  font-size: 1.2rem;
}
.btn-arcade:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

/* ---- Pause Overlay ---- */
.pause-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  padding: max(env(safe-area-inset-top), 20px)
    max(env(safe-area-inset-right), 20px) max(env(safe-area-inset-bottom), 20px)
    max(env(safe-area-inset-left), 20px);
}
.pause-overlay:not(.d-none) {
  opacity: 1;
  pointer-events: auto;
}
.pause-content {
  background: #0a1220;
  border: 4px solid #f0c040;
  border-radius: 24px;
  padding: 40px 50px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 0 40px rgba(240, 192, 64, 0.3);
}
.pause-content h1 {
  font-size: clamp(2rem, 10vw, 3rem);
  text-shadow:
    4px 4px 0 #000,
    0 0 30px #f0c040;
}

/* ---- Modals (retro) ---- */
.retro-modal {
  border: 2px solid #f0c040;
  border-radius: 16px;
  background: #0a1220;
}
.retro-modal .modal-header {
  border-bottom: 2px solid #f0c040;
}
.retro-modal .modal-footer {
  border-top: 2px solid #f0c040;
}

/* ---- Utility ---- */
.d-none {
  display: none !important;
}

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* Tablets and small desktops */
@media (max-width: 768px) {
  .hud-container {
    font-size: clamp(0.7rem, 2vw, 1rem);
    padding: 6px 12px;
    gap: 6px 12px;
  }
  .hud-label {
    font-size: 0.65em;
  }
  .hud-value {
    margin-right: 8px;
  }
  .controls-overlay {
    margin-top: 8px;
  }
  .control-btn {
    width: clamp(36px, 8vw, 44px);
    height: clamp(36px, 8vw, 44px);
    font-size: clamp(0.9rem, 3vw, 1.1rem);
  }
  .btn-arcade {
    padding: 8px 16px;
    font-size: 0.9rem;
  }
  .btn-arcade-lg {
    padding: 10px 24px;
    font-size: 1rem;
  }
  #powerupOverlay {
    top: 12px;
    right: 12px;
    min-width: 80px;
    max-width: 150px;
  }
  .powerup-item {
    font-size: clamp(10px, 1.6vw, 12px);
    padding: 4px 10px;
  }
  /* Boss health bar tablet */
  #bossHealthBar {
    top: 60px;
    padding: 6px 14px;
    min-width: 140px;
  }
}

/* Mobile portrait */
@media (max-width: 600px) {
  .hud-container {
    flex-direction: column;
    align-items: stretch;
    gap: 4px 0;
    padding: 6px 12px;
    font-size: clamp(0.65rem, 2.5vw, 0.9rem);
  }
  .hud-left,
  .hud-right {
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 2px 6px;
  }
  .hud-label {
    font-size: 0.6em;
    margin-right: 0;
  }
  .hud-value {
    margin-right: 6px;
    font-size: 0.9em;
  }
  .game-container {
    padding: 4px;
    border-width: 1px;
  }
  .game-border {
    border-width: 2px;
  }
  .controls-overlay {
    margin-top: 6px;
  }
  .control-btn {
    width: clamp(32px, 12vw, 44px);
    height: clamp(32px, 12vw, 44px);
    font-size: clamp(0.8rem, 4vw, 1rem);
  }
  .game-actions {
    gap: 8px;
  }
  .btn-arcade-sm {
    padding: 4px 12px;
    font-size: 0.8rem;
  }
  .overlay .arcade-panel {
    padding: 20px 24px;
  }
  #powerupOverlay {
    top: 8px;
    right: 8px;
    min-width: 70px;
    max-width: 120px;
    gap: 4px;
  }
  .powerup-item {
    font-size: clamp(9px, 1.4vw, 11px);
    padding: 3px 8px;
    border-radius: 6px;
    gap: 4px;
  }
  .powerup-item .icon {
    font-size: 1em;
  }
  .powerup-item .timer {
    min-width: 24px;
  }
  /* Boss health bar mobile */
  #bossHealthBar {
    top: 50px;
    padding: 4px 12px;
    min-width: 120px;
  }
  .boss-health-label {
    font-size: clamp(10px, 1.8vw, 13px);
  }
  .boss-health-track {
    height: clamp(6px, 1.2vw, 10px);
  }
  .boss-health-text {
    font-size: clamp(8px, 1.2vw, 11px);
  }
}

/* Very small phones (≤ 400px) */
@media (max-width: 400px) {
  .hud-container {
    font-size: clamp(0.55rem, 2vw, 0.75rem);
    padding: 4px 8px;
    border-radius: 8px;
  }
  .hud-left,
  .hud-right {
    gap: 1px 4px;
  }
  .hud-label {
    font-size: 0.55em;
    letter-spacing: 0.5px;
  }
  .hud-value {
    margin-right: 4px;
    font-size: 0.85em;
  }
  .control-btn {
    width: clamp(28px, 10vw, 36px);
    height: clamp(28px, 10vw, 36px);
    font-size: clamp(0.7rem, 3vw, 0.9rem);
    border-radius: 6px;
  }
  .game-actions .btn-arcade-sm {
    padding: 3px 10px;
    font-size: 0.7rem;
  }
  .overlay .arcade-panel {
    padding: 16px 20px;
    border-width: 2px;
    border-radius: 16px;
  }
  #powerupOverlay {
    top: 6px;
    right: 6px;
    min-width: 60px;
    max-width: 100px;
  }
  .powerup-item {
    font-size: clamp(8px, 1.2vw, 10px);
    padding: 2px 6px;
    border-radius: 4px;
  }
  .powerup-item .timer {
    min-width: 20px;
  }
  /* Boss health bar very small */
  #bossHealthBar {
    top: 40px;
    padding: 3px 8px;
    min-width: 100px;
  }
  .boss-health-label {
    font-size: clamp(8px, 1.5vw, 11px);
  }
  .boss-health-track {
    height: clamp(5px, 1vw, 8px);
  }
  .boss-health-text {
    font-size: clamp(7px, 1vw, 9px);
  }
}

/* Landscape mobile: reduce top/bottom padding */
@media (max-height: 500px) and (orientation: landscape) {
  .hud-container {
    padding: 4px 12px;
    margin-bottom: 4px;
    font-size: clamp(0.6rem, 1.5vw, 0.85rem);
  }
  .game-container {
    padding: 4px;
  }
  .controls-overlay {
    margin-top: 4px;
  }
  .control-btn {
    width: clamp(28px, 6vh, 40px);
    height: clamp(28px, 6vh, 40px);
    font-size: clamp(0.7rem, 2.5vh, 0.9rem);
  }
  .game-actions {
    margin-top: 4px;
  }
  .btn-arcade-sm {
    padding: 3px 10px;
    font-size: 0.7rem;
  }
  #powerupOverlay {
    top: 6px;
    right: 6px;
    gap: 4px;
  }
  .powerup-item {
    padding: 2px 8px;
    font-size: clamp(8px, 1.2vh, 11px);
  }
  /* Boss health bar landscape */
  #bossHealthBar {
    top: 40px;
    padding: 4px 12px;
    min-width: 120px;
  }
  .boss-health-label {
    font-size: clamp(9px, 1.5vh, 13px);
  }
  .boss-health-track {
    height: clamp(5px, 1vh, 10px);
  }
}

/* Desktop large screens: keep original size */
@media (min-width: 1200px) {
  .hud-container {
    font-size: 1.2rem;
  }
  .control-btn {
    width: 48px;
    height: 48px;
    font-size: 1.2rem;
  }
}
