:root {
  --bg-deep: #0a1210;
  --bg-panel: #111e1b;
  --bg-dock: #0d1816;
  --teal-dark: #1a332f;
  --teal-mid: #2a4a44;
  --teal-light: #3d6b63;
  --emerald: #4a9c8a;
  --emerald-glow: #6bc2ae;
  --brass: #c9a227;
  --brass-light: #e8c84a;
  --brass-dim: #8a6d1a;
  --gold: #f4d03f;
  --text-main: #e0e8e6;
  --text-muted: #8fa39e;
  --text-dim: #5c726d;
  --danger: #d9534f;
  --success: #5cb85c;
  --border-subtle: rgba(106, 194, 174, 0.15);
  --border-strong: rgba(106, 194, 174, 0.3);
  --shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-hard: 0 8px 24px rgba(0, 0, 0, 0.6);
  --glow-brass: 0 0 12px rgba(201, 162, 39, 0.4);
  --glow-emerald: 0 0 12px rgba(106, 194, 174, 0.4);
  --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: "Georgia", "Times New Roman", serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background-color: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 16px;
  line-height: 1.5;
}

body {
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: linear-gradient(180deg, var(--bg-panel) 0%, var(--bg-deep) 100%);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 10;
}

header h1 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--brass-light);
  text-shadow: 0 0 8px rgba(201, 162, 39, 0.3);
  letter-spacing: 1px;
}

/* HUD */
#HUD {
  display: flex;
  gap: 1rem;
  align-items: center;
  font-size: 0.95rem;
  font-weight: 600;
}

#HUD div {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.6rem;
  background: rgba(26, 51, 47, 0.6);
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
}

#HUD span {
  color: var(--text-muted);
  font-size: 0.85rem;
}

#HUD strong {
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

#goldValue { color: var(--gold); }
#livesValue { color: var(--danger); }
#waveValue { color: var(--emerald-glow); }
#enemyValue { color: var(--text-main); }
#nextWaveValue { color: var(--brass); }

/* Main Game Area */
#gameShell {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr minmax(220px, 270px);
  gap: 1rem;
  padding: 1rem;
  height: 100%;
  overflow: hidden;
}

/* Map Container */
#mapWrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #1a2b28 0%, #0a1210 100%);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5), var(--shadow-soft);
  overflow: hidden;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  aspect-ratio: 5 / 3;
  background: transparent;
  cursor: crosshair;
}

/* Side Dock */
#sideDock {
  display: flex;
  flex-direction: column;
  background: var(--bg-dock);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

#panelTitle {
  padding: 1rem;
  background: linear-gradient(90deg, var(--teal-dark), var(--bg-dock));
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--brass-light);
  text-align: center;
}

#panelBody {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#panelBody::-webkit-scrollbar {
  width: 6px;
}
#panelBody::-webkit-scrollbar-track {
  background: var(--bg-dock);
}
#panelBody::-webkit-scrollbar-thumb {
  background: var(--teal-mid);
  border-radius: 3px;
}

/* Tower Options */
#towerOptions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.tower-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.8rem;
  background: var(--teal-dark);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px;
  text-align: center;
}

.tower-option:hover, .tower-option:focus-visible {
  background: var(--teal-mid);
  border-color: var(--emerald);
  box-shadow: var(--glow-emerald);
  outline: none;
}

.tower-option.selected {
  background: var(--teal-mid);
  border-color: var(--brass);
  box-shadow: var(--glow-brass);
}

.tower-option span {
  font-size: 0.85rem;
  color: var(--text-main);
  font-weight: 600;
}

.tower-option small {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Buttons */
button {
  min-height: 44px;
  min-width: 44px;
  padding: 0.6rem 1rem;
  font-family: var(--font-main);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  background: var(--teal-dark);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

button:hover:not(:disabled), button:focus-visible {
  background: var(--teal-mid);
  border-color: var(--emerald);
  box-shadow: var(--glow-emerald);
  outline: none;
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-deep);
  color: var(--text-dim);
  border-color: transparent;
}

#upgradeButton {
  background: var(--brass-dim);
  border-color: var(--brass);
  color: var(--gold);
}

#upgradeButton:hover:not(:disabled), #upgradeButton:focus-visible {
  background: var(--brass);
  color: var(--bg-deep);
  box-shadow: var(--glow-brass);
}

#sellButton {
  background: var(--danger);
  border-color: #a94442;
  color: #fff;
}

#sellButton:hover:not(:disabled), #sellButton:focus-visible {
  background: #c9302c;
  box-shadow: 0 0 12px rgba(217, 83, 79, 0.4);
}

#closePanel {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.85rem;
  min-height: 36px;
  padding: 0.4rem 0.8rem;
  align-self: flex-end;
}

#closePanel:hover {
  color: var(--text-main);
  border-color: var(--text-muted);
}

/* Controls Bar */
.controls-bar {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-subtle);
  justify-content: center;
}

#speedButton, #pauseButton, #waveButton {
  flex: 1;
  max-width: 120px;
}

#waveButton {
  background: var(--emerald);
  border-color: var(--emerald-glow);
  color: var(--bg-deep);
}

