/* EL3AB Design System */

:root {
  /* Background Layers */
  --bg-0: #050D17;
  --bg-1: #0A1525;
  --bg-2: #142640;
  --bg-3: #1C3254;

  /* Brand */
  --gold: #E7A832;
  --gold-dark: #C48B1A;
  --cyan: #15D7FF;
  --cyan-dark: #0BA8C9;
  --blue: #2979FF;
  --purple: #7C4DFF;

  /* Status */
  --success: #34D399;
  --error: #EF4444;
  --warning: #F59E0B;
  --online: #22C55E;

  /* Text */
  --text-1: #F1F5F9;
  --text-2: #94A3B8;
  --text-3: #64748B;
  --text-inverse: #0F172A;

  /* Border */
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.16);

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);

  /* Sizes */
  --header-h: 56px;
  --nav-bottom-h: 64px;
  --nav-desktop-w: 72px;
  --content-max: 600px;
  --touch-min: 48px;

  /* Fonts */
  --font-ar: 'IBM Plex Sans Arabic', 'Segoe UI', sans-serif;
  --font-en: 'Inter', 'Segoe UI', sans-serif;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  /* Elevation system */
  --elevation-1: 0 1px 2px rgba(0,0,0,0.2);
  --elevation-2: 0 4px 12px rgba(0,0,0,0.3);
  --elevation-3: 0 8px 24px rgba(0,0,0,0.4);
  --elevation-4: 0 12px 40px rgba(0,0,0,0.5);

  /* Responsive typography */
  --text-page: clamp(22px, 2vw + 16px, 28px);
  --text-section: clamp(12px, 0.5vw + 10px, 14px);
  --text-body: clamp(13px, 0.5vw + 11px, 15px);

  /* Spacing & Layout (admin-editable) */
  --card-padding: 16px;
  --section-gap: 16px;

  /* Board Theme — Chess.com green */
  --board-light: #EBECD0;
  --board-dark: #779556;
  --board-selected: rgba(255, 255, 50, 0.5);
  --board-legal: rgba(0, 0, 0, 0.15);
  --board-last-move: rgba(255, 255, 50, 0.4);
  --board-check: rgba(255, 0, 0, 0.6);
  --board-premove: rgba(21, 180, 240, 0.3);
  --board-highlight-green: rgba(21, 180, 90, 0.4);
  --board-highlight-red: rgba(220, 50, 50, 0.4);
  --board-highlight-yellow: rgba(220, 180, 30, 0.4);

  /* Eval Bar */
  --eval-bg: #1a1a2e;
  --eval-white: #f0f0f0;
  --eval-label-light: #fff;
  --eval-label-dark: #333;

  /* Move Classifications */
  --move-brilliant: #26c6da;
  --move-great: #66bb6a;
  --move-good: #81c784;
  --move-book: #9e9e9e;
  --move-inaccuracy: #fdd835;
  --move-mistake: #ef6c00;
  --move-blunder: #e53935;

  /* Analysis Move Text (slightly different palette) */
  --move-text-brilliant: #00bcd4;
  --move-text-great: #2196f3;
  --move-text-good: #4caf50;
  --move-text-inaccuracy: #ff9800;
  --move-text-mistake: #f44336;
  --move-text-blunder: #d32f2f;

  /* Arrows */
  --arrow-green: rgba(21, 180, 90, 0.7);
  --arrow-red: rgba(220, 50, 50, 0.7);
  --arrow-yellow: rgba(220, 180, 30, 0.7);

  /* Graph / Canvas */
  --graph-bg: #0a1628;
  --graph-grid: #333;
  --graph-accent: #15d7ff;
  --graph-error: #f44336;

  /* Overlays */
  --overlay-dark: rgba(0, 0, 0, 0.8);
  --overlay-result: rgba(5, 13, 23, 0.92);
  --overlay-error-bg: rgba(239, 68, 68, 0.1);
  --overlay-error-border: rgba(239, 68, 68, 0.2);

  /* Bot Avatars */
  --bot-amina: #4ade80, #22c55e;
  --bot-tarek: #38bdf8, #0ea5e9;
  --bot-nour: #a78bfa, #7c3aed;
  --bot-omar: #fb923c, #ea580c;
  --bot-layla: #f472b6, #db2777;
  --bot-ziad: #f87171, #dc2626;
  --bot-gm: var(--gold), #b45309;

  /* Ludo */
  --ludo-p1: #E53935;
  --ludo-p2: #43A047;
  --ludo-p3: #FDD835;
  --ludo-p4: #1E88E5;
  --ludo-board-bg: #1a2332;
  --ludo-path: #f5f5f5;
  --ludo-path-border: rgba(0,0,0,0.1);
  --ludo-safe: #FFD54F;
  --ludo-home-p1: rgba(229,57,53,0.3);
  --ludo-home-p2: rgba(67,160,71,0.3);
  --ludo-home-p3: rgba(253,216,53,0.3);
  --ludo-home-p4: rgba(30,136,229,0.3);
  --ludo-dice-bg: var(--bg-2);
  --ludo-dice-dot: var(--text-inverse);
  --ludo-chat-bg: var(--bg-2);
}

