* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a0a;
  color: #00ffe1;
  font-family: 'Orbitron', 'Arial', sans-serif;
  -ms-touch-action: none;
  touch-action: none;
}

/* ===========================
   SCREEN MANAGEMENT
   =========================== */
.screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
  z-index: 10;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

.screen.overlay {
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(10px);
  z-index: 100;
}

/* ===========================
   MENU CONTENT
   =========================== */
.menu-content {
  text-align: center;
  padding: clamp(10px, 2vh, 24px) clamp(12px, 3vw, 32px);
  animation: fadeIn 0.4s ease-in;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  width: 100%;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===========================
   LOADING SCREEN
   =========================== */
.loading-content {
  text-align: center;
  padding: clamp(16px, 3vh, 40px);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.loader {
  width: min(300px, 70vw);
  height: 6px;
  background: rgba(0, 255, 225, 0.1);
  border-radius: 3px;
  margin: clamp(12px, 2.5vh, 40px) auto;
  overflow: hidden;
  border: 1px solid #00ffe1;
}

.loader-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #00ffe1, #00d4ff, #ff00c8);
  border-radius: 3px;
  animation: loading 2s ease-in-out forwards;
  box-shadow: 0 0 20px #00ffe1;
}

@keyframes loading {
  0%   { width: 0%; }
  100% { width: 100%; }
}

.loading-text {
  font-size: clamp(0.75rem, 2.5vw, 1.2rem);
  letter-spacing: 4px;
  margin-top: clamp(8px, 1.5vh, 20px);
  color: #00ffe1;
}

.dots {
  animation: dotAnimation 1.5s infinite;
}

@keyframes dotAnimation {
  0%, 20% { opacity: 1; }
  40%      { opacity: 0.5; }
  60%, 100%{ opacity: 1; }
}

/* ===========================
   TYPOGRAPHY
   =========================== */
.game-title {
  font-size: clamp(1.6rem, 6vw, 4rem);
  letter-spacing: clamp(3px, 1vw, 8px);
  margin-bottom: clamp(4px, 1vh, 10px);
  line-height: 1.1;
  animation: glow 3s ease-in-out infinite alternate;
}

@keyframes glow {
  from { text-shadow: 0 0 5px rgba(0,255,225,0.4), 0 0 8px rgba(0,212,255,0.2); }
  to   { text-shadow: 0 0 10px rgba(0,255,225,0.7), 0 0 16px rgba(0,212,255,0.4); }
}

.neon-line {
  width: 80%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #00ffe1, transparent);
  margin: clamp(6px, 1vh, 16px) auto;
  box-shadow: 0 0 5px rgba(0,255,225,0.4);
  flex-shrink: 0;
}

.game-subtitle {
  font-size: clamp(0.65rem, 2vw, 1rem);
  color: #ff00c8;
  letter-spacing: clamp(1px, 0.5vw, 3px);
  margin-bottom: clamp(8px, 2vh, 28px);
  text-shadow: 0 0 5px rgba(255,0,200,0.4);
}

h2 {
  font-size: clamp(1.2rem, 4vw, 2.4rem);
  margin-bottom: clamp(6px, 1.5vh, 20px);
  text-shadow: 0 0 8px rgba(0,255,225,0.5);
  letter-spacing: clamp(2px, 0.5vw, 4px);
  flex-shrink: 0;
}

/* ===========================
   BUTTONS
   =========================== */
.btn {
  padding: clamp(8px, 1.5vh, 14px) clamp(20px, 4vw, 40px);
  margin: clamp(4px, 0.8vh, 10px);
  font-size: clamp(0.7rem, 2vw, 1.1rem);
  font-weight: bold;
  letter-spacing: 2px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  font-family: inherit;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.btn::before {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 0; height: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.3);
  transform: translate(-50%,-50%);
  transition: width 0.6s, height 0.6s;
}

.btn:active::before { width: 300px; height: 300px; }

.btn-primary {
  background: linear-gradient(135deg, #00ffe1, #00d4ff);
  color: #000;
  box-shadow: 0 0 20px rgba(0,255,225,0.5);
}

.btn-primary:hover {
  box-shadow: 0 0 30px rgba(0,255,225,0.8);
  transform: translateY(-2px);
}

.btn-secondary {
  background: linear-gradient(135deg, #ff00c8, #c800ff);
  color: #fff;
  box-shadow: 0 0 20px rgba(255,0,200,0.5);
}

.btn-secondary:hover {
  box-shadow: 0 0 30px rgba(255,0,200,0.8);
  transform: translateY(-2px);
}

.btn-reward {
  background: linear-gradient(135deg, #ffd700, #ffaa00);
  color: #000;
  box-shadow: 0 0 20px rgba(255,215,0,0.5);
  animation: pulseGold 2s ease-in-out infinite;
}

.btn-reward:hover {
  box-shadow: 0 0 30px rgba(255,215,0,0.8);
  transform: translateY(-2px);
}

@keyframes pulseGold {
  0%,100% { box-shadow: 0 0 20px rgba(255,215,0,0.5); }
  50%     { box-shadow: 0 0 40px rgba(255,215,0,0.9); }
}

.btn-icon {
  background: rgba(0,255,225,0.2);
  border: 2px solid #00ffe1;
  color: #00ffe1;
  padding: clamp(4px, 0.8vh, 8px) clamp(8px, 1.5vw, 14px);
  margin: 0 3px;
  font-size: clamp(0.9rem, 2vw, 1.2rem);
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: rgba(0,255,225,0.4);
  box-shadow: 0 0 15px #00ffe1;
}

.btn-icon.muted {
  color: #ff00c8;
  border-color: #ff00c8;
  background: rgba(255,0,200,0.2);
}

/* ===========================
   HIGH SCORE
   =========================== */
.high-score {
  margin-top: clamp(6px, 1.5vh, 20px);
  font-size: clamp(0.7rem, 2vw, 1.1rem);
  color: #ffd700;
  text-shadow: 0 0 5px rgba(255,215,0,0.4);
  letter-spacing: 2px;
  flex-shrink: 0;
}

/* ===========================
   HOW TO PLAY
   =========================== */
.howtoplay-content {
  justify-content: center;
  gap: 0;
}

.instructions {
  text-align: left;
  width: min(480px, 90vw);
  padding: clamp(8px, 1.5vh, 16px) clamp(12px, 2vw, 20px);
  background: rgba(0,255,225,0.05);
  border: 1px solid #00ffe1;
  border-radius: 10px;
  margin-bottom: clamp(6px, 1.5vh, 16px);
  flex-shrink: 1;
}

.instructions p {
  margin: clamp(1px, 0.4vh, 5px) 0;
  font-size: clamp(0.6rem, 1.6vw, 0.95rem);
  line-height: 1.5;
}

.instructions strong {
  color: #ff00c8;
  display: inline-block;
  margin-top: clamp(2px, 0.5vh, 8px);
}

/* ===========================
   GAME SCREEN LAYOUT
   =========================== */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: clamp(4px, 1vh, 10px) clamp(4px, 1vw, 10px);
  box-sizing: border-box;
  overflow: hidden;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 600px;
  padding: clamp(4px, 0.8vh, 10px) clamp(8px, 1.5vw, 14px);
  margin-bottom: clamp(3px, 0.6vh, 8px);
  background: rgba(0,0,0,0.5);
  border: 2px solid #00ffe1;
  border-radius: 8px;
  flex-shrink: 0;
  flex-wrap: nowrap;
  gap: 4px;
}

.score-display,
.lives-display,
.level-display {
  font-size: clamp(0.55rem, 1.6vw, 1rem);
  font-weight: bold;
  letter-spacing: 1px;
  white-space: nowrap;
}

.score-display span { color: #ffd700; text-shadow: 0 0 5px rgba(255,215,0,0.4); }
.lives-display span { color: #ff00c8; text-shadow: 0 0 5px rgba(255,0,200,0.4); }
.level-display span { color: #00ffe1; text-shadow: 0 0 5px rgba(0,255,225,0.4); }

/* ===========================
   CANVAS WRAPPER
   =========================== */
.canvas-wrapper {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 600px;
  min-height: 0; /* critical for flex shrink */
  overflow: hidden;
}

canvas {
  background: #000;
  border: 3px solid #00ffe1;
  box-shadow: 0 0 25px #00ffe1, inset 0 0 50px rgba(0,255,225,0.1);
  border-radius: 8px;
  display: block;
  /* sizing handled by JS resizeCanvas() */
}

/* ===========================
   MOBILE CONTROLS
   =========================== */
.mobile-controls {
  display: none;
  justify-content: center;
  align-items: center;
  gap: clamp(8px, 2vw, 20px);
  width: 100%;
  max-width: 600px;
  flex-shrink: 0;
  padding: clamp(3px, 0.6vh, 8px) 0;
}

.mobile-btn {
  background: linear-gradient(135deg, #00ffe1, #00d4ff);
  color: #000;
  border: none;
  padding: clamp(10px, 2.5vh, 20px) clamp(16px, 4vw, 30px);
  font-size: clamp(1rem, 3vw, 1.5rem);
  font-weight: bold;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(0,255,225,0.5);
  transition: all 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  flex: 1;
  max-width: 120px;
}

.mobile-btn:active {
  transform: scale(0.95);
  box-shadow: 0 0 30px rgba(0,255,225,0.8);
}

#launchBtn {
  background: linear-gradient(135deg, #ff00c8, #c800ff);
  color: #fff;
  box-shadow: 0 0 20px rgba(255,0,200,0.5);
  max-width: 160px;
  flex: 2;
}

#launchBtn:active { box-shadow: 0 0 30px rgba(255,0,200,0.8); }

/* ===========================
   PAUSE & GAME OVER STATS
   =========================== */
.pause-stats,
.game-over-stats {
  margin: clamp(8px, 1.5vh, 24px) 0;
  padding: clamp(8px, 1.5vh, 18px) clamp(12px, 2vw, 24px);
  background: rgba(0,255,225,0.05);
  border: 1px solid #00ffe1;
  border-radius: 10px;
  flex-shrink: 0;
  width: min(400px, 90vw);
}

.pause-stats p,
.game-over-stats p {
  font-size: clamp(0.75rem, 2.5vw, 1.3rem);
  margin: clamp(4px, 0.8vh, 10px) 0;
  letter-spacing: 2px;
}

.game-over-title {
  color: #ff00c8;
  text-shadow: 0 0 8px rgba(255,0,200,0.5);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%,100% { transform: scale(1); }
  50%      { transform: scale(1.05); }
}

.final-score {
  font-size: clamp(1rem, 3vw, 1.7rem) !important;
  color: #ffd700;
  text-shadow: 0 0 8px rgba(255,215,0,0.5);
}

.high-score-text {
  color: #ffd700;
  font-size: clamp(0.9rem, 2.5vw, 1.4rem) !important;
  animation: celebrate 0.5s ease-in-out infinite alternate;
}

@keyframes celebrate {
  from { transform: scale(1); }
  to   { transform: scale(1.08); }
}

/* ===========================
   MOBILE: show controls
   =========================== */
@media (pointer: coarse), (max-width: 768px) {
  .mobile-controls {
    display: flex;
  }
}

/* ===========================
   COMPACT LAYOUT: short viewports
   e.g. 800x450 iframe
   =========================== */
@media (max-height: 520px) {
  .game-title {
    font-size: clamp(1.2rem, 4vw, 2.2rem);
    letter-spacing: 3px;
  }
  h2 { font-size: clamp(1rem, 3.5vw, 1.8rem); margin-bottom: 4px; }
  .neon-line { margin: 4px auto; }
  .game-subtitle { margin-bottom: 6px; }
  .instructions p { font-size: clamp(0.55rem, 1.4vw, 0.8rem); margin: 1px 0; }
  .instructions { padding: 6px 10px; margin-bottom: 6px; }
  .pause-stats, .game-over-stats { margin: 4px 0; padding: 6px 12px; }
  .pause-stats p, .game-over-stats p { margin: 2px 0; }
}

@media (max-height: 380px) {
  .instructions strong { margin-top: 1px; }
  .btn { padding: 5px 18px; font-size: 0.65rem; margin: 2px; }
}

/* ===========================
   MISC
   =========================== */
body, button, canvas {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}