/**
 * Ultimate Showcase - Animations
 * Keyframes, transitions, and special effects
 */

/* ========================================
   KEYFRAMES - GENERAL ANIMATIONS
   ======================================== */

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

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

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

@keyframes fadeInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

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

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

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

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

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-5px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(5px);
    }
}

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

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

@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 5px var(--color-primary), 0 0 10px var(--color-primary), 0 0 15px var(--color-primary);
    }
    50% {
        box-shadow: 0 0 10px var(--color-primary), 0 0 20px var(--color-primary), 0 0 30px var(--color-primary);
    }
}

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

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

@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

/* ========================================
   GLITCH EFFECT
   ======================================== */

@keyframes glitch-1 {
    0% {
        clip-path: inset(20% 0 60% 0);
        transform: translate(-2px, 2px);
    }
    20% {
        clip-path: inset(60% 0 20% 0);
        transform: translate(2px, -2px);
    }
    40% {
        clip-path: inset(40% 0 40% 0);
        transform: translate(-2px, 2px);
    }
    60% {
        clip-path: inset(80% 0 5% 0);
        transform: translate(2px, -2px);
    }
    80% {
        clip-path: inset(10% 0 70% 0);
        transform: translate(-2px, 2px);
    }
    100% {
        clip-path: inset(30% 0 50% 0);
        transform: translate(2px, -2px);
    }
}

@keyframes glitch-2 {
    0% {
        clip-path: inset(60% 0 20% 0);
        transform: translate(2px, -2px);
    }
    20% {
        clip-path: inset(20% 0 60% 0);
        transform: translate(-2px, 2px);
    }
    40% {
        clip-path: inset(80% 0 5% 0);
        transform: translate(2px, -2px);
    }
    60% {
        clip-path: inset(10% 0 70% 0);
        transform: translate(-2px, 2px);
    }
    80% {
        clip-path: inset(40% 0 40% 0);
        transform: translate(2px, -2px);
    }
    100% {
        clip-path: inset(50% 0 30% 0);
        transform: translate(-2px, 2px);
    }
}

.glitch-text {
    position: relative;
}

.glitch-text::before,
.glitch-text::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.glitch-text::before {
    color: #ff0000;
    animation: glitch-1 2s infinite linear alternate-reverse;
}

.glitch-text::after {
    color: #00ffff;
    animation: glitch-2 2s infinite linear alternate-reverse;
}

/* ========================================
   TYPEWRITER EFFECT
   ======================================== */

.typewriter-text {
    overflow: hidden;
    border-right: 2px solid var(--color-accent);
    white-space: nowrap;
    animation: typing 3.5s 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(--color-accent);
    }
}

/* ========================================
   SCROLL ANIMATIONS
   ======================================== */

.reveal {
    opacity: 0;
    transform: translateY(50px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.reveal.active {
    opacity: 1;
    transform: translateY(0);
}

.reveal-left {
    opacity: 0;
    transform: translateX(-50px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.reveal-left.active {
    opacity: 1;
    transform: translateX(0);
}

.reveal-right {
    opacity: 0;
    transform: translateX(50px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.reveal-right.active {
    opacity: 1;
    transform: translateX(0);
}

.reveal-scale {
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.reveal-scale.active {
    opacity: 1;
    transform: scale(1);
}

/* Stagger children animations */
.stagger-children > * {
    opacity: 0;
    transform: translateY(20px);
}

.stagger-children.active > * {
    animation: fadeInUp 0.6s ease forwards;
}

.stagger-children.active > *:nth-child(1) { animation-delay: 0.1s; }
.stagger-children.active > *:nth-child(2) { animation-delay: 0.2s; }
.stagger-children.active > *:nth-child(3) { animation-delay: 0.3s; }
.stagger-children.active > *:nth-child(4) { animation-delay: 0.4s; }
.stagger-children.active > *:nth-child(5) { animation-delay: 0.5s; }
.stagger-children.active > *:nth-child(6) { animation-delay: 0.6s; }

/* ========================================
   HOVER ANIMATIONS
   ======================================== */

.hover-lift {
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.hover-lift:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-xl);
}

.hover-scale {
    transition: transform var(--transition-base);
}

.hover-scale:hover {
    transform: scale(1.05);
}

.hover-rotate {
    transition: transform var(--transition-base);
}

.hover-rotate:hover {
    transform: rotate(5deg);
}

.hover-glow {
    transition: box-shadow var(--transition-base);
}

.hover-glow:hover {
    animation: glow 2s ease-in-out infinite;
}

/* Underline animation */
.hover-underline {
    position: relative;
}

.hover-underline::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--gradient-primary);
    transition: width var(--transition-base);
}

.hover-underline:hover::after {
    width: 100%;
}

/* ========================================
   LOADING ANIMATIONS
   ======================================== */

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-primary);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-dots {
    display: flex;
    gap: 8px;
}

.loading-dots span {
    width: 10px;
    height: 10px;
    background: var(--color-primary);
    border-radius: 50%;
    animation: pulse 1.4s ease-in-out infinite both;
}

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

.loading-pulse {
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, transparent, var(--color-primary), transparent);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

/* ========================================
   PARTICLE EFFECTS
   ======================================== */

.particle {
    position: absolute;
    pointer-events: none;
    border-radius: 50%;
    animation: particle-float 3s ease-out forwards;
}

@keyframes particle-float {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx, 100px), var(--ty, -100px)) scale(0);
    }
}

