/* motion.css — 跨各界面主题共用的动效与细节修正，加载在 ui-themes.css 之后。
 * 位移一律用独立的 translate / scale / rotate 属性：Liquid 的光学层用 transform
 * 做视差倾斜，单独属性与之叠加而不是覆盖。只做一次性动画，不加常驻的全屏动画层
 * （Liquid 的滚动掉帧就是被这类层拖出来的，见 ui-themes.css 注释）。 */
:root {
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
}

/* ---------- 首屏编排：题头落下 → 两侧面板 → 中央校样依次浮起 ---------- */
@keyframes wp-drop { from { opacity: 0; translate: 0 -10px; } }
@keyframes wp-rise { from { opacity: 0; translate: 0 12px; } }
:root .app .topbar { animation: wp-drop .52s var(--ease-out) backwards; }
:root .app .panel-left .panel-col { animation: wp-rise .6s .06s var(--ease-out) backwards; }
:root .app .panel-right .panel-col { animation: wp-rise .6s .12s var(--ease-out) backwards; }
:root .app .preview-top { animation: wp-rise .5s .1s var(--ease-out) backwards; }
:root .app .pet-dock { animation: wp-rise .5s .16s var(--ease-out) backwards; }
:root .app .stage { animation: wp-rise .62s .22s var(--ease-out) backwards; }

/* 各主题原本给卡片各配一个不同名字的进场动画，导致每次换主题所有卡片都重播一遍：
   动画开始时逐张提升为合成层、结束时再合并回去，整片侧栏要重新光栅化两次。
   统一成同一个动画名，换主题时就不会重播。 */
@keyframes wp-card-enter { from { opacity: 0; translate: 0 8px; } }
:root:root .app .card { animation: none; }
:root:root .app .card.motion-enter { animation: wp-card-enter .36s var(--ease-out) backwards; }
:root:root .app .panel-col > .card:nth-child(2) { animation-delay: .04s; }
:root:root .app .panel-col > .card:nth-child(3) { animation-delay: .08s; }
:root:root .app .panel-col > .card:nth-child(4) { animation-delay: .12s; }
:root:root .app .panel-col > .card:nth-child(n+5) { animation-delay: .16s; }

/* Snapshot only for the duration of a theme change. Opacity runs on the
   compositor; gradients and glass don't repaint independently on every frame. */
html.theme-snapshot::view-transition,
html.theme-snapshot::view-transition-group(*),
html.theme-snapshot::view-transition-image-pair(*),
html.theme-snapshot::view-transition-old(*),
html.theme-snapshot::view-transition-new(*) { pointer-events: none; }
html.theme-snapshot::view-transition-group(*) {
  animation-duration: .46s;
  animation-timing-function: cubic-bezier(.22, 1, .36, 1);
}
html.theme-snapshot::view-transition-image-pair(root) { isolation: isolate; }
html.theme-snapshot::view-transition-old(root) {
  animation: wp-theme-dissolve .46s cubic-bezier(.4, 0, .2, 1) both;
  mix-blend-mode: normal;
  z-index: 2;
}
html.theme-snapshot::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
@keyframes wp-theme-dissolve { to { opacity: 0; } }
/* Keep the picker crisp and interactive above the dissolving page. Its live
   destination retains the spring-like indicator instead of double exposure. */
html.theme-snapshot #ui-theme-picker { view-transition-name: theme-picker; }
html.theme-snapshot::view-transition-old(theme-picker) { display: none; }
html.theme-snapshot::view-transition-new(theme-picker) { animation: none; }
html.theme-snapshot::view-transition-group(theme-picker) { z-index: 3; }
html.theme-snapshot .app :is(.panel-col, .card, .stage, .topbar, .pet-dock, .lib-card, .swatch, .pattern-chip) {
  transition: none !important;
}
/* Older browsers retain a bounded color fade. No animated blur or blanket
   transition:all across the thousands of elements in the word library. */
html.theme-switching :is(body, .topbar, .panel-col, .card, .stage, .pet-dock, .lib-card, .ui-theme-option) {
  transition: color .46s ease, border-color .46s ease, background-color .46s ease;
}

