/* ==========================================================================
   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
   ========================================================================== */
/* overflow-x on html/body intentionally NOT set here —
   html:overflow-x:hidden creates an iOS WebKit scroll container that
   blocks all child horizontal scroll (e.g. the mobile tab bar).
   The real overflow-x rules live in the "Global Mobile Overflow Fix"
   section further below, using 'clip' (not 'hidden') which avoids
   creating a scroll container. Inner containers (.app-shell etc.) still
   use overflow-x:clip/hidden to prevent content from reaching this level. */
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;
  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); }
}


/* --- 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 --- (styles in section 5.1) */

/* --- App Header (Logged In) --- */
.app-header {
  position: sticky; top: 0; z-index: 100;
  display: grid;
  /* Wide (≥1291px): brand | stats | tools | profile — 4 auto-balanced columns */
  grid-template-columns: 1fr auto auto 1fr;
  grid-template-areas: "brand center util right";
  align-items: center;
  min-height: 60px;
  padding: 0 1.25rem;
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  transition: background var(--transition-normal), border-color var(--transition-normal);
  overflow-x: clip;   /* no scrollbar; clip (not hidden) so flex children can scroll */
  overflow-y: visible; /* allow expanded util-group row to show below header */
}
.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: .4rem; font-weight: 800; color: var(--text-heading); font-size: 1rem; }
.brand__icon { font-size: 1.2rem; }
.brand__name { font-size: 0.92rem; }
.brand__dot  { display: none; }
.brand__section { display: none; }

/* Header grid sections */
.app-header__brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
  overflow: hidden;
}
.app-header__center {
  grid-area: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0 0.5rem;
  min-width: 0; /* allow shrinking in grid */
}
.app-header__right {
  grid-area: right;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
  min-width: 0;
}

/* Uniform utility buttons — menu-button style */
.header-util-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 0.875rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  height: 38px;
  flex-shrink: 0;
}
.header-util-btn:hover {
  border-color: var(--primary-400);
  color: var(--primary-500);
  background: rgba(99, 102, 241, 0.06);
}

/* =====================================================================
   RESPONSIVE HEADER — 2-row wrap at ≤768px (no fixed overlays)
   ===================================================================== */
@media (max-width: 768px) {
  .app-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    min-height: auto;
    padding: 0.35rem 0.75rem 0;
    gap: 0;
  }
  /* Row 1: Brand (fills available space) */
  .app-header__brand {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    padding-bottom: 0.35rem;
  }
  /* Row 1: Right (theme + user + toggle, right-aligned) */
  .app-header__right {
    flex: 0 0 auto;
    gap: 0.25rem;
    flex-wrap: nowrap;
    align-items: center;
    padding-bottom: 0.35rem;
  }
  /* Row 2: Center (streak, score, premium) — full width, below Row 1 */
  .app-header__center {
    flex: 0 0 100%;
    position: static !important;
    width: auto !important;
    border-top: 1px solid var(--border);
    padding: 0.35rem 0.75rem;
    gap: 0.6rem;
    justify-content: center;
    display: flex !important;
    align-items: center;
    background: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
  }
  /* No padding needed — center is in header flow, not fixed */
  #main-app-screen .app-shell { padding-bottom: 0 !important; }
  .header-util-btn { height: 32px; font-size: 0.75rem; padding: 0 0.45rem; }
}

/* Streak Pill */
.streak-pill {
  display: flex; align-items: center; gap: .3rem; padding: 0 0.75rem;
  height: 38px;
  background: rgba(251, 146, 60, 0.09);
  border: 1px solid rgba(251, 146, 60, 0.3); border-radius: 8px;
  transition: all 0.2s ease;
  flex-shrink: 0; white-space: nowrap; cursor: default;
}
.streak-pill:hover { background: rgba(251, 146, 60, 0.14); border-color: rgba(234, 88, 12, 0.45); }
html[data-theme="dark"] .streak-pill {
  background: rgba(251, 146, 60, 0.1);
  border-color: rgba(251, 146, 60, 0.3);
}
.streak-fire { font-size: 1.1rem; line-height: 1; }
.streak-count { font-size: 1.15rem; font-weight: 800; color: #ea580c; line-height: 1; }
html[data-theme="dark"] .streak-count { color: #fb923c; }
.streak-label { font-size: 0.7rem; font-weight: 600; color: #9a3412; opacity: 0.8; }
html[data-theme="dark"] .streak-label { color: #fdba74; }

/* Streak glow when active (3+ days) */
.streak-pill.streak-hot {
  border-color: rgba(234, 88, 12, 0.5);
  box-shadow: 0 2px 12px rgba(234, 88, 12, 0.25);
  animation: streakGlow 2s ease-in-out infinite;
}
@keyframes streakGlow {
  0%, 100% { box-shadow: 0 2px 12px rgba(234, 88, 12, 0.2); }
  50% { box-shadow: 0 4px 20px rgba(234, 88, 12, 0.4); }
}

/* Score Pill */
.score-pill {
  display: flex; align-items: center; gap: .25rem; padding: 0 0.75rem;
  height: 38px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); transition: all 0.2s ease;
  flex-shrink: 0; white-space: nowrap; font-size: 0.85rem;
}
.score-pill:hover { border-color: var(--primary-400); background: rgba(99,102,241,0.05); }
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; }

/* Quest completion celebration overlay */
.quest-celebration {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.quest-celebration-card {
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(20px);
  border: 2px solid rgba(52, 211, 153, 0.4);
  border-radius: 24px;
  padding: 2.5rem 3rem;
  text-align: center;
  color: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 40px rgba(52, 211, 153, 0.2);
  animation: celebrationPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: auto;
}
html[data-theme="light"] .quest-celebration-card {
  background: rgba(255, 255, 255, 0.95);
  color: var(--text-heading);
  border-color: rgba(52, 211, 153, 0.5);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 0 40px rgba(52, 211, 153, 0.15);
}
@keyframes celebrationPop {
  0% { opacity: 0; transform: scale(0.5) translateY(30px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes celebrationFade {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.9) translateY(-20px); }
}

/* 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 (legacy - kept for compatibility) --- */
.dashboard-container {
    display: flex; flex-direction: column; gap: 2rem;
    max-width: 1280px; margin: 1rem auto; padding: 0 1rem;
    position: relative; z-index: 2;
}

/* ==========================================================================
   SIDEBAR DASHBOARD LAYOUT
   ========================================================================== */

/* Main two-panel layout */
.dash-layout {
    display: flex;
    gap: 0;
    min-height: calc(100vh - 120px);
    position: relative;
}

/* ---- SIDEBAR ---- */
.dash-sidebar {
    width: 240px;
    min-width: 240px;
    background: linear-gradient(180deg, var(--card-bg) 0%, var(--bg) 100%);
    border-left: 2px solid var(--border);
    border-radius: 0 var(--radius-2xl) var(--radius-2xl) 0;
    display: flex;
    flex-direction: column;
    padding: 1rem 0;
    position: sticky;
    top: 80px;
    height: fit-content;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    box-shadow: -4px 0 20px rgba(0,0,0,0.04);
    z-index: 10;
}

html[data-theme="dark"] .dash-sidebar {
    background: linear-gradient(180deg, var(--secondary-800) 0%, var(--secondary-900) 100%);
    border-left-color: var(--secondary-700);
    box-shadow: -4px 0 20px rgba(0,0,0,0.2);
}

.dash-sidebar__header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
}

.dash-sidebar__logo {
    font-size: 1.6rem;
}

.dash-sidebar__title {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-heading);
    letter-spacing: -0.02em;
}

.dash-sidebar__menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 0.5rem;
    flex: 1;
}

/* ---- Menu Item ---- */
.dash-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-lg);
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: right;
    width: 100%;
    position: relative;
    font-family: inherit;
}

.dash-menu-item:hover {
    background: var(--primary-50);
}

html[data-theme="dark"] .dash-menu-item:hover {
    background: var(--secondary-700);
}

.dash-menu-item--active {
    background: linear-gradient(135deg, var(--primary-500), var(--primary-600)) !important;
    color: white !important;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
    transform: scale(1.02);
}

.dash-menu-item--active .dash-menu-item__label,
.dash-menu-item--active .dash-menu-item__desc {
    color: white !important;
}

.dash-menu-item--locked {
    opacity: 0.55;
}

.dash-menu-item--locked:hover {
    opacity: 0.75;
}

.dash-menu-item__icon {
    font-size: 1.4rem;
    flex-shrink: 0;
    width: 32px;
    text-align: center;
}

.dash-menu-item__text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.dash-menu-item__label {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-heading);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dash-menu-item__desc {
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.2;
}

.dash-menu-item__lock {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    opacity: 0.7;
}

/* ---- Sidebar Footer ---- */
.dash-sidebar__footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
}

.dash-sidebar__fact {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.dash-sidebar__fact-text {
    font-style: italic;
}

/* ---- CONTENT PANEL ---- */
.dash-content {
    flex: 1;
    padding: 1.5rem 2.5rem;
    min-width: 0;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

/* ---- MOBILE NAV BAR ---- */
.dash-mobile-nav {
    display: none; /* hidden on desktop */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
    padding: 8px 8px 6px;
    background: var(--card-bg);
    border-bottom: 2px solid var(--border);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    position: sticky;
    top: 0;
    z-index: 15;
}

html[data-theme="dark"] .dash-mobile-nav {
    background: var(--secondary-800);
    border-bottom-color: var(--secondary-700);
}

.dash-mobile-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    flex-shrink: 0;
    font-family: inherit;
    position: relative;
}

.dash-mobile-tab:hover {
    background: var(--primary-50);
}

.dash-mobile-tab--active {
    background: linear-gradient(135deg, var(--primary-500), var(--primary-600)) !important;
    color: white !important;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.dash-mobile-tab--active .dash-mobile-tab__label {
    color: white !important;
}

.dash-mobile-tab--locked {
    opacity: 0.5;
}

.dash-mobile-tab__icon {
    font-size: 1.3rem;
}

.dash-mobile-tab__label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-heading);
}

.dash-mobile-tab__lock {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 0.55rem;
}

/* ---- Section Header ---- */
.dash-section-header {
    margin-bottom: 1.5rem;
}

.dash-section-title {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-heading);
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

.dash-section-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ---- Dashboard Cards ---- */
.dash-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-2xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.dash-card:hover {
    box-shadow: var(--shadow-md);
}

.dash-card--hero {
    background: linear-gradient(135deg, #6366f1, #7c3aed);
    color: white;
    border: none;
    box-shadow: 0 8px 30px rgba(99, 102, 241, 0.25);
}

.dash-card--hero:hover {
    box-shadow: 0 12px 40px rgba(99, 102, 241, 0.35);
    transform: translateY(-2px);
}

.dash-card--article {
    background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
    border-color: #bae6fd;
}

html[data-theme="dark"] .dash-card--article {
    background: linear-gradient(135deg, var(--secondary-800), var(--secondary-900));
    border-color: var(--secondary-700);
}

/* ---- Skill Category Headers ---- */
.dash-category__header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.dash-category__badge {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 3px 10px rgba(0,0,0,0.15);
}

.dash-category__badge-icon {
    font-size: 1.4rem;
    filter: brightness(1.2);
}

.dash-category__info {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.dash-category__title {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-heading);
    line-height: 1.2;
}

.dash-category__count {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* ---- Empty State ---- */
.dash-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 2rem;
    min-height: 320px;
    background: var(--card-bg);
    border-radius: var(--radius-lg, 1rem);
    border: 2px dashed var(--secondary-200);
}
.dash-empty-state__icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: emptyBounce 2s ease-in-out infinite;
}
@keyframes emptyBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}
.dash-empty-state__title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-heading);
    margin-bottom: 0.5rem;
}
.dash-empty-state__text {
    font-size: 1.05rem;
    color: var(--text-muted);
    line-height: 1.7;
    max-width: 400px;
}
.dark .dash-empty-state {
    background: rgba(30, 41, 59, 0.6);
    border-color: var(--secondary-700);
}

