/**
 * Android Performance Fixes
 * Addresses flickering, flashing, and performance issues on Android devices
 */

/* ========================================
   FIX 1: Android Scroll Flickering
   ======================================== */
@media screen and (max-width: 768px) {
    /* Prevent scroll jank/flickering on Android */
    * {
        -webkit-overflow-scrolling: touch !important;
        -webkit-tap-highlight-color: transparent !important;
    }
    
    html, body {
        /* Smooth scrolling without flicker */
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        /* Prevent background attachment flicker */
        background-attachment: scroll !important;
        /* Hardware acceleration */
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }
    
    /* Prevent white flash during scroll */
    body {
        background-color: #FFF9E6 !important;
        min-height: 100vh;
    }
    
    /* Smoother scrolling for containers */
    .menu-container,
    .quiz-container,
    #honeyLoader,
    #systemChecks {
        -webkit-overflow-scrolling: touch;
        will-change: scroll-position;
    }
}

/* ========================================
   FIX 2: Disable backdrop-filter (causes flickering)
   ======================================== */
@media screen and (max-width: 768px) {
    /* Replace backdrop-filter with solid semi-transparent background on mobile */
    *[style*="backdrop-filter"] {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    
    /* Override inline backdrop-filter styles */
    .modal-content,
    .bee-prompt,
    .bee-confirm,
    .loading-overlay,
    #beePromptModal,
    #beeConfirmModal {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
}

/* ========================================
   FIX 3: Reduce animation intensity
   ======================================== */
@media screen and (max-width: 768px) {
    /* Slow down rapid animations that cause flashing */
    *[style*="animation: flash-light"],
    *[style*="animation:flash-light"] {
        animation-duration: 1.5s !important;
        animation-iteration-count: 3 !important;
    }
    
    /* Disable infinite alternating animations on mobile */
    @keyframes flash-light {
        from { opacity: 1; }
        to { opacity: 0.5; }
    }
    
    /* Hardware acceleration for smoother animations */
    * {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        -webkit-perspective: 1000;
        perspective: 1000;
    }
    
    /* Reduce motion for accessibility */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
}

/* ========================================
   FIX 4: Position fixes - prevent blank space
   ======================================== */
@media screen and (max-width: 768px) {
    /* Ensure content starts at top of viewport */
    body {
        padding-top: 0 !important;
        margin-top: 0 !important;
    }
    
    /* Fix loading screen position */
    #honeyLoader {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        margin: 0 !important;
    }
    
    /* Disable problematic 3D transforms on lower-end Android */
    @media (max-device-pixel-ratio: 2) {
        .mascot-3d-container,
        canvas {
            transform: none !important;
            -webkit-transform: none !important;
        }
    }
}
