/* =====================================================================
   chat-motion.css — 聊天室场景动画层
   ---------------------------------------------------------------------
   设计约束（来自 chat.js / chat.html 实际实现，勿随意改动）：
   1. showTab 在 300ms 后强制 hidden=true      → 页面过渡 ≤ .30s
   2. ciShow / csShow 在 280~300ms 后 hidden=true → 面板过渡 ≤ .28s
   3. .wx-chatinfo / .wx-console 也带 .wx-page → 必须排除，否则离场
      规则会覆盖它们的 translateX(100%)
   4. .tg-sheet 用 transition 上滑 → 不能再挂 animation 抢控制权
   5. .wx-conv 等有 transition-duration:0s!important → 按下靠 transform
      ⚠ 所有入场动画必须用 backwards，绝不能用 both/forwards，
        否则动画结束后 animation 会永久压制 :active 的 transform
   6. loadConvs 每 3 秒跑一次，签名含分钟数会重建列表
      ⚠ .wx-conv 的入场动画限定在 .cm-in 窗口内，否则每分钟闪一次
   7. .wx-page 的 transform 已被 tab 平移占用
      ⚠ 3D 入场只加在子组件（.wx-top / .wx-tabbar button / 列表行），
        绝不能加在 .wx-page 或 #wxApp 上
   8. 一条 transition/animation 的同一 item 内只能有一个时间函数
      ⚠ 曲线统一走 curves.css 的 --cv-*，不要叠加 --cm-* / --ios-*
   9. ⚠ .wx-chatinfo / .wx-console 的动画由 chat-panel.css 统一管理，
      本文件不得再定义它们的 transform，否则会互相覆盖导致面板打不开
   10. .tg-back / .tg-edit 用 translateY(-50%) 做垂直居中
      ⚠ 它们的 :active 必须把位移一起写回，否则按下会跳位
   ===================================================================== */

:root {
  --cm-dur-in: .46s;
  --cm-dur-tap: .18s;
  /* 局部高斯模糊：进场时的初始模糊半径 */
  --cm-blur: 7px;
}

/* =====================================================================
   0. 首屏加载：组件逐个 3D 出现（取代原来的整体高斯模糊）
   ===================================================================== */

/* 架掉 chat.css 的 page-loading 高斯模糊与整体缩放 */
html.page-loading #wxApp,
html.page-loading .wx-tabbar {
  filter: none !important;
  opacity: 1 !important;
  transform: none !important;
}

/* 顶部导航：从上方翻下来 + 局部解模糊 */
@keyframes cm3dTop {
  from {
    opacity: 0;
    filter: blur(var(--cm-blur));
    transform: perspective(820px) translate3d(0, -18px, -60px) rotateX(-24deg) scale(.96);
  }
  to { opacity: 1; filter: blur(0); transform: none; }
}

/* 底栏按钮：从下方翻上来 + 局部解模糊 */
@keyframes cm3dTab {
  from {
    opacity: 0;
    filter: blur(var(--cm-blur));
    transform: perspective(700px) translate3d(0, 26px, -70px) rotateX(32deg) scale(.9);
  }
  to { opacity: 1; filter: blur(0); transform: none; }
}

html.cm-boot #pageChats > .wx-top,
html.cm-boot #pageContacts > .wx-top,
html.cm-boot #pageDiscover > .wx-top,
html.cm-boot #pageMe > .wx-top {
  animation: cm3dTop .58s var(--cv-enter) backwards;
}

html.cm-boot .wx-tabbar button {
  animation: cm3dTab .62s var(--cv-spring) backwards;
}
html.cm-boot .wx-tabbar button:nth-child(1) { animation-delay: .10s; }
html.cm-boot .wx-tabbar button:nth-child(2) { animation-delay: .18s; }
html.cm-boot .wx-tabbar button:nth-child(3) { animation-delay: .26s; }
html.cm-boot .wx-tabbar button:nth-child(4) { animation-delay: .34s; }

/* ---------- 1. 四个主 tab 页：左右平移 ---------- */
:is(.wx-page:not(.wx-chatinfo):not(.wx-console)) {
  transition: opacity .26s var(--cv-standard),
              transform .28s var(--cv-standard),
              visibility .30s var(--cv-standard);
  will-change: transform, opacity;
}
:is(.wx-page:not(.wx-chatinfo):not(.wx-console)).on {
  transform: translate3d(0, 0, 0) scale(1);
}
/* 离场时轻微缩小，视觉上退到后面 */
:is(.wx-page:not(.wx-chatinfo):not(.wx-console)):not(.on):not([hidden]) {
  transform: translate3d(var(--tx, 0px), 0, 0) scale(.985);
}

