/* ===== SPACE ANIMATION STYLES - HERO BACKGROUND ONLY ===== */

/* Hero Section Space Animation Container - FIXED */
.hero-section {
    position: relative;
    overflow: hidden;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent !important;
    z-index: 100;
    transform-style: flat;
    isolation: isolate;
}

.hero-section .space-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.hero-section .hero-content {
    position: relative;
    z-index: 20;
}

.hero-section .scroll-down {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;
    color: #4facfe;
    font-size: 24px;
    text-decoration: none;
    opacity: 1;
    visibility: visible;
    pointer-events: all;
    animation: bounce 2s infinite;
    text-shadow: 0 0 10px rgba(79, 172, 254, 0.7);
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateX(-50%) translateY(0);
    }
    40% {
        transform: translateX(-50%) translateY(-10px);
    }
    60% {
        transform: translateX(-50%) translateY(-5px);
    }
}

/* Prevent 3D context leakage */
.hero-section + * {
    transform-style: flat;
    position: relative;
    z-index: 1;
}

/* Ensure space animation doesn't interfere */
.space-container {
    pointer-events: none;
}

.space-container .star-layer,
.space-container .nebula,
.space-container .planet,
.space-container .shooting-star {
    pointer-events: none;
}

/* Space Travel Container */
.space-container {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;
    perspective: 1200px;
    background: 
        radial-gradient(ellipse at 20% 20%, 
            #000000 0%,
            #0a0a2a 25%,
            transparent 50%),
        radial-gradient(ellipse at 80% 80%, 
            #1a0a2a 0%,
            #2d1b4e 40%,
            transparent 70%),
        radial-gradient(ellipse at 50% 50%, 
            #0c0e2a 0%,
            #1a1a4a 30%,
            #2d1b69 60%,
            transparent 100%);
}

/* Earth Introduction View */
.earth-intro {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 30;
    transition: transform 3s ease-out, opacity 2s ease-in;
    text-align: center;
}

.earth-intro.zoom-out {
    transform: translate(-50%, -50%) scale(0.1);
    opacity: 0;
}

.intro-text {
    margin-top: 20px;
    font-size: 1.5rem;
    color: #4facfe;
    text-shadow: 0 0 10px rgba(79, 172, 254, 0.7);
    animation: pulse 2s infinite alternate;
}

/* Realistic Star Layers */
.star-layer {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    transform-style: preserve-3d;
}

/* Deep Space Stars */
.stars-deep {
    z-index: 2;
}

.stars-deep .star {
    position: absolute;
    border-radius: 50%;
    animation: starDriftDeep linear infinite, starTwinkle 4s ease-in-out infinite;
    background: radial-gradient(circle, 
        rgba(255, 255, 255, 0.9) 0%,
        rgba(255, 255, 255, 0.6) 40%,
        transparent 70%);
    box-shadow: 
        0 0 3px 1px rgba(255, 255, 255, 0.8),
        0 0 6px 2px rgba(200, 220, 255, 0.4);
    filter: blur(0.2px);
}

/* Mid-field Stars */
.stars-mid {
    z-index: 3;
}

.stars-mid .star {
    position: absolute;
    border-radius: 50%;
    animation: starDriftMid linear infinite, starPulse 3s ease-in-out infinite;
    background: radial-gradient(circle, 
        var(--star-color, rgba(255, 255, 255, 1)) 0%,
        var(--star-color, rgba(255, 255, 255, 0.8)) 50%,
        transparent 80%);
    box-shadow: 
        0 0 4px 1px var(--star-glow, rgba(255, 255, 255, 0.9)),
        0 0 8px 2px var(--star-halo, rgba(100, 150, 255, 0.4));
    filter: blur(0.1px);
}

/* Near-field Stars */
.stars-near {
    z-index: 4;
}

.stars-near .star {
    position: absolute;
    border-radius: 50%;
    animation: starDriftNear linear infinite;
    background: radial-gradient(circle, 
        rgba(255, 255, 255, 1) 0%,
        rgba(255, 255, 255, 0.9) 30%,
        transparent 60%);
    box-shadow: 
        0 0 6px 2px rgba(255, 255, 255, 1),
        0 0 12px 4px rgba(100, 180, 255, 0.6);
}

.stars-near .star::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200%;
    height: 2px;
    background: linear-gradient(90deg, 
        transparent,
        rgba(255, 255, 255, 0.8),
        transparent);
    transform: translate(-50%, -50%) rotate(45deg);
    filter: blur(1px);
}

