/**
 * Shake-Open 抽奖动画 - 实体盲盒摇晃开箱
 * 设计理念：拟物化 + 真实物理 + 强烈爆发感
 */

/* ========== CSS变量定义 ========== */
:root {
  /* 盲盒颜色 */
  --box-primary: #667eea;
  --box-secondary: #764ba2;
  --box-highlight: #ffd89b;
  --box-shadow-color: rgba(0, 0, 0, 0.3);

  /* 碎片颜色 */
  --fragment-colors: #667eea, #764ba2, #ffd89b, #f093fb;

  /* 动画时长 */
  --shake-duration: 2s;
  --explode-duration: 0.8s;
  --reveal-duration: 1.5s;
}

/* ========== 容器布局 ========== */
.shake-open-container {
  width: 100%;
  max-width: 400px;
  margin: 40px auto;
  padding: 40px 20px;
  perspective: 1200px;
  position: relative;
  min-height: 500px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ========== 盲盒主体 ========== */
.mystery-box {
  position: relative;
  width: 280px;
  height: 280px;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: pointer;
  user-select: none;
}

/* 盒子外壳 */
.box-shell {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--box-primary) 0%, var(--box-secondary) 100%);
  box-shadow:
    0 20px 60px var(--box-shadow-color),
    0 0 0 8px rgba(255, 255, 255, 0.1),
    inset 0 4px 0 rgba(255, 255, 255, 0.3),
    inset 0 -4px 0 rgba(0, 0, 0, 0.2);
  transform-style: preserve-3d;
  overflow: hidden;
}

/* 盒子反光效果 */
.box-shell::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    45deg,
    transparent 30%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 70%
  );
  transform: rotate(45deg);
  animation: shimmer 3s infinite;
}

@keyframes shimmer {
  0%, 100% { transform: rotate(45deg) translateX(-100%); }
  50% { transform: rotate(45deg) translateX(100%); }
}

/* 问号标识 */
.box-question-mark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 120px;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.9);
  text-shadow:
    0 4px 8px rgba(0, 0, 0, 0.3),
    0 0 40px rgba(255, 255, 255, 0.3);
  z-index: 2;
  pointer-events: none;
  animation: questionPulse 2s ease-in-out infinite;
}

@keyframes questionPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.9; }
  50% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
}

/* 盒子装饰条纹 */
.box-ribbon {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 60px;
  background: linear-gradient(
    135deg,
    var(--box-highlight) 0%,
    #ffeaa7 100%
  );
  transform: translateY(-50%);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.2),
    inset 0 2px 0 rgba(255, 255, 255, 0.4);
  z-index: 1;
}

.box-ribbon::before,
.box-ribbon::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 80px;
  height: 80px;
  background: inherit;
  border-radius: 50%;
  transform: translateY(-50%);
  box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.2);
}

.box-ribbon::before { left: 50%; transform: translate(-50%, -50%); }
.box-ribbon::after { right: -40px; }

/* ========== 点击提示 ========== */
.tap-hint {
  position: absolute;
  bottom: -60px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 16px;
  color: rgba(255, 255, 255, 0.8);
  text-align: center;
  animation: tapBounce 1.5s ease-in-out infinite;
  pointer-events: none;
}

.tap-hint::before {
  content: '👆';
  display: block;
  font-size: 32px;
  margin-bottom: 8px;
}

@keyframes tapBounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-10px); }
}

/* ========== 摇晃动画 ========== */
.mystery-box.shaking {
  animation: violentShake var(--shake-duration) ease-in-out;
}

