/* ========================================
   數獨遊戲 - 動畫效果
   ======================================== */

/* Cell Animations */
@keyframes correctPulse {
    0% {
        transform: scale(1);
        background-color: rgba(39, 174, 96, 0.2);
    }

    50% {
        transform: scale(1.1);
        background-color: rgba(39, 174, 96, 0.4);
    }

    100% {
        transform: scale(1);
        background-color: transparent;
    }
}

@keyframes errorShake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-4px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(4px);
    }
}

@keyframes cellAppear {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes numberPop {
    0% {
        transform: scale(0);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

/* Victory Animations */
@keyframes victoryBounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-20px);
    }

    60% {
        transform: translateY(-10px);
    }
}

@keyframes confetti {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

@keyframes starBurst {
    0% {
        transform: scale(0) rotate(0deg);
        opacity: 1;
    }

    50% {
        transform: scale(1.5) rotate(180deg);
        opacity: 0.8;
    }

    100% {
        transform: scale(0) rotate(360deg);
        opacity: 0;
    }
}

/* Button Animations */
@keyframes buttonGlow {

    0%,
    100% {
        box-shadow: 0 0 5px rgba(74, 144, 164, 0.3);
    }

    50% {
        box-shadow: 0 0 20px rgba(74, 144, 164, 0.6);
    }
}

@keyframes unlockPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(39, 174, 96, 0.5);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(39, 174, 96, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(39, 174, 96, 0);
    }
}

/* Theme-specific Animations */
@keyframes floatBubble {

    0%,
    100% {
        transform: translateY(0) scale(1);
    }

    50% {
        transform: translateY(-10px) scale(1.05);
    }
}

@keyframes glowPulse {

    0%,
    100% {
        filter: brightness(1);
    }

    50% {
        filter: brightness(1.2);
    }
}

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

    100% {
        background-position: 200% 0;
    }
}

@keyframes twinkle {

    0%,
    100% {
        opacity: 0.3;
    }

    50% {
        opacity: 1;
    }
}

@keyframes fireFlicker {

    0%,
    100% {
        opacity: 1;
        transform: scaleY(1);
    }

    50% {
        opacity: 0.8;
        transform: scaleY(0.95);
    }
}

@keyframes cherryFall {
    0% {
        transform: translateY(-20px) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(100vh) rotate(360deg);
        opacity: 0;
    }
}

/* Loading Animation */
@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

@keyframes fadeOut {
    0% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

@keyframes slideUp {
    0% {
        transform: translateY(20px);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideDown {
    0% {
        transform: translateY(-20px);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Apply Animations */
.sudoku-cell.error {
    animation: errorShake 0.5s ease;
}

.sudoku-cell.new-number {
    animation: numberPop 0.3s ease;
}

.modal-content.victory h2 {
    animation: victoryBounce 1s ease infinite;
}

.theme-card.just-unlocked {
    animation: unlockPulse 1s ease infinite;
}

/* Pencil Writing Effect */
.sudoku-cell.writing::after {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 50%;
    width: 0;
    height: 2px;
    background-color: var(--text-primary);
    animation: writingLine 0.3s ease forwards;
}

@keyframes writingLine {
    0% {
        width: 0;
        left: 50%;
    }

    100% {
        width: 60%;
        left: 20%;
    }
}

/* Erase Effect */
.sudoku-cell.erasing {
    animation: eraseEffect 0.3s ease;
}

@keyframes eraseEffect {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }

    100% {
        opacity: 1;
    }
}

/* Hint Animation */
.sudoku-cell.hint-reveal {
    animation: hintReveal 0.5s ease;
}

@keyframes hintReveal {
    0% {
        background-color: rgba(255, 215, 0, 0.5);
        transform: scale(1.1);
    }

    100% {
        background-color: transparent;
        transform: scale(1);
    }
}

/* Board Complete Animation */
#sudoku-board.complete .sudoku-cell {
    animation: cellComplete 0.5s ease forwards;
    animation-delay: calc(var(--cell-index) * 0.02s);
}

@keyframes cellComplete {
    0% {
        background-color: transparent;
    }

    50% {
        background-color: rgba(39, 174, 96, 0.3);
    }

    100% {
        background-color: rgba(39, 174, 96, 0.1);
    }
}