/* ===== 基础 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, sans-serif;
  background: linear-gradient(180deg, #070b26 0%, #0b1035 45%, #16204f 78%, #1e2a5e 100%);
  color: #ffe9a8;
  overflow-x: hidden;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
}

/* ===== 星空 ===== */
.stars { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.star {
  position: absolute;
  background: #fff;
  border-radius: 50%;
  animation: twinkle var(--dur, 3s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
  opacity: 0.7;
}
@keyframes twinkle {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 0.9; transform: scale(1.15); }
}

/* ===== 月亮与云 ===== */
.moon {
  position: fixed;
  top: 8vh; right: 8vw;
  width: 88px; height: 88px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #fffbe8 0%, #ffe9a8 45%, #f5c65b 100%);
  box-shadow: 0 0 40px 14px rgba(255, 233, 168, 0.35), 0 0 120px 60px rgba(245, 198, 91, 0.15);
  z-index: 0;
  animation: moonFloat 7s ease-in-out infinite;
}
.moon::after {
  content: "";
  position: absolute; left: 18%; top: 22%;
  width: 14px; height: 14px; border-radius: 50%;
  background: rgba(233, 190, 110, 0.5);
  box-shadow: 28px 20px 0 -2px rgba(233, 190, 110, 0.42), 16px 40px 0 -1px rgba(233, 190, 110, 0.35);
}
@keyframes moonFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.cloud {
  position: fixed;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  z-index: 0;
  filter: blur(1px);
}
.cloud-1 { width: 220px; height: 46px; top: 22vh; left: -60px; animation: cloudDrift 46s linear infinite; }
.cloud-2 { width: 300px; height: 56px; top: 40vh; left: -120px; animation: cloudDrift 64s linear infinite; animation-delay: -20s; }
@keyframes cloudDrift {
  0% { transform: translateX(-340px); }
  100% { transform: translateX(calc(100vw + 380px)); }
}

/* ===== 音效开关 ===== */
.sound-toggle {
  position: fixed; top: max(14px, env(safe-area-inset-top)); right: 16px;
  z-index: 50;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 233, 168, 0.35);
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(6px);
  color: #ffe9a8;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ===== 主舞台 ===== */
.stage {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 440px;
  padding: 0 20px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.title-area { text-align: center; margin-top: 8vh; }
.title {
  font-size: 40px;
  letter-spacing: 10px;
  text-indent: 10px;
  background: linear-gradient(180deg, #fffbe8, #ffd76a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 2px 20px rgba(255, 215, 106, 0.25);
  animation: titleGlow 3.2s ease-in-out infinite;
}
@keyframes titleGlow {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(255, 215, 106, 0.1)); }
  50% { filter: drop-shadow(0 0 20px rgba(255, 215, 106, 0.45)); }
}
.subtitle { margin-top: 10px; font-size: 14px; color: rgba(255, 233, 168, 0.75); letter-spacing: 4px; }

/* ===== 盲盒 ===== */
.mooncake-box {
  position: relative;
  margin-top: 46px;
  width: 230px; height: 210px;
  cursor: pointer;
  outline: none;
}
.mooncake-box:focus-visible .box-lid { box-shadow: 0 0 0 3px rgba(255, 233, 168, 0.8); }

/* 光晕 */
.glow {
  position: absolute; left: 50%; top: 46%;
  width: 300px; height: 300px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 215, 106, 0.28) 0%, transparent 62%);
  animation: glowPulse 3s ease-in-out infinite;
  pointer-events: none;
}
@keyframes glowPulse {
  0%, 100% { opacity: 0.55; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
}

/* 月饼（初始藏在盒内） */
.mooncake-wrap {
  position: absolute;
  left: 50%; bottom: 26px;
  width: 170px;
  transform: translateX(-50%) translateY(30px) scale(0.5);
  opacity: 0;
  z-index: 2;
  transition: none;
}
.mooncake { width: 100%; height: auto; display: block; filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.35)); }

