/**
 * GCSE Revision Hub - Design System
 *
 * Feature: F-032.1 Design Tokens & CSS Variables
 * Version: 1.0
 * Created: 2026-01-20
 *
 * This file contains all design tokens for the modern UI/UX redesign.
 * All tokens are CSS custom properties that work in both light and dark themes.
 *
 * USAGE:
 * - Include this file BEFORE other stylesheets
 * - Reference tokens via var(--token-name)
 * - Theme is controlled via [data-theme="light"] or [data-theme="dark"]
 * - Default theme is DARK
 */

/* ============================================================================
   ROOT TOKENS (Theme-agnostic)
   ============================================================================ */

:root {
  /* --------------------------------------------------------------------------
     TYPOGRAPHY
     -------------------------------------------------------------------------- */

  /* Font Families */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Monaco, monospace;

  /* Font Sizes */
  --text-2xs: 0.625rem;   /* 10px - badges, overlines */
  --text-xs: 0.75rem;     /* 12px - captions */
  --text-sm: 0.875rem;    /* 14px - body small */
  --text-base: 1rem;      /* 16px - body */
  --text-lg: 1.125rem;    /* 18px - h4 */
  --text-xl: 1.25rem;     /* 20px - h3 */
  --text-2xl: 1.5rem;     /* 24px - h2 */
  --text-3xl: 1.875rem;   /* 30px - h1 */
  --text-4xl: 2.25rem;    /* 36px - display */

  /* Font Weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* Line Heights */
  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  /* Letter Spacing */
  --tracking-tight: -0.025em;
  --tracking-normal: 0;
  --tracking-wide: 0.025em;

  /* --------------------------------------------------------------------------
     SPACING SYSTEM (4px base)
     -------------------------------------------------------------------------- */

  --space-0: 0;
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;    /* 24px */
  --space-8: 2rem;      /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */
  --space-16: 4rem;     /* 64px */
  --space-20: 5rem;     /* 80px */
  --space-24: 6rem;     /* 96px */

  /* X2-001: Semantic spacing aliases for consistency with legacy code */
  --space-xs: var(--space-1);   /* 4px */
  --space-sm: var(--space-2);   /* 8px */
  --space-md: var(--space-4);   /* 16px */
  --space-lg: var(--space-6);   /* 24px */
  --space-xl: var(--space-8);   /* 32px */
  --space-2xl: var(--space-12); /* 48px */

  /* --------------------------------------------------------------------------
     BORDER RADIUS
     -------------------------------------------------------------------------- */

  --radius-none: 0;
  --radius-sm: 0.25rem;   /* 4px - small elements */
  --radius-md: 0.5rem;    /* 8px - buttons, inputs */
  --radius-lg: 0.75rem;   /* 12px - cards */
  --radius-xl: 1rem;      /* 16px - large cards */
  --radius-2xl: 1.5rem;   /* 24px - modals */
  --radius-full: 9999px;  /* Pills, avatars */

  /* --------------------------------------------------------------------------
     TRANSITIONS & ANIMATIONS
     -------------------------------------------------------------------------- */

  /* Durations */
  --duration-instant: 50ms;
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 350ms;
  --duration-slower: 500ms;

  /* Easings */
  --ease-linear: linear;
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);

  /* Common Transitions */
  --transition-colors: color var(--duration-fast) var(--ease-in-out),
                       background-color var(--duration-fast) var(--ease-in-out),
                       border-color var(--duration-fast) var(--ease-in-out);
  --transition-transform: transform var(--duration-normal) var(--ease-out);
  --transition-opacity: opacity var(--duration-fast) var(--ease-in-out);
  --transition-shadow: box-shadow var(--duration-fast) var(--ease-in-out);
  --transition-all: all var(--duration-fast) var(--ease-in-out);

  /* --------------------------------------------------------------------------
     GLASSMORPHISM
     -------------------------------------------------------------------------- */

  --glass-blur: 10px;              /* Backdrop blur amount */
  --glass-opacity-light: 0.7;      /* Background opacity in light mode */
  --glass-opacity-dark: 0.7;       /* Background opacity in dark mode */
  --glass-border-light: 0.18;      /* Border opacity in light mode */
  --glass-border-dark: 0.1;        /* Border opacity in dark mode */

  /* --------------------------------------------------------------------------
     SEMANTIC COLORS (Consistent across themes)
     -------------------------------------------------------------------------- */

  --color-primary: #3b82f6;     /* Blue - Primary actions, Quiz */
  --color-secondary: #8b5cf6;   /* Purple - Flashcards, premium */
  --color-success: #22c55e;     /* Green - Correct, positive feedback */
  --color-warning: #f59e0b;     /* Amber - Caution states */
  --color-error: #ef4444;       /* Red - Wrong, negative feedback */

  /* --------------------------------------------------------------------------
     FEATURE COLORS (Consistent across themes)
     -------------------------------------------------------------------------- */

  --feature-flashcards: #8b5cf6;  /* Purple */
  --feature-quiz: #3b82f6;        /* Blue */
  --feature-learn: #3b82f6;       /* Blue */
  --feature-review: #8b5cf6;      /* Purple */
  --feature-test: #f59e0b;        /* Amber */

  /* --------------------------------------------------------------------------
     SUBJECT COLORS (Consistent across themes)
     -------------------------------------------------------------------------- */

  --subject-physics: #6366f1;          /* Indigo */
  --subject-chemistry: #ec4899;        /* Pink */
  --subject-biology: #22c55e;          /* Green */
  --subject-history: #f59e0b;          /* Amber */
  --subject-maths: #3b82f6;            /* Blue */
  --subject-computer-science: #06b6d4; /* Cyan */
}

