/* ==========================================================================
   1. DESIGN TOKENS & VARIABLES
   ========================================================================== */
:root {
  /* --- Brand Palette --- */
  --primary-50:#f0f9ff; --primary-100:#e0f2fe; --primary-200:#bae6fd;
  --primary-300:#7dd3fc; --primary-400:#38bdf8; --primary-500:#0ea5e9;
  --primary-600:#0284c7; --primary-700:#0369a1; --primary-800:#075985;

  /* --- Grayscale --- */
  --secondary-50:#f8fafc; --secondary-100:#f1f5f9; --secondary-200:#e2e8f0;
  --secondary-300:#cbd5e1; --secondary-400:#94a3b8; --secondary-500:#64748b;
  --secondary-600:#475569; --secondary-700:#334155; --secondary-800:#1e293b;
  --secondary-900:#0f172a;

  /* --- States --- */
  --success-50: #f0fdf4; --success-100: #dcfce7;
  --success-400:#4ade80; --success-500:#22c55e; --success-600:#16a34a;
  
  --danger-50: #fef2f2; --danger-100: #fee2e2;
  --danger-400:#f87171; --danger-500:#ef4444; --danger-600:#dc2626;
  
  --warning-400:#facc15; --warning-500:#eab308;
  
  --purple-400:#c084fc; --purple-500:#8b5cf6; --purple-600:#7c3aed;
  --gradient-hero-text: linear-gradient(135deg, var(--primary-400), var(--purple-500));
  
  /* --- Social Colors --- */
  --facebook-blue: #1877F2;
  --whatsapp-green: #25D366;

  /* --- Gradients --- */
  --gradient-ocean: linear-gradient(135deg, #06b6d4 0%, #3b82f6 50%, #8b5cf6 100%);
  --gradient-success: linear-gradient(135deg, var(--success-400) 0%, var(--success-600) 100%);
  --gradient-sunset: linear-gradient(135deg, #f59e0b 0%, #ef4444 50%, #ec4899 100%);
  --gradient-primary: linear-gradient(135deg, var(--primary-400) 0%, var(--primary-600) 100%);
  --gradient-hero-text: linear-gradient(to right, var(--primary-600), var(--purple-600));

  /* --- Surfaces & Materials --- */
  --surface: linear-gradient(135deg, var(--secondary-50) 0%, var(--primary-50) 100%);
  --nav-bg: rgba(255, 255, 255, 0.8);
  --card-bg: rgba(255, 255, 255, 0.95);
  --glass-bg: rgba(255, 255, 255, 0.7);
  --border: rgba(15, 23, 42, .08);
  --text: var(--secondary-800);
  --text-muted: var(--secondary-500);
  --text-heading: var(--secondary-900);
  --progress-bg: var(--secondary-200);
  
  /* --- Geometry --- */
  --radius-xs:.375rem; --radius-sm:.5rem; --radius-md:.75rem;
  --radius-lg:1rem; --radius-xl:1.5rem; --radius-2xl:2rem; --radius-3xl:3rem;

  /* --- Shadows --- */
  --shadow-sm:0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md:0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg:0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl:0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --shadow-2xl:0 25px 50px -12px rgb(0 0 0 / 0.25);
  --shadow-glow: 0 0 20px 0 rgb(14 165 233 / 0.3);
  --shadow-glow-purple: 0 0 20px 0 rgb(139 92 246 / 0.3);

  /* --- Effects --- */
  --blur-sm: 8px;
  --blur-md: 12px;
  --blur-lg: 16px;
  --blur-xl: 24px;

  /* --- Animation Speeds --- */
  --transition-fast:.15s ease-out;
  --transition-normal:.2s ease-out;
  --transition-slow:.3s ease-out;
  --transition-bounce:.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* --- Dark Mode Variables --- */
html[data-theme="dark"] {
  --surface: linear-gradient(135deg, #0b1220 0%, #0f172a 100%);
  --nav-bg: rgba(255, 255, 255, 0.05);
  --card-bg: #1e293b; 
  --glass-bg: #1e293b; 
  --border: rgba(148, 163, 184, .15);
  --text: #cbd5e1;
  --text-muted: var(--secondary-400);
  --text-heading: #f1f5f9;
  --progress-bg: rgba(255, 255, 255, 0.1);
--gradient-hero-text: linear-gradient(135deg, var(--primary-300), var(--purple-400));
}

/* ==========================================================================
   2. BASE STYLES & BACKGROUNDS
   ========================================================================== */
body {
  font-family: 'Assistant', 'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--surface);
  color: var(--text);
  line-height: 1.6;
  font-size: 24px;
  margin: 0;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  transition: background 0.3s ease, color 0.3s ease;
}

/* --- Decorative Backgrounds --- */
.bg-ornaments {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(circle at 20% 50%, rgba(14,165,233,.08) 0%, transparent 60%),
    radial-gradient(circle at 80% 80%, rgba(139,92,246,.08) 0%, transparent 60%),
    radial-gradient(circle at 40% 20%, rgba(236,72,153,.05) 0%, transparent 60%),
    radial-gradient(rgba(203,213,225,.2) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 100% 100%, 20px 20px;
  animation: meshMove 25s ease-in-out infinite;
}

html[data-theme="dark"] .bg-ornaments {
  background-image:
    radial-gradient(circle at 20% 50%, rgba(14,165,233,.12) 0%, transparent 60%),
    radial-gradient(circle at 80% 80%, rgba(139,92,246,.12) 0%, transparent 60%),
    radial-gradient(circle at 40% 20%, rgba(236,72,153,.08) 0%, transparent 60%),
    radial-gradient(rgba(51, 65, 85, .3) 1px, transparent 1px);
}

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

/* ==========================================================================
   2.1. PARTICLES (Visuals - Fixed for Dark Mode)
   ========================================================================== */
#particles {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 0; pointer-events: none; overflow: hidden;
}
.particle {
    position: absolute; background: white; border-radius: 50%;
    opacity: 0.2; animation: floatParticle 15s linear infinite;
}
[data-theme="dark"] .particle {
    opacity: 0.8; 
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
}
@keyframes floatParticle {
    0% { transform: translateY(100vh) translateX(0) rotate(0deg); opacity: 0; }
    10% { opacity: var(--particle-opacity, 0.5); }
    90% { opacity: var(--particle-opacity, 0.5); }
    100% { transform: translateY(-20vh) translateX(50px) rotate(360deg); opacity: 0; }
}

/* --- Brain Pulse Effect (Fixed & Enhanced) --- */
.brain-pulse {
    animation: brainPulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
    display: inline-block;
    position: relative;
    z-index: 10;
    will-change: transform, filter; 
    transform-origin: center center;
}
@keyframes brainPulse {
    0% { 
        transform: scale(1); 
        filter: drop-shadow(0 0 2px rgba(139, 92, 246, 0.3)); 
    }
    50% { 
        transform: scale(1.25); 
        filter: drop-shadow(0 0 15px rgba(139, 92, 246, 0.8)); 
    }
    100% { 
        transform: scale(1); 
        filter: drop-shadow(0 0 2px rgba(139, 92, 246, 0.3)); 
    }
}

/* --- Pulse Badge Animation (For 'Free!' tag) --- */
.animate-pulse-fast {
    animation: pulseBadge 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes pulseBadge {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .8; transform: scale(1.1); }
}

/* --- Floating Elements --- */
.float-element { animation: float 6s ease-in-out infinite; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-15px); } }

/* --- Fade In Up Entrance --- */
.fade-in-up { animation: fadeInUp 0.8s ease-out forwards; opacity: 0; transform: translateY(20px); }
@keyframes fadeInUp { to { opacity: 1; transform: translateY(0); } }

@keyframes gradientShift { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@keyframes fadeOutUp { from {opacity:1; transform: translateY(0) scale(1);} to {opacity:0; transform: translateY(-20px) scale(.98);} }
@keyframes fadeInDown { from {opacity:0; transform: translateY(20px) scale(.98);} to {opacity:1; transform: translateY(0) scale(1);} }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)} }
@keyframes pulse { 0%, 100% { transform: scale(1.15); opacity: 1; } 50% { transform: scale(1.25); opacity: 0.9; } }
@keyframes popIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }


/* ==========================================================================
   3. LAYOUT & HEADER
   ========================================================================== */
.app-shell { max-width: 1280px; margin: 0 auto; }

/* --- Landing Page Nav --- */
.landing-nav {
    position: relative; z-index: 20;
    background: var(--nav-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    transition: all var(--transition-normal);
}

/* --- App Header (Logged In) --- */
.app-header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.75rem 1rem;
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  transition: all var(--transition-normal);
}
.app-header::after {
  content: ''; position: absolute; bottom: -1px; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--primary-500), transparent);
  opacity: 0; transition: opacity var(--transition-normal);
}
.app-header:hover::after { opacity: 1; }

.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; color: var(--text-heading); font-size: 1.25rem; }
.brand__icon { font-size: 1.4rem; }
.brand__name { font-size: 1.125rem; }
.brand__dot { width: 6px; height: 6px; border-radius: 999px; background: var(--primary-500); display: inline-block; margin-inline: .25rem; }
.brand__section { color: var(--text-muted); font-weight: 600; margin-right: 0.5rem; }

.app-header__right { display: flex; align-items: center; gap: .75rem; }

/* Score Pill */
.score-pill {
  display: flex; align-items: center; gap: .375rem; padding: .4rem .75rem;
  background: linear-gradient(135deg, var(--secondary-50), #fff);
  border: 1px solid var(--border); border-radius: 999px; box-shadow: var(--shadow-sm);
  color: var(--text); transition: all var(--transition-normal);
}
.score-pill:hover { transform: scale(1.05); box-shadow: var(--shadow-lg); }
html[data-theme="dark"] .score-pill { background: rgba(255,255,255,.06); color: var(--text); }
.score-pill .text-slate-600 { color: var(--text-muted) !important; }
.score-pill .text-emerald-600 { color: var(--success-600) !important; }
html[data-theme="dark"] .score-pill .text-emerald-600 { color: var(--success-400) !important; }

/* User Box */
.user-box { display:flex; align-items:center; gap:.5rem; }
.user-box .font-bold { color: var(--text-heading); }
.logout-link { font-size: .85rem; color: var(--danger-500); margin-inline-start:.35rem; }
.logout-link:hover { text-decoration: underline; }

/* Toolbar */
.toolbar {
  display:flex; align-items:center; justify-content:space-between;
  gap:1rem; margin: 1rem auto 1.25rem; padding:.75rem;
  background: var(--card-bg); border:1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-md);
}
.toolbar__left, .toolbar__right { display:flex; gap:.5rem; align-items:center; flex-wrap: wrap; }

/* --- Dashboard Container --- */
.dashboard-container {
    display: flex; flex-direction: column; gap: 2rem;
    max-width: 1280px; margin: 1rem auto; padding: 0 1rem;
    position: relative; z-index: 2;
}

/* --- THE 4-COLUMN GRID FIX (Responsive) --- */
/* Changed to 4 columns max as requested */
.stats-grid-4 { 
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(1, 1fr); /* Mobile default */
}

@media (min-width: 640px) {
    .stats-grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
    .stats-grid-4 { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1280px) {
    .stats-grid-4 { grid-template-columns: repeat(4, 1fr); } /* Strictly 4 items per row on large screens */
}

/* Ensure Games Grid also uses appropriate layout (auto-fit is flexible) */
.dashboard-grid, .stats-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.dashboard-grid .dashboard-section { padding: 1.5rem; }

/* ==========================================================================
   4. UI COMPONENTS (Buttons, Cards, Forms)
   ========================================================================== */

/* --- Buttons --- */
.btn {
  border: none; cursor: pointer; font-weight: 800; padding: .75rem 1.25rem;
  border-radius: var(--radius-lg); transition: transform var(--transition-fast), box-shadow var(--transition-fast), filter var(--transition-fast);
  box-shadow: var(--shadow-md); display: inline-flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden; color: var(--text);
  text-decoration: none;
}
.btn::before {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 0; height: 0; border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  transform: translate(-50%, -50%); transition: width 0.5s, height 0.5s;
}
.btn:hover::before { width: 280px; height: 280px; }
.btn:hover { transform: translateY(-2px); filter: brightness(1.05); box-shadow: var(--shadow-xl); }
.btn:active { transform: translateY(0); }
.btn-sm { padding:.5rem .75rem; font-weight:700; border-radius: .75rem; }

.btn-primary { color: #fff; background: linear-gradient(135deg, var(--primary-500), var(--purple-500)); background-size: 200% 200%; animation: gradientShift 3s ease infinite; }
.btn-secondary { color: #fff; background: linear-gradient(135deg, #10b981, #0ea5e9); }
.btn-success { color: #fff; background: linear-gradient(135deg, var(--success-400), var(--success-500)); }
.btn-danger { color: #fff; background: linear-gradient(135deg, #fb7185, #ef4444); }
.btn-outline { background: transparent; border: 2px solid var(--border); color: var(--text-heading); }
.btn-outline:hover { background: var(--secondary-100); border-color: var(--secondary-400); }
html[data-theme="dark"] .btn-outline:hover { background: var(--secondary-800); border-color: var(--secondary-500); }
.btn-ghost { background: transparent; color: var(--text-muted); box-shadow: none; }
.btn-ghost:hover { background: var(--secondary-100); color: var(--text-heading); box-shadow: none; }
html[data-theme="dark"] .btn-ghost:hover { background: var(--secondary-800); }

/* Social Buttons */
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 0.75rem;
  width: 100%; padding: 0.75rem 1rem; border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text-heading); font-weight: 800;
  cursor: pointer; transition: all var(--transition-normal); box-shadow: var(--shadow-sm);
  background: linear-gradient(135deg, #db4437, #ef4444);
  color: #fff;
}
.btn-google:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); border-color: var(--secondary-400);

  background: linear-gradient(135deg, #ed5c4f, #ef4444);}
html[data-theme="dark"] .btn-google { background: var(--secondary-700); border-color: var(--secondary-600); }
html[data-theme="dark"] .btn-google:hover { background: var(--secondary-600); border-color: var(--secondary-400);

}

.btn-facebook {
  display: flex; align-items: center; justify-content: center; gap: 0.75rem;
  width: 100%; padding: 0.75rem 1rem; border: 1px solid transparent; border-radius: var(--radius-lg);
  background: var(--facebook-blue); color: white; font-weight: 800; cursor: pointer;
  transition: all var(--transition-normal); box-shadow: var(--shadow-sm);
}
.btn-facebook:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); filter: brightness(1.1); }

.btn-whatsapp {
    background-color: var(--whatsapp-green); color: white;
    padding: 0.75rem 1.5rem; border-radius: 999px; font-weight: bold;
    text-decoration: none; display: flex; align-items: center; gap: 0.5rem;
    margin-top: 1rem; width: 100%; justify-content: center;
}
.btn-whatsapp:hover { background-color: #1ebc57; transform: translateY(-2px); }

.personalized-btn {
    width: 100%; height: 100%; flex-grow: 1; padding: 1.5rem; border-radius: var(--radius-xl);
    background: linear-gradient(135deg, var(--primary-500) 0%, var(--purple-500) 50%, var(--purple-600) 100%);
    color: white; text-align: right; display: flex; flex-direction: column;
    align-items: flex-start; justify-content: center; transition: all var(--transition-slow);
    box-shadow: 0 8px 25px -5px rgba(139, 92, 246, 0.4); border: none; cursor: pointer;
    position: relative; overflow: hidden;
}
.personalized-btn::before {
    content: ''; position: absolute; top: 0; left: -100%; width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.6s ease-out;
}
.personalized-btn:hover { transform: translateY(-4px); box-shadow: 0 12px 40px -10px rgba(139, 92, 246, 0.6); }
.personalized-btn:hover::before { left: 100%; }
.personalized-btn .text-sm { color: rgba(255, 255, 255, 0.8); }

/* --- Hero Typography --- */
.hero-title {
    background: var(--gradient-hero-text);
    /* Essential: This makes the background only exist behind the letters */
    -webkit-background-clip: text;
    background-clip: text;
    
    /* Change this to transparent so the background shows through */
    -webkit-text-fill-color: transparent; 
    
    /* Fallback for older browsers */
    color: var(--primary-500); 
}
html[data-theme="dark"] .hero-title {
    /* Stronger glow for the "Dark Bold" aesthetic */
    filter: drop-shadow(0 0 15px rgba(139, 92, 246, 0.3));
    color: var(--primary-200);
       -webkit-text-fill-color: rgb(204, 244, 255); 
}

.hero-subtitle { color: var(--text-muted); }

/* --- Sections & Cards --- */
.dashboard-section {
  padding: 2rem; background: var(--card-bg); backdrop-filter: blur(24px);
  border-radius: var(--radius-2xl); box-shadow: var(--shadow-lg); border: 1px solid var(--border);
  transition: all var(--transition-normal); position: relative; overflow: hidden;
  display: flex; flex-direction: column;
}
.dashboard-section:hover {
  transform: translateY(-3px); box-shadow: var(--shadow-2xl); border-color: var(--primary-400);
}
.dashboard-section::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--gradient-ocean); transform: scaleX(0); transition: transform var(--transition-slow);
  transform-origin: left;
}
.dashboard-section:hover::before { transform: scaleX(1); }

.dashboard-title {
  font-size: 1.75rem; font-weight: 700; color: var(--text-heading);
  margin-bottom: 1.5rem; padding-bottom: 0.75rem; position: relative;
  border-bottom: 2px solid var(--border);
}
.dashboard-title::after {
  content: ''; position: absolute; bottom: -2px; right: 0; width: 60px; height: 2px;
  background: linear-gradient(90deg, var(--primary-500), var(--purple-500)); border-radius: 1px;
}

/* Feature Cards (Landing) */
.feature-card {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: var(--radius-xl); padding: 2rem;
    text-align: center; transition: all var(--transition-normal);
}
.feature-card:hover { border-color: var(--primary-400); box-shadow: var(--shadow-lg); transform: translateY(-5px); }
.feature-card h3 { color: var(--text-heading); font-size: 1.5rem; margin-bottom: 1rem; font-weight: 700; }
.feature-card p { color: var(--text); }

/* --- Stat Cards (Fixed Layout + Design) --- */
.stat-card {
    background: var(--surface); padding: 1.5rem; border-radius: var(--radius-xl); border: 1px solid var(--border);
    transition: all var(--transition-normal); position: relative; overflow: hidden;
    text-align: center; cursor: pointer; display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 140px;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--primary-200); }
.stat-card::before {
  content: ''; position: absolute; top: -2px; left: -2px; right: -2px; bottom: -2px;
  background: var(--gradient-ocean); border-radius: var(--radius-xl); opacity: 0; z-index: -1;
  transition: opacity var(--transition-normal);
}
.stat-card:hover::before { opacity: 1; }
.stat-card-title { font-weight: 700; margin-bottom: 0.5rem; color: var(--text-heading); }
.stat-card h4 { font-weight: 800; margin-bottom: 0.5rem; color: var(--text-heading); }
.stat-card .text-2xl { color: var(--text); }
.stat-card .w-full { background-color: var(--progress-bg); }

/* Stat Colors Helpers */
.text-primary-500 { color: var(--primary-500); }
.text-success-500 { color: var(--success-500); }
.text-purple-500 { color: var(--purple-500); }
.text-blue-500 { color: var(--facebook-blue); }
.text-warning-400 { color: var(--warning-400); }

/* Game Cards */
.game-preview-card {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    height: 100px;
    border-radius: 1rem;
    cursor: pointer;
    background: var(--card-bg);
    border: 1px solid var(--border);
    transition: all var(--transition-normal);
}
.game-preview-card:hover {
    transform: scale(1.05);
    border-color: var(--primary-400);
    box-shadow: var(--shadow-lg);
}

/* Overview Cards */
.overview-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 1.5rem; margin-bottom: 0.5rem; }
@media (max-width: 768px) { .overview-grid { grid-template-columns: 1fr; } }
.overview-card {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-xl);
    padding: 1.5rem; box-shadow: var(--shadow-lg); transition: transform 0.2s;
    min-height: 200px; display: flex; flex-direction: column; justify-content: center;
}
.overview-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-xl); }
.article-card {
    background: linear-gradient(135deg, var(--secondary-50), #fff);
    border-right: 4px solid var(--primary-500);
    justify-content: flex-start;
}
html[data-theme="dark"] .article-card { background: linear-gradient(135deg, var(--secondary-800), var(--secondary-900)); }

/* --- Forms & Inputs --- */
.form-group { display: grid; gap:.4rem; }
.form-label { font-weight:700; color: var(--secondary-700); }
html[data-theme="dark"] .form-label { color: #e2e8f0; }
.form-input {
  width:100%; padding:.8rem 1rem; border-radius: .9rem; border:1px solid var(--border);
  background: var(--surface);
  color: var(--text); outline: none; box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}
.form-input::placeholder { color: var(--secondary-400); }
html[data-theme="dark"] .form-input::placeholder { color: var(--secondary-500); }
.form-input:focus { border-color: var(--primary-500); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2); }

.register-radio-group label {
  display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-size: 1rem; font-weight: 600;
  color: var(--text-heading); padding: 0.75rem 1rem; border: 2px solid var(--border);
  border-radius: var(--radius-lg); width: 100%; transition: all 0.2s ease;
}
.register-radio-group label:has(input:checked) { border-color: var(--primary-500); background-color: var(--primary-50); }
html[data-theme="dark"] .register-radio-group label:has(input:checked) { background-color: rgba(14, 165, 233, 0.1); border-color: var(--primary-600); }

/* --- Chips --- */
.chip {
  padding: .35rem .7rem; border-radius: 999px;
  background: linear-gradient(135deg, var(--secondary-100), #fff);
  border: 1px solid var(--border); font-weight:700; font-size:.85rem; color: var(--text);
}
html[data-theme="dark"] .chip { background: rgba(255,255,255,.06); color: var(--text); }
.chip-primary {
  background: linear-gradient(135deg, var(--primary-100), var(--primary-50));
  border-color: rgba(14,165,233,.35); color: var(--primary-700);
}
html[data-theme="dark"] .chip-primary { background: rgba(14, 165, 233, 0.2); border-color: rgba(14, 165, 233, 0.4); color: var(--primary-200); }
.brand-chip {
  width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary-500), var(--purple-500)); color: #fff;
  box-shadow: 0 10px 25px rgba(99,102,241,.35);
}

/* --- Toggle Switch --- */
.theme-toggle { position: relative; display:inline-flex; align-items:center; cursor:pointer; }
.theme-toggle input { display:none; }
.toggle-track {
  width: 52px; height: 30px; border-radius: 999px; position: relative;
  background: var(--secondary-200); border: 1px solid var(--border);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.1); transition: background-color .2s ease;
}
.theme-toggle input:checked + .toggle-track { background-color: var(--primary-600); }
.toggle-track::after {
  content: ""; position: absolute; top: 2px; right: 2px; width: 24px; height: 24px;
  background: white; border-radius: 999px; box-shadow: var(--shadow-sm);
  transition: transform .25s ease;
}
.theme-toggle input:checked + .toggle-track::after { transform: translateX(-22px); }
html[data-theme="dark"] .toggle-track { background: var(--secondary-800); }

/* --- Reset Button --- */
.reset-btn {
    padding: 0.5rem 1rem; border-radius: var(--radius-md); border: 1px solid var(--danger-400);
    color: var(--danger-500); background-color: var(--danger-50); font-weight: 600;
    transition: all var(--transition-normal);
}
.reset-btn:hover { background-color: var(--danger-100); border-color: var(--danger-500); }
html[data-theme="dark"] .reset-btn { background-color: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.3); color: var(--danger-400); }
html[data-theme="dark"] .reset-btn:hover { background-color: rgba(239, 68, 68, 0.2); border-color: rgba(239, 68, 68, 0.4); }

/* ==========================================================================
   5. MODALS & AUTH SCREEN
   ========================================================================== */

/* --- Modals --- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 99999; padding: 1rem;
}
.modal-content {
  background: var(--card-bg); padding: 2rem; border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl); text-align: center; max-width: 520px; width: 100%;
  animation: fadeInDown .3s cubic-bezier(0,0,.2,1); border: 1px solid var(--border);
}
.modal-content h2, .modal-content h3 { color: var(--text-heading); }
.modal-content p { color: var(--text-muted); }
.modal-btn { padding: .8rem 1.5rem; border-radius: var(--radius-lg); font-weight: 800; color:white; border: none; cursor:pointer; transition: all var(--transition-normal); }
.modal-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }

/* --- Auth Screen Specifics --- */
.card-auth {
  position: relative; z-index: 1; padding: 2.25rem;
  background: var(--card-bg); backdrop-filter: blur(14px);
  border-radius: var(--radius-2xl); box-shadow: var(--shadow-xl); border: 1px solid var(--border);
  transition: all var(--transition-normal);
}
#auth-screen > * { position: relative; z-index: 2; }
.auth-card h2 { color: var(--text-heading); }
.auth-card p { color: var(--text-muted); }
.auth-card #auth-error { color: var(--danger-500); }

/* ==========================================================================
   6. GAMIFICATION & FEATURES
   ========================================================================== */

/* --- Daily Quest --- */
.daily-quest-section {
    background: linear-gradient(135deg, var(--primary-50), var(--secondary-50));
    border-color: var(--primary-300); order: -1;
}
html[data-theme="dark"] .daily-quest-section {
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.1), rgba(30, 41, 59, 0.5));
    border-color: var(--primary-700);
}
.daily-quest-section.completed {
    background: linear-gradient(135deg, var(--success-50), var(--secondary-50)); border-color: var(--success-400);
}
html[data-theme="dark"] .daily-quest-section.completed {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), rgba(30, 41, 59, 0.5)); border-color: var(--success-600);
}

/* Quest Header Fixes */
.quest-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; }
.quest-header .dashboard-title {
    margin-bottom: 0.5rem;
    border-bottom: none;
    color: var(--text-heading) !important;
    background: none !important;
    -webkit-text-fill-color: initial !important;
}
.quest-header .dashboard-title::after { background: linear-gradient(90deg, var(--warning-400), var(--warning-500)); }

.quest-completed-badge {
    background-color: var(--success-500); color: white; padding: 0.25rem 0.75rem;
    border-radius: 999px; font-weight: bold; font-size: 0.8rem; animation: popIn 0.5s ease-out;
}
.quest-description { font-size: 1.1rem; font-weight: 500; color: var(--text); margin: 0.5rem 0 1rem 0; }
.quest-progress-bar { width: 100%; height: 12px; background-color: var(--progress-bg); border-radius: 999px; overflow: hidden; margin-bottom: 0.25rem; }
.quest-progress-bar .progress-fill { height: 100%; background: linear-gradient(90deg, var(--warning-400), var(--warning-500)); border-radius: 999px; transition: width 0.5s ease-out; }
.daily-quest-section.completed .progress-fill { background: linear-gradient(90deg, var(--success-400), var(--success-500)); }
.quest-progress-text { text-align: left; font-size: 0.8rem; font-weight: bold; color: var(--text-muted); }

/* Dark Mode Fixes for Quest Text */
html[data-theme="dark"] .daily-quest-section h2,
html[data-theme="dark"] .daily-quest-section h3,
html[data-theme="dark"] .daily-quest-section h4 { color: var(--purple-400) !important; }
html[data-theme="dark"] .daily-quest-section p,
html[data-theme="dark"] .daily-quest-section li,
html[data-theme="dark"] .daily-quest-section span { color: var(--primary-100); }

/* --- Level Path --- */
.levels-container {
    display: flex; align-items: center; justify-content: flex-start; gap: 1rem; flex-wrap: wrap;
    padding: 1rem; background: var(--surface); border-radius: var(--radius-xl); border: 1px solid var(--border);
}
.level-node {
    width: 66px; height: 66px; border-radius: 50%; border: 3px solid var(--border);
    display: flex; align-items: center; justify-content: center; font-size: 1.25rem; font-weight: 700;
    color: var(--text-muted); background: var(--surface); transition: all var(--transition-normal);
    position: relative;
}
.level-connector { flex-grow: 1; max-width: 40px; height: 4px; background: var(--border); border-radius: 2px; }

/* Level States */
.level-node.completed {
    border-color: var(--success-500); background: linear-gradient(135deg, var(--success-400), var(--success-600)); color: white;
    cursor: pointer; box-shadow: 0 4px 15px rgba(34, 197, 94, 0.3);
}
.level-node.completed:hover { transform: scale(1.1); box-shadow: 0 8px 25px rgba(34, 197, 94, 0.4); }

.level-node.completed-partial {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%); color: white;
    border-color: #f59e0b; box-shadow: 0 0 15px rgba(245, 158, 11, 0.4); cursor: pointer;
    transition: all 0.3s ease;
}
.level-node.completed-partial:hover { transform: translateY(-2px); box-shadow: 0 0 25px rgba(245, 158, 11, 0.6); }

.level-node.unlocked { border-width: 3px; cursor: pointer; }
.level-node.unlocked:hover { transform: scale(1.1); box-shadow: 0 0 20px rgba(14, 165, 233, 0.4); }

.level-node.locked { background: transparent; color: var(--text-muted); cursor: not-allowed; opacity: 0.6; }
.unlocked-sky { border-color: var(--primary-500); color: var(--primary-600); box-shadow: 0 4px 15px rgba(14, 165, 233, 0.2); }
html[data-theme="dark"] .unlocked-sky { color: var(--primary-300); }

/* Current Level Pulse */
@keyframes pulse-attention {
  0% { box-shadow: 0 0 0 0 rgba(14, 165, 233, 0.7); transform: scale(1); }
  50% { box-shadow: 0 0 0 10px rgba(14, 165, 233, 0); transform: scale(1.1); }
  100% { box-shadow: 0 0 0 0 rgba(14, 165, 233, 0); transform: scale(1); }
}
.level-node.current-level-pulse {
  border-color: var(--primary-500); background-color: var(--surface); color: var(--primary-600);
  animation: pulse-attention 2s infinite; z-index: 2;
}
.level-node.current-level-pulse::after {
  content: 'Start'; position: absolute; top: -20px; left: 50%; transform: translateX(-50%);
  background: var(--primary-600); color: white; font-size: 0.7rem; padding: 2px 6px;
  border-radius: 4px; white-space: nowrap; opacity: 0.9; pointer-events: none;
}

/* Star Tooltip */
.level-tooltip {
    position: absolute; background-color: var(--secondary-800); color: white;
    padding: 0.5rem 1rem; border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    z-index: 10; opacity: 0; transform: translateY(10px); transition: all var(--transition-normal);
    pointer-events: none;
}
html[data-theme="dark"] .level-tooltip { background-color: var(--secondary-100); color: var(--secondary-900); border: 1px solid var(--border); }
.level-tooltip.visible { opacity: 1; transform: translateY(0); }
.star-rating { display: flex; gap: 0.25rem; }
.star { font-size: 1.25rem; color: var(--secondary-600); }
.star.filled { color: var(--warning-400); }

/* --- AI Coach --- */
.ai-coach-container { position: fixed; bottom: 20px; right: 20px; z-index: 99; }
.ai-coach-bubble {
    position: absolute; bottom: 75px; right: 0; max-width: 280px; padding: 0.75rem 1.25rem;
    background: var(--card-bg); border: 1px solid var(--border); color: var(--text);
    border-radius: var(--radius-xl); border-bottom-right-radius: var(--radius-xs);
    box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(10px) scale(0.95);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out; pointer-events: none; z-index: 98; font-weight: 600;
}
.ai-coach-bubble.show { opacity: 1; transform: translateY(0) scale(1); }
.ai-coach-toggle {
    width: 60px; height: 60px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-500), var(--purple-500));
    color: white; border: 3px solid white;
    box-shadow: var(--shadow-xl); font-size: 2rem; cursor: pointer;
    display: flex; justify-content: center; align-items: center; transition: all var(--transition-slow);
}
.ai-coach-toggle:hover { transform: scale(1.1); }
.ai-coach-toggle.open { opacity: 0; transform: scale(0.5); }
.ai-coach-window {
    position: absolute; bottom: 0; right: 0; width: 350px; max-height: 500px;
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl); display: flex; flex-direction: column; opacity: 0;
    transform: translateY(20px); transition: all var(--transition-slow); pointer-events: none;
}
.ai-coach-window.open { opacity: 1; transform: translateY(0); pointer-events: all; }
.ai-coach-header {
    padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); font-weight: bold;
    display: flex; justify-content: space-between; align-items: center; color: var(--text-heading);
}
.ai-coach-header #ai-coach-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); }
.ai-coach-messages { flex-grow: 1; padding: 1rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.75rem; }
.ai-coach-message { padding: 0.5rem 1rem; border-radius: var(--radius-lg); max-width: 85%; display: flex; gap: 0.5rem; align-items: flex-end; }
.ai-coach-message.user { background: var(--primary-500); color: white; align-self: flex-end; border-bottom-right-radius: var(--radius-xs); }
.ai-coach-message.bot { background: var(--surface); color: var(--text); align-self: flex-start; border-bottom-left-radius: var(--radius-xs); border: 1px solid var(--border); }
.ai-coach-message.system { align-self: center; background: transparent; color: var(--text-muted); font-style: italic; font-size: 0.8rem; padding: 0.2rem; }
.ai-coach-input-area { display: flex; padding: 0.75rem; border-top: 1px solid var(--border); gap: 0.5rem; }
#ai-coach-input-field { flex-grow: 1; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0.6rem 1rem; background: var(--surface); color: var(--text); outline: none; }
#ai-coach-send { border: none; background: var(--primary-500); color: white; border-radius: var(--radius-lg); padding: 0 1rem; cursor: pointer; display: grid; place-items: center; }
.ai-coach-options { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.ai-coach-options button {
    padding: 0.5rem 0.75rem; font-size: 0.8rem; border: 1px solid var(--primary-300);
    color: var(--primary-600); background: transparent; border-radius: 999px;
    cursor: pointer; transition: all 0.2s;
}
.ai-coach-options button:hover { background: var(--primary-100); }
.ai-coach-options button.disabled { opacity: 0.5; cursor: not-allowed; background: var(--secondary-200); }
html[data-theme="dark"] .ai-coach-options button { border-color: var(--primary-500); color: var(--primary-200); }
html[data-theme="dark"] .ai-coach-options button:hover { background: rgba(14, 165, 233, 0.2); }
html[data-theme="dark"] .ai-coach-options button.disabled { background: var(--secondary-700); }

/* --- AI Coach Notification Badge (FIX: Single Pseudo Element) --- */
.ai-coach-toggle { position: relative; }
/* Use a pseudo element on the toggle itself so it doesn't duplicate */
.ai-coach-toggle.has-notification::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background-color: var(--danger-500);
    border-radius: 50%;
    border: 2px solid white; /* Contrast border */
    animation: pulseBadge 1s infinite;
    pointer-events: none;
}
/* Remove any inline badge elements if they exist in HTML to prevent duplication */

/* --- Achievements --- */
.achievement-toast {
    position: fixed; bottom: 20px; left: 20px; z-index: 100;
    background: var(--card-bg); color: var(--text); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 1rem 1.5rem; display: flex; align-items: center; gap: 1rem;
    box-shadow: var(--shadow-xl); transform: translateY(200%); transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.achievement-toast.show { transform: translateY(0); }
.achievement-toast__icon { font-size: 2.5rem; }
.achievement-toast__title { font-weight: 800; color: var(--text-heading); }
.achievement-toast__name { font-weight: 600; }

.achievements-container .achievement-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl);
    padding: 1.5rem; display: flex; align-items: center; gap: 1.5rem; opacity: 0.5;
    transition: all var(--transition-normal); position: relative;
}
.achievements-container .achievement-card.unlocked { opacity: 1; border-left: 5px solid var(--success-500); }
.achievement-card .achievement-icon {
    font-size: 3rem; background: var(--card-bg); width: 80px; height: 80px;
    display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--border);
}
.achievement-card .achievement-name { font-weight: 700; color: var(--text-heading); font-size: 1.1rem; }
.achievement-card .achievement-desc { color: var(--text-muted); font-size: 0.9rem; }
.achievement-unlocked-badge {
    position: absolute; top: 1rem; right: 1rem; background: var(--success-500);
    color: white; font-size: 0.75rem; font-weight: bold; padding: 0.2rem 0.5rem; border-radius: 999px;
}
html[data-theme="dark"] .bg-indigo-50 { background-color: rgba(129, 140, 248, 0.1) !important; }
html[data-theme="dark"] .border-indigo-200 { border-color: rgba(165, 180, 252, 0.2) !important; }
html[data-theme="dark"] .text-indigo-800 { color: #a5b4fc !important; }

.game-recommendation-btn {
    flex: 1; padding: 0.75rem; border-radius: var(--radius-md); background-color: white;
    border: 1px solid var(--border); cursor: pointer; transition: all var(--transition-normal); text-align: center;
}
.game-recommendation-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--primary-300); }
html[data-theme="dark"] .game-recommendation-btn { background-color: var(--secondary-700); }
html[data-theme="dark"] .game-recommendation-btn .font-bold { color: var(--text-heading); }
html[data-theme="dark"] .game-recommendation-btn .text-xs { color: var(--text-muted); }

/* --- Freemium Locked State --- */
.locked-feature {
  position: relative; opacity: 0.6; cursor: not-allowed;
  filter: grayscale(80%); transition: all 0.3s ease;
}
.locked-feature:hover { filter: grayscale(50%); opacity: 0.8; }
.locked-feature::after {
  content: '🔒'; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%); font-size: 2.5rem;
  color: white; text-shadow: 0 0 10px rgba(0,0,0,0.7); z-index: 10; opacity: 0.8;
}
.locked-level {
  background: var(--secondary-200) !important; color: var(--secondary-500) !important;
  border-color: var(--secondary-300) !important; box-shadow: none !important; cursor: not-allowed; filter: grayscale(100%);
}
html[data-theme="dark"] .locked-level {
  background: var(--secondary-800) !important; color: var(--secondary-600) !important;
  border-color: var(--secondary-700) !important;
}

/* ==========================================================================
   7. GAME SPECIFIC STYLES
   ========================================================================== */

/* --- General Game Board --- */
.game-board {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem;
    perspective: 1000px; padding: 1rem; background: var(--surface); border-radius: var(--radius-xl);
    border: 1px solid var(--border); max-width: 500px; margin: 0 auto;
}
.game-board.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.6rem; max-width: 600px; }
.game-board.cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.5rem; max-width: 700px; }

/* Game Containers */
.perception-game-area, .quantitative-game-area, .trail-making-area, .vnm-display-area, .track-switcher-area, .oi-game-area, .ss-game-area, .tt-game-container {
    position: relative; width: 100%; background: var(--surface); border-radius: var(--radius-xl);
    border: 2px solid var(--border); transition: all var(--transition-normal); overflow: hidden;
}

/* --- Synapse Sprinter Tutorial (Custom Theme) --- */
#synapse-sprinter-tutorial, .ss-tutorial-modal {
    background-color: var(--secondary-900); /* Force Dark BG in Light Mode */
    color: #ffffff !important; /* Force White Text */
    border: 1px solid var(--border);
    border-radius: var(--radius-2xl);
    padding: 2rem;
}
#synapse-sprinter-tutorial h2, #synapse-sprinter-tutorial p, #synapse-sprinter-tutorial li,
.ss-tutorial-modal h2, .ss-tutorial-modal p, .ss-tutorial-modal li {
    color: #ffffff !important;
}

/* Revert to standard theme colors in Dark Mode */
html[data-theme="dark"] #synapse-sprinter-tutorial,
html[data-theme="dark"] .ss-tutorial-modal {
    background-color: var(--card-bg);
    color: var(--text) !important;
}
html[data-theme="dark"] #synapse-sprinter-tutorial h2,
html[data-theme="dark"] .ss-tutorial-modal h2 {
    color: var(--text-heading) !important;
}
html[data-theme="dark"] #synapse-sprinter-tutorial p,
html[data-theme="dark"] .ss-tutorial-modal p {
    color: var(--text-muted) !important;
}

/* --- Memory Game --- */
.memory-card {
    width: 100%; aspect-ratio: 1 / 1; position: relative; transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275); cursor: pointer;
}
.memory-card.flip { transform: rotateY(180deg); }
.front-face, .back-face {
    position: absolute; width: 100%; height: 100%; backface-visibility: hidden;
    border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
    display: flex; justify-content: center; align-items: center; transition: all var(--transition-normal);
}
.front-face {
    background: linear-gradient(135deg, var(--primary-600), var(--primary-700));
    font-size: 2.5rem; color: white;
}
.back-face {
    background: var(--surface); transform: rotateY(180deg); border: 2px solid var(--border);
}
.back-face img { width: 85%; height: 85%; object-fit: contain; border-radius: var(--radius-md); }

