/* =====================================================
   CodeTigrinya - Animations
   Glitch Effects, Reveals, and Micro-interactions
   ===================================================== */

/* ===== GLITCH TEXT EFFECT ===== */
.glitch {
    position: relative;
    animation: glitchText 3s infinite;
}

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

.glitch::before {
    animation: glitchBefore 3s infinite;
    color: #ff00ff;
    z-index: -1;
}

.glitch::after {
    animation: glitchAfter 3s infinite;
    color: #00ffff;
    z-index: -2;
}

@keyframes glitchText {
    0%, 90%, 100% { opacity: 1; }
    91% { opacity: 0.8; }
    92% { opacity: 1; }
    93% { opacity: 0.9; }
}

@keyframes glitchBefore {
    0%, 90%, 94%, 100% { opacity: 0; clip-path: inset(0); transform: translate(0); }
    91% { opacity: 0.8; clip-path: inset(20% 0 60% 0); transform: translate(-3px, -1px); }
    92% { opacity: 0.8; clip-path: inset(40% 0 40% 0); transform: translate(3px, 1px); }
    93% { opacity: 0.8; clip-path: inset(60% 0 20% 0); transform: translate(-2px, 2px); }
}

@keyframes glitchAfter {
    0%, 90%, 94%, 100% { opacity: 0; clip-path: inset(0); transform: translate(0); }
    91% { opacity: 0.8; clip-path: inset(60% 0 20% 0); transform: translate(3px, 1px); }
    92% { opacity: 0.8; clip-path: inset(20% 0 60% 0); transform: translate(-3px, -1px); }
    93% { opacity: 0.8; clip-path: inset(40% 0 40% 0); transform: translate(2px, -2px); }
}

/* ===== SCROLL REVEAL ===== */
.reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

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

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

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

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

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

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

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

/* Stagger children */
.stagger-children .reveal:nth-child(1) { transition-delay: 0.1s; }
.stagger-children .reveal:nth-child(2) { transition-delay: 0.2s; }
.stagger-children .reveal:nth-child(3) { transition-delay: 0.3s; }
.stagger-children .reveal:nth-child(4) { transition-delay: 0.4s; }
.stagger-children .reveal:nth-child(5) { transition-delay: 0.5s; }
.stagger-children .reveal:nth-child(6) { transition-delay: 0.6s; }

/* ===== TYPING ANIMATION ===== */
.typing {
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid var(--accent);
    animation: typing 3s steps(30, end), blink 0.75s step-end infinite;
}

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

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

/* ===== FLOATING ANIMATION ===== */
.float {
    animation: float 4s ease-in-out infinite;
}

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

/* ===== PULSE GLOW ===== */
.pulse-glow {
    animation: pulseGlow 2s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 20px var(--accent-glow); }
    50% { box-shadow: 0 0 40px var(--accent-glow), 0 0 60px var(--accent-glow); }
}

/* ===== FADE IN ===== */
.fade-in {
    animation: fadeIn 0.5s ease forwards;
}

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

/* ===== SLIDE UP ===== */
.slide-up {
    animation: slideUp 0.5s ease forwards;
}

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

/* ===== SHAKE ===== */
.shake {
    animation: shake 0.5s ease-in-out;
}

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

/* ===== BOUNCE ===== */
.bounce {
    animation: bounce 0.6s ease;
}

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

/* ===== SPIN ===== */
.spin {
    animation: spin 1s linear infinite;
}

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

/* ===== GRADIENT FLOW ===== */
.gradient-flow {
    background: linear-gradient(90deg, var(--accent), #00ffff, var(--accent));
    background-size: 200% 100%;
    animation: gradientFlow 3s linear infinite;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

/* ===== PARTICLE DOTS ===== */
.particles {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--accent);
    border-radius: 50%;
    opacity: 0.5;
    animation: particleFloat 8s infinite;
}

.particle:nth-child(1) { left: 10%; animation-delay: 0s; }
.particle:nth-child(2) { left: 20%; animation-delay: 1s; }
.particle:nth-child(3) { left: 30%; animation-delay: 2s; }
.particle:nth-child(4) { left: 40%; animation-delay: 3s; }
.particle:nth-child(5) { left: 50%; animation-delay: 4s; }
.particle:nth-child(6) { left: 60%; animation-delay: 5s; }
.particle:nth-child(7) { left: 70%; animation-delay: 6s; }
.particle:nth-child(8) { left: 80%; animation-delay: 7s; }

@keyframes particleFloat {
    0% {
        transform: translateY(100vh) scale(0);
        opacity: 0;
    }
    10% {
        opacity: 0.5;
    }
    90% {
        opacity: 0.5;
    }
    100% {
        transform: translateY(-100px) scale(1);
        opacity: 0;
    }
}

/* ===== SUCCESS CHECKMARK ===== */
.checkmark {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: checkPop 0.4s ease;
}

.checkmark::after {
    content: '✓';
    color: var(--bg-primary);
    font-size: 1.2rem;
    font-weight: bold;
}

@keyframes checkPop {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* ===== LOADING DOTS ===== */
.loading-dots {
    display: flex;
    gap: 4px;
}

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

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

@keyframes loadingDot {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ===== CODE TYPING ANIMATION ===== */
.code-typing .code-line {
    opacity: 0;
    animation: codeLine 0.3s ease forwards;
}

.code-typing .code-line:nth-child(1) { animation-delay: 0.2s; }
.code-typing .code-line:nth-child(2) { animation-delay: 0.6s; }
.code-typing .code-line:nth-child(3) { animation-delay: 1.0s; }
.code-typing .code-line:nth-child(4) { animation-delay: 1.4s; }
.code-typing .code-line:nth-child(5) { animation-delay: 1.8s; }
.code-typing .code-line:nth-child(6) { animation-delay: 2.2s; }

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

/* ===== CURSOR BLINK ===== */
.cursor-blink::after {
    content: '|';
    color: var(--accent);
    animation: cursorBlink 1s step-end infinite;
}

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

/* ===== COUNTER ANIMATION ===== */
.counter {
    display: inline-block;
}

.counter.counting {
    animation: counterPulse 0.3s ease;
}

@keyframes counterPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); color: var(--accent); }
    100% { transform: scale(1); }
}

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