/* Reset */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  direction: rtl;
  font-family: var(--font-ar);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-1);
  background: var(--bg-0);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
}

input, select, textarea {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

img {
  display: block;
  max-width: 100%;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: var(--radius-full); }

/* Latin text override */
.font-en { font-family: var(--font-en); direction: ltr; unicode-bidi: embed; }

/* Icon base */
.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.icon-sm, .icon-lg, .icon-xl { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }
.icon-xl { width: 32px; height: 32px; }
.icon-fill { fill: currentColor; stroke: none; }

/* ==================== LAYOUT ==================== */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  background: rgba(10, 21, 37, 0.75);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  max-width: calc(var(--content-max) + 40px);
  margin: 0 auto;
  padding: 0 20px;
}

.header-logo {
  font-family: var(--font-en);
  font-weight: 800;
  font-size: 20px;
  color: var(--gold);
  letter-spacing: -0.5px;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-en);
}

.header-bell {
  position: relative;
  padding: 8px;
  margin: -8px;
  color: var(--text-2);
}

.header-badge {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--error);
  border-radius: var(--radius-full);
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--eval-label-light);
}

/* Main content */
.main {
  flex: 1;
  padding-bottom: calc(var(--nav-bottom-h) + env(safe-area-inset-bottom) + 40px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.main-inner {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 24px 16px 48px;
}

@media (min-width: 400px) {
  .main-inner {
    padding: 28px 20px 48px;
  }
}

/* Desktop nav */
.nav-desktop {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--nav-desktop-w);
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 4px;
  background: rgba(10, 21, 37, 0.8);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  z-index: 50;
  overflow-y: auto;
}

.nav-desktop-logo {
  font-family: var(--font-en);
  font-weight: 800;
  font-size: 14px;
  color: var(--gold);
  margin-bottom: 16px;
}

.nav-desktop-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  color: var(--text-3);
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
  text-decoration: none;
}

.nav-desktop-item:hover { color: var(--text-2); }
.nav-desktop-item.active { background: rgba(21, 215, 255, 0.08); color: var(--cyan); }

.nav-desktop-label {
  font-size: 9px;
  margin-top: 2px;
}

/* Bottom nav (mobile) */
.nav-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  height: calc(var(--nav-bottom-h) + env(safe-area-inset-bottom));
  background: rgba(10, 21, 37, 0.92);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  padding-top: 8px;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-bottom-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  color: var(--text-3);
  transition: color 0.2s var(--ease);
  text-decoration: none;
  padding: 4px 0;
}

.nav-bottom-item.active { color: var(--cyan); }

.nav-bottom-label {
  font-size: 10px;
  font-weight: 500;
  line-height: 1;
}

/* Tablet responsive */
@media (min-width: 768px) and (max-width: 1023px) {
  .main-inner {
    max-width: 720px;
    padding: 32px 24px 48px;
  }
  .games-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .nav-bottom-label {
    font-size: 11px;
  }
  .lobby-card .card-body {
    padding: 24px;
  }
  .lobby-card-row {
    padding: 20px 24px;
  }
}

/* Desktop responsive */
@media (min-width: 1024px) {
  .nav-desktop { display: flex; }
  .nav-bottom { display: none; }
  .main { padding-bottom: 24px; margin-right: var(--nav-desktop-w); }
  .header { margin-right: var(--nav-desktop-w); }
}

