/* ==========================================================================
   摇出好运 · 卖家幸运签 — v3 3D IP 动效样式（css/fx3d.css）
   --------------------------------------------------------------------------
   · 由 game-dev 维护；在 css/app.css 之后加载，只负责 IP/3D 动效，不动页面骨架
   · 本文件独占的节点：#ipStage .ip-halo #ipOrbit #ipFigure #welcomeMascot
     #ipBlink #ipCheer .ip-floor #drawMascot #resultIp .ip-prop
     以及 .result-card 的 3D 倾斜 / 高光
   · JS 只写状态与 CSS 变量：--fx-rx/--fx-ry/--fx-tx/--fx-ty/--fx-mx/--fx-my
     --fx-card-rx/--fx-card-ry、data-tilt、is-shine / is-cheer / is-blink / is-tilting
   · 全部使用品牌变量（蓝 + 金），变量缺失时用同族 fallback，不写死粉色
   · 所有动效遵守 prefers-reduced-motion；不阻塞抽签主流程
   ========================================================================== */

:root {
  --fx-blue: var(--c-brand-blue, #2F6BFF);
  --fx-blue-deep: var(--c-brand-blue-deep, #1B45C9);
  --fx-blue-soft: var(--c-brand-blue-soft, #E6EEFF);
  --fx-gold: var(--c-brand-gold, #FFC94D);
  --fx-gold-soft: var(--c-brand-gold-soft, #FFF3D1);
  --fx-ip-shadow: rgba(27, 69, 201, .18);
  --fx-ip-shadow-deep: rgba(27, 69, 201, .30);
  --fx-ip-halo: rgba(255, 201, 77, .46);
  --fx-ip-halo-blue: rgba(230, 92, 76, .15);  /* 暖红底光（背景改喜庆色后由蓝光改为红光） */
  --fx-ink: var(--c-ink, #24314C);
}

/* 视差变量默认值（JS 会实时覆盖） */
#app {
  --fx-rx: 0;
  --fx-ry: 0;
  --fx-tx: 0px;
  --fx-ty: 0px;
  --fx-mx: 0;
  --fx-my: 0;
}

/* ==========================================================================
   一、欢迎页 IP 舞台（#ipStage / #ipFigure / 眨眼 / 欢呼 / 地面阴影 / 光晕）
   ========================================================================== */

#ipStage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-height: clamp(226px, 43vh, 360px);
  margin: 2px 0;
  perspective: 900px;
  perspective-origin: 50% 42%;
}

/* 背后光晕：金色主光 + 蓝色环境光，缓慢呼吸 */
.ip-halo {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(88vw, 360px);
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -54%);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 46%, var(--fx-ip-halo) 0%, rgba(255, 201, 77, .18) 42%, transparent 68%),
    radial-gradient(circle at 50% 56%, var(--fx-ip-halo-blue) 0%, transparent 66%);
  filter: blur(2px);
  opacity: .9;
  pointer-events: none;
  z-index: 0;
  animation: fxHaloBreath 4.6s ease-in-out infinite;
}
@keyframes fxHaloBreath {
  0%, 100% { transform: translate(-50%, -54%) scale(1); opacity: .82; }
  50%      { transform: translate(-50%, -55%) scale(1.08); opacity: 1; }
}

/* 3D 角色层：rotateX/rotateY ±7° + 微位移，由 JS 变量驱动 */
#ipFigure {
  position: relative;
  z-index: 2;
  width: clamp(212px, 66vw, 300px);
  height: clamp(228px, 47vh, 330px);
  transform:
    perspective(900px)
    rotateX(calc(var(--fx-rx, 0) * 1deg))
    rotateY(calc(var(--fx-ry, 0) * 1deg))
    translate3d(var(--fx-tx, 0px), var(--fx-ty, 0px), 0);
  transform-style: preserve-3d;
  will-change: transform;
  transition: transform .18s linear;
}
#ipFigure img {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  transform: translateX(-50%);
  transform-origin: 50% 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  animation: fxIpIdle 3.8s ease-in-out infinite;
  filter: drop-shadow(0 14px 16px var(--fx-ip-shadow));
}

/* idle / 眨眼帧 / 欢呼帧 叠放：硬切不渐变。
   渐变（transition opacity）会让 hero 与 blink 两层在同一瞬间各为半透明，
   叠加后角色整体变淡再恢复 = 肉眼可见的"闪一下"；硬切只改变单层透明度，无闪烁。 */
