/* InfiniTopia Game Styles - Matching landing page dark theme */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=DM+Sans:wght@400;500&display=swap');

:root {
  --bg-deep: #0a0e17;
  --bg-mid: #111827;
  --bg-card: #1a2236;
  --accent: #22d3ee;
  --accent-dim: #0891b2;
  --gold: #fbbf24;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --tile-green: #34d399;
  --tile-blue: #60a5fa;
  --tile-sand: #fcd34d;
  --tile-mountain: #a78bfa;
  --tile-red: #f87171;
  --border: rgba(255,255,255,0.08);
}

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

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

h1, h2, h3, h4 { font-family: 'Space Grotesk', sans-serif; }

/* ─── SCREENS ────────────────────────────── */
.screen { display: none; width: 100vw; height: 100vh; }
.screen.active { display: flex; }

/* ─── MENU SCREEN ────────────────────────── */
#menu-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  background: var(--bg-deep);
  position: relative;
}

.menu-bg {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  opacity: 0.05;
  background-image:
    linear-gradient(var(--accent-dim) 1px, transparent 1px),
    linear-gradient(90deg, var(--accent-dim) 1px, transparent 1px);
  background-size: 48px 48px;
  animation: gridShift 20s linear infinite;
  z-index: 0;
}

@keyframes gridShift {
  0% { transform: translate(0, 0); }
  100% { transform: translate(48px, 48px); }
}

.menu-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
}

.menu-title {
  font-size: 3.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--accent), var(--tile-green), var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.menu-subtitle {
  color: var(--text-dim);
  font-size: 1.1rem;
  margin-top: -1rem;
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 320px;
}

.btn {
  padding: 14px 28px;
  border: none;
  border-radius: 12px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: var(--bg-deep);
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(34,211,238,0.3); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { border-color: var(--accent); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.input-field {
  width: 100%;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.input-field:focus { border-color: var(--accent); }
.input-field::placeholder { color: var(--text-dim); }

.input-group { display: flex; flex-direction: column; gap: 0.5rem; }
.input-label { font-size: 0.85rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.1em; }

.menu-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.menu-divider::before, .menu-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.back-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
  transition: color 0.2s;
}
.back-link:hover { color: var(--accent); }

/* ─── LOBBY SCREEN ───────────────────────── */
#lobby-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  position: relative;
}

.lobby-card {
  position: relative;
  z-index: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3rem;
  width: 420px;
  max-width: 90vw;
  text-align: center;
}

.lobby-code {
  font-family: 'Space Grotesk', monospace;
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--accent);
  margin: 1rem 0;
}

.lobby-hint {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.player-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.player-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 10px 16px;
  background: rgba(255,255,255,0.03);
  border-radius: 10px;
}

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

.player-name {
  font-weight: 500;
}

.waiting-slot {
  color: var(--text-dim);
  font-style: italic;
}

/* ─── GAME SCREEN ────────────────────────── */
#game-screen {
  flex-direction: column;
  position: relative;
}

/* Top HUD */
.game-hud-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 16px;
  pointer-events: none;
}

.game-hud-top > * { pointer-events: auto; }

.hud-panel {
  background: rgba(10, 14, 23, 0.9);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 16px;
}

.turn-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
}

.turn-badge {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  color: var(--gold);
}

.turn-player { color: var(--text); }
.turn-status { font-size: 0.8rem; }
.your-turn { color: var(--accent); font-weight: 600; }
.waiting { color: var(--text-dim); }

.stars-display {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--gold);
}

/* Player list HUD */
.players-hud {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
}

.player-hud-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  padding: 4px 0;
}

.player-hud-item.current { font-weight: 600; }
.player-hud-item.eliminated { opacity: 0.4; text-decoration: line-through; }

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

/* Canvas container */
.game-canvas-container {
  width: 100%;
  height: 100%;
  position: relative;
}

#game-canvas {
  width: 100%;
  height: 100%;
  cursor: grab;
}

#game-canvas:active { cursor: grabbing; }

/* Bottom action bar */
.game-hud-bottom {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 16px;
  pointer-events: none;
  gap: 12px;
}

.game-hud-bottom > * { pointer-events: auto; }

.action-bar {
  display: flex;
  gap: 8px;
  background: rgba(10, 14, 23, 0.9);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
}

.action-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.action-btn:hover { border-color: var(--accent); background: rgba(34,211,238,0.1); }
.action-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.action-btn.active { border-color: var(--accent); background: rgba(34,211,238,0.15); color: var(--accent); }

.end-turn-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: var(--bg-deep);
  border: none;
  padding: 10px 24px;
  border-radius: 12px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.end-turn-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(34,211,238,0.3); }
.end-turn-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }

/* ─── SIDE PANELS ─────────────────────────── */
.side-panel {
  position: absolute;
  z-index: 15;
  top: 70px;
  right: 16px;
  width: 300px;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  background: rgba(10, 14, 23, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: none;
}

.side-panel.open { display: block; }

.panel-title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 1.1rem;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
}

.panel-close:hover { color: var(--text); }

/* ─── TECH TREE PANEL ────────────────────── */