/* ==================== COMPONENTS ==================== */

/* Cards */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-body { padding: 18px; }
.card-body-lg { padding: 24px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch-min);
  padding: 12px 24px;
  font-weight: 600;
  font-size: 14px;
  border-radius: var(--radius-md);
  transition: transform 0.1s var(--ease), opacity 0.2s var(--ease);
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn-gold { background: var(--gold); color: var(--text-inverse); position: relative; overflow: hidden; }
.btn-gold::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  animation: shimmer-sweep 3s ease-in-out infinite;
}
.btn-cyan { background: var(--cyan); color: var(--text-inverse); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-2); }
.btn-error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.2); color: var(--error); }
.btn-ghost { background: transparent; color: var(--text-2); }

.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 56px; font-size: 16px; font-weight: 700; border-radius: var(--radius-lg); }
.btn-sm { min-height: 36px; padding: 8px 16px; font-size: 12px; }

/* Button ripple */
.btn {
  position: relative;
  overflow: hidden;
}

.btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  transform: scale(0);
  animation: ripple-expand 0.5s ease-out forwards;
  pointer-events: none;
}

@keyframes ripple-expand {
  to { transform: scale(4); opacity: 0; }
}

/* Card hover/tap lift */
.card {
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card:active {
  transform: translateY(-1px);
}

/* Inputs */
.input-group { margin-bottom: 16px; }

.input-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}

.input {
  width: 100%;
  height: var(--touch-min);
  padding: 0 16px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-1);
  font-size: 14px;
  transition: border-color 0.2s var(--ease);
}

.input:focus { border-color: var(--cyan); }
.input::placeholder { color: var(--text-3); }

/* Section headers */
.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

/* Page title */
.page-title {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 24px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 24px;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-md);
  white-space: nowrap;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  transition: all 0.2s var(--ease);
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tab.active { background: var(--cyan); border-color: var(--cyan); color: var(--text-inverse); }

/* Tab group (inline selection - time control, bot difficulty, etc.) */
.tab-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab-group .tab {
  flex: 1;
  min-width: 56px;
  text-align: center;
  padding: 10px 12px;
}

/* List items */
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.list-item:last-child { border-bottom: none; }

/* Avatar */
.avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--bg-3);
  overflow: hidden;
  flex-shrink: 0;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 32px; height: 32px; }
.avatar-lg { width: 64px; height: 64px; }
.avatar-xl { width: 96px; height: 96px; }

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  border-radius: var(--radius-full);
}

.badge-gold { background: rgba(231,168,50,0.15); color: var(--gold); }
.badge-cyan { background: rgba(21,215,255,0.15); color: var(--cyan); }
.badge-error { background: rgba(239,68,68,0.15); color: var(--error); }
.badge-success { background: rgba(52,211,153,0.15); color: var(--success); }

/* Toast */
.toast-container {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.3s var(--ease);
  pointer-events: auto;
}

.toast-success { border-color: var(--success); }
.toast-error { border-color: var(--error); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Empty state */
.empty-state {
  padding: 56px 24px;
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.empty-state .icon,
.empty-state .icon-lg {
  color: var(--text-3);
  opacity: 0.5;
  margin-bottom: 4px;
}

.empty-state p {
  max-width: 240px;
  line-height: 1.5;
}

/* Skeleton loader */
.skeleton {
  background: var(--bg-2);
  border-radius: var(--radius-md);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Stat grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 400px) {
  .stat-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: center;
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  font-family: var(--font-en);
}

.stat-label {
  font-size: 10px;
  color: var(--text-3);
  margin-top: 2px;
}

/* Toggle (class-based, legacy) */
.toggle-legacy {
  width: 44px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--bg-3);
  position: relative;
  cursor: pointer;
  transition: background 0.2s var(--ease);
}

.toggle-legacy.active { background: var(--cyan); }

.toggle-knob {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--eval-label-light);
  transition: right 0.2s var(--ease);
}

.toggle-legacy.active .toggle-knob { right: 22px; }