.ip-figure .ip-blink,
.ip-figure .ip-cheer { opacity: 0; transition: none; }

/* 眨眼：blink 帧与 idle 帧同源同位置同相位浮动，直接叠加覆盖，无需隐藏 idle 帧 */
#ipFigure.is-blink .ip-blink { opacity: 1; }

#ipFigure.is-cheer .ip-hero,
#ipFigure.is-cheer .ip-blink { opacity: 0; }
#ipFigure.is-cheer .ip-cheer {
  opacity: 1;
  animation: fxIpCheerPop .62s cubic-bezier(.24, 1.32, .38, 1) 2 both;
}

/* 兴奋抖动（抽签中） */
#ipFigure.is-excited img {
  animation: fxIpExcited .28s ease-in-out infinite;
}

@keyframes fxIpIdle {
  0%, 100% { transform: translateX(-50%) translateY(0) scale(1) rotate(0deg); }
  50%      { transform: translateX(-50%) translateY(-9px) scale(1.018) rotate(-.8deg); }
}
@keyframes fxIpCheerPop {
  0%   { transform: translateX(-50%) translateY(0) scale(1); }
  35%  { transform: translateX(-50%) translateY(-26px) scale(1.06) rotate(-3deg); }
  62%  { transform: translateX(-50%) translateY(-2px) scale(.99); }
  100% { transform: translateX(-50%) translateY(0) scale(1); }
}
@keyframes fxIpExcited {
  0%, 100% { transform: translateX(-50%) translateY(0) rotate(-2deg); }
  50%      { transform: translateX(-50%) translateY(-4px) rotate(2deg); }
}

/* 地面阴影：随浮动高度缩放/变淡（与 fxIpIdle 同周期） */
#ipStage .ip-floor {
  position: absolute;
  left: 50%;
  bottom: max(8px, 4%);
  width: min(64vw, 246px);
  height: 26px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 50%, var(--fx-ip-shadow-deep) 0%, rgba(27, 69, 201, .08) 58%, transparent 74%);
  filter: blur(4px);
  pointer-events: none;
  z-index: 1;
  animation: fxFloorShadow 3.8s ease-in-out infinite;
}
@keyframes fxFloorShadow {
  0%, 100% { transform: translateX(-50%) scale(1); opacity: .9; }
  50%      { transform: translateX(-50%) scale(.86); opacity: .55; }
}

/* 漂浮道具层（多层视差：内层 img 用 --depth 放大位移差） */
#ipOrbit {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  overflow: visible;
}
.ip-prop {
  position: absolute;
  display: block;
  width: var(--size, 40px);
  animation: fxPropFloat 5.2s ease-in-out infinite;
}
.ip-prop--1 { left: 2%;  top: 18%; --size: 36px; animation-delay: -1.2s; }
.ip-prop--2 { right: 1%; top: 9%;  --size: 32px; animation-delay: -2.6s; }
.ip-prop--3 { left: 5%;  bottom: 16%; --size: 40px; animation-delay: -3.4s; }
.ip-prop--4 { right: 4%; bottom: 10%; --size: 30px; animation-delay: -.6s; }

.ip-prop-img {
  display: block;
  width: 100%;
  height: auto;
  transform:
    translate3d(
      calc(var(--fx-mx, 0) * var(--depth, 20px)),
      calc(var(--fx-my, 0) * var(--depth, 20px)),
      0
    )
    rotate(calc(var(--fx-mx, 0) * 8deg));
  transition: transform .2s linear;
  filter: drop-shadow(0 6px 8px var(--fx-ip-shadow));
  user-select: none;
  -webkit-user-drag: none;
}
.ip-prop-emoji {
  display: block;
  font-size: calc(var(--size, 40px) * .82);
  line-height: 1.1;
  filter: drop-shadow(0 4px 6px var(--fx-ip-shadow));
}

@keyframes fxPropFloat {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50%      { transform: translateY(-12px) rotate(4deg); }
}

/* ==========================================================================
   二、抽签页（#drawMascot 探身 + 签筒光晕脉冲 + 兴奋抖动）
   ========================================================================== */

.tube-stage { perspective: 820px; }

/* 签筒列抬高一层，确保盖住身后的吉祥物（探身效果：只露出探头/爪子） */
.tube-col { z-index: 1; }

/* 吉祥物躲在签筒右后方探身看（peek 素材构图 = 小龙从图片左侧探出，左缘自带遮挡边）。
   以签筒中心为锚点（签筒也是水平居中）：只让图片最左的遮挡边(~18px)被筒身盖住，
   脸（图片 20%~55% 区域）完整露在签筒右侧 —— 避免窄屏上签筒过宽把脸遮住 */