/* ---- Free Play Game Cards ---- */
.dash-games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 1.25rem;
}

.dash-game-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1.25rem 1rem;
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: var(--radius-xl);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    font-family: inherit;
}

.dash-game-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
    border-color: var(--primary-300);
}

.dash-game-card--locked {
    opacity: 0.5;
    filter: grayscale(60%);
    cursor: not-allowed;
}

.dash-game-card--locked:hover {
    opacity: 0.65;
    filter: grayscale(30%);
    transform: none;
}

.dash-game-card__top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 0.5rem;
}

.dash-game-card__icon {
    font-size: 2rem;
}

.dash-game-card__lock-badge {
    font-size: 0.65rem;
    font-weight: 700;
    background: #374151;
    color: white;
    padding: 2px 8px;
    border-radius: 999px;
}

.dash-game-card__free-badge {
    font-size: 0.65rem;
    font-weight: 700;
    background: #dcfce7;
    color: #166534;
    padding: 2px 8px;
    border-radius: 999px;
}

html[data-theme="dark"] .dash-game-card__free-badge {
    background: #064e3b;
    color: #6ee7b7;
}

.dash-game-card__name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-heading);
    margin-bottom: 0.25rem;
}

.dash-game-card__stats {
    font-size: 1.2rem;
    font-weight: 300;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.dash-game-card__bar {
    width: 100%;
    height: 5px;
    background: var(--progress-bg, #e5e7eb);
    border-radius: 999px;
    overflow: hidden;
}

.dash-game-card__bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.3s ease;
}

/* ---- Responsive: Mobile ---- */
@media (max-width: 768px) {
    .dash-sidebar {
        display: none !important;
    }

    .dash-mobile-nav {
        display: flex !important;
    }

    .dash-content {
        padding: 1rem;
    }

    .dash-layout {
        flex-direction: column;
        min-height: auto;
    }

    .dash-section-title {
        font-size: 1.3rem;
    }

    .dash-games-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 0.75rem;
    }
}

/* ---- Responsive: Tablet (768-1024) ---- */
@media (min-width: 769px) and (max-width: 1024px) {
    .dash-sidebar {
        width: 200px;
        min-width: 200px;
    }

    .dash-menu-item__desc {
        display: none;
    }

    .dash-content {
        padding: 1rem 1.5rem;
    }

    /* Header: compact for tablets */
    .app-header { padding: 0.35rem 0.6rem; gap: 0.35rem; }
    .brand__name { font-size: 0.95rem; }
    .brand__dot { display: none; }
    .brand__section { font-size: 0.8rem; }
    .score-pill { padding: 0.2rem 0.5rem; font-size: 0.8rem; }
    .score-pill .text-2xl { font-size: 1.1rem !important; }
    #go-premium-btn { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
    .header-util-btn { font-size: 0.7rem; padding: 0.2rem 0.4rem; height: 26px; }
    .user-box { font-size: 0.8rem; }
    .music-player-compact { padding: 2px 5px; height: 26px; }
    .music-player-compact .mp-btn { width: 20px; height: 20px; font-size: 0.8rem; }
    .music-player-compact .mp-volume { width: 40px; }
    .music-player button { width: 22px; height: 22px; font-size: 0.8rem; }
    .music-player__volume { width: 40px; }
    .music-player { padding: 2px 5px; }
}

/* --- 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 > .landing-nav { position: sticky; top: 0; z-index: 50; }
#auth-screen > .relative { 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); }

/* ==========================================================================
   5.1 LANDING PAGE — FLOATING SIDEBAR & MOBILE NAV
   ========================================================================== */

/* --- Sticky Top Navbar --- */
.landing-nav {
  position: sticky !important;
  top: 0;
  z-index: 50 !important;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(15, 23, 42, 0.85) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  overflow: visible; /* allow dropdown to overflow */
}

/* --- Hamburger Button (hidden on desktop) --- */
.landing-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  min-height: 38px;
  min-width: 38px;
  flex-shrink: 0;
  color: rgba(255,255,255,0.9);
  transition: background 0.2s, border-color 0.2s;
}
html[data-theme="light"] .landing-hamburger {
  background: rgba(0,0,0,0.04);
  border-color: rgba(0,0,0,0.18);
  color: rgba(30,41,59,0.85);
}
.landing-hamburger:hover {
  background: rgba(255,255,255,0.16);
  border-color: rgba(255,255,255,0.4);
}
html[data-theme="light"] .landing-hamburger:hover {
  background: rgba(0,0,0,0.09);
  border-color: rgba(0,0,0,0.28);
}
.landing-hamburger .ham-line {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: transform 0.25s ease, opacity 0.2s ease;
}
.landing-hamburger.open .ham-line:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.landing-hamburger.open .ham-line:nth-child(2) { opacity: 0; transform: scaleX(0); }
.landing-hamburger.open .ham-line:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
/* Label shown at 1024-1286px */
.landing-hamburger .ham-label {
  display: none;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
}
@media (min-width: 1024px) and (max-width: 1286px) {
  .landing-hamburger { padding: 5px 10px; gap: 3px; min-height: 42px; }
  .landing-hamburger .ham-label { display: block; }
}

/* --- Mobile Dropdown (under nav row) --- */
.landing-dropdown {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}
.landing-dropdown.open {
  max-height: 420px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
html[data-theme="light"] .landing-dropdown.open {
  border-top-color: rgba(0,0,0,0.06);
}
.landing-dropdown-inner {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.6rem 1rem 0.8rem;
}
.landing-dropdown .nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s;
}
.landing-dropdown-actions {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.65rem;
  margin-top: 0.4rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}
html[data-theme="light"] .landing-dropdown-actions {
  border-top-color: rgba(0,0,0,0.06);
}
html[data-theme="light"] .landing-nav {
  background: rgba(255, 255, 255, 0.92) !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.06);
}

/* --- Desktop Nav Links Container --- */
.landing-nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* --- Each Nav Link --- */
.landing-nav-links .nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  text-decoration: none;
  color: rgba(148, 163, 184, 0.85);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  white-space: nowrap;
}
html[data-theme="light"] .landing-nav-links .nav-link {
  color: rgba(71, 85, 105, 0.7);
}

/* Nav link hover */
.landing-nav-links .nav-link:hover {
  background: rgba(14, 165, 233, 0.1);
  color: #38bdf8;
}
html[data-theme="light"] .landing-nav-links .nav-link:hover {
  background: rgba(14, 165, 233, 0.07);
  color: #0284c7;
}

/* Nav link active — highlighted with bottom indicator */
.landing-nav-links .nav-link.active {
  color: #38bdf8;
  background: rgba(14, 165, 233, 0.12);
}
.landing-nav-links .nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 20%;
  right: 20%;
  height: 3px;
  border-radius: 3px;
  background: #0ea5e9;
  box-shadow: 0 0 8px rgba(14, 165, 233, 0.5);
}
html[data-theme="light"] .landing-nav-links .nav-link.active {
  color: #0284c7;
  background: rgba(14, 165, 233, 0.08);
}
html[data-theme="light"] .landing-nav-links .nav-link.active::after {
  background: #0284c7;
  box-shadow: 0 0 8px rgba(2, 132, 199, 0.3);
}

/* Contact link green accent */
.landing-nav-links .nav-link-contact:hover {
  background: rgba(16, 185, 129, 0.1);
  color: #34d399;
}
html[data-theme="light"] .landing-nav-links .nav-link-contact:hover {
  background: rgba(16, 185, 129, 0.07);
  color: #059669;
}

/* --- Login Button in Nav --- */
.nav-login-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: #fff;
  box-shadow: 0 3px 14px rgba(14, 165, 233, 0.3);
  transition: all 0.25s ease;
  white-space: nowrap;
}
.nav-login-btn:hover {
  box-shadow: 0 5px 22px rgba(14, 165, 233, 0.5);
  transform: translateY(-1px);
  background: linear-gradient(135deg, #38bdf8, #818cf8);
}

/* --- Register Button in Nav --- */
.nav-register-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #8b5cf6, #a855f7);
  color: #fff;
  box-shadow: 0 3px 14px rgba(139, 92, 246, 0.3);
  transition: all 0.25s ease;
  white-space: nowrap;
}
.nav-register-btn:hover {
  box-shadow: 0 5px 22px rgba(139, 92, 246, 0.5);
  transform: translateY(-1px);
  background: linear-gradient(135deg, #a78bfa, #c084fc);
}

/* --- Mobile Bottom Navigation Bar --- */
.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 60;
  display: none;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  background: rgba(15, 23, 42, 0.92);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.3);
}
html[data-theme="light"] .mobile-bottom-nav {
  background: rgba(255, 255, 255, 0.93);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.06);
}

.mobile-bottom-nav-inner {
  display: flex;
  justify-content: space-around;
  align-items: center;
  max-width: 520px;
  margin: 0 auto;
  
  padding: 0 8px;
}

.mobile-bottom-nav a,
.mobile-bottom-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 10px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(148, 163, 184, 0.8);
  transition: all 0.2s ease;
  min-width: 58px;
}
html[data-theme="light"] .mobile-bottom-nav a,
html[data-theme="light"] .mobile-bottom-nav button {
  color: rgba(71, 85, 105, 0.6);
}

.mobile-bottom-nav a .mob-icon,
.mobile-bottom-nav button .mob-icon {
  font-size: 24px;
  line-height: 1;
}

.mobile-bottom-nav a.active {
  color: #38bdf8;
}
html[data-theme="light"] .mobile-bottom-nav a.active {
  color: #0284c7;
}

/* Mobile login CTA */
.mobile-bottom-nav .mob-login-btn {
  background: linear-gradient(135deg, #0ea5e9, #6366f1) !important;
  color: #fff !important;
  border-radius: 16px !important;
  padding: 8px 16px !important;
  box-shadow: 0 4px 16px rgba(14, 165, 233, 0.35);
  font-size: 16px !important;
  min-width: 64px;
}
.mobile-bottom-nav .mob-login-btn .mob-icon { font-size: 20px; }

/* ==========================================================================
   DASHBOARD HEADER
   ≥1291px : 4-col grid — brand | stats | tools | profile (all one row)
   769–1290px: 3-col grid, toggle visible; tools expand as second row
   ≤768px  : flex-wrap 2-row, stats row scrolls horizontally, tools hidden
   ========================================================================== */

/* ── Util group (direct grid child of .app-header) ──
   Wide: grid-area "util" (column 3, row 1) — inline with stats
   ──────────────────────────────────────────────────────────── */
#app-util-group {
  grid-area: util;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: nowrap;
  padding: 0 0.5rem;
  min-width: 0;
  border-inline-start: 1px solid var(--border); /* subtle separator from stats */
}

