/* === Reset & Base === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* === @font-face: Retro Pixel Font === */
@font-face {
  font-family: 'Press Start 2P';
  src: url('../assets/fonts/PressStart2P.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  background: var(--bg-color, #1a1a2e);
  color: var(--text-color, #eee);
  font-family: 'Press Start 2P', monospace;
}

/* === CSS Custom Properties (theming) === */
:root {
  --bg-color: #1a1a2e;
  --header-bg: rgba(0, 0, 0, 0.7);
  --text-color: #eee;
  --accent-color: #e94560;
  --slot-bg: rgba(255, 255, 255, 0.1);
  --slot-active: rgba(233, 69, 96, 0.5);
  --platform-color: #16213e;
  --player-color: #e94560;
  --enemy-color: #ff6b6b;
  --pickup-color: #ffd93d;
  --bullet-color: #4ecdc4;
  --shield-color: rgba(78, 205, 196, 0.4);
  --retro-font: 'Press Start 2P', monospace;
}

/* === Game Container === */
#game-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  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);
}

/* === Canvas === */
#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: block;
  background: #000;
}

/* === UI Overlay === */
#ui-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

#ui-overlay > * {
  pointer-events: auto;
}

/* === Header Zone === */
#header-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 48px;
  padding: 4px 8px;
  padding-top: calc(4px + env(safe-area-inset-top));
  background: var(--header-bg);
  z-index: 10;
  position: relative;
}

/* === Item Selector === */
#item-selector {
  display: flex;
  gap: 6px;
}

.weapon-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 40px;
  background: var(--slot-bg);
  border: 2px solid transparent;
  border-radius: 6px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  touch-action: manipulation;
  color: var(--text-color);
}

.weapon-slot.active {
  border-color: var(--accent-color);
  background: var(--slot-active);
}

.weapon-slot .ammo {
  font-size: 10px;
  opacity: 0.7;
}

/* === HUD === */
#hud {
  display: flex;
  gap: 16px;
  font-size: 14px;
  font-weight: bold;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* === Pause Button === */
#pause-btn {
  width: 40px;
  height: 40px;
  background: var(--slot-bg);
  border: none;
  border-radius: 6px;
  color: var(--text-color);
  font-size: 16px;
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* === Screens (menu, game over, wave transition) === */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  z-index: 20;
}

/* === Entry Gate === */
#entry-gate.screen {
  background: var(--bg-color, #1a1a2e);
}

.entry-border {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 40px 60px;
  border: 3px solid var(--accent-color, #e94560);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.6);
  min-width: 280px;
  min-height: 180px;
}

.entry-title {
  font-size: 28px;
  color: #fff;
  text-shadow: 0 0 10px var(--accent-color), 0 0 20px var(--accent-color);
}

.entry-btn {
  font-size: 16px;
  padding: 12px 32px;
}

.entry-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.entry-sprite {
  position: absolute;
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  pointer-events: none;
  z-index: 21;
}

/* Menu screen: background image, no dark overlay */
#menu-screen.screen {
  background: #000;
  background-image: url('../assets/backgrounds/home-screen.webp');
  background-size: 100% auto;
  background-position: top center;
  background-repeat: no-repeat;
  justify-content: flex-start;
}

/* Menu options container: positioned at bottom third of 16:9 image */
.menu-options-container {
  position: absolute;
  top: calc(100vw * 9 / 16 * 0.667);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(40, 40, 40, 0.75);
  padding: 5px;
  border-radius: 8px;
}

.menu-options-container .menu-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.screen.hidden {
  display: none;
}

.screen .hidden {
  display: none;
}

.screen h1 {
  font-size: 32px;
  margin-bottom: 16px;
}

.screen h2 {
  font-size: 24px;
  margin-bottom: 12px;
}

.screen p {
  font-size: 16px;
  margin-bottom: 24px;
  opacity: 0.8;
}

.screen .btn {
  padding: 12px 32px;
  margin: 8px;
  font-size: 18px;
  font-weight: bold;
  border: 2px solid var(--accent-color);
  background: transparent;
  color: var(--text-color);
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  min-width: 200px;
}

.screen .btn:active {
  background: var(--accent-color);
}

/* === Modal (pause) === */
.modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.9);
  z-index: 30;
}

.modal.hidden {
  display: none;
}

.modal .hidden {
  display: none;
}

.modal h2 {
  font-size: 24px;
  margin-bottom: 24px;
}

.modal .btn {
  padding: 12px 32px;
  margin: 8px;
  font-size: 16px;
  font-weight: bold;
  border: 2px solid var(--accent-color);
  background: transparent;
  color: var(--text-color);
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  min-width: 200px;
}

