/**
 * FRANÇAISPRO - ADVANCED MOBILE CSS
 * 
 * Production-ready mobile optimizations for iOS/Android
 * - Touch-optimized interactions (44x44px targets)
 * - Smooth scrolling with Safari compatibility
 * - Safe Area Insets for iPhone notch
 * - Landscape/Portrait handling
 * - Reduced motion support
 * - Performance optimizations
 */

/* ==========================================================================
   1. VIEWPORT & SAFE AREAS (iOS Notch Support)
   ========================================================================== */

:root {
    /* Safe area insets for iPhone X+ notch */
    --safe-area-top: env(safe-area-inset-top);
    --safe-area-bottom: env(safe-area-inset-bottom);
    --safe-area-left: env(safe-area-inset-left);
    --safe-area-right: env(safe-area-inset-right);
    
    /* Touch target minimum size (Apple HIG & Material Design) */
    --min-touch-target: 44px;
}

/* ==========================================================================
   2. SMOOTH SCROLLING (Safari/iOS Compatible)
   ========================================================================== */

html {
    /* Smooth scrolling with Safari support */
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch; /* iOS momentum scrolling */
    
    /* Prevent text size adjustment on orientation change (iOS) */
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    /* Prevent overscroll bounce on iOS */
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: touch;
    
    /* Safe area padding for notch */
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
    padding-left: var(--safe-area-left);
    padding-right: var(--safe-area-right);
}

/* ==========================================================================
   3. NAVIGATION & HEADER - MOBILE OPTIMIZED
   ========================================================================== */

/* Sticky navigation with safe area */
@media (max-width: 1024px) {
    .neural-nav {
        position: sticky;
        top: 0;
        top: var(--safe-area-top);
        z-index: 1000;
        padding-top: calc(0.5rem + var(--safe-area-top));
    }
    
    /* Horizontal scrolling navigation */
    .neural-nav .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE/Edge */
    }
    
    .neural-nav .overflow-x-auto::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }
    
    /* Touch-optimized nav buttons */
    .nav-btn {
        min-height: var(--min-touch-target);
        min-width: 120px;
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        white-space: nowrap;
    }
}

/* ==========================================================================
   4. RESPONSIVE BREAKPOINTS
   ========================================================================== */

/* Extra Small Devices (iPhone SE, small Android) */
@media (max-width: 374px) {
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    /* Smaller text for tiny screens */
    h1 { font-size: 1.5rem !important; }
    h2 { font-size: 1.25rem !important; }
    h3 { font-size: 1.1rem !important; }
    
    /* Reduce padding in cards */
    .glass-card {
        padding: 1rem !important;
    }
    
    /* Stack gamification stats vertically */
    #gamification-display {
        display: none !important; /* Hide on smallest screens */
    }
}

/* Small Devices (iPhone 12/13, standard Android) */
@media (min-width: 375px) and (max-width: 767px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    /* Optimize card layouts */
    .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-3 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    /* Better button spacing */
    button {
        min-height: var(--min-touch-target);
        padding: 0.75rem 1.5rem;
    }
}

