/* ═══════════════════════════════════════════
   DOTS & BOXES — Premium Dark Theme
   ═══════════════════════════════════════════ */

:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #111128;
  --bg-card: rgba(20, 20, 50, 0.6);
  --glass: rgba(255, 255, 255, 0.04);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-hover: rgba(255, 255, 255, 0.08);
  --text-primary: #e8e8f0;
  --text-secondary: #8888aa;
  --text-muted: #555577;
  --accent-1: #7c5cfc;
  --accent-2: #00d4ff;
  --accent-3: #ff2d95;
  --accent-4: #50fa7b;
  --gold: #ffd700;
  --p1-color: #7c5cfc;
  --p2-color: #ff2d95;
  --radius: 12px;
  --radius-lg: 20px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

#particleCanvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* ─── SCREENS ─── */
.screen { display: none; position: fixed; inset: 0; z-index: 1; }
.screen.active { display: flex; }

/* ─── GLASS CARD ─── */
.glass-card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border: none; border-radius: var(--radius);
  font-family: inherit; font-weight: 600; font-size: 0.95rem;
  cursor: pointer; transition: var(--transition); position: relative; overflow: hidden;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent-1), #5a3de8);
  color: #fff;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 25px rgba(124,92,252,0.4); }
.btn-secondary {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
}
.btn-secondary:hover { background: var(--glass-hover); border-color: var(--accent-2); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); }
.btn-full { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: 0.8rem; }
.btn-shine {
  position: absolute; top: 0; left: -100%; width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  transition: left 0.5s;
}
.btn-primary:hover .btn-shine { left: 100%; }

/* ─── AUTH SCREEN ─── */
#authScreen {
  align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, rgba(124,92,252,0.12) 0%, transparent 50%),
              radial-gradient(ellipse at 70% 80%, rgba(255,45,149,0.08) 0%, transparent 50%),
              var(--bg-primary);
}
.auth-container { width: 100%; max-width: 420px; padding: 20px; }

.logo-section { text-align: center; margin-bottom: 32px; }
.logo-dots {
  position: relative; width: 80px; height: 80px; margin: 0 auto 16px;
}
.logo-dot {
  position: absolute; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent-2); box-shadow: 0 0 12px var(--accent-2);
}
.d1 { top: 0; left: 0; } .d2 { top: 0; right: 0; }
.d3 { bottom: 0; left: 0; } .d4 { bottom: 0; right: 0; background: var(--accent-3); box-shadow: 0 0 12px var(--accent-3); }
.logo-line {
  position: absolute; background: var(--accent-1); border-radius: 2px;
}
.l1 { top: 6px; left: 14px; width: 52px; height: 3px; }
.l2 { bottom: 6px; left: 14px; width: 52px; height: 3px; }
.l3 { top: 14px; left: 6px; width: 3px; height: 52px; }
.l4 { top: 14px; right: 6px; width: 3px; height: 52px; }

.logo-title {
  font-size: 2.2rem; font-weight: 900; letter-spacing: 3px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent-1), var(--accent-3));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.logo-subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-top: 4px; }

.auth-card { padding: 32px; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 24px; background: var(--glass); border-radius: var(--radius); padding: 4px; }
.auth-tab {
  flex: 1; padding: 10px; border: none; background: none; color: var(--text-secondary);
  font-family: inherit; font-weight: 600; border-radius: 8px; cursor: pointer; transition: var(--transition);
}
.auth-tab.active { background: var(--accent-1); color: #fff; }

.auth-form { display: none; flex-direction: column; gap: 16px; }
.auth-form.active { display: flex; }

.input-group { position: relative; }
.input-group input {
  width: 100%; padding: 14px 16px; background: var(--glass);
  border: 1px solid var(--glass-border); border-radius: var(--radius);
  color: var(--text-primary); font-family: inherit; font-size: 0.95rem;
  transition: var(--transition); outline: none;
}
.input-group input:focus { border-color: var(--accent-1); }
.input-group input::placeholder { color: var(--text-muted); }
.input-glow {
  position: absolute; inset: -1px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent-1), var(--accent-3));
  opacity: 0; z-index: -1; transition: opacity 0.3s; filter: blur(8px);
}
.input-group input:focus ~ .input-glow { opacity: 0.3; }

.error-msg { color: var(--accent-3); font-size: 0.85rem; text-align: center; min-height: 20px; margin-top: 12px; }
.success-msg { color: var(--accent-4); font-size: 0.85rem; text-align: center; min-height: 20px; margin-top: 12px; }

/* ─── TOP NAV ─── */
.top-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px;
  background: rgba(10,10,26,0.8); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border); z-index: 10;
}
.nav-left, .nav-right { display: flex; align-items: center; gap: 16px; }
.nav-logo { font-weight: 800; font-size: 1.1rem; color: var(--accent-2); }
.nav-online { font-size: 0.8rem; color: var(--accent-4); }
.nav-points {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px; background: var(--glass); border-radius: 20px;
  border: 1px solid var(--glass-border); font-weight: 600;
}
.pip-icon { color: var(--gold); }
.nav-user { font-weight: 600; }

