*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; touch-action: manipulation; -ms-touch-action: manipulation; }
html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0a0a1a;
  font-family: 'Press Start 2P', monospace;
  color: #fff;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body::after {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.06) 2px, rgba(0,0,0,0.06) 4px);
  pointer-events: none;
  z-index: 9999;
}

#gameContainer {
  width: 100vw; height: 100vh; height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

#hud {
  width: 100%; max-width: 500px;
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 6px 52px 6px 10px;
  font-size: 10px;
  color: #0ff;
  text-shadow: 0 0 8px #0ff;
  flex-shrink: 0;
  z-index: 10;
}
#hud.visible { display: flex; }
#hud .hud-item { display: flex; align-items: center; gap: 5px; }
#hud .hud-item i { font-size: 13px; }
#hud .hud-value { color: #ff0; text-shadow: 0 0 8px #ff0; }

/* Power-up timer bar */
#hudPowerBar {
  width: 50px; height: 6px;
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
  overflow: hidden;
}
#hudPowerFill {
  height: 100%;
  width: 100%;
  border-radius: 3px;
  background: #0ff;
  transition: width 0.1s linear, background 0.3s;
}

/* Game Over red overlay */
#gameOverFlash {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  display: none; align-items: center; justify-content: center;
  z-index: 38; pointer-events: none;
  flex-direction: column; gap: 10px;
}
#gameOverFlash.active { display: flex; }
#gameOverFlash .go-bg {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(180,0,0,0);
  transition: background 0.5s;
}
#gameOverFlash.active .go-bg { background: rgba(180,0,0,0.55); }
#gameOverFlash .go-text {
  font-family: 'Orbitron', sans-serif; font-weight: 900;
  font-size: clamp(28px, 8vw, 56px);
  color: #f44; text-shadow: 0 0 30px #f00, 0 0 60px #a00;
  position: relative; z-index: 1;
  opacity: 0; transition: opacity 0.4s;
}
#gameOverFlash.active .go-text { opacity: 1; }

#muteBtn {
  position: fixed;
  top: 8px; right: 10px;
  background: rgba(0,0,0,0.7);
  border: 2px solid #f44;
  color: #f44;
  font-size: 18px;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  z-index: 10000;
  text-shadow: 0 0 8px #f44;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, color 0.15s, text-shadow 0.15s;
}
#muteBtn:active { transform: scale(0.88); background: rgba(0,255,255,0.2); }

#gameCanvas {
  border: 2px solid #333;
  border-radius: 4px;
  box-shadow: 0 0 20px rgba(0,255,255,0.15), inset 0 0 40px rgba(0,0,0,0.5);
  background: #05051a;
  flex-shrink: 0;
  display: none;
  cursor: none;
}
#gameCanvas.visible { display: block; }

#controls {
  width: 100%; max-width: 500px;
  display: none;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  flex-shrink: 0;
  z-index: 10;
}
#controls.visible { display: flex; }

.ctrl-group { display: flex; gap: 10px; align-items: center; }