/* ============================================================================
   DARK THEME (Default)
   ============================================================================ */

:root,
[data-theme="dark"] {
  /* --------------------------------------------------------------------------
     BACKGROUND & SURFACE COLORS (Dark Mode)
     -------------------------------------------------------------------------- */

  --bg-base: #0f172a;         /* Slate-900 - Page background */
  --bg-surface: #1e293b;      /* Slate-800 - Cards, panels */
  --bg-elevated: #334155;     /* Slate-700 - Elevated cards, modals */
  --bg-subtle: #1e293b;       /* Slate-800 - Subtle backgrounds */
  --bg-interactive: #475569;  /* Slate-600 - Hover states */

  /* --------------------------------------------------------------------------
     TEXT COLORS (Dark Mode)
     -------------------------------------------------------------------------- */

  --text-primary: #f1f5f9;    /* Slate-100 - Headings, primary content */
  --text-secondary: #94a3b8;  /* Slate-400 - Body text, descriptions */
  --text-muted: #64748b;      /* Slate-500 - Captions, hints */
  --text-inverse: #0f172a;    /* Slate-900 - Text on colored backgrounds */

  /* --------------------------------------------------------------------------
     BORDER COLORS (Dark Mode)
     -------------------------------------------------------------------------- */

  --border-default: #334155;  /* Slate-700 - Default borders */
  --border-subtle: #1e293b;   /* Slate-800 - Subtle dividers */
  --border-strong: #475569;   /* Slate-600 - Emphasized borders */

  /* --------------------------------------------------------------------------
     GLASSMORPHISM COLORS (Dark Mode)
     -------------------------------------------------------------------------- */

  --glass-bg: rgba(30, 41, 59, 0.7);      /* Slate-800 with 70% opacity */
  --glass-border: rgba(255, 255, 255, 0.1); /* White with 10% opacity */

  /* --------------------------------------------------------------------------
     SHADOWS (Dark Mode)
     -------------------------------------------------------------------------- */

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);

  /* Colored shadows for interactive elements */
  --shadow-primary: 0 4px 14px rgba(59, 130, 246, 0.4);
  --shadow-secondary: 0 4px 14px rgba(139, 92, 246, 0.4);
  --shadow-success: 0 4px 14px rgba(34, 197, 94, 0.4);
  --shadow-warning: 0 4px 14px rgba(245, 158, 11, 0.4);
  --shadow-error: 0 4px 14px rgba(239, 68, 68, 0.4);
}

/* ============================================================================
   LIGHT THEME
   ============================================================================ */

[data-theme="light"] {
  /* --------------------------------------------------------------------------
     BACKGROUND & SURFACE COLORS (Light Mode)
     -------------------------------------------------------------------------- */

  --bg-base: #f8fafc;         /* Slate-50 - Page background */
  --bg-surface: #ffffff;      /* White - Cards, panels */
  --bg-elevated: #ffffff;     /* White - Elevated cards, modals */
  --bg-subtle: #f1f5f9;       /* Slate-100 - Subtle backgrounds */
  --bg-interactive: #e2e8f0;  /* Slate-200 - Hover states */

  /* --------------------------------------------------------------------------
     TEXT COLORS (Light Mode)
     -------------------------------------------------------------------------- */

  --text-primary: #0f172a;    /* Slate-900 - Headings, primary content */
  --text-secondary: #475569;  /* Slate-600 - Body text, descriptions */
  --text-muted: #94a3b8;      /* Slate-400 - Captions, hints */
  --text-inverse: #ffffff;    /* White - Text on colored backgrounds */

  /* --------------------------------------------------------------------------
     BORDER COLORS (Light Mode)
     -------------------------------------------------------------------------- */

  --border-default: #e2e8f0;  /* Slate-200 - Default borders */
  --border-subtle: #f1f5f9;   /* Slate-100 - Subtle dividers */
  --border-strong: #cbd5e1;   /* Slate-300 - Emphasized borders */

  /* --------------------------------------------------------------------------
     GLASSMORPHISM COLORS (Light Mode)
     -------------------------------------------------------------------------- */

  --glass-bg: rgba(255, 255, 255, 0.7);      /* White with 70% opacity */
  --glass-border: rgba(255, 255, 255, 0.18); /* White with 18% opacity */

  /* --------------------------------------------------------------------------
     SHADOWS (Light Mode)
     -------------------------------------------------------------------------- */

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* Colored shadows remain the same across themes */
  --shadow-primary: 0 4px 14px rgba(59, 130, 246, 0.4);
  --shadow-secondary: 0 4px 14px rgba(139, 92, 246, 0.4);
  --shadow-success: 0 4px 14px rgba(34, 197, 94, 0.4);
  --shadow-warning: 0 4px 14px rgba(245, 158, 11, 0.4);
  --shadow-error: 0 4px 14px rgba(239, 68, 68, 0.4);
}

