/* AI Image Animations - 15 different animations for template processing effects */

/* ****************************
 * NATURAL SCROLL BEHAVIOR - Connected to browser's native scrolling
 * ****************************
 */

/* Enable smooth scrolling globally for all scroll operations */
html {
    scroll-behavior: smooth;
}

/* Enhanced smooth scrolling for progress containers */
.ai-progress-cards-container {
    scroll-behavior: smooth;
    /* Browser handles all scroll timing naturally */
}

@keyframes aiScan {
    0% { transform: scale(1) rotate(0deg); filter: blur(3px) hue-rotate(0deg); }
    25% { transform: scale(1.05) rotate(1deg); filter: blur(3px) hue-rotate(90deg); }
    50% { transform: scale(1.1) rotate(0deg); filter: blur(3px) hue-rotate(180deg); }
    75% { transform: scale(1.05) rotate(-1deg); filter: blur(3px) hue-rotate(270deg); }
    100% { transform: scale(1) rotate(0deg); filter: blur(3px) hue-rotate(360deg); }
}

@keyframes aiPulse {
    0%, 100% { transform: scale(1); filter: blur(3px) brightness(1); }
    50% { transform: scale(1.08); filter: blur(3px) brightness(1.3); }
}

@keyframes aiGlow {
    0%, 100% { filter: blur(3px) drop-shadow(0 0 8px rgba(0, 212, 255, 0.4)); }
    50% { filter: blur(3px) drop-shadow(0 0 25px rgba(0, 212, 255, 0.9)); }
}

@keyframes aiProcessing {
    0% { filter: blur(3px); }
    25% { filter: blur(3px) contrast(1.2); }
    50% { filter: blur(3px) contrast(1.4) saturate(1.3); }
    75% { filter: blur(3px) contrast(1.2); }
    100% { filter: blur(3px); }
}

@keyframes aiAnalyzing {
    0% { 
        filter: blur(3px); 
        box-shadow: 0 0 0 0 rgba(0, 212, 255, 0.2);
    }
    50% { 
        filter: blur(3px) brightness(1.1); 
        box-shadow: 0 0 0 8px rgba(0, 212, 255, 0.1);
    }
    100% { 
        filter: blur(3px); 
        box-shadow: 0 0 0 16px rgba(0, 212, 255, 0);
    }
}

@keyframes aiFlicker {
    0%, 90%, 100% { opacity: 1; filter: blur(3px); }
    5%, 15%, 25%, 35% { opacity: 0.7; filter: blur(3px) brightness(1.2); }
}

@keyframes aiMatrix {
    0% { filter: blur(3px) hue-rotate(0deg) contrast(1); }
    33% { filter: blur(3px) hue-rotate(120deg) contrast(1.2); }
    66% { filter: blur(3px) hue-rotate(240deg) contrast(0.8); }
    100% { filter: blur(3px) hue-rotate(360deg) contrast(1); }
}

@keyframes aiWave {
    0% { transform: skew(0deg) scale(1); filter: blur(3px); }
    25% { transform: skew(2deg) scale(1.03); filter: blur(3px) saturate(1.2); }
    50% { transform: skew(0deg) scale(1.06); filter: blur(3px) saturate(1.4); }
    75% { transform: skew(-2deg) scale(1.03); filter: blur(3px) saturate(1.2); }
    100% { transform: skew(0deg) scale(1); filter: blur(3px); }
}

@keyframes aiSpin {
    0% { transform: rotate(0deg) scale(1); filter: blur(3px); }
    50% { transform: rotate(180deg) scale(1.05); filter: blur(3px) brightness(1.2); }
    100% { transform: rotate(360deg) scale(1); filter: blur(3px); }
}

@keyframes aiShimmer {
    0% { filter: blur(3px) brightness(1) contrast(1); }
    25% { filter: blur(3px) brightness(1.3) contrast(1.2); }
    50% { filter: blur(3px) brightness(1.6) contrast(1.4); }
    75% { filter: blur(3px) brightness(1.3) contrast(1.2); }
    100% { filter: blur(3px) brightness(1) contrast(1); }
}

@keyframes aiZoom {
    0%, 100% { transform: scale(1); filter: blur(3px); }
    20% { transform: scale(1.1); filter: blur(3px) saturate(1.3); }
    40% { transform: scale(0.95); filter: blur(3px) saturate(0.8); }
    60% { transform: scale(1.05); filter: blur(3px) saturate(1.1); }
    80% { transform: scale(0.98); filter: blur(3px) saturate(0.9); }
}

