/* ==========================================
   Logic Studies - Animations
   Didactic and smooth animations
   ========================================== */

/* ==========================================
   Base Keyframes
   ========================================== */

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

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

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

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

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

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

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

/* ==========================================
   Confirmation Animation (Green glow)
   ========================================== */

@keyframes confirmGlow {
    0% {
        box-shadow: inset 0 0 0 2px transparent;
        background-color: var(--bg-secondary);
    }
    50% {
        box-shadow: inset 0 0 0 2px var(--color-confirmed), 0 0 20px var(--color-confirmed);
    }
    100% {
        box-shadow: inset 0 0 0 2px var(--color-confirmed);
        background-color: var(--color-confirmed-bg);
    }
}

.cell-confirm {
    animation: confirmGlow 0.6s ease forwards;
}

.cell-confirm::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 1.5em;
    color: var(--color-confirmed);
    animation: checkmarkPop 0.4s ease 0.2s forwards;
}

@keyframes checkmarkPop {
    0% {
        transform: translate(-50%, -50%) scale(0);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2);
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
    }
}

/* ==========================================
   Elimination Animation (Strikethrough)
   ========================================== */

@keyframes eliminateStrike {
    0% {
        background-size: 0% 2px;
    }
    100% {
        background-size: 100% 2px;
    }
}

@keyframes eliminateFade {
    0% {
        opacity: 1;
        background-color: var(--bg-secondary);
    }
    50% {
        background-color: var(--color-eliminated-bg);
    }
    100% {
        opacity: 0.6;
        background-color: var(--color-eliminated-bg);
    }
}

.cell-eliminate {
    animation: eliminateFade 0.5s ease forwards;
    position: relative;
}

.cell-eliminate::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 10%;
    width: 80%;
    height: 2px;
    background: var(--color-eliminated);
    transform: translateY(-50%);
    animation: eliminateStrike 0.3s ease 0.2s forwards;
    background-size: 0% 2px;
    background-repeat: no-repeat;
    background-position: left center;
}

/* ==========================================
   Highlight Animation (Blue pulse)
   ========================================== */

@keyframes highlightPulse {
    0% {
        box-shadow: inset 0 0 0 2px transparent;
    }
    25% {
        box-shadow: inset 0 0 0 3px var(--color-highlight), 0 0 15px var(--color-highlight);
    }
    75% {
        box-shadow: inset 0 0 0 3px var(--color-highlight), 0 0 10px var(--color-highlight);
    }
    100% {
        box-shadow: inset 0 0 0 2px var(--color-highlight);
    }
}

.cell-highlight {
    animation: highlightPulse 0.8s ease;
    background-color: var(--color-highlight-bg) !important;
}

/* ==========================================
   Sequence Box Animations
   ========================================== */

@keyframes boxReveal {
    0% {
        transform: rotateY(90deg);
        opacity: 0;
    }
    100% {
        transform: rotateY(0);
        opacity: 1;
    }
}

.sequence-box-reveal {
    animation: boxReveal 0.5s ease forwards;
    transform-style: preserve-3d;
}

@keyframes boxHighlight {
    0% {
        transform: scale(1);
        box-shadow: none;
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 25px var(--color-highlight);
    }
    100% {
        transform: scale(1.05);
        box-shadow: 0 0 15px var(--color-highlight);
    }
}

.sequence-box-highlight {
    animation: boxHighlight 0.6s ease forwards;
}

/* ==========================================
   Order/Position Animations
   ========================================== */

@keyframes slotFill {
    0% {
        transform: translateY(-20px);
        opacity: 0;
    }
    60% {
        transform: translateY(5px);
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.slot-fill {
    animation: slotFill 0.5s ease forwards;
}

@keyframes slotEmpty {
    0% {
        transform: translateY(0);
        opacity: 1;
    }
    100% {
        transform: translateY(20px);
        opacity: 0;
    }
}

.slot-empty {
    animation: slotEmpty 0.3s ease forwards;
}

/* ==========================================
   Explanation Animations
   ========================================== */

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

.explanation-animate {
    animation: fadeIn 0.4s ease forwards;
}

.tip-animate {
    animation: slideInLeft 0.4s ease 0.2s forwards;
    opacity: 0;
}

.tip-animate.visible {
    opacity: 1;
}

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

.btn-click {
    animation: pulse 0.3s ease;
}

/* ==========================================
   Summary Animations
   ========================================== */

@keyframes celebrateIn {
    0% {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    50% {
        transform: scale(1.02) translateY(-5px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.summary-animate {
    animation: celebrateIn 0.6s ease forwards;
}

/* ==========================================
   Card Hover Enhancements
   ========================================== */

.problem-card {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.problem-card:hover {
    animation: none; /* Remove animation on hover to avoid conflicts */
}

/* ==========================================
   Step Transition
   ========================================== */

@keyframes stepTransition {
    0% {
        opacity: 0.5;
        transform: scale(0.98);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.step-transition {
    animation: stepTransition 0.3s ease;
}

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

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

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

/* ==========================================
   Stagger Animation for Lists
   ========================================== */

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

/* ==========================================
   Solution Fast-Forward Flash
   Applied to the visualization area when "Ver Solução" is clicked.
   Signals a jump to the final state before the staggered reveal plays.
   ========================================== */

@keyframes solutionFlash {
    0%   { opacity: 1; filter: none; }
    30%  { opacity: 0.15; filter: blur(4px) brightness(1.8); }
    60%  { opacity: 0.15; filter: blur(4px) brightness(1.8); }
    100% { opacity: 1; filter: none; }
}

.solution-flash {
    animation: solutionFlash 0.45s ease forwards;
}

/* ==========================================
   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;
    }
}
