/* iPhone Specific Fixes and Optimizations */

/* CRITICAL SAFARI VIEWPORT BUG FIXES */
* {
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
}

/* Safari 100vw bug fix - prevents horizontal scroll */
html {
    width: 100% !important;
    overflow-x: hidden !important;
}

body {
    width: 100% !important;
    overflow-x: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Safe Area Support for iPhone X and later */
:root {
    --safe-area-inset-top: env(safe-area-inset-top);
    --safe-area-inset-right: env(safe-area-inset-right);
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
    --safe-area-inset-left: env(safe-area-inset-left);
}

/* iOS Safari viewport height fix - Updated 2024 approach */
html, body {
    height: 100%;
}

/* Fix for 100vh on iPhone Safari - Modern approach */
.hero, .journey-intro, .journey-timeline, .journey-workshop, .journey-climax {
    min-height: 100vh;
}

/* iPhone-specific header fixes */
@supports (-webkit-backdrop-filter: blur(10px)) {
    .header {
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
    }
}

/* Fixed positioning improvements for iPhone */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
}

/* Safe area padding for fixed header */
.header {
    padding-top: var(--safe-area-inset-top);
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
}

/* Prevent input zoom on iPhone */
input[type="text"], 
input[type="email"], 
textarea, 
select {
    font-size: 16px !important;
    -webkit-appearance: none;
    border-radius: 0;
}

/* Touch optimization - simplified to avoid touch issues */
button, 
.cta-button, 
.submit-button, 
a {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    touch-action: manipulation;
}

/* Scroll behavior improvements for iPhone */
body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
    -webkit-overscroll-behavior: none;
}

/* Optimized scroll-snap for iPhone - Re-enabled with better performance */
@media (max-width: 768px) {
    html {
        scroll-snap-type: y proximity;
        -webkit-scroll-snap-type: y proximity;
        scroll-behavior: smooth;
    }
    
    /* Apply scroll snap to main sections for smooth navigation */
    section {
        scroll-snap-align: start;
        -webkit-scroll-snap-align: start;
    }
    
    /* Disable scroll snap only on specific problematic elements */
    .timeline-track,
    .workshop-gallery,
    .fusion-images {
        scroll-snap-type: none;
        -webkit-scroll-snap-type: none;
    }
}

/* iPhone SE (375px) specific fixes */
@media only screen and (max-width: 375px) and (-webkit-min-device-pixel-ratio: 2) {
    .intro-year {
        font-size: clamp(1.4rem, 7vw, 2rem);
    }
    
    .story-main-text {
        font-size: clamp(1.1rem, 4vw, 1.6rem);
    }
    
    .climax-quote .quote-large {
        font-size: clamp(1.3rem, 6vw, 1.8rem);
    }
}

/* iPhone Hero Image Positioning - Below Header */
@media only screen and (max-width: 768px) {
    .hero-image {
        top: 85px; /* Position below header */
        height: calc(100vh - 85px); /* Adjust height accordingly */
    }
    
    .hero-img {
        object-position: center top; /* Align to top of visible area */
    }
}

/* iPhone 15 (393px) specific viewport and hero fixes */
@media only screen and (min-width: 393px) and (max-width: 852px) and (-webkit-min-device-pixel-ratio: 3) {
    /* Override -webkit-fill-available issues on iPhone 15 */
    html, body {
        height: 100% !important;
    }
    
    .hero {
        min-height: 100vh;
        height: auto;
    }
    
    /* Precise hero image positioning for iPhone 15 */
    .hero-image {
        top: 85px;
        height: calc(100vh - 85px);
        /* transform: translateZ(0); removed to avoid stacking context issues */
    }
    
    .hero-img {
        object-fit: cover;
        object-position: center 15%; /* Optimized for iPhone 15 */
    }
    
    .container {
        padding: 0 16px;
        max-width: calc(100vw - 32px);
    }
    
    .timeline-content, 
    .workshop-content {
        padding: 50px 0;
        overflow: hidden;
        width: 100%;
        box-sizing: border-box;
    }
}

/* iPhone 12/13/14 (390px) specific fixes */
@media only screen and (max-width: 390px) and (-webkit-min-device-pixel-ratio: 3) {
    .container {
        padding: 0 15px;
    }
    
    .timeline-content, 
    .workshop-content {
        padding: 50px 0;
    }
}