.ctrl-btn {
  border: 2.5px solid;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ctrl-btn:active { transform: scale(0.93); }

/* Directional pads — wide rectangles */
.ctrl-dir {
  width: 72px; height: 56px;
  border-radius: 14px;
  font-size: 22px;
}

.ctrl-left { border-color: #f0f; color: #f0f; text-shadow: 0 0 10px #f0f; }
.ctrl-left:active { background: rgba(255,0,255,0.3); }
.ctrl-right { border-color: #f0f; color: #f0f; text-shadow: 0 0 10px #f0f; }
.ctrl-right:active { background: rgba(255,0,255,0.3); }

/* Action buttons — round */
.ctrl-round {
  width: 54px; height: 54px;
  border-radius: 50%;
  font-size: 20px;
}
.ctrl-pause { border-color: #ff0; color: #ff0; text-shadow: 0 0 10px #ff0; }
.ctrl-pause:active { background: rgba(255,255,0,0.3); }
.ctrl-fire { border-color: #f44; color: #f44; text-shadow: 0 0 10px #f44; width: 58px; height: 58px; font-size: 22px; }
.ctrl-fire:active { background: rgba(255,68,68,0.3); }

/* ================== INTRO ================== */
#introScreen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #1a0a2e 0%, #0a0a1a 70%);
  z-index: 50;
  padding: 20px;
  text-align: center;
}
.stars { position: absolute; width: 100%; height: 100%; overflow: hidden; pointer-events: none; }
.star {
  position: absolute; background: #fff; border-radius: 50%;
  animation: twinkle 3s ease-in-out infinite;
}
@keyframes twinkle { 0%, 100% { opacity: 0.15; } 50% { opacity: 1; } }

#introScreen h1 {
  font-family: 'Orbitron', sans-serif;
  font-weight: 900;
  font-size: clamp(30px, 9vw, 60px);
  background: linear-gradient(180deg, #ff0 0%, #f80 40%, #f44 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 20px rgba(255,136,0,0.6));
  margin-bottom: 6px;
  letter-spacing: 4px;
  position: relative; z-index: 2;
}
#introScreen .subtitle {
  font-size: clamp(10px, 2.5vw, 16px);
  color: #0ff;
  text-shadow: 0 0 15px #0ff;
  margin-bottom: 35px;
  letter-spacing: 3px;
  position: relative; z-index: 2;
}

.intro-buttons {
  display: flex; flex-direction: column; gap: 14px; align-items: center;
  position: relative; z-index: 2; margin-bottom: 30px;
}

.start-btn, .scores-intro-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(13px, 3vw, 19px);
  padding: 16px 44px;
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  -webkit-tap-highlight-color: transparent;
  min-width: 250px;
  justify-content: center;
}
.start-btn:active, .scores-intro-btn:active { transform: scale(0.94); }

.start-btn {
  background: linear-gradient(180deg, #4a0, #280);
  border: 3px solid #6f0;
  color: #fff;
  text-shadow: 0 0 10px #6f0;
  box-shadow: 0 0 30px rgba(102,255,0,0.3), inset 0 2px 0 rgba(255,255,255,0.2);
  animation: pulse 1.5s ease-in-out infinite;
}
.scores-intro-btn {
  background: linear-gradient(180deg, #a60, #640);
  border: 3px solid #fa0;
  color: #fff;
  text-shadow: 0 0 10px #fa0;
  box-shadow: 0 0 20px rgba(255,170,0,0.2), inset 0 2px 0 rgba(255,255,255,0.2);
  font-size: clamp(11px, 2.5vw, 15px);
  padding: 13px 36px;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(102,255,0,0.3); }
  50% { box-shadow: 0 0 40px rgba(102,255,0,0.6), 0 0 60px rgba(102,255,0,0.2); }
}

.intro-info {
  font-size: clamp(8px, 2vw, 11px);
  color: #888; line-height: 2.2;
  max-width: 340px;
  position: relative; z-index: 2;
}
.intro-info i { color: #0ff; margin: 0 3px; }

/* ================== OVERLAY ================== */
#overlay {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.88);
  z-index: 40; padding: 20px; text-align: center;
  gap: 6px;
  overflow-y: auto;
}
#overlay.active { display: flex; }
#overlay h2 {
  font-family: 'Orbitron', sans-serif; font-weight: 900;
  font-size: clamp(22px, 6vw, 44px); margin-bottom: 8px;
}
#overlay .score-display {
  font-size: clamp(13px, 3.5vw, 22px);
  color: #ff0; text-shadow: 0 0 10px #ff0; margin-bottom: 10px;
}
#overlayNameArea {
  margin: 8px 0 4px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  width: 100%; max-width: 260px;
}
#overlayNameArea button { width: 100%; justify-content: center; }
#overlay .overlay-btns {
  display: flex; flex-direction: column; gap: 14px; align-items: center;
  margin-top: 10px; width: 100%; max-width: 260px;
}
#overlay .overlay-btns button { width: 100%; justify-content: center; }
#overlay button, #scoresScreen button {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(9px, 2.2vw, 13px);
  padding: 14px 24px; border-radius: 6px; cursor: pointer; border: 2px solid;
  -webkit-tap-highlight-color: transparent;
  display: flex; align-items: center; gap: 6px;
}

