/* Animation Styles */

/* === Core Animations === */
@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 slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

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

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

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

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

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

/* === Timer Specific Animations === */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }
}

@keyframes heartbeat {
    0%, 50%, 100% {
        transform: scale(1);
    }
    25% {
        transform: scale(1.1);
    }
    75% {
        transform: scale(0.95);
    }
}

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

@keyframes bounce {
    0%, 20%, 53%, 80%, 100% {
        animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
        transform: translate3d(0, 0, 0);
    }
    40%, 43% {
        animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
        transform: translate3d(0, -8px, 0);
    }
    70% {
        animation-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
        transform: translate3d(0, -4px, 0);
    }
    90% {
        transform: translate3d(0, -1px, 0);
    }
}

@keyframes flip {
    from {
        transform: perspective(400px) rotateX(0deg);
        opacity: 1;
    }
    to {
        transform: perspective(400px) rotateX(180deg);
        opacity: 0;
    }
}

@keyframes flipBack {
    from {
        transform: perspective(400px) rotateX(-180deg);
        opacity: 0;
    }
    to {
        transform: perspective(400px) rotateX(0deg);
        opacity: 1;
    }
}

/* === Progress Ring Animations === */
@keyframes progressFill {
    from {
        stroke-dashoffset: var(--progress-ring-circumference);
    }
    to {
        stroke-dashoffset: 0;
    }
}

@keyframes progressGlow {
    0%, 100% {
        filter: drop-shadow(0 0 8px rgba(102, 126, 234, 0.3));
    }
    50% {
        filter: drop-shadow(0 0 16px rgba(102, 126, 234, 0.6));
    }
}

@keyframes finalCountdown {
    0%, 100% {
        transform: scale(1);
        filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.5));
    }
    50% {
        transform: scale(1.02);
        filter: drop-shadow(0 0 20px rgba(239, 68, 68, 0.8));
    }
}

/* === Confetti Animation === */
@keyframes confetti-fall {
    0% {
        transform: translateY(-100vh) rotateZ(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotateZ(360deg);
        opacity: 0;
    }
}

@keyframes confetti-sway {
    0%, 100% {
        transform: translateX(0);
    }
    50% {
        transform: translateX(20px);
    }
}

/* === Ripple Animation === */
@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 0.6;
    }
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

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

@keyframes dots {
    0%, 20% {
        color: rgba(0, 0, 0, 0);
        text-shadow: 0.25em 0 0 rgba(0, 0, 0, 0),
                     0.5em 0 0 rgba(0, 0, 0, 0);
    }
    40% {
        color: currentColor;
        text-shadow: 0.25em 0 0 rgba(0, 0, 0, 0),
                     0.5em 0 0 rgba(0, 0, 0, 0);
    }
    60% {
        text-shadow: 0.25em 0 0 currentColor,
                     0.5em 0 0 rgba(0, 0, 0, 0);
    }
    80%, 100% {
        text-shadow: 0.25em 0 0 currentColor,
                     0.5em 0 0 currentColor;
    }
}

/* === Theme Transition Animations === */
@keyframes themeTransition {
    0% {
        transform: scale(1) rotate(0deg);
    }
    50% {
        transform: scale(1.1) rotate(180deg);
    }
    100% {
        transform: scale(1) rotate(360deg);
    }
}

/* === Component State Animations === */
.timer-time.digit-flip {
    animation: flip var(--duration-standard) var(--easing-default);
}

.timer-time.counting-down {
    animation: pulse 1s ease-in-out infinite;
}

.timer-time.final-countdown {
    animation: finalCountdown 1s ease-in-out infinite;
}

.timer-time.completed {
    animation: bounce var(--duration-emphasized) var(--easing-bounce);
}

.progress-ring.pulsing .progress-ring__progress {
    animation: progressGlow 2s ease-in-out infinite;
}

.progress-ring.final-countdown .progress-ring__progress {
    animation: finalCountdown 1s ease-in-out infinite;
}

/* === Button Animation States === */
.btn.pressed {
    animation: heartbeat 0.3s ease-in-out;
}

.btn--loading .btn__text::after {
    content: '...';
    animation: dots 1.5s infinite;
}

/* === Modal Animation States === */
.modal.opening .modal__content {
    animation: scaleIn var(--duration-emphasized) var(--easing-bounce);
}

.modal.closing .modal__content {
    animation: scaleOut var(--duration-standard) var(--easing-default);
}

/* === Settings Panel Animation States === */
.settings.opening {
    animation: slideInRight var(--duration-emphasized) var(--easing-smooth);
}

.settings.closing {
    animation: slideInLeft var(--duration-standard) var(--easing-default) reverse;
}

/* === Notification Animations === */
.notification.entering {
    animation: slideInRight var(--duration-emphasized) var(--easing-smooth);
}

.notification.leaving {
    animation: slideInRight var(--duration-standard) var(--easing-default) reverse;
}

/* === Theme Toggle Animation === */
.theme-toggle.transitioning {
    animation: themeTransition var(--duration-emphasized) var(--easing-bounce);
}