/* Buttons inside util group */
#app-util-group .header-util-btn {
  height: 34px;
  font-size: 0.82rem;
  padding: 0 0.75rem;
  gap: 5px;
  border-radius: 10px;
  background: var(--surface);
  white-space: nowrap;
  flex-shrink: 0;
}
#app-util-group .header-util-btn:hover {
  background: rgba(99, 102, 241, 0.08);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.1);
}
#app-util-group .btn-label { display: inline !important; }

/* Close button — hidden on wide screens */
.util-panel-close { display: none !important; }

/* ── Toggle button (אפשרויות נוספות) — hidden on wide screens ── */
.app-util-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(99,102,241,0.08), rgba(99,102,241,0.04));
  border: 1px solid rgba(99,102,241,0.2);
  color: var(--primary-600, #4f46e5);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.25s ease;
  box-shadow: 0 1px 4px rgba(99,102,241,0.08);
}
.app-util-toggle:hover {
  background: linear-gradient(135deg, rgba(99,102,241,0.14), rgba(99,102,241,0.08));
  box-shadow: 0 3px 10px rgba(99,102,241,0.15);
  transform: translateY(-1px);
}
.app-util-toggle.open {
  background: var(--primary-500, #6366f1);
  color: #fff;
  border-color: var(--primary-600, #4f46e5);
  box-shadow: 0 2px 8px rgba(99,102,241,0.3);
}
.toggle-icon { font-size: 0.9rem; line-height: 1; }
.app-util-label { font-size: 0.78rem; }
.toggle-chevron {
  font-size: 0.65rem;
  transition: transform 0.25s ease;
  line-height: 1;
}
.app-util-toggle.open .toggle-chevron { transform: rotate(180deg); }

/* ── Compact profile area ── */
@media (max-width: 1200px) {
  #reset-progress-button { display: none; }
  .brand__section { display: none; }
  .brand__dot { display: none; }
}

/* Hide tool labels at tighter wide widths to prevent overflow */
@media (max-width: 1450px) and (min-width: 1291px) {
  #app-util-group .btn-label { display: none !important; }
  #app-util-group .header-util-btn { padding: 0 0.5rem; }
  #app-util-group { gap: 0.3rem; }
}

/* Fullscreen button: icon only at ≤1290px */
@media (max-width: 1290px) {
  #header-fullscreen-btn #fullscreen-label { display: none !important; }
  #header-fullscreen-btn { margin-left: 0 !important; padding: 4px 6px !important; }
}

/* Home button in center column — always visible */
.home-btn {
  flex-shrink: 0;
  white-space: nowrap;
}

/* At tight medium widths, compact items */
@media (max-width: 950px) {
  .brand__name { display: none; }
  .home-btn .btn-label { display: none !important; }
  .home-btn { padding: 0 0.45rem !important; }
}

/* ═══════════════════════════════════════════════════════════════
   MEDIUM (769–1290px): 3-col grid, tools expand as second row
   Brand and right get auto width; center (stats) fills remaining.
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 1290px) {
  .app-header {
    /* auto = natural width for brand/right; 1fr = stats fill remainder */
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "brand center right";
  }

  /* Show toggle */
  .app-util-toggle { display: flex; }

  /* Util-group: full-width row 2, collapsed by default */
  #app-util-group {
    grid-area: 2 / 1 / auto / -1;
    justify-content: center;
    align-items: center;
    padding: 0 1rem;
    max-height: 0;
    overflow: hidden;
    border-top: 0 solid var(--border);
    border-inline-start: none;
    background: var(--card-bg);
    transition: max-height 0.28s ease, padding 0.28s ease, border-top 0.15s;
  }

  /* Expanded state */
  .app-header.util-open #app-util-group {
    max-height: 60px;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--border);
  }

  /* Close button in expanded row */
  .util-panel-close {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--border);
    font-size: 0.8rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
  }
  .util-panel-close:hover { background: rgba(239,68,68,0.1); color: #ef4444; border-color: #ef4444; }

  /* Labels visible in the expanded row */
  #app-util-group .btn-label { display: inline !important; }

  /* ── Header right-side compaction at ≤1290px ──
     The reset button and a wide upgrade button would overflow the right
     column when the util-toggle is also visible.  Hide reset and shrink
     the premium CTA so the row stays on a single line. */
  #reset-progress-button { display: none !important; }
  #go-premium-btn {
    font-size: 0.72rem !important;
    padding: 0.2rem 0.5rem !important;
    white-space: nowrap;
  }
}

/* At tighter medium widths: compact the toggle button — icon only */
@media (max-width: 950px) and (min-width: 769px) {
  .app-util-toggle .app-util-label { display: none; }
  .app-util-toggle .toggle-chevron { display: none; }
  .app-util-toggle { padding: 0 10px; min-width: 36px; justify-content: center; }
  .app-util-toggle .toggle-icon { font-size: 1.1rem; }
  /* Also compact the user-box */
  .user-box .reset-btn { display: none; }
  .logout-link { font-size: 0.7rem; }
}

/* ── Premium modal: compact for screens that can't fit the full 850px design ── */
@media (max-width: 1400px) {
  /* Prevent the modal from taller-than-viewport overflow.
     The backdrop already centers via flex; adding max-height + overflow-y
     makes the modal independently scrollable when the viewport is short. */
  .premium-modal-redesign {
    max-height: 90vh    !important;
    overflow-y: auto    !important;
    /* override the inline overflow:hidden so the scroll bar can appear */
    overflow-x: hidden  !important;
  }

  /* Tighten the header section */
  .premium-modal-redesign .premium-modal-header {
    padding: 1.25rem 1.5rem !important;
  }
  .premium-modal-redesign .premium-modal-title,
  #premium-title {
    font-size: 1.9rem !important;
  }
  .premium-modal-redesign .premium-modal-desc {
    font-size: 0.95rem !important;
  }

  /* Tighten the plan cards grid */
  #premium-modal-body {
    padding: 1.25rem 1.5rem !important;
  }
}

/* At the exact 1280px problem zone, squeeze just a touch more */
@media (max-width: 1300px) {
  .premium-modal-redesign .premium-modal-header { padding: 1rem 1.25rem !important; }
  .premium-modal-redesign .premium-modal-title, #premium-title { font-size: 1.6rem !important; }
  #premium-modal-body { padding: 1rem 1.25rem !important; }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE (≤768px): flex-wrap 2-row
   Row 1: Brand | Profile; Row 2: Stats scrollable; tools hidden
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .app-header {
    display: flex !important;
    flex-wrap: wrap !important;
    padding: 0.4rem 0.75rem 0 !important;
    gap: 0 !important;
    min-height: auto !important;
  }
  .app-header__brand {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    overflow: hidden !important;
    padding-bottom: 0.4rem !important;
  }
  .app-header__right {
    flex: 0 0 auto !important;
    flex-wrap: nowrap !important;
    gap: 0.3rem !important;
    padding-bottom: 0.4rem !important;
  }
  .app-header__center {
    flex: 0 0 100% !important;
    justify-content: flex-start !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    border-top: 1px solid var(--border) !important;
    padding: 0.4rem 0.5rem !important;
    gap: 0.4rem !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .app-header__center::-webkit-scrollbar { display: none; }
  /* Hide toggle and tools on mobile */
  .app-util-toggle { display: none !important; }
  #app-util-group { display: none !important; }
  #main-app-screen .app-shell { padding-bottom: 0 !important; }
}

/* ==========================================================================
   ACHIEVEMENTS GRID — responsive column layout
   Breakpoints:
     ≥1400px  →  3 columns  (Tailwind lg:grid-cols-3, no override)
     1024–1399px  →  2 columns
     ≤1023px  →  1 column  (sidebar + narrow viewport can't fit 2)
   ========================================================================== */

/* Prevent grid items from overflowing their track (RTL clipping fix) */
.achievements-container .grid > * {
  min-width: 0;
}

/* 2 columns: 1024px–1399px */
@media (max-width: 1399px) {
  .achievements-container .grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* Compact card style at narrower widths */
@media (max-width: 1280px) {
  .achievements-container .achievement-card {
    padding: 1rem;
    gap: 1rem;
  }
  .achievement-card .achievement-icon {
    width: 64px;
    height: 64px;
    font-size: 2.2rem;
  }
}

/* 1 column: ≤1023px — sidebar makes 2-col overflow/clip at these widths */
@media (max-width: 1023px) {
  .achievements-container .grid {
    grid-template-columns: 1fr !important;
  }
  .achievements-container .achievement-card {
    padding: 1.25rem;
    gap: 1.25rem;
  }
  .achievement-card .achievement-icon {
    width: 56px;
    height: 56px;
    font-size: 2rem;
  }
}

/* --- Responsive visibility --- */
@media (max-width: 1286px) {
  .landing-nav-links { display: none !important; }
  .nav-login-btn, .nav-register-btn { display: none !important; }
  /* Keep dropdown auth buttons visible */
  .landing-dropdown-actions .nav-login-btn,
  .landing-dropdown-actions .nav-register-btn { display: inline-flex !important; }
  .landing-hamburger { display: flex !important; }
  .mobile-bottom-nav { display: none !important; }
  #auth-screen { padding-bottom: 0; }
}
@media (min-width: 1289px) {
  .landing-nav-links { display: flex !important; }
  .landing-hamburger { display: none !important; }
  .landing-dropdown { display: none !important; }
  .mobile-bottom-nav { display: none !important; }
}

/* --- Hide landing menus when app screen is active (user logged in) --- */
#auth-screen.hidden ~ .mobile-bottom-nav,
#main-app-screen:not(.hidden) ~ .mobile-bottom-nav {
  display: none !important;
}
#auth-screen.hidden .landing-nav,
#auth-screen.hidden .mobile-bottom-nav {
  display: none !important;
}

/* ==========================================================================
   5.2 LANDING PAGE — DASHBOARD-STYLE SECTION CARDS
   ========================================================================== */

.dash-section-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transition: all var(--transition-normal);
}

/* ==========================================================================
   5.3 LANDING PAGE — SCIENTIFIC AUTO-ROTATING SLIDESHOW
   ========================================================================== */

.sci-slideshow {
  position: relative;
  width: 100%;
  overflow: hidden;
  min-height: 340px;
}

.sci-slides-track {
  position: relative;
  width: 100%;
  min-height: 300px;
}

.sci-slide {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  opacity: 0;
  transform: translateY(18px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}
.sci-slide.active {
  position: relative;
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  z-index: 2;
}

.sci-slide-inner {
  display: flex;
  align-items: center;
  gap: 40px;
  padding: 20px 0;
}

.sci-slide-visual {
  flex: 0 0 220px;
  height: 220px;
  border-radius: var(--radius-2xl);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.5rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.sci-slide-visual::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 0.15;
}

.sci-slide-content {
  flex: 1;
  min-width: 0;
}
.sci-slide-content .sci-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(14, 165, 233, 0.12);
  color: var(--primary-400);
  border: 1px solid rgba(14, 165, 233, 0.2);
  margin-bottom: 12px;
}
.sci-slide-content h3 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 10px;
  color: var(--text-primary);
}
.sci-slide-content p {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

/* Slide Navigation Dots */
.sci-slide-nav {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}
.sci-dot {
  width: 32px;
  height: 6px;
  border-radius: 999px;
  background: var(--secondary-300);
  transition: all 0.3s ease;
  cursor: pointer;
  border: none;
  padding: 0;
}
html[data-theme="dark"] .sci-dot {
  background: var(--secondary-600);
}
.sci-dot.active {
  background: var(--primary-500) !important;
  width: 48px;
}
.sci-dot:hover:not(.active) {
  background: var(--secondary-400);
}

/* Progress bar */
.sci-progress-bar {
  width: 120px;
  height: 3px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  margin: 12px auto 0;
  overflow: hidden;
}
.sci-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary-500);
  border-radius: 999px;
}

/* Responsive slideshow */
@media (max-width: 768px) {
  .sci-slide-inner {
    flex-direction: column;
    text-align: center;
    gap: 20px;
  }
  .sci-slide-visual {
    flex: 0 0 160px;
    width: 160px;
    height: 160px;
    margin: 0 auto;
    font-size: 2.8rem;
  }
  .sci-slide-content h3 {
    font-size: 1.25rem;
  }
  .sci-slideshow {
    min-height: 420px;
  }
}

/* ==========================================================================
   5.4 LANDING PAGE — NAV ACTION BUTTONS (Bookmark / Shortcut)
   ========================================================================== */

/* Toast animation */
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ==========================================================================
   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; flex-shrink: 0;
    display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--border);
}
.achievement-card .achievement-content,
.achievement-card .achievement-details {
    flex: 1;
    min-width: 0;
    /* Guarantee text never collapses to a single-character column */
    min-width: 120px;
}
.achievement-card .achievement-name {
    font-weight: 700; color: var(--text-heading); font-size: 1.1rem;
    overflow-wrap: break-word; word-break: break-word;
}
.achievement-card .achievement-desc {
    color: var(--text-muted); font-size: 0.9rem;
    overflow-wrap: break-word; word-break: break-word;
}
.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%; max-width: 100%; background: var(--surface); border-radius: var(--radius-xl);
    border: 2px solid var(--border); transition: all var(--transition-normal); overflow: hidden; box-sizing: border-box;
}

/* --- 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 --- */
/* Global safety rule: board never overflows its container on ANY screen size.
   calc(100% - 8px) resolves against the *actual* container width (not the
   viewport), so it handles Tailwind's responsive container max-widths correctly
   (e.g. the md breakpoint caps app-shell at 768 px for 769–1023 px viewports).
   !important overrides any JS inline-style that might compute a larger value. */
#memory-game-board {
    max-width: min(calc(100% - 8px), calc(100vw - 32px)) !important;
    box-sizing: border-box;
    overflow: hidden;
}
.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; box-sizing: border-box; }
.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; width: 100%; box-sizing: border-box; }
.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; }

/* --- High Saturation Mode --- */
html.acc-high-saturation { filter: saturate(2); }

/* --- 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: 2px 5px; }
    .music-player button { width: 24px; height: 24px; font-size: 0.85rem; }
    .music-player__volume { width: 35px; }
    .header-guide-btn__text { 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
   ========================================================================== */
/* --- Guide Button --- */
.header-guide-btn {
    background: none;
    border: 1px solid var(--border);
    cursor: pointer;
    border-radius: 8px;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text);
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}
.header-guide-btn:hover {
    border-color: var(--primary-500);
    background: rgba(99,102,241,0.08);
}
.header-guide-btn__icon { font-size: 1rem; }

/* --- Compact Music Player (Refactored) --- */
.music-player-compact {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
    direction: ltr;
    flex-shrink: 0;
    height: 32px;
}
.music-player-compact .mp-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-heading);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
    padding: 0;
    flex-shrink: 0;
}
.music-player-compact .mp-btn:hover {
    background: var(--secondary-200);
}
html[data-theme="dark"] .music-player-compact .mp-btn:hover {
    background: var(--secondary-600);
}
.music-player-compact .mp-divider {
    width: 1px;
    height: 14px;
    background: var(--border);
    margin: 0 2px;
    flex-shrink: 0;
}
.music-player-compact .mp-volume {
    width: 50px;
    height: 3px;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 2px;
    background: var(--secondary-300);
    outline: none;
    -webkit-appearance: none;
}
.music-player-compact .mp-volume::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary-500);
    cursor: pointer;
}

/* --- Legacy Music Player (kept for compatibility) --- */
.music-player {
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--card-bg);
    padding: 3px 6px;
    border-radius: 999px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
    direction: ltr;
    flex-shrink: 0;
}
.music-player__divider {
    width: 1px;
    height: 14px;
    background: var(--border);
    margin: 0 1px;
}
.music-player button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-heading);
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
    padding: 0;
    flex-shrink: 0;
}
.music-player button:hover {
    background: var(--secondary-200);
}
html[data-theme="dark"] .music-player button:hover {
    background: var(--secondary-600);
}
.music-player__volume {
    width: 50px;
    height: 3px;
    cursor: pointer;
    flex-shrink: 0;
}

#music-volume-slider {
    height: 3px;
    border-radius: 2px;
    background: var(--secondary-300);
    outline: none;
    -webkit-appearance: none;
    cursor: pointer;
}
#music-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary-500);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

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

/* --- FAQ Accordion --- */
#faq-section details summary { list-style: none; }
#faq-section details summary::-webkit-details-marker { display: none; }
#faq-section details summary::marker { display: none; }
#faq-section details[open] summary { border-bottom: 1px solid var(--border); }
#faq-section details > div {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease, padding 0.35s ease;
}
#faq-section details[open] > div {
    max-height: 300px;
}

/* ==========================================================================
   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"] .streak-pill,
[data-theme="dark-bold"] .music-player-compact,
[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: CSS zoom on <html> scales everything (px, rem, inline styles).
   The zoom enlarges the CSS coordinate system so body at width:100% naturally
   fills the viewport after zoom.  The global "max-width:100vw" on html & body
   uses the REAL viewport which is too narrow inside the zoomed coordinate
   system, so we lift it.  Inner containers now use max-width:100% (parent-
   relative) so they adapt automatically and keep their Tailwind max-widths. */
html.acc-scale-75  { zoom: 0.75 !important; }
html.acc-scale-90  { zoom: 0.90 !important; }
html.acc-scale-115 { zoom: 1.15 !important; }
html.acc-scale-125 { zoom: 1.25 !important; }

/* Only html & body need the 100vw cap lifted for zoom-down */
html.acc-scale-75,
html.acc-scale-75 > body,
html.acc-scale-90,
html.acc-scale-90 > body { max-width: none !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;
  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
   ========================================================================== */

.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 (legacy overrides removed — see section 11 for compact player)
   ========================================================================== */
[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); } }

/* ==========================================================================
   14.9  TOUCH & POINTER UX — eliminates 300ms tap delay, kills iOS blue flash
   Applies globally so every interactive element responds instantly on
   mobile/tablet. touch-action:manipulation tells the browser we handle
   our own panning/zooming — no double-tap wait needed.
   ========================================================================== */
