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

body {
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #1a2340 0%, #0d1117 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overflow-x: auto;
  padding: 20px;
}

#game-container {
  position: relative;
  background: #161b22;
  border: 1.5px solid #30363d;
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.04),
    0 32px 96px rgba(0,0,0,0.6);
}

/* ── Header ───────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 10px 24px;
  background: linear-gradient(90deg, #1c2333, #131924);
  border-bottom: 1.5px solid #21293d;
}

.stat {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 1rem;
  font-weight: 600;
  color: #e5e7eb;
}

.stat span {
  color: #fbbf24;
  font-size: 1.15rem;
  font-weight: 700;
}

#wave-status {
  margin-left: auto;
  font-size: 0.8rem;
  color: #6b7280;
  font-style: italic;
  letter-spacing: 0.02em;
}

/* ── Game area ────────────────────────────────────── */
#game-area {
  display: flex;
}

#gameCanvas {
  display: block;
  cursor: crosshair;
  flex-shrink: 0;
}

/* ── Sidebar ──────────────────────────────────────── */
#sidebar {
  width: 196px;
  background: #161b22;
  border-left: 1.5px solid #21293d;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

#sidebar h3 {
  color: #fbbf24;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  padding-bottom: 8px;
  border-bottom: 1px solid #21293d;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Tower cards */
.tower-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  background: #1f2937;
  border: 1.5px solid #374151;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  user-select: none;
}

.tower-card:hover {
  border-color: #6366f1;
  background: #1e2d4a;
  transform: translateX(2px);
}

.tower-card.selected {
  border-color: #fbbf24;
  background: #2a2010;
  transform: translateX(4px);
}

.tower-icon {
  font-size: 22px;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.tower-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: #f3f4f6;
}

.tower-desc {
  font-size: 0.67rem;
  color: #9ca3af;
  margin-top: 2px;
}

.tower-cost {
  font-size: 0.72rem;
  color: #4ade80;
  margin-top: 3px;
  font-weight: 600;
}

/* Legend */
.legend {
  background: #1f2937;
  border-radius: 8px;
  padding: 8px 10px;
  border: 1px solid #374151;
}

.legend-title {
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7280;
  margin-bottom: 5px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  color: #9ca3af;
  margin: 3px 0;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Info panel */
#info-panel {
  flex: 1;
  font-size: 0.72rem;
  color: #9ca3af;
  line-height: 1.55;
  padding: 8px 10px;
  background: #0d1117;
  border-radius: 8px;
  border: 1px solid #21293d;
}

#selected-tower-panel {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

#sell-info {
  font-size: 0.75rem;
  color: #e5e7eb;
  text-align: center;
  padding: 8px;
  background: #1f2937;
  border-radius: 8px;
  border: 1px solid #374151;
  line-height: 1.5;
}

/* Buttons */
.btn-primary {
  width: 100%;
  padding: 11px 8px;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 4px 14px rgba(109, 40, 217, 0.3);
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.92;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(109, 40, 217, 0.45);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-danger {
  width: 100%;
  padding: 9px 8px;
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-danger:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

#shortcuts {
  font-size: 0.62rem;
  color: #4b5563;
  text-align: center;
  line-height: 1.5;
  padding-top: 2px;
}

/* ── Overlay ──────────────────────────────────────── */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(6px);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

#overlay-box {
  background: #1f2937;
  border: 1.5px solid #4f46e5;
  border-radius: 20px;
  padding: 48px 44px;
  text-align: center;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 24px 80px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

#overlay-title {
  font-size: 2.4rem;
  font-weight: 900;
  color: #f9fafb;
  line-height: 1.1;
}

#overlay-text {
  font-size: 1rem;
  color: #9ca3af;
  white-space: pre-line;
  line-height: 1.7;
}

/* ── Scrollbar ────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }
