* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Courier New', monospace;
  color: #0f0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* HUD */
#ui-overlay {
  position: absolute;
  top: 0; left: 0; right: 0;
  pointer-events: none;
  z-index: 10;
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
}

#score-display {
  font-size: 20px;
  text-shadow: 0 0 8px #0f0;
  letter-spacing: 2px;
}

#btn-pause {
  pointer-events: auto;
  background: none;
  border: 1px solid #555;
  color: #888;
  font-size: 14px;
  padding: 4px 10px;
  cursor: pointer;
  line-height: 1;
  letter-spacing: 2px;
}

#btn-pause:hover {
  border-color: #0f0;
  color: #0f0;
  background: transparent;
}

#hp-bar {
  position: relative;
  width: 140px;
  height: 16px;
  background: #300;
  border: 1px solid #555;
  border-radius: 2px;
}

#hp-fill {
  height: 100%;
  background: #0f0;
  width: 100%;
  transition: width 0.2s, background 0.3s;
}

#hp-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #fff;
  text-shadow: 0 0 4px #000;
}

#hud-row2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px 6px;
}

#wave-display {
  font-size: 13px;
  text-shadow: 0 0 6px #0ff;
}

#xp-bar {
  position: relative;
  width: 160px;
  height: 14px;
  background: #111;
  border: 1px solid #333;
  border-radius: 2px;
}

#xp-fill {
  height: 100%;
  background: linear-gradient(90deg, #080, #0f0);
  width: 0%;
  transition: width 0.3s;
}

#xp-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: #fff;
  text-shadow: 0 0 4px #000;
}

/* Buff bar */
#buff-bar {
  display: flex;
  gap: 6px;
  padding: 0 16px 6px;
  min-height: 24px;
}

.buff-icon {
  position: relative;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border: 1px solid #555;
  border-radius: 3px;
  overflow: hidden;
}

.buff-icon .buff-timer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0%;
  transition: height 0.1s linear;
  opacity: 0.3;
  pointer-events: none;
}

.buff-icon .buff-label {
  position: relative;
  z-index: 1;
  text-shadow: 0 0 4px #000;
}

/* Screens (shared) */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
  z-index: 20;
  padding: 24px;
  overflow-y: auto;
}

.screen h2 {
  font-size: 28px;
  text-shadow: 0 0 12px #0f0;
  margin-bottom: 20px;
  letter-spacing: 4px;
}

.overlay-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

/* Main menu */
#main-menu {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.9);
  z-index: 20;
}

#main-menu h1 {
  font-size: 52px;
  letter-spacing: 6px;
  margin-bottom: 8px;
  text-shadow: 0 0 20px #0f0, 0 0 40px #0a0;
}

#main-menu h1 span {
  color: #0ff;
  text-shadow: 0 0 20px #0ff, 0 0 40px #088;
}

#menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 32px;
}

button {
  background: transparent;
  border: 1px solid #0f0;
  color: #0f0;
  font-family: 'Courier New', monospace;
  font-size: 16px;
  padding: 12px 32px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 1px;
}

button:hover, button:focus {
  background: #0f0;
  color: #000;
  outline: none;
}

button.danger {
  border-color: #f44;
  color: #f44;
}

button.danger:hover {
  background: #f44;
  color: #000;
}

#high-score {
  margin-top: 24px;
  font-size: 14px;
  color: #555;
}

/* Wave select */
#wave-select-screen {
  padding: 16px;
  overflow-y: auto;
  justify-content: flex-start;
  touch-action: pan-y;
}

#wave-select-screen h2 {
  margin-bottom: 12px;
  flex-shrink: 0;
}

#wave-select-screen .back-btn {
  margin-top: 12px;
  flex-shrink: 0;
}

#wave-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  width: 100%;
}

#wave-grid .level-btn {
  width: 100%;
  aspect-ratio: 1;
  font-size: 14px;
  padding: 2px;
}

.level-btn.locked {
  border-color: #333;
  color: #333;
  cursor: not-allowed;
}

.level-btn.locked:hover {
  background: transparent;
  color: #333;
}

.level-btn.current {
  border-color: #ff0;
  color: #ff0;
}

/* Skills */
#sp-display {
  font-size: 16px;
  color: #ff0;
  margin-bottom: 16px;
}

#skills-screen {
  justify-content: flex-start;
  padding-top: 20px;
  touch-action: pan-y;
  overflow-y: auto;
}

#skills-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 400px;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  margin-bottom: 20px;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.skill-group-header {
  font-size: 14px;
  color: #0ff;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 8px;
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid #222;
}

.skill-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid #222;
  background: #0a0a0a;
}

.skill-icon {
  font-size: 24px;
  width: 36px;
  text-align: center;
}

.skill-info {
  flex: 1;
}

.skill-name {
  font-size: 14px;
  color: #0f0;
}

.skill-desc {
  font-size: 11px;
  color: #666;
}

.skill-level {
  font-size: 12px;
  color: #888;
  margin-top: 2px;
}

.skill-upgrade {
  font-size: 13px;
  padding: 6px 14px;
  min-width: 60px;
}

.skill-upgrade.maxed {
  border-color: #333;
  color: #333;
  cursor: default;
}

.skill-upgrade.maxed:hover {
  background: transparent;
  color: #333;
}

#skills-actions {
  margin-bottom: 16px;
}

/* Level complete / pause stats */
#complete-stats {
  font-size: 16px;
  color: #888;
  margin-bottom: 24px;
  text-align: center;
  line-height: 2;
}

/* Game over */
#game-over-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  z-index: 20;
}

#game-over-screen h1 {
  font-size: 48px;
  text-shadow: 0 0 20px #f44;
  margin-bottom: 16px;
}

#game-over-screen p {
  font-size: 16px;
  color: #888;
  margin-bottom: 8px;
}

#game-over-screen .overlay-buttons {
  margin-top: 16px;
}

/* Back button */
.back-btn {
  border-color: #555;
  color: #555;
}

.back-btn:hover {
  background: #555;
  color: #000;
}

/* Settings */
.settings-group {
  margin-bottom: 24px;
  text-align: center;
}

.settings-label {
  font-size: 16px;
  color: #0f0;
  margin-bottom: 12px;
}

.joystick-options {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 8px;
}

.joystick-opt {
  font-size: 14px;
  padding: 8px 16px;
  border: 1px solid #333;
  color: #666;
}

.joystick-opt.active {
  border-color: #0ff;
  color: #0ff;
  background: rgba(0, 255, 255, 0.1);
}

.joystick-opt:hover {
  background: rgba(0, 255, 255, 0.15);
  color: #0ff;
  border-color: #0ff;
}

.settings-btn {
  font-size: 14px;
  padding: 8px 16px;
  border: 1px solid #333;
  color: #666;
  background: transparent;
  cursor: pointer;
}

.settings-btn:hover {
  background: rgba(0, 255, 255, 0.15);
  color: #0ff;
  border-color: #0ff;
}

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

/* Update banner */
#update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: #0aa;
  color: #000;
  text-align: center;
  padding: 10px;
  font-family: 'Courier New', monospace;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
}

.hidden { display: none !important; }