button, a[href], [role="button"],
input[type="button"], input[type="submit"],
.btn, .nav-link, .modal-close,
.dash-mobile-tab, .dash-menu-item,
.choice-btn, .nback-btn, .vnm-btn,
.trail-node, .app-util-toggle,
.landing-hamburger, label.theme-toggle {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
/* Prevent accidental text-selection on game areas during swipe/tap */
.game-board, .perception-game-area, .trail-making-area,
.nback-grid, .serial-memory-container, .pr-grid,
.sf-sequence-display, .sf-symbol-choices, .oi-game-area {
    user-select: none;
    -webkit-user-select: none;
}

/* ==========================================================================
   15. MOBILE RESPONSIVE — SMALL SCREENS (≤ 480px)
   Appended at the end so all rules safely override desktop styles.
   Strategy: "mobile-tolerable" — everything visible, scrollable, usable.
   ========================================================================== */

/* ---------- 15.0  GLOBAL MOBILE OVERFLOW FIX ---------- */
/* Prevents the PAGE from scrolling horizontally.
   Using 'clip' (not 'hidden') so that child scroll containers
   (e.g. the mobile tab bar) are NOT blocked by the parent.
   'hidden' creates a scroll container on the element, which on iOS WebKit
   intercepts touch events and prevents child overflow-x:scroll from working. */
html, body {
    max-width: 100vw;
    overflow-x: clip !important;  /* clip ≠ hidden: no scroll-container, children can scroll.
                                     !important beats any Tailwind utility class (e.g. overflow-x-hidden) */
}
.app-shell, #main-app-screen, .dashboard-container,
.app-header, .toolbar, #main-content-area,
.app-header__left, .app-header__right {
    max-width: 100%;
    overflow-x: clip;
    box-sizing: border-box;
}
/* Tailwind container override on mobile */
@media (max-width: 768px) {
    .container { max-width: 100% !important; padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
    .app-shell.container { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
    [class*="px-4"] { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
    /* Prevent Tailwind min-height from blocking scroll */
    [class*="min-h-["] { min-height: auto !important; }
}

/* ---------- 15.1  Tablet Tweaks (≤ 768px) — extends existing rules ---------- */
@media (max-width: 768px) {

    /* Base font trim */
    html { font-size: 16px !important; }

    /* ===== HEADER FIX: wrap items, prevent overflow ===== */
    .app-header {
        padding: 0.4rem 0.75rem;
        gap: 0.4rem;
        flex-wrap: wrap;
    }
    /* Left side (brand) — shrink to fit */
    .app-header__left {
        flex: 0 1 auto;
        min-width: 0;
        overflow: hidden;
    }
    .brand {
        flex-wrap: nowrap;
        overflow: hidden;
        white-space: nowrap;
    }
    .brand__name { font-size: 0.95rem; }
    .brand__icon { font-size: 1.1rem; }
    .brand__dot { display: none; }
    .brand__section { display: none; }

    /* Right side — wrap into rows */
    .app-header__right {
        flex: 1 1 auto;
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 0.35rem;
        min-width: 0;
    }
    .app-header__center { gap: 0.35rem; }
    .streak-pill { padding: 0.2rem 0.45rem; }
    .streak-fire { font-size: 0.9rem; }
    .streak-count { font-size: 0.95rem; }
    .streak-label { font-size: 0.6rem; }
    .score-pill { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
    .header-util-btn { font-size: 0.7rem; padding: 0.2rem 0.4rem; height: 28px; }
    .music-player-compact { padding: 2px 6px; height: 28px; }
    .music-player-compact .mp-btn { width: 20px; height: 20px; font-size: 0.75rem; }
    .music-player-compact .mp-volume { width: 35px; }
    .user-box { font-size: 0.85rem; }
    .logout-link { font-size: 0.75rem; }
    .reset-btn { display: none; } /* Hide reset on mobile — use settings instead */

    /* Music player: compact */
    #music-player-container {
        margin-left: 0.25rem !important;
        padding: 0.3rem 0.5rem;
        order: 5;
    }

    /* Toolbar: wrap nicely */
    .toolbar {
        flex-direction: column;
        padding: 0.5rem;
        gap: 0.5rem;
        margin: 0.5rem 0.5rem 0.75rem;
    }
    .toolbar__left, .toolbar__right {
        width: 100%;
        justify-content: center;
    }

    /* Dashboard */
    .dashboard-container {
        padding: 0 0.5rem;
        gap: 1rem;
    }
    .dashboard-section {
        padding: 1rem;
        border-radius: var(--radius-xl);
    }
    .dashboard-title {
        font-size: 1.25rem;
        margin-bottom: 0.75rem;
    }

    /* Stats & game grids: 2-col on tablets, 1-col handled below */
    .stats-grid, .dashboard-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 0.75rem;
    }
    .stat-card {
        padding: 1rem;
        min-height: 100px;
    }

    /* Game areas: respect screen width */
    .game-board {
        max-width: 100%;
        padding: 0.6rem;
        gap: 0.5rem;
    }
    .game-board.cols-5 { max-width: 100%; gap: 0.4rem; }
    .game-board.cols-6 { max-width: 100%; gap: 0.35rem; }

    .perception-game-area,
    .trail-making-area,
    .oi-game-area,
    .track-switcher-area {
        height: 55vw;
        min-height: 260px;
        max-height: 400px;
    }
    .quantitative-game-area {
        height: 45vw;
        min-height: 200px;
        max-height: 300px;
    }
    .ss-game-area, .tt-game-container {
        height: auto;
        min-height: 200px;
    }

    /* Trail nodes & game pieces: smaller */
    .trail-node { width: 40px; height: 40px; font-size: 1.15rem; border-width: 2px; }
    .station { width: 30px; height: 30px; }
    .station::before { font-size: 16px; }
    .switch { width: 24px; height: 24px; }
    .train { width: 18px; height: 18px; }
    .train::before { font-size: 13px; }
    .balloon { min-width: 40px; min-height: 40px; }

    /* Memory cards */
    .front-face { font-size: 1.8rem; }
    .back-face img { width: 80%; height: 80%; }

    /* N-Back */
    .nback-grid { width: 260px; height: 260px; padding: 1rem; gap: 0.75rem; }

    /* Serial Memory */
    .serial-memory-container { width: 240px; height: 240px; gap: 1rem; }

    /* Pattern Recognition */
    .pr-grid { width: 240px; height: 240px; gap: 0.75rem; }

    /* Sequence Forge */
    .sf-sequence-display { gap: 0.5rem; padding: 0.75rem; }
    .symbol-slot { width: 45px; height: 45px; font-size: 1.5rem; }
    .sf-symbol-choices { gap: 0.5rem; }
    .symbol-btn { width: 55px; height: 55px; font-size: 2rem; }

    /* Buttons */
    .btn { padding: 0.6rem 1rem; font-size: 0.9rem; }
    .btn-sm { padding: 0.4rem 0.65rem; font-size: 0.8rem; }
    .choice-btn { width: 80px; padding: 0.6rem 1rem; }
    .nback-btn, .vnm-btn { padding: 0.6rem 1rem; }

    /* Modals: near-full-width, override inline styles */
    .modal-backdrop {
        padding: 0.5rem;
        align-items: center;
        justify-content: center;
    }
    .modal-content {
        max-width: 95vw !important; /* Override inline style="max-width: 450px" */
        width: 95vw !important;
        padding: 1.25rem;
        max-height: 85vh;
        overflow-y: auto;
        border-radius: var(--radius-xl);
        margin: 0 auto;
        box-sizing: border-box;
    }

    /* In-page content modals (chess difficulty, game results, etc.) */
    #main-content-area .flex.gap-4,
    #main-content-area .flex.gap-3 {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.75rem;
    }
    #main-content-area .flex.gap-4 > button,
    #main-content-area .flex.gap-3 > button {
        flex: 1 1 40%;
        min-width: 120px;
        max-width: 200px;
    }

    /* App shell: prevent content from being pushed to side */
    .app-shell {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }

    /* Level path */
    .levels-container {
        gap: 0.5rem;
        padding: 0.5rem;
    }
    .level-node { width: 44px; height: 44px; font-size: 1rem; }
    .level-connector { display: none; }

    /* Overview grid */
    .overview-grid { grid-template-columns: 1fr; gap: 1rem; }
    .overview-card { min-height: auto; padding: 1rem; }

    /* Actions grid */
    .dashboard-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }
    .personalized-btn { padding: 1rem; }
    .personalized-btn .text-lg { font-size: 1rem; }
    .personalized-btn .text-sm { font-size: 0.8rem; }

    /* Hero / Landing */
    .hero-title { font-size: 2rem; }
    .hero-subtitle { font-size: 1rem; }
    .feature-card { padding: 1.25rem; }
    .feature-card h3 { font-size: 1.2rem; }

    /* Music player */
    .music-player { padding: 2px 4px; }
    .music-player button { width: 22px; height: 22px; font-size: 0.8rem; }
    .music-player__volume { width: 30px; }
    .music-player__divider { height: 10px; }
    .header-guide-btn { padding: 3px 5px; font-size: 0.7rem; }
    .header-guide-btn__text { display: none; }

    /* AI Coach */
    .ai-coach-container { bottom: 12px; right: 12px; }
    .ai-coach-toggle { width: 52px; height: 52px; font-size: 1.6rem; border-width: 3px; }
    .ai-coach-window {
        width: calc(100vw - 24px);
        max-width: 350px;
        right: 0;
        bottom: 70px;
        height: 60vh;
        max-height: 420px;
        border-radius: var(--radius-xl);
    }
    .ai-coach-messages { padding: 0.75rem; gap: 0.5rem; }
    .ai-coach-message { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
    .ai-coach-options { gap: 0.35rem; }
    .ai-coach-options button { padding: 0.35rem 0.6rem; font-size: 0.75rem; }
    #ai-coach-input-field { padding: 0.5rem 0.75rem; font-size: 0.85rem; }
    #ai-coach-send { width: 36px; height: 36px; }

    /* Accessibility widget */
    .acc-widget { bottom: 12px; left: 12px; }
    .acc-toggle-btn { width: 48px; height: 48px; }
    .acc-icon { width: 32px; height: 32px; }
    .acc-menu {
        width: calc(100vw - 32px);
        max-width: 340px;
        bottom: 65px;
        left: -4px;
        padding: 1rem;
    }

    /* Achievement toast */
    .achievement-toast {
        bottom: 10px;
        left: 10px;
        right: 10px;
        padding: 0.75rem 1rem;
        border-radius: var(--radius-lg);
    }
    .achievement-toast__icon { font-size: 2rem; }

    /* Forms */
    .card-auth { padding: 1.5rem; }
    .form-input { padding: 0.7rem 0.85rem; }

    /* Particles: lighter on mobile */
    .particle { opacity: 0.1; }
    [data-theme="dark"] .particle { opacity: 0.4; }
}


/* ---------- 15.2  Phone — Small screens (≤ 480px) ---------- */
@media (max-width: 480px) {

    html { font-size: 15px !important; }

    /* ── Constrain .dash-layout to viewport width ──
       A later ≤480px block sets #main-content-area { align-items: center },
       which makes flex children collapse to their max-content width.
       Without an explicit width, .dash-layout grows wide enough for ALL tabs,
       so .dash-mobile-nav never overflows and overflow-x:scroll has nothing
       to scroll. Forcing width:100% + align-self:stretch fixes this. */
    .dash-layout {
        width: 100% !important;
        align-self: stretch !important; /* defeat align-items:center on parent */
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* ── Mobile tab bar: compact size + working horizontal scroll ──
       Applies to the full 380–480px range.
       The finer breakpoints (≤450px hamburger, ≤380px icon-only) sit
       lower in the file and override specific properties from here. */
    .dash-mobile-nav {
        overflow-x: scroll !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y;
        scrollbar-width: none !important;
        padding: 5px 6px 4px;
        gap: 2px;
        width: 100% !important;   /* also constrain nav directly */
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    .dash-mobile-nav::-webkit-scrollbar { display: none !important; }

    .dash-mobile-tab {
        padding: 5px 9px;
        gap: 1px;
        min-width: 40px;
        flex-shrink: 0; /* never shrink — let the container scroll instead */
    }
    .dash-mobile-tab__icon  { font-size: 1.05rem; }
    .dash-mobile-tab__label { font-size: 0.6rem; font-weight: 600; white-space: nowrap; }

    /* ── Header: single-row compact ─────────────────────────────────────
       Visual order (RTL, right→left): [🐘 logo] [score][streak] [🌙] [☰]
       Technique: brand=order:0 | center=order:1 | theme=order:5 | ham=order:9
       Util rows (order 10/11) still wrap below via flex-wrap:wrap.        */
    .app-header {
        padding: 0.25rem 0.5rem !important;
        gap: 0.3rem !important;
        flex-wrap: wrap;       /* util/user rows still expand below */
        align-items: center;
    }
    /* Brand: icon-only, rightmost (flex-start in RTL) */
    .app-header__brand {
        flex: 0 0 auto !important;
        order: 0 !important;
        padding-bottom: 0 !important;
    }
    .brand { gap: 0.2rem; }
    .brand__name    { display: none !important; }   /* text hidden — icon IS the home link */
    .brand__icon    { height: 20px !important; width: auto !important; }
    .brand__section { display: none !important; }
    /* Stats center: inline (overrides ≤768px flex:0 0 100% full-row) */
    .app-header__center {
        flex: 1 1 auto !important;
        order: 1 !important;
        flex-wrap: nowrap !important;
        border-top: none !important;
        padding: 0 0.2rem !important;
        gap: 0.3rem !important;
        justify-content: flex-start !important;
    }
    .score-pill  { padding: 0.15rem 0.35rem !important; gap: 0.15rem; }
    .streak-pill { padding: 0.12rem 0.3rem  !important; }
    .streak-count{ font-size: 0.82rem; }
    .streak-label{ display: none; }
    .header-util-btn { font-size: 0.65rem; padding: 0.15rem 0.35rem; height: 24px; }

    /* ── App-header score / username — tighter at ≤480px ── */
    .score-pill { font-size: 0.68rem !important; padding: 0.12rem 0.35rem !important; gap: 0.15rem !important; }
    .score-pill > span:first-child { display: none; }  /* hide "נקודות" label — number only */
    /* The big score number inside the pill (.text-2xl Tailwind class) */
    .score-pill .text-2xl { font-size: 1rem !important; line-height: 1.1 !important; }
    #username-display   { font-size: 0.65rem !important; max-width: 55px !important; }
    .logout-link        { font-size: 0.6rem  !important; }
    .streak-pill        { font-size: 0.68rem !important; padding: 0.1rem 0.35rem !important; }
    .streak-count       { font-size: 0.78rem !important; }

    /* ── Hamburger + dropdown: display:contents exposes .app-header__right
       children as direct flex items; individual orders position each one  ── */
    .app-header__right { display: contents; }

    /* Hamburger: far LEFT end of row (order:9 = leftmost in RTL flex) */
    .app-util-toggle {
        order: 9;
        display: flex !important;
        flex-shrink: 0;
        padding: 0 7px !important;
        min-width: 30px !important;
        height: 30px !important;
        justify-content: center;
        align-items: center;
        border-radius: 6px;
    }
    .app-util-toggle .app-util-label { display: none !important; }
    .app-util-toggle .toggle-chevron  { display: none !important; }
    .app-util-toggle .toggle-icon     { font-size: 1rem; }

    /* Theme toggle: between stats and hamburger (order:5); compact track */
    .theme-toggle { order: 5; flex-shrink: 0; }
    .theme-toggle .toggle-track       { width: 32px  !important; height: 19px !important; }
    .theme-toggle .toggle-track::after{ width: 13px  !important; height: 13px !important;
                                        top: 2px     !important; right: 2px   !important; }
    .theme-toggle input:checked + .toggle-track::after { transform: translateX(-13px) !important; }

    /* Reset/progress button: hide on mobile — not critical */
    .reset-btn { display: none !important; }

    /* User-info row: hidden by default; expands as a full-width strip
       beneath the util panel when the hamburger is opened.            */
    #user-info {
        order: 11;
        flex: 0 0 100%;
        display: flex !important;
        justify-content: flex-end;
        align-items: center;
        gap: 0.5rem;
        padding: 0 0.75rem;
        max-height: 0;
        overflow: hidden;
        background: var(--card-bg);
        border-top: 0 solid transparent;
        box-sizing: border-box;
        transition: max-height 0.25s ease, padding 0.2s ease;
    }
    .app-header.util-open #user-info {
        max-height: 44px;
        padding: 0.35rem 0.75rem;
        border-top: 1px solid var(--border);
    }

    /* Util panel: full-width collapsible second row (contact + close) */
    #app-util-group {
        display: flex !important;
        flex: 0 0 100%;
        order: 10;
        flex-wrap: nowrap;
        justify-content: flex-end;
        align-items: center;
        gap: 0.4rem;
        padding: 0 0.75rem;
        max-height: 0;
        overflow: hidden;
        background: var(--card-bg);
        border-top: 0 solid var(--border);
        transition: max-height 0.28s ease, padding 0.25s ease, border-top 0.15s;
    }
    .app-header.util-open #app-util-group {
        max-height: 52px;
        padding: 0.4rem 0.75rem;
        border-top: 1px solid var(--border);
    }
    .util-panel-close {
        display: flex !important;
        align-items: center; justify-content: center;
        width: 24px; height: 24px; border-radius: 50%;
        background: transparent; border: 1px solid var(--border);
        font-size: 0.75rem; cursor: pointer; flex-shrink: 0;
        transition: background 0.2s, color 0.2s;
    }
    .util-panel-close:hover { background: rgba(239,68,68,0.1); color: #ef4444; }
    #app-util-group .btn-label { display: inline !important; }
    #app-util-group .header-util-btn { height: 26px; font-size: 0.68rem; padding: 0 0.45rem; }

    /* ── Game toolbar (in-game stats bar) — tighter at ≤480px ── */
    .toolbar {
        font-size: 0.7rem !important;
        padding: 0.2rem 0.4rem !important;
        gap: 0.2rem !important;
        margin: 0.15rem 0 0.3rem !important;
    }
    .toolbar__left, .toolbar__right { gap: 0.2rem !important; flex-wrap: wrap; }
    /* Stat chips (level, score, game-specific counters) */
    .toolbar .chip {
        font-size: 0.62rem !important;
        padding: 0.15rem 0.4rem !important;
    }
    /* Action buttons inside toolbar (הוראות, דלג, x/y counter) */
    .toolbar .btn,
    .toolbar button {
        font-size: 0.62rem !important;
        padding: 0.18rem 0.38rem !important;
        min-height: unset !important;
        height: auto !important;
    }
    /* Score/timer pills specifically inside the toolbar */
    .toolbar .score-pill,
    .toolbar .timer-pill {
        font-size: 0.65rem !important;
        padding: 0.12rem 0.35rem !important;
    }
    /* Override Tailwind text-size utilities injected by games into the toolbar.
       Games use text-xl/text-2xl for name + timer; these must shrink on mobile
       so the full "Name | Stat | Stat | Timer" bar fits in 1–2 lines.        */
    .toolbar .text-xl,
    .toolbar .text-2xl  { font-size: 0.72rem !important; line-height: 1.2 !important; }
    .toolbar .text-lg   { font-size: 0.68rem !important; line-height: 1.2 !important; }
    .toolbar .text-sm   { font-size: 0.6rem  !important; }
    .toolbar .text-xs   { font-size: 0.58rem !important; }
    /* Tighten injected flex gaps so items compress rather than wrap aggressively */
    .toolbar .gap-4,
    .toolbar .gap-3,
    .toolbar .gap-2 { gap: 0.25rem !important; }

    /* Music player: hide volume on phones */
    .music-player__volume { display: none; }
    .music-player button { width: 20px; height: 20px; font-size: 0.75rem; }
    .music-player__divider { height: 8px; }
    .music-player-compact .mp-volume { display: none; }
    .music-player-compact { padding: 2px 4px; height: 24px; }
    .music-player-compact .mp-btn { width: 18px; height: 18px; font-size: 0.7rem; }
    .header-guide-btn { display: none; }

    /* Dashboard cards: single column */
    .dashboard-container {
        padding: 0 0.35rem;
        gap: 0.75rem;
    }
    .dashboard-section {
        padding: 0.85rem;
        border-radius: var(--radius-lg);
    }
    .dashboard-title {
        font-size: 1.1rem;
        margin-bottom: 0.5rem;
        padding-bottom: 0.5rem;
    }

    /* Force single column everywhere */
    .stats-grid, .dashboard-grid, .stats-grid-4 {
        grid-template-columns: 1fr !important;
        gap: 0.6rem;
    }

    /* Stat cards: horizontal layout on phone */
    .stat-card {
        flex-direction: row;
        text-align: right;
        gap: 0.75rem;
        padding: 0.75rem;
        min-height: auto;
    }
    .stat-card h4 { font-size: 0.9rem; margin-bottom: 0.2rem; }
    .stat-card .text-2xl { font-size: 1.1rem; }
    .stat-card .text-xl { font-size: 1rem; }

    /* Game boards: full width, constrained by viewport */
    .game-board {
        max-width: calc(100vw - 1.5rem);
        gap: 0.35rem;
        padding: 0.5rem;
        border-radius: var(--radius-lg);
    }
    .game-board.cols-5 { gap: 0.3rem; }
    .game-board.cols-6 { gap: 0.25rem; }

    /* Memory cards on small screens */
    .front-face { font-size: 1.5rem; }

    /* Game areas: viewport-based heights */
    .perception-game-area,
    .trail-making-area,
    .oi-game-area {
        height: 65vw;
        min-height: 220px;
        max-height: 340px;
    }
    .quantitative-game-area {
        height: 50vw;
        min-height: 180px;
        max-height: 260px;
    }
    .track-switcher-area {
        height: 60vw;
        min-height: 220px;
        max-height: 320px;
    }

    /* Game elements: further shrink */
    .trail-node { width: 34px; height: 34px; font-size: 1rem; }
    .station { width: 26px; height: 26px; }
    .station::before { font-size: 13px; }
    .switch { width: 20px; height: 20px; }
    .train { width: 16px; height: 16px; }
    .train::before { font-size: 11px; }

    /* N-Back & grids */
    .nback-grid { width: 220px; height: 220px; padding: 0.75rem; gap: 0.5rem; }
    .serial-memory-container { width: 200px; height: 200px; gap: 0.75rem; }
    .pr-grid { width: 200px; height: 200px; gap: 0.5rem; }

    /* Sequence Forge */
    .symbol-slot { width: 38px; height: 38px; font-size: 1.3rem; }
    .symbol-btn { width: 48px; height: 48px; font-size: 1.8rem; }
    .sf-sequence-display { gap: 0.35rem; padding: 0.5rem; }
    .sf-symbol-choices { gap: 0.35rem; }

    /* Buttons: phone-friendly tap targets (min 44px) */
    .btn { padding: 0.6rem 0.85rem; font-size: 0.85rem; min-height: 44px; }
    .choice-btn { width: 70px; min-height: 44px; }
    .nback-btn, .vnm-btn { min-height: 44px; }

    /* Modal: fullscreen-ish */
    .modal-backdrop { padding: 0.35rem; }
    .modal-content {
        max-width: 100% !important;
        width: calc(100vw - 1rem) !important;
        max-height: 90vh;
        padding: 1rem;
        border-radius: var(--radius-lg);
        margin: 0 auto;
        box-sizing: border-box;
    }
    .modal-content h2 { font-size: 1.25rem; }
    .modal-content h3 { font-size: 1.1rem; }

    /* Chess difficulty & game result buttons: stack vertically */
    #main-content-area .flex.gap-4,
    #main-content-area .flex.gap-3 {
        flex-direction: column;
        align-items: center;
        gap: 0.6rem;
    }
    #main-content-area .flex.gap-4 > button,
    #main-content-area .flex.gap-3 > button {
        width: 80%;
        max-width: 220px;
    }

    /* Header: non-essential items hidden on small phones */
    /* (.app-header flex-wrap and padding set above in single-row block) */
    .brand__dot, .brand__section { display: none; }
    .reset-btn { display: none; }
    #go-premium-btn .star-icon { display: none; }
    #go-premium-btn { font-size: 0.7rem; padding: 0.25rem 0.5rem; }
    /* Theme-toggle track sizing already set (compact) in single-row block above */

    /* Level path: wrap into grid */
    .levels-container {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
        gap: 0.4rem;
        padding: 0.5rem;
    }
    .level-node { width: 38px; height: 38px; font-size: 0.85rem; }
    .level-connector { display: none; }
    .level-node.current-level-pulse::after { font-size: 0.6rem; top: -16px; }

    /* Actions grid: single column */
    .personalized-btn {
        padding: 0.85rem;
        border-radius: var(--radius-lg);
    }
    .personalized-btn .text-lg { font-size: 0.9rem; }

    /* Quest section */
    .quest-header { gap: 0.5rem; }
    .quest-description { font-size: 0.95rem; }

    /* Hero / Landing page */
    .hero-title { font-size: 1.6rem; line-height: 1.3; }
    .hero-subtitle { font-size: 0.9rem; margin-bottom: 1rem; }
    .feature-card { padding: 1rem; }
    .feature-card h3 { font-size: 1.05rem; }

    /* AI Coach: bottom sheet style */
    .ai-coach-container { bottom: 8px; right: 8px; }
    .ai-coach-toggle { width: 46px; height: 46px; font-size: 1.4rem; border-width: 2px; }
    .ai-coach-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 70vh;
        max-height: none;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        z-index: 10001;
    }
    .ai-coach-header { padding: 0.6rem 0.75rem; }
    .ai-coach-input-area { padding: 0.5rem; gap: 0.35rem; }
    /* Add safe area for bottom gesture bar on iOS */
    .ai-coach-input-area { padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px)); }

    /* Accessibility widget */
    .acc-toggle-btn { width: 44px; height: 44px; }
    .acc-icon { width: 28px; height: 28px; }
    .acc-menu {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        max-height: 80vh;
        overflow-y: auto;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        padding: 1rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
        transform: translateY(100%);
    }
    .acc-menu.open {
        transform: translateY(0);
    }

    /* Auth card */
    .card-auth {
        padding: 1.25rem;
        border-radius: var(--radius-xl);
    }

    /* Social buttons */
    .btn-google, .btn-facebook { padding: 0.65rem 0.75rem; font-size: 0.9rem; }

    /* Cookie banner */
    #cookie-consent-banner { padding: 12px !important; }
    #cookie-consent-banner p { font-size: 12px !important; }

    /* Achievement toast: full-width bottom */
    .achievement-toast {
        left: 8px;
        right: 8px;
        bottom: 8px;
        padding: 0.6rem 0.8rem;
        gap: 0.5rem;
    }
    .achievement-toast__icon { font-size: 1.8rem; }
    .achievement-toast__title { font-size: 0.9rem; }

    /* Hide decorative stuff on small screens */
    .bg-ornaments { opacity: 0.3; }
    .brain-pulse { animation-duration: 8s; } /* Slower = less battery drain */

    /* Prevent horizontal scroll — clip instead of hidden so child scrollers work */
    body { max-width: 100vw; overflow-x: clip !important; }
    .app-shell { max-width: 100%; overflow-x: clip !important; }
}


