/**
 * TFL AI Landing Animations v1.0
 * Scroll-triggered animations with Lenis smooth scroll integration
 *
 * Dependencies:
 * - Lenis (https://github.com/darkroomengineering/lenis) - optional but recommended
 * - IntersectionObserver (native browser API)
 */

/* ==========================================================================
   1. LENIS SMOOTH SCROLL SETUP
   ========================================================================== */

/**
 * Lenis Integration Notes:
 * Include in HTML: <script src="https://cdn.jsdelivr.net/npm/@studio-freight/lenis@1.0.42/dist/lenis.min.js"></script>
 * Initialize in JS:
 *
 * const lenis = new Lenis({
 *     duration: 1.2,
 *     easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
 *     direction: 'vertical',
 *     gestureDirection: 'vertical',
 *     smooth: true,
 *     mouseMultiplier: 1,
 *     smoothTouch: false,
 *     touchMultiplier: 2,
 *     infinite: false,
 * });
 *
 * function raf(time) {
 *     lenis.raf(time);
 *     requestAnimationFrame(raf);
 * }
 * requestAnimationFrame(raf);
 */

/* Lenis required styles */
html.lenis,
html.lenis body {
    height: auto;
}

.lenis.lenis-smooth {
    scroll-behavior: auto !important;
}

.lenis.lenis-smooth [data-lenis-prevent] {
    overscroll-behavior: contain;
}

.lenis.lenis-stopped {
    overflow: hidden;
}

.lenis.lenis-scrolling iframe {
    pointer-events: none;
}

/* ==========================================================================
   2. SCROLL-TRIGGERED ANIMATION CLASSES
   ========================================================================== */