/* ─── MENU SCREEN ─── */
#menuScreen {
  flex-direction: column;
  background: radial-gradient(ellipse at 50% 0%, rgba(124,92,252,0.08) 0%, transparent 50%), var(--bg-primary);
  overflow-y: auto;
}
.menu-content { flex: 1; padding: 24px; max-width: 900px; margin: 0 auto; width: 100%; }
.menu-hero { text-align: center; margin-bottom: 32px; }
.menu-title { font-size: 1.6rem; font-weight: 700; margin-bottom: 16px; }
.menu-title span { color: var(--accent-2); }

.stats-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.stat-pill {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 20px; background: var(--glass); border: 1px solid var(--glass-border);
  border-radius: var(--radius); min-width: 80px;
}
.stat-pill.streak { border-color: rgba(255,165,0,0.3); }
.stat-label { font-size: 0.7rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; }
.stat-value { font-size: 1.3rem; font-weight: 800; font-family: 'JetBrains Mono', monospace; }

.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.menu-card {
  padding: 24px; text-align: center; transition: var(--transition); cursor: pointer;
}
.menu-card:hover { transform: translateY(-4px); border-color: var(--accent-1); }
.card-icon { font-size: 2.4rem; margin-bottom: 8px; }
.menu-card h3 { font-size: 1.1rem; margin-bottom: 4px; }
.menu-card p { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 16px; }

.grid-size-selector { margin-bottom: 16px; }
.grid-size-selector label { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; display: block; margin-bottom: 8px; }
.size-options { display: flex; gap: 6px; }
.size-btn {
  flex: 1; padding: 8px 4px; border: 1px solid var(--glass-border); background: var(--glass);
  color: var(--text-secondary); border-radius: 8px; cursor: pointer; font-family: inherit;
  font-weight: 600; font-size: 0.8rem; transition: var(--transition);
}
.size-btn.active { background: var(--accent-1); color: #fff; border-color: var(--accent-1); }

/* ─── MATCHMAKING ─── */
#matchmakingScreen {
  align-items: center; justify-content: center;
  background: var(--bg-primary);
}
.matchmaking-card { padding: 48px; text-align: center; }
.spinner-ring {
  width: 60px; height: 60px; margin: 0 auto 24px;
  border: 3px solid var(--glass-border); border-top-color: var(--accent-2);
  border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.mm-tip { color: var(--text-muted); font-size: 0.8rem; font-style: italic; margin-top: 8px; }

/* ─── GAME SCREEN ─── */
#gameScreen {
  flex-direction: column;
  background: radial-gradient(ellipse at 50% 50%, rgba(124,92,252,0.05) 0%, transparent 60%), var(--bg-primary);
}
.game-layout { display: flex; flex-direction: column; height: 100%; }