@keyframes aiPhase {
    0% { opacity: 1; transform: translateX(0) scale(1); filter: blur(3px); }
    25% { opacity: 0.7; transform: translateX(2px) scale(1.02); filter: blur(3px) hue-rotate(90deg); }
    50% { opacity: 0.4; transform: translateX(0) scale(1.04); filter: blur(3px) hue-rotate(180deg); }
    75% { opacity: 0.7; transform: translateX(-2px) scale(1.02); filter: blur(3px) hue-rotate(270deg); }
    100% { opacity: 1; transform: translateX(0) scale(1); filter: blur(3px) hue-rotate(360deg); }
}

@keyframes aiVibrate {
    0%, 100% { transform: translate(0); filter: blur(3px); }
    10% { transform: translate(-1px, -1px); filter: blur(3px); }
    20% { transform: translate(1px, -1px); filter: blur(3px); }
    30% { transform: translate(-1px, 1px); filter: blur(3px); }
    40% { transform: translate(1px, 1px); filter: blur(3px); }
    50% { transform: translate(-1px, -1px); filter: blur(3px); }
    60% { transform: translate(1px, -1px); filter: blur(3px); }
    70% { transform: translate(-1px, 1px); filter: blur(3px); }
    80% { transform: translate(1px, 1px); filter: blur(3px); }
    90% { transform: translate(-1px, -1px); filter: blur(3px); }
}

@keyframes aiMorph {
    0%, 100% { border-radius: 12px; transform: scale(1); filter: blur(3px); }
    25% { border-radius: 50%; transform: scale(1.05); filter: blur(3px) hue-rotate(90deg); }
    50% { border-radius: 0; transform: scale(1.1); filter: blur(3px) hue-rotate(180deg); }
    75% { border-radius: 20px; transform: scale(1.05); filter: blur(3px) hue-rotate(270deg); }
}

@keyframes aiRipple {
    0% { transform: scale(1); filter: blur(3px); box-shadow: 0 0 0 0 rgba(0, 212, 255, 0.4); }
    50% { transform: scale(1.03); filter: blur(3px); box-shadow: 0 0 0 10px rgba(0, 212, 255, 0.1); }
    100% { transform: scale(1); filter: blur(3px); box-shadow: 0 0 0 20px rgba(0, 212, 255, 0); }
}

@keyframes aiGlitch {
    0%, 90%, 100% { transform: translate(0); filter: blur(3px); }
    5% { transform: translate(2px, 0); filter: blur(3px) hue-rotate(180deg); }
    10% { transform: translate(-2px, 0); filter: blur(3px) hue-rotate(90deg); }
    15% { transform: translate(1px, 1px); filter: blur(3px) hue-rotate(270deg); }
    20% { transform: translate(-1px, -1px); filter: blur(3px) hue-rotate(45deg); }
}

@keyframes aiFloat {
    0%, 100% { transform: translateY(0) scale(1); filter: blur(3px); }
    25% { transform: translateY(-3px) scale(1.02); filter: blur(3px) brightness(1.1); }
    50% { transform: translateY(-6px) scale(1.04); filter: blur(3px) brightness(1.2); }
    75% { transform: translateY(-3px) scale(1.02); filter: blur(3px) brightness(1.1); }
}

/* Template images container */
.template-images-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin: 20px 0;
    padding: 30px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 16px;
    border: 2px solid rgba(0, 212, 255, 0.2);
    overflow: visible;
    position: relative;
    min-height: 160px;
}

.template-image-wrapper {
    position: relative;
    display: inline-block;
    overflow: visible;
}

.template-image {
    width: 120px;
    height: 90px;
    object-fit: cover;
    border-radius: 12px;
    border: 3px solid rgba(0, 212, 255, 0.4);
    transition: all 0.3s ease;
    filter: blur(3px);
    opacity: 1;
    display: block;
}

.template-image:hover {
    border-color: rgba(0, 212, 255, 0.8);
    transform: scale(1.1);
}

/* AI Working overlays and effects */
.ai-working-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    border-radius: 12px;
    overflow: hidden;
}

.ai-working-overlay::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    background: rgba(0, 212, 255, 0.8);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    z-index: 10;
}

.ai-working-overlay::after {
    content: attr(data-icon);
    font-family: 'FontAwesome';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    color: white;
    opacity: 0;
    z-index: 11;
}

.ai-working-overlay[data-icon=""]::after {
    content: '\f013'; /* Default gear icon */
}

/* AI progress bars */
.ai-progress-bar {
    position: absolute;
    bottom: 8px;
    left: 8px;
    right: 8px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    overflow: hidden;
    opacity: 0;
}

.ai-progress-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(0, 212, 255, 0.8), transparent);
    animation: progressSweep 2s ease-in-out infinite;
}

