/* Apple Device Specific Fixes and Optimizations */

/* iOS Safe Area Support for iPhone X and newer */
@supports (padding: env(safe-area-inset-top)) {
    /* Account for notch and home indicator */
    .navbar {
        padding-top: env(safe-area-inset-top);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    .container {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .scroll-to-top {
        bottom: calc(2rem + env(safe-area-inset-bottom)) !important;
        right: calc(2rem + env(safe-area-inset-right)) !important;
    }
    
    .cookie-banner {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    /* Mobile menu safe areas */
    .nav-menu {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* iPhone SE, 6, 7, 8 (375px width) */
@media screen and (min-width: 375px) and (max-width: 389px) {
    .hero h1 {
        font-size: 1.875rem;
        line-height: 1.2;
    }
    
    .hero-subtitle {
        font-size: 1rem;
    }
    
    .hero-description {
        font-size: 0.9375rem;
    }
    
    .btn {
        font-size: 0.9375rem;
        padding: 0.9375rem 1.5rem;
    }
    
    .tech-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.625rem;
    }
    
    .stats-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* iPhone 12/13/14/15 Pro (390px width) */
@media screen and (min-width: 390px) and (max-width: 413px) {
    .container {
        padding: 0 1.125rem;
    }
    
    .hero h1 {
        font-size: 2rem;
    }
    
    .section-title {
        font-size: 1.625rem;
    }
    
    .project-card {
        padding: 1.5rem;
    }
}

/* iPhone Plus/Max models (414px-430px width) */
@media screen and (min-width: 414px) and (max-width: 430px) {
    .hero h1 {
        font-size: 2.125rem;
    }
    
    .container {
        padding: 0 1.25rem;
    }
    
    .tech-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* iPad Mini (744px width) */
@media screen and (min-width: 744px) and (max-width: 767px) {
    .hero-content {
        flex-direction: row;
        text-align: left;
    }
    
    .hero-image {
        display: block;
        margin-left: 2rem;
    }
    
    .projects-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .nav-menu {
        display: flex;
        position: static;
        flex-direction: row;
        background: transparent;
    }
    
    .mobile-menu-toggle {
        display: none;
    }
}

/* iPad Air/Pro 11" (820px-834px width) */
@media screen and (min-width: 820px) and (max-width: 834px) {
    .container {
        max-width: 780px;
    }
    
    .hero-content {
        gap: 3rem;
    }
    
    .projects-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
}

/* iPad Pro 12.9" (1024px width) */
@media screen and (min-width: 1024px) and (max-width: 1112px) {
    .container {
        max-width: 980px;
    }
    
    .projects-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .tech-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* iOS Specific Fixes */
@supports (-webkit-touch-callout: none) {
    /* Disable tap highlight */
    a, button {
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Fix iOS bounce scrolling */
    .nav-menu,
    .modal-content,
    [data-scrollable] {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Prevent text size adjustment */
    body {
        -webkit-text-size-adjust: 100%;
    }
    
    /* Fix position sticky on iOS */
    .navbar {
        position: -webkit-sticky;
        position: sticky;
    }
    
    /* Smooth scrolling for iOS */
    html {
        scroll-behavior: smooth;
        -webkit-scroll-behavior: smooth;
    }
    
    /* Fix iOS input zoom */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px !important; /* Prevents zoom on focus */
    }
    
    /* iOS momentum scrolling */
    .scroll-container {
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch;
    }
}

/* Safari Specific Fixes */
@media not all and (min-resolution:.001dpcm) {
    @supports (-webkit-appearance:none) {
        /* Fix Safari flexbox issues */
        .hero-content,
        .nav-container,
        .stats-container {
            display: -webkit-flex;
            display: flex;
        }
        
        /* Fix Safari grid issues */
        .tech-grid,
        .projects-grid {
            display: -webkit-grid;
            display: grid;
        }
        
        /* Safari backdrop-filter support */
        .navbar {
            -webkit-backdrop-filter: blur(10px);
            backdrop-filter: blur(10px);
        }
    }
}

/* Retina Display Optimizations */
@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 192dpi) {
    /* Thinner borders for retina */
    .btn,
    .card,
    .input {
        border-width: 0.5px;
    }
    
    /* Crisp images */
    img {
        image-rendering: -webkit-optimize-contrast;
    }
    
    /* Sharp text */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* MacBook Touch Bar Support */
@media (display-mode: fullscreen) {
    .navbar {
        padding-top: 20px; /* Account for Touch Bar */
    }
}

/* iOS Landscape Optimizations */
@media screen and (max-width: 926px) and (orientation: landscape) {
    /* iPhone landscape */
    .hero {
        min-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        padding: 2rem 0;
    }
    
    .navbar {
        padding-top: 0;
        padding-bottom: 0;
    }
    
    .nav-container {
        min-height: 44px;
    }
    
    /* Hide less important elements in landscape */
    .hero-tagline,
    .social-links {
        display: none;
    }
    
    .section-header {
        margin-bottom: 1rem;
    }
    
    section {
        padding: 1.5rem 0;
    }
}

/* iPad Landscape Specific */
@media screen and (min-width: 1024px) and (max-width: 1366px) and (orientation: landscape) {
    .hero {
        min-height: calc(100vh - 80px);
    }
    
    .hero-content {
        padding: 2rem 0;
    }
}

/* iOS Dark Mode Optimizations */
@media (prefers-color-scheme: dark) {
    @supports (-webkit-touch-callout: none) {
        /* iOS specific dark mode adjustments */
        [data-theme="dark"] {
            --gray-900: #000000; /* True black for OLED iPhones */
            --gray-50: #0a0a0a;
        }
        
        /* Status bar color */
        [data-theme="dark"] .navbar {
            background: rgba(0, 0, 0, 0.95);
        }
    }
}

/* iOS 15+ Focus State */
@supports (accent-color: auto) {
    input[type="checkbox"],
    input[type="radio"] {
        accent-color: var(--primary);
    }
    
    :focus-visible {
        outline: 2px solid var(--primary);
        outline-offset: 2px;
    }
}

/* Prevent iOS callout menus */
.no-select {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* iOS Keyboard Handling */
@supports (-webkit-touch-callout: none) {
    /* When keyboard is open */
    .keyboard-open {
        height: 100vh;
        overflow: hidden;
    }
    
    .keyboard-open .navbar {
        position: absolute;
    }
}

/* Performance optimizations for older iOS devices */
@media screen and (max-width: 768px) {
    @supports (-webkit-touch-callout: none) {
        /* Disable expensive effects */
        .parallax,
        [data-parallax] {
            transform: none !important;
        }
        
        /* 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;
            }
        }
    }
}

/* iOS PWA Specific Styles */
@media (display-mode: standalone) {
    /* Adjust for PWA status bar */
    .navbar {
        padding-top: calc(20px + env(safe-area-inset-top));
    }
    
    /* PWA specific navigation */
    .pwa-navigation {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--white);
        border-top: 1px solid var(--gray-200);
        padding-bottom: env(safe-area-inset-bottom);
    }
}