/* Animations and Effects for Kalibotics Website - Enhanced with Benchmark Institution Designs */

/* Particle Effect - Enhanced with more sophisticated movement */
.particle-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: -5; /* Lower z-index to ensure it stays behind text */
    pointer-events: none; /* Prevent particles from interfering with text interaction */
}

.particle {
    position: absolute;
    display: block;
    pointer-events: none;
    width: 5px;
    height: 5px;
    background-color: rgba(0, 210, 255, 0.15); /* Reduced opacity */
    box-shadow: 0 0 10px rgba(0, 210, 255, 0.3); /* Reduced shadow intensity */
    border-radius: 50%;
    animation: float 15s infinite cubic-bezier(0.37, 0, 0.63, 1);
}

@keyframes float {
    0% {
        transform: translateY(0) translateX(0) rotate(0deg) scale(1);
        opacity: 0.7; /* Reduced starting opacity */
        border-radius: 0;
    }
    25% {
        transform: translateY(-50px) translateX(50px) rotate(90deg) scale(1.2);
        opacity: 0.6; /* Reduced opacity */
        border-radius: 25%;
    }
    50% {
        transform: translateY(-100px) translateX(100px) rotate(180deg) scale(1);
        opacity: 0.5; /* Reduced opacity */
        border-radius: 50%;
    }
    75% {
        transform: translateY(-200px) translateX(120px) rotate(270deg) scale(0.8);
        opacity: 0.3; /* Reduced opacity */
        border-radius: 25%;
    }
    100% {
        transform: translateY(-300px) translateX(150px) rotate(360deg) scale(0.5);
        opacity: 0;
    }
}

/* Circuit Board Pattern Animation - Enhanced with MIT-inspired design */
.circuit-pattern {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(rgba(0, 98, 204, 0.03) 1px, transparent 1px), /* Reduced opacity */
        linear-gradient(90deg, rgba(0, 98, 204, 0.03) 1px, transparent 1px), /* Reduced opacity */
        radial-gradient(circle at 50% 50%, rgba(0, 210, 255, 0.02) 0%, transparent 50%); /* Reduced opacity */
    background-size: 20px 20px, 20px 20px, 100% 100%;
    z-index: -10; /* Lower z-index to ensure it stays behind text */
    pointer-events: none; /* Prevent circuit pattern from interfering with text interaction */
    animation: circuitPulse 8s infinite cubic-bezier(0.4, 0, 0.6, 1);
}

.circuit-pattern::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(45deg, rgba(0, 210, 255, 0.02) 25%, transparent 25%), /* Reduced opacity */
        linear-gradient(-45deg, rgba(0, 210, 255, 0.02) 25%, transparent 25%); /* Reduced opacity */
    background-size: 60px 60px;
    pointer-events: none; /* Ensure no interference with text interaction */
    animation: circuitOverlay 12s infinite linear;
}

@keyframes circuitPulse {
    0% {
        opacity: 0.2; /* Reduced opacity */
        background-size: 20px 20px, 20px 20px, 100% 100%;
    }
    50% {
        opacity: 0.3; /* Reduced opacity */
        background-size: 25px 25px, 25px 25px, 120% 120%;
    }
    100% {
        opacity: 0.2; /* Reduced opacity */
        background-size: 20px 20px, 20px 20px, 100% 100%;
    }
}

@keyframes circuitOverlay {
    0% {
        background-position: 0 0;
    }
    100% {
        background-position: 60px 60px;
    }
}

/* Glowing Effect for Cards - Enhanced with Boston Dynamics-inspired design */
.service-card {
    position: relative;
    overflow: hidden;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.4s ease;
}

.service-card::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, var(--primary-color), var(--accent-color), var(--accent-secondary));
    z-index: -1;
    border-radius: calc(var(--border-radius) + 2px);
    opacity: 0;
    transition: opacity 0.3s ease, background-position 1.5s ease-in-out;
    background-size: 200% 200%;
}

.service-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at center, rgba(0, 210, 255, 0.1), transparent 70%);
    opacity: 0;
    transition: opacity 0.5s ease;
    z-index: -1;
}

.service-card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 10px 30px rgba(0, 98, 204, 0.2);
}

