/* ═══════════════════════════════════════════════════════
   ELYCTRA Tower Defense — Design System v3.0
   Theme: "Warm Fantasy" — accessible, responsive, premium
   ═══════════════════════════════════════════════════════ */

/* ── CSS RESET & VARIABLES ─────────────────────────── */
:root {
  --bg: #0f0e17;
  --surface: #1a1830;
  --surface-2: #232040;
  --surface-3: #2d2952;
  --border: rgba(255, 137, 6, 0.15);
  --border-hover: rgba(255, 137, 6, 0.35);

  --primary: #ff8906;
  --primary-dim: rgba(255, 137, 6, 0.15);
  --primary-glow: rgba(255, 137, 6, 0.4);
  --secondary: #e53170;
  --secondary-dim: rgba(229, 49, 112, 0.15);
  --accent: #5ce0d8;
  --accent-dim: rgba(92, 224, 216, 0.12);

  --green: #2cb67d;
  --green-dim: rgba(44, 182, 125, 0.15);
  --red: #ff4060;
  --red-dim: rgba(255, 64, 96, 0.12);
  --gold: #ffd700;
  --gold-dim: rgba(255, 215, 0, 0.12);
  --purple: #b668f8;
  --purple-dim: rgba(182, 104, 248, 0.12);

  --text: #fffffe;
  --text-muted: #a7a9be;
  --text-dim: #72738a;

  --font-title: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 30px var(--primary-glow);

  --glass: rgba(26, 24, 48, 0.75);
  --glass-border: rgba(255, 255, 255, 0.08);

  --topbar-h: 52px;
  --toolbar-h: 72px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--bg);
  font-family: var(--font-body);
  color: var(--text);
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ── ACCESSIBILITY & FOCUS ─────────────────────────── */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  box-shadow: 0 0 14px var(--primary-glow);
}

/* ── GAME CANVAS ───────────────────────────────────── */
#c {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}

/* ── SCROLLBAR ─────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--primary-dim); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary-glow); }

/* ── UTILITY CLASSES ───────────────────────────────── */
.glass {
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

/* ═══════════════════════════════════════════════════════
   AUTH SCREEN
   ═══════════════════════════════════════════════════════ */
#auth-modal {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

#auth-modal::before {
  content: ''; position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(255, 137, 6, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 50%, rgba(229, 49, 112, 0.06) 0%, transparent 60%);
  pointer-events: none;
}

.auth-container {
  position: relative; z-index: 2;
  width: min(440px, 100%);
}

.auth-logo {
  text-align: center; margin-bottom: 2rem;
}
.auth-logo h1 {
  font-family: var(--font-title);
  font-size: clamp(2rem, 6vw, 2.8rem);
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 4px;
  filter: drop-shadow(0 0 30px var(--primary-glow));
}
.auth-logo .sub {
  font-size: 0.8rem;
  color: var(--text-dim);
  letter-spacing: 3px;
  margin-top: 6px;
  font-family: var(--font-title);
}

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
}

.auth-tabs {
  display: flex; gap: 4px;
  margin-bottom: 1.5rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.auth-tab {
  flex: 1; padding: 10px 14px;
  background: none; border: none;
  border-radius: 6px;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: var(--transition);
  letter-spacing: 1px;
}
.auth-tab.active {
  background: var(--primary);
  color: var(--bg);
}
.auth-tab:hover:not(.active) {
  color: var(--text);
  background: var(--surface-2);
}

.auth-field { margin-bottom: 1rem; }
.auth-label {
  display: block; font-size: 0.75rem; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px;
  letter-spacing: 0.5px;
}
.auth-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: var(--transition);
  outline: none;
}
.auth-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}
.auth-input::placeholder { color: var(--text-dim); }

.auth-btn {
  width: 100%; padding: 14px;
  margin-top: 0.5rem;
  background: linear-gradient(135deg, var(--primary), #e07000);
  border: none; border-radius: var(--radius-sm);
  color: #fff; font-family: var(--font-title);
  font-size: 1rem; font-weight: 700;
  letter-spacing: 2px; cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 15px var(--primary-dim);
}
.auth-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}
.auth-btn:active { transform: translateY(0); }
.auth-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.auth-error {
  font-size: 0.8rem; color: var(--red);
  margin-top: 8px; min-height: 20px;
}

.auth-guest {
  text-align: center; margin-top: 1.2rem;
  font-size: 0.85rem; color: var(--text-dim);
  cursor: pointer; transition: var(--transition);
}
.auth-guest:hover { color: var(--accent); }
.auth-guest span { text-decoration: underline; }

/* ═══════════════════════════════════════════════════════
   TOP BAR (HUD)
   ═══════════════════════════════════════════════════════ */
#topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; position: relative; z-index: 20;
  box-shadow: var(--shadow-sm);
}

.logo {
  font-family: var(--font-title);
  font-size: 1.1rem; font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 2px; flex-shrink: 0;
  margin-right: 4px;
}

.hud-stat {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.85rem; white-space: nowrap;
  transition: var(--transition); flex-shrink: 0;
}
.hud-stat:hover { border-color: var(--border-hover); }
.hud-stat .icon { font-size: 1rem; line-height: 1; }
.hud-stat .label {
  font-size: 0.65rem; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 1px;
  font-weight: 600;
}
.hud-stat .value {
  font-weight: 700; font-size: 0.95rem;
  font-family: var(--font-title);
}
.hud-stat.gold .value { color: var(--gold); }
.hud-stat.lives .value { color: var(--green); }
.hud-stat.lives.danger .value {
  color: var(--red);
  animation: pulse-danger 0.6s ease-in-out infinite alternate;
}
.hud-stat.score .value { color: var(--purple); }
.hud-stat.kills .value { color: var(--accent); }

@keyframes pulse-danger {
  from { opacity: 1; } to { opacity: 0.4; }
}

.spacer { flex: 1; }

#wave-info {
  font-family: var(--font-title);
  font-size: 0.85rem; color: var(--primary);
  text-align: center; flex-shrink: 0;
  letter-spacing: 1px; font-weight: 600;
}
#wave-info .wave-name {
  color: var(--text-muted); font-size: 0.7rem;
  font-weight: 400;
}