/* Spacing utilities */
.space-y-2 > * + * { margin-top: 8px; }
.space-y-3 > * + * { margin-top: 12px; }
.space-y-4 > * + * { margin-top: 16px; }
.space-y-5 > * + * { margin-top: 20px; }
.space-y-6 > * + * { margin-top: 24px; }
.space-y-8 > * + * { margin-top: 32px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.pt-2 { padding-top: 8px; }
.pb-4 { padding-bottom: 16px; }
.text-center { text-align: center; }
.text-gold { color: var(--gold); }
.text-cyan { color: var(--cyan); }
.text-error { color: var(--error); }
.text-success { color: var(--success); }
.text-muted { color: var(--text-3); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.fw-bold { font-weight: 700; }

/* ===== Lazy Image Placeholder ===== */
.img-lazy {
  position: relative;
  background: var(--bg-3);
  overflow: hidden;
}

.img-lazy::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.04), transparent);
  animation: skeleton-shimmer 1.5s infinite;
}

.img-lazy img {
  opacity: 0;
  transition: opacity 0.3s;
}

.img-lazy--loaded::before {
  display: none;
}

.img-lazy--loaded img {
  opacity: 1;
}

/* ===== Streak Calendar Strip ===== */
.streak-strip {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.streak-day {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border-strong);
  transition: all 0.3s var(--ease);
}

.streak-day--claimed {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--text-inverse);
}

.streak-day--claimed .streak-day-num {
  display: none;
}

.streak-day--claimed::after {
  content: '✓';
  font-size: 14px;
  font-weight: 700;
}

.streak-day--current {
  border-color: var(--cyan);
  animation: streak-pulse 1.5s ease-in-out infinite;
}

@keyframes streak-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(21, 215, 255, 0.3); }
  50% { box-shadow: 0 0 0 4px rgba(21, 215, 255, 0.1); }
}

.streak-day-num {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
}

.streak-day--claimed .streak-day-num,
.streak-day--current .streak-day-num {
  color: var(--text-1);
}

/* ===== Skeleton Loading ===== */
.skeleton {
  background: var(--bg-3);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.04), transparent);
  animation: skeleton-shimmer 1.5s infinite;
}

@keyframes skeleton-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.skeleton-text {
  height: 14px;
  width: 60%;
  margin-bottom: 8px;
}

.skeleton-text--short { width: 40%; }
.skeleton-text--full { width: 100%; }

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
}

.skeleton-card {
  height: 80px;
  border-radius: var(--radius-lg);
}

/* ===== Page Transitions ===== */
.main-inner {
  animation: page-enter 0.3s var(--ease) both;
}

@keyframes page-enter {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.page-exit {
  animation: page-exit 0.2s var(--ease) both;
}

@keyframes page-exit {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(-12px);
  }
}

/* ===== Gradient Accent Border ===== */
.card-accent {
  position: relative;
  border: none;
}

.card-accent::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  padding: 2px;
  background: linear-gradient(135deg, var(--gold), var(--cyan));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* ===== Breadcrumb ===== */
.breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-3);
  text-decoration: none;
  transition: color 0.2s;
}

.breadcrumb:hover {
  color: var(--cyan);
}

/* ===== Games Hub ===== */
.games-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.game-card {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.game-card:hover,
.game-card:active {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.game-card--soon {
  opacity: 0.6;
  pointer-events: none;
}

.game-card-cover {
  position: relative;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-card-cover--chess {
  background: linear-gradient(135deg, #1a2a4a, #2a4a6a);
}

.game-card-cover--ludo {
  background: linear-gradient(135deg, #2a1a3a, #4a2a5a);
}

.game-card-cover--domino {
  background: linear-gradient(135deg, #1a3a2a, #2a5a4a);
}

.game-card-cover--backgammon {
  background: linear-gradient(135deg, #3a2a1a, #5a4a2a);
}

.game-card-cover--trix {
  background: linear-gradient(135deg, #1a1a3a, #3a2a5a);
}

.game-card-cover--baloot {
  background: linear-gradient(135deg, #3a1a1a, #5a2a2a);
}

.game-card-icon {
  width: 40px;
  height: 40px;
  color: rgba(255, 255, 255, 0.9);
}

.game-card-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--gold);
  color: var(--text-inverse);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.game-card-info {
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.game-card-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.game-card-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-1);
}

.online-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-3);
}

.online-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--online);
}

.game-card-play {
  white-space: nowrap;
}

@media (max-width: 767px) {
  .games-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .game-card-cover {
    height: 80px;
  }
}

@media (min-width: 1024px) {
  .games-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .game-card-cover {
    height: 120px;
  }
}

/* ===== Visual Improvements ===== */

/* Better avatar placeholder */
.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg-3), var(--bg-2));
}

