/**
 * EcoGround Premium Animations
 * Version 2.0 - GSAP-inspired smooth animations
 */

/* ============================================
   BASE ANIMATION SETTINGS
   ============================================ */
:root {
    --anim-duration: 0.8s;
    --anim-duration-fast: 0.4s;
    --anim-duration-slow: 1.2s;
    --anim-ease: cubic-bezier(0.19, 1, 0.22, 1);
    --anim-ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --anim-ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ============================================
   REVEAL ANIMATIONS (Scroll-triggered)
   ============================================ */

/* Fade In */
.reveal {
    opacity: 0;
    transition: all var(--anim-duration) var(--anim-ease);
}

.reveal.visible {
    opacity: 1;
}

/* Fade In Up */
.fade-in-up {
    opacity: 0;
    transform: translateY(60px);
    transition: opacity var(--anim-duration) var(--anim-ease),
                transform var(--anim-duration) var(--anim-ease);
}

.fade-in-up.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Fade In Down */
.fade-in-down {
    opacity: 0;
    transform: translateY(-60px);
    transition: opacity var(--anim-duration) var(--anim-ease),
                transform var(--anim-duration) var(--anim-ease);
}

.fade-in-down.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Fade In Left */
.fade-in-left {
    opacity: 0;
    transform: translateX(-60px);
    transition: opacity var(--anim-duration) var(--anim-ease),
                transform var(--anim-duration) var(--anim-ease);
}

.fade-in-left.visible {
    opacity: 1;
    transform: translateX(0);
}

/* Fade In Right */
.fade-in-right {
    opacity: 0;
    transform: translateX(60px);
    transition: opacity var(--anim-duration) var(--anim-ease),
                transform var(--anim-duration) var(--anim-ease);
}

.fade-in-right.visible {
    opacity: 1;
    transform: translateX(0);
}

/* Scale In */
.scale-in {
    opacity: 0;
    transform: scale(0.9);
    transition: opacity var(--anim-duration) var(--anim-ease),
                transform var(--anim-duration) var(--anim-ease-spring);
}

.scale-in.visible {
    opacity: 1;
    transform: scale(1);
}

/* Rotate In */
.rotate-in {
    opacity: 0;
    transform: rotate(-10deg) scale(0.9);
    transition: opacity var(--anim-duration) var(--anim-ease),
                transform var(--anim-duration) var(--anim-ease-spring);
}

.rotate-in.visible {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Blur In */
.blur-in {
    opacity: 0;
    filter: blur(20px);
    transform: scale(1.1);
    transition: all var(--anim-duration-slow) var(--anim-ease);
}

.blur-in.visible {
    opacity: 1;
    filter: blur(0);
    transform: scale(1);
}

/* ============================================
   STAGGER ANIMATIONS
   ============================================ */
.stagger-children > * {
    opacity: 0;
    transform: translateY(40px);
    transition: opacity var(--anim-duration) var(--anim-ease),
                transform var(--anim-duration) var(--anim-ease);
}

.stagger-children.visible > *:nth-child(1) { transition-delay: 0s; }
.stagger-children.visible > *:nth-child(2) { transition-delay: 0.1s; }
.stagger-children.visible > *:nth-child(3) { transition-delay: 0.2s; }
.stagger-children.visible > *:nth-child(4) { transition-delay: 0.3s; }
.stagger-children.visible > *:nth-child(5) { transition-delay: 0.4s; }
.stagger-children.visible > *:nth-child(6) { transition-delay: 0.5s; }
.stagger-children.visible > *:nth-child(7) { transition-delay: 0.6s; }
.stagger-children.visible > *:nth-child(8) { transition-delay: 0.7s; }

.stagger-children.visible > * {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger from left */
.stagger-left > * {
    opacity: 0;
    transform: translateX(-40px);
    transition: opacity var(--anim-duration) var(--anim-ease),
                transform var(--anim-duration) var(--anim-ease);
}

.stagger-left.visible > *:nth-child(1) { transition-delay: 0s; }
.stagger-left.visible > *:nth-child(2) { transition-delay: 0.1s; }
.stagger-left.visible > *:nth-child(3) { transition-delay: 0.2s; }
.stagger-left.visible > *:nth-child(4) { transition-delay: 0.3s; }

.stagger-left.visible > * {
    opacity: 1;
    transform: translateX(0);
}

/* ============================================
   HERO ANIMATIONS
   ============================================ */

/* Hero badge entrance */
.hero-badge {
    animation: badge-entrance 1s var(--anim-ease) 0.2s both;
}

@keyframes badge-entrance {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Hero title entrance */
.hero-title {
    animation: title-entrance 1.2s var(--anim-ease) 0.4s both;
}

@keyframes title-entrance {
    from {
        opacity: 0;
        transform: translateY(40px);
        filter: blur(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
        filter: blur(0);
    }
}

/* Hero description entrance */
.hero-description {
    animation: desc-entrance 1s var(--anim-ease) 0.7s both;
}

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

/* Hero actions entrance */
.hero-actions {
    animation: actions-entrance 1s var(--anim-ease) 0.9s both;
}

@keyframes actions-entrance {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Hero stats entrance */
.hero-stats {
    animation: stats-entrance 1s var(--anim-ease) 1.1s both;
}

@keyframes stats-entrance {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.hero-stat {
    animation: stat-entrance 0.8s var(--anim-ease) both;
}

.hero-stat:nth-child(1) { animation-delay: 1.2s; }
.hero-stat:nth-child(2) { animation-delay: 1.3s; }
.hero-stat:nth-child(3) { animation-delay: 1.4s; }
.hero-stat:nth-child(4) { animation-delay: 1.5s; }

@keyframes stat-entrance {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============================================
   TEXT ANIMATIONS
   ============================================ */

/* Gradient text animation */
.text-gradient-animate {
    background-size: 300% auto;
    animation: gradient-flow 8s ease infinite;
}

@keyframes gradient-flow {
    0% { background-position: 0% center; }
    50% { background-position: 100% center; }
    100% { background-position: 0% center; }
}

/* Text reveal character by character */
.text-reveal {
    overflow: hidden;
}

.text-reveal span {
    display: inline-block;
    animation: char-reveal 0.6s var(--anim-ease-spring) both;
}

@keyframes char-reveal {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Typing effect */
.typing {
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid var(--accent-emerald);
    animation: typing 3s steps(40, end), blink-caret 0.75s step-end infinite;
}

@keyframes typing {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes blink-caret {
    from, to { border-color: transparent; }
    50% { border-color: var(--accent-emerald); }
}

/* ============================================
   BUTTON ANIMATIONS
   ============================================ */

/* Button shine effect */
.btn-shine {
    position: relative;
    overflow: hidden;
}

.btn-shine::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -100%;
    width: 50%;
    height: 200%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    transform: skewX(-20deg);
    transition: left 0.7s var(--anim-ease);
}

.btn-shine:hover::after {
    left: 150%;
}

/* Button ripple effect */
.btn-ripple {
    position: relative;
    overflow: hidden;
}

.btn-ripple::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s var(--anim-ease), height 0.6s var(--anim-ease);
}

.btn-ripple:active::before {
    width: 300px;
    height: 300px;
}

/* Magnetic button effect (needs JS) */
.btn-magnetic {
    transition: transform 0.3s var(--anim-ease);
}

/* ============================================
   CARD ANIMATIONS
   ============================================ */

/* Card hover glow */
.card-glow {
    transition: all var(--anim-duration-fast) var(--anim-ease);
}

.card-glow:hover {
    box-shadow:
        0 0 20px var(--accent-emerald-glow),
        0 0 40px var(--accent-emerald-glow),
        0 0 60px rgba(0, 212, 170, 0.1);
}

/* Card 3D tilt (needs JS) */
.card-3d {
    transform-style: preserve-3d;
    transition: transform 0.3s var(--anim-ease);
}

.card-3d:hover {
    transform: perspective(1000px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
}

/* Card border gradient animation */
.card-border-animate {
    position: relative;
}

.card-border-animate::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 2px;
    background: linear-gradient(
        90deg,
        var(--accent-emerald),
        var(--accent-sapphire),
        var(--accent-amethyst),
        var(--accent-emerald)
    );
    background-size: 300% 100%;
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    animation: border-gradient 4s linear infinite;
    opacity: 0;
    transition: opacity 0.3s var(--anim-ease);
}

.card-border-animate:hover::before {
    opacity: 1;
}

@keyframes border-gradient {
    0% { background-position: 0% center; }
    100% { background-position: 300% center; }
}

/* ============================================
   LOADER / SPINNER
   ============================================ */

/* Premium spinner */
.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--glass-border);
    border-top-color: var(--accent-emerald);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Pulse loader */
.pulse-loader {
    width: 12px;
    height: 12px;
    background: var(--accent-emerald);
    border-radius: 50%;
    animation: pulse-loader 1.5s ease-in-out infinite;
}

@keyframes pulse-loader {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.5);
        opacity: 0.5;
    }
}

/* Dots loader */
.dots-loader {
    display: flex;
    gap: 8px;
}

.dots-loader span {
    width: 8px;
    height: 8px;
    background: var(--accent-emerald);
    border-radius: 50%;
    animation: dots-bounce 1.4s ease-in-out infinite both;
}

.dots-loader span:nth-child(1) { animation-delay: -0.32s; }
.dots-loader span:nth-child(2) { animation-delay: -0.16s; }

@keyframes dots-bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* ============================================
   ICON ANIMATIONS
   ============================================ */

/* Floating icon */
.icon-float {
    animation: icon-float 3s ease-in-out infinite;
}

@keyframes icon-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Rotating icon */
.icon-rotate {
    animation: icon-rotate 8s linear infinite;
}

@keyframes icon-rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Pulsing icon */
.icon-pulse {
    animation: icon-pulse 2s ease-in-out infinite;
}

@keyframes icon-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

/* ============================================
   BACKGROUND ANIMATIONS
   ============================================ */

/* Gradient background shift */
.bg-gradient-animate {
    background-size: 200% 200%;
    animation: gradient-bg 15s ease infinite;
}

@keyframes gradient-bg {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Parallax layers (needs JS for full effect) */
.parallax-layer {
    will-change: transform;
}

/* Floating elements */
.float-slow {
    animation: float-slow 6s ease-in-out infinite;
}

.float-medium {
    animation: float-medium 4s ease-in-out infinite;
}

.float-fast {
    animation: float-fast 3s ease-in-out infinite;
}

@keyframes float-slow {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-20px) rotate(5deg); }
}

@keyframes float-medium {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

@keyframes float-fast {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* ============================================
   COSMIC EFFECTS (PC Only)
   ============================================ */

/* Nebula animation */
.nebula {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    animation: nebula-drift 20s ease-in-out infinite;
    pointer-events: none;
}

.nebula-1 {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, var(--accent-sapphire-glow), transparent);
    top: -200px;
    left: -200px;
    animation-delay: 0s;
}

.nebula-2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, var(--accent-amethyst-glow), transparent);
    bottom: -150px;
    right: -150px;
    animation-delay: -5s;
}

.nebula-3 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, var(--accent-emerald-glow), transparent);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -10s;
}

@keyframes nebula-drift {
    0%, 100% {
        transform: translate(0, 0) scale(1);
        opacity: 0.3;
    }
    25% {
        transform: translate(30px, -20px) scale(1.1);
        opacity: 0.4;
    }
    50% {
        transform: translate(-20px, 30px) scale(0.9);
        opacity: 0.5;
    }
    75% {
        transform: translate(-30px, -10px) scale(1.05);
        opacity: 0.35;
    }
}

/* Star twinkle */
.star {
    position: absolute;
    width: 2px;
    height: 2px;
    background: var(--color-white);
    border-radius: 50%;
    animation: twinkle 3s ease-in-out infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.5); }
}