.action-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.8rem; font-weight: 600;
  cursor: pointer; transition: var(--transition);
  white-space: nowrap; flex-shrink: 0;
}
.action-btn:hover {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}
.action-btn:active { transform: translateY(0); }
.action-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--bg);
  box-shadow: 0 0 15px var(--primary-dim);
}
.action-btn:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }
.action-btn.danger { border-color: var(--red-dim); color: var(--red); }
.action-btn.danger:hover { background: var(--red-dim); border-color: var(--red); }
.action-btn.start-btn {
  background: linear-gradient(135deg, var(--green), #1a9060);
  border-color: var(--green);
  color: #fff; font-weight: 700;
}
.action-btn.start-btn:hover {
  box-shadow: 0 0 20px var(--green-dim);
  transform: translateY(-2px);
}
.action-btn.start-btn:not(:disabled) {
  animation: start-glow 2s ease-in-out infinite;
}
@keyframes start-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(44,182,125,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(44,182,125,0); }
}

#user-badge {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  cursor: pointer; transition: var(--transition);
  flex-shrink: 0;
}
#user-badge:hover {
  border-color: var(--border-hover);
  background: var(--primary-dim);
}
.ub-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700;
  font-family: var(--font-title);
}
.ub-name { font-size: 0.8rem; color: var(--text-muted); }

/* ── XP BAR ────────────────────────────────────────── */
.xp-wrap {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; flex-shrink: 0;
}
.xp-label { font-size: 0.65rem; color: var(--purple); letter-spacing: 1px; font-weight: 600; }
#xp-bar-wrap {
  width: 60px; height: 4px;
  background: var(--bg);
  border: 1px solid var(--purple-dim);
  border-radius: 3px; overflow: hidden;
}
#xp-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--purple), var(--secondary));
  transition: width 0.4s;
}

/* ═══════════════════════════════════════════════════════
   MAIN LAYOUT
   ═══════════════════════════════════════════════════════ */
#main {
  flex: 1; display: flex;
  overflow: hidden; min-height: 0;
  position: relative;
}

/* ── CANVAS AREA ───────────────────────────────────── */
#canvas-wrap {
  flex: 1; position: relative;
  overflow: hidden; background: #000;
  display: flex; align-items: center; justify-content: center;
}
#c {
  display: block;
  cursor: crosshair;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* ── RIGHT PANEL (desktop only) ────────────────────── */
#right-panel {
  width: 240px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden; flex-shrink: 0;
  transition: width var(--transition);
}

.rp-tabs {
  display: flex; border-bottom: 1px solid var(--border);
  flex-shrink: 0; padding: 4px;
  background: var(--bg);
}
.rp-tab {
  flex: 1; padding: 8px 4px;
  background: none; border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 0.7rem; font-weight: 600;
  cursor: pointer; transition: var(--transition);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.rp-tab.active {
  color: var(--primary);
  background: var(--primary-dim);
}

.rp-pane {
  display: none; flex: 1;
  flex-direction: column; overflow: hidden;
}
.rp-pane.active { display: flex; }

.rp-content {
  flex: 1; overflow-y: auto; padding: 12px;
}

/* ── Tower info panel ──────────────────────────────── */
.section-title {
  font-size: 0.7rem; letter-spacing: 2px;
  color: var(--text-dim); text-transform: uppercase;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px; font-weight: 600;
}

.ti-title {
  font-family: var(--font-title);
  font-size: 1rem; font-weight: 700;
  color: var(--text); margin-bottom: 8px;
}
.ti-stat-row {
  display: flex; justify-content: space-between;
  font-size: 0.8rem; padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.ti-stat-row .k { color: var(--text-muted); }
.ti-stat-row .v { color: var(--primary); font-weight: 700; }

.ti-upgrade-btn {
  width: 100%; margin-top: 6px; padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.75rem; font-weight: 600;
  cursor: pointer; transition: var(--transition);
  text-align: left;
}
.ti-upgrade-btn:hover:not(:disabled) {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
}
.ti-upgrade-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.ti-upgrade-btn.maxed {
  background: var(--green-dim);
  border-color: var(--green);
  color: var(--green); opacity: 0.7;
}

.sell-btn {
  width: 100%; margin-top: 8px; padding: 8px;
  background: var(--red-dim);
  border: 1px solid rgba(255,64,96,0.25);
  border-radius: var(--radius-sm);
  color: var(--red);
  font-family: var(--font-body);
  font-size: 0.8rem; font-weight: 600;
  cursor: pointer; transition: var(--transition);
}
.sell-btn:hover {
  background: rgba(255,64,96,0.2);
  border-color: var(--red);
}

.target-select {
  width: 100%; margin-top: 8px; padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.8rem; cursor: pointer;
}
.target-select option { background: var(--surface); }

/* ── Kill feed ─────────────────────────────────────── */
#kill-feed {
  flex: 1; overflow: hidden; padding: 8px 12px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.kf-title {
  font-size: 0.65rem; letter-spacing: 2px;
  color: var(--text-dim); text-transform: uppercase;
  margin-bottom: 6px; flex-shrink: 0; font-weight: 600;
}
#kf-entries {
  overflow-y: auto; display: flex;
  flex-direction: column; gap: 3px; flex: 1;
}
.kf-entry {
  font-size: 0.75rem; padding: 3px 6px;
  border-radius: 4px;
  background: rgba(255,255,255,0.02);
  animation: kf-slide 0.2s ease;
}
@keyframes kf-slide {
  from { opacity: 0; transform: translateX(8px); }
  to { opacity: 1; transform: none; }
}
.kf-gold { color: var(--gold); }
.kf-boss { color: var(--red); font-weight: 700; }

/* ═══════════════════════════════════════════════════════
   ERGONOMIC DOCK WRAPPER & CATEGORY SYSTEM
   ═══════════════════════════════════════════════════════ */
#dock-wrapper {
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: relative;
  z-index: 25;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.45);
}

.dock-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  background: rgba(15, 14, 23, 0.65);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  gap: 8px;
  overflow-x: auto;
}
.dock-header::-webkit-scrollbar { height: 0; }

