/* ==========================================================================
   Animations - Motion & Effects
   ========================================================================== */

/* --------------------------------------------------------------------------
   Gradient Background
   -------------------------------------------------------------------------- */
.gradient-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 20s ease-in-out infinite;
}

.gradient-orb:nth-child(1) {
    width: 600px;
    height: 600px;
    background: var(--yale);
    top: -200px;
    right: -100px;
    animation-delay: 0s;
}

.gradient-orb:nth-child(2) {
    width: 500px;
    height: 500px;
    background: var(--keppel);
    bottom: -150px;
    left: -100px;
    animation-delay: -5s;
}

.gradient-orb:nth-child(3) {
    width: 400px;
    height: 400px;
    background: var(--key-lime);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -10s;
    opacity: 0.2;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(50px, -30px) scale(1.1); }
    50% { transform: translate(-30px, 50px) scale(0.95); }
    75% { transform: translate(-50px, -20px) scale(1.05); }
}

/* Third orb needs special handling due to initial transform */
.gradient-orb:nth-child(3) {
    animation: floatCenter 20s ease-in-out infinite;
}

@keyframes floatCenter {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    25% { transform: translate(-45%, -55%) scale(1.1); }
    50% { transform: translate(-55%, -45%) scale(0.95); }
    75% { transform: translate(-48%, -52%) scale(1.05); }
}

/* --------------------------------------------------------------------------
   Fade In Animations
   -------------------------------------------------------------------------- */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Animation utility classes */
.animate-fade-in {
    animation: fadeIn 0.8s ease-out both;
}

.animate-fade-in-up {
    animation: fadeInUp 0.8s ease-out both;
}

.animate-fade-in-down {
    animation: fadeInDown 0.8s ease-out both;
}

.animate-fade-in-left {
    animation: fadeInLeft 0.8s ease-out both;
}

.animate-fade-in-right {
    animation: fadeInRight 0.8s ease-out both;
}

/* Stagger delays */
.delay-100 { animation-delay: 0.1s; }
.delay-200 { animation-delay: 0.2s; }
.delay-300 { animation-delay: 0.3s; }
.delay-400 { animation-delay: 0.4s; }
.delay-500 { animation-delay: 0.5s; }

/* --------------------------------------------------------------------------
   Pulse Animation
   -------------------------------------------------------------------------- */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

.animate-pulse {
    animation: pulse 2s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   Bounce Animation
   -------------------------------------------------------------------------- */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(10px);
    }
}

.animate-bounce {
    animation: bounce 2s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   Flow Animation (for arrows, progress indicators)
   -------------------------------------------------------------------------- */
@keyframes flowRight {
    0% { clip-path: inset(0 100% 0 0); }
    50% { clip-path: inset(0 0 0 0); }
    100% { clip-path: inset(0 0 0 100%); }
}

.animate-flow {
    animation: flowRight 2s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   Scroll-triggered animations (add .in-view class via JS)
   -------------------------------------------------------------------------- */
.reveal {
    opacity: 0;
    transform: translateY(40px);
    transition: all 0.8s ease-out;
}

.reveal.in-view {
    opacity: 1;
    transform: translateY(0);
}

.reveal-left {
    opacity: 0;
    transform: translateX(-40px);
    transition: all 0.8s ease-out;
}

.reveal-left.in-view {
    opacity: 1;
    transform: translateX(0);
}

.reveal-right {
    opacity: 0;
    transform: translateX(40px);
    transition: all 0.8s ease-out;
}

.reveal-right.in-view {
    opacity: 1;
    transform: translateX(0);
}

/* Stagger children */
.stagger-children > * {
    opacity: 0;
    transform: translateY(30px);
    transition: all 0.6s ease-out;
}

.stagger-children.in-view > *:nth-child(1) { opacity: 1; transform: translateY(0); transition-delay: 0s; }
.stagger-children.in-view > *:nth-child(2) { opacity: 1; transform: translateY(0); transition-delay: 0.1s; }
.stagger-children.in-view > *:nth-child(3) { opacity: 1; transform: translateY(0); transition-delay: 0.2s; }
.stagger-children.in-view > *:nth-child(4) { opacity: 1; transform: translateY(0); transition-delay: 0.3s; }
.stagger-children.in-view > *:nth-child(5) { opacity: 1; transform: translateY(0); transition-delay: 0.4s; }
.stagger-children.in-view > *:nth-child(6) { opacity: 1; transform: translateY(0); transition-delay: 0.5s; }
.stagger-children.in-view > *:nth-child(7) { opacity: 1; transform: translateY(0); transition-delay: 0.6s; }
.stagger-children.in-view > *:nth-child(8) { opacity: 1; transform: translateY(0); transition-delay: 0.7s; }
.stagger-children.in-view > *:nth-child(9) { opacity: 1; transform: translateY(0); transition-delay: 0.8s; }
.stagger-children.in-view > *:nth-child(10) { opacity: 1; transform: translateY(0); transition-delay: 0.9s; }
.stagger-children.in-view > *:nth-child(11) { opacity: 1; transform: translateY(0); transition-delay: 1s; }
.stagger-children.in-view > *:nth-child(12) { opacity: 1; transform: translateY(0); transition-delay: 1.1s; }
.stagger-children.in-view > *:nth-child(n+13) { opacity: 1; transform: translateY(0); transition-delay: 1.2s; }

/* --------------------------------------------------------------------------
   Hover Effects
   -------------------------------------------------------------------------- */
.hover-lift {
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.hover-lift:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
}

.hover-glow {
    transition: box-shadow var(--transition-base);
}

.hover-glow:hover {
    box-shadow: var(--shadow-glow);
}

.hover-scale {
    transition: transform var(--transition-base);
}

.hover-scale:hover {
    transform: scale(1.05);
}

/* --------------------------------------------------------------------------
   Animated Graphics - Data Flow Visualization
   -------------------------------------------------------------------------- */
.data-flow-graphic {
    position: relative;
    width: 100%;
    max-width: 600px;
    aspect-ratio: 4/3;
    margin: 0 auto;
}

.data-flow-graphic svg {
    width: 100%;
    height: 100%;
}

/* Animated connection lines */
@keyframes dashFlow {
    0% { stroke-dashoffset: 100; }
    100% { stroke-dashoffset: 0; }
}

@keyframes dashFlowReverse {
    0% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: 100; }
}

.flow-line {
    stroke-dasharray: 8, 4;
    animation: dashFlow 2s linear infinite;
}

.flow-line-reverse {
    stroke-dasharray: 8, 4;
    animation: dashFlowReverse 2s linear infinite;
}

/* Pulsing nodes */
@keyframes nodePulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.15);
        opacity: 0.8;
    }
}