/* === Preset Button Animations === */
.btn--preset.selected {
    animation: bounce var(--duration-standard) var(--easing-bounce);
}

/* === Page Load Animations === */
.header {
    animation: slideInDown var(--duration-emphasized) var(--easing-smooth);
}

.timer-display {
    animation: scaleIn var(--duration-emphasized) var(--easing-bounce);
    animation-delay: 0.1s;
    animation-fill-mode: both;
}

.presets {
    animation: fadeIn var(--duration-emphasized) var(--easing-default);
    animation-delay: 0.2s;
    animation-fill-mode: both;
}

.controls {
    animation: slideInUp var(--duration-emphasized) var(--easing-smooth);
    animation-delay: 0.3s;
    animation-fill-mode: both;
}

.custom-time {
    animation: fadeIn var(--duration-emphasized) var(--easing-default);
    animation-delay: 0.4s;
    animation-fill-mode: both;
}

/* === Confetti Component === */
.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    background: var(--accent-primary);
    pointer-events: none;
    z-index: var(--z-toast);
}

.confetti.fall {
    animation: confetti-fall 3s linear infinite,
               confetti-sway 2s ease-in-out infinite;
}

.confetti:nth-child(odd) {
    background: var(--accent-secondary);
    animation-delay: 0.5s;
}

.confetti:nth-child(3n) {
    background: var(--success);
    animation-delay: 1s;
    transform: scale(0.8);
}

.confetti:nth-child(4n) {
    background: var(--warning);
    animation-delay: 1.5s;
    transform: scale(1.2);
}

/* === Ripple Effect === */
.ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    pointer-events: none;
    animation: ripple 0.6s ease-out;
}

/* === Hover Animations === */
.btn:not(:disabled):hover .icon {
    transform: scale(1.1);
}

.theme-option:hover .theme-preview {
    transform: scale(1.1) rotate(5deg);
}

/* === Focus Animations === */
.btn:focus-visible {
    animation: pulse 0.5s ease-in-out;
}

/* === Error State Animations === */
.error {
    animation: shake 0.5s ease-in-out;
}

.time-input__field:invalid {
    animation: shake 0.3s ease-in-out;
}

/* === Success State Animations === */
.success {
    animation: bounce var(--duration-emphasized) var(--easing-bounce);
}

/* === Reduced Motion Overrides === */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .timer-time.counting-down,
    .timer-time.final-countdown,
    .progress-ring.pulsing .progress-ring__progress,
    .progress-ring.final-countdown .progress-ring__progress {
        animation: none !important;
    }
    
    /* Keep essential state changes visible but instant */
    .timer-time.completed {
        transform: scale(1.05);
        animation: none;
    }
    
    .progress-ring.completed .progress-ring__progress {
        filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.5));
        animation: none;
    }
}

/* === High Contrast Mode Animations === */
@media (prefers-contrast: high) {
    .progress-ring__progress {
        filter: none !important;
    }
    
    .confetti {
        border: 2px solid currentColor;
        background: transparent !important;
    }
}

/* === Animation Performance Optimizations === */
.timer-time,
.progress-ring__progress,
.btn,
.modal__content,
.settings,
.notification {
    will-change: transform;
}

/* Remove will-change after animation completes to save memory */
.animation-complete {
    will-change: auto;
}

/* === Custom Animation Timing Functions === */
:root {
    --easing-bounce-in: cubic-bezier(0.6, 0.04, 0.98, 0.335);
    --easing-bounce-out: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --easing-bounce-in-out: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    
    --easing-back-in: cubic-bezier(0.36, 0, 0.66, -0.56);
    --easing-back-out: cubic-bezier(0.34, 1.56, 0.64, 1);
    --easing-back-in-out: cubic-bezier(0.68, -0.6, 0.32, 1.6);
    
    --easing-elastic-in: cubic-bezier(0.55, 0.055, 0.675, 0.19);
    --easing-elastic-out: cubic-bezier(0.215, 0.61, 0.355, 1);
    --easing-elastic-in-out: cubic-bezier(0.645, 0.045, 0.355, 1);
}

/* === Stagger Animation Delays === */
.presets__grid .btn--preset {
    animation: fadeIn var(--duration-standard) var(--easing-default);
    animation-fill-mode: both;
}

.presets__grid .btn--preset:nth-child(1) { animation-delay: 0.1s; }
.presets__grid .btn--preset:nth-child(2) { animation-delay: 0.15s; }
.presets__grid .btn--preset:nth-child(3) { animation-delay: 0.2s; }
.presets__grid .btn--preset:nth-child(4) { animation-delay: 0.25s; }
.presets__grid .btn--preset:nth-child(5) { animation-delay: 0.3s; }
.presets__grid .btn--preset:nth-child(6) { animation-delay: 0.35s; }
.presets__grid .btn--preset:nth-child(7) { animation-delay: 0.4s; }
.presets__grid .btn--preset:nth-child(8) { animation-delay: 0.45s; }
.presets__grid .btn--preset:nth-child(9) { animation-delay: 0.5s; }
.presets__grid .btn--preset:nth-child(10) { animation-delay: 0.55s; }