.dock-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
}
.dock-tabs::-webkit-scrollbar { height: 0; }

.dock-tab {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  font-family: var(--font-title);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.dock-tab:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.2);
}
.dock-tab.active {
  background: linear-gradient(135deg, rgba(255, 137, 6, 0.25), rgba(229, 49, 112, 0.2));
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 12px rgba(255, 137, 6, 0.35);
}
.dock-tab-count {
  font-size: 0.62rem;
  opacity: 0.65;
}

.dock-abilities {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.dock-ab-btn {
  background: rgba(182, 104, 248, 0.12);
  border: 1px solid rgba(182, 104, 248, 0.28);
  color: #e0b0ff;
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.dock-ab-btn:hover:not(:disabled) {
  background: rgba(182, 104, 248, 0.25);
  border-color: var(--purple);
  transform: translateY(-1px);
  box-shadow: 0 0 10px rgba(182, 104, 248, 0.4);
}
.dock-ab-btn:disabled, .dock-ab-btn.on-cd {
  opacity: 0.45;
  cursor: not-allowed;
}
.dock-ab-btn .dab-hotkey {
  font-size: 0.58rem;
  background: rgba(0, 0, 0, 0.5);
  color: #ffd700;
  padding: 1px 4px;
  border-radius: 4px;
  border: 1px solid rgba(255, 215, 0, 0.3);
}

#bottom-toolbar {
  height: 64px;
  background: transparent;
  display: flex;
  align-items: center;
  padding: 4px 10px;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
#bottom-toolbar::-webkit-scrollbar { height: 3px; }
#bottom-toolbar::-webkit-scrollbar-thumb { background: rgba(255, 137, 6, 0.3); border-radius: 3px; }

.tower-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  background: rgba(15, 14, 23, 0.75);
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
  flex-shrink: 0;
  min-width: 68px;
  height: 54px;
  position: relative;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.tower-slot:hover {
  border-color: var(--primary);
  background: rgba(255, 137, 6, 0.12);
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(255, 137, 6, 0.25);
}
.tower-slot.selected {
  border-color: var(--primary);
  background: linear-gradient(180deg, rgba(255, 137, 6, 0.22), rgba(229, 49, 112, 0.15));
  box-shadow: 0 0 16px var(--primary-glow);
  transform: translateY(-3px) scale(1.02);
}
.tower-slot.cant-afford {
  opacity: 0.5;
  filter: grayscale(0.2);
}
.tower-slot.locked {
  opacity: 0.35;
  filter: grayscale(0.85);
  cursor: not-allowed;
  border-style: dashed;
}
.tower-slot .ts-hotkey {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 0.52rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(0, 0, 0, 0.6);
  padding: 0 3px;
  border-radius: 3px;
  font-family: monospace;
}
.tower-slot .ts-icon {
  font-size: 1.25rem;
  line-height: 1;
  margin-top: 1px;
}
.tower-slot .ts-name {
  font-size: 0.58rem;
  color: var(--text-muted);
  font-weight: 600;
  max-width: 62px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tower-slot .ts-cost {
  font-size: 0.66rem;
  color: var(--gold);
  font-weight: 700;
}
.tower-slot .ts-lock {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 0.55rem;
  color: #ff80a0;
  background: rgba(0, 0, 0, 0.7);
  padding: 1px 3px;
  border-radius: 4px;
  border: 1px solid rgba(255, 64, 96, 0.3);
  font-weight: 700;
}

.toolbar-divider {
  width: 1px;
  height: 42px;
  background: rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
  margin: 0 4px;
}

/* ── Target Priority Pills ────────────────────────── */
.target-pills {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin: 6px 0;
}
.target-pill {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  padding: 4px 2px;
  font-size: 0.65rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  transition: var(--transition);
}
.target-pill:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}
.target-pill.active {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 0 8px rgba(255, 137, 6, 0.3);
}

/* ── Ability slots ─────────────────────────────────── */
.ability-slot {
  display: flex; flex-direction: column;
  align-items: center; gap: 2px;
  padding: 6px 8px;
  background: var(--purple-dim);
  border: 2px solid rgba(182,104,248,0.2);
  border-radius: var(--radius-md);
  cursor: pointer; transition: var(--transition);
  flex-shrink: 0; min-width: 56px;
  position: relative;
}
.ability-slot:hover:not(.on-cooldown) {
  border-color: var(--purple);
  transform: translateY(-3px);
}
.ability-slot.on-cooldown {
  opacity: 0.4; cursor: not-allowed;
}
.ability-slot .as-icon { font-size: 1.1rem; line-height: 1; }
.ability-slot .as-name {
  font-size: 0.55rem; color: var(--purple);
  font-weight: 600;
}
.ability-slot .cooldown-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.6);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; color: var(--purple);
  font-weight: 700;
}

/* ═══════════════════════════════════════════════════════
   WAVE BANNER (center overlay)
   ═══════════════════════════════════════════════════════ */
#wave-banner {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center; pointer-events: none;
  opacity: 0; transition: opacity 0.3s;
  z-index: 25;
}
#wave-banner.visible {
  opacity: 1;
  animation: bannerPop 2.8s forwards;
}
@keyframes bannerPop {
  0% { transform: translate(-50%,-50%) scale(0.7); opacity: 0; }
  10% { transform: translate(-50%,-50%) scale(1.05); opacity: 1; }
  80% { transform: translate(-50%,-50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%,-50%) scale(0.95); opacity: 0; }
}
.wb-wave {
  font-family: var(--font-title);
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  font-weight: 700; letter-spacing: 4px;
  text-shadow: 0 0 40px currentColor;
}
.wb-name {
  font-family: var(--font-body);
  font-size: clamp(0.9rem, 2.5vw, 1.1rem);
  color: rgba(255,255,255,0.7);
  letter-spacing: 2px; margin-top: 6px;
}
.wb-mobs {
  font-size: 0.8rem; color: var(--text-dim);
  margin-top: 8px; letter-spacing: 1px;
}

/* ═══════════════════════════════════════════════════════
   OVERLAYS (Win/Lose, Shop)
   ═══════════════════════════════════════════════════════ */