/* ========================================
   BUTTON RIPPLE EFFECT
   ======================================== */

.ripple {
    position: relative;
    overflow: hidden;
}

.ripple::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
}

.ripple:active::after {
    animation: ripple 0.6s ease-out;
}

/* ========================================
   SORTING ANIMATIONS
   ======================================== */

.sorting-bar {
    transition: height 0.1s ease, background-color 0.1s ease;
}

.sorting-bar.comparing {
    animation: compare-pulse 0.3s ease;
}

@keyframes compare-pulse {
    0%, 100% {
        transform: scaleY(1);
    }
    50% {
        transform: scaleY(1.1);
    }
}

.sorting-bar.swapping {
    animation: swap-flash 0.3s ease;
}

@keyframes swap-flash {
    0%, 100% {
        filter: brightness(1);
    }
    50% {
        filter: brightness(1.5);
    }
}

.sorting-bar.sorted {
    animation: sorted-pop 0.3s ease;
}

@keyframes sorted-pop {
    0% {
        transform: scaleY(1);
    }
    50% {
        transform: scaleY(1.2);
    }
    100% {
        transform: scaleY(1);
    }
}

/* ========================================
   AUDIO VISUALIZER ANIMATIONS
   ======================================== */

.audio-bar {
    transition: height 50ms ease;
}

.audio-bar.active {
    filter: brightness(1.3);
}

/* ========================================
   CARD HOVER EFFECTS
   ======================================== */

.card-shine {
    position: relative;
    overflow: hidden;
}

.card-shine::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        to right,
        transparent 0%,
        rgba(255, 255, 255, 0.1) 50%,
        transparent 100%
    );
    transform: rotate(30deg) translateX(-100%);
    transition: transform 0.6s;
}

.card-shine:hover::before {
    transform: rotate(30deg) translateX(100%);
}

/* ========================================
   SCROLL INDICATOR
   ======================================== */

.scroll-indicator {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-secondary);
    animation: bounce 2s infinite;
}

.scroll-indicator i {
    font-size: 24px;
}

/* ========================================
   NOTIFICATION TOAST
   ======================================== */

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: var(--space-4) var(--space-6);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(var(--glass-blur));
    box-shadow: var(--shadow-lg);
    transform: translateX(150%);
    transition: transform var(--transition-base);
    z-index: var(--z-toast);
}

.toast.show {
    transform: translateX(0);
    animation: slideInRight 0.3s ease;
}

.toast.hide {
    animation: slideOutRight 0.3s ease forwards;
}

@keyframes slideInRight {
    from {
        transform: translateX(150%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(150%);
    }
}

/* ========================================
   MODAL ANIMATIONS
   ======================================== */

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
    z-index: var(--z-modal-backdrop);
}

.modal-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: var(--bg-elevated);
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
    z-index: var(--z-modal);
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal.active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

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

.text-gradient-animate {
    background-size: 200% auto;
    animation: text-gradient 3s linear infinite;
}

@keyframes text-gradient {
    0% {
        background-position: 0% center;
    }
    100% {
        background-position: 200% center;
    }
}

.letter-wave span {
    display: inline-block;
    animation: letter-bounce 1s ease infinite;
}

.letter-wave span:nth-child(1) { animation-delay: 0s; }
.letter-wave span:nth-child(2) { animation-delay: 0.1s; }
.letter-wave span:nth-child(3) { animation-delay: 0.2s; }
.letter-wave span:nth-child(4) { animation-delay: 0.3s; }
.letter-wave span:nth-child(5) { animation-delay: 0.4s; }
.letter-wave span:nth-child(6) { animation-delay: 0.5s; }
.letter-wave span:nth-child(7) { animation-delay: 0.6s; }
.letter-wave span:nth-child(8) { animation-delay: 0.7s; }
.letter-wave span:nth-child(9) { animation-delay: 0.8s; }
.letter-wave span:nth-child(10) { animation-delay: 0.9s; }

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

/* ========================================
   GAME-SPECIFIC ANIMATIONS
   ======================================== */

.snake-eat {
    animation: eat-pop 0.2s ease;
}

@keyframes eat-pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.3);
    }
    100% {
        transform: scale(1);
    }
}

.game-over-shake {
    animation: shake 0.5s ease;
}

.score-update {
    animation: score-bump 0.3s ease;
}

@keyframes score-bump {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
        color: var(--color-success);
    }
}

/* ========================================
   PERFORMANCE MODE ADJUSTMENTS
   ======================================== */

[data-performance="low"] *,
[data-performance="low"] *::before,
[data-performance="low"] *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
}

[data-performance="low"] .webgl-canvas {
    display: none;
}

[data-performance="medium"] .glass-card {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}