/* Profile header gradient */
.profile-card-header {
  background: linear-gradient(135deg, rgba(21, 215, 255, 0.08), rgba(231, 168, 50, 0.05));
}

/* Better list items */
.list-item {
  transition: background 0.15s var(--ease);
}

.list-item:active {
  background: rgba(255, 255, 255, 0.03);
}

/* Better tabs */
.tab {
  min-width: 64px;
  text-align: center;
}

/* Section divider */
.section-divider {
  height: 1px;
  background: var(--border);
  margin: 24px 0;
}

/* Better input focus glow */
.input:focus {
  box-shadow: 0 0 0 3px rgba(21, 215, 255, 0.1);
}

/* Game mode card improvements */
.card-body {
  transition: background 0.15s var(--ease);
}

/* Better button hover states */
.btn-gold:active { background: var(--gold-dark); }
.btn-cyan:active { background: var(--cyan-dark); }

/* Selection pills (time control, bot count, etc) */
.pill-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  min-width: 44px;
  height: 36px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--bg-3);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}

.pill.active,
.pill:active {
  background: var(--cyan);
  border-color: var(--cyan);
  color: var(--text-inverse);
}

/* Progress bar component */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-3);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--cyan), var(--gold));
  transition: width 0.5s var(--ease);
}

/* Notification dot */
.notif-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: var(--error);
  border-radius: 50%;
  border: 2px solid var(--bg-1);
}

/* Card-body padding on mobile */
@media (max-width: 767px) {
  .card-body { padding: 16px; }
  .card-body-lg { padding: 20px; }
}

/* Divider with text */
.divider-text {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-3);
  font-size: 12px;
  margin: 16px 0;
}

.divider-text::before,
.divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Animated gradient text */
.text-gradient {
  background: linear-gradient(135deg, var(--gold), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Focus visible for a11y */
.btn:focus-visible,
.tab:focus-visible,
.input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* Game result overlay improvements */
.game-result {
  animation: result-in 0.4s var(--ease);
}

@keyframes result-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* Haptic feedback visual pulse on game actions */
.pulse-feedback {
  animation: action-pulse 0.3s var(--ease);
}

@keyframes action-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* ===== Win Streak Fire Badge ===== */
.streak-fire::before {
  content: '🔥';
  position: absolute;
  top: -2px;
  right: -2px;
  font-size: 10px;
  animation: fire-flicker 1s ease-in-out infinite alternate;
}

@keyframes fire-flicker {
  from { transform: scale(1); }
  to { transform: scale(1.2); }
}

/* ===== Bottom Sheet Modal ===== */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.3s var(--ease);
  pointer-events: none;
}

.sheet-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 91;
  background: var(--bg-1);
  border-top-left-radius: var(--radius-xl);
  border-top-right-radius: var(--radius-xl);
  padding: 16px 20px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.3s var(--ease);
  max-height: 80vh;
  overflow-y: auto;
}

.sheet.active {
  transform: translateY(0);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--text-3);
  border-radius: var(--radius-full);
  margin: 0 auto 16px;
}

/* ===== Pull to Refresh ===== */
.ptr-indicator {
  position: fixed;
  top: calc(var(--header-h) + 8px);
  left: 50%;
  transform: translateX(-50%) scale(0);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-2);
  border: 2px solid var(--cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 35;
  transition: transform 0.2s var(--ease);
}

.ptr-indicator.active {
  transform: translateX(-50%) scale(1);
}

.ptr-indicator.loading {
  transform: translateX(-50%) scale(1);
  animation: ptr-spin 0.8s linear infinite;
}

@keyframes ptr-spin {
  to { transform: translateX(-50%) scale(1) rotate(360deg); }
}

/* ===== Enhanced Toasts ===== */
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  overflow: hidden;
}

.toast-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--cyan);
  animation: toast-countdown 3s linear forwards;
}

