/* ========================================= */
/* iPhone-Specific Optimizations */
/* ========================================= */

/* Fix for iOS Safari black screen issue */
@supports (-webkit-touch-callout: none) {
    /* Override the problematic body fixed positioning */
    body {
        position: relative !important;
        overflow-x: hidden !important;
        overflow-y: scroll !important;
        width: 100% !important;
        height: auto !important;
        min-height: 100vh !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Fix viewport height for iOS Safari */
    html {
        height: 100%;
        overflow-x: hidden;
    }
    
    /* Hero section iOS fixes */
    .hero {
        min-height: 100vh !important;
        min-height: -webkit-fill-available !important;
        height: 100vh !important;
        position: relative !important;
        overflow: hidden !important;
    }
    
    /* Video optimization for iOS */
    .hero-video,
    .showcase-video {
        -webkit-transform: translateZ(0) !important;
        transform: translateZ(0) !important;
        -webkit-backface-visibility: hidden !important;
        backface-visibility: hidden !important;
        will-change: transform, opacity !important;
        /* Ensure video is visible immediately - override animations */
        opacity: 1 !important;
        visibility: visible !important;
        display: block !important;
        /* Disable the zoom animation on iPhone for immediate display */
        -webkit-animation: none !important;
        animation: none !important;
    }
    
    /* Force video to play inline on iOS */
    video {
        -webkit-transform: translate3d(0, 0, 0) !important;
        transform: translate3d(0, 0, 0) !important;
    }
    
    /* Fix for iOS Safari address bar */
    .navbar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        z-index: 10000 !important;
    }
    
    /* Ensure content is visible */
    .hero-content {
        position: relative !important;
        z-index: 10 !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    .hero-background {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        z-index: 1 !important;
        overflow: hidden !important;
    }
    
    .hero-overlay {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        z-index: 2 !important;
        pointer-events: none !important;
    }
    
    /* Fix for iOS video autoplay */
    .hero-video {
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        min-width: 100% !important;
        min-height: 100% !important;
        width: auto !important;
        height: auto !important;
        -webkit-transform: translate(-50%, -50%) !important;
        transform: translate(-50%, -50%) !important;
        object-fit: cover !important;
        -o-object-fit: cover !important;
    }
    
    /* Ensure sections are visible */
    .section {
        position: relative !important;
        background-color: #ffffff !important;
        min-height: auto !important;
    }
    
    /* Fix for work section videos */
    .video-showcase {
        position: relative !important;
        z-index: 1 !important;
    }
    
    .video-container {
        position: relative !important;
        overflow: hidden !important;
        background-color: #000000 !important;
    }
    
    .video-wrapper {
        position: relative !important;
        overflow: hidden !important;
        background-color: #000000 !important;
    }
    
    .showcase-video {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        -o-object-fit: cover !important;
    }
}

/* iPhone-specific media queries */
@media only screen 
    and (min-device-width: 375px) 
    and (max-device-width: 932px) 
    and (-webkit-min-device-pixel-ratio: 2) {
    
    /* iPhone 14 Pro Max, 15 Pro Max, etc. */
    .hero {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
    
    /* Optimize video performance */
    .hero-video,
    .showcase-video {
        -webkit-filter: brightness(0.9) contrast(1.1);
        filter: brightness(0.9) contrast(1.1);
    }
    
    /* Better text rendering */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }
    
    /* Fix for notch/Dynamic Island */
    .navbar {
        padding-top: max(env(safe-area-inset-top), 0px);
    }
    
    .hero {
        padding-top: max(env(safe-area-inset-top), 0px);
    }
}

/* iPhone in landscape mode */
@media only screen 
    and (min-device-width: 375px) 
    and (max-device-width: 932px) 
    and (-webkit-min-device-pixel-ratio: 2)
    and (orientation: landscape) {
    
    .hero {
        min-height: 100vh;
        height: auto;
    }
    
    .hero-title {
        font-size: clamp(2rem, 6vw, 3.5rem) !important;
        margin-bottom: 1rem !important;
    }
    
    .hero-subtitle {
        font-size: 0.95rem !important;
        margin-bottom: 1.5rem !important;
    }
    
    .scroll-indicator {
        display: none !important;
    }
}

/* Fix for iOS Safari video loading */
@supports (-webkit-touch-callout: none) {
    /* Ensure video loads properly */
    video::-webkit-media-controls-start-playback-button {
        display: none !important;
        -webkit-appearance: none !important;
    }
    
    /* Hide default video controls on iOS */
    video::-webkit-media-controls {
        display: none !important;
    }
    
    video::-webkit-media-controls-panel {
        display: none !important;
    }
    
    video::-webkit-media-controls-play-button {
        display: none !important;
    }
}

/* Prevent iOS zoom on input focus */
@supports (-webkit-touch-callout: none) {
    input,
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Fix for iOS Safari rubber band effect - REMOVED TO ENABLE SCROLLING */
/* The previous fix was preventing scrolling on iPhone */

/* Optimize animations for iOS - SIMPLIFIED */
@supports (-webkit-touch-callout: none) {
    /* Only apply GPU acceleration to videos */
    .hero-video,
    .showcase-video {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
}

/* Fix for iOS Safari black screen on page load */
@supports (-webkit-touch-callout: none) {
    body {
        background-color: #ffffff !important;
    }
    
    .hero {
        background-color: #000000 !important;
    }
    
    /* Ensure all sections have proper background */
    .work-section,
    .services-section,
    .about-section,
    .team-section,
    .contact-section {
        background-color: #ffffff !important;
    }
}

/* Disable card animations on iPhone for index page */
@supports (-webkit-touch-callout: none) {
    /* Disable video container animations */
    .video-container {
        -webkit-animation: none !important;
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
    
    /* Disable service item animations */
    .service-item {
        -webkit-animation: none !important;
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
    
    /* Disable team member animations */
    .team-member {
        -webkit-animation: none !important;
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
    
    /* Disable work item animations */
    .work-item {
        -webkit-animation: none !important;
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
    
    /* Disable stat item animations */
    .stat-item {
        -webkit-animation: none !important;
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
    
    /* Disable section title animations */
    .section-title {
        -webkit-animation: none !important;
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
    
    /* Fix flip card - remove ALL animations on iPhone */
    .flip-card {
        cursor: pointer !important;
        -webkit-tap-highlight-color: rgba(255, 107, 53, 0.2) !important;
        -webkit-animation: none !important;
        animation: none !important;
        transition: none !important;
        -webkit-transition: none !important;
    }
    
    .flip-card * {
        -webkit-animation: none !important;
        animation: none !important;
        transition: none !important;
        -webkit-transition: none !important;
    }
    
    .flip-card-inner {
        -webkit-animation: none !important;
        animation: none !important;
        transition: none !important;
        -webkit-transition: none !important;
        -webkit-transform: none !important;
        transform: none !important;
        position: relative !important;
        -webkit-transform-style: flat !important;
        transform-style: flat !important;
    }
    
    .flip-card-front,
    .flip-card-back {
        position: absolute !important;
        width: 100% !important;
        height: 100% !important;
        top: 0 !important;
        left: 0 !important;
        -webkit-animation: none !important;
        animation: none !important;
        transition: none !important;
        -webkit-transition: none !important;
        -webkit-transform: none !important;
        transform: none !important;
        -webkit-backface-visibility: visible !important;
        backface-visibility: visible !important;
    }
    
    .flip-card-front {
        z-index: 2 !important;
        opacity: 1 !important;
        visibility: visible !important;
        display: block !important;
    }
    
    .flip-card-back {
        z-index: 1 !important;
        opacity: 0 !important;
        visibility: hidden !important;
        display: none !important;
    }
    
    /* Ensure card images are loaded and visible - NO animations */
    .flip-card-front img,
    .flip-card-back img {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
        -o-object-fit: cover !important;
        display: block !important;
        -webkit-animation: none !important;
        animation: none !important;
        transition: none !important;
        -webkit-transition: none !important;
        -webkit-transform: none !important;
        transform: none !important;
    }
    
    /* Disable any fade-in animations */
    [data-aos] {
        -webkit-animation: none !important;
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }
}

/* iOS-specific touch optimizations */
@supports (-webkit-touch-callout: none) {
    /* Improve touch responsiveness */
    a,
    button,
    .nav-link,
    .cta-button,
    .hamburger {
        -webkit-tap-highlight-color: rgba(255, 107, 53, 0.2);
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Prevent text selection on double tap */
    * {
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Allow text selection for content */
    p,
    span,
    h1, h2, h3, h4, h5, h6,
    input,
    textarea {
        -webkit-user-select: text;
        user-select: text;
    }
}

/* Fix for iOS video poster/thumbnail */
@supports (-webkit-touch-callout: none) {
    video {
        background-color: #000000;
    }
    
    video::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: #000000;
        z-index: -1;
    }
}

/* Performance optimizations for iPhone */
@supports (-webkit-touch-callout: none) {
    /* Reduce motion for better performance */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
    
    /* Optimize scrolling performance */
    .section {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        will-change: scroll-position;
    }
}

/* Fix for iOS Safari viewport units */
@supports (-webkit-touch-callout: none) {
    /* Use CSS custom properties for viewport height */
    :root {
        --vh: 1vh;
    }
    
    .hero {
        height: calc(var(--vh, 1vh) * 100);
        min-height: calc(var(--vh, 1vh) * 100);
    }
}

/* Ensure proper z-index stacking on iOS */
@supports (-webkit-touch-callout: none) {
    .navbar {
        z-index: 10000 !important;
        isolation: isolate;
    }
    
    .hero {
        z-index: 1;
        isolation: isolate;
    }
    
    .hero-background {
        z-index: 1;
    }
    
    .hero-overlay {
        z-index: 2;
    }
    
    .hero-content {
        z-index: 10;
    }
}

/* Fix for iOS Safari video flickering */
@supports (-webkit-touch-callout: none) {
    video {
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        -webkit-perspective: 1000;
        perspective: 1000;
    }
}