.btn-continue { background: linear-gradient(180deg, #06a, #048); border-color: #0af !important; color: #fff; text-shadow: 0 0 8px #0af; }
.btn-restart  { background: linear-gradient(180deg, #a00, #600); border-color: #f44 !important; color: #fff; text-shadow: 0 0 8px #f44; }
.btn-scores   { background: linear-gradient(180deg, #a60, #640); border-color: #fa0 !important; color: #fff; text-shadow: 0 0 8px #fa0; }

/* ================== HIGH SCORES ================== */
#scoresScreen {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  display: none; flex-direction: column; align-items: center; justify-content: flex-start;
  background: radial-gradient(ellipse at center, #1a0a2e 0%, #0a0a1a 70%);
  z-index: 55; padding: 18px; overflow-y: auto;
}
#scoresScreen.active { display: flex; }
#scoresScreen h2 {
  font-family: 'Orbitron', sans-serif; font-weight: 900;
  font-size: clamp(18px, 5vw, 34px);
  color: #ff0; text-shadow: 0 0 15px #ff0;
  margin: 12px 0 18px; display: flex; align-items: center; gap: 10px;
}

.scores-table { width: 100%; max-width: 420px; border-collapse: collapse; margin-bottom: 18px; }
.scores-table th {
  font-size: clamp(8px, 2vw, 11px); color: #0ff; text-shadow: 0 0 8px #0ff;
  padding: 8px 4px; border-bottom: 2px solid #0ff; text-align: left;
}
.scores-table td {
  font-size: clamp(9px, 2.2vw, 13px); padding: 9px 4px;
  border-bottom: 1px solid #222; color: #bbb;
}
.scores-table tr:nth-child(1) td { color: #ff0; text-shadow: 0 0 8px #ff0; }
.scores-table tr:nth-child(2) td { color: #ddd; text-shadow: 0 0 5px #aaa; }
.scores-table tr:nth-child(3) td { color: #c84; text-shadow: 0 0 5px #c84; }
.scores-table .rank { color: #f0f; text-shadow: 0 0 8px #f0f; width: 35px; }

#nameInput {
  font-family: 'Press Start 2P', monospace; font-size: 16px;
  padding: 10px 16px; background: #111; border: 2px solid #0ff;
  color: #0ff; text-align: center; border-radius: 6px;
  width: 100%; margin: 0; text-transform: uppercase;
  touch-action: auto; user-select: text; -webkit-user-select: text;
}
#nameInput::placeholder { color: #066; font-size: 9px; }

#pauseOverlay {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.7); z-index: 35;
  flex-direction: column;
}
#pauseOverlay.active { display: flex; }
.pause-content {
  display: flex; flex-direction: column; align-items: center; gap: 28px;
}
.pause-title {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(26px, 8vw, 52px);
  color: #ff0; text-shadow: 0 0 25px #ff0;
  animation: blink 1s step-end infinite;
}
.pause-resume-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(12px, 3vw, 18px);
  padding: 16px 36px;
  background: linear-gradient(180deg, #06a, #048);
  border: 3px solid #0af;
  border-radius: 8px;
  color: #fff;
  text-shadow: 0 0 10px #0af;
  box-shadow: 0 0 25px rgba(0,170,255,0.3), inset 0 2px 0 rgba(255,255,255,0.2);
  cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  -webkit-tap-highlight-color: transparent;
  animation: pulse-resume 1.5s ease-in-out infinite;
}
.pause-resume-btn:active { transform: scale(0.94); }
@keyframes pulse-resume {
  0%, 100% { box-shadow: 0 0 20px rgba(0,170,255,0.3); }
  50% { box-shadow: 0 0 40px rgba(0,170,255,0.6), 0 0 60px rgba(0,170,255,0.2); }
}
@keyframes blink { 50% { opacity: 0; } }

#levelAnnounce {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Orbitron', sans-serif; font-weight: 900;
  font-size: clamp(22px, 7vw, 44px);
  color: #0ff; text-shadow: 0 0 30px #0ff, 0 0 60px #06f;
  z-index: 30; display: none; text-align: center; pointer-events: none;
}

/* ================== KEYBOARD DISPLAY (Desktop) ================== */
#keyboardDisplay {
  display: none;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  width: 100%; max-width: 600px;
  flex-shrink: 0; z-index: 10;
}
#keyboardDisplay.visible { display: flex; }

.kb-key {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #2a2a3a 0%, #1a1a28 100%);
  border: 2px solid #444;
  border-bottom-width: 4px;
  border-radius: 6px;
  color: #888;
  font-family: 'Press Start 2P', monospace;
  transition: all 0.08s;
  position: relative;
}
.kb-key .kb-label {
  font-size: 7px;
  color: #555;
  margin-top: 2px;
}
.kb-key.active {
  border-color: #0ff;
  border-bottom-width: 2px;
  transform: translateY(2px);
  color: #0ff;
  text-shadow: 0 0 10px #0ff;
  background: linear-gradient(180deg, #1a2a3a 0%, #0a1828 100%);
  box-shadow: 0 0 12px rgba(0,255,255,0.3);
}
.kb-key.active .kb-label { color: #0ff; }

.kb-arrow { width: 56px; height: 48px; font-size: 18px; }
.kb-space { width: 140px; height: 44px; font-size: 11px; }
.kb-small { width: 48px; height: 44px; font-size: 12px; }

.kb-key.active.kb-fire { border-color: #f44; color: #f44; text-shadow: 0 0 10px #f44; box-shadow: 0 0 12px rgba(255,68,68,0.3); }
.kb-key.active.kb-fire .kb-label { color: #f44; }
.kb-key.active.kb-pause { border-color: #ff0; color: #ff0; text-shadow: 0 0 10px #ff0; box-shadow: 0 0 12px rgba(255,255,0,0.3); }
.kb-key.active.kb-pause .kb-label { color: #ff0; }
.kb-key.active.kb-left, .kb-key.active.kb-right { border-color: #f0f; color: #f0f; text-shadow: 0 0 10px #f0f; box-shadow: 0 0 12px rgba(255,0,255,0.3); }
.kb-key.active.kb-left .kb-label, .kb-key.active.kb-right .kb-label { color: #f0f; }

@media (min-width: 768px) {
  /* Hide mobile controls on desktop */
  #controls.visible { display: none !important; }
  #keyboardDisplay.visible { display: flex !important; }
  #hud { font-size: 12px; padding: 8px 12px; }
}
@media (max-width: 767px) {
  /* Hide keyboard display on mobile */
  #keyboardDisplay { display: none !important; }
}