/* ---------- 2. 聊天房间：从被点击的会话行长出整页（一镜到底） ----------
   起点矩形由 JS 内联写入（非等比 scale + 位移），此处只留 transition 与原点。
   filter / opacity 均不参与，避免出现淡入淡出。 */
.wx-room,
html[data-style] .wx-room {
  transform: none;
  transform-origin: 0 0;
  transition: transform .52s var(--cv-standard),
              border-radius .52s var(--cv-standard),
              visibility .52s var(--cv-standard);
}
/* 动画期间：锁住重绘范围，并关掉内部 backdrop-filter。
   头部/底栏的 backdrop-filter 在 scale 动画中每帧都要重新采样背景，是掉帧主因。 */
.wx-room.room-anim {
  will-change: transform;
  contain: layout paint;
}
.wx-room.room-anim .tg-head,
.wx-room.room-anim .tg-bar,
.wx-room.room-anim .tg-menu,
.wx-room.room-anim .tg-sheet {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}

/* 头部入场：只做透明度 + 解模糊。
   ⚠ 不能加 transform —— .tg-head 内部 .tg-back/.tg-edit 用
     translateY(-50%) 绝对居中，父级 transform 会改变包含块。 */
@keyframes cmHeaderIn {
  from { opacity: 0; filter: blur(var(--cm-blur)); }
  to   { opacity: 1; filter: blur(0); }
}
@keyframes cmBarIn {
  from {
    opacity: 0;
    filter: blur(var(--cm-blur));
    transform: perspective(820px) translate3d(0, 24px, -60px) rotateX(24deg);
  }
  to { opacity: 1; filter: blur(0); transform: none; }
}
.wx-room.on .tg-head { animation: cmHeaderIn .42s var(--cv-enter) backwards; }
.wx-room.on .tg-bar  { animation: cmBarIn .48s var(--cv-enter) backwards .05s; }

/* ---------- 4. 列表行 / 控件：3D 入场 + 局部高斯模糊 ---------- */
@keyframes cmRowIn {
  from {
    opacity: 0;
    filter: blur(var(--cm-blur));
    transform: perspective(900px) translate3d(0, 15px, -45px) rotateX(20deg) scale(.972);
  }
  to { opacity: 1; filter: blur(0); transform: none; }
}

/* 静态行：随页面/面板显示播一次（内部内容不会自动重刷） */
:where(.wx-page.on, .wx-room.on) :is(
  .wx-cell, .wx-dgroup, .wx-mrow, .wx-usr-row,
  .ug-row, .ci-row, .ci-cell, .ci-card
) {
  animation: cmRowIn var(--cm-dur-in) var(--cv-enter) backwards;
}

/* 会话列表：每 3 秒会被 loadConvs 重建，只在 cm-in 窗口内播，避免周期闪烁 */
.wx-page.cm-in .wx-conv {
  animation: cmRowIn var(--cm-dur-in) var(--cv-enter) backwards;
}

/* 逐条错峰：前 11 条阶梯延迟，之后统一 */
:where(.wx-page.cm-in, .wx-room.on) :is(.wx-conv,.wx-cell,.wx-dgroup,.wx-mrow,.wx-usr-row,.ug-row,.ci-row,.ci-cell):nth-child(1)  { animation-delay: 0ms; }
:where(.wx-page.cm-in, .wx-room.on) :is(.wx-conv,.wx-cell,.wx-dgroup,.wx-mrow,.wx-usr-row,.ug-row,.ci-row,.ci-cell):nth-child(2)  { animation-delay: 30ms; }
:where(.wx-page.cm-in, .wx-room.on) :is(.wx-conv,.wx-cell,.wx-dgroup,.wx-mrow,.wx-usr-row,.ug-row,.ci-row,.ci-cell):nth-child(3)  { animation-delay: 60ms; }
:where(.wx-page.cm-in, .wx-room.on) :is(.wx-conv,.wx-cell,.wx-dgroup,.wx-mrow,.wx-usr-row,.ug-row,.ci-row,.ci-cell):nth-child(4)  { animation-delay: 90ms; }
:where(.wx-page.cm-in, .wx-room.on) :is(.wx-conv,.wx-cell,.wx-dgroup,.wx-mrow,.wx-usr-row,.ug-row,.ci-row,.ci-cell):nth-child(5)  { animation-delay: 120ms; }
:where(.wx-page.cm-in, .wx-room.on) :is(.wx-conv,.wx-cell,.wx-dgroup,.wx-mrow,.wx-usr-row,.ug-row,.ci-row,.ci-cell):nth-child(6)  { animation-delay: 150ms; }
:where(.wx-page.cm-in, .wx-room.on) :is(.wx-conv,.wx-cell,.wx-dgroup,.wx-mrow,.wx-usr-row,.ug-row,.ci-row,.ci-cell):nth-child(7)  { animation-delay: 180ms; }
:where(.wx-page.cm-in, .wx-room.on) :is(.wx-conv,.wx-cell,.wx-dgroup,.wx-mrow,.wx-usr-row,.ug-row,.ci-row,.ci-cell):nth-child(8)  { animation-delay: 210ms; }
:where(.wx-page.cm-in, .wx-room.on) :is(.wx-conv,.wx-cell,.wx-dgroup,.wx-mrow,.wx-usr-row,.ug-row,.ci-row,.ci-cell):nth-child(9)  { animation-delay: 240ms; }
:where(.wx-page.cm-in, .wx-room.on) :is(.wx-conv,.wx-cell,.wx-dgroup,.wx-mrow,.wx-usr-row,.ug-row,.ci-row,.ci-cell):nth-child(10) { animation-delay: 270ms; }
:where(.wx-page.cm-in, .wx-room.on) :is(.wx-conv,.wx-cell,.wx-dgroup,.wx-mrow,.wx-usr-row,.ug-row,.ci-row,.ci-cell):nth-child(11) { animation-delay: 300ms; }
:where(.wx-page.cm-in, .wx-room.on) :is(.wx-conv,.wx-cell,.wx-dgroup,.wx-mrow,.wx-usr-row,.ug-row,.ci-row,.ci-cell):nth-child(n+12) { animation-delay: 330ms; }

