*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[x-cloak] { display: none !important; }

:root {
  --sidebar-w: 230px;
  --bg-dark:   #0f1923;
  --bg-panel:  #141e2b;
  --bg-card:   #1a2740;
  --accent:    #4a9eff;
  --success:   #44dd66;
  --gold:      #ffd700;
  --danger:    #ff4444;
  --text:      #dde4ef;
  --muted:     #7a8aaa;
  --border:    rgba(255,255,255,0.07);
}

html { height: 100%; color-scheme: dark; }

body {
  height: 100%;
  display: flex;
  background: var(--bg-dark);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

/* ─── Sidebar ──────────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  scrollbar-width: none;
}

.game-title h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.4px;
}
.game-title p { font-size: 0.7rem; color: var(--muted); margin-top: 2px; }

/* ─── HUD stats ─────────────────────────────────────────────────────────── */

.hud-stats {
  background: var(--bg-card);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
}
.stat-label { color: var(--muted); }
.stat-value { font-weight: 600; }
.stat-value.gold   { color: var(--gold); }
.stat-value.lives  { color: #ff9999; }
.stat-value.danger { color: var(--danger) !important; }

/* ─── Section label ─────────────────────────────────────────────────────── */

.section-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  margin-bottom: 5px;
}

/* ─── Wave badges ───────────────────────────────────────────────────────── */

.wave-section {}
.wave-label { font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.wave-badges { display: flex; gap: 4px; flex-wrap: wrap; }

/* ─── Speed controls ────────────────────────────────────────────────────── */

.speed-controls { display: flex; gap: 4px; }
.speed-controls wa-button { flex: 1; }

/* ─── Tower shop ────────────────────────────────────────────────────────── */

.tower-shop { display: flex; flex-direction: column; gap: 5px; }

.tower-btn-wrap { display: block; width: 100%; }
.tower-btn-wrap wa-button { width: 100%; }

.placement-hint {
  font-size: 0.72rem;
  color: var(--accent);
  font-style: italic;
  animation: blink 1.4s ease-in-out infinite;
}
@keyframes blink { 0%,100% { opacity: 0.65; } 50% { opacity: 1; } }

/* ─── Action section ────────────────────────────────────────────────────── */

.action-section wa-button { width: 100%; }

/* ─── Legend ────────────────────────────────────────────────────────────── */

.legend { margin-top: auto; font-size: 0.75rem; }
.legend-item { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ─── Game area ─────────────────────────────────────────────────────────── */

.game-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
}

.canvas-wrapper { position: relative; line-height: 0; }

#game-canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 32px);
  aspect-ratio: 1;
  border-radius: 4px;
  box-shadow: 0 0 48px rgba(74,158,255,0.12), 0 0 0 1px rgba(255,255,255,0.06);
}

/* ─── Idle overlay ──────────────────────────────────────────────────────── */

.phase-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.overlay-content {
  background: rgba(0,0,0,0.65);
  border: 1px solid rgba(74,158,255,0.25);
  border-radius: 12px;
  padding: 22px 36px;
  text-align: center;
  backdrop-filter: blur(6px);
}
.overlay-content h2 { font-size: 1.3rem; color: var(--accent); margin-bottom: 6px; }
.overlay-content p  { color: var(--muted); font-size: 0.82rem; }

/* ─── Dialogs ───────────────────────────────────────────────────────────── */

.dialog-body {
  text-align: center;
  padding: 28px 20px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.dialog-icon { font-size: 3rem; line-height: 1; }
.dialog-body h2 { font-size: 1.6rem; font-weight: 700; }
.dialog-body > p { color: var(--muted); }

.dialog-stats {
  display: flex;
  gap: 20px;
  margin: 8px 0;
}
.dialog-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.dialog-stat span { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.dialog-stat strong { font-size: 1.25rem; color: var(--accent); }

/* ─── Tower info drawer ─────────────────────────────────────────────────── */

.tower-info h3 { font-size: 1rem; font-weight: 700; margin-bottom: 12px; }
.tower-stat-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.83rem;
}
.tower-stat-row span  { color: var(--muted); }
.tower-stat-row strong { color: var(--text); }
.upgrade-btn-wrap { margin-top: 14px; }

/* ─── WebAwesome theme overrides ────────────────────────────────────────── */

/* Hide slotted content before custom elements register to prevent FOUC */
wa-tooltip:not(:defined) > [slot] { display: none; }

/* Ensure components inherit our dark palette */
wa-dialog::part(panel) {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
}
wa-drawer::part(panel) {
  background: var(--bg-panel);
  color: var(--text);
}
wa-tooltip::part(base) {
  max-width: 200px;
  font-size: 0.78rem;
  line-height: 1.45;
}

/* Selected tower button highlight */
wa-button.selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