/* Celestial orbit */
.orbit {
    position: absolute;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    animation: orbit-rotate 30s linear infinite;
}

@keyframes orbit-rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ============================================
   SCROLL PROGRESS INDICATOR
   ============================================ */
.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: var(--gradient-primary);
    transform-origin: left;
    transform: scaleX(0);
    z-index: 9999;
    transition: transform 0.1s linear;
}

/* ============================================
   PAGE TRANSITIONS
   ============================================ */
.page-transition-enter {
    opacity: 0;
    transform: translateY(20px);
}

.page-transition-enter-active {
    opacity: 1;
    transform: translateY(0);
    transition: all 0.5s var(--anim-ease);
}

.page-transition-exit {
    opacity: 1;
}

.page-transition-exit-active {
    opacity: 0;
    transition: opacity 0.3s var(--anim-ease);
}

/* ============================================
   COUNTER ANIMATION (Needs JS)
   ============================================ */
.counter {
    font-variant-numeric: tabular-nums;
}

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

    .nebula,
    .star,
    .orbit,
    .parallax-layer {
        animation: none !important;
    }

    .fade-in-up,
    .fade-in-down,
    .fade-in-left,
    .fade-in-right,
    .scale-in,
    .rotate-in,
    .blur-in,
    .stagger-children > *,
    .stagger-left > * {
        opacity: 1;
        transform: none;
        filter: none;
    }
}
