:root {
  --bg-color: #0d0e15;
  --text-color: #ffffff;
  --neon-blue: #00f3ff;
  --neon-pink: #ff00ea;
  --neon-green: #39ff14;
  --neon-purple: #b026ff;
  --neon-cyan: #00e5ff;
  --neon-orange: #ff8800;
  --panel-bg: rgba(20, 22, 35, 0.94);
}

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

body {
  background: var(--bg-color);
  color: var(--text-color);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

#game-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 800px;
  max-height: 100vh;
  position: relative;
  background: radial-gradient(circle at center, #1a1c29 0%, #0d0e15 100%);
  box-shadow: 0 0 30px rgba(0,243,255,0.12);
}

/* ── Top Bar ─────────────────────────────────────────────────────────────── */
#ui-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--panel-bg);
  border-bottom: 2px solid var(--neon-blue);
  box-shadow: 0 0 12px rgba(0,243,255,0.22);
  z-index: 10;
  flex-shrink: 0;
}

.stat {
  font-size: 0.95rem;
  font-weight: bold;
  text-shadow: 0 0 6px var(--neon-blue);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.stat-pts { color: #ffea00; text-shadow: 0 0 6px #ffea00; margin-left: 4px; }

.controls { display: flex; gap: 5px; align-items: center; margin-left: auto; }

.ctrl-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.22);
  color: #fff;
  padding: 3px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.82rem;
  transition: all 0.18s;
}
.ctrl-btn:hover  { border-color: var(--neon-blue); box-shadow: 0 0 7px rgba(0,243,255,0.4); }
.ctrl-btn.active { background: rgba(0,243,255,0.14); border-color: var(--neon-blue); }

/* ── Canvas ──────────────────────────────────────────────────────────────── */
#canvas-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  flex-shrink: 1;
  min-height: 0;
  display: flex;
}

canvas { width: 100%; height: 100%; display: block; cursor: crosshair; }

/* ── Wave Announcement ───────────────────────────────────────────────────── */
#wave-announcement {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  font-size: 3rem; font-weight: bold;
  color: var(--neon-pink);
  text-shadow: 0 0 30px var(--neon-pink), 0 0 60px var(--neon-pink);
  pointer-events: none;
  animation: waveAnnounce 2.2s ease-in-out forwards;
  letter-spacing: 0.1em; text-align: center; white-space: nowrap;
}
@keyframes waveAnnounce {
  0%  { opacity: 0; transform: translate(-50%,-50%) scale(0.5); }
  25% { opacity: 1; transform: translate(-50%,-50%) scale(1.08); }
  65% { opacity: 1; transform: translate(-50%,-50%) scale(1); }
  100%{ opacity: 0; transform: translate(-50%,-50%) scale(1); }
}

/* ── Tower Info Panel ────────────────────────────────────────────────────── */
#tower-info-panel {
  position: absolute; bottom: 10px; right: 10px;
  background: var(--panel-bg);
  border: 1px solid var(--neon-blue);
  border-radius: 10px; padding: 11px 13px; min-width: 200px;
  z-index: 15;
  box-shadow: 0 0 18px rgba(0,243,255,0.28);
  backdrop-filter: blur(4px);
}

.tip-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
#tip-name { font-weight: bold; font-size: 0.92rem; color: var(--neon-blue); text-shadow: 0 0 7px var(--neon-blue); }
#tip-level { font-size: 0.75rem; color: rgba(255,255,255,0.48); }

.tip-stats {
  font-family: monospace; font-size: 0.74rem;
  color: rgba(255,255,255,0.6); margin-bottom: 8px; line-height: 1.55;
}

.tip-target-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 7px; font-size: 0.78rem; color: rgba(255,255,255,0.5);
}

.tip-actions { display: flex; flex-direction: column; gap: 5px; }

.tip-btn {
  padding: 6px 9px; border-radius: 5px; border: 1px solid;
  cursor: pointer; font-size: 0.8rem; font-weight: bold;
  background: transparent; transition: all 0.16s; text-align: left;
}

.upgrade-btn { border-color: var(--neon-green); color: var(--neon-green); }
.upgrade-btn:hover:not(:disabled) { background: rgba(57,255,20,0.11); box-shadow: 0 0 9px rgba(57,255,20,0.35); }
.upgrade-btn:disabled { opacity: 0.33; cursor: not-allowed; }

