:root {
  --bg: #0a0e17;
  --bg2: #111827;
  --card: #1a2234;
  --accent: #00f0ff;
  --accent2: #ff00aa;
  --green: #00ff9d;
  --red: #ff3b5c;
  --gold: #ffd700;
  --text: #e8f0ff;
  --muted: #8b9bb8;
  --border: rgba(0, 240, 255, 0.25);
  --glow: 0 0 20px rgba(0, 240, 255, 0.35);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body.theme-light {
  --bg: #f0f4f8;
  --bg2: #e2e8f0;
  --card: #ffffff;
  --accent: #0891b2;
  --accent2: #db2777;
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(8, 145, 178, 0.3);
  --glow: 0 0 16px rgba(8, 145, 178, 0.25);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.3s, color 0.3s;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; margin-bottom: 12px; }

/* AUTH */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 16px;
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 28px;
  width: 100%; max-width: 400px;
  box-shadow: var(--glow), 0 20px 40px rgba(0,0,0,0.25);
  position: relative; overflow: hidden;
}
.auth-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}
.logo { text-align: center; margin-bottom: 24px; }
.logo h1 {
  font-size: 2rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  letter-spacing: 2px; font-weight: 800;
}
.logo p { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }
.tabs {
  display: flex; gap: 6px; margin-bottom: 20px;
  background: var(--bg2); padding: 4px; border-radius: 12px;
}
.tab {
  flex: 1; padding: 10px; border: none; background: transparent;
  color: var(--muted); border-radius: 10px; cursor: pointer; font-weight: 600;
}
.tab.active { background: var(--accent); color: #000; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.form-group input {
  width: 100%; padding: 12px 14px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 1rem; outline: none;
}
.form-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,240,255,0.12); }
.btn {
  width: 100%; padding: 13px; border: none; border-radius: 12px;
  font-weight: 700; font-size: 0.95rem; cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #00c4d4);
  color: #000; box-shadow: 0 4px 16px rgba(0,240,255,0.25);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-danger { background: linear-gradient(135deg, var(--red), #c41e3a); color: #fff; width: auto; padding: 8px 14px; }
.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  width: auto; padding: 8px 12px; border-radius: 10px;
}
.btn-sm { padding: 8px 12px; font-size: 0.85rem; width: auto; }
.error-msg {
  background: rgba(255,59,92,0.12); border: 1px solid var(--red);
  color: var(--red); padding: 10px 12px; border-radius: 8px;
  margin-bottom: 14px; font-size: 0.9rem; display: none;
}

/* LOBBY */
.lobby { max-width: 960px; margin: 0 auto; padding: 24px 16px; }
.header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 28px; flex-wrap: wrap; gap: 12px;
}
.header h2 { font-size: 1.5rem; }
.user-info { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--muted); font-size: 0.9rem; }
.user-info strong { color: var(--accent); }
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 720px) { .lobby-grid { grid-template-columns: 1fr; } }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px; box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
.card h3 { margin-bottom: 8px; color: var(--accent); font-size: 1.15rem; }
.role-btns, .map-btns { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.role-btn, .map-btn {
  flex: 1; min-width: 90px; padding: 12px 8px; border: 2px solid var(--border);
  background: var(--bg2); border-radius: 10px; color: var(--text);
  cursor: pointer; font-weight: 600; font-size: 0.9rem; transition: all 0.15s;
}
.role-btn:hover, .role-btn.selected, .map-btn:hover, .map-btn.selected {
  border-color: var(--accent); background: rgba(0,240,255,0.08); box-shadow: var(--glow);
}
.role-btn.attacker:hover, .role-btn.attacker.selected {
  border-color: var(--accent2); background: rgba(255,0,170,0.08);
  box-shadow: 0 0 16px rgba(255,0,170,0.25);
}
.join-row { display: flex; gap: 8px; margin-top: 10px; }
.join-row input {
  flex: 1; padding: 12px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); text-transform: uppercase;
  letter-spacing: 2px; font-weight: 700;
}
.join-row .btn { width: auto; padding: 12px 18px; }

/* MODALS */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px;
}
.modal-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 24px; max-width: 420px; width: 100%; max-height: 80vh; overflow-y: auto;
}
.lb-list, .skins-list { margin: 16px 0; }
.lb-item, .skin-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 0.95rem;
}
.skin-item { cursor: pointer; border-radius: 8px; border: 1px solid transparent; }
.skin-item:hover, .skin-item.active { border-color: var(--accent); background: rgba(0,240,255,0.06); }