/* Tablets (iPad, large Android tablets) */
@media (min-width: 768px) and (max-width: 1023px) {
    .container {
        max-width: 720px;
    }
    
    /* 2-column grid for cards */
    .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-3 {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
}

/* ==========================================================================
   5. FORM CONTROLS - TOUCH OPTIMIZED
   ========================================================================== */

@media (max-width: 1024px) {
    /* Larger touch targets for inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        min-height: var(--min-touch-target);
        padding: 0.875rem;
        font-size: 16px; /* Prevents iOS zoom on focus */
        border-radius: 0.5rem;
    }
    
    /* Textarea minimum height */
    textarea {
        min-height: 120px;
        resize: vertical;
    }
    
    /* Select dropdowns */
    select {
        background-position: right 0.75rem center;
        background-size: 1rem;
        padding-right: 2.5rem;
    }
    
    /* Buttons touch-friendly */
    button,
    .btn,
    [role="button"] {
        min-height: var(--min-touch-target);
        min-width: var(--min-touch-target);
        padding: 0.75rem 1.5rem;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
    
    /* Remove iOS button styles */
    button,
    input,
    select,
    textarea {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }
}

/* ==========================================================================
   6. LANDSCAPE MODE OPTIMIZATIONS
   ========================================================================== */

@media (max-height: 500px) and (orientation: landscape) {
    /* Reduce vertical spacing in landscape */
    .py-8 { padding-top: 1rem !important; padding-bottom: 1rem !important; }
    .py-12 { padding-top: 2rem !important; padding-bottom: 2rem !important; }
    .mb-6 { margin-bottom: 1rem !important; }
    .mb-8 { margin-bottom: 1.5rem !important; }
    
    /* Sticky header more compact */
    .neural-nav {
        padding-top: 0.25rem;
        padding-bottom: 0.25rem;
    }
    
    .neural-nav .h-16 {
        height: 3rem;
    }
}

/* ==========================================================================
   7. TOUCH INTERACTIONS & GESTURES
   ========================================================================== */

@media (max-width: 1024px) {
    /* Remove hover effects on touch devices */
    @media (hover: none) {
        .hover\:bg-gray-700:hover,
        .hover\:bg-indigo-700:hover,
        .hover\:text-cyan-300:hover {
            background-color: inherit;
            color: inherit;
        }
    }
    
    /* Active/pressed states for touch */
    button:active,
    .btn:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
    
    /* Flashcard touch interaction */
    .vocabulary-card {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    /* Prevent accidental zooming */
    .prevent-zoom {
        touch-action: pan-y;
    }
}

/* ==========================================================================
   8. MODALS & OVERLAYS - MOBILE FRIENDLY
   ========================================================================== */

@media (max-width: 768px) {
    /* Full-screen modals on mobile */
    .modal,
    .overlay {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        margin: 0;
    }
    
    /* Modal safe areas */
    .modal-content {
        padding-top: calc(1rem + var(--safe-area-top));
        padding-bottom: calc(1rem + var(--safe-area-bottom));
        max-height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ==========================================================================
   9. PERFORMANCE OPTIMIZATIONS
   ========================================================================== */

@media (max-width: 1024px) {
    /* Hardware acceleration for smooth animations */
    .animated-gradient,
    .neon-border,
    .glass-card,
    .nav-btn {
        will-change: transform;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    /* Disable expensive animations on low-end devices */
    @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;
        }
    }
    
    /* Reduce glassmorphism blur on mobile for performance */
    .glass-card {
        backdrop-filter: blur(8px); /* Reduced from 12px */
        -webkit-backdrop-filter: blur(8px);
    }
}

/* ==========================================================================
   10. TEXT READABILITY ON MOBILE
   ========================================================================== */

@media (max-width: 768px) {
    /* Better line height for reading */
    p, li, div {
        line-height: 1.6;
    }
    
    /* Prevent text overflow */
    .text-overflow-mobile {
        overflow-wrap: break-word;
        word-wrap: break-word;
        hyphens: auto;
    }
    
    /* Larger font sizes for better readability */
    body {
        font-size: 16px;
    }
    
    .text-sm {
        font-size: 0.875rem !important;
    }
    
    .text-xs {
        font-size: 0.8125rem !important;
    }
}

/* ==========================================================================
   11. SAFARI & iOS SPECIFIC FIXES
   ========================================================================== */

@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific fixes */
    
    /* Fix 100vh on iOS (viewport bug) */
    .min-h-screen {
        min-height: -webkit-fill-available;
    }
    
    /* Fix sticky footer on iOS */
    body {
        min-height: -webkit-fill-available;
    }
    
    /* Fix input zoom on iOS */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        font-size: 16px; /* Prevents auto-zoom */
    }
    
    /* Fix sticky elements on iOS */
    .sticky {
        position: -webkit-sticky;
        position: sticky;
    }
}

/* ==========================================================================
   12. DARK MODE SPECIFIC (GLOBAL - ALL SCREEN SIZES)
   ========================================================================== */

/* Better placeholder contrast - APPLIES TO ALL BREAKPOINTS */
/* Using [data-theme="dark"] selector to match app's theme system */
[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
    color: rgb(156 163 175) !important;  /* gray-400 */
    opacity: 0.8;
}

/* Light mode placeholders for consistency */
[data-theme="light"] input::placeholder,
[data-theme="light"] textarea::placeholder,
input::placeholder,
textarea::placeholder {
    color: rgb(107 114 128);  /* gray-500 */
    opacity: 0.7;
}

@media (max-width: 1024px) {
    [data-theme="dark"] {
        /* Better contrast on small screens */
        --tw-bg-opacity: 1;
        background-color: rgb(17 24 39 / var(--tw-bg-opacity));
    }
    
    /* Input fields dark mode mobile */
    [data-theme="dark"] input,
    [data-theme="dark"] textarea,
    [data-theme="dark"] select {
        background-color: rgb(31 41 55);
        border-color: rgb(75 85 99);
        color: rgb(243 244 246);
    }
}

/* ==========================================================================
   13. ACCESSIBILITY - MOBILE FOCUS STATES
   ========================================================================== */

@media (max-width: 1024px) {
    /* Larger focus outlines for touch */
    button:focus-visible,
    input:focus-visible,
    select:focus-visible,
    textarea:focus-visible,
    a:focus-visible {
        outline: 3px solid currentColor;
        outline-offset: 3px;
    }
    
    /* Remove focus outline for mouse users */
    button:focus:not(:focus-visible),
    input:focus:not(:focus-visible),
    select:focus:not(:focus-visible),
    textarea:focus:not(:focus-visible) {
        outline: none;
    }
}

/* ==========================================================================
   14. LOADING STATES & SPINNERS - MOBILE
   ========================================================================== */

@media (max-width: 768px) {
    .loading-spinner {
        width: 2.5rem;
        height: 2.5rem;
        border-width: 3px;
    }
    
    /* Center loading states */
    .loading-container {
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 50vh;
    }
}

/* ==========================================================================
   15. PRINT STYLES (BONUS)
   ========================================================================== */

@media print {
    /* Hide navigation */
    .neural-nav,
    button,
    .btn,
    #theme-toggle,
    #gamification-display {
        display: none !important;
    }
    
    /* Optimize for printing */
    body {
        background: white;
        color: black;
    }
    
    .glass-card {
        border: 1px solid #ccc;
        background: white;
    }
}
