/* LearningHub Mobile-First CSS v3 */
/* Based on 2026 best practices: Core Web Vitals, WCAG 2.2, Touch-friendly design */
/* Source: Mobile-first approach using min-width media queries */

/* ===========================================
   CSS CUSTOM PROPERTIES (Mobile-first defaults)
   =========================================== */
:root {
    /* System font stack for better performance */
    --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", "Cascadia Code", "Fira Code", Consolas, "Liberation Mono", Menlo, monospace;

    /* Fluid typography using clamp() */
    --fs-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);     /* 12-14px */
    --fs-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);        /* 14-16px */
    --fs-base: clamp(1rem, 0.9rem + 0.5vw, 1.125rem);       /* 16-18px */
    --fs-lg: clamp(1.125rem, 1rem + 0.625vw, 1.25rem);      /* 18-20px */
    --fs-xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);       /* 20-24px */
    --fs-2xl: clamp(1.5rem, 1.25rem + 1.25vw, 2rem);        /* 24-32px */
    --fs-3xl: clamp(1.75rem, 1.4rem + 1.75vw, 2.5rem);      /* 28-40px */
    --fs-4xl: clamp(2rem, 1.5rem + 2.5vw, 3rem);            /* 32-48px */

    /* Line heights */
    --lh-tight: 1.2;
    --lh-normal: 1.5;
    --lh-relaxed: 1.6;
    --lh-loose: 1.75;

    /* Touch target sizes (WCAG 2.2 AAA) */
    --touch-target-min: 48px;
    --touch-target-spacing: 8px;

    /* Spacing scale */
    --space-xs: 0.25rem;    /* 4px */
    --space-sm: 0.5rem;     /* 8px */
    --space-md: 1rem;       /* 16px */
    --space-lg: 1.5rem;     /* 24px */
    --space-xl: 2rem;       /* 32px */
    --space-2xl: 3rem;      /* 48px */

    /* Border radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
    --transition-slow: 300ms ease;

    /* Focus ring */
    --focus-ring-color: rgba(59, 130, 246, 0.6);
    --focus-ring-offset: 2px;
    --focus-ring-width: 3px;
}

/* ===========================================
   GLOBAL RESETS & BASE STYLES (Mobile-first)
   =========================================== */

/* Modern CSS reset */
*, *::before, *::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

/* Prevent font size inflation on mobile */
html {
    -moz-text-size-adjust: none;
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
    scroll-behavior: smooth;
}

/* Use system fonts for better performance */
body {
    font-family: var(--font-system);
    font-size: var(--fs-base);
    line-height: var(--lh-relaxed);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Remove default list styles */
ul, ol {
    list-style: none;
}

/* Better image defaults */
img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Inherit fonts for form controls */
input, button, textarea, select {
    font: inherit;
}

/* Remove built-in form typography */
button {
    background: none;
    border: none;
    cursor: pointer;
}

/* Avoid text overflows */
p, h1, h2, h3, h4, h5, h6 {
    overflow-wrap: break-word;
}

/* ===========================================
   ACCESSIBILITY IMPROVEMENTS
   =========================================== */

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-md);
    z-index: 9999;
    padding: var(--space-sm) var(--space-md);
    background: var(--accent-blue, #3b82f6);
    color: white;
    font-weight: 600;
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: var(--space-md);
}

/* Focus visible for keyboard users only */
:focus {
    outline: none;
}

:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
    border-radius: var(--radius-sm);
}

/* Remove focus outline for mouse users */
:focus:not(:focus-visible) {
    outline: none;
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ===========================================
   TOUCH-FRIENDLY INTERACTIVE ELEMENTS
   =========================================== */

/* All interactive elements must be at least 48x48px */
a, button, input, select, textarea,
[role="button"], [role="link"], [role="tab"],
.btn, .option, .quiz-option, .nav-btn, .action-btn {
    min-height: var(--touch-target-min);
    touch-action: manipulation; /* Disable double-tap zoom */
}

/* Links with adequate spacing */
a {
    display: inline-block;
    padding: var(--space-xs) 0;
}

/* Buttons with touch-friendly sizing */
button, .btn, [role="button"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    padding: var(--space-sm) var(--space-md);
    gap: var(--space-sm);
    border-radius: var(--radius-md);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition-normal);
    -webkit-tap-highlight-color: transparent;
}