/* ---------- 15.25  Small phones (≤450px) — hamburger + header compaction ---------- */
/* Tab-bar scroll/sizing is already set in the ≤480px block above.
   This block adds the hamburger toggle, collapsible util panel, and
   header text compaction that only kick in at the narrowest widths.     */
@media (max-width: 450px) {

    /* ── Restore the hamburger (util-toggle) for small screens ──
       It was hidden at ≤768px; we bring it back here so users can
       reach the contact/utils panel without crowding the header.    */
    .app-util-toggle {
        display: flex !important;
        padding: 0 7px !important;
        min-width: 30px !important;
        height: 30px !important;
        justify-content: center;
        align-items: center;
        border-radius: 6px;
    }
    .app-util-toggle .app-util-label { display: none !important; }
    .app-util-toggle .toggle-chevron  { display: none !important; }
    .app-util-toggle .toggle-icon     { font-size: 1rem; }

    /* Re-enable the collapsible util panel */
    #app-util-group {
        display: flex !important;
        flex: 0 0 100%;            /* full-width new row in flex-wrap header */
        order: 10;
        flex-wrap: nowrap;
        justify-content: flex-end;
        align-items: center;
        gap: 0.4rem;
        padding: 0 0.75rem;
        max-height: 0;
        overflow: hidden;
        border-top: 0 solid var(--border);
        background: var(--card-bg);
        transition: max-height 0.28s ease, padding 0.25s ease, border-top 0.15s;
    }
    .app-header.util-open #app-util-group {
        max-height: 52px;
        padding: 0.4rem 0.75rem;
        border-top: 1px solid var(--border);
    }
    .util-panel-close {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 24px; height: 24px;
        border-radius: 50%;
        background: transparent;
        border: 1px solid var(--border);
        font-size: 0.75rem;
        cursor: pointer;
        flex-shrink: 0;
        transition: background 0.2s, color 0.2s;
    }
    .util-panel-close:hover { background: rgba(239,68,68,0.1); color: #ef4444; }
    #app-util-group .btn-label     { display: inline !important; }
    #app-util-group .header-util-btn {
        height: 26px; font-size: 0.68rem; padding: 0 0.45rem;
    }

    /* ── Header compaction ── */
    /* Hide score label ("נקודות"), keep just the number */
    .score-pill > span:first-child { display: none; }
    /* Truncate long usernames */
    #username-display {
        max-width: 60px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.72rem !important;
    }
    .logout-link { font-size: 0.64rem; }
    /* Tighten row 1 gap */
    .app-header__right { gap: 0.2rem !important; }
}