/* GAME */
.game-page { display: none; height: 100vh; flex-direction: column; }
.game-top {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-wrap: wrap; gap: 8px; font-size: 0.9rem;
}
.stats { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.stat { font-weight: 700; }
.stat.gold { color: var(--gold); }
.stat.lives { color: var(--red); }
.top-right { display: flex; align-items: center; gap: 8px; }
.code-badge { color: var(--muted); font-size: 0.85rem; }
.game-main { flex: 1; display: flex; overflow: hidden; min-height: 0; }
.canvas-wrap { flex: 1; position: relative; min-width: 0; }
#gameCanvas {
  width: 100%; height: 100%; display: block; background: #0d1320; cursor: crosshair;
  touch-action: none;
}
.upgrade-panel {
  position: absolute; top: 12px; left: 12px; background: var(--card);
  border: 1px solid var(--border); border-radius: 12px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px; z-index: 20; min-width: 160px;
}
.sidebar {
  width: 260px; background: var(--card); border-left: 1px solid var(--border);
  padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
}
.shop-title { font-size: 1rem; color: var(--accent); font-weight: 700; }
.shop-item {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  background: var(--bg2); border: 1px solid transparent; border-radius: 10px;
  cursor: pointer; transition: all 0.12s;
}
.shop-item:hover, .shop-item.selected { border-color: var(--accent); background: rgba(0,240,255,0.07); }
.shop-item .icon {
  width: 36px; height: 36px; border-radius: 8px; display: flex;
  align-items: center; justify-content: center; font-size: 1.2rem;
}
.shop-item .name { font-weight: 600; font-size: 0.9rem; }
.shop-item .price { color: var(--gold); font-size: 0.8rem; }
.shop-item .desc { color: var(--muted); font-size: 0.72rem; }

.chat-box {
  margin-top: auto; border-top: 1px solid var(--border); padding-top: 10px;
  display: flex; flex-direction: column; gap: 6px; max-height: 220px;
}
.chat-title { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.chat-messages {
  flex: 1; overflow-y: auto; font-size: 0.8rem; max-height: 110px;
  display: flex; flex-direction: column; gap: 4px;
}
.chat-msg { line-height: 1.3; }
.chat-msg .u { color: var(--accent); font-weight: 600; }
.emoji-row { display: flex; gap: 4px; flex-wrap: wrap; }
.emoji-row button {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 6px; cursor: pointer; font-size: 1rem;
}
.chat-input-row { display: flex; gap: 4px; }
.chat-input-row input {
  flex: 1; padding: 8px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 0.85rem;
}
.chat-input-row button {
  padding: 8px 12px; background: var(--accent); border: none; border-radius: 8px;
  color: #000; font-weight: 700; cursor: pointer;
}

.waiting-overlay, .finished-overlay {
  position: fixed; inset: 0; background: rgba(10,14,23,0.93);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 100; gap: 16px; text-align: center; padding: 20px;
}
.waiting-overlay h2, .finished-overlay h2 { font-size: 1.7rem; color: var(--accent); }
.code-display {
  font-size: 2.2rem; letter-spacing: 6px; font-weight: 800;
  background: var(--card); padding: 14px 28px; border-radius: 12px;
  border: 2px solid var(--accent); box-shadow: var(--glow);
}
.finished-overlay.win h2 { color: var(--green); }
.finished-overlay.lose h2 { color: var(--red); }
.pulse { animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.45} }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--accent); padding: 10px 20px;
  border-radius: 10px; box-shadow: var(--glow); z-index: 300; font-size: 0.9rem;
}

/* MOBILE */
@media (max-width: 800px) {
  .game-main { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; max-height: 38vh;
    border-left: none; border-top: 1px solid var(--border);
    flex-direction: row; flex-wrap: wrap; align-items: flex-start;
  }
  #shopItems { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
  .shop-item { flex: 1 1 140px; }
  .chat-box { width: 100%; max-height: 140px; }
  .game-top { font-size: 0.8rem; }
  .stats { gap: 8px; }
}

@media (max-width: 480px) {
  .header { flex-direction: column; align-items: flex-start; }
  .user-info { font-size: 0.8rem; }
  .auth-card { padding: 24px 18px; }
}