/* ---------- 预览换内容：旧画面虚化上飘，新画面从下方浮起 ---------- */
.stage > canvas.preview-ghost {
  position: absolute !important;
  z-index: 4 !important;
  margin: 0;
  pointer-events: none;
  box-shadow: none !important;
  animation: none;
}
.stage > canvas.preview-ghost.out { animation: wp-ghost-out .28s cubic-bezier(.4, 0, .2, 1) forwards; }
@keyframes wp-ghost-out { to { opacity: 0; translate: 0 -4px; } }
#preview-canvas.preview-swap-in { animation: wp-swap-in .34s .02s var(--ease-out) backwards; }
@keyframes wp-swap-in { from { opacity: 0; translate: 0 6px; } }

/* 「换一组」的刷新图标每次点击转一圈 */
.btn .btn-ic { display: inline-block; width: 13px; height: 13px; margin: -2px 5px -2px -1px; vertical-align: -2px; stroke-width: 2.3; }
.btn.is-spinning .btn-ic { animation: wp-spin .62s var(--ease-spring); }
@keyframes wp-spin { to { rotate: 360deg; } }

/* ---------- 词库卡片：词数并入第二行，名字独占整行；选中时弹一下 ---------- */
.lib-card { position: relative; }
.lib-card .lib-body .lib-count {
  display: inline;
  margin: 0;
  padding: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  color: var(--accent-2);
  font: inherit;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
.lib-card .lib-body .lib-count::after { content: "·"; margin: 0 3px; color: var(--sub); opacity: .55; font-weight: 400; }
.lib-card.just-picked { animation: wp-pick .26s var(--ease-out); }
.lib-card.just-picked .lib-icon { animation: wp-pick-icon .32s var(--ease-out); }
@keyframes wp-pick { from { scale: .985; } to { scale: 1; } }
@keyframes wp-pick-icon { from { translate: 0 2px; } to { translate: 0 0; } }

/* 配色 / 纹理选中后同样给一个落定的回弹 */
.pattern-chip.on { animation: wp-pick .42s var(--ease-spring); }

/* ---------- 提醒：新增滑入、勾选完成、删除收起 ---------- */
.rem-row.rem-enter { animation: wp-row-in .42s var(--ease-out) backwards; }
@keyframes wp-row-in { from { opacity: 0; translate: -10px 0; scale: .98; } }
.rem-row .rem-text { transition: color .25s ease, text-decoration-color .3s ease; }
.rem-row.rem-just-done input { animation: wp-check-pop .4s var(--ease-spring); }
.rem-row.rem-just-done .rem-text { animation: wp-done .45s ease-out; }
@keyframes wp-check-pop { 0% { scale: .7; } 60% { scale: 1.25; } 100% { scale: 1; } }
@keyframes wp-done { from { text-decoration-color: transparent; translate: 3px 0; } }
.rem-row.rem-leave { overflow: hidden; pointer-events: none; animation: wp-row-out .22s ease-in forwards; }
@keyframes wp-row-out { to { opacity: 0; translate: 16px 0; height: 0; padding-top: 0; padding-bottom: 0; } }

/* ---------- 折叠卡片：展开时内容向下舒展 ---------- */
details.card[open] > .card-body { animation: wp-unfold .34s var(--ease-out); }
@keyframes wp-unfold { from { opacity: 0; translate: 0 -6px; } }

/* ---------- 弹窗：卡片里的各区块错落浮入 ---------- */
.modal-overlay:not([hidden]) .modal-card > * { animation: wp-rise .42s var(--ease-out) backwards; }
.modal-overlay:not([hidden]) .modal-card > :nth-child(2) { animation-delay: .04s; }
.modal-overlay:not([hidden]) .modal-card > :nth-child(3) { animation-delay: .08s; }
.modal-overlay:not([hidden]) .modal-card > :nth-child(4) { animation-delay: .11s; }
.modal-overlay:not([hidden]) .modal-card > :nth-child(5) { animation-delay: .14s; }
.modal-overlay:not([hidden]) .modal-card > :nth-child(n+6) { animation-delay: .17s; }

/* 记忆本是长列表阅读区：双层 backdrop + 3D 玻璃高光会在滚动时反复重采样。
 * 使用不透明纸面、静止遮罩，只让列表滚动；词卡不再逐张淡入或在 700ms 后重播。
 * ID 选择器也覆盖 Liquid 的窄屏模糊规则，作答后的单卡反馈仍保留。 */
html:has(#memory-modal:not([hidden])) { overflow: hidden; scrollbar-gutter: stable; }
#memory-modal { animation: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
#memory-modal .memory-card {
  display: flex;
  flex-direction: column;
  max-height: min(88vh, calc(100dvh - 40px));
  overflow: hidden;
  background: var(--memory-paper, var(--paper));
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  transform: none;
  will-change: auto;
  animation: none;
}
:root[data-ui-theme="liquid"] #memory-modal { --memory-paper: #f7f7fa; }
:root[data-ui-theme="darkliquid"] #memory-modal { --memory-paper: #161b26; }
#memory-modal .memory-card::before, #memory-modal .memory-card::after { display: none; }
#memory-modal .memory-card > * { flex-shrink: 0; animation: none; }
#memory-modal .memory-notebook-list { flex-shrink: 1; min-height: 0; overscroll-behavior: contain; isolation: isolate; }
#memory-modal .memory-entry.due:hover { transform: none; }
@media (forced-colors: active) {
  #memory-modal .memory-card { background: Canvas; }
}

/* ---------- 同步状态：前置小圆点，保存中呼吸，保存完落定 ---------- */
.sync-status { display: inline-flex; align-items: center; gap: 5px; }
.sync-status::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: currentColor;
}
.sync-status[data-state="saving"]::before { animation: wp-pulse 1s ease-in-out infinite; }
.sync-status[data-state="saved"]::before { animation: wp-settle .5s var(--ease-spring); }
@keyframes wp-pulse { 50% { opacity: .3; scale: .65; } }
@keyframes wp-settle { 0% { scale: .3; } 60% { scale: 1.45; } 100% { scale: 1; } }