@keyframes progressSweep {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* AI scanning line */
.ai-scan-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: 100%;
    background: linear-gradient(180deg, transparent, rgba(0, 212, 255, 1), transparent);
    opacity: 0;
    animation: scanLine 3s ease-in-out infinite;
}

@keyframes scanLine {
    0% { left: 0; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { left: calc(100% - 2px); opacity: 0; }
}

/* AI Working Overlay Animations */
@keyframes aiWorkingGear {
    0% { 
        opacity: 0; 
        transform: translate(-50%, -50%) rotate(0deg) scale(0); 
    }
    20% { 
        opacity: 1; 
        transform: translate(-50%, -50%) rotate(45deg) scale(1); 
    }
    80% { 
        opacity: 1; 
        transform: translate(-50%, -50%) rotate(315deg) scale(1); 
    }
    100% { 
        opacity: 0; 
        transform: translate(-50%, -50%) rotate(360deg) scale(0); 
    }
}

@keyframes aiWorkingIcon {
    0% { 
        opacity: 0; 
        transform: translate(-50%, -50%) scale(0); 
    }
    20% { 
        opacity: 1; 
        transform: translate(-50%, -50%) scale(1); 
    }
    80% { 
        opacity: 1; 
        transform: translate(-50%, -50%) scale(1); 
    }
    100% { 
        opacity: 0; 
        transform: translate(-50%, -50%) scale(0); 
    }
}

@keyframes aiProgressShow {
    0% { opacity: 0; }
    30% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes aiScanShow {
    0% { opacity: 0; }
    20% { opacity: 1; }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

/* Animation classes */
.ai-anim-scan { animation: aiScan 3s ease-in-out infinite; }
.ai-anim-pulse { animation: aiPulse 2s ease-in-out infinite; }
.ai-anim-glow { animation: aiGlow 2.5s ease-in-out infinite; }
.ai-anim-flicker { animation: aiFlicker 1.5s ease-in-out infinite; }
.ai-anim-matrix { animation: aiMatrix 4s linear infinite; }
.ai-anim-wave { animation: aiWave 3s ease-in-out infinite; }
.ai-anim-spin { animation: aiSpin 4s linear infinite; }
.ai-anim-shimmer { animation: aiShimmer 2s ease-in-out infinite; }
.ai-anim-zoom { animation: aiZoom 2.5s ease-in-out infinite; }
.ai-anim-phase { animation: aiPhase 3.5s ease-in-out infinite; }
.ai-anim-vibrate { animation: aiVibrate 0.8s ease-in-out infinite; }
.ai-anim-morph { animation: aiMorph 5s ease-in-out infinite; }
.ai-anim-ripple { animation: aiRipple 2s ease-in-out infinite; }
.ai-anim-glitch { animation: aiGlitch 1.2s ease-in-out infinite; }
.ai-anim-float { animation: aiFloat 3s ease-in-out infinite; }
.ai-anim-processing { animation: aiProcessing 2.8s ease-in-out infinite; }
.ai-anim-analyzing { animation: aiAnalyzing 3.2s ease-in-out infinite; }

/* AI Working overlay animations */
.ai-working-overlay.active::before {
    animation: aiWorkingGear 4s ease-in-out infinite;
}

.ai-working-overlay.active::after {
    animation: aiWorkingIcon 4s ease-in-out infinite;
}

.ai-progress-bar.active {
    animation: aiProgressShow 5s ease-in-out infinite;
}

.ai-scan-line.active {
    animation: aiScanShow 4s ease-in-out infinite;
}

/* Different animation delays for randomness */
.ai-delay-1 { animation-delay: 0.1s; }
.ai-delay-2 { animation-delay: 0.3s; }
.ai-delay-3 { animation-delay: 0.5s; }
.ai-delay-4 { animation-delay: 0.7s; }
.ai-delay-5 { animation-delay: 0.9s; }
.ai-delay-6 { animation-delay: 1.1s; }
.ai-delay-7 { animation-delay: 1.3s; }
.ai-delay-8 { animation-delay: 1.5s; }

/* ****************************
 * CSS FALLBACK ANIMATIONS for Background Tabs
 * These animations work when requestAnimationFrame is throttled
 * ****************************
 */

/* Fallback animation for progress cards when tab is hidden */
.css-animation-fallback .ai-progress-card {
    animation: pulse 2s ease-in-out infinite;
}

.css-animation-fallback .ai-progress-card.processing {
    animation: pulse 2s ease-in-out infinite, processingGlow 3s ease-in-out infinite;
}

.css-animation-fallback .ai-progress-card.completed {
    animation: completedGlow 4s ease-in-out infinite;
}

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

@keyframes completedGlow {
    0%, 100% { box-shadow: 0 0 10px rgba(34, 197, 94, 0.2); }
    50% { box-shadow: 0 0 20px rgba(34, 197, 94, 0.4); }
}

/* Fallback animations for template images */
.css-animation-fallback .template-image {
    animation: aiImageFallbackPulse 3s ease-in-out infinite;
}

.css-animation-fallback .ai-working-overlay {
    animation: workingFallback 2s ease-in-out infinite;
}

.css-animation-fallback .ai-progress-bar {
    animation: progressFallback 4s ease-in-out infinite;
}

.css-animation-fallback .ai-scan-line {
    animation: scanFallback 3s ease-in-out infinite;
}

@keyframes aiImageFallbackPulse {
    0%, 100% {
        filter: blur(3px) brightness(1);
        transform: scale(1);
    }
    50% {
        filter: blur(3px) brightness(1.2);
        transform: scale(1.03);
    }
}

@keyframes workingFallback {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

@keyframes progressFallback {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.8; }
}

@keyframes scanFallback {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Enhanced typing cursor animation that works in background tabs */
.css-animation-fallback .typing-cursor {
    animation: typingBlinkFallback 1.5s step-end infinite;
}

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

/* ****************************
 * ACCESSIBILITY - Reduced Motion Support
 * ****************************
 */

/* Respect user's preference for reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    /* Disable complex animations but keep essential feedback */
    .ai-anim-scan, .ai-anim-pulse, .ai-anim-glow, .ai-anim-flicker,
    .ai-anim-matrix, .ai-anim-wave, .ai-anim-spin, .ai-anim-shimmer,
    .ai-anim-zoom, .ai-anim-phase, .ai-anim-vibrate, .ai-anim-morph,
    .ai-anim-ripple, .ai-anim-glitch, .ai-anim-float, .ai-anim-processing,
    .ai-anim-analyzing {
        animation: none !important;
    }

    /* Simple fade for essential state changes */
    .ai-progress-card.processing {
        opacity: 0.8;
        background: rgba(59, 130, 246, 0.1);
    }

    .ai-progress-card.completed {
        opacity: 1;
        background: rgba(34, 197, 94, 0.1);
    }

    /* Keep typing cursor but make it static */
    .typing-cursor {
        animation: none !important;
        opacity: 1;
    }
}

/* ****************************
 * ENHANCED AI PROCESSING EFFECTS
 * ****************************
 */

/* New scan line effect that moves horizontally across images */
@keyframes aiScanLineAdvanced {
    0% {
        transform: translateX(-100%);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Matrix rain effect overlay */
.ai-matrix-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(circle at 20% 80%, rgba(0, 212, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(91, 115, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(139, 92, 246, 0.1) 0%, transparent 50%);
    opacity: 0;
    animation: aiMatrixRain 8s linear infinite;
    pointer-events: none;
}

@keyframes aiMatrixRain {
    0% {
        opacity: 0;
        background-position: 0 -100vh, 0 100vh, 0 -50vh;
    }
    25% {
        opacity: 0.3;
    }
    75% {
        opacity: 0.3;
    }
    100% {
        opacity: 0;
        background-position: 0 100vh, 0 -100vh, 0 50vh;
    }
}

/* Processing bar with gradient sweep */
.ai-processing-bar-enhanced {
    position: absolute;
    bottom: 4px;
    left: 4px;
    right: 4px;
    height: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    overflow: hidden;
}

.ai-processing-bar-enhanced::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg,
        transparent,
        rgba(0, 212, 255, 0.8) 25%,
        rgba(255, 255, 255, 1) 50%,
        rgba(91, 115, 255, 0.8) 75%,
        transparent);
    animation: aiProcessingSweep 3s ease-in-out infinite;
}

@keyframes aiProcessingSweep {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* GPU acceleration hints for better performance */
.template-image,
.ai-working-overlay,
.ai-progress-bar,
.ai-scan-line {
    will-change: transform, opacity, filter;
    transform: translateZ(0); /* Enable GPU acceleration */
    backface-visibility: hidden;
}

/* Optimized animation for mobile devices */
@media (max-width: 768px) {
    /* Reduce animation complexity on mobile */
    .ai-anim-matrix, .ai-anim-glitch, .ai-anim-morph {
        animation-duration: 4s !important; /* Slower for performance */
    }

    /* Simplified effects for mobile */
    .template-image {
        filter: blur(2px) !important; /* Less blur for mobile performance */
    }
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    .template-images-container {
        background: rgba(0, 0, 0, 0.5);
        border-color: rgba(0, 212, 255, 0.3);
    }

    .ai-working-overlay::before {
        background: rgba(0, 212, 255, 0.9);
    }

    .ai-progress-bar {
        background: rgba(255, 255, 255, 0.1);
    }
}