/* --- Perception Game --- */
.perception-game-area { height: 400px; }
html[data-theme="light"] .perception-game-area { background-image: radial-gradient(var(--secondary-200) 1px, transparent 1px); background-size: 15px 15px; }
.shape { position: absolute; cursor: pointer; transition: all var(--transition-normal); box-shadow: var(--shadow-md); }
.shape-pop-in { animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }
.shape:hover { transform: scale(1.15); filter: brightness(1.1); box-shadow: var(--shadow-lg); }

/* --- Quantitative Game --- */
.quantitative-game-area { height: 300px; display: flex; justify-content: center; align-items: center; }
.quantitative-item {
    transition: all var(--transition-normal); cursor: pointer; width: 24px; height: 24px;
    background: linear-gradient(135deg, var(--danger-400), var(--danger-500));
    border-radius: 50%; position: absolute; box-shadow: var(--shadow-sm); animation: popIn 0.3s ease-out;
}

/* --- Trail Making Game --- */
.trail-making-area { height: 450px; cursor: pointer; }
.trail-making-area:hover, .perception-game-area:hover, .quantitative-game-area:hover {
    border-color: var(--primary-300); box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.1);
}
#trail-svg line { stroke: var(--primary-500); stroke-width: 4; stroke-linecap: round; opacity: 0.8; }
.trail-node {
    width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; font-weight: 700; color: var(--text-heading); user-select: none;
    transition: all var(--transition-normal); background: var(--surface); border: 3px solid var(--border);
    position: absolute;
}
.trail-node.next {
    border-color: var(--primary-500); color: var(--primary-600);
    box-shadow: 0 0 25px 8px rgba(6, 182, 212, 0.3); transform: scale(1.15);
    animation: pulse 1.5s infinite;
}
html[data-theme="dark"] .trail-node.next { color: var(--primary-300); }
.trail-node.correct {
    background: linear-gradient(135deg, var(--success-400), var(--success-500));
    border-color: var(--success-600); color: white; transform: scale(1);
}
.trail-node.error {
    animation: shake 0.5s; background: linear-gradient(135deg, var(--danger-400), var(--danger-500));
    border-color: var(--danger-600); color: white;
}
.trail-node.distractor {
    background: var(--secondary-200); border-color: var(--secondary-400); color: var(--secondary-500); opacity: 0.7;
}
html[data-theme="dark"] .trail-node.distractor { background: var(--secondary-700); border-color: var(--secondary-600); color: var(--secondary-400); }

/* --- Track Switcher --- */
.track-switcher-area {
    width: 100%; max-width: 800px; height: 400px; border-radius: 16px; margin: 0 auto;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15); overflow: hidden; position: relative;
}
html[data-theme="light"] .track-switcher-area { background: linear-gradient(135deg, #e8f5e8 0%, #d4f1d4 100%); border: 3px solid #22c55e; }
html[data-theme="dark"] .track-switcher-area { background: linear-gradient(135deg, #1e3a2a 0%, #162a22 100%); border: 3px solid var(--success-700); }
.ts-svg-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
.ts-svg-layer line { stroke: #374151; stroke-width: 4; stroke-linecap: round; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2)); }
html[data-theme="dark"] .ts-svg-layer line { stroke: var(--secondary-400); }
.station {
    position: absolute; width: 40px; height: 40px; border-radius: 50%; transform: translate(-50%, -50%);
    border: 4px solid white; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); z-index: 3; animation: pulse 2s infinite;
}
.station::before { content: '🏁'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 20px; }
.switch {
    position: absolute; width: 30px; height: 30px;
    background: linear-gradient(145deg, var(--warning-400), var(--warning-500));
    border-radius: 50%; transform: translate(-50%, -50%); cursor: pointer;
    border: 3px solid #92400e; z-index: 4; transition: all 0.2s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
.switch:hover { transform: translate(-50%, -50%) scale(1.2); box-shadow: 0 6px 15px rgba(245, 158, 11, 0.4); }
.switch::after { content: ''; position: absolute; top: 50%; left: 50%; font-size: 16px; transform: translate(-50%, -50%); }
.switch.up::after { content: '⬆'; }
.switch.down::after { content: '⬇'; }
.train {
    position: absolute; width: 25px; height: 25px; border-radius: 6px; transform: translate(-50%, -50%);
    border: 2px solid white; z-index: 2; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}
.train::before { content: '🚂'; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 16px; }
.collision-effect { animation: collision 0.5s ease-out; }
@keyframes collision {
    0% { transform: translate(-50%, -50%) scale(1); }
    25% { transform: translate(-50%, -50%) scale(1.3) rotate(10deg); }
    50% { transform: translate(-50%, -50%) scale(1.1) rotate(-10deg); }
    75% { transform: translate(-50%, -50%) scale(1.2) rotate(5deg); }
    100% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
}
.success-effect { animation: success 0.8s ease-out; }
@keyframes success {
    0% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.4); opacity: 0.8; }
    100% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
}

/* --- Object Identification Game --- */
.oi-header {
    width: 100%; padding: 1rem; background: var(--card-bg); backdrop-filter: blur(10px);
    border-radius: 1rem; margin-bottom: 1.5rem; border: 1px solid var(--border); box-shadow: var(--shadow-lg); text-align: center;
}
.oi-header h3 { margin: 0 0 1rem 0; color: var(--text-heading); }
.oi-header .flex { display: flex; justify-content: center; align-items: center; gap: 2rem; margin-bottom: 1rem; }
.oi-header .score, .oi-header .timer {
    font-size: 1.125rem; font-weight: 600; color: var(--text); padding: 0.5rem 1rem;
    background: var(--surface); border-radius: 0.5rem; border: 1px solid var(--border);
}
.oi-target-display {
    font-size: 1.75rem; font-weight: 700; color: var(--text-heading); padding: 1rem;
    background: var(--surface); border-radius: 0.75rem; border: 2px solid var(--border);
}
.oi-target-display span { font-size: 2rem; margin-right: 0.5rem; display: inline-block; animation: targetPulse 2s infinite; }
@keyframes targetPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }
.oi-game-area { height: 450px; width: 100%; max-width: 700px; }
.balloon {
    position: absolute; display: flex; align-items: center; justify-content: center;
    border-radius: 50%; cursor: pointer; transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); user-select: none; font-weight: bold; color: white;
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2), 0 4px 8px rgba(0, 0, 0, 0.1), inset 0 2px 4px rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.3);
}
.balloon:hover { transform: scale(1.1); }
.balloon.popped { pointer-events: none; }
.balloon.pop-correct { animation: popCorrect 0.3s ease-out forwards; }
.balloon.pop-wrong { animation: popWrong 0.5s ease-in-out forwards; }
@keyframes popCorrect { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(1.5); opacity: 0; } }
@keyframes popWrong {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px) rotate(-5deg); }
    75% { transform: translateX(8px) rotate(5deg); }
}
.points-feedback {
    position: absolute; font-size: 1.5rem; font-weight: bold; animation: floatUp 1s ease-out forwards;
    pointer-events: none; z-index: 100; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
@keyframes floatUp { from { transform: translateY(0) scale(1); opacity: 1; } to { transform: translateY(-50px); opacity: 0; } }

/* --- Sequence Forge Game --- */
.sf-sequence-display {
    display: flex; gap: 1rem; justify-content: center; align-items: center; min-height: 80px;
    padding: 1rem; background-color: var(--secondary-100); border-radius: var(--radius-lg);
    border: 2px solid var(--secondary-200); width: 100%; max-width: 600px;
}
html[data-theme="dark"] .sf-sequence-display { background-color: var(--secondary-800); border-color: var(--secondary-700); }
.symbol-slot {
    width: 60px; height: 60px; background-color: var(--secondary-300); border-radius: var(--radius-md);
    display: flex; justify-content: center; align-items: center; font-size: 2rem; transition: all var(--transition-normal);
}
html[data-theme="dark"] .symbol-slot { background-color: var(--secondary-600); }
.symbol-slot.revealed { background-color: white; color: var(--secondary-800); animation: popIn 0.3s ease-out; }

html[data-theme="dark"] .symbol-slot.revealed { background-color: var(--secondary-200); }
.symbol-slot.filled { background-color: var(--primary-200); border-color: var(--primary-400); }
.symbol-slot.correct { background-color: var(--success-500); color: white; }
.symbol-slot.wrong { background-color: var(--danger-500); color: white; animation: shake 0.5s; }
.sf-symbol-choices { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; margin-top: 2rem; max-width: 600px; }
.symbol-btn { width: 70px; height: 70px; font-size: 2.5rem; padding: 0; }

/* --- Serial Memory & N-Back --- */
.serial-memory-container { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.5rem; width: 300px; height: 300px; }
.serial-memory-btn {
    border-radius: var(--radius-xl); border: 4px solid rgba(0,0,0,0.1); cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}
html[data-theme="dark"] .serial-memory-btn { border-color: rgba(255,255,255,0.1); }
.serial-memory-btn.active { transform: scale(0.95); filter: brightness(1.3) saturate(1.2); box-shadow: 0 0 25px 8px currentColor; }

.nback-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; width: 320px; height: 320px;
    padding: 1.5rem; background: var(--surface); border-radius: var(--radius-2xl); border: 2px solid var(--border);
}
.nback-cell {
    background: linear-gradient(135deg, var(--secondary-50), white); border-radius: var(--radius-lg);
    border: 2px solid var(--border); transition: all var(--transition-normal);
}
html[data-theme="dark"] .nback-cell { background: var(--secondary-800); }
.nback-cell.active {
    background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
    border-color: var(--primary-400); transform: scale(1.05); box-shadow: 0 0 30px 8px rgba(59, 130, 246, 0.4);
}
.choice-btn, .nback-btn, .vnm-btn, .symbol-btn {
    padding: 0.75rem 1.5rem; border-radius: var(--radius-md); border: none; font-weight: 600; cursor: pointer;
    transition: all var(--transition-normal); background: var(--surface); color: var(--text);
    box-shadow: var(--shadow-sm); border: 1px solid var(--border);
}
.choice-btn { width: 100px; }
.choice-btn:hover, .stroop-choice-btn:hover, .nback-btn:hover, .vnm-btn:hover, .symbol-btn:hover {
    transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--secondary-400); filter: brightness(1.05);
}
.choice-btn:active, .stroop-choice-btn:active, .nback-btn:active, .vnm-btn:active, .symbol-btn:active {
    transform: translateY(0); box-shadow: var(--shadow-sm);
}
.vnm-btn.bg-success-500, .choice-btn.bg-success-500 { background: linear-gradient(135deg, var(--success-400), var(--success-500)); color: white; border: none;}
.vnm-btn.bg-danger-500, .choice-btn.bg-danger-500 { background: linear-gradient(135deg, var(--danger-400), var(--danger-500)); color: white; border: none;}
.vnm-display-area { min-height: 200px; padding: 2rem; display: flex; align-items: center; justify-content: center; }

