/*
 * 3D Model/Video Section
 * Scroll-triggered 3D display with optimized performance
 * No conflicts with ScrollTrigger pinning
 */

.model-3d-section {
    min-height: 100vh; /* Minimum height, will be extended by JS based on video duration */
    width: 100%;
    position: relative;
    background: #171a25; /* Mirage - consistent with all sections */
    overflow: hidden;
    /* Keep flex for proper content centering (inherited from .fullscreen-section) */
    /* display: flex is inherited from .fullscreen-section */
    padding: 0;
    /* GPU acceleration - optimized */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    perspective: 1000px;
    /* Remove scroll-snap to avoid conflicts with ScrollTrigger */
    /* scroll-snap-align: start; */
    /* scroll-snap-stop: always; */
}

.model-3d-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 30% 40%, rgba(107, 182, 255, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 70% 60%, rgba(74, 158, 255, 0.1) 0%, transparent 50%),
        linear-gradient(135deg, rgba(107, 182, 255, 0.05) 0%, transparent 50%);
    z-index: 1;
    pointer-events: none;
    /* Optimized animation - use transform for better performance */
    will-change: opacity, transform;
    animation: shinyGlow 8s ease-in-out infinite alternate;
    transform: translate3d(0, 0, 0);
}

@keyframes shinyGlow {
    0% {
        opacity: 0.5;
        transform: translate3d(0, 0, 0) scale(1);
    }
    100% {
        opacity: 0.8;
        transform: translate3d(0, 0, 0) scale(1.1);
    }
}

.model-3d-section::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: 
        radial-gradient(circle, rgba(107, 182, 255, 0.1) 0%, transparent 70%),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(74, 158, 255, 0.03) 2px,
            rgba(74, 158, 255, 0.03) 4px
        );
    /* Optimized rotation animation */
    will-change: transform;
    animation: shinyRotate 20s linear infinite;
    z-index: 0;
    pointer-events: none;
    transform: translate3d(0, 0, 0);
}

@keyframes shinyRotate {
    from {
        transform: translate3d(0, 0, 0) rotate(0deg);
    }
    to {
        transform: translate3d(0, 0, 0) rotate(360deg);
    }
}

.model-3d-container {
    position: relative;
    z-index: 2;
    max-width: 1400px;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4rem;
    align-items: center;
    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
}

.model-3d-content {
    opacity: 0;
    transform: translate3d(-50px, 0, 0);
    transition: opacity 1s cubic-bezier(0.4, 0, 0.2, 1),
                transform 1s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: opacity, transform;
    backface-visibility: hidden;
}

.model-3d-content.visible,
.model-3d-content.is-visible {
    opacity: 1;
    transform: translate3d(0, 0, 0);
    will-change: auto; /* Remove will-change when animation completes */
}

.model-3d-content h2 {
    font-family: var(--ff-heading);
    font-size: clamp(2.5rem, 6vw, 4.5rem);
    font-weight: 900;
    line-height: 1.1;
    color: #ffffff;
    margin-bottom: 1.5rem;
    text-transform: uppercase;
    letter-spacing: -0.02em;
    text-shadow: 0 0 30px rgba(107, 182, 255, 0.3);
    /* Prevent text selection issues */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.model-3d-content .section-number {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: rgba(107, 182, 255, 0.6);
    margin-bottom: 1rem;
    display: block;
}

.model-3d-content p {
    font-size: clamp(1rem, 2vw, 1.3rem);
    line-height: 1.8;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 2rem;
}

.model-3d-display {
    position: relative;
    width: 100%;
    height: 600px;
    border-radius: 20px;
    overflow: hidden;
    opacity: 0;
    transform: translate3d(50px, 0, 0) scale(0.9);
    transition: opacity 1s cubic-bezier(0.4, 0, 0.2, 1) 0.3s,
                transform 1s cubic-bezier(0.4, 0, 0.2, 1) 0.3s;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.5),
        0 0 40px rgba(107, 182, 255, 0.3),
        inset 0 0 60px rgba(74, 158, 255, 0.1);
    border: 1px solid rgba(107, 182, 255, 0.2);
    will-change: opacity, transform;
    backface-visibility: hidden;
}

.model-3d-display.visible,
.model-3d-display.is-visible {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
    will-change: auto;
}

.model-3d-display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        linear-gradient(135deg, rgba(107, 182, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at center, rgba(74, 158, 255, 0.2) 0%, transparent 70%);
    z-index: 1;
    pointer-events: none;
    will-change: opacity;
    animation: modelShine 3s ease-in-out infinite;
}

@keyframes modelShine {
    0%, 100% {
        opacity: 0.3;
    }
    50% {
        opacity: 0.6;
    }
}

.model-3d-display video,
.model-3d-display iframe,
.model-3d-display img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: relative;
    z-index: 0;
    /* Optimize video rendering */
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
}

