/* ==========================================================================
   Xinh Motion Engine — motion.css
   Reusable CSS motion primitives, keyframes, and utility classes.
   Honors prefers-reduced-motion and --motion-intensity.
   ========================================================================== */

/* ==========================================================================
   1. Motion Intensity & Reduced Motion
   ========================================================================== */

:root {
    --motion-intensity: 1;          /* 0=minimal, 0.5=balanced, 1=dynamic, 1.25=cinematic */
    --motion-duration-multiplier: 1;
    --motion-distance-multiplier: 1;
}

/* Respect OS-level reduced motion preference */
@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;
    }
}

/* ==========================================================================
   2. Consolidated Keyframe Library
   (migrated from base.css and components.css)
   ========================================================================== */

/* --- Heart interactions --- */
@keyframes heartBeat {
    0%, 100% { transform: scale(1); }
    15% { transform: scale(1.18); }
    30% { transform: scale(1); }
    45% { transform: scale(1.12); }
}

@keyframes heartBurst {
    0% { transform: scale(0) rotate(-15deg); opacity: 0; }
    40% { transform: scale(1.35) rotate(0deg); opacity: 1; }
    70% { transform: scale(1.1) rotate(5deg); opacity: 0.9; }
    100% { transform: scale(1.5) rotate(0deg); opacity: 0; }
}

@keyframes heartPop {
    0% {
        transform: translate(-50%, -50%) scale(0) rotate(-15deg);
        opacity: 0;
    }
    40% {
        transform: translate(-50%, -50%) scale(1.25) rotate(0deg);
        opacity: 1;
    }
    70% {
        transform: translate(-50%, -50%) scale(1.0) translateY(-20px);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(0.8) translateY(-60px);
        opacity: 0;
    }
}

/* --- Bounce & Spin --- */
@keyframes bounceScale {
    0% { transform: scale(1); }
    30% { transform: scale(1.35); }
    60% { transform: scale(0.88); }
    100% { transform: scale(1); }
}

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

/* --- Glow & Pulse --- */
@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 45, 85, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(255, 45, 85, 0); }
}

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

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

/* --- Entrance / Exit --- */
@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes floatEmoji {
    0% {
        transform: translateY(0) scale(0.8);
        opacity: 1;
    }
    100% {
        transform: translateY(-120px) scale(1.4);
        opacity: 0;
    }
}

@keyframes soundWave {
    0%, 100% { height: 4px; }
    50% { height: 16px; }
}

/* --- Toast --- */
@keyframes toastProgress {
    from { width: 100%; }
    to { width: 0%; }
}