.draw-ip {
  position: absolute;
  left: 50%;
  right: auto;
  margin-left: calc(min(27.5vw, 124px) - 18px);
  bottom: 32%;
  z-index: 0;
  width: clamp(96px, 23vw, 130px);
  height: auto;
  transform-origin: 78% 92%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 10px 14px var(--fx-ip-shadow));
  animation: fxPeek 3.6s ease-in-out infinite;
}
@keyframes fxPeek {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(-2deg) scale(1); }
  45%      { transform: translate3d(2px, -9px, 0) rotate(2deg) scale(1.02); }
  70%      { transform: translate3d(0, -3px, 0) rotate(-1deg) scale(1); }
}

/* 抽签中：小龙兴奋抖动 + 签筒周围光晕脉冲 */
.screen--draw.is-drawing .draw-ip {
  animation: fxPeekExcited .26s ease-in-out infinite;
}
.tube-ring.is-pulse {
  border-color: rgba(255, 201, 77, .92);
  animation: fxRingPulse 1.5s ease-in-out infinite;
  box-shadow: 0 0 46px 8px rgba(255, 201, 77, .28), inset 0 0 30px rgba(47, 107, 255, .12);
}
@keyframes fxPeekExcited {
  0%, 100% { transform: translate3d(0, -2px, 0) rotate(-3deg) scale(1.02); }
  50%      { transform: translate3d(3px, -8px, 0) rotate(3deg) scale(1.05); }
}
@keyframes fxRingPulse {
  0%, 100% { transform: rotate(0deg) scale(1); opacity: .9; }
  50%      { transform: rotate(180deg) scale(1.07); opacity: 1; }
}

/* 签筒 3D 摇晃（覆盖 app.css：从"摇头"改为"绕瓶底 3D 摆动"） */
.tube-wrap.is-shaking {
  animation: fxTubeShake .62s cubic-bezier(.36, .07, .19, .97) infinite;
  transform-style: preserve-3d;
}
@keyframes fxTubeShake {
  0%   { transform: perspective(760px) rotateX(0deg) rotateZ(0deg) translateY(0); }
  14%  { transform: perspective(760px) rotateX(5deg) rotateZ(-7deg) translateY(-7px); }
  30%  { transform: perspective(760px) rotateX(-4deg) rotateZ(6deg) translateY(-1px); }
  46%  { transform: perspective(760px) rotateX(4deg) rotateZ(-5deg) translateY(-6px); }
  62%  { transform: perspective(760px) rotateX(-3deg) rotateZ(4deg) translateY(-1px); }
  78%  { transform: perspective(760px) rotateX(2deg) rotateZ(-2.5deg) translateY(-3px); }
  100% { transform: perspective(760px) rotateX(0deg) rotateZ(0deg) translateY(0); }
}
/* 签筒：正式版已改为更矮胖的 618×900（≈1:1.46），按宽度收敛并限高，避免压迫感 */
#tubeImg {
  width: clamp(186px, 54vw, 250px);
  height: auto;
  max-height: 52vh;
  max-width: 56vw;
  object-fit: contain;
  margin: 12px 0;
}
.tube-stage { padding: 10px 0; }

/* ==========================================================================
   三、结果页（#resultIp 欢呼跳跃 + 卡片 3D 倾斜 / 高光扫过）
   ========================================================================== */

.result-stage { position: relative; perspective: 1200px; padding-top: 16px; }

.result-ip {
  position: absolute;
  left: auto;
  right: 3%;
  top: 4.5%;
  bottom: auto;
  z-index: 1;
  width: clamp(80px, 21vw, 88px);
  height: auto;
  transform: rotate(-4deg);
  transform-origin: 50% 92%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  opacity: .98;
  filter: drop-shadow(0 12px 16px var(--fx-ip-shadow));
  animation: fxResultIdle 3.4s ease-in-out infinite;
}
@keyframes fxResultIdle {
  0%, 100% { transform: translateY(0) rotate(-4deg) scale(1); }
  50%      { transform: translateY(-6px) rotate(-2deg) scale(1.012); }
}
.result-ip.is-cheer {
  animation: fxCheerJump 1.05s cubic-bezier(.22, 1.36, .36, 1) both;
}
@keyframes fxCheerJump {
  0%   { transform: translateY(0) rotate(-4deg) scale(1); opacity: .9; }
  22%  { transform: translateY(-12px) rotate(1deg) scale(1.04); opacity: 1; }
  48%  { transform: translateY(0) rotate(-5deg) scale(.99); }
  64%  { transform: translateY(-6px) rotate(-1deg) scale(1.02); }
  82%  { transform: translateY(0) rotate(-4deg) scale(1.01); }
  100% { transform: translateY(0) rotate(-4deg) scale(1); }
}