/* iPhone 12/13/14/15 Pro Max (428px) specific fixes */
@media only screen and (max-width: 428px) and (-webkit-min-device-pixel-ratio: 3) {
    .fusion-images {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .fusion-img img {
        height: 220px;
    }
}

/* Landscape orientation fixes for iPhone */
@media only screen and (max-height: 500px) and (orientation: landscape) {
    .hero {
        min-height: 100vh;
    }
    
    .hero-content {
        padding: 60px 0;
    }
    
    .nav-list {
        flex-direction: row;
        gap: 20px;
    }
}

/* Performance optimization for parallax on iPhone */
@media (max-width: 768px) {
    .parallax-bg,
    .timeline-bg-img,
    .workshop-bg-img {
        transform: none !important;
        will-change: auto;
    }
}

/* Hardware acceleration for smooth animations */
.timeline-progress,
.particles::before,
.particles::after,
.image-glow {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
}

/* iPhone Safari address bar compensation */
@supports (-webkit-touch-callout: none) {
    .hero {
        height: calc(100vh - var(--safe-area-inset-top));
    }
}

/* Fix for iPhone sticky elements */
.sticky-element {
    position: -webkit-sticky;
    position: sticky;
    top: calc(var(--safe-area-inset-top) + 80px);
}

/* Touch event improvements */
.mobile-menu-toggle {
    touch-action: manipulation;
    -webkit-touch-callout: none;
}

/* Form improvements for iPhone */
.contact-form {
    padding-bottom: var(--safe-area-inset-bottom);
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    -webkit-appearance: none;
    transform: translateZ(0);
}

/* iPhone-specific button improvements */
.submit-button {
    -webkit-appearance: none;
    border-radius: 8px;
    min-height: 44px; /* Apple's minimum touch target */
    padding: 12px 24px;
}

/* Improved scroll behavior for iPhone without breaking functionality */
body {
    overscroll-behavior: none;
    -webkit-overscroll-behavior: none;
}

/* iPhone notch area handling for hero section */
.hero-content {
    padding-top: calc(120px + var(--safe-area-inset-top));
    padding-bottom: calc(60px + var(--safe-area-inset-bottom));
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
}

/* Safe Area support for hero image positioning */
@supports (padding-top: env(safe-area-inset-top)) {
    @media only screen and (max-width: 768px) {
        .hero-image {
            top: calc(85px + env(safe-area-inset-top));
            height: calc(100vh - 85px - env(safe-area-inset-top));
        }
    }
    
    /* iPhone X and later with Dynamic Island */
    @media only screen and (min-width: 393px) and (max-width: 852px) and (-webkit-min-device-pixel-ratio: 3) {
        .hero-image {
            top: calc(85px + env(safe-area-inset-top));
            height: calc(100vh - 85px - env(safe-area-inset-top));
        }
    }
}

/* Footer safe area */
.footer {
    padding-bottom: max(20px, var(--safe-area-inset-bottom));
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
}

/* Main content sections safe area support */
.products,
.performance,
.lessons,
.message-journey {
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
}

/* Container safe area for all sections */
.products .container,
.performance .container,
.lessons .container,
.message-journey .container {
    padding-left: max(20px, var(--safe-area-inset-left));
    padding-right: max(20px, var(--safe-area-inset-right));
}

/* Prevent horizontal overflow on iPhone - Safari Critical Fix */
.products-content,
.lessons-content,
.performance-packages,
.timeline-content,
.workshop-content {
    max-width: 100%;
    width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
    /* Safari-specific containment */
    -webkit-box-sizing: border-box;
    contain: layout style;
}

/* Ensure images don't cause overflow */
.products-image img,
.lessons-image img,
.story-img,
.gallery-img {
    max-width: 100%;
    height: auto;
}

/* Message Journey iPhone optimizations */
.fusion-images {
    grid-template-columns: 1fr !important;
    gap: 20px !important;
    align-items: center;
}

.fusion-img {
    max-width: 200px;
    margin: 0 auto;
}

.fusion-center {
    order: 2;
    padding: 20px;
}

.climax-message {
    padding: 0 10px;
    text-align: center;
}

/* Particles optimization for iPhone */
.particles {
    display: none; /* Disable on mobile for performance */
}

@media (min-width: 769px) {
    .particles {
        display: block;
    }
}

/* Table responsive design for Lessons section */
.pricing-table {
    width: 100%;
    overflow-x: auto;
    display: block;
    white-space: nowrap;
}

.pricing-table td {
    white-space: normal;
    min-width: 120px;
    padding: 8px;
}

/* Performance packages mobile optimization */
.package-card {
    max-width: 100%;
    margin: 0 auto;
}