/* ---------- 桌面小词灵条 ---------- */
.pet-pages { transform-origin: center; transition: transform .25s var(--ease-out); }
@media (hover: hover) {
  .pet-dock:hover .pet-pages { transform: translateY(-1px); }
}
.pet-dock[data-state="checking"] .pet-orbit-point { animation: wp-pulse 1.4s ease-in-out infinite; }
.pet-dock[data-state="active"] .pet-orbit-point { animation: wp-settle .4s var(--ease-out); }
/* 状态文案允许折成两行，不再被省略号吃掉一半 */
.pet-dock-copy span {
  display: -webkit-box;
  white-space: normal;
  line-height: 1.38;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
/* 「换词特效 / 同步壁纸」的浅色字原本是给深色小词灵条用的；
   Liquid 与校样的小词灵条是浅底，需要换回正文色才看得见 */
:root:is([data-ui-theme="liquid"], [data-ui-theme="darkliquid"], [data-ui-theme="editorial"]) :is(.pet-dock-fx, .pet-dock-sync) { color: var(--sub); }
:root:is([data-ui-theme="liquid"], [data-ui-theme="editorial"]) .pet-dock-fx select {
  color: var(--ink);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, .72);
}
:root:is([data-ui-theme="liquid"], [data-ui-theme="darkliquid"], [data-ui-theme="editorial"]) .pet-dock-sync input { accent-color: var(--accent-2); }
/* 校样主题的 DESK ASSISTANT 角标会压在按钮上 */
:root[data-ui-theme="editorial"] .pet-dock::before { display: none; }

/* ---------- 壁纸配色色块：名字压一层暗底，浅色色块上也读得出来 ---------- */
.swatch span {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(20, 20, 24, .34);
  text-shadow: none;
}
.swatch { transition: transform .2s var(--ease-spring), border-color .15s ease, opacity .2s ease, filter .2s ease; }
:root:is([data-ui-theme="liquid"], [data-ui-theme="darkliquid"]) .swatch:not(.on) { opacity: .9; filter: saturate(.78); }
:root:is([data-ui-theme="liquid"], [data-ui-theme="darkliquid"]) .swatch:not(.on):hover { opacity: 1; filter: none; transform: translateY(-2px); }
:root:is([data-ui-theme="liquid"], [data-ui-theme="darkliquid"]) .swatch.on { animation: wp-pick .42s var(--ease-spring); }