/* ============================================================================
   THEME TRANSITION
   ============================================================================ */

body {
  transition: background-color 300ms ease, color 300ms ease;
}

/* ============================================================================
   CONTENT OVERFLOW UTILITIES
   ============================================================================ */

.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============================================================================
   ANIMATION KEYFRAMES
   ============================================================================ */

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

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Gen Z/Gen Alpha Animation Library - Social media quality */
@keyframes touchResponse {
  0% { transform: scale(1); }
  50% { transform: scale(0.98); }
  100% { transform: scale(1); }
}

@keyframes rippleEffect {
  from {
    opacity: 1;
    transform: scale(0);
  }
  to {
    opacity: 0;
    transform: scale(4);
  }
}

@keyframes successFlash {
  0% { opacity: 0; background-color: rgba(34, 197, 94, 0); }
  50% { opacity: 1; background-color: rgba(34, 197, 94, 0.1); }
  100% { opacity: 0; background-color: rgba(34, 197, 94, 0); }
}

@keyframes bounceIn {
  0% { transform: scale(0.8) translateY(10px); opacity: 0; }
  50% { transform: scale(1.05) translateY(-5px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

/* Simple slide animations - easy to see */
@keyframes slideOutLeft {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(-50%);
    opacity: 0;
  }
}

@keyframes slideInRight {
  from {
    transform: translateX(50%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOutRight {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(50%);
    opacity: 0;
  }
}

@keyframes slideInLeft {
  from {
    transform: translateX(-50%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ============================================================================
   GEN Z MICRO-INTERACTION UTILITIES
   ============================================================================ */

/* Touch responsive elements */
.touch-responsive {
  cursor: pointer;
  transition: transform var(--duration-instant, 50ms) var(--ease-out);
  will-change: transform;
}

.touch-responsive:active {
  animation: touchResponse var(--duration-instant, 50ms) var(--ease-out);
}

/* Ripple effect for button clicks */
.ripple-container {
  position: relative;
  overflow: hidden;
}

.ripple-container::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  pointer-events: none;
  transform: scale(0);
  animation: rippleEffect var(--duration-normal, 250ms) var(--ease-out);
}

/* Success animations */
.success-flash {
  animation: successFlash var(--duration-normal, 250ms) var(--ease-out);
}

.success-bounce {
  animation: bounceIn var(--duration-normal, 250ms) var(--ease-bounce);
}

/* Hover states for interactive elements */
.hover-lift {
  transition: transform var(--duration-fast, 150ms) var(--ease-out);
}

.hover-lift:hover {
  transform: translateY(-2px);
}

/* Progress pulse animation */
.progress-pulse {
  animation: pulse var(--duration-fast, 150ms) var(--ease-out);
}

/* Simple fade transition - smooth and visible */
.slide-out {
  animation: fadeOut 250ms ease-out forwards;
}

.slide-in {
  animation: fadeIn 250ms ease-out forwards;
}

/* Component entrance animations */
.animate-slide-up {
  animation: slideUpFade 400ms ease-out forwards;
}

.animate-slide-right {
  animation: slideInFromRight 400ms ease-out forwards;
}

/* Staggered animations for multiple components */
.animate-stagger-1 { animation-delay: 100ms; }
.animate-stagger-2 { animation-delay: 200ms; }
.animate-stagger-3 { animation-delay: 300ms; }
.animate-stagger-4 { animation-delay: 400ms; }
.animate-stagger-5 { animation-delay: 500ms; }

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Component entrance animations - simple and clean */
@keyframes slideUpFade {
  from { 
    opacity: 0; 
    transform: translateY(20px);
  }
  to { 
    opacity: 1; 
    transform: translateY(0);
  }
}

@keyframes slideInFromRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ============================================================================
   ACCESSIBILITY: REDUCED MOTION SUPPORT
   ============================================================================ */

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

  body {
    transition: none;
  }
}

/* ============================================================================
   GLASSMORPHISM FALLBACK
   ============================================================================ */

/**
 * For browsers that don't support backdrop-filter (< 5% of users),
 * increase opacity for better readability without the blur effect.
 */
@supports not (backdrop-filter: blur(10px)) {
  :root,
  [data-theme="dark"] {
    --glass-bg: rgba(30, 41, 59, 0.95);
  }

  [data-theme="light"] {
    --glass-bg: rgba(255, 255, 255, 0.95);
  }
}
