/* Safari Mobile Specific Rules for ForrestJordan.art 
   These rules target Safari's specific rendering quirks and behaviors */

/* Safari iOS specific media query */
@supports (-webkit-touch-callout: none) {
    /* Safari-specific navigation fixes */
    nav {
        -webkit-overflow-scrolling: touch !important;
        scroll-behavior: smooth;
        /* Fix Safari's momentum scrolling on navigation */
        overflow-x: auto !important;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    nav::-webkit-scrollbar {
        display: none !important;
    }

    /* Safari viewport height issues - use -webkit-fill-available */
    .main-content {
        min-height: -webkit-fill-available;
        background: #fff !important;
        color: #222 !important;
    }

    /* Ensure body stays light themed */
    body {
        background: #f7f7f7 !important;
        color: #222 !important;
    }

    /* Ensure header stays light themed */
    header {
        background: #fff !important;
        color: #222 !important;
    }

    /* Safari image rendering improvements */
    .carousel-img-large,
    .thumbnail,
    .grid-item .thumbnail {
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        image-rendering: -webkit-optimize-contrast;
    }

    /* Fix Safari's flexbox gap issues */
    .carousel-multi {
        gap: 12px !important;
        -webkit-gap: 12px !important;
    }

    .gallery-grid {
        gap: 8px !important;
        -webkit-gap: 8px !important;
    }

    /* Safari touch action improvements */
    .carousel-btn,
    .grid-item,
    nav a {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        touch-action: manipulation;
    }

    /* Safari-specific text rendering */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }
}

/* Safari on iOS specific viewport and orientation fixes */
@media screen and (-webkit-min-device-pixel-ratio: 1) and (orientation: portrait) {
    /* Portrait mode adjustments for Safari */
    .main-content {
        max-width: 100vw;
        margin: 8px auto;
        padding: 12px 8px;
    }

    /* Ensure proper image scaling in Safari portrait */
    .carousel-img-large {
        width: calc(100vw - 32px) !important;
        max-width: calc(100vw - 32px) !important;
        height: auto !important;
        object-fit: contain;
    }

    /* Gallery grid adjustments for Safari portrait */
    .grid-4x5 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }

    .grid-4x5 .thumbnail {
        width: 100% !important;
        height: 180px !important;
        min-height: 180px !important;
        object-fit: cover !important;
        border-radius: 8px !important;
    }
}

@media screen and (-webkit-min-device-pixel-ratio: 1) and (orientation: landscape) {
    /* Landscape mode adjustments for Safari */
    .carousel-img-large {
        max-height: 50vh !important;
        width: auto !important;
        max-width: 90vw !important;
    }

    /* Better navigation spacing in landscape */
    nav {
        gap: 16px !important;
        padding: 0 16px !important;
    }

    nav a {
        font-size: 1rem !important;
        padding: 8px 12px !important;
    }
}

/* Safari-specific small screen fixes */
@media screen and (max-width: 480px) and (-webkit-min-device-pixel-ratio: 1) {
    /* Address Safari's address bar height issues */
    .main-content {
        min-height: calc(100vh - 120px);
        min-height: calc(100dvh - 120px); /* Dynamic viewport height for newer Safari */
    }

    /* Safari-specific navigation centering */
    header {
        position: relative;
    }

    nav {
        justify-content: flex-start !important;
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* Ensure first nav item (Home) is visible */
    nav a:first-child {
        margin-left: 0 !important;
        flex-shrink: 0 !important;
    }

    /* Safari-specific grid improvements */
    .grid-4x5 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        padding: 0 8px !important;
    }

    .grid-4x5 .thumbnail {
        height: 160px !important;
        min-height: 160px !important;
        object-fit: cover !important;
        border-radius: 8px !important;
    }

    /* Safari carousel touch improvements */
    .carousel-section {
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x pan-y;
    }

    .thumbs-inner {
        -webkit-overflow-scrolling: touch !important;
        scroll-behavior: smooth;
    }
}

/* Safari on older iOS versions (iOS 12-14) */
@media screen and (max-width: 600px) and (-webkit-min-device-pixel-ratio: 1) {
    /* Fallback flexbox support for older Safari */
    .carousel-multi {
        display: -webkit-flex !important;
        display: flex !important;
        -webkit-flex-direction: column !important;
        flex-direction: column !important;
        -webkit-align-items: center !important;
        align-items: center !important;
    }

    /* Ensure proper grid fallback */
    .grid-4x5 {
        display: -webkit-grid !important;
        display: grid !important;
        -webkit-grid-template-columns: repeat(2, 1fr) !important;
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* High DPI Safari displays */
@media screen and (-webkit-min-device-pixel-ratio: 2) {
    .thumbnail,
    .carousel-img-large,
    .grid-item .thumbnail {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* Safari Dark Mode support - Only apply if user explicitly wants dark mode */
@media (prefers-color-scheme: dark) and (-webkit-min-device-pixel-ratio: 1) {
    /* Remove automatic dark mode - let the site maintain its original light theme */
    /* Users can manually enable dark mode if desired through browser settings */
}