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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #1a1a2e;
  color: #e8e8e8;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Start Screen */
#start-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  z-index: 100;
}

#start-screen h1 {
  font-size: 2.5rem;
  font-weight: 700;
  color: #00d9ff;
  text-shadow: 0 0 20px rgba(0, 217, 255, 0.5);
  margin-bottom: 1rem;
}

#start-screen .goal {
  font-size: 1.25rem;
  color: #ffd700;
  margin-bottom: 0.5rem;
}

#start-screen .best-wave {
  font-size: 1rem;
  color: #7fdbca;
  margin-bottom: 2rem;
}

#start-screen .controls-info {
  background: rgba(0, 0, 0, 0.3);
  padding: 1.5rem 2rem;
  border-radius: 12px;
  margin-bottom: 2rem;
  max-width: 500px;
}

#start-screen .controls-info h3 {
  color: #00d9ff;
  margin-bottom: 0.75rem;
}

#start-screen .controls-info ul {
  list-style: none;
  font-size: 0.9rem;
  line-height: 1.8;
  color: #b8b8b8;
}

#start-screen .controls-info ul li span {
  color: #ffd700;
  font-weight: 600;
}

#start-btn {
  padding: 1rem 3rem;
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, #00d9ff 0%, #0099cc 100%);
  color: #1a1a2e;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

#start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 217, 255, 0.4);
}

/* HUD */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: none;
  padding: 1rem 1.5rem;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.7) 0%, transparent 100%);
  z-index: 10;
}

#hud.visible {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.hud-stats {
  display: flex;
  gap: 2rem;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  font-size: 0.75rem;
  color: #888;
  text-transform: uppercase;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-value.gold { color: #ffd700; }
.stat-value.lives { color: #ff6b6b; }
.stat-value.wave { color: #00d9ff; }

.hud-controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

#start-wave-btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
  color: #1a1a2e;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

#start-wave-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(74, 222, 128, 0.4);
}

#start-wave-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.speed-btn, .pause-btn {
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.1);
  color: #e8e8e8;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.speed-btn:hover, .pause-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.speed-btn.active {
  background: rgba(0, 217, 255, 0.3);
  border-color: #00d9ff;
}

.pause-btn.paused {
  background: rgba(255, 215, 0, 0.3);
  border-color: #ffd700;
}

/* Tower Selection Bar */
#tower-bar {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 10;
}

#tower-bar.visible {
  display: flex;
}

.tower-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 100px;
}

.tower-option:hover {
  background: rgba(255, 255, 255, 0.1);
}

.tower-option.selected {
  border-color: #00d9ff;
  background: rgba(0, 217, 255, 0.15);
}

.tower-option.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tower-icon {
  width: 40px;
  height: 40px;
  margin-bottom: 0.5rem;
}

.tower-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #e8e8e8;
  margin-bottom: 0.25rem;
}

.tower-cost {
  font-size: 0.8rem;
  color: #ffd700;
}

.tower-key {
  font-size: 0.7rem;
  color: #888;
  margin-top: 0.25rem;
}

/* Tower Info Panel */
#tower-panel {
  position: absolute;
  display: none;
  padding: 1rem 1.25rem;
  background: rgba(0, 0, 0, 0.9);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  z-index: 15;
  min-width: 180px;
}

#tower-panel.visible {
  display: block;
}

#tower-panel h4 {
  font-size: 1rem;
  color: #00d9ff;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 0.5rem;
}

.panel-stats {
  margin-bottom: 1rem;
}

.panel-stat {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

.panel-stat-label { color: #888; }
.panel-stat-value { color: #e8e8e8; }

.panel-buttons {
  display: flex;
  gap: 0.5rem;
}

.panel-btn {
  flex: 1;
  padding: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.2s;
}

.panel-btn:hover:not(:disabled) {
  transform: scale(1.05);
}

.panel-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.upgrade-btn {
  background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
  color: white;
}

.sell-btn {
  background: rgba(255, 107, 107, 0.2);
  color: #ff6b6b;
  border: 1px solid #ff6b6b;
}

.sell-refund {
  font-size: 0.7rem;
  color: #888;
  text-align: center;
  margin-top: 0.25rem;
}

/* Wave Preview */
#wave-preview {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  padding: 1.5rem 2rem;
  background: rgba(0, 0, 0, 0.9);
  border-radius: 16px;
  border: 2px solid #00d9ff;
  z-index: 20;
  text-align: center;
}

#wave-preview.visible {
  display: block;
}

#wave-preview h3 {
  font-size: 1.25rem;
  color: #00d9ff;
  margin-bottom: 1rem;
}

.wave-enemies {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin-bottom: 1rem;
}

.wave-enemy {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.enemy-count {
  font-size: 1.5rem;
  font-weight: 700;
  color: #ffd700;
}

.enemy-type {
  font-size: 0.8rem;
  color: #888;
  text-transform: uppercase;
}

/* End Screens */
#end-screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  z-index: 50;
}

#end-screen.visible {
  display: flex;
}

#end-screen h2 {
  font-size: 3rem;
  margin-bottom: 1.5rem;
}

#end-screen.victory h2 {
  color: #4ade80;
  text-shadow: 0 0 30px rgba(74, 222, 128, 0.6);
}

#end-screen.defeat h2 {
  color: #ff6b6b;
  text-shadow: 0 0 30px rgba(255, 107, 107, 0.6);
}

.end-stats {
  background: rgba(255, 255, 255, 0.05);
  padding: 1.5rem 2.5rem;
  border-radius: 12px;
  margin-bottom: 2rem;
}

.end-stat {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.end-stat-label { color: #888; }
.end-stat-value { color: #ffd700; font-weight: 600; }

#restart-btn {
  padding: 1rem 3rem;
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, #00d9ff 0%, #0099cc 100%);
  color: #1a1a2e;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

#restart-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 217, 255, 0.4);
}

/* Invalid placement feedback */
#feedback {
  position: absolute;
  padding: 0.75rem 1.25rem;
  background: rgba(255, 107, 107, 0.9);
  color: white;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 30;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

#feedback.visible {
  opacity: 1;
}

/* Gold popup */
.gold-popup {
  position: absolute;
  color: #ffd700;
  font-size: 0.9rem;
  font-weight: 700;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  animation: goldFloat 1s ease-out forwards;
  z-index: 25;
}

@keyframes goldFloat {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-40px); }
}

/* Pause overlay */
#pause-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 40;
}

#pause-overlay.visible {
  display: flex;
}

#pause-overlay h2 {
  font-size: 3rem;
  color: #ffd700;
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .gold-popup {
    animation: none;
    opacity: 0.5;
  }
  
  #start-btn:hover,
  #start-wave-btn:hover,
  #restart-btn:hover,
  .panel-btn:hover {
    transform: none;
  }
}

/* Keyboard focus styles */
button:focus-visible, .tower-option:focus-visible {
  outline: 2px solid #00d9ff;
  outline-offset: 2px;
}
