/* ========================================
   yuru.be Animation System
   Performance-optimized, GPU-accelerated
   ======================================== */

/* ========================================
   1. MICRO-INTERACTIONS
   ======================================== */

/* Button Press - Subtle scale with fast spring */
.btn:active,
.btn-primary:active,
.btn-accent:active,
.ai-card:active,
.theme-color:active,
.back-link:active {
    transform: scale(0.98);
    transition: transform 0.1s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Hover Lifts - Subtle elevation with shadow */
.card-interactive:hover,
.btn:hover,
.ai-card:hover {
    transform: translateY(-1px);
    box-shadow:
        0 0 16px rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.15),
        0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Focus Rings - Animated outline expansion */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    animation: focus-ring 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes focus-ring {
    0% {
        outline-offset: 0px;
        outline-width: 0px;
    }
    100% {
        outline-offset: 2px;
        outline-width: 2px;
    }
}

/* Input Focus - Border color fade with glow */
.input:focus,
input:focus,
textarea:focus,
select:focus {
    border-color: rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.5);
    box-shadow:
        0 0 8px rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.1),
        0 0 0 3px rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.05);
    transition:
        border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Ripple Effect Base (using ::before pseudo-element) */
.btn::before,
.link::before,
.ai-card::before {
    transform: scale(0);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:active::before,
.link:active::before,
.ai-card:active::before {
    transform: scale(1);
    opacity: 1;
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   2. PAGE TRANSITIONS (CSS-only)
   ======================================== */

/* Fade-in on load */
@keyframes pageLoad {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page-load {
    animation: pageLoad 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Staggered card animations using custom properties */
.stagger-item {
    opacity: 0;
    animation: staggerFadeIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    animation-delay: calc(var(--stagger-delay, 0) * 0.05s);
}

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

/* Content reveal animations */
.reveal-fade {
    animation: revealFade 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.reveal-slide-up {
    animation: revealSlideUp 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.reveal-slide-left {
    animation: revealSlideLeft 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.reveal-scale {
    animation: revealScale 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

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

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

@keyframes revealScale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Page navigation transitions */
.page-transition-enter {
    animation: pageEnter 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.page-transition-exit {
    animation: pageExit 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

/* ========================================
   3. SMOOTH SCROLLING
   ======================================== */

html {
    scroll-behavior: smooth;
}

/* Scroll-linked fade for headers */
.scroll-fade-header {
    opacity: 1;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: opacity, transform;
}

.scroll-fade-header.scrolled {
    opacity: 0.7;
    transform: translateY(-2px);
}

/* Parallax scroll effect (minimal, performance-safe) */
.parallax-slow {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   4. LOADING ANIMATIONS
   ======================================== */

/* Skeleton Pulse - Shimmer effect */
.skeleton {
    position: relative;
    overflow: hidden;
    background: linear-gradient(
        90deg,
        var(--hover) 0%,
        rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.08) 50%,
        var(--hover) 100%
    );
    background-size: 200% 100%;
    animation: skeletonPulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

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

/* Alternative skeleton with shimmer overlay */
.skeleton-shimmer {
    position: relative;
    overflow: hidden;
    background: var(--hover);
}

.skeleton-shimmer::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.1) 50%,
        transparent 100%
    );
    animation: shimmerSlide 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes shimmerSlide {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* Spinner - Minimal industrial style */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 0.6s linear infinite;
    will-change: transform;
}

.spinner-sm {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

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

/* Spinner variant with accent glow */
.spinner-glow {
    border: 2px solid rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.2);
    border-top-color: var(--accent);
    box-shadow: 0 0 12px rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.3);
}

/* Progress Bar Animation */
.progress-bar {
    position: relative;
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: width;
}

/* Indeterminate progress bar */
.progress-bar-indeterminate .progress-bar-fill {
    width: 40%;
    animation: progressIndeterminate 1.5s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}

@keyframes progressIndeterminate {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(250%);
    }
}

/* Loading dots */
.loading-dots {
    display: inline-flex;
    gap: 4px;
}

.loading-dot {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: dotPulse 1.4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.loading-dot:nth-child(1) {
    animation-delay: 0s;
}

.loading-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dotPulse {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1.2);
    }
}

/* ========================================
   5. STATE CHANGES
   ======================================== */

/* Checkbox/Toggle Animations */
input[type="checkbox"] {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
    animation: checkboxCheck 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes checkboxCheck {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

/* Toggle switch animation */
.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
    background: var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: var(--fg);
    border-radius: 50%;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    will-change: transform;
}

.toggle.active {
    background: var(--accent);
}

.toggle.active::after {
    transform: translateX(24px);
}

/* Accordion Expand/Collapse */
.accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    will-change: max-height, opacity;
}

.accordion-content.open {
    max-height: 1000px; /* Adjust based on content */
    opacity: 1;
}

.accordion-header {
    cursor: pointer;
    transition: color 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.accordion-header:hover {
    color: var(--accent);
}

.accordion-icon {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

.accordion-header.open .accordion-icon {
    transform: rotate(180deg);
}

/* Modal Fade + Scale */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9000;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    transform: scale(0.95) translateY(10px);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform, opacity;
}

.modal.active .modal-content {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Toast/Notification slide-up */
.toast {
    transform: translateX(-50%) translateY(20px);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    visibility: visible;
}

/* Dropdown menu animations */
.dropdown-menu {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.dropdown-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Badge pop-in animation */
.badge-animated {
    animation: badgePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes badgePop {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
   ======================================== */

/* GPU-accelerated elements */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Will-change for specific animations */
.animating {
    will-change: transform, opacity;
}

/* Remove will-change after animation completes */
.animation-done {
    will-change: auto;
}

/* ========================================
   ACCESSIBILITY - Reduced Motion
   ======================================== */

@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;
    }

    /* Disable all custom animations */
    .skeleton,
    .skeleton-shimmer::after,
    .spinner,
    .spinner-glow,
    .progress-bar-indeterminate .progress-bar-fill,
    .loading-dot,
    .stagger-item,
    .page-load,
    .reveal-fade,
    .reveal-slide-up,
    .reveal-slide-left,
    .reveal-scale,
    .page-transition-enter,
    .page-transition-exit {
        animation: none !important;
    }

    /* Simplify transitions for essential state changes */
    .toggle::after,
    .accordion-content,
    .modal,
    .modal-content,
    .toast,
    .dropdown-menu {
        transition-duration: 0.01ms !important;
    }

    /* Keep focus visible but without animation */
    :focus-visible {
        animation: none !important;
    }

    /* Disable hover transforms */
    .card-interactive:hover,
    .btn:hover,
    .ai-card:hover {
        transform: none !important;
    }

    /* Disable scale on press */
    .btn:active,
    .btn-primary:active,
    .btn-accent:active,
    .ai-card:active,
    .theme-color:active,
    .back-link:active {
        transform: none !important;
    }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

/* Quick fade utilities */
.fade-in {
    animation: revealFade 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.fade-out {
    animation: revealFade 0.3s cubic-bezier(0.4, 0, 0.2, 1) reverse;
}

/* Slide utilities */
.slide-in-up {
    animation: revealSlideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.slide-in-left {
    animation: revealSlideLeft 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Scale utilities */
.scale-in {
    animation: revealScale 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Pulse animation */
.pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

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

/* Bounce animation (subtle) */
.bounce-subtle {
    animation: bounceSubtle 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

/* Shake animation for errors */
.shake {
    animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

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

/* Glow pulse animation */
.glow-pulse {
    animation: glowPulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes glowPulse {
    0%, 100% {
        box-shadow: 0 0 8px rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.2);
    }
    50% {
        box-shadow: 0 0 20px rgba(var(--accent-r), var(--accent-g), var(--accent-b), 0.4);
    }
}