@keyframes toastSlideInRight {
    from {
        opacity: 0;
        transform: translateX(80px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

/* --- Badge pop --- */
@keyframes popBadge {
    0% { transform: scale(0.5); opacity: 0; }
    70% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

/* --- Loading dots --- */
@keyframes loadingDot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* --- Gradient spin (story ring, ambient) --- */
@keyframes gradientSpin {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* ==========================================================================
   3. Motion Primitive Keyframes (new)
   ========================================================================== */

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

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

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

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

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

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

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

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

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

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

@keyframes motionSpringIn {
    0% { opacity: 0; transform: scale(0.8); }
    50% { opacity: 0.8; transform: scale(1.05); }
    75% { opacity: 1; transform: scale(0.96); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes motionReveal {
    from { clip-path: inset(0 0 100% 0); }
    to { clip-path: inset(0 0 0 0); }
}

/* ==========================================================================
   4. Motion Utility Classes
   ========================================================================== */

/* --- Fade --- */
.motion-fade-in {
    animation: motionFadeIn var(--motion-normal) var(--ease-standard) both;
}

.motion-fade-out {
    animation: motionFadeOut var(--motion-fast) var(--ease-standard) both;
}

/* --- Slide --- */
.motion-slide-in-up {
    animation: motionSlideInUp var(--motion-normal) var(--ease-emphasized) both;
}

.motion-slide-in-down {
    animation: motionSlideInDown var(--motion-normal) var(--ease-emphasized) both;
}

.motion-slide-in-left {
    animation: motionSlideInLeft var(--motion-normal) var(--ease-emphasized) both;
}

.motion-slide-in-right {
    animation: motionSlideInRight var(--motion-normal) var(--ease-emphasized) both;
}

.motion-slide-out-up {
    animation: motionSlideOutUp var(--motion-fast) var(--ease-standard) both;
}

.motion-slide-out-down {
    animation: motionSlideOutDown var(--motion-fast) var(--ease-standard) both;
}

/* --- Scale --- */
.motion-scale-in {
    animation: motionScaleIn var(--motion-normal) var(--ease-emphasized) both;
}

.motion-scale-out {
    animation: motionScaleOut var(--motion-fast) var(--ease-standard) both;
}

/* --- Spring --- */
.motion-spring-in {
    animation: motionSpringIn var(--motion-slow) var(--ease-emphasized) both;
}

/* --- Reveal --- */
.motion-reveal {
    animation: motionReveal var(--motion-emphasized) var(--ease-emphasized) both;
}

/* --- Hover interactions --- */
.motion-hover-lift {
    transition: transform var(--motion-fast) var(--ease-standard);
}

.motion-hover-lift:hover {
    transform: translateY(-3px);
}

.motion-hover-glow {
    transition: box-shadow var(--motion-normal) var(--ease-standard);
}

.motion-hover-glow:hover {
    box-shadow: var(--shadow-glow-primary);
}

.motion-hover-scale {
    transition: transform var(--motion-fast) var(--ease-standard);
}

.motion-hover-scale:hover {
    transform: scale(1.04);
}

/* --- Press interaction --- */
.motion-press:active {
    transform: scale(0.96);
    transition: transform var(--motion-fast) var(--ease-standard);
}

/* --- Stagger children --- */
.motion-stagger > * {
    opacity: 0;
    animation: motionFadeIn var(--motion-normal) var(--ease-standard) both;
}

.motion-stagger > *:nth-child(1) { animation-delay: 0ms; }
.motion-stagger > *:nth-child(2) { animation-delay: 60ms; }
.motion-stagger > *:nth-child(3) { animation-delay: 120ms; }
.motion-stagger > *:nth-child(4) { animation-delay: 180ms; }
.motion-stagger > *:nth-child(5) { animation-delay: 240ms; }
.motion-stagger > *:nth-child(6) { animation-delay: 300ms; }
.motion-stagger > *:nth-child(7) { animation-delay: 360ms; }
.motion-stagger > *:nth-child(8) { animation-delay: 420ms; }
.motion-stagger > *:nth-child(9) { animation-delay: 480ms; }
.motion-stagger > *:nth-child(10) { animation-delay: 540ms; }

/* --- Shimmer (loading) --- */
.motion-shimmer {
    background: linear-gradient(
        90deg,
        var(--surface-3) 25%,
        var(--surface-hover) 50%,
        var(--surface-3) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite;
}

/* ==========================================================================
   5. Motion Intensity Levels (CSS custom property driven)
   ========================================================================== */

/* Balanced: 0.5x speed */
[data-motion-intensity="balanced"] {
    --motion-duration-multiplier: 1.4;
    --motion-distance-multiplier: 0.7;
}

/* Dynamic: 1x (default) */
[data-motion-intensity="dynamic"] {
    --motion-duration-multiplier: 1;
    --motion-distance-multiplier: 1;
}

/* Cinematic: 1.25x speed, extra distance */
[data-motion-intensity="cinematic"] {
    --motion-duration-multiplier: 0.85;
    --motion-distance-multiplier: 1.3;
}

/* Minimal: instant */
[data-motion-intensity="minimal"] {
    --motion-duration-multiplier: 0;
    --motion-distance-multiplier: 0;
}