/* --- Pattern Recognition Game --- */
.pr-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; width: 300px; height: 300px;
    padding: 1rem; background-color: var(--secondary-100); border-radius: var(--radius-xl); border: 2px solid var(--secondary-200);
}
html[data-theme="dark"] .pr-grid { background-color: var(--secondary-800); border-color: var(--secondary-700); }
.pr-cell { background-color: var(--secondary-300); border-radius: var(--radius-md); transition: all var(--transition-fast); cursor: pointer; }
html[data-theme="dark"] .pr-cell { background-color: var(--secondary-600); }
.pr-cell:hover { background-color: var(--secondary-400); }
html[data-theme="dark"] .pr-cell:hover { background-color: var(--secondary-500); }
html[data-theme="dark"] .pr-cell:active { background-color: var(--secondary-600); }
.pr-cell.active { background-color: var(--purple-500); box-shadow: 0 0 15px var(--purple-500); }
.pr-cell.selected { background-color: var(--primary-500); }
.pr-cell.correct { background-color: var(--success-500); }
.pr-cell.wrong { background-color: var(--danger-500); animation: shake 0.5s; }

/* ==========================================================================
   8. ANIMATION KEYFRAMES (Consolidated)
   ========================================================================== */
@keyframes gradientShift { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@keyframes fadeOutUp { from {opacity:1; transform: translateY(0) scale(1);} to {opacity:0; transform: translateY(-20px) scale(.98);} }
@keyframes fadeInDown { from {opacity:0; transform: translateY(20px) scale(.98);} to {opacity:1; transform: translateY(0) scale(1);} }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)} }
@keyframes pulse { 0%, 100% { transform: scale(1.15); opacity: 1; } 50% { transform: scale(1.25); opacity: 0.9; } }
@keyframes popIn { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Flash Effects */
.flash-red { animation: flashRed 0.4s cubic-bezier(0.4, 0, 0.2, 1); }
@keyframes flashRed { 0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } 50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0.2); } }
.flash-green { animation: flashGreen 0.5s cubic-bezier(0.4, 0, 0.2, 1); }
@keyframes flashGreen { 0%, 100% { color: inherit; } 50% { color: var(--success-500); transform: scale(1.05); } }

@keyframes flashRedBg { from { background-color: var(--danger-50); } to { background-color: transparent; } }
@keyframes flashGreenBg { from { background-color: var(--success-50); } to { background-color: transparent; } }
@keyframes flashRedBg-dark { from { background-color: rgba(239, 68, 68, 0.2); } to { background-color: transparent; } }
@keyframes flashGreenBg-dark { from { background-color: rgba(34, 197, 94, 0.2); } to { background-color: transparent; } }

.flash-red-bg { animation: flashRedBg 0.4s ease-out; }
.flash-green-bg { animation: flashGreenBg 0.4s ease-out; }
html[data-theme="dark"] .flash-red-bg { animation: flashRedBg-dark 0.4s ease-out; }
html[data-theme="dark"] .flash-green-bg { animation: flashGreenBg-dark 0.4s ease-out; }

.fade-out-and-up { animation: fadeOutUp .35s cubic-bezier(.4,0,1,1) forwards; }
.fade-in-from-down { animation: fadeInDown .35s cubic-bezier(0,0,.2,1) forwards; }

/* ==========================================================================
   9. ACCESSIBILITY FEATURES & FAB
   ========================================================================== */