/* ---------- Liquid 展示板：极淡的点阵，让中央区读起来像一块画板 ---------- */
:root[data-ui-theme="darkliquid"] .stage {
  background:
    radial-gradient(220px circle at var(--glass-x, 24%) var(--glass-y, 8%), rgba(90, 115, 175, .2), transparent 74%),
    radial-gradient(circle, rgba(160, 185, 235, .1) 1px, transparent 1.5px) 0 0 / 18px 18px,
    linear-gradient(150deg, rgba(30, 38, 58, .7), rgba(16, 21, 34, .62));
}
:root[data-ui-theme="liquid"] .stage {
  background:
    radial-gradient(220px circle at var(--glass-x, 24%) var(--glass-y, 8%), rgba(255, 255, 255, .54), transparent 74%),
    radial-gradient(circle, rgba(60, 60, 67, .12) 1px, transparent 1.5px) 0 0 / 18px 18px,
    linear-gradient(150deg, rgba(255, 255, 255, .34), rgba(230, 230, 230, .22));
}
@media (prefers-reduced-transparency: reduce) {
  :root[data-ui-theme="liquid"] .stage { background: rgba(250, 250, 252, .97); }
  :root[data-ui-theme="darkliquid"] .stage { background: rgba(22, 27, 40, .97); }
}
@media (prefers-contrast: more) {
  :root[data-ui-theme="liquid"] .stage { background: rgba(255, 255, 255, .97); }
  :root[data-ui-theme="darkliquid"] .stage { background: rgba(10, 13, 20, .97); }
}
@media (forced-colors: active) {
  :root[data-ui-theme="liquid"] .stage,
  :root[data-ui-theme="darkliquid"] .stage { background: Canvas; }
}

/* 词书浏览一次有几千条：屏幕外的词条跳过布局与绘制 */
.library-word { content-visibility: auto; contain-intrinsic-size: auto 58px; }

/* 手动添加单词：「释义」原本落单占半行 */
.nw-grid #nw-meaning { grid-column: 1 / -1; }

/* Motion preferences also cover transforms triggered by hover and JS state. */
@media (prefers-reduced-motion: reduce) {
  html.theme-switching .app, html.theme-switching .app *, html.theme-switching body { transition: none !important; }
  html.theme-snapshot::view-transition-group(*),
  html.theme-snapshot::view-transition-old(*),
  html.theme-snapshot::view-transition-new(*) { animation-duration: .01ms !important; }
  :root:root .app .card.motion-enter { animation: none; }
  .pet-pages { transition: none; transform: none !important; }
  .pet-orbit-point { animation: none !important; }
  :root .ui-theme-picker.theme-pill-ready::before { transition: none !important; }
}
@media print {
  :root:root .app * { animation: none !important; opacity: 1; }
}

/* ---------- 弹窗退场：打开有浮起，关闭也要有落回，才不会"啪一下消失" ---------- */
/* JS 在 hidden 前加 .modal-closing；动画结束再真正隐藏。只动透明度与位移，合成器友好。 */
.modal-overlay.modal-closing { animation: wp-overlay-out .19s ease-in forwards; }
.modal-overlay.modal-closing .modal-card {
  animation: wp-card-out .19s cubic-bezier(.4, 0, .2, 1) forwards;
}
@keyframes wp-overlay-out { to { opacity: 0; } }
@keyframes wp-card-out { to { opacity: 0; translate: 0 10px; scale: .97; } }

/* ---------- 实时模式：全屏壁纸淡入合拢 / 退出舒展 ---------- */
#live-canvas { animation: wp-live-in .42s var(--ease-out) backwards; }
@keyframes wp-live-in { from { opacity: 0; scale: .988; } }
.live-overlay.live-exiting { animation: wp-overlay-out .26s ease-in forwards; }
.live-overlay.live-exiting #live-canvas { animation: none; }