.service-card:hover::before {
    opacity: 1;
    animation: glowingBorder 3s ease-in-out infinite;
}

.service-card:hover::after {
    opacity: 1;
    animation: pulseGlow 2s infinite;
}

@keyframes glowingBorder {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

@keyframes pulseGlow {
    0%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.05);
    }
}

/* Robot Animation Enhancement - Inspired by Boston Dynamics and MIT Robotics */
.robot-animation {
    position: relative;
    transform-style: preserve-3d;
    perspective: 1000px;
}

.robot-animation img {
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    filter: drop-shadow(0 0 15px rgba(0, 210, 255, 0.3));
}

.robot-animation:hover img {
    transform: translateY(-10px) rotateY(10deg);
}

.robot-animation::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(0, 210, 255, 0.1), transparent 70%);
    opacity: 0;
    transition: opacity 0.5s ease;
    z-index: -1;
}

.robot-animation:hover::before {
    opacity: 1;
    animation: robotGlow 3s infinite ease-in-out;
}

.robot-animation::after {
    content: '';
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 10px;
    background: radial-gradient(ellipse at center, rgba(0, 210, 255, 0.6) 0%, rgba(0, 210, 255, 0) 70%);
    border-radius: 50%;
    animation: robotHover 2s infinite cubic-bezier(0.455, 0.03, 0.515, 0.955);
}

@keyframes robotHover {
    0%, 100% {
        transform: translateX(-50%) scale(1);
        opacity: 0.6;
    }
    50% {
        transform: translateX(-50%) scale(1.2);
        opacity: 0.8;
    }
}

@keyframes robotGlow {
    0%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.1);
    }
}

/* Animated Counter for Stats */
.stat-number {
    display: inline-block;
    position: relative;
}

/* Scroll Reveal Animations - Enhanced with MIT Media Lab-inspired transitions */
.reveal-left {
    opacity: 0;
    transform: translateX(-50px);
    transition: all 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    filter: blur(5px);
}

.reveal-right {
    opacity: 0;
    transform: translateX(50px);
    transition: all 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    filter: blur(5px);
}

.reveal-up {
    opacity: 0;
    transform: translateY(50px);
    transition: all 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    filter: blur(5px);
}

.reveal-visible {
    opacity: 1;
    transform: translate(0);
    filter: blur(0);
}

/* Staggered reveal for multiple elements */
.stagger-reveal > * {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.stagger-reveal.reveal-visible > *:nth-child(1) { transition-delay: 0.1s; }
.stagger-reveal.reveal-visible > *:nth-child(2) { transition-delay: 0.2s; }
.stagger-reveal.reveal-visible > *:nth-child(3) { transition-delay: 0.3s; }
.stagger-reveal.reveal-visible > *:nth-child(4) { transition-delay: 0.4s; }
.stagger-reveal.reveal-visible > *:nth-child(5) { transition-delay: 0.5s; }
.stagger-reveal.reveal-visible > *:nth-child(6) { transition-delay: 0.6s; }

.stagger-reveal.reveal-visible > * {
    opacity: 1;
    transform: translateY(0);
}

/* Typing Animation for Hero Title - Enhanced with Stanford AI Lab-inspired effect */
.typing-animation {
    border-right: 3px solid var(--accent-color);
    white-space: nowrap;
    overflow: hidden;
    position: relative;
    animation: blink-caret 0.75s step-end infinite;
}

.typing-animation::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0; /* Changed from 100% to 0 to prevent covering the text */
    background: linear-gradient(90deg, transparent 0%, var(--dark-background) 5%);
    animation: typingGlow 3.5s steps(40, end);
    pointer-events: none; /* Ensure the overlay doesn't interfere with text interaction */
    z-index: -1; /* Place behind the text */
}

@keyframes typing {
    from { width: 0 }
    to { width: 100% }
}

@keyframes typingGlow {
    from { left: 0 }
    to { left: 100% }
}

@keyframes blink-caret {
    from, to { border-color: transparent }
    50% { border-color: var(--accent-color); box-shadow: 0 0 5px var(--accent-color); }
}

/* Pulse Animation for CTA Button - Enhanced with MIT/Stanford-inspired design */
.cta-button {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1;
}