/* ---------- 5. 点按反馈 ---------- */
:is(.wx-conv, .wx-cell, .wx-dgroup, .wx-mrow, .wx-usr-row, .ug-row,
    .ci-row, .cs-row, .wx-style-opt, .wx-djoin) {
  transition: transform var(--cm-dur-tap) var(--cv-enter),
              background-color .16s var(--cv-standard);
  -webkit-tap-highlight-color: transparent;
}
:is(.wx-conv, .wx-cell, .wx-dgroup, .wx-mrow, .wx-usr-row, .ug-row,
    .ci-row, .cs-row, .wx-style-opt, .wx-djoin):active {
  transform: scale(.975);
}

/* ⚠ 全站用 translateY(-50%) 做垂直居中的绝对定位按钮只有这两个：
     .tg-back  chat.css:35  (left:2px;  top:50%)
     .tg-edit  chat.css:56  (right:2px; top:50%)
   居中依赖 transform，:active 必须把位移一起写回，
   否则按下瞬间丢掉 -50% 而向下跳 20px，表现为触摸区偏移。
   其余按钮不是靠 transform 定位，只做缩放即可。 */
:is(.wx-back, .wx-plus, .tg-imgbtn, .tg-viewer-close) {
  transition: transform var(--cm-dur-tap) var(--cv-spring),
              background-color .16s var(--cv-standard),
              opacity .16s var(--cv-standard);
  -webkit-tap-highlight-color: transparent;
}
:is(.wx-back, .wx-plus, .tg-imgbtn, .tg-viewer-close):active {
  transform: scale(.88);
}
.tg-back,
.tg-edit {
  transition: transform var(--cm-dur-tap) var(--cv-spring),
              background-color .16s var(--cv-standard),
              opacity .16s var(--cv-standard);
}
.tg-back:active,
.tg-edit:active {
  transform: translateY(-50%) scale(.88);
}

/* ---------- 6. 消息气泡：入场 + 局部解模糊 ---------- */
@keyframes cmBubbleIn {
  0%   { opacity: 0; filter: blur(5px); transform: translateY(10px) scale(.94); }
  60%  { opacity: 1; }
  100% { opacity: 1; filter: blur(0); transform: translateY(0) scale(1); }
}
.tg-msg.anim { animation: cmBubbleIn .34s var(--cv-spring) backwards; }
.tg-msg.revoking { transition: opacity .3s var(--cv-standard), transform .3s var(--cv-standard); }

/* 已读状态更新 */
@keyframes cmBumpIn {
  0%   { opacity: .3; transform: scale(.86); }
  70%  { opacity: 1; transform: scale(1.06); }
  100% { opacity: 1; transform: scale(1); }
}
.tg-reads.bump { animation: cmBumpIn .46s var(--cv-enter) backwards; }

/* 日期分隔线 */
@keyframes cmDayIn {
  from { opacity: 0; filter: blur(3px); transform: scale(.94); }
  to   { opacity: 1; filter: blur(0); transform: scale(1); }
}
.tg-day { animation: cmDayIn .36s var(--cv-enter) backwards; }

/* ---------- 7. 输入栏 ---------- */
.tg-bar { transition: transform .26s var(--cv-enter), background-color .2s var(--cv-standard); }
.tg-bar:focus-within { transform: translateY(-2px); }

