/**
 * CyberGlass 动画与过渡效果
 * 霓虹脉冲、文字故障闪烁、CRT 扫描线、Pjax 页面过渡。
 */

/* ========== 霓虹脉冲呼吸 ========== */
@keyframes neonPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ========== 赛博朋克文字故障闪烁 ========== */
@keyframes glitchFlicker {
    0% { transform: translate(0); }
    2% { transform: translate(-2px, 1px); }
    4% { transform: translate(2px, -1px); }
    6% { transform: translate(0); }
    98% { transform: translate(0); }
    100% { transform: translate(-1px, 2px); }
}

.glitch-text {
    position: relative;
    animation: neonPulse 4s ease-in-out infinite;
}

/* NOTE: 故障效果伪元素——通过色彩偏移模拟 CRT 信号干扰 */
.glitch-text::before,
.glitch-text::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.glitch-text::before {
    color: var(--neon-cyan);
    z-index: -1;
    animation: glitchFlicker 3s infinite;
    clip-path: polygon(0 0, 100% 0, 100% 35%, 0 35%);
    transform: translate(-2px, -1px);
    opacity: 0.7;
}

.glitch-text::after {
    color: var(--neon-magenta);
    z-index: -2;
    animation: glitchFlicker 2.5s infinite reverse;
    clip-path: polygon(0 65%, 100% 65%, 100% 100%, 0 100%);
    transform: translate(2px, 1px);
    opacity: 0.7;
}

/* ========== CRT 扫描线 ========== */
@keyframes scanline {
    0% { transform: translateY(-100%); }
    100% { transform: translateY(100vh); }
}

/* ========== 淡入动画 ========== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

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

/* Pjax 页面进入/离开动画 */
.pjax-enter {
    animation: fadeIn 0.4s ease forwards;
}

.pjax-exit {
    animation: fadeOut 0.2s ease forwards;
}

/* ========== 卡片入场动画 ========== */
.post-card {
    opacity: 0;
    animation: fadeIn 0.5s ease forwards;
}

/* 逐张延迟入场 */
.post-card:nth-child(1) { animation-delay: 0.05s; }
.post-card:nth-child(2) { animation-delay: 0.1s; }
.post-card:nth-child(3) { animation-delay: 0.15s; }
.post-card:nth-child(4) { animation-delay: 0.2s; }
.post-card:nth-child(5) { animation-delay: 0.25s; }
.post-card:nth-child(6) { animation-delay: 0.3s; }
.post-card:nth-child(7) { animation-delay: 0.35s; }
.post-card:nth-child(8) { animation-delay: 0.4s; }
.post-card:nth-child(9) { animation-delay: 0.45s; }

/* ========== 鼠标粒子样式 ========== */
.cursor-particle {
    position: fixed;
    pointer-events: none;
    border-radius: 50%;
    z-index: var(--z-cursor);
    will-change: transform, opacity;
}

.cursor-trail {
    width: 6px;
    height: 6px;
    background: var(--neon-cyan);
    box-shadow: var(--glow-sm) var(--neon-cyan);
}

.cursor-burst {
    width: 4px;
    height: 4px;
    background: var(--neon-magenta);
    box-shadow: var(--glow-xs) var(--neon-magenta);
}

/* ========== 按钮涟漪效果 ========== */
@keyframes ripple {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

.neon-btn .ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0);
    animation: ripple 0.6s linear;
    pointer-events: none;
}

/* ========== 主题切换过渡 ========== */
html {
    transition: background-color var(--transition-slow);
}

html * {
    transition: background-color var(--transition-slow), color var(--transition-base), border-color var(--transition-base), box-shadow var(--transition-base);
}

/* NOTE: 降低过渡性能消耗——只在切换时启用全局过渡 */
html.theme-transitioning * {
    transition-duration: 0.5s !important;
}

/* ========== 减少动效偏好 ========== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .glitch-text::before,
    .glitch-text::after {
        display: none;
    }

    .cursor-particle {
        display: none;
    }
}
