/* 小书童形象动画 — 规则见 DESIGN.md §11.1
 * 5 个形象, 各自固定场景 + 固定动画; 幅度小、无弹跳/弹性曲线; prefers-reduced-motion 下全部静止。
 * 用法: <div class="mascot m-greet"><img src="images/mascot/face.png" alt="小书童"></div>
 */
.mascot {
  position: relative;
  display: inline-block;
  width: 160px;
  aspect-ratio: 1;
  flex: none;
}

.mascot > img { display: block; width: 100%; height: 100%; }
.mascot > svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* 深色底上给 G1 / G3 垫一块米白圆底 (衣服是墨绿, 直接放色带上会融掉) */
.mascot.on-dark::before {
  content: "";
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  background: var(--surface);
}
.mascot.on-dark > img { position: relative; }

/* ---------- G1 头像 · 打招呼: 眨眼 (循环) + 点头 (进入时一次) ---------- */
.m-greet > img { transform-origin: 50% 90%; animation: m-nod 0.6s ease-out 0.2s 1 both; }
.m-greet .lid { transform-box: fill-box; transform-origin: 50% 0; transform: scaleY(0); animation: m-blink 4.8s ease-in-out 1s infinite; }
.m-greet .lash { opacity: 0; animation: m-lash 4.8s ease-in-out 1s infinite; }

@keyframes m-nod {
  0% { transform: rotate(0); }
  35% { transform: rotate(-3deg) translateY(2px); }
  70% { transform: rotate(1deg); }
  100% { transform: rotate(0); }
}

@keyframes m-blink {
  0%, 90%, 100% { transform: scaleY(0); }
  93%, 95% { transform: scaleY(1); }
}

@keyframes m-lash {
  0%, 90%, 100% { opacity: 0; }
  93%, 95% { opacity: 1; }
}

/* ---------- G2 背书箱 · 行走: 手绘序列帧走路循环 (APNG, 按腿部位移分配每帧时长, 不上下跳) ---------- */
/* 用法:
 * <picture class="mascot m-walk">
 *   <source srcset="images/mascot/walk-frame1.png" media="(prefers-reduced-motion: reduce)">
 *   <img src="images/mascot/walk-anim.png" alt="">
 * </picture>
 */
picture.mascot { display: inline-block; }
.m-walk { aspect-ratio: 191 / 300; }
.m-walk > img { object-fit: contain; }
.m-walk::after {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  bottom: 0;
  height: 3%;
  border-radius: 50%;
  background: color-mix(in oklab, var(--ink) 14%, transparent);
  z-index: -1;
}

/* ---------- G3 捧书 · 空状态 / 阅读: 呼吸 (循环, 很慢) ---------- */
.m-read > img { transform-origin: 50% 100%; animation: m-breathe 4s ease-in-out infinite; }

@keyframes m-breathe {
  0%, 100% { transform: scale(1) rotate(0); }
  50% { transform: scale(1.015) rotate(-0.6deg); }
}

/* ---------- G4 朱砂印 · 确认时刻: 盖印 (一次) + 印泥晕开 ---------- */
.m-stamp > img { animation: m-press 0.3s ease-out both; }
.m-stamp::after {
  content: "";
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: m-ink 0.6s ease-out 0.22s 1 both;
}
.m-stamp.replay > img, .m-stamp.replay::after { animation: none; }

@keyframes m-press {
  0% { transform: scale(1.25) rotate(-8deg); opacity: 0; }
  70% { transform: scale(0.97) rotate(0); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes m-ink {
  0% { transform: scale(0.96); opacity: 0.5; }
  100% { transform: scale(1.18); opacity: 0; }
}

/* ---------- G5 书页 · 品牌时刻: 展卷 (一次, 从书脊向两侧) ---------- */
.m-unfold > img { animation: m-unfold 0.8s ease-out both; }
.m-unfold.replay > img { animation: none; }

@keyframes m-unfold {
  0% { clip-path: inset(0 50% 0 50%); }
  100% { clip-path: inset(0 0 0 0); }
}

/* 页面滚到才播放 (由脚本加 .in-view); 未进入视口前保持首帧 */
.play-on-view:not(.in-view) > img,
.play-on-view:not(.in-view)::after { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  .mascot > img, .mascot::after, .mascot .lid, .mascot .lash { animation: none !important; }
  .m-greet .lid, .m-greet .lash { display: none; }
}