/* 盒身 */
.box-body {
  position: absolute;
  left: 50%; bottom: 0;
  width: 200px; height: 120px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #a92e2e 0%, #8f2323 60%, #7a1b1b 100%);
  border-radius: 12px 12px 16px 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45), inset 0 8px 0 rgba(255, 255, 255, 0.12);
  z-index: 3;
  display: flex; align-items: flex-end; justify-content: center;
  overflow: hidden;
}
.box-ribbon-v {
  position: absolute; top: 0; left: 50%;
  transform: translateX(-50%);
  width: 44px; height: 100%;
  background: linear-gradient(180deg, rgba(255, 215, 106, 0.95), rgba(212, 160, 45, 0.9));
  clip-path: polygon(18% 0, 82% 0, 100% 100%, 0 100%);
}
.box-word {
  position: relative;
  margin-bottom: 14px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #ffe9a8, #e8b23a);
  color: #8a4e12;
  font-size: 30px;
  font-family: KaiTi, STKaiti, serif;
  display: flex; align-items: center; justify-content: center;
  z-index: 2;
  box-shadow: 0 0 0 4px rgba(255, 233, 168, 0.25);
}

/* 盒盖 */
.box-lid {
  position: absolute;
  left: 50%; bottom: 108px;
  width: 216px; height: 42px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #c43a3a 0%, #a92e2e 100%);
  border-radius: 10px 10px 4px 4px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4), inset 0 4px 0 rgba(255, 255, 255, 0.14);
  z-index: 4;
  display: flex; align-items: center; justify-content: center;
  transition: box-shadow 0.2s;
}
.box-word-lid { margin: 0; }

/* ===== 开盒动画状态 ===== */
.mooncake-box.opening .box-lid {
  animation: lidFly 1.1s cubic-bezier(0.3, 0.9, 0.4, 1.2) forwards;
}
@keyframes lidFly {
  0% { transform: translateX(-50%) translateY(0) rotate(0); opacity: 1; }
  40% { transform: translateX(-50%) translateY(-150px) rotate(-14deg); opacity: 1; }
  70% { transform: translateX(-50%) translateY(-175px) rotate(10deg); opacity: 0.6; }
  100% { transform: translateX(-50%) translateY(-190px) rotate(6deg); opacity: 0; }
}
.mooncake-box.opening .box-body { animation: boxShake 1.1s ease-in-out; }
@keyframes boxShake {
  0%, 100% { transform: translateX(-50%) rotate(0); }
  15% { transform: translateX(calc(-50% - 5px)) rotate(-1.6deg); }
  30% { transform: translateX(calc(-50% + 5px)) rotate(1.6deg); }
  45% { transform: translateX(calc(-50% - 4px)) rotate(-1.2deg); }
  60% { transform: translateX(calc(-50% + 4px)) rotate(1.2deg); }
  75% { transform: translateX(calc(-50% - 2px)) rotate(-0.6deg); }
}
.mooncake-box.opening .mooncake-wrap {
  animation: cakePop 1.2s cubic-bezier(0.2, 0.8, 0.3, 1.15) 0.35s forwards;
}
@keyframes cakePop {
  0% { opacity: 0; transform: translateX(-50%) translateY(40px) scale(0.45); }
  45% { opacity: 1; transform: translateX(-50%) translateY(-58px) scale(1.12); }
  65% { transform: translateX(-50%) translateY(-30px) scale(0.97); }
  80% { transform: translateX(-50%) translateY(-42px) scale(1.04); }
  100% { opacity: 1; transform: translateX(-50%) translateY(-38px) scale(1); }
}
/* 开盒后：盖保持消失、月饼保持呈现 */
.mooncake-box.opened .box-lid { opacity: 0; }
.mooncake-box.opened .mooncake-wrap,
.mooncake-box.opened.opening .mooncake-wrap {
  opacity: 1;
  transform: translateX(-50%) translateY(-38px) scale(1);
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.3, 1.1), opacity 0.45s;
}