.game-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px;
  background: rgba(10,10,26,0.8); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
}
.player-info { display: flex; align-items: center; gap: 12px; }
.player-avatar {
  width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.8rem;
}
.p1-avatar { background: linear-gradient(135deg, var(--p1-color), #5a3de8); color: #fff; }
.p2-avatar { background: linear-gradient(135deg, var(--p2-color), #cc1177); color: #fff; }
.player-details { display: flex; flex-direction: column; }
.player-details.right { text-align: right; }
.player-name { font-weight: 600; font-size: 0.9rem; }
.player-score { font-family: 'JetBrains Mono', monospace; font-weight: 800; font-size: 1.3rem; }
#p1Score { color: var(--p1-color); }
#p2Score { color: var(--p2-color); }

.turn-indicator {
  padding: 8px 20px; border-radius: 20px;
  background: var(--glass); border: 1px solid var(--glass-border);
  font-weight: 600; font-size: 0.85rem;
  animation: pulse-glow 2s infinite;
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 10px rgba(124,92,252,0.2); }
  50% { box-shadow: 0 0 20px rgba(124,92,252,0.5); }
}

.game-board-container {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
#gameCanvas { max-width: 100%; max-height: 100%; }

.game-footer { padding: 12px 24px; border-top: 1px solid var(--glass-border); }
.emote-bar { display: flex; gap: 8px; justify-content: center; }
.emote-btn {
  padding: 8px 14px; border: 1px solid var(--glass-border); background: var(--glass);
  border-radius: 20px; cursor: pointer; font-size: 1.1rem; transition: var(--transition);
}
.emote-btn:hover { transform: scale(1.15); border-color: var(--accent-2); }

.emote-overlay {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: 4rem; pointer-events: none; z-index: 100; opacity: 0;
  transition: opacity 0.3s;
}
.emote-overlay.show { opacity: 1; animation: emote-pop 1.5s forwards; }
@keyframes emote-pop {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translate(-50%, -80%) scale(1); opacity: 0; }
}

/* ─── MODALS ─── */
.modal {
  display: none; position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(6px);
  align-items: center; justify-content: center; padding: 20px;
}
.modal.active { display: flex; }
.modal-content { width: 100%; max-width: 600px; max-height: 80vh; overflow-y: auto; padding: 32px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.modal-header h2 { font-size: 1.3rem; }
.modal-close {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--glass-border);
  background: var(--glass); color: var(--text-primary); font-size: 1.1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center; transition: var(--transition);
}
.modal-close:hover { background: var(--accent-3); color: #fff; }

/* Result Modal */
.result-card { text-align: center; }
.result-icon { font-size: 4rem; margin-bottom: 8px; }
.result-scores { display: flex; align-items: center; justify-content: center; gap: 24px; margin: 20px 0; }
.result-score { text-align: center; }
.result-score span:first-child { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 4px; }
.result-score span:last-child { font-size: 2rem; font-weight: 900; font-family: 'JetBrains Mono', monospace; }
.result-vs { color: var(--text-muted); font-weight: 700; }
.result-points { font-size: 1.2rem; font-weight: 700; color: var(--gold); margin-bottom: 20px; }

/* Shop */
.shop-modal-content { max-width: 700px; }
.shop-balance { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 1.1rem; }
.shop-tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--glass); border-radius: var(--radius); padding: 4px; }
.shop-tab {
  flex: 1; padding: 8px; border: none; background: none; color: var(--text-secondary);
  font-family: inherit; font-weight: 600; border-radius: 8px; cursor: pointer; transition: var(--transition); font-size: 0.85rem;
}
.shop-tab.active { background: var(--accent-1); color: #fff; }

.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.shop-item {
  padding: 16px; border-radius: var(--radius); background: var(--glass);
  border: 1px solid var(--glass-border); text-align: center; transition: var(--transition);
}
.shop-item:hover { border-color: var(--accent-1); transform: translateY(-2px); }
.shop-item-preview {
  width: 48px; height: 48px; margin: 0 auto 8px; border-radius: 50%;
}
.shop-item-name { font-weight: 600; font-size: 0.85rem; margin-bottom: 4px; }
.shop-item-rarity { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
.rarity-common { color: #888; } .rarity-uncommon { color: var(--accent-4); }
.rarity-rare { color: var(--accent-2); } .rarity-epic { color: var(--accent-1); }
.rarity-legendary { color: var(--gold); }
.shop-item-price { display: flex; align-items: center; justify-content: center; gap: 4px; font-weight: 700; margin-bottom: 8px; }
.shop-item .btn { padding: 6px 16px; font-size: 0.8rem; }
.shop-item.owned { opacity: 0.6; border-color: var(--accent-4); }

/* Leaderboard */
.lb-modal-content { max-width: 500px; }
.lb-tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--glass); border-radius: var(--radius); padding: 4px; }
.lb-tab {
  flex: 1; padding: 8px; border: none; background: none; color: var(--text-secondary);
  font-family: inherit; font-weight: 600; border-radius: 8px; cursor: pointer; transition: var(--transition); font-size: 0.8rem;
}
.lb-tab.active { background: var(--accent-1); color: #fff; }
.lb-list { display: flex; flex-direction: column; gap: 6px; }
.lb-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--glass); border-radius: var(--radius);
  border: 1px solid var(--glass-border);
}
.lb-rank { font-weight: 900; font-family: 'JetBrains Mono', monospace; width: 30px; text-align: center; }
.lb-rank.gold { color: var(--gold); font-size: 1.2rem; }
.lb-rank.silver { color: #c0c0c0; font-size: 1.1rem; }
.lb-rank.bronze { color: #cd7f32; font-size: 1.05rem; }
.lb-name { flex: 1; font-weight: 600; }
.lb-value { font-weight: 700; font-family: 'JetBrains Mono', monospace; color: var(--accent-2); }

/* Profile */
.profile-modal-content { max-width: 500px; }
.profile-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 20px; }
.profile-stat {
  padding: 14px; background: var(--glass); border-radius: var(--radius);
  border: 1px solid var(--glass-border); text-align: center;
}
.profile-stat-label { font-size: 0.7rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; }
.profile-stat-value { font-size: 1.5rem; font-weight: 800; font-family: 'JetBrains Mono', monospace; }
.profile-history h3 { font-size: 1rem; margin-bottom: 12px; color: var(--text-secondary); }
.profile-match {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: var(--glass); border-radius: 8px;
  margin-bottom: 6px; border: 1px solid var(--glass-border);
}
.profile-match.win { border-left: 3px solid var(--accent-4); }
.profile-match.loss { border-left: 3px solid var(--accent-3); }

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

/* ─── RESPONSIVE ─── */
@media (max-width: 600px) {
  .logo-title { font-size: 1.6rem; }
  .menu-grid { grid-template-columns: 1fr; }
  .game-header { padding: 8px 12px; }
  .player-name { font-size: 0.75rem; }
  .turn-indicator { font-size: 0.75rem; padding: 6px 12px; }
  .modal-content { padding: 20px; }
}
