﻿/* ============================================================
   动效层 · 克制的运动语言
   所有动画都服务于层级与节奏，不做无意义的炫技
   ============================================================ */

/* ---------- 1. 加载 ---------- */
.loading-box {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    transition: opacity 0.6s var(--ease), visibility 0.6s var(--ease);
}

html.skip-loading .loading-box {
    display: none !important;
}

.loading-box.hide {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-core {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    width: min(320px, 72vw);
    text-align: center;
}

/* 用一条 1px 的轨道代替转圈 */
.loading-ring {
    width: 46px;
    height: 46px;
    margin-bottom: 2rem;
    border-radius: 50%;
    border: 1px solid var(--border);
    border-top-color: var(--text-primary);
    animation: lm-spin 1.1s linear infinite;
}

.loading-ring.ring2,
.loading-text::after {
    display: none;
}

.loading-text {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.42em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 1.4rem;
    animation: lm-breathe 2.4s var(--ease) infinite;
}

.loading-bar {
    width: 100%;
    height: 1px;
    background: var(--border);
    overflow: hidden;
}

.loading-bar-inner {
    width: 0;
    height: 100%;
    background: var(--text-primary);
    animation: lm-progress 1.4s var(--ease-out) forwards;
}

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

@keyframes lm-breathe {
    0%, 100% { opacity: 0.35; }
    50% { opacity: 0.9; }
}

@keyframes lm-progress {
    0% { width: 0; }
    60% { width: 72%; }
    100% { width: 100%; }
}

/* ---------- 2. 入场 ---------- */
.animate-fade-up {
    opacity: 0;
    transform: translateY(18px);
    animation: lm-fade-up 0.9s var(--ease-out) forwards;
}

@keyframes lm-fade-up {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-on-scroll {
    opacity: 0;
    transform: translateY(22px);
    transition: opacity 0.8s var(--ease-out), transform 0.8s var(--ease-out);
    will-change: opacity, transform;
}

.animate-on-scroll.visible {
    opacity: 1;
    transform: none;
}

/* 滚动到视口后逐条错开 */
.animate-on-scroll.visible {
    transition-delay: var(--reveal-delay, 0s);
}

/* 动态插入的卡片（作品 / 列表） */
.card-in {
    animation: lm-card-in 0.55s var(--ease-out) both;
    animation-delay: calc(var(--i, 0) * 45ms);
}

@keyframes lm-card-in {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* ---------- 3. 背景层 ---------- */
.bg-layer {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
    background: var(--bg-primary);
}

/* 时间气质底色：一层极淡的时间色温 */
.bg-layer::before {
    content: "";
    position: absolute;
    inset: -10%;
    background:
        radial-gradient(60% 45% at 50% -5%, var(--bg-glow), transparent 70%),
        radial-gradient(40% 30% at 95% 100%, var(--bg-glow), transparent 70%);
    opacity: 0.9;
    transition: opacity 0.8s var(--ease);
}

/* 细颗粒噪点，避免纯色带来的"塑料感" */
.bg-layer::after {
    content: "";
    position: absolute;
    inset: 0;
    opacity: 0.14;
    background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
    mix-blend-mode: overlay;
}

.bg-wallpaper,
.grid-overlay,
.glow-orb {
    display: none;
}

#particleCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.55;
}

/* 光标光斑：极简版的"跟随光" */
.cursor-glow {
    position: fixed;
    top: 0;
    left: 0;
    width: 420px;
    height: 420px;
    margin: -210px 0 0 -210px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
    background: radial-gradient(circle, var(--accent-glow), transparent 62%);
    opacity: 0;
    transition: opacity 0.6s var(--ease);
    will-change: transform;
}

.cursor-glow.on {
    opacity: 1;
}

/* ---------- 4. 滚动进度 / 回顶 ---------- */
.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 2px;
    width: 100%;
    transform: scaleX(0);
    transform-origin: left;
    background: var(--text-primary);
    z-index: 1200;
    opacity: 0.55;
    pointer-events: none;
}

.back-top {
    position: fixed;
    right: clamp(1rem, 3vw, 2.4rem);
    bottom: clamp(1rem, 3vw, 2.4rem);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--navbar-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    color: var(--text-secondary);
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 0.4s var(--ease), transform 0.5s var(--ease-out),
        border-color 0.3s, color 0.3s;
}

.back-top.show {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.back-top:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.back-top svg {
    width: 15px;
    height: 15px;
}

/* ---------- 5. 卡片 3D 倾斜 + 光斑 ---------- */
.tilt {
    transform-style: preserve-3d;
    transition: transform 0.5s var(--ease-out), border-color 0.4s var(--ease),
        background-color 0.4s var(--ease);
}

.tilt.is-tilting {
    transition: transform 0.12s linear, border-color 0.4s var(--ease);
}

/* 光斑由 JS 写入 --mx/--my */
.spotlight::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(
        240px circle at var(--mx, 50%) var(--my, 0%),
        rgba(255, 255, 255, 0.07),
        transparent 60%
    );
    opacity: 0;
    transition: opacity 0.45s var(--ease);
    pointer-events: none;
    z-index: 0;
}

.spotlight:hover::before {
    opacity: 1;
}

.spotlight > * {
    position: relative;
    z-index: 1;
}

/* ---------- 6. 磁性按钮 ---------- */
.magnetic {
    transition: transform 0.4s var(--ease-out);
    will-change: transform;
}

.magnetic.is-pulling {
    transition: transform 0.1s linear;
}

.magnetic > * {
    pointer-events: none;
}

/* ---------- 7. 打字机 ---------- */
.type-cursor {
    display: inline-block;
    width: 1px;
    height: 1em;
    margin-left: 2px;
    background: currentColor;
    vertical-align: -0.12em;
    animation: lm-blink 1.1s step-end infinite;
}

@keyframes lm-blink {
    0%, 45% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* ---------- 8. 页面切换 ---------- */
body {
    opacity: 1;
    transition: opacity 0.28s var(--ease);
}

html.page-leaving body {
    opacity: 0;
}

html.page-enter body {
    animation: lm-page-in 0.5s var(--ease-out);
}

@keyframes lm-page-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

/* ---------- 9. Toast ---------- */
.toast-stack {
    position: fixed;
    left: 50%;
    bottom: 2.2rem;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
    pointer-events: none;
}

.toast {
    max-width: min(92vw, 420px);
    padding: 0.7rem 1.15rem;
    border-radius: 999px;
    border: 1px solid var(--border-hover);
    background: var(--navbar-bg);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    color: var(--text-primary);
    font-size: 0.82rem;
    letter-spacing: 0.02em;
    box-shadow: var(--shadow);
    animation: lm-toast-in 0.4s var(--ease-out);
}

.toast.out {
    animation: lm-toast-out 0.35s var(--ease) forwards;
}

@keyframes lm-toast-in {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

@keyframes lm-toast-out {
    to { opacity: 0; transform: translateY(6px) scale(0.98); }
}

/* ---------- 10. 音乐波形 ---------- */
.music-wave {
    display: none;
    align-items: flex-end;
    gap: 2px;
    height: 12px;
}

.music-wave i {
    width: 2px;
    height: 4px;
    background: currentColor;
    border-radius: 1px;
    animation: lm-wave 0.9s var(--ease) infinite;
}

.music-wave i:nth-child(2) { animation-delay: 0.18s; }
.music-wave i:nth-child(3) { animation-delay: 0.36s; }

.music-btn.playing .music-wave { display: flex; }
.music-btn.playing .music-icon { display: none; }

@keyframes lm-wave {
    0%, 100% { height: 3px; }
    50% { height: 12px; }
}

/* ---------- 11. 主题模式图标（跟随时间 ◐ / 纯黑 ☾ / 亮色 ☀） ---------- */
.dark-btn .icon-dark,
.dark-btn .icon-light { display: none; }
.dark-btn .icon-auto { display: inline; }

html[data-mode="dark"] .dark-btn .icon-auto,
html[data-mode="light"] .dark-btn .icon-auto { display: none; }
html[data-mode="dark"] .dark-btn .icon-dark { display: inline; }
html[data-mode="light"] .dark-btn .icon-light { display: inline; }

/* ---------- 12. 滚动提示 ---------- */
.scroll-hint-line {
    width: 1px;
    height: 46px;
    background: linear-gradient(var(--border-hover), transparent);
    position: relative;
    overflow: hidden;
}

.scroll-hint-line::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 14px;
    background: var(--text-primary);
    animation: lm-scroll-line 2.4s var(--ease) infinite;
}

@keyframes lm-scroll-line {
    0% { transform: translateY(-16px); opacity: 0; }
    35% { opacity: 1; }
    100% { transform: translateY(46px); opacity: 0; }
}

/* ---------- 13. 数字 ---------- */
.stat-num {
    display: block;
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

/* ---------- 14. 尊重系统偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
    .animate-fade-up,
    .animate-on-scroll {
        opacity: 1 !important;
        transform: none !important;
        animation: none !important;
    }
    .cursor-glow,
    .scroll-progress { display: none; }
}