/* 输入有内容时发送键弹起（含按下态，需 id 特异性压过 has-text） */
.tg-bar.has-text button#send { transform: scale(1.06); }
.tg-bar.has-text button#send:active { transform: scale(.86); }

/* ---------- 8. 遮罩 / 菜单 / toast ---------- */
.tg-mask { transition: opacity .26s var(--cv-standard); }

/* sheet 内部各块：从模糊到清晰逐个浮现 */
@keyframes cmPartIn {
  from { opacity: 0; filter: blur(4px); transform: translateY(8px); }
  to   { opacity: 1; filter: blur(0); transform: none; }
}
.tg-sheet.show > :is(h3, .tg-sheet-tip, input, .tg-sheet-actions, .tg-quick, .tg-colors, .tg-curves, .wx-style-list) {
  animation: cmPartIn .38s var(--cv-enter) backwards;
}
.tg-sheet.show > h3                                        { animation-delay: 40ms; }
.tg-sheet.show > .tg-sheet-tip                              { animation-delay: 70ms; }
.tg-sheet.show > input                                     { animation-delay: 100ms; }
.tg-sheet.show > :is(.tg-quick, .tg-colors, .tg-curves)     { animation-delay: 130ms; }
.tg-sheet.show > :is(.wx-style-list)                        { animation-delay: 130ms; }
.tg-sheet.show > .tg-sheet-actions                          { animation-delay: 160ms; }

/* 面板里的每个选项按钮：逐个解模糊浮现 */
@keyframes cmOptIn {
  from { opacity: 0; filter: blur(4px); transform: scale(.96); }
  to   { opacity: 1; filter: blur(0); transform: none; }
}
.tg-sheet.show .wx-style-opt {
  animation: cmOptIn .34s var(--cv-enter) backwards;
}
.tg-sheet.show .wx-style-opt:nth-child(1) { animation-delay: 150ms; }
.tg-sheet.show .wx-style-opt:nth-child(2) { animation-delay: 182ms; }
.tg-sheet.show .wx-style-opt:nth-child(3) { animation-delay: 214ms; }
.tg-sheet.show .wx-style-opt:nth-child(4) { animation-delay: 246ms; }
.tg-sheet.show .wx-style-opt:nth-child(n+5) { animation-delay: 278ms; }

@keyframes cmMenuIn {
  0%   { opacity: 0; filter: blur(4px); transform: scale(.86) translateY(4px); }
  60%  { opacity: 1; }
  100% { opacity: 1; filter: blur(0); transform: scale(1) translateY(0); }
}
.tg-menu { animation: cmMenuIn .24s var(--cv-spring) backwards; }

@keyframes cmToastIn {
  0%   { opacity: 0; filter: blur(4px); transform: translate(-50%, 16px) scale(.94); }
  100% { opacity: 1; filter: blur(0); transform: translate(-50%, 0) scale(1); }
}
.tg-toast.show { animation: cmToastIn .30s var(--cv-spring) backwards; }

/* ---------- 9. 图片 / 视频查看器 ---------- */
.tg-viewer { transition: opacity .30s var(--cv-standard), visibility .30s var(--cv-standard); }

@keyframes cmViewerIn {
  from { opacity: 0; filter: blur(6px); transform: scale(.92); }
  to   { opacity: 1; filter: blur(0); transform: scale(1); }
}
.tg-vviewer { animation: cmViewerIn .28s var(--cv-enter) backwards; }

/* ---------- 10. 头像 / 开关 / 骨架屏 / 角标 ---------- */
.ci-sw::after { transition: transform .26s var(--cv-spring); }

.wx-cav img, .ci-av img, .tg-av img {
  transition: opacity .30s var(--cv-standard), transform .34s var(--cv-enter);
}

@keyframes cmSkeleton {
  0%, 100% { opacity: .5; }
  50%      { opacity: .95; }
}
.wx-sk i { animation: cmSkeleton 1.25s var(--cv-both) infinite; }

@keyframes cmBadgeIn {
  0%   { opacity: 0; filter: blur(3px); transform: scale(.4); }
  60%  { opacity: 1; transform: scale(1.18); }
  100% { opacity: 1; filter: blur(0); transform: scale(1); }
}
.wx-badge { animation: cmBadgeIn .30s var(--cv-spring) backwards; }

/* ---------- 11. 无障碍：减少动态效果 ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .001ms !important;
    animation-delay: 0ms !important;
    transition-duration: .001ms !important;
    filter: none !important;
  }
  :is(.wx-page, .wx-room, .wx-chatinfo, .wx-console),
  .tg-sheet, .tg-menu, .tg-toast, .tg-vviewer, .tg-day, .wx-badge {
    animation: none !important;
  }
}
