/**
 * 3D Animations and Enhancements CSS
 * Supports Three.js and GSAP animations
 */

/* ========================================
   Global 3D Transform Settings
   ======================================== */

* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* REMOVED: body { perspective: 1000px; }
   This breaks position: fixed for navbar.
   Apply perspective to specific containers instead. */

body {
    overflow-x: clip;
}

/* ========================================
   Particle Background
   ======================================== */

#particle-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
}

#particle-background canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ========================================
   3D Logo Container
   ======================================== */

#three-logo-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#three-logo-container canvas {
    display: block;
}

/* Hide original logo when 3D version is active */
.logo {
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

/* ========================================
   3D Carousel
   ======================================== */

.carousel-3d-container {
    position: relative;
    width: 100%;
    height: 400px;
    overflow: hidden;
    border-radius: 15px;
}

.carousel-3d-container canvas {
    display: block;
    border-radius: 15px;
}

.carousel-3d-btn {
    transition: all 0.3s ease;
}

.carousel-3d-btn:hover {
    transform: scale(1.1);
}

.carousel-3d-indicators button {
    transition: all 0.3s ease;
}

.carousel-3d-indicators button:hover {
    transform: scale(1.2);
}

/* ========================================
   3D Timeline
   ======================================== */

.timeline-3d-container {
    position: relative;
    width: 100%;
    min-height: 800px;
    border-radius: 15px;
    overflow: hidden;
}

.timeline-3d-container canvas {
    display: block;
}

/* ========================================
   3D Cards and News Gallery
   ======================================== */

.card {
    transform-style: preserve-3d;
    transition: all 0.3s ease-out;
    will-change: transform;
    backface-visibility: hidden;
    opacity: 1 !important;
}

.card:hover {
    z-index: 10;
}

/* Ensure cards are visible */
.blog-card,
.blog-scroll-card .card {
    opacity: 1 !important;
}

.card img {
    transition: transform 0.4s ease;
    will-change: transform;
}

.card-glow {
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, #B91D3A, #8B1538, #6B0F1A);
    border-radius: inherit;
    opacity: 0;
    z-index: -1;
    filter: blur(15px);
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.card-ripple {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(185, 29, 58, 0.4) 0%, transparent 70%);
    pointer-events: none;
    animation: ripple-expand 0.6s ease-out forwards;
}

@keyframes ripple-expand {
    from {
        width: 0;
        height: 0;
        opacity: 1;
    }
    to {
        width: 300px;
        height: 300px;
        opacity: 0;
    }
}

/* ========================================
   Hero Background
   ======================================== */

.hero-background-3d {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.hero-background-3d canvas {
    display: block;
}

section.gradient-background-identity {
    position: relative;
    overflow: visible;
}

section.gradient-background-identity > * {
    position: relative;
    z-index: 1;
}

/* ========================================
   Page Transitions
   ======================================== */

#page-transition-curtain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #6B0F1A, #8B1538, #B91D3A);
    z-index: 10000;
    pointer-events: none;
    transform-origin: top;
}

#shader-transition-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    pointer-events: none;
}

/* ========================================
   Scroll Progress Indicator
   ======================================== */

#scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, #6B0F1A, #8B1538, #B91D3A);
    z-index: 9999;
    transform-origin: left;
}

/* ========================================
   Text Animation Enhancements
   ======================================== */

.display-4 span {
    display: inline-block;
    transform-origin: bottom;
}

/* ========================================
   Horizontal Scroll Section Enhancements
   ======================================== */

.scroll-section {
    cursor: grab;
    user-select: none;
}

.scroll-section:active {
    cursor: grabbing;
}

.scroll-wrapper {
    display: flex;
    gap: 20px;
    padding: 20px 0;
}

.blog-scroll-card {
    flex-shrink: 0;
    transform-style: preserve-3d;
}

/* ========================================
   Loading Indicator
   ======================================== */

.loading-3d {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10001;
    display: none;
}

.loading-3d.active {
    display: block;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(185, 29, 58, 0.2);
    border-top-color: #B91D3A;
    border-radius: 50%;
    animation: spinner-rotate 1s linear infinite;
}

@keyframes spinner-rotate {
    to {
        transform: rotate(360deg);
    }
}

/* ========================================
   Performance Optimizations
   ======================================== */

.gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
}

/* Disable animations on low-performance devices */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========================================
   Mobile Optimizations
   ======================================== */

@media (max-width: 768px) {
    .carousel-3d-container {
        height: 300px;
    }

    .timeline-3d-container {
        min-height: 600px;
    }

    .card {
        transform: none !important;
    }

    /* Disable some 3D effects on mobile for performance */
    .hero-background-3d {
        display: none;
    }

    #particle-background {
        opacity: 0.5;
    }
}

@media (max-width: 576px) {
    .carousel-3d-container {
        height: 250px;
    }

    .timeline-3d-container {
        min-height: 500px;
    }
}

/* ========================================
   Dark Mode Support
   ======================================== */

@media (prefers-color-scheme: dark) {
    .card-glow {
        filter: blur(20px);
        opacity: 0.8;
    }
}

/* ========================================
   High DPI Display Optimizations
   ======================================== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ========================================
   Accessibility
   ======================================== */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Skip to main content for keyboard navigation */
.skip-to-main {
    position: absolute;
    left: -9999px;
    z-index: 10002;
    padding: 10px 20px;
    background: #B91D3A;
    color: white;
    text-decoration: none;
    border-radius: 5px;
}

.skip-to-main:focus {
    left: 50%;
    transform: translateX(-50%);
    top: 10px;
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
    #particle-background,
    .hero-background-3d,
    #page-transition-curtain,
    #shader-transition-canvas,
    .carousel-3d-container,
    .timeline-3d-container {
        display: none !important;
    }

    .card {
        transform: none !important;
        page-break-inside: avoid;
    }
}

/* ========================================
   Custom Scrollbar
   ======================================== */

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #6B0F1A, #B91D3A);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #8B1538, #B91D3A);
}

/* ========================================
   Utilities
   ======================================== */

.fade-in-up {
    opacity: 0;
    transform: translateY(30px);
}

.fade-in-left {
    opacity: 0;
    transform: translateX(-30px);
}

.fade-in-right {
    opacity: 0;
    transform: translateX(30px);
}

.scale-in {
    opacity: 0;
    transform: scale(0.8);
}

.rotate-in {
    opacity: 0;
    transform: rotateY(-90deg);
}

/* Smooth transitions */
.smooth-transform {
    transition: transform 0.3s ease, opacity 0.3s ease;
}