.sell-btn { border-color: #ff6b6b; color: #ff6b6b; }
.sell-btn:hover { background: rgba(255,107,107,0.11); box-shadow: 0 0 9px rgba(255,107,107,0.35); }

.target-btn { border-color: var(--neon-blue); color: var(--neon-blue); padding: 3px 8px; font-size: 0.74rem; }
.target-btn:hover { background: rgba(0,243,255,0.1); }

/* ── Bottom Bar ──────────────────────────────────────────────────────────── */
#ui-bottom {
  display: flex; flex-direction: column;
  padding: 8px 12px;
  background: var(--panel-bg);
  border-top: 2px solid var(--neon-pink);
  box-shadow: 0 0 12px rgba(255,0,234,0.22);
  z-index: 10; gap: 7px; flex-shrink: 0;
}

.tower-row { display: flex; justify-content: center; gap: 7px; flex-wrap: wrap; }
.wave-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ── Wave Preview ────────────────────────────────────────────────────────── */
#wave-preview { font-size: 0.77rem; color: rgba(255,255,255,0.6); flex: 1; min-height: 16px; }
#wave-preview .wp-boss  { color: #ff4444; font-weight: bold; text-shadow: 0 0 5px #ff4444; }
#wave-preview .wp-tank  { color: #ff8844; }
#wave-preview .wp-fast  { color: #ffea00; }
#wave-preview .wp-basic { color: rgba(255,255,255,0.45); }

