/**
 * Swup 页面过渡动画样式
 * 17NAS.com - 丝滑的页面切换体验
 */

/* ========================================
   1. 基础过渡动画 - 淡入淡出
   ======================================== */

/* 页面切换时的过渡效果 */
.transition-fade {
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 1;
}

/* 页面淡出 */
html.is-animating .transition-fade {
    opacity: 0;
}

/* 页面切换中的状态 */
body.is-changing {
    cursor: wait;
    pointer-events: none;
}

/* ========================================
   2. 滑动过渡动画（可选）
   ======================================== */

.transition-slide {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateX(0);
    opacity: 1;
}

/* 页面向左滑出 */
html.is-animating .transition-slide {
    transform: translateX(-30px);
    opacity: 0;
}

/* ========================================
   3. 缩放过渡动画（可选）
   ======================================== */

.transition-scale {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform: scale(1);
    opacity: 1;
}

/* 页面缩小淡出 */
html.is-animating .transition-scale {
    transform: scale(0.95);
    opacity: 0;
}

/* ========================================
   4. 加载指示器
   ======================================== */

/* 页面切换时的加载指示器 */
body.is-changing::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    z-index: 9999;
    animation: loading-bar 1s ease-in-out infinite;
}

@keyframes loading-bar {
    0% {
        width: 0;
        left: 0;
    }
    50% {
        width: 50%;
        left: 25%;
    }
    100% {
        width: 0;
        left: 100%;
    }
}

/* ========================================
   5. 页面切换时的遮罩效果（可选）
   ======================================== */

/* 页面切换遮罩 */
body.is-changing::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(2px);
    z-index: 9998;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

body.is-changing::after {
    opacity: 1;
}

/* ========================================
   6. 导航栏在页面切换时保持固定
   ======================================== */

/* 确保导航栏不参与过渡动画 */
.top-navbar,
#mobileNav {
    position: fixed !important;
    z-index: 1000 !important;
}

/* ========================================
   7. 页脚在页面切换时的处理
   ======================================== */

/* 页脚不参与过渡动画 */
.site-footer {
    opacity: 1 !important;
    transform: none !important;
}

/* ========================================
   8. 特殊页面的过渡效果
   ======================================== */

/* 工具页面 - 从下方滑入 */
.page-tools .transition-fade {
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

html.is-animating .page-tools .transition-fade {
    transform: translateY(20px);
    opacity: 0;
}

/* 文章页面 - 淡入 + 轻微缩放 */
.page-article .transition-fade {
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

html.is-animating .page-article .transition-fade {
    transform: scale(0.98);
    opacity: 0;
}

/* ========================================
   9. 移动端优化
   ======================================== */

@media (max-width: 768px) {
    /* 移动端使用更快的过渡 */
    .transition-fade {
        transition-duration: 0.2s;
    }

    /* 移动端禁用复杂动画 */
    .transition-slide,
    .transition-scale {
        transition: opacity 0.2s ease;
        transform: none !important;
    }

    /* 移动端加载指示器更细 */
    body.is-changing::before {
        height: 2px;
    }

    /* 移动端不显示遮罩 */
    body.is-changing::after {
        display: none;
    }
}

/* ========================================
   10. 性能优化
   ======================================== */

/* 使用 GPU 加速 */
.transition-fade,
.transition-slide,
.transition-scale {
    will-change: transform, opacity;
    backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
}

/* 页面切换完成后移除 will-change */
html:not(.is-animating) .transition-fade,
html:not(.is-animating) .transition-slide,
html:not(.is-animating) .transition-scale {
    will-change: auto;
}

/* ========================================
   11. 降级方案 - 不支持 Swup 时
   ======================================== */

/* 如果 JavaScript 被禁用或 Swup 加载失败 */
.no-js .transition-fade,
.no-swup .transition-fade {
    opacity: 1 !important;
    transform: none !important;
}

/* ========================================
   12. 调试模式（开发时使用）
   ======================================== */

/* 添加 .debug-swup 类到 body 可以看到过渡边界 */
.debug-swup #swup {
    outline: 2px dashed #667eea;
    outline-offset: -2px;
}

.debug-swup .transition-fade {
    background: rgba(102, 126, 234, 0.05);
}

/* ========================================
   13. 预加载提示
   ======================================== */

/* 鼠标悬停在链接上时的预加载提示 */
a[href]:hover {
    cursor: pointer;
}

/* 正在预加载的链接 */
a[data-swup-preload] {
    position: relative;
}

a[data-swup-preload]::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
}

a[data-swup-preload]:hover::after {
    width: 100%;
}

/* ========================================
   14. 页面切换方向动画（高级）
   ======================================== */

/* 向前导航（点击链接） */
html.is-animating.to-next .transition-fade {
    animation: slideOutLeft 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 向后导航（浏览器后退） */
html.is-animating.to-prev .transition-fade {
    animation: slideOutRight 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

/* ========================================
   15. 平滑滚动
   ======================================== */

/* Swup 滚动插件的平滑滚动 */
html {
    scroll-behavior: smooth;
}

/* 页面切换时禁用滚动 */
html.is-animating {
    overflow: hidden;
}