/* Research queue banner */
.research-queue-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(34,211,238,0.08);
  border: 1px solid rgba(34,211,238,0.25);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--accent);
}
.queue-turns {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Tech branch */
.tech-branch {
  margin-bottom: 18px;
}

.branch-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--branch-color, var(--text-dim));
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.branch-techs {
  display: flex;
  align-items: flex-start;
  gap: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 4px;
}

.branch-arrow {
  display: flex;
  align-items: center;
  padding: 0 4px;
  color: var(--text-dim);
  font-size: 0.9rem;
  flex-shrink: 0;
  margin-top: 10px;
}

/* Tech nodes */
.tech-node {
  flex: 1;
  min-width: 72px;
  max-width: 90px;
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.tech-node:hover:not(.locked):not(.researched) {
  border-color: var(--branch-color, var(--accent-dim));
  background: rgba(255,255,255,0.04);
  transform: translateY(-1px);
}

.tech-node.researched {
  border-color: var(--tile-green);
  background: rgba(52,211,153,0.08);
}
.tech-node.queued {
  border-color: var(--accent);
  background: rgba(34,211,238,0.08);
  animation: pulse 2s infinite;
}
.tech-node.affordable {
  border-color: var(--branch-color, var(--gold));
}
.tech-node.locked {
  opacity: 0.4;
  cursor: default;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,211,238,0.3); }
  50%       { box-shadow: 0 0 0 4px rgba(34,211,238,0); }
}

.tech-node-icon { font-size: 1.3rem; margin-bottom: 2px; }
.tech-node-name { font-weight: 600; font-size: 0.75rem; margin-bottom: 3px; line-height: 1.2; }
.tech-node-cost { font-size: 0.7rem; color: var(--gold); margin-bottom: 3px; }
.tech-node.researched .tech-node-cost { color: var(--tile-green); }
.tech-node.queued .tech-node-cost { color: var(--accent); }
.tech-node.locked .tech-node-cost { color: var(--text-dim); }
.tech-node-desc { font-size: 0.65rem; color: var(--text-dim); line-height: 1.3; }

/* HUD research badge */
.hud-research-badge {
  font-size: 0.85rem;
  animation: pulse 2s infinite;
}

/* ─── UNIT CARDS ──────────────────────────── */
.unit-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  transition: all 0.2s;
  cursor: default;
}

.unit-card.can-train {
  cursor: pointer;
}

.unit-card.can-train:hover {
  border-color: var(--accent-dim);
  background: rgba(34,211,238,0.05);
  transform: translateY(-1px);
}

.unit-card.locked {
  opacity: 0.45;
}

.unit-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.unit-card-icon { font-size: 1.3rem; }
.unit-card-name { font-weight: 600; font-size: 0.95rem; flex: 1; }
.unit-card-cost {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.unit-card-cost.can-afford { color: var(--gold); }

.unit-card-stats {
  display: flex;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.unit-card-desc {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.4;
}

.unit-req {
  display: block;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--tile-red);
}

/* Legacy tech-item (kept for fallback) */
.tech-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.tech-item:hover { border-color: var(--accent-dim); }
.tech-item.researched { border-color: var(--tile-green); opacity: 0.6; }
.tech-item.affordable { border-color: var(--gold); }

.tech-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }
.tech-cost { color: var(--gold); font-size: 0.8rem; }
.tech-desc { color: var(--text-dim); font-size: 0.8rem; margin-top: 4px; }

/* City/Unit info panel */
.info-panel {
  position: absolute;
  z-index: 15;
  bottom: 80px;
  left: 16px;
  width: 280px;
  background: rgba(10, 14, 23, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: none;
}

.info-panel.open { display: block; }

.info-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.info-icon { font-size: 1.5rem; }

.info-name {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 1rem;
}

.info-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

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

.stat-value { color: var(--text); font-weight: 500; }

.info-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.info-btn {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
}

.info-btn:hover { border-color: var(--accent); }
.info-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ─── TOAST NOTIFICATIONS ─────────────────── */
.toast-container {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
  pointer-events: auto;
}

.toast.info { background: rgba(34,211,238,0.15); border: 1px solid var(--accent-dim); color: var(--accent); }
.toast.error { background: rgba(248,113,113,0.15); border: 1px solid var(--tile-red); color: var(--tile-red); }
.toast.success { background: rgba(52,211,153,0.15); border: 1px solid var(--tile-green); color: var(--tile-green); }

@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* ─── GAME OVER OVERLAY ──────────────────── */
.game-over-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 200;
  background: rgba(10, 14, 23, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
}

.game-over-overlay.visible { display: flex; }

.game-over-card {
  text-align: center;
  padding: 3rem;
}

.game-over-card h1 {
  font-size: 3rem;
  background: linear-gradient(135deg, var(--gold), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 1rem;
}

.game-over-card p {
  font-size: 1.2rem;
  color: var(--text-dim);
  margin-bottom: 2rem;
}

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

/* ─── MOBILE ─────────────────────────────── */
@media (max-width: 768px) {
  .menu-title { font-size: 2.5rem; }
  .menu-actions { width: 280px; }
  .lobby-card { padding: 2rem; }
  .lobby-code { font-size: 2rem; }
  .side-panel { width: 260px; right: 8px; }
  .info-panel { width: 240px; left: 8px; bottom: 70px; }
  .action-btn { padding: 6px 10px; font-size: 0.8rem; }
  .players-hud { min-width: 120px; }
}
