* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  background: #000;
  color: #fff;
  font-family: system-ui, -apple-system, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport */
  overflow: hidden;
  touch-action: none;
  margin: 0;
}

#game-container {
  position: relative;
  border: 1px solid #222;
  border-radius: 4px;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
  width: min(92vw, 800px);
  height: min(92vw, 800px);
  max-width: 800px;
  max-height: 800px;
  background: #000;
}

canvas {
  display: block;
  background: #000;
  touch-action: none;
}

/* Desktop default */
#game-container canvas {
  width: 100%;
  height: 100%;
}

#ui {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
}

#score {
  font-family: monospace;
  font-size: 22px;
  letter-spacing: 3px;
  color: #0f0;
  text-shadow: 0 0 8px #0f0;
}

.fullscreen-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.4);
  border: 1px solid #0f0;
  color: #0f0;
  width: 32px;
  height: 32px;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  z-index: 50;
  pointer-events: auto;
}

.fullscreen-btn:active {
  background: rgba(0,255,0,0.2);
}

#lives {
  display: flex;
  gap: 6px;
}

.life {
  width: 14px;
  height: 11px;
  border: 2px solid #0f0;
  border-radius: 1px;
  background: transparent;
}

/* Touch Controls */
#touch-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: none; /* Hidden by default, shown via JS or media query */
  flex-direction: column;
  align-items: center;
  padding: 8px;
  gap: 6px;
  pointer-events: auto;
}

.touch-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 0 12px;
}

.touch-btn {
  background: rgba(20, 20, 25, 0.65);
  border: 2px solid #0f0;
  color: #0f0;
  font-size: 24px;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-btn:active {
  background: rgba(0, 255, 0, 0.2);
  transform: scale(0.95);
}

#btn-fire {
  font-size: 15px;
  letter-spacing: 2px;
  width: 160px;
  height: 56px;
  margin-top: 4px;
}

#btn-fire:active {
  background: rgba(255, 100, 0, 0.3);
  border-color: #f80;
  color: #f80;
}

@media (max-width: 768px) {
  body {
    align-items: stretch;
    justify-content: stretch;
    background: #000;
  }

  #game-container {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #game-container canvas {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: calc(100% - 70px); /* leave room for buttons */
  }

  #touch-controls {
    display: flex;
    padding-bottom: env(safe-area-inset-bottom, 8px);
  }

  .desktop-only {
    display: none;
  }
  
  .mobile-only {
    display: block;
  }

  #score {
    font-size: 16px;
  }

  .fullscreen-btn {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .touch-btn {
    width: 68px;
    height: 68px;
    font-size: 26px;
  }

  #btn-fire {
    width: 180px;
    height: 60px;
    font-size: 14px;
  }

  .overlay {
    padding: 12px;
  }

  h1 {
    font-size: 42px;
    letter-spacing: 6px;
  }
}

@media (min-width: 769px) {
  .mobile-only {
    display: none;
  }
  .fullscreen-btn {
    display: none;
  }
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.78);
  z-index: 40;
  text-align: center;
  padding: 20px;
}

.overlay.hidden {
  display: none;
}

h1 {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: 8px;
  margin-bottom: 8px;
}

p {
  color: #888;
  margin-bottom: 20px;
  line-height: 1.5;
  font-size: 14px;
}

button {
  background: transparent;
  color: #0f0;
  border: 2px solid #0f0;
  padding: 10px 36px;
  font-size: 16px;
  letter-spacing: 2px;
  cursor: pointer;
  transition: all 0.1s ease;
  font-family: inherit;
}

button:hover {
  background: #0f0;
  color: #000;
}

#final-score {
  font-family: monospace;
  font-size: 26px;
  color: #0f0;
  margin-bottom: 24px;
  letter-spacing: 3px;
}

.hint {
  font-size: 12px;
  margin-top: 12px;
  color: #555;
}