/* Base state for all animated elements */
[data-animate] {
    opacity: 0;
    will-change: transform, opacity;
    transition:
        opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Visible state */
[data-animate].is-visible {
    opacity: 1;
}

/* Fade In Up */
[data-animate="fade-up"] {
    transform: translateY(40px);
}

[data-animate="fade-up"].is-visible {
    transform: translateY(0);
}

/* Fade In Down */
[data-animate="fade-down"] {
    transform: translateY(-40px);
}

[data-animate="fade-down"].is-visible {
    transform: translateY(0);
}

/* Fade In Left */
[data-animate="fade-left"] {
    transform: translateX(-40px);
}

[data-animate="fade-left"].is-visible {
    transform: translateX(0);
}

/* Fade In Right */
[data-animate="fade-right"] {
    transform: translateX(40px);
}

[data-animate="fade-right"].is-visible {
    transform: translateX(0);
}

/* Scale Up */
[data-animate="scale-up"] {
    transform: scale(0.9);
}

[data-animate="scale-up"].is-visible {
    transform: scale(1);
}

/* Scale Down */
[data-animate="scale-down"] {
    transform: scale(1.1);
}

[data-animate="scale-down"].is-visible {
    transform: scale(1);
}

/* Blur In */
[data-animate="blur-in"] {
    filter: blur(10px);
    transform: translateY(20px);
}

[data-animate="blur-in"].is-visible {
    filter: blur(0);
    transform: translateY(0);
}

/* Rotate In */
[data-animate="rotate-in"] {
    transform: rotate(-5deg) translateY(30px);
}

[data-animate="rotate-in"].is-visible {
    transform: rotate(0) translateY(0);
}

/* Clip Reveal (from bottom) */
[data-animate="clip-up"] {
    clip-path: inset(100% 0 0 0);
    transform: translateY(0);
    opacity: 1;
}

[data-animate="clip-up"].is-visible {
    clip-path: inset(0 0 0 0);
}

/* Clip Reveal (from left) */
[data-animate="clip-left"] {
    clip-path: inset(0 100% 0 0);
    transform: translateX(0);
    opacity: 1;
}

[data-animate="clip-left"].is-visible {
    clip-path: inset(0 0 0 0);
}

/* ==========================================================================
   3. STAGGER DELAYS
   ========================================================================== */

[data-delay="1"] { transition-delay: 0.1s; }
[data-delay="2"] { transition-delay: 0.2s; }
[data-delay="3"] { transition-delay: 0.3s; }
[data-delay="4"] { transition-delay: 0.4s; }
[data-delay="5"] { transition-delay: 0.5s; }
[data-delay="6"] { transition-delay: 0.6s; }
[data-delay="7"] { transition-delay: 0.7s; }
[data-delay="8"] { transition-delay: 0.8s; }

/* Stagger children automatically */
.stagger-children > *:nth-child(1) { transition-delay: 0.1s; }
.stagger-children > *:nth-child(2) { transition-delay: 0.2s; }
.stagger-children > *:nth-child(3) { transition-delay: 0.3s; }
.stagger-children > *:nth-child(4) { transition-delay: 0.4s; }
.stagger-children > *:nth-child(5) { transition-delay: 0.5s; }
.stagger-children > *:nth-child(6) { transition-delay: 0.6s; }
.stagger-children > *:nth-child(7) { transition-delay: 0.7s; }
.stagger-children > *:nth-child(8) { transition-delay: 0.8s; }
.stagger-children > *:nth-child(9) { transition-delay: 0.9s; }
.stagger-children > *:nth-child(10) { transition-delay: 1s; }

/* ==========================================================================
   4. DURATION MODIFIERS
   ========================================================================== */

[data-duration="fast"] {
    transition-duration: 0.4s;
}

[data-duration="normal"] {
    transition-duration: 0.8s;
}

[data-duration="slow"] {
    transition-duration: 1.2s;
}

[data-duration="very-slow"] {
    transition-duration: 1.6s;
}

/* ==========================================================================
   5. EASING MODIFIERS
   ========================================================================== */

[data-easing="ease-out"] {
    transition-timing-function: cubic-bezier(0, 0, 0.2, 1);
}

[data-easing="ease-in-out"] {
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

[data-easing="spring"] {
    transition-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-easing="bounce"] {
    transition-timing-function: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

[data-easing="smooth"] {
    transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==========================================================================
   6. KEYFRAME ANIMATIONS
   ========================================================================== */

/* Glow Pulse */
@keyframes glowPulse {
    0%, 100% {
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4), 0 0 20px rgba(81, 175, 234, 0.3);
    }
    50% {
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4), 0 0 40px rgba(81, 175, 234, 0.5);
    }
}

.animate-glow {
    animation: glowPulse 2s ease-in-out infinite;
}

/* Float */
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.animate-float {
    animation: float 3s ease-in-out infinite;
}

/* Pulse Scale */
@keyframes pulseScale {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.animate-pulse-scale {
    animation: pulseScale 2s ease-in-out infinite;
}

/* Shimmer */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.animate-shimmer {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 2s linear infinite;
}

/* Rotate Border (for CTAs) */
@keyframes rotateBorder {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.animate-rotate-border::before {
    animation: rotateBorder 4s linear infinite;
}

/* Typing Cursor */
@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.animate-cursor::after {
    content: '|';
    animation: blink 1s step-end infinite;
    color: var(--accent-primary, #51afea);
    margin-left: 2px;
}

/* Gradient Flow */
@keyframes gradientFlow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.animate-gradient {
    background-size: 200% 200%;
    animation: gradientFlow 4s ease infinite;
}

/* Logo Scroll (for carousel) */
@keyframes logoScroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

.animate-logo-scroll {
    animation: logoScroll 30s linear infinite;
}

/* Fade In (general use) */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.animate-fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

/* Slide In From Bottom */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-slide-in-up {
    animation: slideInUp 0.6s ease-out forwards;
}

/* Bounce In */
@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        transform: scale(1);
    }
}

.animate-bounce-in {
    animation: bounceIn 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

/* ==========================================================================
   7. COUNTER ANIMATIONS
   ========================================================================== */

@keyframes countUp {
    from {
        opacity: 0;
        transform: scale(0.5) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.counter-animate {
    animation: countUp 0.5s ease-out forwards;
}

/* ==========================================================================
   8. PARALLAX HELPERS
   ========================================================================== */

[data-parallax] {
    will-change: transform;
    transition: transform 0.1s linear;
}

[data-parallax="slow"] {
    --parallax-speed: 0.3;
}

[data-parallax="medium"] {
    --parallax-speed: 0.5;
}

[data-parallax="fast"] {
    --parallax-speed: 0.7;
}

/* ==========================================================================
   9. HERO-SPECIFIC ANIMATIONS
   ========================================================================== */

/* Hero Title Animation */
.hero-title-animate {
    animation: heroTitleReveal 1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    animation-delay: 0.2s;
    opacity: 0;
}

@keyframes heroTitleReveal {
    from {
        opacity: 0;
        transform: translateY(40px);
        filter: blur(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
        filter: blur(0);
    }
}

/* Hero Subtitle Animation */
.hero-subtitle-animate {
    animation: heroSubtitleReveal 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    animation-delay: 0.4s;
    opacity: 0;
}

@keyframes heroSubtitleReveal {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Hero CTA Animation */
.hero-cta-animate {
    animation: heroCTAReveal 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    animation-delay: 0.6s;
    opacity: 0;
}

@keyframes heroCTAReveal {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Hero Demo Animation */
.hero-demo-animate {
    animation: heroDemoReveal 1s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    animation-delay: 0.8s;
    opacity: 0;
}

@keyframes heroDemoReveal {
    from {
        opacity: 0;
        transform: translateY(60px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==========================================================================
   10. HOVER EFFECTS
   ========================================================================== */

/* Lift on Hover */
.hover-lift {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.hover-lift:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

/* Glow on Hover */
.hover-glow {
    transition: box-shadow 0.3s ease;
}

.hover-glow:hover {
    box-shadow: 0 0 30px rgba(81, 175, 234, 0.3);
}

/* Scale on Hover */
.hover-scale {
    transition: transform 0.3s ease;
}

.hover-scale:hover {
    transform: scale(1.02);
}

/* Border Accent on Hover */
.hover-border-accent {
    transition: border-color 0.3s ease;
}

.hover-border-accent:hover {
    border-color: rgba(81, 175, 234, 0.5);
}

/* ==========================================================================
   11. LOADING STATES
   ========================================================================== */

/* Skeleton Loading */
@keyframes skeletonPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.skeleton {
    background: linear-gradient(90deg,
        rgba(255, 255, 255, 0.05) 0%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0.05) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s linear infinite;
    border-radius: 4px;
}

/* Spinner */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(81, 175, 234, 0.2);
    border-top-color: #51afea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ==========================================================================
   12. REDUCED MOTION SUPPORT
   ========================================================================== */