/* ===== 按钮 ===== */
.open-btn {
  margin-top: 30px;
  padding: 14px 40px;
  font-size: 17px;
  letter-spacing: 4px;
  color: #6b3d0b;
  background: linear-gradient(180deg, #ffe9a8 0%, #f5c65b 60%, #e8b23a 100%);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(232, 178, 58, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.6);
  animation: btnPulse 2.4s ease-in-out infinite;
}
.open-btn:active { transform: scale(0.95); }
@keyframes btnPulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(232, 178, 58, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.6); }
  50% { box-shadow: 0 8px 34px rgba(232, 178, 58, 0.6), inset 0 2px 0 rgba(255, 255, 255, 0.6); }
}
.again-btn { animation: none; }
.hidden { display: none !important; }

/* ===== 祝福卡 ===== */
.blessing-card {
  margin-top: 30px;
  width: 100%;
  max-width: 340px;
  padding: 26px 24px 20px;
  text-align: center;
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(62, 38, 14, 0.92), rgba(36, 22, 10, 0.95));
  border: 1px solid rgba(255, 215, 106, 0.45);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5), inset 0 0 0 3px rgba(255, 215, 106, 0.12);
  transform: translateY(30px) scale(0.9);
  opacity: 0;
}
.blessing-card.show { animation: cardIn 0.65s cubic-bezier(0.2, 0.9, 0.3, 1.1) forwards; }
@keyframes cardIn {
  to { transform: translateY(0) scale(1); opacity: 1; }
}
.card-deco {
  font-size: 15px;
  color: rgba(255, 215, 106, 0.75);
  letter-spacing: 10px;
  margin-bottom: 10px;
}
.blessing-text {
  font-size: 19px;
  line-height: 1.75;
  color: #ffedba;
  letter-spacing: 1.5px;
  min-height: 3.5em;
}
.card-tag {
  margin-top: 16px;
  font-size: 12px;
  letter-spacing: 6px;
  color: rgba(255, 215, 106, 0.8);
  border-top: 1px dashed rgba(255, 215, 106, 0.35);
  padding-top: 12px;
}
/* 重新开盒时的淡出 */
.blessing-card.fade-out { animation: cardOut 0.35s ease forwards; }
@keyframes cardOut {
  to { transform: translateY(14px) scale(0.96); opacity: 0; }
}

/* ===== GIF 祝福播放层 ===== */
.gift-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 7, 22, 0.88);
  backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0.35s;
}
.gift-overlay.show { opacity: 1; visibility: visible; }
.gift-panel {
  position: relative;
  width: min(92vw, 560px);
  text-align: center;
  animation: giftPop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
@keyframes giftPop {
  from { transform: scale(0.82) translateY(24px); opacity: 0.5; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}
.gift-close {
  position: absolute;
  top: -14px; right: -8px;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 233, 168, 0.5);
  background: rgba(20, 12, 4, 0.9);
  color: #ffe9a8;
  font-size: 16px;
  cursor: pointer;
  z-index: 2;
}
.gift-close:active { transform: scale(0.92); }
.gift-gif {
  width: 100%;
  height: auto;
  border-radius: 14px;
  box-shadow: 0 0 40px rgba(245, 198, 91, 0.45), 0 14px 40px rgba(0, 0, 0, 0.6);
}
.gift-tip {
  margin-top: 16px;
  font-size: 15px;
  letter-spacing: 3px;
  color: #ffe9a8;
}

/* ===== 计数与页脚 ===== */
.counter {
  margin-top: 24px;
  font-size: 13px;
  color: rgba(255, 233, 168, 0.6);
  letter-spacing: 2px;
}
.footer {
  position: relative;
  z-index: 10;
  padding: 18px 20px calc(18px + env(safe-area-inset-bottom));
  font-size: 12px;
  color: rgba(255, 233, 168, 0.45);
  letter-spacing: 2px;
}

@media (max-width: 380px) {
  .title { font-size: 34px; }
  .mooncake-box { transform: scale(0.92); }
  .moon { width: 70px; height: 70px; }
}

@media (prefers-reduced-motion: reduce) {
  .star, .moon, .glow, .cloud, .title, .open-btn { animation: none; }
}