/* --- FAB Widget --- */
.acc-widget { position: fixed; bottom: 20px; left: 20px; z-index: 9999; font-family: 'Assistant', sans-serif; }
.acc-toggle-btn { width: 56px; height: 56px; border-radius: 50%; background: #ffffff; color: white; border: 2px solid white; box-shadow: 0 4px 12px rgba(0,0,0,0.3); font-size: 28px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: transform 0.3s ease; }
.acc-toggle-btn:hover { transform: scale(1.1); }
.acc-menu { position: absolute; bottom: 70px; left: 0; background: white; border: 1px solid #ccc; border-radius: 12px; padding: 10px; width: 220px; box-shadow: 0 5px 20px rgba(0,0,0,0.2); display: flex; flex-direction: column; gap: 8px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: all 0.3s ease; }
.acc-menu.open { opacity: 1; transform: translateY(0); pointer-events: all; }
html[data-theme="dark"] .acc-menu { background: #1e293b; border-color: #475569; }
.acc-option-btn { display: flex; align-items: center; gap: 10px; padding: 10px; background: #f1f5f9; border: 1px solid #cbd5e1; border-radius: 8px; cursor: pointer; font-size: 16px; font-weight: 600; color: #334155; text-align: right; }
html[data-theme="dark"] .acc-option-btn { background: #0f172a; border-color: #334155; color: #e2e8f0; }
.acc-option-btn.active { background: #0ea5e9; color: white; border-color: #0284c7; }

/* NEW: Highlight active accessibility options in dark mode */
html[data-theme="dark"] .acc-option-btn.active { 
    background: #0ea5e9; 
    color: white; 
    border-color: #0ea5e9; 
}

/* --- High Contrast Mode --- */
html.acc-high-contrast {
    --surface: #ffffff !important; --card-bg: #ffffff !important; --glass-bg: #ffffff !important;
    --text: #000000 !important; --text-muted: #000000 !important; --text-heading: #000000 !important;
    --border: #000000 !important; --primary-500: #0000EE !important;
    --gradient-ocean: none !important; --gradient-success: none !important;
    background: #ffffff !important;
}
html.acc-high-contrast[data-theme="dark"] {
    --surface: #000000 !important; --card-bg: #000000 !important; --glass-bg: #000000 !important;
    --text: #FFFF00 !important; --text-muted: #FFFFFF !important; --text-heading: #FFFF00 !important;
    --border: #FFFFFF !important; --primary-500: #FFFF00 !important;
    background: #000000 !important;
}
html.acc-high-contrast .btn,
html.acc-high-contrast .card-auth,
html.acc-high-contrast .stat-card,
html.acc-high-contrast .dashboard-section,
html.acc-high-contrast .level-node,
html.acc-high-contrast .overview-card,
html.acc-high-contrast .acc-menu,
html.acc-high-contrast .acc-option-btn,
html.acc-high-contrast .acc-toggle-btn {
    border: 3px solid var(--text) !important; box-shadow: none !important;
    background: var(--surface) !important; color: var(--text) !important;
}
/* FIX: Force title visibility in High Contrast Mode */
html.acc-high-contrast h1, html.acc-high-contrast h2, html.acc-high-contrast h3,
html.acc-high-contrast h4, html.acc-high-contrast .dashboard-title,
html.acc-high-contrast .stat-card h4, html.acc-high-contrast .overview-card h3,
html.acc-high-contrast .article-card h3, html.acc-high-contrast .personalized-btn span {
    color: var(--text-heading) !important; background: none !important;
    -webkit-text-fill-color: initial !important;
}
html.acc-high-contrast .acc-option-btn:hover { text-decoration: underline; }
html.acc-high-contrast .acc-option-btn.active { background: var(--text) !important; color: var(--surface) !important; }

/* --- Text Sizes --- */
html.acc-medium-text { font-size: 19px !important; }
html.acc-medium-text .btn { padding: 1rem 1.5rem !important; font-size: 1.1rem !important; }
html.acc-medium-text .game-board { gap: 1.25rem !important; }

html.acc-large-text { font-size: 22px !important; }
html.acc-large-text .btn { padding: 1.25rem 1.75rem !important; font-size: 1.3rem !important; }
html.acc-large-text .game-board { gap: 1.5rem !important; }

html.acc-extra-large-text { font-size: 26px !important; }
html.acc-extra-large-text .btn { padding: 1.5rem 2rem !important; font-size: 1.5rem !important; }
html.acc-extra-large-text .game-board { gap: 1.75rem !important; }

/* --- Reduced Motion --- */
html.acc-no-motion .particles, html.acc-no-motion .bg-ornaments, html.acc-no-motion .ai-coach-toggle,
html.acc-no-motion .brand-chip, html.acc-no-motion .stat-card::before, html.acc-no-motion .dashboard-section::before {
    animation: none !important; transition: none !important; transform: none !important;
}
html.acc-no-motion .btn, html.acc-no-motion .modal-content, html.acc-no-motion .dashboard-section,
html.acc-no-motion .level-node { transition: none !important; animation: none !important; }

/* ==========================================================================
   10. MEDIA QUERIES
   ========================================================================== */
@media (max-width: 768px) {
    .dashboard-container { gap: 1.5rem; }
    .dashboard-section { padding: 1.5rem; margin: 0 0.5rem; }
    .dashboard-title { font-size: 1.5rem; }
    .levels-container { gap: 0.75rem; padding: 0.75rem; }
    .level-node { width: 48px; height: 48px; font-size: 1.125rem; }
    .level-connector { width: 30px; height: 3px; display: none; }
    .stats-grid { grid-template-columns: 1fr; gap: 1rem; }
    .game-board { gap: 0.75rem; padding: 0.75rem; }
    .music-player { padding: 0.4rem 0.5rem; flex-direction: row; flex-wrap: wrap; justify-content: center; }
    .music-track-info { display: none; }
    #music-volume-slider { width: 40px; }
    .divider-vertical { display: none; }
}

@media (max-width: 640px) {
    .level-node { margin-bottom: 0.5rem; }
    .levels-container { justify-content: center; }
    .dashboard-section { margin: 0; border-radius: var(--radius-xl); }
    .personalized-btn { padding: 1.25rem; }
}

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

/* Focus States */
.level-node:focus, .choice-btn:focus, .nback-btn:focus, .vnm-btn:focus, .personalized-btn:focus, *:focus-visible {
    outline: 2px solid var(--primary-500); outline-offset: 2px;
}

/* High Contrast Mode System Pref */
@media (prefers-contrast: high) {
    :root {
        --shadow-sm: 0 2px 4px 0 rgb(0 0 0 / 0.3);
        --shadow-md: 0 4px 8px 0 rgb(0 0 0 / 0.3);
        --shadow-lg: 0 8px 16px 0 rgb(0 0 0 / 0.3);
    }
}

/* ==========================================================================
   11. MUSIC PLAYER
   ========================================================================== */
.music-player {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-left: 1rem;
    backdrop-filter: blur(8px);
    direction: ltr;
}

.music-controls-row, .music-info-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.music-player button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-heading);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.music-player button:hover {
    background: var(--secondary-200);
}
html[data-theme="dark"] .music-player button:hover {
    background: var(--secondary-600);
}

.music-track-info {
    display: flex;
    flex-direction: column;
    min-width: 80px;
    margin: 0 0.5rem;
    text-align: center;
}

.music-track-title {
    font-size: 0.8rem;
    font-weight: bold;
    color: var(--text-heading);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
}

.music-label {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.volume-container {
    display: flex;
    align-items: center;
    gap: 4px;
}
#music-volume-slider {
    width: 60px;
    height: 4px;
    border-radius: 2px;
    background: var(--secondary-300);
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}
#music-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary-500);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.divider-vertical {
    width: 1px;
    height: 24px;
    background-color: var(--border);
    margin: 0 8px;
}

.sfx-btn.muted {
    opacity: 0.5;
    filter: grayscale(1);
}

/* ==========================================================================
   12. FINAL POLISH PATCHES
   ========================================================================== */

/* --- AI Coach Button Mobile Safety --- */
@media (max-width: 768px) {
    #ai-coach-toggle-btn {
        bottom: 90px;
        right: 20px;
        width: 54px;
        height: 54px;
        font-size: 1.4rem;
        box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    }

    .ai-coach-window {
        width: 92%;
        right: 4%;
        left: 4%;
        bottom: 155px;
        height: 55vh;
    }
}

/* --- Dark Mode High-Contrast Overrides --- */
[data-theme="dark"] .game-card {
    background-color: #1e293b;
    border: 1px solid #334155;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .game-card h3 {
    color: #f8fafc;
}

[data-theme="dark"] .game-card p {
    color: #cbd5e1;
}

[data-theme="dark"] .modal-content {
    background-color: #0f172a;
    border: 1px solid #334155;
    color: #e2e8f0;
}

[data-theme="dark"] .modal-content h2 {
    color: #38bdf8;
}

/* --- Z-Index Safety --- */
.modal-backdrop {
    z-index: 99999 !important;
}

#ai-coach-toggle-btn, .ai-coach-window {
    z-index: 10000;
}

/* ==========================================================================
   13. SPINNER (Appended for Compatibility)
   ========================================================================== */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-left-color: var(--primary-500);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
[data-theme="light"] .spinner {
    border-color: #e2e8f0;
    border-left-color: #0ea5e9;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   14. RESPONSIVE LAPTOP & HIGH ZOOM FIXES
   ========================================================================== */
@media screen and (max-width: 1440px) and (min-resolution: 1.25dppx), 
       screen and (max-width: 1366px),
       screen and (max-height: 850px) {

    /* --- Compact Layout --- */
    .app-shell {
        max-width: 1000px; 
        padding-bottom: 2rem;
    }
    
    .dashboard-container {
        gap: 1rem;
    }
    
    /* --- Smaller Header --- */
    .app-header {
        padding: 0.5rem 1rem;
    }
    .brand__icon { font-size: 1.2rem; }
    .brand__name { font-size: 1.1rem; }
    .score-pill { padding: 0.25rem 0.5rem; font-size: 0.9rem; }
    
    /* --- Compact Game Boards --- */
    .game-board {
        gap: 0.5rem;
        padding: 0.75rem;
        max-width: 420px; /* Reduced from 500px */
    }
    .game-board.cols-5 { max-width: 500px; }
    .game-board.cols-6 { max-width: 580px; }
    
    /* Memory Cards */
    .front-face { font-size: 2rem; }
    
    /* --- Fixed Height Game Areas Reduction --- */
    .perception-game-area,
    .trail-making-area,
    .oi-game-area, 
    .ss-game-area,
    .track-switcher-area {
        height: 380px; /* Reduced from 400-450px */
    }
    
    /* Game Elements Scaling */
    .trail-node { width: 42px; height: 42px; font-size: 1.2rem; }
    .station { width: 32px; height: 32px; font-size: 16px; }
    .switch { width: 24px; height: 24px; }
    .train { width: 20px; height: 20px; }
    
    /* Dashboard Elements */
    .stat-card {
        padding: 1rem;
        min-height: 110px;
    }
    .stat-card .text-4xl { font-size: 1.8rem; }
    
    .dashboard-section {
        padding: 1.25rem;
    }
    .dashboard-title {
        font-size: 1.4rem;
        margin-bottom: 1rem;
    }
    
    /* Toolbar */
    .toolbar {
        margin: 0.5rem auto 1rem;
        padding: 0.5rem;
    }
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.95rem;
    }
}

/* --- Extreme Vertical Constraint (e.g. 150% zoom on 1080p gives ~720px height) --- */
@media screen and (max-height: 720px) {
    .app-header { padding: 0.25rem 1rem; }
    
    .perception-game-area,
    .trail-making-area,
    .oi-game-area,
    .ss-game-area,
    .track-switcher-area {
        height: 320px; /* Further reduction */
    }
    
    .game-board {
        max-width: 380px;
    }
    
    .modal-content {
        padding: 1rem;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .hero-title { font-size: 2.5rem; }
    .hero-subtitle { font-size: 1.1rem; margin-bottom: 1.5rem; }
    
    /* Hide non-essential elements on short screens during gameplay if needed */
    .bg-ornaments { display: none; }
}

/* ==========================================================================
   1. DESIGN TOKENS & VARIABLES
   ========================================================================== */
:root {
  /* --- Brand Palette --- */
  --primary-50:#f0f9ff; --primary-100:#e0f2fe; --primary-200:#bae6fd;
  --primary-300:#7dd3fc; --primary-400:#38bdf8; --primary-500:#0ea5e9;
  --primary-600:#0284c7; --primary-700:#0369a1; --primary-800:#075985;

  /* --- Grayscale --- */
  --secondary-50:#f8fafc; --secondary-100:#f1f5f9; --secondary-200:#e2e8f0;
  --secondary-300:#cbd5e1; --secondary-400:#94a3b8; --secondary-500:#64748b;
  --secondary-600:#475569; --secondary-700:#334155; --secondary-800:#1e293b;
  --secondary-900:#0f172a;

  /* --- States --- */
  --success-50: #f0fdf4; --success-100: #dcfce7;
  --success-400:#4ade80; --success-500:#22c55e; --success-600:#16a34a;
  
  --danger-50: #fef2f2; --danger-100: #fee2e2;
  --danger-400:#f87171; --danger-500:#ef4444; --danger-600:#dc2626;
  
  --warning-400:#facc15; --warning-500:#eab308;
  
  --purple-400:#c084fc; --purple-500:#8b5cf6; --purple-600:#7c3aed;
  
  /* --- Social Colors --- */
  --facebook-blue: #1877F2;
  --whatsapp-green: #25D366;

  /* --- Gradients --- */
  --gradient-ocean: linear-gradient(135deg, #06b6d4 0%, #3b82f6 50%, #8b5cf6 100%);
  --gradient-success: linear-gradient(135deg, var(--success-400) 0%, var(--success-600) 100%);
  --gradient-sunset: linear-gradient(135deg, #f59e0b 0%, #ef4444 50%, #ec4899 100%);
  --gradient-primary: linear-gradient(135deg, var(--primary-400) 0%, var(--primary-600) 100%);
  --gradient-hero-text: linear-gradient(to right, var(--primary-600), var(--purple-600));

  /* --- Surfaces & Materials --- */
  --surface: linear-gradient(135deg, var(--secondary-50) 0%, var(--primary-50) 100%);
  --nav-bg: rgba(255, 255, 255, 0.8);
  --card-bg: rgba(255, 255, 255, 0.95);
  --glass-bg: rgba(255, 255, 255, 0.7);
  --border: rgba(15, 23, 42, .08);
  --text: var(--secondary-800);
  --text-muted: var(--secondary-500);
  --text-heading: var(--secondary-900);
  --progress-bg: var(--secondary-200);
  
  /* --- Geometry --- */
  --radius-xs:.375rem; --radius-sm:.5rem; --radius-md:.75rem;
  --radius-lg:1rem; --radius-xl:1.5rem; --radius-2xl:2rem; --radius-3xl:3rem;

  /* --- Shadows --- */
  --shadow-sm:0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md:0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg:0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl:0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --shadow-2xl:0 25px 50px -12px rgb(0 0 0 / 0.25);
  --shadow-glow: 0 0 20px 0 rgb(14 165 233 / 0.3);
  --shadow-glow-purple: 0 0 20px 0 rgb(139 92 246 / 0.3);

  /* --- Effects --- */
  --blur-sm: 8px; --blur-md: 12px; --blur-lg: 16px; --blur-xl: 24px;

  /* --- Animation Speeds --- */
  --transition-fast:.15s ease-out;
  --transition-normal:.2s ease-out;
  --transition-slow:.3s ease-out;
  --transition-bounce:.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* --- THEME DEFINITIONS --- */

html[data-theme="dark"] {
  --surface: linear-gradient(135deg, #0b1220 0%, #0f172a 100%);
  --nav-bg: rgba(255, 255, 255, 0.05);
  --card-bg: #1e293b; 
  --glass-bg: #1e293b; 
  --border: rgba(148, 163, 184, .15);
  --text: #cbd5e1;
  --text-muted: var(--secondary-400);
  --text-heading: #f1f5f9;
  --progress-bg: rgba(255, 255, 255, 0.1);
  --gradient-hero-text: linear-gradient(to right, #ffffff, var(--primary-200), var(--purple-200));
}

/* Light Pastel Theme (Color Blind Friendly) */
[data-theme="light-pastel"] {
    --surface: linear-gradient(135deg, #fef2f2 0%, #f0f9ff 100%);
    --card-bg: #ffffff;
    --text: #334155;
    --text-heading: #0f172a;
    --primary-500: #ec4899; 
    --primary-gradient: linear-gradient(135deg, #f472b6 0%, #60a5fa 100%);
    --border: rgba(236, 72, 153, 0.2);
    --secondary-50: #fdf2f8;
}

/* Dark Bold Theme (Neon Strokes) */
[data-theme="dark-bold"] {
    --surface: #000000;
    --card-bg: #0a0a0a;
    --text: #ffffff;
    --text-heading: #00ffff; /* Neon Cyan */
    --primary-500: #00ffff;
    --primary-gradient: linear-gradient(135deg, #00ffff 0%, #ff00ff 100%);
    --border: #00ffff;
    --progress-bg: #1a1a1a;
}
[data-theme="dark-bold"] .card, 
[data-theme="dark-bold"] .stat-card,
[data-theme="dark-bold"] .dashboard-section,
[data-theme="dark-bold"] .score-pill,
[data-theme="dark-bold"] .user-box {
    border: 3px solid #00ffff !important;
    box-shadow: 0 0 15px rgba(0, 255, 204, 0.3) !important;
}
[data-theme="dark-bold"] .btn-outline {
    border: 3px solid #ff00ff !important;
    color: #ff00ff !important;
}

/* ==========================================================================
   2. ACCESSIBILITY SCALING & FIT LOGIC
   ========================================================================== */

html {
    font-size: 18px !important; /* Naturally bigger baseline */
    transition: font-size 0.3s ease;
}

/* Interface Zoom: Proportional scaling */
html.acc-scale-85 { font-size: 15.3px !important; }
html.acc-scale-100 { font-size: 18px !important; }
html.acc-scale-120 { font-size: 21.6px !important; }
html.acc-scale-140 { font-size: 25.2px !important; }
html.acc-scale-160 { font-size: 28.8px !important; }

/* Global growth fixes: Containers grow vertically for large text */
html[class*="acc-text"] body, 
html[class*="acc-text"] .dashboard-section,
html[class*="acc-text"] .stat-card,
html[class*="acc-text"] .achievement-card,
html[class*="acc-text"] .user-box,
html[class*="acc-text"] .levels-container {
    height: auto !important;
    min-height: min-content !important;
}

html[class*="acc-text"] .level-node,
html[class*="acc-text"] .star-rating,
html[class*="acc-text"] .score-pill,
html[class*="acc-text"] .achievement-icon,
html[class*="acc-text"] .game-preview-card {
    flex-wrap: wrap !important;
    height: auto !important;
    padding: 0.8rem !important;
    min-width: unset !important;
}

/* 150% Zoom shrink Detection */
@media screen and (max-height: 750px) {
    .app-header { padding: 0.25rem 1rem; }
    .hero-title { font-size: 2.2rem; }
    .game-board, .qmm-grid, .perception-game-area, .trail-making-area, .quantitative-game-area { 
        max-height: 52vh !important; 
        max-width: 52vh !important; 
        padding: 0.5rem !important;
    }
    #qm-display-area { height: 240px !important; }
}

/* ==========================================================================
   3. BASE STYLES & BACKGROUNDS
   ========================================================================== */
body {
  background: var(--surface);
  color: var(--text);
  line-height: 1.6;
  margin: 0;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  transition: background 0.3s ease, color 0.3s ease;
}

.bg-ornaments {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(circle at 20% 50%, rgba(14,165,233,.08) 0%, transparent 60%),
    radial-gradient(circle at 80% 80%, rgba(139,92,246,.08) 0%, transparent 60%),
    radial-gradient(circle at 40% 20%, rgba(236,72,153,.05) 0%, transparent 60%),
    radial-gradient(rgba(203,213,225,.2) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 100% 100%, 20px 20px;
  animation: meshMove 25s ease-in-out infinite;
}

/* ==========================================================================
   4. PARTICLES & VISUALS
   ========================================================================== */
#particles { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.particle { position: absolute; background: white; border-radius: 50%; opacity: 0.2; animation: floatParticle 15s linear infinite; }
[data-theme="dark"] .particle, [data-theme="dark-bold"] .particle { opacity: 0.8; box-shadow: 0 0 10px rgba(255, 255, 255, 0.4); }

@keyframes floatParticle {
    0% { transform: translateY(100vh) translateX(0) rotate(0deg); opacity: 0; }
    10% { opacity: var(--particle-opacity, 0.5); }
    100% { transform: translateY(-20vh) translateX(50px) rotate(360deg); opacity: 0; }
}

.brain-pulse {
    animation: brainPulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
    display: inline-block;
    will-change: transform;
}
@keyframes brainPulse {
    0% { transform: scale(1); filter: drop-shadow(0 0 2px rgba(139, 92, 246, 0.3)); }
    50% { transform: scale(1.25); filter: drop-shadow(0 0 15px rgba(139, 92, 246, 0.8)); }
}

/* ==========================================================================
   5. LAYOUT & HEADER
   ========================================================================== */
.app-shell { max-width: 1280px; margin: 0 auto; }

.app-header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.75rem 1rem;
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; color: var(--text-heading); font-size: 1.25rem; }
.score-pill {
  display: flex; align-items: center; gap: .375rem; padding: .4rem .75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  color: var(--text);
}

.dashboard-container { display: flex; flex-direction: column; gap: 2rem; padding: 1rem; }

.stats-grid-4 { 
    display: grid; gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
@media (min-width: 1280px) { .stats-grid-4 { grid-template-columns: repeat(4, 1fr); } }

/* ==========================================================================
   6. UI COMPONENTS
   ========================================================================== */
.btn {
  border: none; cursor: pointer; font-weight: 800; padding: .75rem 1.25rem;
  border-radius: var(--radius-lg); transition: all 0.3s;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-primary { color: #fff; background: var(--primary-gradient); box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6); }

.stat-card {
    background: var(--surface); padding: 1.5rem; border-radius: var(--radius-xl); border: 1px solid var(--border);
    transition: all 0.3s; text-align: center; cursor: pointer; display: flex; flex-direction: column; justify-content: center;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--card-shadow-hover); }

/* ==========================================================================
   7. ACCESSIBILITY WIDGET & FAB
   ========================================================================== */
.acc-widget {
    position: fixed; bottom: 20px; left: 20px; /* MOVED TO LEFT */
    z-index: 10000;
}
.acc-toggle-btn {
    width: 68px; height: 68px; border-radius: 50%; background: var(--primary-gradient);
    border: 4px solid white; box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
    cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.3s;
}
.acc-icon { width: 48px; height: 48px; filter: brightness(0) invert(1); }
.acc-toggle-btn:hover { transform: scale(1.1) rotate(5deg); }

.acc-menu {
    position: absolute; bottom: 85px; left: 0;
    background: var(--card-bg); border-radius: var(--radius-xl);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    opacity: 0; transform: translateY(20px) scale(0.9);
    pointer-events: none; transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    width: 360px; padding: 1.5rem;
}
.acc-menu.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: all; }

#acc-reset {
    width: 100% !important; padding: 1.25rem !important; min-height: 56px !important;
    background: var(--danger-gradient) !important; color: white !important;
    border-radius: var(--border-radius-md); font-weight: 800; border: none;
    margin-top: 1rem; box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.acc-option-btn {
    padding: 0.75rem 0.5rem; border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-md); background: white; cursor: pointer;
    font-weight: 600; font-size: 0.8rem; transition: 0.3s;
}
[data-theme*="dark"] .acc-option-btn { background: #16213e; color: white; border-color: rgba(255,255,255,0.1); }
.acc-option-btn.active { background: var(--primary-gradient); color: white; border-color: transparent; }

.status-dot { width: 12px; height: 12px; border-radius: 50%; background: #cbd5e1; transition: 0.3s; }
.active .status-dot { background: #22c55e; box-shadow: 0 0 10px #22c55e; }

/* ==========================================================================
   8. GAME ENGINE STYLES
   ========================================================================== */
.game-board {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem;
    padding: 1rem; background: var(--surface); border-radius: var(--radius-xl);
    border: 1px solid var(--border); max-width: 500px; margin: 0 auto;
}

.memory-card {
    width: 100%; aspect-ratio: 1 / 1; position: relative; transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275); cursor: pointer;
}
.memory-card.flip { transform: rotateY(180deg); }
.front-face { background: var(--primary-gradient); color: white; border-radius: var(--radius-lg); font-size: 2.5rem; }

.trail-node {
    width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; font-weight: 700; background: var(--surface); border: 3px solid var(--border);
    position: absolute; transition: 0.2s;
}

/* ==========================================================================
   9. FORMS & INPUTS
   ========================================================================== */
.form-input {
  width:100%; padding:.8rem 1rem; border-radius: .9rem; border:1px solid var(--border);
  background: var(--surface); color: var(--text); outline: none; transition: 0.3s;
}
.form-input:focus { border-color: var(--primary-500); box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2); }

/* ==========================================================================
   10. MUSIC PLAYER
   ========================================================================== */
.music-player {
    display: flex; align-items: center; background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px); padding: 0.75rem 1rem; border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm); direction: ltr;
}
[data-theme*="dark"] .music-player { background: rgba(0,0,0,0.5); }

/* ==========================================================================
   11. MODALS & TOASTS
   ========================================================================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; z-index: 99999; padding: 1rem;
}
.modal-content {
  background: var(--card-bg); padding: 2rem; border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl); text-align: center; max-width: 520px; width: 100%;
}

.achievement-toast {
    position: fixed; bottom: 20px; left: 20px; z-index: 10000;
    background: var(--primary-gradient); color: white; border-radius: var(--radius-xl);
    padding: 1rem 1.5rem; display: flex; align-items: center; gap: 1rem;
    box-shadow: 0 20px 40px rgba(102, 126, 234, 0.4);
}

/* ==========================================================================
   12. FINAL UTILITIES
   ========================================================================== */
.spinner {
    width: 40px; height: 40px; border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: white; border-radius: 50%; animation: spinRotate 1s linear infinite;
}
@keyframes spinRotate { to { transform: rotate(360deg); } }

