/**
 * 两山·茶管家 - 高级动画库
 * 现代化微动画、页面过渡、交互反馈
 */

/* ==================== 页面加载动画 ==================== */

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

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

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

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

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

/* 动画工具类 */
.animate-fade-in-up {
    animation: fadeInUp 0.6s var(--ease-smooth) forwards;
}

.animate-fade-in-down {
    animation: fadeInDown 0.6s var(--ease-smooth) forwards;
}

.animate-fade-in-left {
    animation: fadeInLeft 0.6s var(--ease-smooth) forwards;
}

.animate-fade-in-right {
    animation: fadeInRight 0.6s var(--ease-smooth) forwards;
}

.animate-fade-in-scale {
    animation: fadeInScale 0.6s var(--ease-bounce) forwards;
}

/* 延迟类 */
.delay-100 { animation-delay: 0.1s; }
.delay-200 { animation-delay: 0.2s; }
.delay-300 { animation-delay: 0.3s; }
.delay-400 { animation-delay: 0.4s; }
.delay-500 { animation-delay: 0.5s; }

/* ==================== 按钮交互动画 ==================== */

@keyframes buttonPress {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.95);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 0.6;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

.btn-interactive {
    position: relative;
    overflow: hidden;
    transition: all 0.3s var(--ease-smooth);
}

.btn-interactive:active {
    animation: buttonPress 0.3s var(--ease-smooth);
}

.btn-interactive::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%) scale(0);
    pointer-events: none;
}

.btn-interactive:active::after {
    animation: ripple 0.6s ease-out;
}

/* ==================== 卡片悬停动画 ==================== */

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

@keyframes cardTilt {
    0% {
        transform: perspective(1000px) rotateX(0) rotateY(0);
    }
    100% {
        transform: perspective(1000px) rotateX(var(--rotate-x, 0)) rotateY(var(--rotate-y, 0));
    }
}

.card-float:hover {
    animation: cardFloat 2s ease-in-out infinite;
}

.card-3d {
    transition: transform 0.3s var(--ease-smooth);
    transform-style: preserve-3d;
}

.card-3d:hover {
    transform: perspective(1000px) rotateX(-5deg) rotateY(5deg);
}

/* ==================== 加载动画 ==================== */

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

@keyframes spinFade {
    0% {
        transform: rotate(0deg);
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
    100% {
        transform: rotate(360deg);
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.05);
    }
}

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

@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: var(--primary-color);
        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 var(--primary-color),
            0.5em 0 0 rgba(0, 0, 0, 0);
    }
    80%, 100% {
        text-shadow:
            0.25em 0 0 var(--primary-color),
            0.5em 0 0 var(--primary-color);
    }
}

.loading-spin {
    animation: spin 1s linear infinite;
}

.loading-spin-fade {
    animation: spinFade 1.5s ease-in-out infinite;
}

.loading-pulse {
    animation: pulse 1.5s ease-in-out infinite;
}

.loading-bounce {
    animation: bounce 1s ease-in-out infinite;
}

.loading-dots::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

/* ==================== 滚动显现动画 ==================== */

.scroll-reveal {
    opacity: 0;
    transform: translateY(50px);
    transition: opacity 0.8s var(--ease-smooth), transform 0.8s var(--ease-smooth);
}

.scroll-reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

.scroll-reveal-left {
    opacity: 0;
    transform: translateX(-50px);
    transition: opacity 0.8s var(--ease-smooth), transform 0.8s var(--ease-smooth);
}

.scroll-reveal-left.revealed {
    opacity: 1;
    transform: translateX(0);
}

.scroll-reveal-right {
    opacity: 0;
    transform: translateX(50px);
    transition: opacity 0.8s var(--ease-smooth), transform 0.8s var(--ease-smooth);
}

.scroll-reveal-right.revealed {
    opacity: 1;
    transform: translateX(0);
}

.scroll-reveal-scale {
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.8s var(--ease-smooth), transform 0.8s var(--ease-bounce);
}

.scroll-reveal-scale.revealed {
    opacity: 1;
    transform: scale(1);
}