.cta-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, rgba(0, 210, 255, 0.2), rgba(0, 98, 204, 0.2));
    transition: left 0.3s ease;
    z-index: -1;
}

.cta-button:hover::before {
    left: 0;
}

.cta-button::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: var(--border-radius);
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    z-index: -2;
    animation: ctaPulse 2s infinite cubic-bezier(0.455, 0.03, 0.515, 0.955);
    opacity: 0;
}

.cta-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 7px 20px rgba(0, 98, 204, 0.3);
}

@keyframes ctaPulse {
    0% {
        transform: scale(1);
        opacity: 0.7;
    }
    50% {
        transform: scale(1.05);
        opacity: 0;
    }
    100% {
        transform: scale(1.2);
        opacity: 0;
    }
}

/* Rotating Gear Animation - Enhanced with mechanical precision */
.rotating-gear {
    animation: rotate 10s cubic-bezier(0.85, 0, 0.15, 1) infinite;
    transform-origin: center;
    filter: drop-shadow(0 0 5px rgba(0, 210, 255, 0.3));
    transition: filter 0.3s ease;
}

.rotating-gear:hover {
    filter: drop-shadow(0 0 10px rgba(0, 210, 255, 0.6));
    animation-play-state: paused;
}

@keyframes rotate {
    0% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(90deg) scale(1.05); }
    50% { transform: rotate(180deg) scale(1); }
    75% { transform: rotate(270deg) scale(1.05); }
    100% { transform: rotate(360deg) scale(1); }
}

/* Blinking Lights Animation - Enhanced with tech lab-inspired effects */
.blinking-light {
    animation: blink 2s infinite alternate cubic-bezier(0.455, 0.03, 0.515, 0.955);
    position: relative;
}

.blinking-light::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-color);
    animation: blinkGlow 2s infinite alternate cubic-bezier(0.455, 0.03, 0.515, 0.955);
    opacity: 0;
}

@keyframes blink {
    0% { opacity: 0.3; filter: brightness(0.8); }
    50% { opacity: 0.7; filter: brightness(1.1); }
    100% { opacity: 1; filter: brightness(1.3); }
}

@keyframes blinkGlow {
    0% { opacity: 0; transform: scale(0.8); }
    100% { opacity: 0.7; transform: scale(1.2); }
}

/* VTOL Drone Animation */
.vtol-drone {
    position: relative;
    width: 500px;
    height: 300px;
    transform-style: preserve-3d;
    transition: transform 0.3s ease;
    animation: droneHover 4s infinite ease-in-out;
}

.vtol-drone svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 10px rgba(0, 210, 255, 0.3));
}

.vtol-drone:hover {
    filter: drop-shadow(0 0 15px rgba(0, 210, 255, 0.5));
}

/* Self-Driving Car Animation */
.self-driving-car {
    position: absolute;
    width: 200px;
    height: 100px;
    bottom: 20px;
    left: -200px; /* Start off-screen */
    z-index: 1;
    animation: carDrive 15s linear infinite;
    transform-style: preserve-3d;
    pointer-events: none;
}

.self-driving-car svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 10px rgba(0, 210, 255, 0.2));
}

.self-driving-car:nth-child(2) {
    animation-delay: 5s;
    transform: scale(0.8);
    bottom: 15px;
}

.self-driving-car:nth-child(3) {
    animation-delay: 10s;
    transform: scale(0.7);
    bottom: 10px;
}

@keyframes carDrive {
    0% {
        left: -200px;
        transform: translateZ(0) translateY(0);
    }
    45% {
        left: 45%;
        transform: translateZ(0) translateY(-2px);
    }
    55% {
        left: 55%;
        transform: translateZ(0) translateY(0);
    }
    100% {
        left: 100%;
        transform: translateZ(0) translateY(-1px);
    }
}

/* Underwater Robot Animation */
.underwater-robot {
    position: absolute;
    width: 200px;
    height: 150px;
    bottom: -50px;
    right: 10%;
    z-index: 0;
    animation: robotSwim 12s ease-in-out infinite;
    transform-style: preserve-3d;
    pointer-events: none;
    opacity: 0.8;
}

.underwater-robot svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 15px rgba(0, 210, 255, 0.4));
}