#waveButton:hover:not(:disabled), #waveButton:focus-visible {
  background: var(--emerald-glow);
  box-shadow: var(--glow-emerald);
}

/* Toast */
#toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 30, 27, 0.95);
  border: 1px solid var(--brass);
  color: var(--brass-light);
  padding: 0.8rem 1.5rem;
  border-radius: 6px;
  box-shadow: var(--shadow-hard), var(--glow-brass);
  font-size: 0.95rem;
  font-weight: 600;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#toast.show {
  opacity: 1;
}

/* Overlays */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 18, 16, 0.92);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.overlay-content {
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 2rem;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-hard);
}

.overlay h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--brass-light);
  margin-bottom: 1rem;
  text-shadow: 0 0 10px rgba(201, 162, 39, 0.3);
}

.overlay p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 1rem;
}

#startButton, #restartButton {
  background: var(--brass);
  border-color: var(--brass-light);
  color: var(--bg-deep);
  font-size: 1.1rem;
  padding: 0.8rem 2rem;
  width: 100%;
}

#startButton:hover, #restartButton:hover {
  background: var(--brass-light);
  box-shadow: var(--glow-brass);
}

/* Footer */
footer {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-subtle);
  font-size: 0.85rem;
  color: var(--text-dim);
  z-index: 10;
}

/* Responsive */
@media (max-width: 900px) {
  #gameShell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    overflow-y: auto;
  }

  #mapWrap {
    height: 60vh;
    min-height: 300px;
  }

  #sideDock {
    height: auto;
    max-height: 40vh;
  }

  #HUD {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  header {
    padding: 0 0.5rem;
  }

  header h1 {
    font-size: 1.2rem;
  }
}

@media (max-width: 600px) {
  #HUD div {
    padding: 0.2rem 0.4rem;
    font-size: 0.85rem;
  }

  #HUD span {
    display: none;
  }

  .controls-bar {
    flex-wrap: wrap;
  }

  #speedButton, #pauseButton, #waveButton {
    max-width: none;
  }
}
#gameShell{display:flex;flex-direction:column;height:100vh;overflow:hidden}
header.hud{flex-shrink:0;display:flex;align-items:center;justify-content:space-between}
.hud-stats,.hud-actions{display:flex;align-items:center;gap:8px}
main.game-area{flex:1;min-height:0;display:grid;grid-template-columns:minmax(0,1fr) minmax(220px,270px)}
#mapWrap{min-width:0;overflow:hidden}
#sideDock{min-height:0;overflow:auto}
.hidden{display:none!important}
#startOverlay{display:flex}
@media(max-width:900px){
#gameShell{overflow-y:auto}
main.game-area{grid-template-columns:1fr;grid-template-rows:auto auto}
#mapWrap{min-height:50vh}
#sideDock{min-height:auto}
}
#startOverlay:not(.hidden), #endOverlay:not(.hidden) { opacity: 1; pointer-events: auto; }
#gameShell { display: flex; flex-direction: column; height: 100vh; background: #0a1f14; }
header.hud { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; background: #112b1d; border-bottom: 2px solid #c5a35a; }
.hud-stats { display: flex; gap: 15px; }
.stat { background: #1a3a28; border: 1px solid #c5a35a; border-radius: 8px; padding: 8px 12px; color: #e0d5b0; font-weight: bold; font-size: 14px; min-width: 80px; text-align: center; }
.hud-actions { display: flex; gap: 10px; }
.hud-actions button { background: #c5a35a; color: #0a1f14; border: none; border-radius: 6px; padding: 8px 16px; font-weight: bold; cursor: pointer; min-height: 44px; }
main.game-area { flex: 1; display: flex; gap: 15px; padding: 15px; overflow: hidden; }
#mapWrap { flex: 1; display: flex; align-items: center; justify-content: center; background: #0d2618; border: 2px solid #c5a35a; border-radius: 10px; position: relative; }
#gameCanvas { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
#sideDock { width: 250px; display: flex; flex-direction: column; background: #112b1d; border: 2px solid #c5a35a; border-radius: 10px; padding: 15px; overflow-y: auto; }
#panelBody > p:first-child { display: none; }
#towerOptions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 15px; }
.tower-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; background: #1a3a28; border: 1px solid #c5a35a; border-radius: 8px; padding: 10px; color: #e0d5b0; cursor: pointer; min-height: 60px; text-align: center; }
.tower-name { font-weight: bold; font-size: 14px; margin-bottom: 4px; }
.tower-cost { font-size: 12px; color: #c5a35a; }
.controls { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.controls button { width: 100%; background: #2a5a3e; color: #e0d5b0; border: 1px solid #c5a35a; border-radius: 6px; padding: 10px; font-weight: bold; cursor: pointer; min-height: 44px; }
.dock-footer { margin-top: 15px; padding-top: 10px; border-top: 1px solid #c5a35a; text-align: center; font-size: 12px; color: #8a9a8a; }
.dock-footer a { color: #c5a35a; text-decoration: none; }

@media (max-width: 900px) {
  main.game-area { flex-direction: column; }
  #sideDock { width: 100%; max-height: 200px; }
  #mapWrap { min-height: 300px; }
}