/* Form inputs */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="url"],
input[type="number"],
textarea,
select {
    width: 100%;
    min-height: var(--touch-target-min);
    padding: var(--space-sm) var(--space-md);
    font-size: 16px; /* Prevent iOS zoom on focus */
    border-radius: var(--radius-md);
    border: 1px solid var(--border, #2d2d44);
    background: var(--bg-secondary, #12121f);
    color: var(--text-primary, #f1f5f9);
}

/* Checkboxes and radios */
input[type="checkbox"],
input[type="radio"] {
    width: 24px;
    height: 24px;
    margin: 0;
    cursor: pointer;
}

/* ===========================================
   TYPOGRAPHY (Fluid & Responsive)
   =========================================== */

h1 {
    font-size: var(--fs-3xl);
    font-weight: 800;
    line-height: var(--lh-tight);
    margin-bottom: var(--space-md);
}

h2 {
    font-size: var(--fs-2xl);
    font-weight: 700;
    line-height: var(--lh-tight);
    margin-bottom: var(--space-sm);
}

h3 {
    font-size: var(--fs-xl);
    font-weight: 600;
    line-height: var(--lh-normal);
    margin-bottom: var(--space-sm);
}

h4, h5, h6 {
    font-size: var(--fs-lg);
    font-weight: 600;
    line-height: var(--lh-normal);
    margin-bottom: var(--space-sm);
}

p {
    font-size: var(--fs-base);
    line-height: var(--lh-relaxed);
    margin-bottom: var(--space-md);
    max-width: 65ch; /* Optimal line length */
}

small, .text-sm {
    font-size: var(--fs-sm);
}

.text-xs {
    font-size: var(--fs-xs);
}

/* Code blocks */
code, pre, .code-block {
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
}

/* ===========================================
   LAYOUT CONTAINERS (Mobile-first)
   =========================================== */

.container {
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--space-md);
    padding-right: var(--space-md);
}

/* Tablet and up */
@media (min-width: 768px) {
    .container {
        padding-left: var(--space-lg);
        padding-right: var(--space-lg);
    }
}

/* Desktop */
@media (min-width: 1024px) {
    .container {
        max-width: 1024px;
    }
}

/* Large desktop */
@media (min-width: 1280px) {
    .container {
        max-width: 1200px;
    }
}

/* ===========================================
   RESPONSIVE GRID SYSTEM (Mobile-first)
   =========================================== */

.grid {
    display: grid;
    gap: var(--space-md);
    grid-template-columns: 1fr;
}

/* 2 columns on tablet */
@media (min-width: 640px) {
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Full grid on desktop */
@media (min-width: 1024px) {
    .grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }
    .grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ===========================================
   CARDS & COMPONENTS (Mobile-first)
   =========================================== */

.card {
    padding: var(--space-md);
    border-radius: var(--radius-lg);
    background: var(--bg-card, #1a1a2e);
    border: 1px solid var(--border, #2d2d44);
}

@media (min-width: 768px) {
    .card {
        padding: var(--space-lg);
    }
}

/* ===========================================
   NAVIGATION (Mobile-first)
   =========================================== */

/* Navigation links with adequate spacing */
nav a {
    display: flex;
    align-items: center;
    min-height: var(--touch-target-min);
    padding: var(--space-sm) var(--space-md);
    gap: var(--space-sm);
}

/* Navigation buttons stack on mobile */
.nav-buttons, .actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    width: 100%;
}

.nav-buttons > *, .actions > * {
    width: 100%;
}

/* Side-by-side on larger screens */
@media (min-width: 640px) {
    .nav-buttons, .actions {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .nav-buttons > *, .actions > * {
        width: auto;
        flex: 1;
    }
}

/* ===========================================
   MEDIA QUERY HELPERS (Mobile-first breakpoints)
   =========================================== */

/* Hide on mobile, show on tablet+ */
.hide-mobile {
    display: none;
}

@media (min-width: 768px) {
    .hide-mobile {
        display: block;
    }

    .hide-tablet-up {
        display: none;
    }
}

/* Hide on desktop */
@media (min-width: 1024px) {
    .hide-desktop {
        display: none;
    }
}

/* ===========================================
   ACCESSIBILITY PREFERENCES
   =========================================== */

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

/* High contrast mode support */
@media (prefers-contrast: more) {
    :root {
        --focus-ring-width: 4px;
    }

    .btn, button, a {
        text-decoration: underline;
    }
}

/* Forced colors mode (Windows High Contrast) */
@media (forced-colors: active) {
    .btn, button {
        border: 2px solid currentColor;
    }
}

/* ===========================================
   TOUCH DEVICE OPTIMIZATIONS
   =========================================== */

@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .path-card:hover,
    .lesson-card:hover,
    .grade-card:hover,
    .btn:hover,
    button:hover {
        transform: none;
    }

    /* Active states for touch feedback */
    .path-card:active,
    .lesson-card:active,
    .grade-card:active,
    .btn:active,
    button:active,
    .option:active,
    .quiz-option:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
}

/* ===========================================
   SAFE AREA INSETS (for notched phones)
   =========================================== */

@supports (padding: max(0px)) {
    .container {
        padding-left: max(var(--space-md), env(safe-area-inset-left));
        padding-right: max(var(--space-md), env(safe-area-inset-right));
    }

    footer, .bottom-nav {
        padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
    }
}

/* ===========================================
   PRINT STYLES
   =========================================== */

@media print {
    /* Hide non-essential elements */
    nav, .nav-buttons, .actions, .progress-steps,
    .hint-box, footer, .skip-link {
        display: none !important;
    }

    /* Reset backgrounds and colors */
    body {
        background: white !important;
        color: black !important;
    }

    .container {
        max-width: 100% !important;
        padding: 0 !important;
    }

    /* Show all content */
    .section {
        display: block !important;
    }

    /* Avoid page breaks inside elements */
    .card, .concept-card, .quiz-question {
        page-break-inside: avoid;
    }
}

/* ===========================================
   PERFORMANCE: CONTENT VISIBILITY
   =========================================== */

/* Use content-visibility for off-screen content */
.section:not(.active) {
    content-visibility: auto;
    contain-intrinsic-size: 0 500px;
}

/* ===========================================
   LAZY LOADING PLACEHOLDER
   =========================================== */

img[loading="lazy"] {
    background-color: var(--bg-secondary, #12121f);
    background-image: linear-gradient(
        90deg,
        var(--bg-secondary, #12121f) 0%,
        var(--bg-card, #1a1a2e) 50%,
        var(--bg-secondary, #12121f) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

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

img[loading="lazy"].loaded {
    animation: none;
    background: none;
}
