/* pixel-anim.css —— 像素动画库
   纪律：只动画 transform / opacity / background-position；
   全部装饰动画包裹在 prefers-reduced-motion: no-preference 内 */

/* ═══ CRT 开机动画：黑屏 → 白线 → 展开 → 熄灭 ═══ */
#crt-boot {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--px-ink);
  display: flex; align-items: center; justify-content: center;
  pointer-events: all;
}
#crt-boot .crt-line {
  width: 0; height: 3px;
  background: var(--px-teal);
  box-shadow: 0 0 0 0 transparent;
  animation: crt-expand 1.15s steps(12, end) forwards;
}
#crt-boot .crt-logo {
  position: absolute;
  font-size: var(--px-fs-title);
  color: var(--px-teal);
  text-shadow: 3px 3px 0 var(--px-ink);
  opacity: 0;
  animation: crt-logo-in .4s steps(4, end) .75s forwards;
}
#crt-boot.done { animation: crt-fade .3s steps(3, end) forwards; pointer-events: none; }
@keyframes crt-expand {
  0%   { width: 0;    opacity: 0; transform: scaleY(40); }
  35%  { width: 92vw; opacity: 1; transform: scaleY(40); }
  60%  { width: 92vw; opacity: 1; transform: scaleY(1); }
  100% { width: 92vw; opacity: 1; transform: scaleY(1); }
}
@keyframes crt-logo-in { to { opacity: 1; } }
@keyframes crt-fade { to { opacity: 0; visibility: hidden; } }

/* ═══ 吉祥物「算算」idle 循环（4 帧精灵表） ═══ */
.px-mascot {
  width: 96px; height: 96px;                 /* 16px × 6 倍 */
  background-image: url('../assets/sprites/mascot-idle.svg');
  background-size: 384px 96px;               /* 4 帧 × 96px */
  background-repeat: no-repeat;
  image-rendering: pixelated;
  animation: mascot-idle 1.2s steps(4, end) infinite;
}
@keyframes mascot-idle {
  from { background-position: 0 0; }
  to   { background-position: -384px 0; }
}
/* 64px 帧（4×64=256）专用位移：steps(4) 落点 0/-64/-128/-192 全部对齐帧边界 */
.ch-mascot { animation-name: mascot-idle-64; }
@keyframes mascot-idle-64 {
  from { background-position: 0 0; }
  to   { background-position: -256px 0; }
}

/* ═══ 悬浮弹跳（卡片/按钮装饰） ═══ */
.px-bounce { animation: px-bounce 1.6s steps(2, end) infinite; }
@keyframes px-bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

/* ═══ 打字机（由 JS 逐字填充，光标闪烁纯 CSS） ═══ */
.px-typewriter::after {
  content: '▌';
  margin-left: 4px;
  color: var(--px-accent);
  animation: caret-blink .7s steps(1, end) infinite;
}
@keyframes caret-blink { 50% { opacity: 0; } }

/* ═══ 卡片依次入场（纯位移动画：不碰 opacity，后台节流冻结时卡片仍可见） ═══ */
.px-enter { animation: px-enter .25s steps(4, end) backwards; }
.px-enter:nth-child(2) { animation-delay: .12s; }
.px-enter:nth-child(3) { animation-delay: .24s; }
.px-enter:nth-child(4) { animation-delay: .36s; }
.px-enter:nth-child(5) { animation-delay: .48s; }
.px-enter:nth-child(6) { animation-delay: .6s; }
@keyframes px-enter { from { transform: translateY(16px); } }

/* ═══ 得分跳动（数字滚动时用） ═══ */
.px-pop { animation: px-pop .3s steps(3, end); }
@keyframes px-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

/* ═══ 答错抖动 ═══ */
.px-shake { animation: px-shake .35s steps(6, end); }
@keyframes px-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

/* ═══ 像素星尘（结算/答对时 JS 动态插入 .px-spark 元素） ═══ */
.px-spark {
  position: absolute;
  width: 8px; height: 8px;
  background: var(--px-yellow);
  box-shadow: 2px 2px 0 var(--px-ink);
  animation: spark-fly .7s steps(7, end) forwards;
  pointer-events: none;
}
@keyframes spark-fly {
  to { transform: translate(var(--dx, 0), var(--dy, -40px)) rotate(90deg); opacity: 0; }
}

/* ═══ 减少动态：全部装饰动画静止，保留透明度淡入 ═══ */
@media (prefers-reduced-motion: reduce) {
  #crt-boot .crt-line, #crt-boot .crt-logo { animation-duration: .01s; animation-delay: 0s; }
  .px-mascot { animation: none; background-position: 0 0; }
  .px-bounce, .px-enter, .px-pop, .px-shake, .px-spark { animation: none; }
  .px-enter { opacity: 1; transform: none; }
}
