/* ============================================
   MOBILE OPTIMIZATION FIXES
   Add this file AFTER responsive.css
   ============================================ */

/* ============================================
   FIX 1: backdrop-filter performance
   Remove expensive blur on mobile devices
   ============================================ */
@media (max-width: 768px) {
    .flashcard-container {
        /* Remove expensive backdrop-filter on mobile */
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        /* Compensate with slightly more opaque background */
        background: rgba(255, 255, 255, 0.98);
    }
}

/* ============================================
   FIX 2: background-attachment: fixed
   iOS doesn't support fixed backgrounds properly
   ============================================ */
@supports (-webkit-touch-callout: none) {
    /* iOS-specific fix */
    body.time-morning,
    body.time-afternoon,
    body.time-evening,
    body.time-night {
        background-attachment: scroll !important;
    }
}

@media (max-width: 768px) {
    /* All mobile devices - use scroll instead of fixed */
    body {
        background-attachment: scroll !important;
    }
    
    body.time-morning,
    body.time-afternoon,
    body.time-evening,
    body.time-night {
        background-attachment: scroll !important;
    }
}

/* ============================================
   FIX 3: Touch target sizing
   Ensure all interactive elements are 44x44px minimum
   ============================================ */
@media (max-width: 768px) {
    /* Hamburger menu - increase to Apple minimum */
    .hamburger-menu {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Quiz mode buttons - make them more tappable */
    .quiz-mode-btn,
    .reading-toggle-btn {
        min-height: 44px;
        padding: 12px 16px;
        font-size: 13px;
    }
    
    /* Footer buttons */
    .footer-btn {
        min-height: 44px;
        padding: 12px 20px;
    }
    
    /* Tab buttons */
    .tab-button {
        min-height: 44px;
        padding: 12px 20px;
    }
    
    /* Quiz options - ensure comfortable tap area */
    .quiz-option {
        min-height: 48px;
        padding: 14px 18px;
    }
    
    /* Dropdown menu items */
    .filter-option,
    .level-option {
        min-height: 48px;
        padding: 14px 20px;
    }
    
    /* Toggle switches - larger tap area */
    .toggle-switch {
        width: 52px;
        height: 28px;
    }
    
    .toggle-slider:before {
        height: 22px;
        width: 22px;
        left: 3px;
        bottom: 3px;
    }
    
    input:checked + .toggle-slider:before {
        transform: translateX(24px);
    }
    
    /* Kana toggle - ensure tappable */
    .kana-toggle-container {
        min-height: 36px;
        padding: 8px 14px;
    }
}

/* ============================================
   FIX 4: Prevent text selection on buttons
   Improves touch feel
   ============================================ */
.btn,
.footer-btn,
.quiz-mode-btn,
.reading-toggle-btn,
.tab-button,
.quiz-option,
.filter-option,
.level-option,
.hamburger-menu,
.audio-button,
.quiz-audio-button {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* ============================================
   FIX 5: Smooth scrolling and momentum
   ============================================ */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.learning-info-content,
.dropdown-menu {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* ============================================
   FIX 6: Safe area insets for notched devices
   ============================================ */
@supports (padding: max(0px)) {
    body {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    
    .flashcard-container {
        /* Ensure content doesn't get hidden behind notch */
        margin-left: env(safe-area-inset-left);
        margin-right: env(safe-area-inset-right);
    }
}

/* ============================================
   FIX 7: Prevent zoom on input focus (iOS)
   ============================================ */
@media (max-width: 768px) {
    input, 
    textarea, 
    select {
        font-size: 16px !important; /* Prevents iOS zoom */
    }
}

/* ============================================
   FIX 8: Active states for better touch feedback
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Touch devices - use active instead of hover */
    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    .quiz-option:active {
        transform: scale(0.99);
        background: #f5f5f5;
    }
    
    .footer-btn:active,
    .quiz-mode-btn:active,
    .tab-button:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    /* Remove hover effects that feel janky on touch */
    .btn:hover,
    .quiz-option:hover,
    .footer-btn:hover {
        transform: none;
    }
}

/* ============================================
   FIX 9: Optimize animations for mobile
   Reduce complexity on lower-powered devices
   ============================================ */
@media (max-width: 480px) {
    /* Simpler transitions on small devices */
    .flashcard,
    .quiz-option,
    .btn {
        transition-duration: 0.2s;
    }
    
    /* Reduce shadow complexity */
    .flashcard-container {
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
    }
    
    .flashcard:hover {
        box-shadow: 0 6px 16px rgba(56, 142, 60, 0.12);
    }
}

/* ============================================
   FIX 10: PWA standalone mode adjustments
   ============================================ */
@media (display-mode: standalone) {
    /* When running as installed PWA */
    body {
        /* Slightly taller to account for no browser UI */
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
    
    .flashcard-container {
        /* More padding at top for status bar */
        margin-top: env(safe-area-inset-top, 20px);
    }
}

/* ============================================
   FIX 11: Capacitor-specific adjustments
   Prepare for native app wrapper
   ============================================ */
.capacitor-ios body,
.capacitor-android body {
    /* Disable pull-to-refresh in app */
    overscroll-behavior-y: none;
}

.capacitor-ios .flashcard-container {
    /* iOS status bar padding */
    padding-top: max(40px, env(safe-area-inset-top));
}

/* ============================================
   FIX 12: Offline indicator styling
   ============================================ */
.offline-indicator {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #ff9800;
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 9999;
    display: none;
}

.offline-indicator.show {
    display: block;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}
