@layer animations {
/* ============================================
   Animations & Transitions
   ============================================ */

/* --- Pulse animation for status indicator --- */
@keyframes pulse {
    0% {
        opacity: 0.6;
        transform: scale(1);
    }
    50% {
        opacity: 0;
        transform: scale(2);
    }
    100% {
        opacity: 0;
        transform: scale(2);
    }
}

/* --- Standard spin (loading spinners) --- */
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Slow spin for brand icon --- */
@keyframes spin-slow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* --- Toast slide in/out --- */
@keyframes toast-slide-in {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toast-slide-out {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100px);
    }
}

/* --- Feed entry appear --- */
@keyframes feed-appear {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.feed-entry-new {
    animation: feed-appear 0.2s ease-out;
}

/* --- Gauge glow pulse (when within tolerance) --- */
@keyframes gauge-glow {
    0%, 100% {
        filter: drop-shadow(0 0 6px var(--color-success-glow));
    }
    50% {
        filter: drop-shadow(0 0 20px var(--color-success-glow));
    }
}

.gauge-value[style*="var(--color-success)"] {
    animation: gauge-glow 1.5s ease-in-out infinite;
}

/* --- Card hover lift --- */
@keyframes card-lift {
    from { transform: translateY(0); }
    to { transform: translateY(-4px); }
}

/* --- Timer glow animation (while running) --- */
@keyframes timer-glow {
    0%, 100% {
        text-shadow: 0 0 6px var(--accent-glow);
        color: var(--text-primary);
    }
    50% {
        text-shadow: 0 0 14px var(--accent), 0 0 28px var(--accent-glow);
        color: var(--accent);
    }
}

.timer-display.running {
    animation: timer-glow 2s ease-in-out infinite;
}

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

.loading-shimmer {
    background: linear-gradient(
        90deg,
        var(--surface-1) 25%,
        var(--surface-2) 50%,
        var(--surface-1) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--border-radius-sm);
}

/* --- Win modal scale-in --- */
@keyframes modal-scale-in {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* --- Win time celebration pulse --- */
@keyframes win-time-pulse {
    0%, 100% {
        filter: drop-shadow(0 0 16px var(--color-success-glow));
    }
    50% {
        filter: drop-shadow(0 0 32px var(--color-success-glow));
    }
}

.win-time {
    animation: win-time-pulse 2s ease-in-out 3;
}

/* --- Fade in utility --- */
@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.fade-in {
    animation: fade-in 0.5s ease-out;
}

/* --- Staggered grid entrance --- */
.challenge-card {
    opacity: 0;
    animation: card-entrance 0.4s ease-out forwards;
}

/* Note: Animation delay for challenge cards is set dynamically via JS
   (dashboard.js) to support any number of cards beyond 6.
   Skeleton cards retain their CSS nth-child stagger below since
   they have a fixed count. */

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

/* --- Reduce motion for accessibility --- */
@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;
    }

    /* Ensure elements that use animation-fill-mode forwards are still visible */
    .challenge-card,
    .account-card,
    .form-section,
    .controls-panel .widget-block,
    .controls-panel .action-buttons,
    .skeleton-card,
    .skeleton-lb-row {
        opacity: 1 !important;
    }
}

/* --- Page entrance fade --- */
body {
    animation: page-fade-in 0.4s ease-out;
}

@keyframes page-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --- Account card staggered entrance --- */
.account-card {
    opacity: 0;
    animation: card-entrance 0.4s ease-out forwards;
}

.account-left .account-card:nth-child(1) { animation-delay: 0.05s; }
.account-left .account-card:nth-child(2) { animation-delay: 0.1s; }
.account-left .account-card:nth-child(3) { animation-delay: 0.15s; }
.account-right .account-card:nth-child(1) { animation-delay: 0.1s; }
.account-right .account-card:nth-child(2) { animation-delay: 0.15s; }
.account-right .account-card:nth-child(3) { animation-delay: 0.2s; }
.account-right .account-card:nth-child(4) { animation-delay: 0.25s; }

/* --- Completion ring fill animation --- */
@keyframes ring-fill {
    from { stroke-dashoffset: 314.16; }
}

.completion-ring-fill {
    animation: ring-fill 1.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    animation-delay: 0.3s;
}

/* --- Form section staggered entrance (create page) --- */
.form-section {
    opacity: 0;
    animation: card-entrance 0.4s ease-out forwards;
}

