/**
 * 灵休 · 液态玻璃 —— 动效（motion）
 *
 * 动效原则（规范第 6 节）：
 *   - 只用 transform / opacity 做动画（不触发布局），时长 0.18～0.6s。
 *   - 弹性（spring）用于“有物理感”的东西：镜片、面板、开关、按下回弹；
 *     淡入淡出用 ease（--lg-ease）。
 *   - 同一屏最多 1 个持续循环动画（骨架屏闪光除外，且只在加载中存在）。
 *   - 所有动效在“减少动态效果”系统设置下自动停用（见 material.css 末尾 + 本文件）。
 */

/* ============================================================
   页面入场：内容区的块依次升起（只作用于首屏前 10 个直接子元素）
   ============================================================ */
@keyframes lg-rise {
    from { opacity: 0; transform: translateY(20px) scale(0.985); }
    to { opacity: 1; transform: none; }
}

body.lg .content-area > :not(.lg-largetitle):not(.modal-overlay):not(script):not(style) {
    animation: lg-rise 0.62s var(--lg-ease) backwards;
    animation-delay: calc(var(--lg-i, 0) * 55ms + 30ms);
}

body.lg .content-area > :nth-child(1) { --lg-i: 0; }
body.lg .content-area > :nth-child(2) { --lg-i: 1; }
body.lg .content-area > :nth-child(3) { --lg-i: 2; }
body.lg .content-area > :nth-child(4) { --lg-i: 3; }
body.lg .content-area > :nth-child(5) { --lg-i: 4; }
body.lg .content-area > :nth-child(6) { --lg-i: 5; }
body.lg .content-area > :nth-child(7) { --lg-i: 6; }
body.lg .content-area > :nth-child(8) { --lg-i: 7; }
body.lg .content-area > :nth-child(n+9) { --lg-i: 8; }

/* 大标题自己从左侧滑入 */
@keyframes lg-title-in {
    from { opacity: 0; transform: translateX(-12px); }
    to { opacity: 1; transform: none; }
}

body.lg .lg-largetitle__text {
    animation: lg-title-in 0.6s var(--lg-ease) backwards;
}

/* 组块内的网格子项（统计卡、快捷入口）再错开一档，更有层次 */
body.lg .stats-grid > *,
body.lg .quick-actions > * {
    animation: lg-rise 0.6s var(--lg-ease) backwards;
}

body.lg .stats-grid > :nth-child(1), body.lg .quick-actions > :nth-child(1) { animation-delay: 140ms; }
body.lg .stats-grid > :nth-child(2), body.lg .quick-actions > :nth-child(2) { animation-delay: 200ms; }
body.lg .stats-grid > :nth-child(3), body.lg .quick-actions > :nth-child(3) { animation-delay: 260ms; }
body.lg .stats-grid > :nth-child(4), body.lg .quick-actions > :nth-child(4) { animation-delay: 320ms; }
body.lg .stats-grid > :nth-child(n+5) { animation-delay: 360ms; }

/* ============================================================
   按下回弹：可点的东西按下时缩小、松手弹回
   ============================================================ */
body.lg .lg-press,
body.lg a.card,
body.lg .list-item,
body.lg .lg-row {
    -webkit-tap-highlight-color: transparent;
    transition: transform var(--lg-dur-1) var(--lg-spring), background var(--lg-dur-2) var(--lg-ease);
}

body.lg .lg-press:active,
body.lg a.card:active,
body.lg a.list-item:active,
body.lg .lg-row:active {
    transform: scale(0.975);
}

/* ============================================================
   开关：旋钮按下时拉长，松手回弹（和 iOS 开关一致）
   ============================================================ */
body.lg .toggle {
    width: 52px;
    height: 32px;
    border-radius: var(--lg-r-pill);
    transition: background var(--lg-dur-2) var(--lg-ease);
}

body.lg .toggle::after {
    top: 2px;
    left: 2px;
    width: 28px;
    height: 28px;
    background: linear-gradient(180deg, #ffffff, #f1f5f4);
    box-shadow: 0 2px 6px rgba(12, 50, 36, 0.28), inset 0 -1px 0 rgba(0, 0, 0, 0.04);
    transition: transform var(--lg-dur-3) var(--lg-spring), width var(--lg-dur-1) var(--lg-ease);
}

body.lg .toggle:active::after {
    width: 34px;
}

body.lg .toggle.active::after {
    transform: translateX(20px);
}

body.lg .toggle.active:active::after {
    transform: translateX(14px);
}

/* ============================================================
   进度条：宽度变化带弹性，填充内一道流光
   ============================================================ */
body.lg .progress-fill {
    position: relative;
    overflow: hidden;
    transition: width var(--lg-dur-3) var(--lg-spring);
}

body.lg .progress-fill::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: -40%;
    width: 40%;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0));
    animation: lg-sweep 2.4s var(--lg-ease) 0.6s 1 both;
}

@keyframes lg-sweep {
    from { left: -40%; }
    to { left: 110%; }
}

/* ============================================================
   骨架屏：数据加载中的占位（给 .lg-skeleton 加宽高即可）
   ============================================================ */
.lg-skeleton {
    display: block;
    border-radius: var(--lg-r-xs);
    color: transparent !important;
    background: linear-gradient(100deg, var(--lg-fill) 30%, var(--lg-fill-2) 50%, var(--lg-fill) 70%);
    background-size: 220% 100%;
    animation: lg-shimmer 1.4s linear infinite;
    pointer-events: none;
    user-select: none;
}

@keyframes lg-shimmer {
    from { background-position: 100% 0; }
    to { background-position: -120% 0; }
}

/* ============================================================
   页面切换：支持“跨文档视图过渡”的浏览器会在页面间交叉淡入，
   悬浮导航保持不动，像原生应用一样。不支持的浏览器自动忽略。
   ============================================================ */
@view-transition {
    navigation: auto;
}

body.lg .lg-tabbar {
    view-transition-name: lg-tabbar;
}

::view-transition-old(root) {
    animation: lg-vt-out 0.16s ease both;
}

::view-transition-new(root) {
    animation: lg-vt-in 0.34s var(--lg-ease) both;
}

@keyframes lg-vt-out {
    to { opacity: 0; transform: scale(0.985); }
}

@keyframes lg-vt-in {
    from { opacity: 0; transform: translateY(10px); }
}

@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
        animation: none !important;
    }
}