/* Enhanced Shooting Stars */
.shooting-star {
    position: absolute;
    width: 2px;
    height: 2px;
    background: white;
    border-radius: 50%;
    z-index: 5;
    animation: shootingStarAnimation linear infinite;
    filter: blur(0.3px);
}

.shooting-star::before {
    content: '';
    position: absolute;
    top: 50%;
    left: -40px;
    width: 50px;
    height: 1px;
    background: linear-gradient(90deg, 
        transparent 0%,
        rgba(255, 255, 255, 0.9) 20%,
        rgba(100, 200, 255, 0.7) 50%,
        rgba(255, 100, 255, 0.5) 80%,
        transparent 100%);
    transform: translateY(-50%);
    filter: blur(0.8px);
}

/* Realistic Planets with Atmospheres - FIXED ANIMATION */
.planet {
    position: absolute;
    border-radius: 50%;
    z-index: 5;
    animation: planetTravel linear infinite;
    overflow: hidden;
    width: var(--planet-size, 60px);
    height: var(--planet-size, 60px);
    min-width: 40px;
    min-height: 40px;
    animation-fill-mode: both;
    will-change: transform, opacity;
}

.planet::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--planet-surface, radial-gradient(circle, #888 0%, #666 50%, #444 100%));
    box-shadow: inset 0 0 20px 5px rgba(0, 0, 0, 0.5);
}

.planet::after {
    content: '';
    position: absolute;
    top: -10%;
    left: -10%;
    width: 120%;
    height: 120%;
    border-radius: 50%;
    background: var(--planet-atmosphere, radial-gradient(circle, 
        rgba(255, 255, 255, 0.1) 0%,
        transparent 70%));
    box-shadow: 
        0 0 30px 10px var(--planet-glow, rgba(100, 150, 255, 0.3)),
        inset 0 0 20px 5px rgba(255, 255, 255, 0.1);
    filter: blur(5px);
    z-index: -1;
}

/* Planet Labels */
.planet-label {
    position: absolute;
    color: white;
    font-size: 14px;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(0, 0, 0, 0.8);
    z-index: 6;
    pointer-events: none;
    opacity: 0.8;
    transition: opacity 0.3s;
    white-space: nowrap;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
}

.planet-label:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.5);
}

