/**
 * Oracle Collective Interface - Animations
 * Particle effects, orb animations, transitions
 * Copyright © 2025 Tammy L Casey
 */

/* ============================================================================
   Particle System Animations
   ============================================================================ */

@keyframes particleFloat {
    0%, 100% {
        transform: translate(0, 0) scale(1);
        opacity: 0.4;
    }
    50% {
        transform: translate(var(--particle-x, 10px), var(--particle-y, -20px)) scale(1.2);
        opacity: 0.8;
    }
}

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

/* ============================================================================
   Oracle Orb Animations
   ============================================================================ */

/* Resting State - Gentle Pulse */
@keyframes orbPulseRest {
    0%, 100% {
        transform: scale(1);
        opacity: 0.6;
    }
    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }
}

/* Listening State - Active Pulse */
@keyframes orbPulseListening {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 20px var(--glow-silver);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 40px var(--glow-bright);
    }
}

/* Processing State - Rotation */
@keyframes orbRotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Speaking State - Intensity Pulse */
@keyframes orbPulseSpeaking {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 30px var(--glow-silver);
    }
    25% {
        transform: scale(1.15);
        box-shadow: 0 0 60px var(--glow-bright);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 40px var(--glow-silver);
    }
    75% {
        transform: scale(1.2);
        box-shadow: 0 0 70px var(--glow-bright);
    }
}

/* Orb Glow Ripple */
@keyframes glowRipple {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

.orb-ripple {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--text-silver);
    animation: glowRipple 2s ease-out infinite;
}

.orb-ripple:nth-child(2) {
    animation-delay: 0.5s;
}

.orb-ripple:nth-child(3) {
    animation-delay: 1s;
}

/* ============================================================================
   Voice Waveform Animations
   ============================================================================ */

@keyframes waveformPulse {
    0%, 100% {
        height: 20%;
    }
    50% {
        height: 80%;
    }
}

.waveform-bar {
    animation: waveformPulse 0.8s ease-in-out infinite;
}

.waveform-bar:nth-child(1) { animation-delay: 0s; }
.waveform-bar:nth-child(2) { animation-delay: 0.1s; }
.waveform-bar:nth-child(3) { animation-delay: 0.2s; }
.waveform-bar:nth-child(4) { animation-delay: 0.3s; }
.waveform-bar:nth-child(5) { animation-delay: 0.4s; }
.waveform-bar:nth-child(6) { animation-delay: 0.3s; }
.waveform-bar:nth-child(7) { animation-delay: 0.2s; }
.waveform-bar:nth-child(8) { animation-delay: 0.1s; }

/* ============================================================================
   Message Animations
   ============================================================================ */

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

.message {
    animation: messageSlideIn 0.3s ease-out;
}

/* Typing Indicator */
@keyframes typingDot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: var(--space-md);
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-silver);
    animation: typingDot 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* ============================================================================
   Perspective Card Animations
   ============================================================================ */

@keyframes cardExpand {
    from {
        max-height: 60px;
        opacity: 0.8;
    }
    to {
        max-height: 500px;
        opacity: 1;
    }
}

.perspective-body.expanding {
    animation: cardExpand 0.3s ease-out;
}

/* Consensus Animation */
@keyframes consensusGlow {
    0%, 100% {
        box-shadow: 0 0 10px var(--glow-silver);
    }
    50% {
        box-shadow: 0 0 20px var(--glow-bright);
    }
}

.consensus-reached {
    animation: consensusGlow 2s ease-in-out infinite;
}

/* ============================================================================
   Button Animations
   ============================================================================ */

@keyframes buttonPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

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

@keyframes shimmer {
    0% {
        background-position: -100% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

.btn-shimmer {
    background: linear-gradient(
        90deg,
        var(--bg-medium) 0%,
        var(--text-silver) 50%,
        var(--bg-medium) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 2s linear infinite;
}

/* ============================================================================
   Modal Animations
   ============================================================================ */

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

.modal {
    animation: modalFadeIn 0.3s ease-out;
}

.modal-content {
    animation: modalSlideIn 0.3s ease-out;
}

/* ============================================================================
   Loading States
   ============================================================================ */

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

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--bg-medium);
    border-top-color: var(--text-white);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.skeleton {
    background: var(--bg-medium);
    animation: skeletonPulse 1.5s ease-in-out infinite;
}

/* ============================================================================
   Notification Animations
   ============================================================================ */

@keyframes notificationSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes notificationSlideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.notification {
    animation: notificationSlideIn 0.3s ease-out;
}

.notification.closing {
    animation: notificationSlideOut 0.3s ease-in;
}

/* ============================================================================
   Collective Selector Animations
   ============================================================================ */

@keyframes collectiveActivate {
    0% {
        transform: translateX(0);
    }
    50% {
        transform: translateX(8px);
    }
    100% {
        transform: translateX(4px);
    }
}

.collective-btn.activating {
    animation: collectiveActivate 0.3s ease-out;
}

/* Status Indicator Pulse */
@keyframes statusPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.7;
    }
}

.collective-status.active {
    animation: statusPulse 2s ease-in-out infinite;
}

/* ============================================================================
   Timeline Visualization Animations
   ============================================================================ */

@keyframes timelineSweep {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

.timeline-bar {
    animation: timelineSweep 0.5s ease-out;
}

/* ============================================================================
   Accessibility - Reduced Motion
   ============================================================================ */

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

    .orb-ripple,
    .particle,
    .voice-waveform {
        animation: none !important;
    }
}

/* ============================================================================
   Performance Optimizations
   ============================================================================ */

/* GPU Acceleration for smooth animations */
.voice-orb,
.particles-background,
.message,
.modal-content,
.orb-ripple {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Reduce animations on low-end devices */
@media (max-width: 768px) and (prefers-reduced-motion: no-preference) {
    .particles-background {
        opacity: 0.5;
    }

    @keyframes particleFloat {
        0%, 100% {
            transform: translate(0, 0);
        }
        50% {
            transform: translate(5px, -10px);
        }
    }
}