#overlay {
  position: absolute; inset: 0;
  background: rgba(15,14,23,0.88);
  display: none; align-items: center; justify-content: center;
  z-index: 40; backdrop-filter: blur(6px);
}
#overlay.active { display: flex; }

.overlay-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 2rem 2.5rem; text-align: center;
  max-width: 500px; width: 92%;
  box-shadow: var(--shadow-lg);
}
.overlay-box h2 {
  font-family: var(--font-title);
  font-size: clamp(1.3rem, 4vw, 2rem);
  font-weight: 700; letter-spacing: 3px;
  margin-bottom: 0.5rem;
}
.overlay-box.win h2 {
  color: var(--green);
  text-shadow: 0 0 30px var(--green-dim);
}
.overlay-box.lose h2 {
  color: var(--red);
  text-shadow: 0 0 30px var(--red-dim);
}
.overlay-box p {
  color: var(--text-muted); font-size: 0.9rem;
  margin-bottom: 1.5rem; line-height: 1.8;
}

.overlay-stats {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-bottom: 1.5rem;
}
.o-stat {
  background: var(--bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md); padding: 10px 12px;
}
.o-stat .ok {
  font-size: 0.65rem; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 4px; font-weight: 600;
}
.o-stat .ov {
  font-size: 1.1rem; color: var(--primary);
  font-family: var(--font-title); font-weight: 700;
}

.overlay-btns {
  display: flex; gap: 10px;
  justify-content: center; flex-wrap: wrap;
}
.overlay-btn {
  background: linear-gradient(135deg, var(--primary), #e07000);
  border: none; border-radius: var(--radius-sm);
  padding: 10px 24px; color: #fff;
  font-family: var(--font-title);
  font-size: 0.9rem; font-weight: 700;
  cursor: pointer; transition: var(--transition);
  letter-spacing: 1px;
}
.overlay-btn:hover {
  transform: scale(1.05) translateY(-2px);
  box-shadow: 0 4px 20px var(--primary-dim);
}
.overlay-btn.secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.overlay-btn.secondary:hover {
  color: var(--text);
  border-color: var(--border-hover);
}

.overlay-achievements {
  margin: 1rem 0; display: flex;
  flex-wrap: wrap; gap: 6px; justify-content: center;
}
.overlay-ach-badge {
  background: var(--gold-dim);
  border: 1px solid rgba(255,215,0,0.3);
  border-radius: 20px; padding: 5px 14px;
  font-size: 0.75rem; color: var(--gold);
  display: flex; align-items: center; gap: 6px;
  animation: achPop 0.4s ease;
}
@keyframes achPop {
  from { transform: scale(0); } to { transform: scale(1); }
}

/* ── Shop overlay ──────────────────────────────────── */
#shop-overlay {
  position: absolute; inset: 0;
  background: rgba(15,14,23,0.9);
  display: none; align-items: center; justify-content: center;
  z-index: 45; backdrop-filter: blur(4px);
}
#shop-overlay.active { display: flex; }

.shop-box {
  background: var(--surface);
  border: 1px solid rgba(182,104,248,0.25);
  border-radius: var(--radius-xl);
  padding: 2rem; max-width: 520px; width: 95%;
  box-shadow: var(--shadow-lg);
}
.shop-box h3 {
  font-family: var(--font-title);
  font-size: 1.2rem; color: var(--purple);
  letter-spacing: 3px; margin-bottom: 0.3rem;
}
.shop-box .sub {
  font-size: 0.8rem; color: var(--text-dim);
  margin-bottom: 1.2rem;
}
.shop-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 1.2rem;
}
.shop-item {
  background: var(--purple-dim);
  border: 1px solid rgba(182,104,248,0.15);
  border-radius: var(--radius-md);
  padding: 12px; cursor: pointer;
  transition: var(--transition); position: relative;
}
.shop-item:hover:not(.sold-out):not(.cant-buy) {
  border-color: var(--purple);
  background: rgba(182,104,248,0.12);
  transform: translateY(-2px);
}
.shop-item.sold-out { opacity: 0.3; cursor: default; }
.shop-item.cant-buy { opacity: 0.4; cursor: not-allowed; }
.shop-item .si-icon { font-size: 1.2rem; margin-bottom: 4px; }
.shop-item .si-name {
  font-size: 0.85rem; color: var(--text);
  font-weight: 600;
}
.shop-item .si-desc {
  font-size: 0.7rem; color: var(--text-muted);
  margin-top: 3px; line-height: 1.4;
}
.shop-item .si-cost {
  position: absolute; top: 8px; right: 10px;
  font-size: 0.8rem; color: var(--gold); font-weight: 700;
}

/* ═══════════════════════════════════════════════════════
   LEVEL SELECT
   ═══════════════════════════════════════════════════════ */
