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

:root {
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --canvas-bg: #1a2234;
  --path-color: #2e3a4e;
  --radius: 12px;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Vazirmatn', sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  direction: rtl;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Top Navigation Bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(30, 41, 59, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  padding: 10px 24px;
  gap: 16px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h1 {
  font-size: 1.35rem;
  font-weight: 800;
  background: linear-gradient(135deg, #60a5fa, #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge-multi {
  background: #059669;
  color: white;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 9999px;
  font-weight: 600;
}

.stats-bar {
  display: flex;
  gap: 16px;
}

.stat-box {
  display: flex;
  align-items: center;
  background: var(--bg-card-hover);
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  gap: 8px;
  font-size: 0.9rem;
}

.stat-icon {
  font-size: 1.1rem;
}

.stat-lives strong { color: #f87171; font-size: 1.1rem; }
.stat-coins strong { color: #fbbf24; font-size: 1.1rem; }
.stat-score strong { color: #60a5fa; font-size: 1.1rem; }
.stat-wave strong { color: #a78bfa; font-size: 1.1rem; }

/* Buttons */
.btn {
  cursor: pointer;
  border: none;
  outline: none;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 8px;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
}

.btn-primary:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

.btn-secondary {
  background: #475569;
  color: white;
}

.btn-secondary:hover { background: #64748b; }

.btn-success {
  background: #10b981;
  color: white;
}

.btn-success:hover { background: #059669; }

.btn-danger {
  background: #ef4444;
  color: white;
}

.btn-danger:hover { background: #dc2626; }

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
}

/* Main Content Layout */
.main-content {
  display: grid;
  grid-template-columns: 290px 1fr 310px;
  gap: 16px;
  padding: 16px;
  flex: 1;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #cbd5e1;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
}

.panel h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Tower Cards */
.tower-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tower-card {
  background: rgba(15, 23, 42, 0.6);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.tower-card:hover {
  border-color: #64748b;
  background: rgba(51, 65, 85, 0.4);
}

.tower-card.active {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.15);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.2);
}

.tower-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.tower-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.tower-title {
  font-weight: 700;
  font-size: 0.9rem;
  flex: 1;
  margin-right: 8px;
}

.tower-cost {
  font-weight: 700;
  color: #fbbf24;
  font-size: 0.85rem;
}

.tower-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  line-height: 1.4;
}

.tower-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: #94a3b8;
  background: rgba(0, 0, 0, 0.2);
  padding: 4px 8px;
  border-radius: 6px;
}

.selected-tower-box {
  background: rgba(37, 99, 235, 0.15);
  border: 1px solid var(--primary);
  padding: 12px;
  border-radius: 10px;
}

.selected-tower-box.hidden {
  display: none;
}

.tower-mgmt-buttons {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* Center Game Area */
.game-canvas-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.canvas-container {
  position: relative;
  background: var(--canvas-bg);
  border: 2px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  width: 800px;
  height: 500px;
}

canvas {
  display: block;
  cursor: crosshair;
}

.canvas-footer {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* Game Overlay (Game Over / Victory) */
.game-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.game-overlay.hidden {
  display: none;
}

.overlay-modal {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 30px 40px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  max-width: 400px;
}

.overlay-modal h2 {
  font-size: 1.8rem;
  margin-bottom: 12px;
}

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

/* Right Panel / Multiplayer / Chat */
.room-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.2);
  padding: 8px;
  border-radius: 8px;
}

.switch-room-form {
  display: flex;
  gap: 6px;
}

.switch-room-form input {
  flex: 1;
  background: #0f172a;
  border: 1px solid var(--border-color);
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.8rem;
}

.players-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 100px;
  overflow-y: auto;
}

.players-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  background: rgba(0, 0, 0, 0.15);
  padding: 4px 8px;
  border-radius: 6px;
}

.player-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.chat-box {
  height: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(0, 0, 0, 0.2);
  padding: 8px;
  border-radius: 8px;
  font-size: 0.8rem;
}

.chat-msg {
  line-height: 1.3;
}

.chat-msg .chat-author {
  font-weight: 700;
  color: #60a5fa;
}

.chat-msg .chat-time {
  font-size: 0.7rem;
  color: #64748b;
  margin-right: 4px;
}

.chat-input-row {
  display: flex;
  gap: 6px;
}

.chat-input-row input {
  flex: 1;
  background: #0f172a;
  border: 1px solid var(--border-color);
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.82rem;
}

.logs-box {
  height: 100px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.2);
  padding: 8px;
  border-radius: 8px;
}

.logs-box div {
  border-bottom: 1px dashed rgba(255, 255, 255, 0.05);
  padding-bottom: 2px;
}

/* Responsive */
@media (max-width: 1200px) {
  .main-content {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  .app-container {
    height: auto;
    overflow: visible;
  }
  .canvas-container {
    width: 100%;
    max-width: 800px;
  }
}