@keyframes violentShake {
  0%, 100% { transform: translateX(0) translateY(0) rotate(0deg); }
  5% { transform: translateX(-15px) translateY(-5px) rotate(-8deg); }
  10% { transform: translateX(15px) translateY(5px) rotate(8deg); }
  15% { transform: translateX(-12px) translateY(-8px) rotate(-6deg); }
  20% { transform: translateX(12px) translateY(8px) rotate(6deg); }
  25% { transform: translateX(-10px) translateY(-10px) rotate(-5deg); }
  30% { transform: translateX(10px) translateY(10px) rotate(5deg); }
  35% { transform: translateX(-8px) translateY(-6px) rotate(-4deg); }
  40% { transform: translateX(8px) translateY(6px) rotate(4deg); }
  45% { transform: translateX(-6px) translateY(-8px) rotate(-3deg); }
  50% { transform: translateX(6px) translateY(8px) rotate(3deg); }
  55% { transform: translateX(-5px) translateY(-5px) rotate(-3deg); }
  60% { transform: translateX(5px) translateY(5px) rotate(3deg); }
  65% { transform: translateX(-4px) translateY(-6px) rotate(-2deg); }
  70% { transform: translateX(4px) translateY(6px) rotate(2deg); }
  75% { transform: translateX(-3px) translateY(-4px) rotate(-2deg); }
  80% { transform: translateX(3px) translateY(4px) rotate(2deg); }
  85% { transform: translateX(-2px) translateY(-3px) rotate(-1deg); }
  90% { transform: translateX(2px) translateY(3px) rotate(1deg); }
  95% { transform: translateX(-1px) translateY(-2px) rotate(-1deg); }
}

/* 摇晃时问号跳动 */
.mystery-box.shaking .box-question-mark {
  animation: questionShake 0.1s linear infinite;
}

@keyframes questionShake {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.05); }
}

/* ========== 爆炸效果 ========== */
.mystery-box.exploding .box-shell {
  animation: boxExplode var(--explode-duration) cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

@keyframes boxExplode {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.8;
  }
  100% {
    transform: scale(0);
    opacity: 0;
  }
}

/* 碎片容器 */
.fragments-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
}

/* 碎片 */
.fragment {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  background: var(--box-primary);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  opacity: 0;
}

.fragment.active {
  animation: fragmentFly 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes fragmentFly {
  0% {
    transform: translate(-50%, -50%) rotate(0deg) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) rotate(var(--rot)) scale(0.5);
    opacity: 0;
  }
}

/* ========== 烟雾效果 ========== */
.smoke-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 90;
}

.smoke {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.6) 0%,
    rgba(255, 255, 255, 0.3) 40%,
    transparent 70%
  );
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
}

.smoke.active {
  animation: smokeExpand 1s ease-out forwards;
}

@keyframes smokeExpand {
  0% {
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
  }
  30% {
    opacity: 0.8;
  }
  100% {
    transform: translate(-50%, -50%) scale(2.5);
    opacity: 0;
  }
}

/* ========== 商品展示 ========== */
.product-reveal {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  max-width: 320px;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0) rotateY(180deg);
  z-index: 50;
}

.product-reveal.show {
  animation: productAppear var(--reveal-duration) cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes productAppear {
  0% {
    transform: translate(-50%, -50%) scale(0) rotateY(180deg);
    opacity: 0;
  }
  60% {
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(1) rotateY(0deg);
    opacity: 1;
  }
}

/* 商品图片 */
.product-image-shake {
  width: 200px;
  height: 200px;
  margin: 0 auto 20px;
  border-radius: 20px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.1);
  box-shadow:
    0 0 60px rgba(255, 255, 255, 0.3),
    0 20px 40px rgba(0, 0, 0, 0.3);
  position: relative;
}

.product-image-shake img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.3));
}

/* 光环效果 */
.product-aura {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 120%;
  height: 120%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
}

.product-reveal.show .product-aura {
  animation: auraRotate 3s linear infinite;
}

@keyframes auraRotate {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
    opacity: 0.6;
  }
  100% {
    transform: translate(-50%, -50%) rotate(360deg);
    opacity: 0.6;
  }
}