/* 欢呼时的一圈金色光爆 */
.result-stage.is-cheering::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 6%;
  width: min(78vw, 340px);
  height: 168px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 100%, rgba(255, 105, 75, .24) 0%, rgba(255, 160, 90, .10) 46%, transparent 70%);
  pointer-events: none;
  z-index: 0;
  animation: fxCheerGlow 1.3s ease-out both;
}
@keyframes fxCheerGlow {
  0%   { opacity: 0; transform: translateX(-50%) scale(.6); }
  35%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) scale(1.15); }
}

/* 结果卡签图：3:4 正式签（480×640）在 204px 高度下更饱满，上下留白合适；
   只在高度充足的屏幕放大，短屏沿用 app.css 的 162/148/138 压缩规则 */
@media (min-height: 721px) {
  .card-stick { height: 204px; }
  .card-stick img { max-width: 172px; }
}

/* 卡片：指针 3D 倾斜 + 高光扫过（不拦截点击） */
.result-card {
  position: relative;
  z-index: 3;
  transform-style: preserve-3d;
  transition: transform .18s ease-out;
  will-change: transform;
}
.result-card.is-tilting {
  transform:
    perspective(1000px)
    rotateX(calc(var(--fx-card-rx, 0) * 1deg))
    rotateY(calc(var(--fx-card-ry, 0) * 1deg));
}
.result-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(
    115deg,
    transparent 30%,
    rgba(255, 255, 255, .62) 44%,
    rgba(255, 201, 77, .34) 52%,
    transparent 68%
  );
  background-size: 240% 100%;
  background-position: 120% 0;
  z-index: 5;
}
.result-card.is-shine::after {
  animation: fxCardShine 1.15s ease-out 1 both;
}
@keyframes fxCardShine {
  0%   { opacity: 0; background-position: 130% 0; }
  18%  { opacity: .95; }
  100% { opacity: 0; background-position: -70% 0; }
}

/* ==========================================================================
   四、响应式（iPhone SE 375×667 / 短屏）
   ========================================================================== */

@media (max-height: 720px) {
  #ipStage { min-height: clamp(196px, 37vh, 286px); }
  #ipFigure { height: clamp(196px, 41vh, 276px); width: clamp(186px, 57vw, 252px); }
  .ip-halo { width: min(80vw, 300px); }
  .ip-prop--1 { --size: 28px; }
  .ip-prop--2 { --size: 26px; }
  .ip-prop--3 { --size: 32px; }
  .ip-prop--4 { --size: 24px; }
  .draw-ip { width: clamp(88px, 21vw, 110px); margin-left: calc(min(27.5vw, 124px) - 16px); }
  .result-ip { width: clamp(76px, 20vw, 84px); right: 3%; top: 3%; }
  #tubeImg { width: clamp(176px, 52vw, 220px); max-height: 46vh; }
  .result-stage { padding-top: 10px; }
}

@media (max-width: 360px) {
  #ipFigure { width: clamp(150px, 56vw, 210px); }
  .ip-prop--1, .ip-prop--3 { left: 0; }
  .ip-prop--2, .ip-prop--4 { right: 0; }
}

/* ==========================================================================
   五、降低动效偏好：静帧呈现，不做视差/漂浮/翻转（SPEC §12.4-7）
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  #ipFigure,
  #ipFigure img,
  .ip-halo,
  #ipStage .ip-floor,
  .ip-prop,
  .ip-prop-img,
  .draw-ip,
  .result-ip,
  .result-card,
  .result-card::after,
  .result-stage.is-cheering::after,
  .tube-wrap.is-shaking,
  .tube-ring.is-pulse {
    animation: none !important;
    transition: none !important;
  }
  #ipFigure,
  .result-card.is-tilting {
    transform: none !important;
  }
  .ip-prop-img { transform: none !important; }
  #ipFigure.is-cheer .ip-cheer { animation: none !important; opacity: 1; }
  #ipFigure.is-cheer .ip-hero,
  #ipFigure.is-cheer .ip-blink { opacity: 0; }
  .ip-halo { opacity: .75; }
}