/* ── Tower Buttons ───────────────────────────────────────────────────────── */
.tower-btn {
  background: transparent; border: 1px solid rgba(255,255,255,0.28);
  color: #fff; padding: 6px 9px; border-radius: 7px;
  cursor: pointer; display: flex; flex-direction: column;
  align-items: center; gap: 3px; transition: all 0.2s;
  position: relative; min-width: 68px;
}
.tower-btn:hover:not(:disabled), .tower-btn.selected {
  border-color: var(--neon-green);
  box-shadow: 0 0 9px var(--neon-green) inset, 0 0 9px var(--neon-green);
  text-shadow: 0 0 5px var(--neon-green);
}
.tower-btn.selected { background: rgba(57,255,20,0.09); }
.tower-btn:disabled { opacity: 0.33; cursor: not-allowed; border-color: #444; filter: grayscale(80%); }
.tower-btn span { font-size: 0.73rem; }
.cost { color: #ffea00; }
.key-hint { position: absolute; top: 3px; right: 5px; font-size: 0.58rem; color: rgba(255,255,255,0.28); }

.tower-icon { width: 20px; height: 20px; border-radius: 50%; }
.basic-icon  { background: var(--neon-blue);   box-shadow: 0 0 7px var(--neon-blue); }
.sniper-icon { background: var(--neon-purple);  box-shadow: 0 0 7px var(--neon-purple); border-radius: 0; }
.rapid-icon  { background: var(--neon-pink);    box-shadow: 0 0 7px var(--neon-pink); clip-path: polygon(50% 0%,100% 100%,0% 100%); border-radius: 0; }
.freeze-icon { background: var(--neon-cyan);    box-shadow: 0 0 7px var(--neon-cyan); clip-path: polygon(50% 0%,93% 25%,93% 75%,50% 100%,7% 75%,7% 25%); border-radius: 0; }
.mortar-icon { background: var(--neon-orange);  box-shadow: 0 0 7px var(--neon-orange); border-radius: 50%; border: 3px solid #cc5500; }

.action-btn {
  background: transparent; border: 2px solid var(--neon-pink); color: #fff;
  padding: 8px 18px; font-size: 0.9rem; font-weight: bold; border-radius: 18px;
  cursor: pointer; text-transform: uppercase; transition: all 0.22s;
  text-shadow: 0 0 5px var(--neon-pink); box-shadow: 0 0 9px var(--neon-pink) inset;
  letter-spacing: 0.06em; white-space: nowrap;
}
.action-btn:hover:not(:disabled) { background: rgba(255,0,234,0.14); box-shadow: 0 0 16px var(--neon-pink) inset, 0 0 16px var(--neon-pink); }
.action-btn:disabled { opacity: 0.38; cursor: not-allowed; border-color: #555; box-shadow: none; text-shadow: none; }

/* ── Game Over ───────────────────────────────────────────────────────────── */
.overlay {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(13,14,21,0.93);
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  z-index: 20; gap: 12px;
}

.overlay h1 { font-size: 3rem; color: var(--neon-pink); text-shadow: 0 0 25px var(--neon-pink); letter-spacing: 0.08em; }

.hs-badge { color: #ffea00; font-size: 1.1rem; font-weight: bold; text-shadow: 0 0 10px #ffea00; letter-spacing: 0.05em; }

.go-stats { display: flex; flex-direction: column; gap: 6px; min-width: 240px; }
.go-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 1rem; color: rgba(255,255,255,0.72); padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.go-score span:last-child { color: #ffea00; font-size: 1.2rem; font-weight: bold; text-shadow: 0 0 8px #ffea00; }
.go-hs    span:last-child { color: var(--neon-blue); font-weight: bold; }

/* ── Start Screen ────────────────────────────────────────────────────────── */
#start-screen {
  background: rgba(10, 11, 20, 0.97);
  backdrop-filter: blur(6px);
  gap: 18px;
}

.start-title {
  font-size: 3.2rem; font-weight: bold; letter-spacing: 0.18em;
  color: var(--neon-blue);
  text-shadow: 0 0 20px var(--neon-blue), 0 0 50px var(--neon-blue);
}

.start-hs { font-size: 0.88rem; color: rgba(255,255,255,0.45); letter-spacing: 0.05em; }
.start-hs span { color: #ffea00; }

.select-section { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.select-label {
  font-size: 0.7rem; letter-spacing: 0.2em; color: rgba(255,255,255,0.4);
  text-transform: uppercase;
}

/* Map selection */
.map-options { display: flex; gap: 10px; }

.map-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 10px; padding: 8px;
  cursor: pointer; color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: all 0.2s; min-width: 110px;
}
.map-btn:hover { border-color: var(--neon-blue); box-shadow: 0 0 10px rgba(0,243,255,0.25); }
.map-btn.active {
  border-color: var(--neon-blue);
  background: rgba(0,243,255,0.08);
  box-shadow: 0 0 14px rgba(0,243,255,0.35);
}

.map-preview {
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.1);
  display: block;
}

.map-info { text-align: center; }
.map-name { font-size: 0.82rem; font-weight: bold; color: var(--neon-blue); }
.map-desc { font-size: 0.68rem; color: rgba(255,255,255,0.4); margin-top: 2px; }

/* Difficulty selection */
.diff-options { display: flex; gap: 10px; }

.diff-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px; padding: 8px 16px;
  cursor: pointer; color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  transition: all 0.2s; min-width: 90px;
}
.diff-btn:hover { border-color: var(--neon-pink); box-shadow: 0 0 10px rgba(255,0,234,0.2); }
.diff-btn.active {
  border-color: var(--neon-pink);
  background: rgba(255,0,234,0.08);
  box-shadow: 0 0 14px rgba(255,0,234,0.3);
}

.diff-name { font-size: 0.88rem; font-weight: bold; }
.diff-btn[data-diff="easy"]   .diff-name { color: var(--neon-green); }
.diff-btn[data-diff="normal"] .diff-name { color: #ffea00; }
.diff-btn[data-diff="hard"]   .diff-name { color: #ff4444; }
.diff-desc { font-size: 0.65rem; color: rgba(255,255,255,0.38); white-space: nowrap; }

.start-btn { font-size: 1.05rem; padding: 11px 36px; margin-top: 4px; border-color: var(--neon-blue); text-shadow: 0 0 5px var(--neon-blue); box-shadow: 0 0 10px var(--neon-blue) inset; }
.start-btn:hover { box-shadow: 0 0 20px var(--neon-blue) inset, 0 0 20px var(--neon-blue); background: rgba(0,243,255,0.12); }

.hidden { display: none !important; }

/* ── Scanlines overlay ───────────────────────────────────────────────────── */
#canvas-container::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px, transparent 3px,
    rgba(0, 0, 0, 0.11) 3px, rgba(0, 0, 0, 0.11) 4px
  );
  pointer-events: none;
  z-index: 6;
  animation: scanMove 10s linear infinite;
}
@keyframes scanMove {
  from { background-position: 0 0; }
  to   { background-position: 0 4px; }
}

/* ── Boss health bar ─────────────────────────────────────────────────────── */
#boss-bar {
  position: absolute;
  top: 8px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 9px;
  background: rgba(8, 8, 18, 0.9);
  border: 1px solid #ff3333;
  border-radius: 7px; padding: 5px 13px;
  min-width: 270px; z-index: 12;
  box-shadow: 0 0 16px rgba(255, 0, 0, 0.38);
  font-family: monospace;
}
.boss-label {
  color: #ff4444; font-size: 0.68rem; font-weight: bold;
  letter-spacing: 1px; white-space: nowrap;
  text-shadow: 0 0 7px #ff4444;
}
.boss-track {
  flex: 1; height: 11px;
  background: rgba(255, 51, 51, 0.16);
  border-radius: 6px; overflow: hidden;
}
#boss-fill {
  height: 100%;
  background: linear-gradient(to right, #ff3333, #ff7700);
  border-radius: 6px;
  transition: width 0.12s linear;
  box-shadow: 0 0 8px rgba(255, 80, 0, 0.6);
}
#boss-hp-txt {
  color: #ffaaaa; font-size: 0.63rem; white-space: nowrap;
}

/* ── Tower button tooltips ───────────────────────────────────────────────── */
.tower-btn::before {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 7px); left: 50%;
  transform: translateX(-50%);
  background: rgba(8, 10, 22, 0.97);
  border: 1px solid var(--neon-blue);
  color: #b8e0ff; padding: 5px 10px;
  border-radius: 6px; font-size: 0.67rem;
  font-family: monospace; white-space: nowrap;
  pointer-events: none; opacity: 0;
  transition: opacity 0.15s; z-index: 50;
  box-shadow: 0 0 10px rgba(0, 243, 255, 0.22);
}
.tower-btn:hover:not(:disabled)::before { opacity: 1; }

/* ── Tower info panel keyboard hint ─────────────────────────────────────── */
.tip-keys {
  font-size: 0.6rem; color: rgba(255,255,255,0.28);
  text-align: center; margin-top: 6px; font-family: monospace;
}

/* ── Start screen keyboard hint ─────────────────────────────────────────── */
.start-hint {
  font-size: 0.65rem; color: rgba(255,255,255,0.25);
  text-align: center; letter-spacing: 0.04em;
  margin-top: -6px; max-width: 380px;
}

/* ── Leaderboard ─────────────────────────────────────────────────────────── */
.leaderboard {
  margin-top: 10px; width: 100%; max-width: 420px;
}
.lb-title {
  font-size: 0.68rem; color: var(--neon-blue);
  letter-spacing: 2px; text-align: center;
  margin-bottom: 7px; text-shadow: 0 0 8px var(--neon-blue);
}
#lb-table {
  width: 100%; border-collapse: collapse;
  font-size: 0.7rem; font-family: monospace;
}
#lb-table th {
  color: rgba(255,255,255,0.38); padding: 3px 7px; text-align: left;
  border-bottom: 1px solid rgba(0, 243, 255, 0.18);
  font-weight: normal; letter-spacing: 0.05em;
}
#lb-table td { padding: 3px 7px; color: rgba(255,255,255,0.6); }
#lb-table tr.lb-top td { color: #ffd700; text-shadow: 0 0 5px rgba(255,215,0,0.5); }
#lb-table tr:nth-child(even) td { background: rgba(255,255,255,0.03); }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  #ui-top { padding: 6px 8px; gap: 6px; }
  .stat { font-size: 0.82rem; }
  .stat-pts { display: none; }  /* hide score on tiny screens, show in game over */
  .tower-btn { min-width: 58px; padding: 5px 6px; }
  .tower-btn span { font-size: 0.66rem; }
  .tower-btn::before { display: none; } /* no hover tooltip on touch */
  .action-btn { padding: 7px 12px; font-size: 0.82rem; }
  #wave-announcement { font-size: 2rem; }
  .map-options { gap: 6px; }
  .map-btn { min-width: 90px; }
  .map-preview { width: 90px; height: 52px; }
  .start-title { font-size: 2.2rem; }
  .diff-options { gap: 6px; }
  .diff-btn { min-width: 76px; padding: 7px 10px; }
  .leaderboard { max-width: 100%; }
  #lb-table { font-size: 0.62rem; }
  .start-hint { display: none; }
  #boss-bar { min-width: 200px; padding: 4px 8px; gap: 6px; }
}