.data-node {
    animation: nodePulse 2s ease-in-out infinite;
}

.data-node:nth-child(2) { animation-delay: 0.3s; }
.data-node:nth-child(3) { animation-delay: 0.6s; }
.data-node:nth-child(4) { animation-delay: 0.9s; }
.data-node:nth-child(5) { animation-delay: 1.2s; }

/* Data particle animation */
@keyframes particleMove {
    0% {
        offset-distance: 0%;
        opacity: 0;
    }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% {
        offset-distance: 100%;
        opacity: 0;
    }
}

.data-particle {
    offset-rotate: 0deg;
    animation: particleMove 3s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   Hero Data Visualization
   -------------------------------------------------------------------------- */
.hero-visual {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
}

.hero-visual svg {
    width: 100%;
    max-width: 500px;
    height: auto;
}

/* Animated hexagon grid */
@keyframes hexPulse {
    0%, 100% {
        fill-opacity: 0.1;
        stroke-opacity: 0.3;
    }
    50% {
        fill-opacity: 0.3;
        stroke-opacity: 0.6;
    }
}

.hex-cell {
    animation: hexPulse 3s ease-in-out infinite;
}

.hex-cell:nth-child(odd) { animation-delay: 0s; }
.hex-cell:nth-child(even) { animation-delay: 1.5s; }
.hex-cell:nth-child(3n) { animation-delay: 0.5s; }
.hex-cell:nth-child(4n) { animation-delay: 1s; }
.hex-cell:nth-child(5n) { animation-delay: 2s; }

/* Circuit pattern animation */
@keyframes circuitGlow {
    0%, 100% {
        stroke: var(--yale);
        filter: drop-shadow(0 0 2px var(--yale));
    }
    50% {
        stroke: var(--keppel);
        filter: drop-shadow(0 0 8px var(--keppel));
    }
}

.circuit-line {
    stroke-width: 2;
    fill: none;
    animation: circuitGlow 4s ease-in-out infinite;
}

.circuit-line:nth-child(2) { animation-delay: 0.5s; }
.circuit-line:nth-child(3) { animation-delay: 1s; }
.circuit-line:nth-child(4) { animation-delay: 1.5s; }

/* Animated code/data blocks */
@keyframes codeScroll {
    0% { transform: translateY(0); }
    100% { transform: translateY(-50%); }
}

.code-stream {
    animation: codeScroll 20s linear infinite;
}

/* Transformation arrow animation */
@keyframes arrowPulse {
    0%, 100% {
        transform: translateX(0);
        opacity: 1;
    }
    50% {
        transform: translateX(10px);
        opacity: 0.6;
    }
}

.transform-arrow {
    animation: arrowPulse 1.5s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   Floating Elements
   -------------------------------------------------------------------------- */
@keyframes floatGentle {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-10px) rotate(2deg); }
    50% { transform: translateY(-5px) rotate(-1deg); }
    75% { transform: translateY(-15px) rotate(1deg); }
}