/* ≤ 380px: icon-only tabs — all 7 tabs (~280px) fit without scrolling */
@media (max-width: 380px) {
    .dash-mobile-tab__label { display: none !important; }
    .dash-mobile-tab {
        padding: 6px 9px;
        min-width: 36px;
    }
    .dash-mobile-tab__icon { font-size: 1.2rem; }
    .dash-mobile-nav { padding: 5px 4px 4px; gap: 2px; }
}

/* ---------- 15.3  Extra-Small phones (≤ 360px, e.g. iPhone SE) ---------- */
@media (max-width: 360px) {

    html { font-size: 14px !important; }

    .app-header { padding: 0.25rem 0.4rem; }
    .brand__name { font-size: 0.8rem; }
    .score-pill { font-size: 0.7rem; }

    .dashboard-section { padding: 0.65rem; }
    .dashboard-title { font-size: 1rem; }

    /* Game boards */
    .game-board { gap: 0.25rem; padding: 0.35rem; }
    .front-face { font-size: 1.2rem; }

    /* Game areas */
    .perception-game-area,
    .trail-making-area,
    .oi-game-area,
    .track-switcher-area {
        height: 70vw;
        min-height: 200px;
        max-height: 300px;
    }

    .trail-node { width: 30px; height: 30px; font-size: 0.85rem; }
    .nback-grid { width: 190px; height: 190px; gap: 0.4rem; padding: 0.5rem; }
    .serial-memory-container { width: 180px; height: 180px; }
    .pr-grid { width: 180px; height: 180px; }

    .symbol-slot { width: 32px; height: 32px; font-size: 1.1rem; }
    .symbol-btn { width: 42px; height: 42px; font-size: 1.5rem; }

    /* Levels: tighter grid */
    .level-node { width: 34px; height: 34px; font-size: 0.8rem; }

    /* Hero */
    .hero-title { font-size: 1.4rem; }
    .hero-subtitle { font-size: 0.85rem; }

    /* Buttons minimum touch */
    .btn { min-height: 42px; }
}


/* ---------- 15.4  Landscape phone (short + wide) ---------- */
@media (max-height: 500px) and (orientation: landscape) {

    .app-header { padding: 0.2rem 0.75rem; }

    /* Game areas: use height-based sizing in landscape */
    .perception-game-area,
    .trail-making-area,
    .oi-game-area,
    .track-switcher-area {
        height: 50vh;
        min-height: 180px;
    }
    .quantitative-game-area {
        height: 40vh;
        min-height: 150px;
    }

    .game-board {
        max-width: 50vh;
        max-height: 70vh;
    }
    .nback-grid { width: min(220px, 45vh); height: min(220px, 45vh); }
    .serial-memory-container { width: min(200px, 40vh); height: min(200px, 40vh); }

    /* Modal: landscape friendly */
    .modal-content {
        max-height: 90vh;
        max-width: 80vw;
    }

    /* AI Coach: side panel instead of tall */
    .ai-coach-window {
        height: 85vh;
        width: 320px;
        max-width: 50vw;
    }

    /* Hide ornaments in landscape to save space */
    .bg-ornaments { display: none; }
}


/* ---------- 15.5  Touch-device improvements ---------- */
@media (hover: none) and (pointer: coarse) {

    /* Remove hover effects that don't work on touch */
    .dashboard-section:hover { transform: none; }
    .stat-card:hover { transform: none; }
    .btn:hover { transform: none; filter: none; }
    .btn:hover::before { width: 0; height: 0; }
    .level-node.completed:hover { transform: none; }
    .shape:hover { transform: none; filter: none; }
    .game-preview-card:hover { transform: none; }

    /* Ensure tap targets ≥ 44px */
    .choice-btn, .nback-btn, .vnm-btn, .symbol-btn,
    .level-node, .trail-node, .switch {
        min-width: 44px;
        min-height: 44px;
    }

    /* Active state instead of hover */
    .btn:active { transform: scale(0.97); filter: brightness(0.95); }
    .stat-card:active { transform: scale(0.98); }
    .level-node:active { transform: scale(0.95); }
    .dashboard-section:active { transform: translateY(-1px); }
}


/* ---------- 15.6  Mobile Game-Fit — ensure all games visible on small screens ---------- */

/* --- Global: all game containers must respect viewport width --- */
@media (max-width: 480px) {

    /* Force all game areas to be viewport-aware */
    .perception-game-area,
    .quantitative-game-area,
    .trail-making-area,
    .vnm-display-area,
    .track-switcher-area,
    .oi-game-area,
    .ss-game-area,
    .tt-game-container {
        max-width: calc(100vw - 1.5rem);
        box-sizing: border-box;
    }

    /* Fixed-size grids: make them viewport-relative */
    .nback-grid {
        width: min(220px, calc(100vw - 3rem));
        height: min(220px, calc(100vw - 3rem));
    }
    .serial-memory-container {
        width: min(200px, calc(100vw - 3rem));
        height: min(200px, calc(100vw - 3rem));
    }
    .pr-grid {
        width: min(200px, calc(100vw - 3rem));
        height: min(200px, calc(100vw - 3rem));
    }

    /* Sequence Forge: full width */
    .sf-sequence-display {
        max-width: calc(100vw - 2rem);
        flex-wrap: wrap;
    }
    .sf-symbol-choices {
        max-width: calc(100vw - 2rem);
    }

    /* OI game area: viewport-based */
    .oi-game-area {
        max-width: calc(100vw - 1.5rem);
        height: 60vw;
        min-height: 200px;
        max-height: 320px;
    }

    /* VNM display: compact */
    .vnm-display-area {
        min-height: 140px;
        padding: 1rem;
    }

    /* Game info/status bars: allow wrapping */
    #main-content-area .flex {
        flex-wrap: wrap;
    }

    /* Ensure centered game grids don't overflow */
    #main-content-area {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 0 0.25rem;
    }

    /* Scale down any inline-styled game containers */
    [style*="width: 500px"],
    [style*="width: 600px"],
    [style*="width: 700px"],
    [style*="max-width: 500px"],
    [style*="max-width: 600px"],
    [style*="max-width: 700px"] {
        max-width: calc(100vw - 1.5rem) !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
}

/* --- Extra-small phones: aggressive fitting (≤ 360px) --- */
@media (max-width: 360px) {

    .nback-grid {
        width: min(180px, calc(100vw - 2.5rem));
        height: min(180px, calc(100vw - 2.5rem));
        padding: 0.4rem;
        gap: 0.35rem;
    }
    .serial-memory-container {
        width: min(170px, calc(100vw - 2.5rem));
        height: min(170px, calc(100vw - 2.5rem));
        gap: 0.5rem;
    }
    .pr-grid {
        width: min(170px, calc(100vw - 2.5rem));
        height: min(170px, calc(100vw - 2.5rem));
        gap: 0.35rem;
    }

    /* Game areas: further shrink */
    .perception-game-area,
    .trail-making-area,
    .oi-game-area,
    .track-switcher-area {
        height: 75vw;
        min-height: 180px;
        max-height: 280px;
    }
    .quantitative-game-area {
        height: 55vw;
        min-height: 150px;
        max-height: 230px;
    }

    /* Trail nodes: smallest size */
    .trail-node { width: 28px; height: 28px; font-size: 0.75rem; border-width: 2px; }

    /* Balloons: ensure they fit */
    .balloon { min-width: 35px; min-height: 35px; font-size: 0.8rem; }

    /* Sequence Forge: tighter */
    .symbol-slot { width: 28px; height: 28px; font-size: 1rem; }
    .symbol-btn { width: 38px; height: 38px; font-size: 1.3rem; }
    .sf-sequence-display { gap: 0.25rem; padding: 0.4rem; }
    .sf-symbol-choices { gap: 0.25rem; }

    /* Memory card faces */
    .front-face { font-size: 1rem; }
    .back-face img { width: 75%; height: 75%; }

    /* Choice buttons: compact */
    .choice-btn { width: 60px; min-height: 40px; padding: 0.4rem 0.6rem; font-size: 0.8rem; }
    .nback-btn, .vnm-btn { min-height: 40px; padding: 0.5rem 0.75rem; font-size: 0.8rem; }
}

/* --- Portrait phone: ensure game fits in viewport height --- */
@media (max-width: 480px) and (orientation: portrait) {

    /* Game containers: limit height so entire game + controls are visible */
    .perception-game-area,
    .trail-making-area,
    .oi-game-area,
    .track-switcher-area {
        max-height: 45vh;
    }
    .quantitative-game-area {
        max-height: 35vh;
    }

    /* Game board (memory cards): ensure it fits vertically */
    .game-board {
        max-height: 55vh;
    }
    .game-board.cols-5,
    .game-board.cols-6 {
        max-height: 50vh;
    }

    /* Fixed-size grids: cap height to viewport */
    .nback-grid,
    .serial-memory-container,
    .pr-grid {
        max-height: 45vh;
        max-width: min(45vh, calc(100vw - 2rem));
    }

    /* Compact game header/timer/score bars */
    #main-content-area .text-2xl,
    #main-content-area .text-xl {
        font-size: 1.1rem;
    }
    #main-content-area .text-lg {
        font-size: 0.95rem;
    }

    /* Reduce vertical margins/padding around game areas */
    #main-content-area .mb-4,
    #main-content-area .mb-6 {
        margin-bottom: 0.5rem !important;
    }
    #main-content-area .mt-4,
    #main-content-area .mt-6 {
        margin-top: 0.5rem !important;
    }
    #main-content-area .p-4,
    #main-content-area .p-6 {
        padding: 0.5rem !important;
    }
    #main-content-area .py-4 {
        padding-top: 0.5rem !important;
        padding-bottom: 0.5rem !important;
    }
}