.model-3d-placeholder {
    width: 100%;
    height: 100%;
    background: 
        linear-gradient(135deg, rgba(30, 58, 95, 0.8) 0%, rgba(23, 26, 37, 0.9) 100%),
        radial-gradient(circle at center, rgba(107, 182, 255, 0.2) 0%, transparent 70%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 2rem;
    color: rgba(255, 255, 255, 0.6);
    font-size: 1.2rem;
    position: relative;
    z-index: 0;
}

.model-3d-placeholder i {
    font-size: 4rem;
    color: rgba(107, 182, 255, 0.4);
    will-change: transform, opacity;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.4;
        transform: translate3d(0, 0, 0) scale(1);
    }
    50% {
        opacity: 0.8;
        transform: translate3d(0, 0, 0) scale(1.1);
    }
}

/* Section 03: 2-Column Grid Layout */
.model-3d-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4rem;
    align-items: center;
    max-width: 1400px;
    width: 100%;
    padding: 8rem 4rem;
    margin: 0 auto;
}

/* Left Column: Content */
.model-3d-content-column {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.model-3d-content-column .section-header {
    text-align: left;
    margin-bottom: 2rem;
}

.model-3d-content-column .section-title-large {
    text-align: left;
}

.model-3d-content-column .narrative-content {
    text-align: left;
    max-width: 100%;
    margin: 0;
}

.model-3d-content-column .narrative-text {
    text-align: left;
}

/* Right Column: Video */
.model-3d-video-column {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Video Display Container */
.model-3d-display {
    position: relative;
    width: 100%;
    height: 600px;
    border-radius: 20px;
    overflow: hidden;
    opacity: 0;
    transform: translate3d(50px, 0, 0) scale(0.9);
    transition: opacity 1s cubic-bezier(0.4, 0, 0.2, 1) 0.3s,
                transform 1s cubic-bezier(0.4, 0, 0.2, 1) 0.3s;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.5),
        0 0 40px rgba(107, 182, 255, 0.3),
        inset 0 0 60px rgba(74, 158, 255, 0.1);
    border: 1px solid rgba(107, 182, 255, 0.2);
    will-change: opacity, transform;
    backface-visibility: hidden;
}

.model-3d-display.visible,
.model-3d-display.is-visible,
.model-3d-section.section-active .model-3d-display {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
    will-change: auto;
}

.model-3d-display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        linear-gradient(135deg, rgba(107, 182, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at center, rgba(74, 158, 255, 0.2) 0%, transparent 70%);
    z-index: 1;
    pointer-events: none;
    will-change: opacity;
    animation: modelShine 3s ease-in-out infinite;
}

@keyframes modelShine {
    0%, 100% {
        opacity: 0.3;
    }
    50% {
        opacity: 0.6;
    }
}

.model-3d-display video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: relative;
    z-index: 0;
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    display: block;
}

/* Ensure video section integrates with immersive sections */
.model-3d-section .section-content {
    position: relative;
    z-index: 2;
    /* Ensure content is visible when section is active */
    opacity: 1 !important;
    transform: translateY(0) !important;
}

/* When section is active, show all content */
.model-3d-section.section-active .section-content {
    opacity: 1 !important;
    transform: translateY(0) !important;
}


.model-3d-display .model-3d-placeholder {
    width: 100%;
    height: 100%;
    background: 
        linear-gradient(135deg, rgba(30, 58, 95, 0.8) 0%, rgba(23, 26, 37, 0.9) 100%),
        radial-gradient(circle at center, rgba(107, 182, 255, 0.2) 0%, transparent 70%);
    display: none; /* Hidden by default, shown only when video fails to load */
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 2rem;
    color: rgba(255, 255, 255, 0.6);
    font-size: 1.2rem;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
    transform: translate3d(0, 0, 0);
}

.model-3d-display .model-3d-placeholder.show {
    display: flex;
}

/* Performance optimizations for smooth scrolling */
@media (prefers-reduced-motion: no-preference) {
    .model-3d-section::before,
    .model-3d-section::after,
    .model-3d-display::before,
    .model-3d-placeholder i {
        animation-play-state: running;
    }
}

@media (prefers-reduced-motion: reduce) {
    .model-3d-section::before,
    .model-3d-section::after,
    .model-3d-display::before,
    .model-3d-placeholder i {
        animation: none;
    }
}

/* Responsive Design - Optimized */
@media (max-width: 992px) {
    .model-3d-grid {
        grid-template-columns: 1fr;
        gap: 3rem;
        padding: 4rem 2rem;
    }
    
    .model-3d-content-column .section-header,
    .model-3d-content-column .narrative-content,
    .model-3d-content-column .narrative-text {
        text-align: center;
    }
    
    .model-3d-display {
        height: 400px;
    }
}

@media (max-width: 768px) {
    .model-3d-grid {
        padding: 3rem 1.5rem;
        gap: 2rem;
    }
    
    .model-3d-display {
        height: 300px;
    }
}


/* High DPI displays optimization */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .model-3d-display video {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Reduce animations on low-end devices */
@media (max-width: 480px) {
    .model-3d-section::before,
    .model-3d-section::after {
        animation-duration: 12s; /* Slower animations for better performance */
    }
}