/* === Print Mode Animation Overrides === */
@media print {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}

/* Pulse animation for preset buttons */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: var(--shadow-subtle);
    }
    50% {
        transform: scale(1.05);
        box-shadow: var(--shadow-medium);
    }
}

/* Add subtle pulse animation to indicate clickability */
@keyframes timer-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
}

.timer-display.clickable .progress-ring {
    animation: timer-pulse 3s ease-in-out infinite;
}

.timer-display.clickable .progress-ring:hover {
    animation: none; /* Stop pulse on hover */
}

/* === SLAY MODE ANIMATIONS === */

/* Sparkle animation for completion */
@keyframes sparkle {
    0%, 100% {
        transform: scale(1) rotate(0deg);
        opacity: 0.8;
    }
    25% {
        transform: scale(1.1) rotate(90deg);
        opacity: 1;
    }
    50% {
        transform: scale(1.2) rotate(180deg);
        opacity: 0.9;
    }
    75% {
        transform: scale(1.1) rotate(270deg);
        opacity: 1;
    }
}

/* Rainbow glow effect */
@keyframes rainbowGlow {
    0% {
        box-shadow: 0 0 20px rgba(255, 0, 150, 0.6);
        filter: hue-rotate(0deg);
    }
    25% {
        box-shadow: 0 0 30px rgba(0, 150, 255, 0.8);
        filter: hue-rotate(90deg);
    }
    50% {
        box-shadow: 0 0 40px rgba(150, 255, 0, 0.6);
        filter: hue-rotate(180deg);
    }
    75% {
        box-shadow: 0 0 30px rgba(255, 150, 0, 0.8);
        filter: hue-rotate(270deg);
    }
    100% {
        box-shadow: 0 0 20px rgba(255, 0, 150, 0.6);
        filter: hue-rotate(360deg);
    }
}

/* Celebration bounce */
@keyframes celebrationBounce {
    0%, 20%, 53%, 80%, 100% {
        transform: scale(1) translateY(0);
    }
    40%, 43% {
        transform: scale(1.08) translateY(-12px);
    }
    70% {
        transform: scale(1.04) translateY(-6px);
    }
    90% {
        transform: scale(1.02) translateY(-3px);
    }
}

/* Floating particles effect */
@keyframes floatUp {
    0% {
        opacity: 1;
        transform: translateY(0) scale(0.8) rotate(0deg);
    }
    50% {
        opacity: 0.8;
        transform: translateY(-150px) scale(1.2) rotate(180deg);
    }
    100% {
        opacity: 0;
        transform: translateY(-250px) scale(1.5) rotate(360deg);
    }
}

/* Pulsing glow for running timer */
@keyframes focusGlow {
    0%, 100% {
        box-shadow: 0 0 15px rgba(102, 126, 234, 0.3);
    }
    50% {
        box-shadow: 0 0 25px rgba(102, 126, 234, 0.6), 0 0 40px rgba(102, 126, 234, 0.2);
    }
}

/* Smooth scale hover effect */
@keyframes smoothScale {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1.02);
    }
}

/* Shimmer effect for buttons */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Completion celebration classes */
.timer-display.celebration {
    animation: celebrationBounce 2s ease-in-out;
}

.timer-display.celebration::before {
    content: '';
    position: absolute;
    top: -20px;
    left: -20px;
    right: -20px;
    bottom: -20px;
    border-radius: 50%;
    animation: rainbowGlow 3s ease-in-out infinite;
    z-index: -1;
}

.progress-ring.celebration {
    animation: sparkle 1.5s ease-in-out;
}

/* Focus mode enhancements */
.timer-display.running {
    animation: focusGlow 3s ease-in-out infinite;
}

/* Button hover enhancements */
.btn--preset:hover,
.btn--primary:hover {
    animation: smoothScale 0.3s ease-in-out forwards;
    background: linear-gradient(90deg, var(--primary), var(--primary-light), var(--primary));
    background-size: 200% 100%;
    animation-name: smoothScale, shimmer;
    animation-duration: 0.3s, 1.5s;
    animation-iteration-count: 1, infinite;
}

/* Floating particles container */
.particles-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    overflow: visible;
    z-index: 1000;
}

.particle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: radial-gradient(circle, var(--primary), var(--accent));
    border-radius: 50%;
    animation: floatUp 4s ease-out forwards;
    box-shadow: 0 0 6px rgba(102, 126, 234, 0.8);
}

/* Responsive adjustments for slay mode */
@media (max-width: 768px) {
    .timer-display.celebration {
        animation-duration: 1.5s;
    }
    
    .timer-display.celebration::before {
        top: -10px;
        left: -10px;
        right: -10px;
        bottom: -10px;
    }
}

/* Confetti fall animation */
@keyframes confettiFall {
    0% {
        transform: translateY(-10px) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

.confetti {
    border-radius: 2px;
    pointer-events: none;
}