#level-select {
  position: absolute; inset: 0;
  background: var(--bg); z-index: 50;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 20px; overflow: auto; padding: 24px;
}
#level-select::before {
  content: ''; position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 30% 30%, rgba(255,137,6,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 70%, rgba(229,49,112,0.05) 0%, transparent 50%);
  pointer-events: none;
}
#level-select h1 {
  font-family: var(--font-title);
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 6px;
  filter: drop-shadow(0 0 20px var(--primary-glow));
  position: relative; z-index: 2;
}
#level-select .sub {
  color: var(--text-dim); font-size: 0.9rem;
  letter-spacing: 3px; font-family: var(--font-title);
  position: relative; z-index: 2;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px; width: min(1100px, 100%);
  position: relative; z-index: 2;
}
.level-card {
  background: rgba(26, 24, 48, 0.75);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  padding: 18px 14px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.level-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 0%, var(--primary-glow) 0%, transparent 70%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.level-card:hover::before { opacity: 0.35; }
.level-card:hover {
  border-color: var(--primary);
  transform: translateY(-5px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px var(--primary-glow);
}
.level-card:active:not(.locked) {
  transform: scale(0.96);
}
.level-card.locked {
  filter: grayscale(0.7);
  opacity: 0.45;
  cursor: not-allowed;
}
.level-card .lc-num {
  font-family: var(--font-title);
  font-size: 1.4rem; font-weight: 700;
}
.level-card .lc-name {
  font-size: 0.9rem; color: var(--text);
  margin: 6px 0; font-weight: 600;
}
.level-card .lc-diff {
  font-size: 0.7rem; letter-spacing: 2px;
  font-weight: 700;
}
.level-card .lc-waves {
  font-size: 0.7rem; color: var(--text-dim);
  margin-top: 4px;
}
.level-card .lc-desc {
  font-size: 0.7rem; color: var(--text-dim);
  margin-top: 6px; line-height: 1.4;
}
.level-card .lc-best {
  font-size: 0.7rem; color: var(--purple);
  margin-top: 8px; font-weight: 600;
}
.level-card .lc-mode {
  font-size: 0.6rem; color: var(--gold);
  margin-top: 4px; border: 1px solid var(--gold-dim);
  border-radius: 4px; padding: 2px 8px;
  display: inline-block;
}
.lock-icon {
  font-size: 0.9rem; color: var(--red);
  margin-top: 6px;
}

.diff-easy { color: var(--green); }
.diff-medium { color: var(--gold); }
.diff-hard { color: var(--primary); }
.diff-extreme { color: var(--red); }

.ls-nav {
  display: flex; gap: 10px; align-items: center;
  flex-wrap: wrap; justify-content: center;
  position: relative; z-index: 2;
}
.ls-nav-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 16px; color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.8rem; font-weight: 600;
  cursor: pointer; transition: var(--transition);
}
.ls-nav-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.ls-user-info {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px; text-align: center;
  font-size: 0.8rem; color: var(--text-muted);
  position: relative; z-index: 2;
}
.ls-user-info .ls-username {
  font-size: 1rem; color: var(--text);
  font-weight: 700; margin-bottom: 4px;
}
.ls-user-info .ls-score { color: var(--purple); font-weight: 700; }

/* ── Wave progress ─────────────────────────────────── */
#wave-progress {
  height: 3px; background: var(--bg); flex-shrink: 0;
}
#wave-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  transition: width 0.4s;
  box-shadow: 0 0 8px var(--primary-glow);
  width: 0%;
}

/* ═══════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ═══════════════════════════════════════════════════════ */
#toast {
  position: fixed; top: 60px; left: 50%;
  transform: translateX(-50%); z-index: 200;
  pointer-events: none;
  display: flex; flex-direction: column;
  align-items: center; gap: 6px;
}
.toast-msg {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  font-size: 0.85rem; color: var(--text);
  box-shadow: var(--shadow-md);
  animation: toastSlide 2.5s forwards;
  font-weight: 600;
}
@keyframes toastSlide {
  0% { opacity: 0; transform: translateY(-10px) scale(0.95); }
  15% { opacity: 1; transform: none; }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-6px); }
}

/* ═══════════════════════════════════════════════════════
   TOOLTIP
   ═══════════════════════════════════════════════════════ */
#tooltip {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.8rem; pointer-events: none;
  z-index: 100; max-width: 220px;
  display: none; box-shadow: var(--shadow-md);
}
#tooltip.visible { display: block; }
#tooltip .tt-title {
  color: var(--primary); font-weight: 700;
  font-size: 0.85rem; margin-bottom: 4px;
}
#tooltip .tt-body {
  color: var(--text-muted); line-height: 1.5;
}

/* ═══════════════════════════════════════════════════════
   MINIMAP
   ═══════════════════════════════════════════════════════ */
#minimap-canvas {
  position: absolute; bottom: 10px; right: 10px;
  width: 100px; height: 100px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  opacity: 0.85; background: var(--bg);
}

/* ═══════════════════════════════════════════════════════
   WEATHER & EVENTS
   ═══════════════════════════════════════════════════════ */
#weather-badge {
  display: none; align-items: center; gap: 6px;
  padding: 4px 10px;
  background: var(--accent-dim);
  border: 1px solid rgba(92,224,216,0.2);
  border-radius: var(--radius-sm);
  font-size: 0.75rem; color: var(--accent);
  font-weight: 600; flex-shrink: 0;
}

#event-banner {
  position: absolute; top: 12px; left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--primary-dim);
  border-radius: var(--radius-md);
  padding: 10px 20px; text-align: center;
  pointer-events: none; opacity: 0;
  transition: opacity 0.3s; z-index: 30;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}
#event-banner.visible {
  opacity: 1;
  animation: eventSlide 3s forwards;
}
@keyframes eventSlide {
  0% { opacity: 0; transform: translateX(-50%) translateY(-12px); }
  10% { opacity: 1; transform: translateX(-50%) translateY(0); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}
.ev-icon { font-size: 1.2rem; }
.ev-name {
  font-family: var(--font-title); font-size: 0.85rem;
  letter-spacing: 1px; margin: 0 10px; font-weight: 700;
}
.ev-desc { font-size: 0.75rem; opacity: 0.6; }

/* ── Relic strip ───────────────────────────────────── */
#relic-strip {
  display: flex; gap: 4px; align-items: center;
  flex-shrink: 0; flex-wrap: wrap; max-width: 110px;
}
.relic-icon {
  font-size: 1rem; cursor: help; position: relative;
  filter: drop-shadow(0 0 4px var(--purple-dim));
}
.relic-icon:hover::after {
  content: attr(data-tip);
  position: absolute; bottom: 120%; left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--purple-dim);
  border-radius: var(--radius-sm);
  padding: 6px 10px; font-size: 0.7rem;
  white-space: nowrap; color: var(--text-muted);
  z-index: 999; pointer-events: none;
  box-shadow: var(--shadow-sm);
}

/* ═══════════════════════════════════════════════════════
   PROFILE MODAL
   ═══════════════════════════════════════════════════════ */
#profile-modal {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(15,14,23,0.92);
  backdrop-filter: blur(8px);
  display: none; align-items: center; justify-content: center;
  padding: 20px;
}
#profile-modal.active { display: flex; }

