/**
 * Animations
 * Keyframes and animation effects
 */

/* ===== Token Animations ===== */
@keyframes token-appear {
    0% {
        opacity: 0;
        transform: translateY(10px) scale(0.9);
    }
    50% {
        opacity: 1;
        transform: translateY(-2px) scale(1.05);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.token-entering {
    animation: token-appear 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.token-entered {
    animation: none;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(245, 166, 35, 0.7);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(245, 166, 35, 0);
        transform: scale(1.05);
    }
}

@keyframes fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slide-in-right {
    from {
        transform: translateX(-20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slide-in-up {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ===== Thinking Animations ===== */
@keyframes thinking-pulse {
    0%, 100% {
        opacity: 0.6;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.02);
    }
}

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

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

@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 10px currentColor;
    }
    50% {
        box-shadow: 0 0 20px currentColor, 0 0 30px currentColor;
    }
}

/* ===== Progress Bar Animations ===== */
@keyframes progress-shimmer {
    0% {
        background-position: -100% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

.progress-bar,
.progress-fill {
    background-size: 200% 100%;
    animation: progress-shimmer 2s linear infinite;
}

/* ===== Attention Grid Animations ===== */
@keyframes attention-fade-in {
    from {
        opacity: 0;
        transform: translateX(10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.attention-cell {
    animation: attention-fade-in 200ms ease-out;
}

.attention-cell.focused {
    animation: attention-fade-in 200ms ease-out, pulse 1.5s ease-in-out infinite;
}

/* ===== Probability Bar Animations ===== */
@keyframes bar-grow {
    from {
        width: 0;
    }
}

.bar-fill {
    animation: bar-grow 500ms ease-out;
}

@keyframes bar-highlight {
    0%, 100% {
        box-shadow: none;
    }
    50% {
        box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.3);
    }
}

.probability-bar-container.selected .bar-fill {
    animation: bar-grow 500ms ease-out, bar-highlight 1.5s ease-in-out infinite;
}

/* ===== Control Button Animations ===== */
@keyframes button-press {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.95);
    }
}

.control-btn:active:not(:disabled) {
    animation: button-press 150ms ease-out;
}

/* ===== Detail Panel Animations ===== */
@keyframes slide-in-from-right {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

.detail-panel.panel-visible {
    animation: slide-in-from-right 300ms ease-out;
}

/* ===== Loading Animations ===== */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-spinner {
    animation: spin 1s linear infinite;
}

@keyframes loading-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.loading-overlay {
    animation: fade-in 200ms ease-out;
}

/* ===== Hover Effects ===== */
@keyframes hover-lift {
    from {
        transform: translateY(0);
    }
    to {
        transform: translateY(-2px);
    }
}

.token:hover,
.control-btn:hover:not(:disabled),
.btn-primary:hover {
    animation: hover-lift 150ms ease-out forwards;
}

/* ===== Focus Animations ===== */
@keyframes focus-ring {
    0%, 100% {
        box-shadow: 0 0 0 0 var(--color-primary);
    }
    50% {
        box-shadow: 0 0 0 4px var(--color-primary);
    }
}

:focus-visible {
    animation: focus-ring 500ms ease-out;
}

/* ===== Stagger Animations ===== */
.token:nth-child(1) { animation-delay: 0ms; }
.token:nth-child(2) { animation-delay: 30ms; }
.token:nth-child(3) { animation-delay: 60ms; }
.token:nth-child(4) { animation-delay: 90ms; }
.token:nth-child(5) { animation-delay: 120ms; }
.token:nth-child(6) { animation-delay: 150ms; }
.token:nth-child(7) { animation-delay: 180ms; }
.token:nth-child(8) { animation-delay: 210ms; }
.token:nth-child(9) { animation-delay: 240ms; }
.token:nth-child(10) { animation-delay: 270ms; }

/* ===== Entrance Animations ===== */
@keyframes fade-in-scale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.app-container {
    animation: fade-in-scale 400ms ease-out;
}

section {
    animation: slide-in-up 400ms ease-out;
    animation-fill-mode: backwards;
}

section:nth-child(1) { animation-delay: 0ms; }
section:nth-child(2) { animation-delay: 100ms; }
section:nth-child(3) { animation-delay: 200ms; }
section:nth-child(4) { animation-delay: 300ms; }

/* ===== Transition Classes ===== */
.transition-fast {
    transition: all var(--transition-fast);
}

.transition-normal {
    transition: all var(--transition-normal);
}

.transition-slow {
    transition: all var(--transition-slow);
}

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

/* ===== Custom Bounce Effect ===== */
@keyframes bounce-in {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ===== Shimmer Effect ===== */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

.shimmer {
    background: linear-gradient(
        90deg,
        var(--color-bg-lighter) 0%,
        var(--color-bg) 50%,
        var(--color-bg-lighter) 100%
    );
    background-size: 1000px 100%;
    animation: shimmer 2s infinite;
}

/* ===== Wiggle Effect ===== */
@keyframes wiggle {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(-3deg);
    }
    75% {
        transform: rotate(3deg);
    }
}

.error-state {
    animation: wiggle 500ms ease-in-out;
}

/* ===== Fade Out ===== */
@keyframes fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.fade-out {
    animation: fade-out 300ms ease-out forwards;
}

/* ===== Scale In ===== */
@keyframes scale-in {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.scale-in {
    animation: scale-in 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ===== Slide Out ===== */
@keyframes slide-out-right {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.slide-out-right {
    animation: slide-out-right 300ms ease-out forwards;
}

/* ===== Heartbeat Effect ===== */
@keyframes heartbeat {
    0%, 100% {
        transform: scale(1);
    }
    10%, 30% {
        transform: scale(1.1);
    }
    20%, 40% {
        transform: scale(1);
    }
}

.heartbeat {
    animation: heartbeat 1.5s ease-in-out infinite;
}