/* --- Very short portrait phones (e.g. older iPhones, Galaxy A series) --- */
@media (max-width: 480px) and (max-height: 700px) and (orientation: portrait) {

    .perception-game-area,
    .trail-making-area,
    .oi-game-area,
    .track-switcher-area {
        max-height: 38vh;
        min-height: 160px;
    }
    .quantitative-game-area {
        max-height: 30vh;
        min-height: 130px;
    }

    .game-board {
        max-height: 45vh;
        gap: 0.25rem;
        padding: 0.35rem;
    }

    .nback-grid,
    .serial-memory-container,
    .pr-grid {
        max-height: 38vh;
    }

    /* Shrink toolbar to save vertical space */
    .toolbar {
        padding: 0.3rem;
        gap: 0.3rem;
        margin: 0.25rem 0.5rem 0.5rem;
    }

    /* Compact buttons */
    .btn { padding: 0.45rem 0.7rem; font-size: 0.8rem; min-height: 40px; }
}

/* ---------- 15.7  iOS safe areas ---------- */
@supports (padding: env(safe-area-inset-bottom)) {
    .ai-coach-container { bottom: calc(12px + env(safe-area-inset-bottom)); }
    .acc-widget { bottom: calc(12px + env(safe-area-inset-bottom)); }
    .achievement-toast { bottom: calc(8px + env(safe-area-inset-bottom)); }
    #cookie-consent-banner { padding-bottom: calc(12px + env(safe-area-inset-bottom)) !important; }
}

/* ---------- 15.8  Mobile optimisation (< 600px) ----------
   Only affects narrow phones. Desktop / tablet (≥ 600px) is untouched.
   ------------------------------------------------------------------ */
@media (max-width: 599px) {

    /* --- Hide floating overlay buttons --- */
    .ai-coach-container,
    .acc-widget { display: none !important; }

    /* --- Reset base font to a sensible mobile size ---
       Desktop accessibility classes (acc-large-text, acc-scale-*) set font-size on
       the <html> element, which rem values scale from.  Both html AND body must be
       locked to 16px so that rem-based Tailwind utilities (text-5xl = 3rem etc.)
       stay small on mobile regardless of any saved accessibility preferences. */
    html { font-size: 16px !important; }
    body { font-size: 16px !important; }

    /* --- Landing hero heading --- */
    /* Tailwind text-5xl / text-7xl + acc scale can push this above 70px on phone.
       Cap it at a size that comfortably fits ~5 Hebrew words in 2 lines. */
    .hero-title {
        font-size: 1.75rem !important;
        line-height: 1.25   !important;
    }
    .hero-subtitle {
        font-size: 0.95rem !important;
        line-height: 1.5   !important;
    }
    /* Tailwind large-text helpers used elsewhere on the landing page */
    .text-6xl, .text-7xl, .text-8xl { font-size: 2rem !important; }

    /* --- App header --- */
    .app-header {
        padding: 0.3rem 0.6rem 0 !important;
    }
    .app-header__brand .brand-logo { font-size: 1rem !important; }
    .app-header__brand .brand-section { font-size: 0.7rem !important; }
    .header-util-btn { height: 28px !important; font-size: 0.7rem !important; padding: 0 0.35rem !important; }
    #username-display { font-size: 0.75rem !important; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #total-score-display { font-size: 0.75rem !important; }
    .streak-pill { height: 28px !important; font-size: 0.72rem !important; padding: 0 0.5rem !important; }
    #go-premium-btn { font-size: 0.65rem !important; padding: 0.2rem 0.4rem !important; }

    /* --- Dashboard layout --- */
    .dash-content { padding: 0.6rem !important; }
    .dash-section-title { font-size: 1.1rem !important; }
    .dash-section-subtitle { font-size: 0.78rem !important; }
    .dash-section-header { margin-bottom: 0.75rem !important; }

    /* --- Dashboard mobile tab bar --- */
    .dash-mobile-nav { font-size: 0.65rem !important; }
    .dash-mobile-tab__icon { font-size: 1.1rem !important; }
    .dash-mobile-tab__label { font-size: 0.6rem !important; }

    /* --- Game cards in free-play / performance grids --- */
    .dash-game-card { padding: 0.6rem !important; }
    .dash-game-card__name { font-size: 0.78rem !important; }
    .dash-games-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important; gap: 0.5rem !important; }

    /* --- Stat / performance cards --- */
    .stat-card { padding: 0.6rem !important; font-size: 0.8rem !important; }
    .stat-card-title { font-size: 0.8rem !important; }

    /* --- Bonus game cards --- */
    .bonus-game-card { padding: 0.75rem !important; }
    .bonus-game-card h4 { font-size: 0.85rem !important; }
    .bonus-game-card p  { font-size: 0.7rem !important; }

    /* --- Cards / overview --- */
    .dash-card,
    .overview-card { padding: 0.75rem !important; }
    .dashboard-title { font-size: 1rem !important; }

    /* --- Daily quest --- */
    .daily-quest-section { padding: 0.75rem !important; }
    .quest-header .dashboard-title { font-size: 0.95rem !important; }

    /* --- Buttons --- */
    .btn { font-size: 0.8rem !important; padding: 0.4rem 0.75rem !important; }
    .btn-primary,
    .btn-success,
    .btn-warning { font-size: 0.8rem !important; }

    /* --- Modals --- */
    .modal-content { padding: 1rem !important; border-radius: 0.75rem !important; }
    .modal-content h2,
    .modal-content h3 { font-size: 1.1rem !important; }

    /* --- Settings modal (mobile) --- */
    #settings-modal .modal-content {
        padding: 0.85rem !important;
        max-width: calc(100vw - 16px) !important;
    }
    #settings-modal h2 { font-size: 1.05rem !important; }
    #settings-modal .form-label { font-size: 0.78rem !important; margin-bottom: 0.2rem !important; }
    #settings-modal .form-input,
    #settings-modal select.form-input { font-size: 0.82rem !important; padding: 0.35rem 0.5rem !important; }
    #settings-modal .space-y-4 > * + * { margin-top: 0.6rem !important; }
    #settings-modal .mt-6 { margin-top: 0.75rem !important; }
    #settings-modal .text-sm { font-size: 0.72rem !important; }
    #settings-modal a { font-size: 0.78rem !important; }

    /* --- Memory game board ≤480px ---------------------------------------- */
    /* Override the JS inline px width with a stricter viewport clamp.
       width (not just max-width) is set so the board can never be wider
       than the viewport regardless of what the parent element does. */
    #memory-game-board {
        width:     calc(100vw - 32px) !important;
        max-width: calc(100vw - 32px) !important;
        padding: 0.35rem !important;
    }
    #memory-game-board[data-cols="5"] { gap: 0.22rem !important; }
    #memory-game-board[data-cols="6"] { gap: 0.18rem !important; }

    /* --- Win / instructions modal --- */
    #win-message { font-size: 0.85rem !important; }

    /* --- Toolbar (in-game top bar) --- */
    .toolbar { padding: 0.25rem 0.5rem !important; gap: 0.25rem !important; font-size: 0.78rem !important; }
    .toolbar .score-pill,
    .toolbar .timer-pill { font-size: 0.75rem !important; padding: 0.2rem 0.5rem !important; }
}

/* ── Memory board clamp for medium screens (601–800 px) ──────────────────────
   At 769–800 px the app-shell uses full px-4 padding (16 px each side = 32 px
   total), which equals the JS safety margin — leaving zero buffer. This block
   shrinks the board to calc(100vw - 48px), giving 24 px each side and
   preventing the right column from being clipped by overflow-x: clip. */
@media (max-width: 800px) {
    /* min() picks the more conservative of the two formulas:
       - calc(100vw - 48px): viewport-based clamp for ≤768 px screens
       - calc(100% - 8px):   container-based clamp for 769–800 px where
         Tailwind's md breakpoint caps app-shell at 768 px → content ≈ 736 px */
    #memory-game-board {
        width:     min(calc(100vw - 48px), calc(100% - 8px)) !important;
        max-width: min(calc(100vw - 48px), calc(100% - 8px)) !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        padding: 0.5rem !important;
    }
    #memory-game-board[data-cols="5"] { gap: 0.3rem !important; }
    #memory-game-board[data-cols="6"] { gap: 0.25rem !important; }
}

/* ── Memory board clamp for mid-size phones / small tablets (481–600 px) ─────
   The ≤480px block above covers small phones.  This block catches screens
   that are slightly wider (e.g. 500–600 px) where 5–6 column grids would
   still overflow without clamping. */
@media (max-width: 600px) {
    #memory-game-board {
        width:     calc(100vw - 32px) !important;
        max-width: calc(100vw - 32px) !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        padding: 0.4rem !important;
    }
    #memory-game-board[data-cols="5"] { gap: 0.25rem !important; }
    #memory-game-board[data-cols="6"] { gap: 0.2rem  !important; }
}

/* תיקון גובה עבור מודל האימון היומי וחלונות קופצים אחרים */
.modal-content {
    max-height: 90vh !important; /* מגביל את הגובה ל-60% מהמסך */
    overflow-y: auto !important; /* מוסיף גלילה פנימית אם יש הרבה משחקים */
}

/* ═══════════════════════════════════════════════════════════════
   LTR (English) layout overrides
   Applied when html[dir="ltr"] — English language mode
   ═══════════════════════════════════════════════════════════════ */

/* Base: let text flow naturally left-to-right */
html[dir="ltr"] {
    text-align: left;
}

/* Components with hardcoded text-align: right that must flip in LTR */
html[dir="ltr"] .dash-menu-item,
html[dir="ltr"] .dash-mobile-tab,
html[dir="ltr"] .personalized-btn,
html[dir="ltr"] .acc-option-btn,
html[dir="ltr"] .stat-card {
    text-align: left;
}

/* Override Tailwind text-right utility class in LTR context */
html[dir="ltr"] [class~="text-right"] {
    text-align: left !important;
}

/* Sidebar & nav link icon order: keep icon before text in LTR */
html[dir="ltr"] .dash-menu-item__text,
html[dir="ltr"] .dash-mobile-tab__label {
    text-align: left;
}

/* Auth / form labels */
html[dir="ltr"] label,
html[dir="ltr"] .form-label {
    text-align: left;
}

/* ═══════════════════════════════════════════════════════════════
   Language-specific visibility  (data-lang-only="he"|"en")
   ═══════════════════════════════════════════════════════════════ */

/* English-only elements hidden by default (Hebrew is default) */
[data-lang-only="en"] { display: none !important; }

/* In English mode: hide Hebrew-only, reveal English-only */
html[lang="en"] [data-lang-only="he"] { display: none !important; }
html[lang="en"] [data-lang-only="en"] { display: flex !important; }