.underwater-robot:nth-child(2) {
    animation-delay: 4s;
    transform: scale(0.6);
    right: 30%;
    bottom: -30px;
}

@keyframes robotSwim {
    0% {
        transform: translateY(0) rotate(2deg);
        opacity: 0.7;
    }
    25% {
        transform: translateY(-15px) rotate(-2deg);
        opacity: 0.8;
    }
    50% {
        transform: translateY(-25px) rotate(1deg);
        opacity: 0.9;
    }
    75% {
        transform: translateY(-10px) rotate(-1deg);
        opacity: 0.8;
    }
    100% {
        transform: translateY(0) rotate(2deg);
        opacity: 0.7;
    }
}

/* SVG Element Animations for Self-Driving Car and Underwater Robot */

/* Car Wheel Animation */
.car .wheel {
    transform-origin: center;
    animation: rotateWheel 1s linear infinite;
}

@keyframes rotateWheel {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Car Lidar Animation */
.car .lidar-scan {
    animation: lidarPulse 2s infinite;
    transform-origin: center;
}

@keyframes lidarPulse {
    0% { opacity: 0.9; stroke-width: 0.5; }
    50% { opacity: 0.3; stroke-width: 1; }
    100% { opacity: 0.9; stroke-width: 0.5; }
}

/* Car Headlight and Sensor Animation */
.car .headlight, .car .sensor {
    animation: glowPulse 1.5s infinite alternate;
}

@keyframes glowPulse {
    0% { opacity: 0.7; filter: blur(1px); }
    100% { opacity: 1; filter: blur(2px); }
}

/* Underwater Robot Propeller Animation */
.robot .propeller-blade {
    transform-origin: center;
    animation: rotatePropeller 0.2s linear infinite;
}

/* Bubble Animation */
.bubbles .bubble {
    animation: bubbleRise 8s linear infinite;
}

.bubbles .bubble:nth-child(1) { animation-delay: 0s; }
.bubbles .bubble:nth-child(2) { animation-delay: 1s; }
.bubbles .bubble:nth-child(3) { animation-delay: 2s; }
.bubbles .bubble:nth-child(4) { animation-delay: 3s; }
.bubbles .bubble:nth-child(5) { animation-delay: 4s; }

@keyframes bubbleRise {
    0% {
        transform: translateY(0) translateX(0);
        opacity: 0.6;
    }
    100% {
        transform: translateY(-250px) translateX(20px);
        opacity: 0;
    }
}

/* Water Current Animation */
.water-current {
    animation: waterFlow 8s linear infinite;
    stroke-dasharray: 10;
}

@keyframes waterFlow {
    0% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: 100; }
}

/* Robot Light Animation */
.robot-light, .antenna-light {
    animation: robotLightPulse 2s infinite alternate;
}

@keyframes robotLightPulse {
    0% { opacity: 0.7; filter: blur(2px); }
    100% { opacity: 1; filter: blur(4px); }
}

/* Rotor Animation */
.rotor {
    transform-origin: center;
    animation: rotatePropeller 0.2s linear infinite;
}

#left-front-rotor, #right-rear-rotor {
    animation-direction: reverse;
}

.rotor-circle {
    animation: pulseRotorGlow 2s infinite;
}

/* Drone Lights Animation */
.drone-light {
    animation: blinkDroneLights 1.5s infinite alternate;
}

@keyframes rotatePropeller {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

@keyframes droneHover {
    0% {
        transform: translateY(0px) rotate(0deg);
    }
    25% {
        transform: translateY(-10px) rotate(-1deg);
    }
    50% {
        transform: translateY(0px) rotate(0deg);
    }
    75% {
        transform: translateY(10px) rotate(1deg);
    }
    100% {
        transform: translateY(0px) rotate(0deg);
    }
}

@keyframes pulseRotorGlow {
    0% {
        opacity: 0.2;
        stroke-width: 1;
    }
    50% {
        opacity: 0.5;
        stroke-width: 1.5;
    }
    100% {
        opacity: 0.2;
        stroke-width: 1;
    }
}

@keyframes blinkDroneLights {
    0% {
        opacity: 0.7;
        filter: blur(1px);
    }
    100% {
        opacity: 1;
        filter: blur(2px);
        box-shadow: 0 0 5px currentColor;
    }
}