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

body {
  background: #06060e;
  color: #e0e0e0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
}

#app { position: relative; width: 960px; }

#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: linear-gradient(180deg, #141420 0%, #0e0e1a 100%);
  border: 1px solid #2a2a44;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  font-size: 14px;
}
#hud-left, #hud-right { display: flex; gap: 18px; }
#hud-center { font-weight: bold; color: #ffcc00; font-size: 16px; letter-spacing: 0.5px; }
#lives-info { color: #ff6666; font-weight: bold; }
#money-info { color: #44ff88; font-weight: bold; font-size: 15px; }
#wave-info, #zone-info { color: #8888aa; }

#game-area {
  display: flex;
  border: 1px solid #2a2a44;
  border-top: none;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
}

#game-canvas {
  display: block;
  cursor: crosshair;
  background: #0a0a14;
  flex-shrink: 0;
}

/* ── Side panel ── */
#side-panel {
  width: 160px;
  background: linear-gradient(180deg, #0e0e1a 0%, #0a0a14 100%);
  border-left: 1px solid #2a2a44;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.panel-header {
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 700;
  color: #8888aa;
  letter-spacing: 1px;
  border-bottom: 1px solid #1a1a30;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#help-btn {
  background: #1a1a30;
  border: 1px solid #2a2a44;
  color: #8888aa;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
#help-btn:hover { background: #2a2a44; color: #ffcc00; }

/* ── Tower cards ── */
#tower-list { flex: 1; }

.tower-card {
  padding: 6px 8px;
  border-bottom: 1px solid #1a1a30;
  cursor: grab;
  transition: background 0.12s;
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  user-select: none;
}
.tower-card:hover { background: #161628; }
.tower-card.selected { background: #1a1a10; border-left: 2px solid #ffcc00; }
.tower-card.disabled { opacity: 0.35; cursor: not-allowed; }

.card-icon {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  flex-shrink: 0;
}
.blaster-icon { background: radial-gradient(circle, #00ff88 30%, #006633); }
.freeze-icon { background: radial-gradient(circle, #00ccff 30%, #004466); }
.sniper-icon { background: radial-gradient(circle, #ffdd00 30%, #665500); }
.plasma-icon { background: radial-gradient(circle, #ff44ff 30%, #660066); }
.tesla-icon { background: radial-gradient(circle, #88bbff 30%, #334466); }
.missile-icon { background: radial-gradient(circle, #ff6622 30%, #662200); }
.beam-icon { background: radial-gradient(circle, #ff3366 30%, #661133); }
.pylon-icon { background: radial-gradient(circle, #aaffdd 30%, #336655); }

.card-info { flex: 1; min-width: 0; }
.card-name { font-size: 11px; font-weight: 600; color: #ddd; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-cost { color: #44ff88; }
.card-stats { font-size: 9px; color: #666; line-height: 1.3; }

.card-key {
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 9px;
  color: #444;
  background: #0a0a18;
  padding: 1px 4px;
  border-radius: 3px;
}

/* ── Upgrade panel ── */
#upgrade-panel {
  padding: 8px;
  border-top: 1px solid #2a2a44;
}
#upgrade-panel.hidden { display: none; }

#upgrade-name { font-size: 13px; font-weight: 700; color: #ddd; margin-bottom: 4px; }
#upgrade-level { font-size: 11px; color: #8888aa; margin-bottom: 6px; }
#upgrade-stats-current { font-size: 10px; color: #999; margin-bottom: 4px; line-height: 1.4; }
#upgrade-stats-next { font-size: 10px; color: #ffcc00; margin-bottom: 8px; line-height: 1.4; }

.action-btn {
  display: block;
  width: 100%;
  padding: 6px;
  margin-bottom: 4px;
  border: 1px solid #2a2a44;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  transition: all 0.12s;
}
.action-btn.upgrade {
  background: #1a2a1a;
  color: #44ff88;
  border-color: #2a442a;
}
.action-btn.upgrade:hover { background: #2a3a2a; }
.action-btn.upgrade:disabled, .action-btn.upgrade.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.action-btn.sell {
  background: #2a1a1a;
  color: #ff6666;
  border-color: #442a2a;
}
.action-btn.sell:hover { background: #3a2a2a; }

.action-btn.path-btn {
  background: #1a1a30;
  color: #aaccff;
  border-color: #2a2a55;
}
.action-btn.path-btn:hover { background: #2a2a44; }

.btn-key {
  font-size: 9px;
  color: #555;
  background: #0a0a18;
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 4px;
}

/* ── Path choice ── */
#path-choice { margin-bottom: 6px; }
#path-choice.hidden { display: none; }
.path-choice-title {
  font-size: 10px;
  color: #ffcc00;
  margin-bottom: 4px;
  font-weight: 600;
}
.path-desc {
  font-size: 9px;
  color: #888;
  margin-top: 2px;
}

/* ── Tooltip ── */
#tooltip {
  position: absolute;
  background: #141420;
  border: 1px solid #3a3a60;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 11px;
  color: #ccc;
  max-width: 200px;
  pointer-events: none;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  line-height: 1.4;
}
#tooltip.hidden { display: none; }
#tooltip .tip-title { font-weight: 700; color: #fff; margin-bottom: 4px; }
#tooltip .tip-stat { color: #aaa; }
#tooltip .tip-highlight { color: #ffcc00; }

/* ── Overlay ── */
#overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(4, 4, 12, 0.85);
  z-index: 10;
  pointer-events: none;
  border-radius: 8px;
}
#overlay.hidden { display: none; }
#overlay-text {
  font-size: 28px;
  font-weight: bold;
  color: #ffcc00;
  text-align: center;
  text-shadow: 0 0 30px rgba(255, 200, 0, 0.4);
  line-height: 1.8;
}
#overlay-text small { font-size: 15px; font-weight: normal; color: #aaa; }

/* ── Lobby / Difficulty selector ── */
#lobby-panel {
  margin-top: 20px;
  text-align: center;
  pointer-events: auto;
}
#lobby-panel.hidden { display: none; }

.lobby-title {
  font-size: 14px;
  color: #8888aa;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 12px;
}

#lobby-players {
  margin-bottom: 12px;
  font-size: 12px;
  color: #aaa;
}
.lobby-player {
  display: inline-block;
  padding: 4px 10px;
  margin: 2px 4px;
  background: #141420;
  border: 1px solid #2a2a44;
  border-radius: 4px;
  font-size: 11px;
}
.lobby-player.cpu { color: #88aacc; }
.lobby-player.you { border-color: #ffcc00; color: #ffcc00; }

.lobby-section-title {
  font-size: 11px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

#difficulty-selector {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 12px;
}

.diff-btn {
  background: #141420;
  border: 1px solid #2a2a44;
  border-radius: 6px;
  padding: 10px 16px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  min-width: 130px;
}
.diff-btn:hover { background: #1a1a30; border-color: #3a3a60; }
.diff-btn.selected { border-color: #ffcc00; background: #1a1a10; }
.diff-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.diff-name {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: #e0e0e0;
  margin-bottom: 4px;
}
.diff-btn.selected .diff-name { color: #ffcc00; }
.diff-btn[data-diff="easy"] .diff-name { color: #44cc88; }
.diff-btn[data-diff="easy"].selected .diff-name { color: #44ff88; }
.diff-btn[data-diff="hard"] .diff-name { color: #cc4444; }
.diff-btn[data-diff="hard"].selected .diff-name { color: #ff4444; }

.diff-desc {
  display: block;
  font-size: 10px;
  color: #666;
  line-height: 1.3;
}

#lobby-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 8px;
}

.lobby-btn {
  background: #141420;
  border: 1px solid #2a2a44;
  border-radius: 6px;
  padding: 8px 18px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: #aaa;
  transition: all 0.15s;
}
.lobby-btn:hover { background: #1a1a30; border-color: #3a3a60; color: #ddd; }
.lobby-btn.primary { color: #44ff88; border-color: #2a442a; background: #1a2a1a; }
.lobby-btn.primary:hover { background: #2a3a2a; }
.lobby-btn:disabled { opacity: 0.4; cursor: not-allowed; }

#difficulty-info {
  font-size: 12px;
  color: #555;
}

#difficulty-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 8px;
  font-weight: 600;
}
#difficulty-badge.hidden { display: none; }
#difficulty-badge.easy { background: #1a2a1a; color: #44cc88; }
#difficulty-badge.normal { background: #1a1a30; color: #8888aa; }
#difficulty-badge.hard { background: #2a1a1a; color: #cc4444; }

/* ── Help overlay ── */
#help-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(4, 4, 12, 0.92);
  z-index: 20;
  border-radius: 8px;
}
#help-overlay.hidden { display: none; }

#help-content {
  width: 700px;
  max-height: 500px;
  background: #0e0e1a;
  border: 1px solid #2a2a44;
  border-radius: 8px;
  padding: 16px;
  overflow-y: auto;
  position: relative;
}

#help-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  color: #888;
  font-size: 24px;
  cursor: pointer;
}
#help-close:hover { color: #fff; }

#help-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}
.help-tab {
  padding: 6px 16px;
  background: #161628;
  border: 1px solid #2a2a44;
  border-radius: 4px;
  color: #888;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.help-tab:hover { background: #1e1e38; color: #ccc; }
.help-tab.active { background: #1a1a30; color: #ffcc00; border-color: #ffcc00; }

.help-page.hidden { display: none; }
.help-page h3 { color: #ffcc00; font-size: 14px; margin-bottom: 10px; }

.help-tower, .help-enemy, .help-tip {
  padding: 6px 0;
  border-bottom: 1px solid #1a1a30;
  font-size: 12px;
  line-height: 1.5;
}
.help-levels { font-size: 10px; color: #888; margin-top: 2px; }
.help-tip { color: #aaa; }

/* ── Drag preview ── */
.drag-preview {
  position: fixed;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  opacity: 0.7;
  pointer-events: none;
  z-index: 100;
  border: 2px solid rgba(255,255,255,0.3);
}