/* 稀有度光环 - 6级系统 */
.product-aura.sp {
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    var(--color-rarity-sp, #b967ff) 45deg,
    transparent 90deg,
    var(--color-rarity-sp, #b967ff) 135deg,
    transparent 180deg,
    var(--color-rarity-sp, #b967ff) 225deg,
    transparent 270deg,
    var(--color-rarity-sp, #b967ff) 315deg,
    transparent 360deg
  );
  filter: blur(8px);
}

.product-aura.sss {
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    var(--color-rarity-sss, #ff0844) 45deg,
    transparent 90deg,
    var(--color-rarity-sss, #ff0844) 135deg,
    transparent 180deg,
    var(--color-rarity-sss, #ff0844) 225deg,
    transparent 270deg,
    var(--color-rarity-sss, #ff0844) 315deg,
    transparent 360deg
  );
  filter: blur(8px);
}

.product-aura.ss {
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    var(--color-rarity-ss, #ff8c00) 45deg,
    transparent 90deg,
    var(--color-rarity-ss, #ff8c00) 135deg,
    transparent 180deg,
    var(--color-rarity-ss, #ff8c00) 225deg,
    transparent 270deg,
    var(--color-rarity-ss, #ff8c00) 315deg,
    transparent 360deg
  );
  filter: blur(8px);
}

.product-aura.s {
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    var(--color-rarity-s, #ffea00) 45deg,
    transparent 90deg,
    var(--color-rarity-s, #ffea00) 135deg,
    transparent 180deg,
    var(--color-rarity-s, #ffea00) 225deg,
    transparent 270deg,
    var(--color-rarity-s, #ffea00) 315deg,
    transparent 360deg
  );
  filter: blur(8px);
}

.product-aura.sr {
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    var(--color-rarity-sr, #00f5ff) 90deg,
    transparent 180deg,
    var(--color-rarity-sr, #00f5ff) 270deg,
    transparent 360deg
  );
  filter: blur(8px);
}

.product-aura.r {
  background: conic-gradient(
    from 0deg,
    var(--color-rarity-r, #ff69b4) 0deg,
    transparent 180deg,
    var(--color-rarity-r, #ff69b4) 360deg
  );
  filter: blur(8px);
}

/* 商品名称 */
.product-name-shake {
  font-size: 24px;
  font-weight: 700;
  color: #ffffff;
  text-align: center;
  text-shadow:
    0 2px 8px rgba(0, 0, 0, 0.5),
    0 0 20px rgba(255, 255, 255, 0.3);
  margin-bottom: 12px;
}

/* 稀有度徽章 */
.product-rarity-shake {
  display: inline-block;
  padding: 8px 24px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  animation: rarityGlow 2s ease-in-out infinite;
}

@keyframes rarityGlow {
  0%, 100% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3); }
  50% { box-shadow: 0 4px 24px rgba(255, 255, 255, 0.5); }
}

.product-rarity-shake.sp {
  background: linear-gradient(135deg,
    var(--color-rarity-sp, #b967ff) 0%,
    var(--color-rarity-sp, #b967ff) 100%);
  color: #ffffff;
}

.product-rarity-shake.sss {
  background: linear-gradient(135deg,
    var(--color-rarity-sss, #ff0844) 0%,
    var(--color-rarity-sss, #ff0844) 100%);
  color: #ffffff;
}

.product-rarity-shake.ss {
  background: linear-gradient(135deg,
    var(--color-rarity-ss, #ff8c00) 0%,
    var(--color-rarity-ss, #ff8c00) 100%);
  color: #1a1a2e;
}

.product-rarity-shake.s {
  background: linear-gradient(135deg,
    var(--color-rarity-s, #ffea00) 0%,
    var(--color-rarity-s, #ffea00) 100%);
  color: #1a1a2e;
}

.product-rarity-shake.sr {
  background: linear-gradient(135deg,
    var(--color-rarity-sr, #00f5ff) 0%,
    var(--color-rarity-sr, #00f5ff) 100%);
  color: #ffffff;
}

.product-rarity-shake.r {
  background: linear-gradient(135deg,
    var(--color-rarity-r, #ff69b4) 0%,
    var(--color-rarity-r, #ff69b4) 100%);
  color: #ffffff;
}

/* ========== 响应式设计 ========== */
@media (max-width: 480px) {
  .shake-open-container {
    max-width: 100%;
    padding: 20px 10px;
    min-height: 400px;
  }

  .mystery-box {
    width: 240px;
    height: 240px;
  }

  .box-question-mark {
    font-size: 100px;
  }

  .product-image-shake {
    width: 160px;
    height: 160px;
  }

  .product-name-shake {
    font-size: 20px;
  }

  .product-rarity-shake {
    font-size: 12px;
    padding: 6px 18px;
  }
}

@media (max-width: 375px) {
  .mystery-box {
    width: 200px;
    height: 200px;
  }

  .box-question-mark {
    font-size: 80px;
  }

  .product-image-shake {
    width: 140px;
    height: 140px;
  }
}

/* ========== 性能优化 ========== */
.mystery-box,
.box-shell,
.fragment,
.smoke,
.product-reveal {
  will-change: transform, opacity;
  backface-visibility: hidden;
  -webkit-font-smoothing: antialiased;
}