.float-gentle {
    animation: floatGentle 6s ease-in-out infinite;
}

.float-gentle:nth-child(2) { animation-delay: -1s; }
.float-gentle:nth-child(3) { animation-delay: -2s; }
.float-gentle:nth-child(4) { animation-delay: -3s; }

/* --------------------------------------------------------------------------
   Icon Animations
   -------------------------------------------------------------------------- */
@keyframes iconSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes iconBounce {
    0%, 100% { transform: translateY(0); }
    25% { transform: translateY(-5px); }
    75% { transform: translateY(3px); }
}

.icon-spin {
    animation: iconSpin 8s linear infinite;
}

.icon-bounce {
    animation: iconBounce 2s ease-in-out infinite;
}

/* Database icon pulse */
@keyframes dbPulse {
    0%, 100% {
        transform: scaleY(1);
    }
    50% {
        transform: scaleY(1.05);
    }
}

.db-icon {
    transform-origin: center bottom;
    animation: dbPulse 2s ease-in-out infinite;
}

/* Gear rotation */
@keyframes gearRotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.gear-icon {
    animation: gearRotate 10s linear infinite;
}

.gear-icon-reverse {
    animation: gearRotate 10s linear infinite reverse;
}

/* --------------------------------------------------------------------------
   Number Counter Animation (CSS only visual)
   -------------------------------------------------------------------------- */
@keyframes countUp {
    0% { opacity: 0; transform: translateY(20px); }
    10% { opacity: 1; transform: translateY(0); }
    90% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-20px); }
}

.stat-number {
    animation: countUp 3s ease-out both;
}

/* --------------------------------------------------------------------------
   Typing/Loading Animation
   -------------------------------------------------------------------------- */
@keyframes typing {
    0%, 100% { width: 0; }
    50% { width: 100%; }
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.typing-text {
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid var(--color-primary);
    animation: typing 4s steps(30) infinite, blink 0.8s step-end infinite;
}

/* --------------------------------------------------------------------------
   Progress Bar Animation
   -------------------------------------------------------------------------- */
@keyframes progressFill {
    0% { width: 0; }
    100% { width: var(--progress, 100%); }
}

.progress-bar {
    animation: progressFill 2s ease-out both;
}

/* --------------------------------------------------------------------------
   Morphing Shape
   -------------------------------------------------------------------------- */
@keyframes morphShape {
    0%, 100% {
        border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
    }
    25% {
        border-radius: 30% 60% 70% 40% / 50% 60% 30% 60%;
    }
    50% {
        border-radius: 50% 60% 30% 60% / 30% 60% 70% 40%;
    }
    75% {
        border-radius: 60% 40% 60% 30% / 70% 30% 50% 60%;
    }
}

.morph-shape {
    animation: morphShape 8s ease-in-out infinite;
}

/* --------------------------------------------------------------------------
   Data Stream Visualization
   -------------------------------------------------------------------------- */
.data-stream-container {
    position: relative;
    overflow: hidden;
    height: 300px;
    border-radius: var(--radius-xl);
    background: var(--bg-dark-elevated);
    border: 1px solid var(--border-subtle);
}

@keyframes streamLine {
    0% {
        transform: translateX(-100%);
        opacity: 0;
    }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% {
        transform: translateX(100vw);
        opacity: 0;
    }
}

.stream-line {
    position: absolute;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--keppel), var(--color-primary), transparent);
    animation: streamLine 3s linear infinite;
}

.stream-line:nth-child(1) { top: 20%; animation-delay: 0s; width: 100px; }
.stream-line:nth-child(2) { top: 40%; animation-delay: 0.5s; width: 150px; }
.stream-line:nth-child(3) { top: 60%; animation-delay: 1s; width: 80px; }
.stream-line:nth-child(4) { top: 80%; animation-delay: 1.5s; width: 120px; }
.stream-line:nth-child(5) { top: 30%; animation-delay: 2s; width: 90px; }
.stream-line:nth-child(6) { top: 70%; animation-delay: 2.5s; width: 110px; }

/* --------------------------------------------------------------------------
   Reduced Motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .gradient-orb {
        animation: none;
    }
}