.profile-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: min(800px, 100%); max-height: 85dvh;
  overflow: hidden; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.profile-header {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.profile-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 700;
  font-family: var(--font-title); flex-shrink: 0;
}
.profile-title { flex: 1; }
.profile-username {
  font-family: var(--font-title);
  font-size: 1.2rem; color: var(--text);
  letter-spacing: 1px; font-weight: 700;
}
.profile-subtitle {
  font-size: 0.75rem; color: var(--text-dim); margin-top: 3px;
}
.profile-close {
  background: none;
  border: 1px solid rgba(255,64,96,0.3);
  border-radius: var(--radius-sm);
  color: var(--red);
  font-size: 0.8rem; cursor: pointer;
  padding: 6px 12px; font-weight: 600;
  transition: var(--transition);
}
.profile-close:hover {
  background: var(--red-dim);
  border-color: var(--red);
}

.profile-tabs {
  display: flex; border-bottom: 1px solid var(--border);
  padding: 4px 8px; gap: 4px;
}
.profile-tab {
  padding: 10px 18px;
  background: none; border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 0.75rem; font-weight: 600;
  cursor: pointer; transition: var(--transition);
  letter-spacing: 0.5px;
}
.profile-tab.active {
  color: var(--primary);
  background: var(--primary-dim);
}
.profile-content {
  flex: 1; overflow-y: auto; padding: 20px 24px;
}

/* ── Stats grid ────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px; margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 14px; text-align: center;
  transition: var(--transition);
}
.stat-card:hover { border-color: var(--border-hover); }
.stat-card .sc-icon { font-size: 1.4rem; margin-bottom: 6px; }
.stat-card .sc-val {
  font-family: var(--font-title);
  font-size: 1.2rem; color: var(--primary);
  font-weight: 700;
}
.stat-card .sc-label {
  font-size: 0.65rem; color: var(--text-dim);
  letter-spacing: 1px; margin-top: 3px;
  text-transform: uppercase; font-weight: 600;
}

/* ── History table ─────────────────────────────────── */
.history-table {
  width: 100%; border-collapse: collapse;
  font-size: 0.8rem;
}
.history-table th {
  color: var(--text-dim); font-size: 0.65rem;
  letter-spacing: 1px; text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.history-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-muted);
}
.history-table tr:hover td { background: var(--primary-dim); }
.status-won { color: var(--green); font-weight: 600; }
.status-lost { color: var(--red); }
.status-abandoned { color: var(--text-dim); }

.history-detail-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px; color: var(--primary);
  font-size: 0.7rem; cursor: pointer;
  padding: 3px 8px; transition: var(--transition);
  font-weight: 600;
}
.history-detail-btn:hover {
  border-color: var(--primary);
  background: var(--primary-dim);
}

/* ── Achievements ──────────────────────────────────── */
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.ach-card {
  background: var(--bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 12px; position: relative;
  transition: var(--transition);
}
.ach-card.unlocked {
  border-color: rgba(255,215,0,0.3);
  background: var(--gold-dim);
}
.ach-card.locked { filter: grayscale(0.7); opacity: 0.5; }
.ach-card:hover { transform: translateY(-2px); }
.ach-icon { font-size: 1.6rem; margin-bottom: 6px; }
.ach-name {
  font-size: 0.85rem; color: var(--gold);
  font-weight: 700;
}
.ach-desc {
  font-size: 0.75rem; color: var(--text-muted);
  margin-top: 3px; line-height: 1.4;
}
.ach-points {
  position: absolute; top: 10px; right: 10px;
  font-size: 0.7rem; color: var(--gold); font-weight: 700;
}
.ach-unlocked-at {
  font-size: 0.65rem; color: var(--text-dim); margin-top: 6px;
}
.ach-rarity {
  font-size: 0.6rem; letter-spacing: 1px;
  margin-top: 4px; font-weight: 600;
}
.ach-rarity.common { color: var(--text-dim); }
.ach-rarity.rare { color: var(--accent); }
.ach-rarity.epic { color: var(--purple); }
.ach-rarity.legendary { color: var(--gold); }

/* XP bar full */
.xp-bar-full {
  height: 8px; background: var(--bg);
  border: 1px solid var(--purple-dim);
  border-radius: 4px; overflow: hidden; margin: 8px 0;
}
.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--purple), var(--secondary));
  border-radius: 4px; transition: width 0.6s;
}

/* ── Wave preview (right panel) ────────────────────── */
.wp-header {
  font-family: var(--font-title);
  font-size: 0.8rem; color: var(--primary);
  letter-spacing: 1px; margin-bottom: 10px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
  font-weight: 700;
}
.wp-wave-name {
  font-size: 0.95rem; color: var(--text);
  font-weight: 700; margin-bottom: 4px;
}
.wp-is-boss {
  font-size: 0.75rem; color: var(--red);
  letter-spacing: 2px; margin-bottom: 10px;
  font-weight: 700;
}
.mob-preview-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--glass-border);
  margin-bottom: 5px; transition: var(--transition);
}
.mob-preview-row:hover { border-color: var(--border-hover); }
.mob-icon { font-size: 1.1rem; flex-shrink: 0; }
.mob-info { flex: 1; min-width: 0; }
.mob-name {
  font-size: 0.8rem; color: var(--text);
  font-weight: 600;
}
.mob-count { font-size: 0.7rem; color: var(--gold); font-weight: 600; }
.mob-stats-mini {
  display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px;
}
.mst {
  font-size: 0.6rem; background: var(--surface);
  border-radius: 3px; padding: 2px 6px;
  color: var(--text-dim); font-weight: 600;
}
.mst.boss { color: var(--red); }
.mst.flying { color: var(--accent); }
.mst.armored { color: var(--gold); }
.mst.shielded { color: var(--purple); }
.mst.stealth { color: rgba(180,180,255,0.8); }

/* ── Leaderboard (right panel / profile) ───────────── */
.lb-header {
  font-family: var(--font-title); font-size: 0.75rem;
  color: var(--primary); letter-spacing: 1px;
  margin-bottom: 10px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between;
  align-items: center; font-weight: 700;
}
.lb-filter {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px; color: var(--text);
  font-size: 0.7rem; padding: 4px 6px;
  cursor: pointer;
}
.lb-filter option { background: var(--surface); }