/* Enhanced Realistic Planet Variations */
.planet[data-type="earth"] {
    --planet-size: clamp(80px, 12vw, 120px);
    --planet-surface: 
        radial-gradient(circle at 30% 30%, 
            #2a5c82 0%, #1e3a5f 20%, #2d5a3a 40%, #4a7c3a 60%, #8b7355 80%),
        radial-gradient(circle at 70% 60%, 
            #1e3a5f 0%, transparent 40%);
    --planet-atmosphere: radial-gradient(circle, 
        rgba(100, 150, 255, 0.4) 0%, 
        rgba(70, 130, 255, 0.3) 30%,
        transparent 70%);
    --planet-glow: rgba(100, 150, 255, 0.6);
}

.planet[data-type="mars"] {
    --planet-size: clamp(50px, 8vw, 70px);
    --planet-surface: 
        radial-gradient(circle at 40% 40%, 
            #c1440e 0%, #9c3a0c 30%, #7a2e09 60%, #5a2206 90%),
        radial-gradient(circle at 60% 20%, 
            #9c3a0c 0%, transparent 50%);
    --planet-atmosphere: radial-gradient(circle, 
        rgba(255, 100, 50, 0.3) 0%, 
        rgba(200, 80, 40, 0.2) 40%,
        transparent 80%);
    --planet-glow: rgba(255, 100, 50, 0.4);
}

.planet[data-type="jupiter"] {
    --planet-size: clamp(100px, 18vw, 180px);
    --planet-surface: 
        radial-gradient(circle at 30% 40%, #c19a6b 0%, transparent 50%),
        radial-gradient(circle at 60% 70%, #b08c5a 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, #a67c52 0%, transparent 50%),
        linear-gradient(45deg, 
            #c19a6b 0%, #b08c5a 25%, #a67c52 50%, 
            #9c7c4a 75%, #8c6c42 100%);
    --planet-atmosphere: radial-gradient(circle, 
        rgba(255, 200, 100, 0.4) 0%, 
        rgba(255, 180, 80, 0.3) 50%,
        transparent 90%);
    --planet-glow: rgba(255, 200, 100, 0.6);
}

.planet[data-type="saturn"] {
    --planet-size: clamp(90px, 16vw, 160px);
    --planet-surface: 
        radial-gradient(circle at 30% 30%, 
            #e6c9a8 0%, #d4b897 30%, #c2a786 60%, #b09675 90%),
        radial-gradient(circle at 70% 50%, 
            #d4b897 0%, transparent 40%);
    --planet-atmosphere: radial-gradient(circle, 
        rgba(255, 220, 150, 0.4) 0%, 
        rgba(255, 200, 120, 0.3) 40%,
        transparent 85%);
    --planet-glow: rgba(255, 220, 150, 0.5);
}

.planet[data-type="venus"] {
    --planet-size: clamp(60px, 9vw, 90px);
    --planet-surface: 
        radial-gradient(circle at 30% 30%, 
            #e6e6fa 0%, #d8bfd8 30%, #b19cd9 60%, #9370db 90%),
        radial-gradient(circle at 60% 60%, 
            #d8bfd8 0%, transparent 40%);
    --planet-atmosphere: radial-gradient(circle, 
        rgba(255, 255, 255, 0.5) 0%, 
        rgba(230, 230, 250, 0.4) 50%,
        transparent 90%);
    --planet-glow: rgba(255, 255, 255, 0.6);
}

.planet[data-type="neptune"] {
    --planet-size: clamp(70px, 10vw, 100px);
    --planet-surface: 
        radial-gradient(circle at 30% 30%, 
            #4169e1 0%, #1e90ff 30%, #00bfff 60%, #87ceeb 90%),
        radial-gradient(circle at 70% 40%, 
            #1e90ff 0%, transparent 40%);
    --planet-atmosphere: radial-gradient(circle, 
        rgba(65, 105, 225, 0.5) 0%, 
        rgba(30, 144, 255, 0.4) 50%,
        transparent 90%);
    --planet-glow: rgba(65, 105, 225, 0.6);
}

/* Saturn's Rings */
.planet[data-type="saturn"]::before {
    box-shadow: 
        inset 0 0 20px 5px rgba(0, 0, 0, 0.5),
        0 0 0 2px rgba(210, 180, 140, 0.7),
        0 0 0 6px rgba(210, 180, 140, 0.5),
        0 0 0 10px rgba(210, 180, 140, 0.3),
        0 0 0 14px rgba(210, 180, 140, 0.1);
}

/* Enhanced Realistic Nebula */
.nebula {
    position: absolute;
    width: 300%;
    height: 300%;
    top: -100%;
    left: -100%;
    background: 
        radial-gradient(circle at 30% 40%, 
            rgba(255, 105, 180, 0.15) 0%, 
            rgba(255, 105, 180, 0.05) 20%,
            transparent 50%),
        radial-gradient(circle at 60% 70%, 
            rgba(138, 43, 226, 0.12) 0%, 
            rgba(138, 43, 226, 0.04) 25%,
            transparent 55%),
        radial-gradient(circle at 40% 20%, 
            rgba(30, 144, 255, 0.1) 0%, 
            rgba(30, 144, 255, 0.03) 30%,
            transparent 60%),
        radial-gradient(circle at 80% 50%, 
            rgba(50, 205, 50, 0.08) 0%, 
            rgba(50, 205, 50, 0.02) 15%,
            transparent 45%),
        radial-gradient(circle at 20% 80%, 
            rgba(255, 165, 0, 0.06) 0%, 
            rgba(255, 140, 0, 0.02) 20%,
            transparent 50%);
    animation: nebulaDrift 300s linear infinite;
    z-index: 1;
    opacity: 0.3;
    mix-blend-mode: screen;
    filter: blur(8px) contrast(1.2) brightness(1);
}

/* Additional Nebula Layer */
.nebula-2 {
    position: absolute;
    width: 200%;
    height: 200%;
    top: -50%;
    left: -50%;
    background: 
        radial-gradient(circle at 70% 30%, 
            rgba(147, 112, 219, 0.1) 0%, 
            rgba(147, 112, 219, 0.03) 25%,
            transparent 60%),
        radial-gradient(circle at 30% 70%, 
            rgba(255, 69, 0, 0.06) 0%, 
            rgba(255, 69, 0, 0.02) 20%,
            transparent 55%),
        radial-gradient(circle at 50% 50%, 
            rgba(0, 191, 255, 0.05) 0%, 
            rgba(0, 191, 255, 0.01) 15%,
            transparent 50%);
    animation: nebulaDrift2 240s linear infinite;
    z-index: 1;
    opacity: 0.2;
    mix-blend-mode: overlay;
    filter: blur(10px) contrast(1.1) brightness(1);
}

/* Subtle Cosmic Grid */
.particles-grid-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        linear-gradient(rgba(100, 100, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(100, 100, 255, 0.05) 1px, transparent 1px);
    background-size: 80px 80px;
    z-index: 2;
    opacity: 0.1;
    pointer-events: none;
    animation: gridMove 60s linear infinite;
    mix-blend-mode: plus-lighter;
}

/* Space Controls */
.space-controls {
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 10000;
    display: flex;
    gap: 10px;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.space-controls.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.space-control-btn {
    background: rgba(79, 172, 254, 0.3);
    border: 1px solid rgba(79, 172, 254, 0.5);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s;
    backdrop-filter: blur(5px);
    font-size: 14px;
    font-weight: 500;
}

.space-control-btn:hover {
    background: rgba(79, 172, 254, 0.5);
    border-color: rgba(79, 172, 254, 0.8);
    transform: translateY(-1px);
}

/* ===== FIXED ANIMATIONS ===== */

/* FIXED: Planet Animation - Immediate Visibility */
@keyframes planetTravel {
    0% {
        transform: translateZ(-500px) translateX(-30vw) translateY(120vh) scale(0.8) rotate(0deg);
        opacity: 1; /* Start visible */
    }
    3% {
        transform: translateZ(-500px) translateX(-15vw) translateY(100vh) scale(0.9) rotate(45deg);
        opacity: 1;
    }
    10% {
        transform: translateZ(-500px) translateX(5vw) translateY(80vh) scale(1) rotate(90deg);
    }
    85% {
        transform: translateZ(-500px) translateX(95vw) translateY(10vh) scale(1) rotate(300deg);
        opacity: 1;
    }
    95% {
        opacity: 1;
        transform: translateZ(-500px) translateX(115vw) translateY(-20vh) scale(0.8) rotate(345deg);
    }
    100% {
        transform: translateZ(-500px) translateX(130vw) translateY(-50vh) scale(0.6) rotate(360deg);
        opacity: 0; /* Fade out at end */
    }
}

@keyframes starDriftDeep {
    0% {
        transform: translateZ(-2000px) translateY(100vh) rotateX(5deg);
        opacity: 0;
    }
    10% {
        opacity: 0.7;
        transform: translateZ(-2000px) translateY(80vh) rotateX(3deg);
    }
    90% {
        opacity: 0.7;
        transform: translateZ(-2000px) translateY(20vh) rotateX(-3deg);
    }
    100% {
        transform: translateZ(-2000px) translateY(-100vh) rotateX(-5deg);
        opacity: 0;
    }
}

@keyframes starDriftMid {
    0% {
        transform: translateZ(-1000px) translateY(100vh) rotateX(8deg);
        opacity: 0;
    }
    8% {
        opacity: 0.9;
        transform: translateZ(-1000px) translateY(85vh) rotateX(5deg);
    }
    92% {
        opacity: 0.9;
        transform: translateZ(-1000px) translateY(15vh) rotateX(-5deg);
    }
    100% {
        transform: translateZ(-1000px) translateY(-100vh) rotateX(-8deg);
        opacity: 0;
    }
}

@keyframes starDriftNear {
    0% {
        transform: translateZ(-400px) translateY(100vh) rotateX(15deg);
        opacity: 0;
    }
    5% {
        opacity: 1;
        transform: translateZ(-400px) translateY(90vh) rotateX(10deg);
    }
    95% {
        opacity: 1;
        transform: translateZ(-400px) translateY(10vh) rotateX(-10deg);
    }
    100% {
        transform: translateZ(-400px) translateY(-100vh) rotateX(-15deg);
        opacity: 0;
    }
}

@keyframes starTwinkle {
    0%, 100% { 
        opacity: 0.7; 
        transform: scale(1); 
    }
    50% { 
        opacity: 1; 
        transform: scale(1.1); 
    }
}

@keyframes starPulse {
    0%, 100% { 
        opacity: 0.8; 
        filter: brightness(1); 
    }
    50% { 
        opacity: 1; 
        filter: brightness(1.3); 
    }
}

@keyframes shootingStarAnimation {
    0% {
        transform: 
            translateX(calc(-150px - 10vw)) 
            translateY(calc(100px + 10vh)) 
            scale(0.3);
        opacity: 0;
    }
    10% {
        opacity: 0.8;
        transform: 
            translateX(calc(-75px - 5vw)) 
            translateY(calc(50px + 5vh)) 
            scale(0.6);
    }
    20% {
        opacity: 1;
        transform: 
            translateX(0px) 
            translateY(0px) 
            scale(1);
    }
    30% {
        opacity: 0.9;
        transform: 
            translateX(calc(75px + 5vw)) 
            translateY(calc(-50px - 5vh)) 
            scale(0.8);
    }
    50% {
        opacity: 0.7;
        transform: 
            translateX(calc(150px + 10vw)) 
            translateY(calc(-100px - 10vh)) 
            scale(0.6);
    }
    100% {
        transform: 
            translateX(calc(300px + 20vw)) 
            translateY(calc(-200px - 20vh)) 
            scale(0.2);
        opacity: 0;
    }
}

@keyframes nebulaDrift {
    0% {
        transform: rotate(0deg) scale(1) translate(0px, 0px);
        filter: hue-rotate(0deg) blur(8px);
    }
    50% {
        transform: rotate(180deg) scale(1.05) translate(10px, 5px);
        filter: hue-rotate(90deg) blur(10px);
    }
    100% {
        transform: rotate(360deg) scale(1) translate(0px, 0px);
        filter: hue-rotate(180deg) blur(8px);
    }
}

@keyframes nebulaDrift2 {
    0% {
        transform: rotate(0deg) scale(1.1) translate(0px, 0px);
        filter: hue-rotate(90deg) blur(10px);
    }
    50% {
        transform: rotate(180deg) scale(1.15) translate(-15px, 8px);
        filter: hue-rotate(180deg) blur(12px);
    }
    100% {
        transform: rotate(360deg) scale(1.1) translate(0px, 0px);
        filter: hue-rotate(270deg) blur(10px);
    }
}

@keyframes gridMove {
    0% {
        background-position: 0 0;
        opacity: 0.08;
    }
    100% {
        background-position: 80px 80px;
        opacity: 0.12;
    }
}

@keyframes pulse {
    0% {
        opacity: 0.7;
        transform: scale(1);
    }
    100% {
        opacity: 1;
        transform: scale(1.05);
    }
}

/* ===== MOBILE OPTIMIZATIONS ===== */

@media (max-width: 768px) {
    .planet-label {
        font-size: 12px;
        padding: 1px 6px;
    }
    
    .space-controls {
        bottom: 10px;
        left: 10px;
        padding: 8px;
    }
    
    .space-control-btn {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .intro-text {
        font-size: 1.2rem;
    }
    
    .hero-section .scroll-down {
        font-size: 20px;
        bottom: 25px;
    }
    
    .space-container {
        perspective: 800px;
    }
    
    .planet {
        min-width: 30px;
        min-height: 30px;
        animation-duration: 25s !important;
    }
    
    /* Mobile-specific planet animation */
    @keyframes planetTravel {
        0% {
            transform: translateZ(-400px) translateX(-25vw) translateY(115vh) scale(0.7);
            opacity: 1;
        }
        5% {
            transform: translateZ(-400px) translateX(-10vw) translateY(95vh) scale(0.85);
        }
        15% {
            transform: translateZ(-400px) translateX(10vw) translateY(75vh) scale(1);
        }
        80% {
            transform: translateZ(-400px) translateX(90vw) translateY(15vh) scale(1);
        }
        90% {
            opacity: 1;
            transform: translateZ(-400px) translateX(110vw) translateY(-10vh) scale(0.7);
        }
        100% {
            transform: translateZ(-400px) translateX(130vw) translateY(-35vh) scale(0.5);
            opacity: 0;
        }
    }
}

@media (max-width: 480px) {
    .planet-label {
        font-size: 10px;
    }
    
    .intro-text {
        font-size: 1rem;
    }
    
    .space-controls {
        bottom: 5px;
        left: 5px;
        flex-direction: column;
        padding: 6px;
    }
    
    .hero-section .scroll-down {
        font-size: 18px;
        bottom: 20px;
    }
    
    .planet {
        min-width: 25px;
        min-height: 25px;
    }
}

/* Performance Optimizations */
.star-layer {
    will-change: transform;
    backface-visibility: hidden;
}

.star, .planet, .shooting-star {
    will-change: transform, opacity;
    transform: translate3d(0, 0, 0);
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .star-layer,
    .particles-grid-bg,
    .nebula,
    .nebula-2,
    .scroll-down,
    .star, .planet, .shooting-star {
        animation: none !important;
    }
    
    .space-controls {
        display: none !important;
    }
}

/* Chromium Hardware Acceleration Fix */
.space-container {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000;
}

/* Services protection */
.services {
    transform-style: flat !important;
    perspective: none !important;
    isolation: isolate;
    z-index: 1;
    position: relative;
}

.service-card,
.services-grid,
.services-container,
.service-card-inner {
    transform-style: flat !important;
    perspective: none !important;
}