/* ==================== 文字动画 ==================== */

@keyframes textGradient {
    0%, 100% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
}

@keyframes textGlow {
    0%, 100% {
        text-shadow: 0 0 10px rgba(46, 125, 50, 0.5);
    }
    50% {
        text-shadow: 0 0 20px rgba(46, 125, 50, 0.8), 0 0 30px rgba(46, 125, 50, 0.5);
    }
}

.text-gradient-animated {
    background: linear-gradient(90deg, #2E7D32, #43A047, #66BB6A, #43A047, #2E7D32);
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: textGradient 3s ease infinite;
}

.text-glow {
    animation: textGlow 2s ease-in-out infinite;
}

/* ==================== 数字滚动动画 ==================== */

@keyframes numberRoll {
    0% {
        transform: translateY(100%);
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.number-roll {
    display: inline-block;
    overflow: hidden;
}

.number-roll span {
    display: inline-block;
    animation: numberRoll 0.5s var(--ease-bounce) forwards;
}

/* ==================== 进度条动画 ==================== */

@keyframes progressFill {
    from {
        width: 0%;
    }
    to {
        width: var(--progress-width, 100%);
    }
}

@keyframes progressGlow {
    0%, 100% {
        box-shadow: 0 0 10px rgba(46, 125, 50, 0.5);
    }
    50% {
        box-shadow: 0 0 20px rgba(46, 125, 50, 0.8);
    }
}

.progress-animated {
    animation: progressFill 1.5s var(--ease-smooth) forwards;
}

.progress-glow {
    animation: progressGlow 2s ease-in-out infinite;
}

/* ==================== 徽章脉动 ==================== */

@keyframes badgePulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(46, 125, 50, 0.7);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(46, 125, 50, 0);
    }
}

.badge-pulse {
    animation: badgePulse 2s ease-in-out infinite;
}

/* ==================== 图片悬停效果 ==================== */

@keyframes imageZoom {
    from {
        transform: scale(1);
    }
    to {
        transform: scale(1.1);
    }
}

.image-zoom {
    overflow: hidden;
}

.image-zoom img {
    transition: transform 0.6s var(--ease-smooth);
}

.image-zoom:hover img {
    transform: scale(1.1);
}

.image-zoom-rotate {
    overflow: hidden;
}

.image-zoom-rotate img {
    transition: transform 0.6s var(--ease-smooth);
}

.image-zoom-rotate:hover img {
    transform: scale(1.1) rotate(3deg);
}

/* ==================== 通知滑入动画 ==================== */

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.notification-slide-in {
    animation: slideInRight 0.4s var(--ease-smooth) forwards;
}

.notification-slide-out {
    animation: slideOutRight 0.4s var(--ease-smooth) forwards;
}

/* ==================== 模态框动画 ==================== */

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

@keyframes modalSlideUp {
    from {
        transform: translateY(50px) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.modal-backdrop {
    animation: modalFadeIn 0.3s ease forwards;
}

.modal-content {
    animation: modalSlideUp 0.4s var(--ease-bounce) forwards;
}

/* ==================== 骨架屏闪烁 ==================== */

@keyframes skeletonShimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 2000px 100%;
    animation: skeletonShimmer 2s infinite linear;
    border-radius: 4px;
}

/* ==================== 视差滚动 ==================== */

.parallax-slow {
    transform: translateY(calc(var(--scroll-y, 0) * -0.3px));
    transition: transform 0.1s ease-out;
}

.parallax-medium {
    transform: translateY(calc(var(--scroll-y, 0) * -0.5px));
    transition: transform 0.1s ease-out;
}

.parallax-fast {
    transform: translateY(calc(var(--scroll-y, 0) * -0.8px));
    transition: transform 0.1s ease-out;
}

/* ==================== 响应式动画控制 ==================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media (max-width: 768px) {
    /* 移动端简化动画 */
    .card-3d:hover {
        transform: none;
    }

    .parallax-slow,
    .parallax-medium,
    .parallax-fast {
        transform: none;
    }
}