.lb-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: var(--radius-sm);
  background: var(--bg); margin-bottom: 4px;
  transition: var(--transition);
}
.lb-row:hover { background: var(--primary-dim); }
.lb-row.me {
  background: var(--primary-dim);
  border: 1px solid var(--border);
}
.lb-rank {
  font-size: 0.8rem; color: var(--text-dim);
  width: 22px; text-align: center;
  flex-shrink: 0; font-weight: 700;
}
.lb-rank.top1 { color: var(--gold); }
.lb-rank.top2 { color: #c0c0c0; }
.lb-rank.top3 { color: #cd7f32; }
.lb-avatar {
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.6rem; font-weight: 700; flex-shrink: 0;
}
.lb-username {
  font-size: 0.8rem; color: var(--text);
  flex: 1; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-score {
  font-size: 0.8rem; color: var(--purple);
  flex-shrink: 0; font-weight: 700;
}
.lb-level {
  font-size: 0.65rem; color: var(--text-dim);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════ */

/* ── Large tablets & landscape ─────────────────────── */
@media (max-width: 1024px) {
  #right-panel { width: 220px; }
  .hud-stat .label { display: none; }
  #wave-name-display { display: none; }
  #wave-counter { font-size: 0.82rem; }
}

/* ── Small tablets & mobile landscape ───────────────── */
@media (max-width: 768px) {
  #right-panel { display: none; }
  .hud-stat.kills { display: none; }
  .hud-stat.score { display: none; }
  .xp-wrap { display: none; }
  #shortcutsBtn { display: none; }

  #topbar {
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    padding: 0 8px;
  }
  #topbar::-webkit-scrollbar { display: none; }

  .action-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 0 8px;
    font-size: 0.82rem;
    border-radius: 10px;
    flex-shrink: 0;
  }
  .action-btn.start-btn {
    min-width: 95px;
    font-weight: 700;
  }

  #wave-info {
    padding: 4px 8px;
    border-radius: 10px;
    gap: 2px;
  }
  #wave-counter { font-size: 0.8rem; }
  #wave-name-display { display: none; }

  #minimap-canvas { width: 70px; height: 70px; }

  .dock-header {
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding: 4px 6px;
    gap: 4px;
  }
  .dock-header::-webkit-scrollbar { display: none; }

  .dock-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .dock-tabs::-webkit-scrollbar { display: none; }

  .dock-tab {
    padding: 4px 10px;
    font-size: 0.68rem;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 32px;
  }

  .dock-ab-btn {
    padding: 3px 8px;
    font-size: 0.65rem;
    min-height: 32px;
    white-space: nowrap;
  }

  #bottom-toolbar {
    height: 64px;
    padding: 3px 6px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
  }
  #bottom-toolbar::-webkit-scrollbar { display: none; }

  .tower-slot {
    min-width: 64px;
    height: 58px;
    padding: 3px 6px;
    border-radius: 10px;
    flex-shrink: 0;
  }
  .tower-slot:active {
    transform: scale(0.92);
  }
  .tower-slot .ts-name { font-size: 0.55rem; }
  .tower-slot .ts-cost { font-size: 0.65rem; }

  :root { --toolbar-h: 96px; }
}

/* ── Mobile phones (Portrait) ───────────────────────── */
@media (max-width: 480px) {
  #topbar { gap: 5px; padding: 0 6px; }
  .logo { font-size: 0.88rem; letter-spacing: 1px; margin-right: 2px; }
  .hud-stat { padding: 4px 7px; border-radius: 8px; }
  .hud-stat .value { font-size: 0.82rem; }
  .hud-stat .icon { font-size: 0.85rem; }
  .hud-stat.lives .label { display: none; }

  .action-btn { min-width: 38px; min-height: 38px; padding: 0 6px; font-size: 0.8rem; }
  .action-btn.start-btn { min-width: 86px; font-size: 0.78rem; }

  .dock-header { padding: 3px 4px; gap: 4px; }
  .dock-tab { padding: 3px 8px; font-size: 0.62rem; border-radius: 10px; }
  .dock-ab-btn { padding: 3px 6px; font-size: 0.6rem; }

  .tower-slot { min-width: 58px; height: 54px; padding: 2px 4px; }
  .tower-slot .ts-icon { font-size: 1.1rem; }
  .tower-slot .ts-name { font-size: 0.52rem; max-width: 54px; }
  .tower-slot .ts-cost { font-size: 0.6rem; }
  #bottom-toolbar { height: 60px; gap: 5px; padding: 2px 4px; }
  :root { --toolbar-h: 92px; }

  #minimap-canvas { width: 55px; height: 55px; bottom: 6px; right: 6px; }

  .level-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
  .level-card { padding: 12px; }

  .overlay-box { padding: 1.25rem; }
  .shop-grid { grid-template-columns: 1fr; }
}

/* ── Very small phones (<360px) ─────────────────────── */
@media (max-width: 360px) {
  .logo { display: none; }
  :root { --topbar-h: 46px; }
}

/* ═══════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════ */
@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* ── Global Upgrade Cards ────────────────────────────── */
.upgrade-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: var(--transition);
}
.upgrade-card:hover:not(.maxed):not(.cant-afford) {
  border-color: var(--primary);
  background: var(--primary-dim);
  transform: translateY(-2px);
}
.upgrade-card.maxed {
  opacity: 0.6;
  border-color: var(--green);
  cursor: default;
}
.upgrade-card.cant-afford:not(.maxed) {
  opacity: 0.4;
  cursor: not-allowed;
}
.ug-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}
.ug-icon { font-size: 1.1rem; }
.ug-name { flex: 1; }
.ug-cost {
  color: var(--gold);
  font-weight: 700;
  font-size: 0.8rem;
}
.ug-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 4px 0 6px;
  line-height: 1.4;
}
.ug-level {
  display: flex;
  gap: 4px;
}
.ug-pip {
  flex: 1;
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
}
.ug-pip.filled {
  background: var(--primary);
  box-shadow: 0 0 6px var(--primary-glow);
}

