/* ============================================================
   动效层（按《提示词归纳整理》动效规范实现）
   · 4 条基础曲线：linear / ease-in(150) / ease-out(250) / ease-in-out(300)
   · 统一贝塞尔变量：--ease-in / --ease-out / --ease-move / --ease-spring
   · 页面转场 0.4s：旧页淡出上移，新页接续进入
   · 错峰 50ms、滚动渐显（仅一次）、数字滚动、按压回弹、
     磁吸按钮、点赞炸开、骨架屏、Tab 指示条滑动
   ============================================================ */
:root {
  --dur-exit: 150ms;
  --dur-enter: 250ms;
  --dur-move: 300ms;
  --dur-page: 400ms;
  --ease-in: cubic-bezier(.4, 0, 1, 1);
  --ease-out: cubic-bezier(0, 0, .2, 1);
  --ease-move: cubic-bezier(.4, 0, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease-page: cubic-bezier(.22, 1, .36, 1);
  --stagger: 50ms;
}

/* ---------- 页面转场：旧页淡出上移，新页接续 ---------- */
@keyframes pageIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
#view { transition: opacity var(--dur-exit) var(--ease-in), transform var(--dur-exit) var(--ease-in); }
#view:not(.no-anim) > * { animation: pageIn var(--dur-page) var(--ease-page) both; }

/* ---------- 进场：ease-out 250ms ---------- */
@keyframes riseIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }

/* ---------- 滚动渐显（仅一次） ---------- */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity 420ms var(--ease-out), transform 420ms var(--ease-out); }
.reveal.is-in { opacity: 1; transform: none; }
.reveal-img { filter: blur(8px); transition: filter 560ms var(--ease-out); }
.reveal-img.is-in { filter: none; }

/* ---------- 错峰列表（仅首屏进入播放，切换不重播） ---------- */
#view:not(.no-anim) .stagger > * { animation: riseIn var(--dur-enter) var(--ease-out) both; }
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 50ms; }
.stagger > *:nth-child(3) { animation-delay: 100ms; }
.stagger > *:nth-child(4) { animation-delay: 150ms; }
.stagger > *:nth-child(5) { animation-delay: 200ms; }
.stagger > *:nth-child(6) { animation-delay: 250ms; }
.stagger > *:nth-child(n + 7) { animation-delay: 300ms; }

/* ---------- 弹窗：进场 easeOutQuint 340ms，离场 easeIn 170ms ---------- */
.modal-mask { animation: fadeIn 220ms var(--ease-out) both; }
.modal-panel {
  animation: modalIn 340ms cubic-bezier(.16, 1, .3, 1) both;
  will-change: transform, opacity;
  backface-visibility: hidden;
}
.modal-mask.is-closing { animation: fadeOut 170ms var(--ease-in) both; pointer-events: none; }
.modal-mask.is-closing .modal-panel { animation: modalOut 170ms var(--ease-in) both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(15px) scale(.972); }
  60%  { opacity: 1; }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes modalOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(7px) scale(.986); }
}
/* 登录面板内部跟着面板一起「落位」，两栏错峰 60ms */
.auth-shell > * { animation: authItemIn 460ms cubic-bezier(.16, 1, .3, 1) both; }
.auth-shell > *:nth-child(2) { animation-delay: 60ms; }
@keyframes authItemIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.drawer-panel { animation: drawerIn var(--dur-move) var(--ease-out) both; }
@keyframes drawerIn { from { transform: translateX(-100%); } to { transform: none; } }
.menu { animation: menuIn 180ms var(--ease-out) both; transform-origin: 100% 0; }
@keyframes menuIn { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- 按压回弹 ---------- */
.btn, .tool-btn, .calc-key, .icon-btn, .chip, .tool-chip, .cal-seg button, .tab, .feed-tab, .nav a, .tool-tile, .menu-item, .tool-pill, .tool-back {
  transition: transform 140ms var(--ease-out), background-color 160ms ease, border-color 160ms ease,
    color 160ms ease, box-shadow 220ms var(--ease-out), opacity 160ms ease;
}
.btn:active, .tool-btn:active, .calc-key:active, .chip:active, .tool-chip:active, .cal-seg button:active { transform: scale(.97); }
.icon-btn:active { transform: scale(.9); }
.tool-tile:active { transform: scale(.99); }

/* ---------- 按钮涟漪（跟手波纹） ---------- */
.ripple-host { position: relative; overflow: hidden; }
.ripple {
  position: absolute; border-radius: 50%; pointer-events: none;
  background: currentColor; opacity: .22; transform: translate(-50%, -50%) scale(0);
  animation: rippleOut 560ms var(--ease-out) forwards;
}
@keyframes rippleOut { to { transform: translate(-50%, -50%) scale(2.6); opacity: 0; } }
.tool-btn.primary .ripple, .btn-primary .ripple { background: #fff; opacity: .3; }

/* ---------- 磁吸按钮（仅核心按钮） ---------- */
[data-magnetic] { transition: transform 220ms var(--ease-out); will-change: transform; }

/* ---------- 点赞炸开 ---------- */
@keyframes likePop { 0% { transform: scale(1); } 35% { transform: scale(1.32); } 100% { transform: scale(1); } }
@keyframes sparkFly {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(.5); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.2); }
}
.liked-pop { animation: likePop 380ms var(--ease-spring); }
.spark {
  position: absolute; left: 50%; top: 50%; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; pointer-events: none; animation: sparkFly 520ms var(--ease-out) forwards;
}

/* ---------- Tab 指示条滑动 ---------- */
.feed-tab::after, .tab::after { transition: transform 260ms var(--ease-move), opacity 200ms ease; }

/* ---------- 数字滚动 ---------- */
.tnum, .fmt-num, [data-count] { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum' 1; }

/* ---------- 骨架屏 ---------- */
@keyframes shimmer { 100% { background-position: 200% 0; } }
.sk {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 37%, var(--bg2) 63%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

/* ---------- 悬浮层级 ---------- */
.card, .tool-card, .cal-month, .thread-card, .r-card { transition: box-shadow 260ms var(--ease-out), border-color 200ms ease, transform 260ms var(--ease-out); }
.tool-tile:hover { transform: translateY(-2px); }
.post { transition: background-color 180ms ease; }

/* ---------- 焦点可见（键盘） ---------- */
:focus-visible { outline: 2px solid rgb(var(--brand) / .55); outline-offset: 2px; border-radius: 6px; }

/* ---------- 减弱动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-delay: 0ms !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
  .reveal { opacity: 1; transform: none; }
  .reveal-img { filter: none; }
}