.modal .btn:active {
  background: var(--accent-color);
}

/* Pause modal view panels — vertical column layout */
.pause-main,
.pause-instructions,
.pause-options {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.modal .instructions-content,
.modal .options-content {
  max-width: 320px;
  text-align: left;
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 16px;
}

.modal .instructions-content {
  max-height: 60vh;
  overflow-y: auto;
}

.modal .instructions-content h3,
.modal .options-content h3 {
  font-size: 16px;
  margin-bottom: 8px;
  color: var(--accent-color);
}

/* === Wave Transition === */
#wave-transition {
  font-size: 24px;
  font-weight: bold;
  text-shadow: 0 0 10px var(--accent-color);
}

#wave-transition .countdown {
  font-size: 48px;
  margin-top: 16px;
  text-shadow: 0 0 20px var(--accent-color);
}

/* === Leaderboard === */
.leaderboard-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.95);
  z-index: 25;
}

.leaderboard-screen.hidden {
  display: none;
}

.leaderboard-table {
  border-collapse: collapse;
  font-size: 10px;
  max-height: 60vh;
  overflow-y: auto;
  display: block;
  margin-bottom: 16px;
}

.leaderboard-table thead {
  position: sticky;
  top: 0;
  background: #1a1a2e;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 6px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(233, 69, 96, 0.3);
  color: var(--text-color);
}

.leaderboard-table th {
  color: var(--accent-color);
  text-transform: uppercase;
  font-size: 8px;
}

/* === Character Select === */
#character-select-screen h1 {
  font-size: 20px;
  margin-bottom: 24px;
  text-shadow: 0 0 10px var(--accent-color);
}

.character-cards {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.character-card {
  width: 200px;
  padding: 16px;
  border: 2px solid var(--accent-color);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.7);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.character-card:hover,
.character-card:active {
  border-color: #fff;
  box-shadow: 0 0 15px var(--accent-color);
}

.character-card h2 {
  font-size: 12px;
  margin-bottom: 8px;
  color: var(--accent-color);
}

.character-card .char-desc {
  font-size: 8px;
  line-height: 1.6;
  opacity: 0.8;
}

/* === Theme Options === */
.theme-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  margin: 4px 0;
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
  color: var(--text-color);
  background: var(--slot-bg);
}

.theme-option.active {
  border-color: var(--accent-color);
}

.theme-swatch {
  width: 24px;
  height: 24px;
  border-radius: 4px;
}

/* === Volume Control === */
.volume-control {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

/* === Quality Control === */
.quality-control {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

#volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 6px;
  border-radius: 3px;
  background: var(--slot-bg);
  outline: none;
}

#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-color);
  cursor: pointer;
}

#quality-slider,
#menu-quality-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 6px;
  border-radius: 3px;
  background: var(--slot-bg);
  outline: none;
}

#quality-slider::-webkit-slider-thumb,
#menu-quality-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-color);
  cursor: pointer;
}

#quality-label,
#menu-quality-label {
  font-size: 10px;
  min-width: 80px;
  color: var(--text-color);
}

#mute-toggle {
  background: none;
  border: 1px solid var(--accent-color);
  color: var(--accent-color);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--retro-font);
  font-size: 8px;
}

/* === Weapon Icons === */
.weapon-icon {
  width: 20px;
  height: 20px;
  image-rendering: pixelated;
}

/* === Retro Glow Effects === */
.screen h1,
.modal-content h2 {
  text-shadow: 0 0 10px var(--accent-color), 0 0 20px var(--accent-color);
}

.btn {
  text-shadow: 0 0 2px currentColor;
  box-shadow: 0 0 8px rgba(233, 69, 96, 0.3);
}

.btn:hover,
.btn:active {
  box-shadow: 0 0 16px var(--accent-color);
}

/* ── Menu main & subview layout ── */

.menu-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#menu-screen .menu-main .btn {
  min-width: unset;
  font-size: 14px;
  padding: 10px 16px;
  margin: 0;
}

.menu-subview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-height: 80vh;
  overflow-y: auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.85);
  padding: 24px;
  border-radius: 8px;
}

.menu-subview.hidden {
  display: none;
}

/* ── Game over main & subview layout ── */

.go-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.go-subview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-height: 80vh;
  overflow-y: auto;
}

.go-subview.hidden {
  display: none;
}

/* ── Pause confirm panel ── */

.pause-confirm {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* ── Save summary ── */

#save-summary {
  text-align: left;
  width: 100%;
  max-width: 300px;
}

#save-summary p {
  margin: 4px 0;
  font-size: 0.85em;
}