/* ── Mobile Tower Contextual Sheet & Backdrop ───────────────── */
.mobile-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 9, 18, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 95;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.mobile-sheet-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.mobile-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(22, 20, 38, 0.95);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 2px solid var(--primary);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -12px 40px rgba(0,0,0,0.8), 0 0 25px var(--primary-dim);
  z-index: 100;
  padding: 12px 18px 28px;
  transform: translateY(115%);
  transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 82vh;
  overflow-y: auto;
}
.mobile-sheet.active {
  transform: translateY(0);
}
.ms-handle {
  width: 44px; height: 5px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  margin: 0 auto 12px;
  cursor: pointer;
}
.ms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.ms-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}
.ms-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ms-icon svg {
  width: 36px;
  height: 36px;
}
.ms-title {
  font-family: var(--font-title);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.ms-subtitle {
  font-size: 0.78rem;
  color: var(--text-dim);
}
.ms-close {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 50%;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.ms-close:hover, .ms-close:active {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0.92);
}
.ms-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.ms-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 14, 23, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
}
.ms-stat .k { color: var(--text-muted); }
.ms-stat .v { color: var(--primary); font-weight: 700; }
.ms-target-row {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.ms-target-row::-webkit-scrollbar { display: none; }
.tgt-chip {
  flex: 1;
  min-height: 38px;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(15, 14, 23, 0.65);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.tgt-chip:active {
  transform: scale(0.94);
}
.tgt-chip.active {
  border-color: var(--primary);
  background: var(--primary-dim);
  color: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}
.ms-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ms-actions .ti-upgrade-btn, .ms-actions .sell-btn {
  min-height: 44px;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ms-actions .ti-upgrade-btn:active, .ms-actions .sell-btn:active {
  transform: scale(0.96);
}
.hud-stat.combo .value { color: var(--accent); }
.action-btn.active {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
}

/* ══════════════ SHORTCUTS MODAL & A11Y ══════════════ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

#shortcuts-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.shortcuts-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: min(550px, 100%);
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  color: var(--text);
  animation: modalIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.shortcuts-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}

.shortcuts-title {
  font-family: var(--font-title);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.shortcuts-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s;
}

.shortcuts-close:hover {
  color: var(--red);
  background: rgba(255, 51, 85, 0.1);
}

.shortcuts-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sc-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text);
}

.sc-item kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom: 2px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-family: monospace;
  font-weight: 700;
  color: var(--primary);
  font-size: 0.8rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* ══════════════ VECTOR ICONS (NO EMOJIS) ══════════════ */
.tow-svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 0 5px rgba(0, 0, 0, 0.6));
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.tower-slot .ts-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-top: 1px;
}
.tower-slot:hover .tow-svg {
  transform: scale(1.12);
}
.tower-slot.selected .tow-svg {
  filter: drop-shadow(0 0 8px var(--primary-glow));
}
.tower-slot.mine-slot {
  border-color: rgba(239, 68, 68, 0.45);
}
.tower-slot.mine-slot:hover {
  border-color: rgba(239, 68, 68, 0.85);
  box-shadow: 0 4px 16px rgba(239, 68, 68, 0.35);
}
.tower-slot.mine-slot.selected {
  border-color: #ef4444;
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.6), inset 0 0 8px rgba(239, 68, 68, 0.25);
  animation: mineSlotPulse 1.2s infinite alternate ease-in-out;
}
.tower-slot.mine-slot.selected .tow-svg {
  filter: drop-shadow(0 0 10px rgba(255, 68, 68, 0.95));
}
@keyframes mineSlotPulse {
  0% { transform: scale(1.04); box-shadow: 0 0 10px rgba(239, 68, 68, 0.5); }
  100% { transform: scale(1.08); box-shadow: 0 0 20px rgba(255, 107, 53, 0.85); }
}
.rp-icon, .ms-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.rp-icon .tow-svg, .ms-icon .tow-svg {
  width: 42px;
  height: 42px;
  filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.7));
}
.tc-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tc-icon .tow-svg {
  width: 28px;
  height: 28px;
}

/* ══════════════ FULLSCREEN MODE ══════════════ */
:fullscreen, :-webkit-full-screen {
  width: 100vw;
  height: 100vh;
}
:fullscreen #main, :-webkit-full-screen #main {
  height: calc(100vh - 52px);
}
:fullscreen #topbar, :-webkit-full-screen #topbar {
  padding: 6px 16px;
  background: rgba(10, 9, 15, 0.95);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}
:fullscreen #dock-wrapper, :-webkit-full-screen #dock-wrapper {
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.8);
}
#overlayBtn.active {
  background: rgba(56, 189, 248, 0.25);
  border-color: #38bdf8;
  color: #38bdf8;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

/* ══════════════ WAVE THREAT RADAR ══════════════ */
.wave-radar-preview {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.65rem;
  margin-top: 2px;
  overflow-x: auto;
}
.wave-radar-preview::-webkit-scrollbar { height: 0; }
.wr-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  font-family: monospace;
  font-size: 0.62rem;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.12);
  white-space: nowrap;
}
.wr-badge.flying {
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.4);
  color: #38bdf8;
}
.wr-badge.boss {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
  animation: pulse-glow 1.5s infinite;
}
.wr-badge.armored {
  background: rgba(251, 146, 60, 0.15);
  border-color: rgba(251, 146, 60, 0.4);
  color: #fb923c;
}

/* ══════════════ MVP COMBAT BADGE ══════════════ */
.mvp-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.25), rgba(255, 137, 6, 0.2));
  border: 1px solid #ffd700;
  color: #ffd700;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.65rem;
  font-weight: 700;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
  margin-bottom: 6px;
  animation: pulse-glow 2s infinite;
}

/* ══════════════ GOOGLE AUTH BUTTON ══════════════ */
.auth-divider {
  display: flex;
  align-items: center;
  margin: 16px 0 12px 0;
  text-align: center;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.auth-divider span {
  padding: 0 10px;
  font-size: 0.72rem;
  color: var(--text-dim, #94a3b8);
  letter-spacing: 1px;
  font-weight: 700;
}
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 10px 16px;
  background: #ffffff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-radius: var(--radius-sm, 8px);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  box-sizing: border-box;
}
.btn-google:hover {
  background: #f8fafc;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  border-color: #cbd5e1;
}
.btn-google:active {
  transform: translateY(0);
}
.btn-google svg {
  flex-shrink: 0;
}