.form-section:nth-child(1) { animation-delay: 0.05s; }
.form-section:nth-child(2) { animation-delay: 0.15s; }
.form-section:nth-child(3) { animation-delay: 0.1s; }

/* --- Widget block staggered entrance (challenge page) --- */
.controls-panel .widget-block {
    opacity: 0;
    animation: card-entrance 0.3s ease-out forwards;
}

.controls-panel .widget-block:nth-child(1) { animation-delay: 0.05s; }
.controls-panel .widget-block:nth-child(2) { animation-delay: 0.1s; }
.controls-panel .widget-block:nth-child(3) { animation-delay: 0.15s; }
.controls-panel .widget-block:nth-child(4) { animation-delay: 0.2s; }

.controls-panel .action-buttons {
    opacity: 0;
    animation: card-entrance 0.3s ease-out forwards;
    animation-delay: 0.15s;
}

/* --- Skeleton card staggered entrance --- */
.skeleton-card {
    opacity: 0;
    animation: skeleton-fade-in 0.4s ease-out forwards;
}

.skeleton-card:nth-child(1) { animation-delay: 0.05s; }
.skeleton-card:nth-child(2) { animation-delay: 0.1s; }
.skeleton-card:nth-child(3) { animation-delay: 0.15s; }
.skeleton-card:nth-child(4) { animation-delay: 0.2s; }
.skeleton-card:nth-child(5) { animation-delay: 0.25s; }
.skeleton-card:nth-child(6) { animation-delay: 0.3s; }

@keyframes skeleton-fade-in {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Skeleton leaderboard row stagger --- */
.skeleton-lb-row {
    opacity: 0;
    animation: skeleton-fade-in 0.3s ease-out forwards;
}

.skeleton-lb-row:nth-child(1) { animation-delay: 0.05s; }
.skeleton-lb-row:nth-child(2) { animation-delay: 0.1s; }
.skeleton-lb-row:nth-child(3) { animation-delay: 0.15s; }
.skeleton-lb-row:nth-child(4) { animation-delay: 0.2s; }
.skeleton-lb-row:nth-child(5) { animation-delay: 0.25s; }

/* --- Empty state fade-in --- */
.empty-state {
    animation: fade-scale-in 0.5s ease-out;
}

@keyframes fade-scale-in {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* --- Hero badge entrance --- */
.hero-badge {
    animation: badge-slide-in 0.6s ease-out;
}

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

/* --- Footer accent gradient pulse --- */
@keyframes footer-glow {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* --- Stat counter animation --- */
@keyframes count-up-pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
    100% {
        transform: scale(1);
    }
}

.stat-value.counting {
    animation: count-up-pop 0.3s ease-out;
}

/* ============================================
   View Transitions API
   ============================================ */

/* Smooth page transition for browsers that support it */
::view-transition-old(root) {
    animation: view-fade-out 0.15s ease-in forwards;
}

::view-transition-new(root) {
    animation: view-fade-in 0.25s ease-out forwards;
}

@keyframes view-fade-out {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.99); }
}

@keyframes view-fade-in {
    from { opacity: 0; transform: scale(1.005); }
    to { opacity: 1; transform: scale(1); }
}

/* Prevent flash of unstyled content during view transitions */
::view-transition-group(root) {
    animation-duration: 0.25s;
}

/* ============================================
   Phase 16.2 — Countdown Animations
   ============================================ */

@keyframes countdown-pulse {
    0%, 100% {
        border-color: var(--border-color);
        box-shadow: none;
    }
    50% {
        border-color: rgba(239, 68, 68, 0.4);
        box-shadow: 0 0 24px rgba(239, 68, 68, 0.1);
    }
}

@keyframes countdown-flash {
    0% { background-color: rgba(239, 68, 68, 0.15); }
    100% { background-color: transparent; }
}

/* ============================================
   Phase 16.3 — Podium Animations
   ============================================ */

@keyframes podium-rise {
    from {
        opacity: 0;
        transform: translateY(60px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   Enhanced Stepper — Checkmark Pop
   ============================================ */

@keyframes step-check-pop {
    0% { transform: scale(0.6); opacity: 0.5; }
    60% { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

/* ============================================
   Activity Feed — Slide In
   ============================================ */

@keyframes feed-slide-in {
    from {
        opacity: 0;
        transform: translateX(-12px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

} /* end @layer animations */