.toast-success .toast-progress { background: var(--success); }
.toast-error .toast-progress { background: var(--error); }

@keyframes toast-countdown {
  from { width: 100%; }
  to { width: 0%; }
}

/* ===== Nav Sliding Indicator ===== */
.nav-desktop-item.active {
  position: relative;
}

.nav-desktop-item.active::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 24px;
  background: var(--cyan);
  border-radius: var(--radius-full);
}

.nav-bottom-item.active::after {
  content: '';
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 3px;
  background: var(--cyan);
  border-radius: var(--radius-full);
}

.nav-bottom-item {
  position: relative;
}

/* ===== Animated Background (Games Hub) ===== */
.bg-animated {
  background: linear-gradient(135deg, var(--bg-0), var(--bg-1), var(--bg-2), var(--bg-1));
  background-size: 400% 400%;
  animation: bg-shift 15s ease infinite;
}

@keyframes bg-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* ===== Gold Shimmer ===== */
.shimmer {
  position: relative;
  overflow: hidden;
}

.shimmer::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  animation: shimmer-sweep 3s ease-in-out infinite;
}

@keyframes shimmer-sweep {
  0% { left: -100%; }
  100% { left: 150%; }
}

/* ===== Celebration Overlay ===== */
.celebrate-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  animation: celebrate-in 0.3s var(--ease);
}

@keyframes celebrate-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.celebrate-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(231, 168, 50, 0.5);
  animation: celebrate-bounce 0.5s var(--ease) 0.2s both;
}

@keyframes celebrate-bounce {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

.confetti-particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  animation: confetti-fall 2.5s ease-out forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

/* ===== Responsive Typography ===== */
.page-title {
  font-size: var(--text-page);
}

.section-title {
  font-size: var(--text-section);
}

/* ===== Safe Area Handling ===== */
@supports (padding: env(safe-area-inset-top)) {
  .main-inner {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* ===== Landscape Game Layout ===== */
@media (orientation: landscape) and (max-height: 500px) {
  .header { height: 40px; }
  .header-inner { padding: 0 12px; }
  .nav-bottom { height: 48px; }
  .main { padding-bottom: 48px; }
}

/* ===== Clock Urgency (Chess) ===== */
.clock-urgent {
  animation: clock-pulse 1s ease-in-out infinite;
  color: var(--error) !important;
}

.clock-critical {
  animation: clock-shake 0.3s ease-in-out infinite;
  color: var(--error) !important;
}

@keyframes clock-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes clock-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}

/* ===== Lobby Pages (Play / Ludo) ===== */
.lobby-page {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.lobby-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

.lobby-cards {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 24px;
}

.lobby-card {
  border-radius: var(--radius-lg);
}

.lobby-card--featured {
  border: 2px solid var(--gold);
  box-shadow: 0 0 20px rgba(231, 168, 50, 0.08);
}

.lobby-card .card-body {
  padding: 20px;
}

@media (max-width: 400px) {
  .lobby-card .card-body {
    padding: 16px;
  }
}

.lobby-card-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.lobby-card-title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}

.lobby-card-title-sm {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.lobby-card-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
}

@media (max-width: 400px) {
  .lobby-card-row {
    padding: 16px;
    gap: 12px;
  }
}

.lobby-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
}

.lobby-btn-pair {
  display: flex;
  gap: 10px;
}

.lobby-btn-pair .btn {
  flex: 1;
}

.lobby-code-row {
  display: flex;
  gap: 10px;
}

.lobby-code-row .input {
  flex: 1;
}

.avatar-game {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ===== Input Label Spacing ===== */
.input-label {
  margin-bottom: 8px;
}

/* ===== Toggle (checkbox-based) ===== */
.toggle {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-3);
  border-radius: var(--radius-full);
  transition: background 0.2s var(--ease);
  cursor: pointer;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  transition: transform 0.2s var(--ease);
}

.toggle input:checked + .toggle-slider {
  background: var(--cyan);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(-22px);
}

/* ===== Better select dropdown ===== */
select.input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  padding-left: 36px;
}

/* ===== Scrollable page guarantee ===== */
@media (max-width: 767px) {
  .main {
    min-height: calc(100dvh - var(--header-h));
  }
  .lobby-cards {
    padding-bottom: 16px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
