/* =======================
   PREMIUM ANGPAO THEME
   Red & Gold Lucky Envelope
========================== */

/* --- RESET & BASE --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: 
    radial-gradient(ellipse at 50% 0%, #6b0000 0%, #3a0000 50%, #1a0000 100%);
  font-family: "Noto Sans Thai", "Noto Serif SC", system-ui, sans-serif;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  padding-bottom: 40px;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: 
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 60px,
      rgba(255, 215, 0, 0.02) 60px,
      rgba(255, 215, 0, 0.02) 61px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 60px,
      rgba(255, 215, 0, 0.02) 60px,
      rgba(255, 215, 0, 0.02) 61px
    );
  pointer-events: none;
  z-index: 0;
}

/* --- FLOATING LANTERNS --- */
.lanterns-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.lantern {
  position: absolute;
  font-size: 40px;
  opacity: 0.15;
  animation: lanternFloat 8s ease-in-out infinite;
  filter: blur(1px);
}

.lantern-1 { left: 5%; top: 10%; animation-delay: 0s; animation-duration: 7s; }
.lantern-2 { left: 85%; top: 5%; animation-delay: 1.5s; animation-duration: 9s; }
.lantern-3 { left: 15%; top: 60%; animation-delay: 3s; animation-duration: 6s; font-size: 30px; }
.lantern-4 { left: 75%; top: 55%; animation-delay: 2s; animation-duration: 8s; font-size: 35px; }
.lantern-5 { left: 50%; top: 80%; animation-delay: 4s; animation-duration: 10s; font-size: 25px; }

@keyframes lanternFloat {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-25px) rotate(3deg); }
}

/* --- GOLD PARTICLES --- */
.particles-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.gold-particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: radial-gradient(circle, #ffd700, rgba(255, 215, 0, 0));
  border-radius: 50%;
  animation: particleRise 4s ease-out forwards;
  opacity: 0;
}

@keyframes particleRise {
  0% { transform: translateY(0) scale(0); opacity: 0; }
  10% { opacity: 1; transform: scale(1); }
  100% { transform: translateY(-200px) scale(0); opacity: 0; }
}

/* --- WRAPPER --- */
.wrapper {
  width: 400px;
  max-width: 95vw;
  text-align: center;
  position: relative;
  z-index: 10;
  padding: 20px 10px 40px;
}

/* --- HEADER --- */
.header-section {
  margin-bottom: 10px;
  padding-top: 15px;
}

.chinese-ornament {
  font-family: "Ma Shan Zheng", "Noto Serif SC", serif;
  font-size: 22px;
  color: #ffd700;
  text-shadow: 
    0 0 10px rgba(255, 215, 0, 0.6),
    0 0 30px rgba(255, 215, 0, 0.3);
  letter-spacing: 8px;
  margin-bottom: 6px;
  animation: goldPulse 2s ease-in-out infinite;
}

@keyframes goldPulse {
  0%, 100% { text-shadow: 0 0 10px rgba(255,215,0,0.6), 0 0 30px rgba(255,215,0,0.3); }
  50% { text-shadow: 0 0 20px rgba(255,215,0,0.9), 0 0 50px rgba(255,215,0,0.5); }
}

.title {
  font-size: 28px;
  font-weight: 900;
  background: linear-gradient(180deg, #ffe88a 0%, #ffd700 30%, #ff9500 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
  margin-bottom: 4px;
}

.subtitle {
  font-size: 14px;
  color: #ffb6b6;
  font-weight: 400;
  letter-spacing: 1px;
}

/* --- DRAGON DIVIDER --- */
.dragon-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 15px 0;
}

.dragon-line {
  flex: 1;
  height: 2px;
  background: linear-gradient(90deg, transparent, #ffd700, transparent);
  max-width: 120px;
}

.dragon-icon {
  font-size: 28px;
  animation: dragonBob 3s ease-in-out infinite;
  filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.5));
}

@keyframes dragonBob {
  0%, 100% { transform: translateY(0) scaleX(1); }
  25% { transform: translateY(-4px) scaleX(1); }
  75% { transform: translateY(2px) scaleX(-1); }
}

/* =======================
   ANGPAO ENVELOPE GRID
========================== */
.angpao-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  justify-items: center;
  position: relative;
  min-height: 340px;
  padding: 10px 5px;
}

/* --- ANGPAO WRAPPER --- */
.angpao-wrapper {
  width: 105px;
  height: 150px;
  position: relative;
  perspective: 800px;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.angpao-wrapper:hover {
  transform: translateY(-6px) scale(1.04);
}

.angpao-wrapper:hover .angpao-glow {
  opacity: 1;
}

/* --- ANGPAO GLOW --- */
.angpao-glow {
  position: absolute;
  inset: -8px;
  background: radial-gradient(ellipse, rgba(255,215,0,0.3), transparent 70%);
  border-radius: 16px;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: -1;
  pointer-events: none;
}

/* --- ANGPAO ENVELOPE (3D flip container) --- */
.angpao-envelope {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.2);
}

.angpao-wrapper.opened .angpao-envelope {
  transform: rotateY(180deg);
}

/* --- FACE BASE --- */
.angpao-face {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  backface-visibility: hidden;
  overflow: hidden;
}

/* =======================
   ANGPAO BACK (Sealed - visible first)
========================== */
.angpao-back {
  background: linear-gradient(165deg, #ff1a1a 0%, #cc0000 35%, #8b0000 100%);
  border: 2px solid #ffd700;
  box-shadow:
    0 8px 25px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.15),
    inset 0 -2px 0 rgba(0,0,0,0.2),
    0 0 15px rgba(255, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Flap at top */
.angpao-flap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 35px;
  background: linear-gradient(180deg, #ff3333 0%, #cc0000 100%);
  clip-path: polygon(0 0, 100% 0, 85% 100%, 15% 100%);
  border-bottom: 1.5px solid #ffd700;
  z-index: 2;
}

.angpao-flap::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 12px;
  background: #ffd700;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(255,215,0,0.8);
}

/* Gold seal circle */
.angpao-seal {
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
}

.seal-circle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffe88a, #ffd700, #b8860b);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 3px 10px rgba(0,0,0,0.3),
    inset 0 1px 2px rgba(255,255,255,0.5),
    0 0 15px rgba(255,215,0,0.4);
  border: 2px solid #b8860b;
  animation: sealShimmer 3s ease-in-out infinite;
}

@keyframes sealShimmer {
  0%, 100% { box-shadow: 0 3px 10px rgba(0,0,0,0.3), 0 0 15px rgba(255,215,0,0.4); }
  50% { box-shadow: 0 3px 10px rgba(0,0,0,0.3), 0 0 25px rgba(255,215,0,0.7); }
}

.seal-text {
  font-family: "Ma Shan Zheng", "Noto Serif SC", serif;
  font-size: 28px;
  color: #8b0000;
  font-weight: 900;
  text-shadow: 0 1px 0 rgba(255,255,255,0.3);
}

/* Cloud pattern decorations */
.angpao-cloud-top,
.angpao-cloud-bottom {
  position: absolute;
  left: 0;
  right: 0;
  height: 25px;
  background: 
    radial-gradient(ellipse 20px 18px at 20% 100%, rgba(255,215,0,0.15) 49%, transparent 50%),
    radial-gradient(ellipse 25px 20px at 50% 100%, rgba(255,215,0,0.12) 49%, transparent 50%),
    radial-gradient(ellipse 20px 18px at 80% 100%, rgba(255,215,0,0.15) 49%, transparent 50%);
  z-index: 1;
}

.angpao-cloud-top {
  top: 32px;
  transform: scaleY(-1);
}

.angpao-cloud-bottom {
  bottom: 0;
}

/* =======================
   ANGPAO FRONT (Opened - reward side)
========================== */
.angpao-front {
  transform: rotateY(180deg);
  background: linear-gradient(165deg, #fff7e6 0%, #ffe4b5 50%, #ffd699 100%);
  border: 2px solid #ffd700;
  box-shadow:
    0 8px 25px rgba(0,0,0,0.3),
    inset 0 0 30px rgba(255,215,0,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.angpao-inner-design {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.angpao-coin {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffd700, #daa520, #b8860b);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Ma Shan Zheng", "Noto Serif SC", serif;
  font-size: 32px;
  color: #8b0000;
  font-weight: 900;
  box-shadow:
    0 4px 12px rgba(0,0,0,0.3),
    inset 0 2px 3px rgba(255,255,255,0.4),
    0 0 20px rgba(255,215,0,0.4);
  border: 2px solid #daa520;
  animation: coinSpin 0.6s ease-out;
}

@keyframes coinSpin {
  0% { transform: rotateY(0deg) scale(0.5); }
  50% { transform: rotateY(180deg) scale(1.1); }
  100% { transform: rotateY(360deg) scale(1); }
}

.angpao-amount {
  font-size: 13px;
  font-weight: 900;
  color: #8b0000;
  text-align: center;
  line-height: 1.3;
}

/* =======================
   SHAKE ANIMATION
========================== */
.angpao-wrapper.shaking .angpao-envelope {
  animation: envelopeShake 0.12s ease-in-out infinite;
}

@keyframes envelopeShake {
  0% { transform: rotate(0deg); }
  25% { transform: rotate(-4deg); }
  50% { transform: rotate(4deg); }
  75% { transform: rotate(-2deg); }
  100% { transform: rotate(0deg); }
}

.angpao-wrapper.shaking .angpao-glow {
  opacity: 1;
  animation: glowPulse 0.3s ease-in-out infinite;
}

@keyframes glowPulse {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.15); opacity: 1; }
}

/* =======================
   SHAKE HINT
========================== */
.shake-hint {
  margin-top: 15px;
  color: #ffd700;
  font-size: 14px;
  font-weight: 700;
  animation: hintBounce 1s ease-in-out infinite;
  text-shadow: 0 0 10px rgba(255,215,0,0.5);
}

.shake-hint.hidden { display: none; }

.shake-emoji {
  display: inline-block;
  animation: fingerTap 0.6s ease-in-out infinite alternate;
}

@keyframes fingerTap {
  0% { transform: translateY(0); }
  100% { transform: translateY(-5px); }
}

@keyframes hintBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* =======================
   SHUFFLE BUTTON
========================== */
.shuffle-btn {
  background: linear-gradient(180deg, #ffd700 0%, #daa520 50%, #b8860b 100%);
  color: #5c0000;
  font-size: 17px;
  font-weight: 900;
  padding: 14px 32px;
  border: 2px solid #ffd700;
  border-radius: 50px;
  margin-top: 18px;
  cursor: pointer;
  box-shadow:
    0 4px 0 #8b6914,
    0 6px 20px rgba(255,215,0,0.3);
  transition: all 0.2s;
  font-family: "Noto Sans Thai", system-ui;
  letter-spacing: 1px;
  position: relative;
  overflow: hidden;
}

.shuffle-btn::before {
  content: '';
  position: absolute;
  inset: -2px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  transform: translateX(-100%);
  animation: btnShine 3s ease-in-out infinite;
}

@keyframes btnShine {
  0% { transform: translateX(-100%); }
  50% { transform: translateX(100%); }
  100% { transform: translateX(100%); }
}

.shuffle-btn.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

.shuffle-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #8b6914;
}

.shuffle-btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 6px 0 #8b6914,
    0 10px 30px rgba(255,215,0,0.5);
}

.btn-icon {
  margin-right: 4px;
}

/* =======================
   SHUFFLE ANIMATIONS
========================== */
.shuffle-stage {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle, rgba(139,0,0,0.5), rgba(0,0,0,0.7) 70%);
  backdrop-filter: blur(4px);
  z-index: 50;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.shuffle-stage.show {
  opacity: 1;
}

/* Cards move to center */
.angpao-wrapper.to-center {
  position: absolute !important;
  left: 50% !important;
  top: 50% !important;
  transform: translate(-50%, -50%) scale(0.7) !important;
  transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 100;
}

/* Deck shake */
.angpao-wrapper.deck-shake {
  animation: deckShake 0.35s ease-in-out 3 !important;
}

@keyframes deckShake {
  0% { transform: translate(-50%,-50%) rotate(0deg) scale(0.7); }
  25% { transform: translate(-48%,-52%) rotate(-6deg) scale(0.72); }
  50% { transform: translate(-52%,-48%) rotate(6deg) scale(0.72); }
  75% { transform: translate(-51%,-49%) rotate(-3deg) scale(0.71); }
  100% { transform: translate(-50%,-50%) rotate(0deg) scale(0.7); }
}

/* Cards fly out */
.angpao-wrapper.fly-out {
  transition: all 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
  opacity: 1 !important;
}

/* =======================
   SPARKLE PARTICLES
========================== */
.sparkle {
  position: fixed;
  width: 8px;
  height: 8px;
  background: radial-gradient(circle, #ffd700, rgba(255, 215, 0, 0));
  border-radius: 50%;
  pointer-events: none;
  z-index: 200;
  opacity: 0;
  animation: sparkleFloat 1.2s ease-out forwards;
}

@keyframes sparkleFloat {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  50% { transform: translateY(-40px) scale(1.5); opacity: 0.8; }
  100% { transform: translateY(-80px) scale(0.5); opacity: 0; }
}

/* =======================
   TERMS AND CONDITIONS
========================== */
.tnc {
  margin-top: 25px;
  background: linear-gradient(135deg, rgba(139,0,0,0.6), rgba(100,0,0,0.8));
  border: 1px solid rgba(255,215,0,0.3);
  border-radius: 16px;
  padding: 18px;
  backdrop-filter: blur(5px);
}

.tnc-header {
  font-size: 16px;
  font-weight: 900;
  color: #ffd700;
  margin-bottom: 10px;
  text-shadow: 0 0 10px rgba(255,215,0,0.5);
}

.tnc-body {
  font-size: 13px;
  color: #ffcccc;
  line-height: 1.8;
}

.gold-text {
  color: #ffd700;
  font-weight: 900;
  text-shadow: 0 0 5px rgba(255,215,0,0.5);
}

.tnc-highlight {
  color: #ffd700;
  font-weight: 900;
  font-size: 14px;
  text-shadow: 0 0 8px rgba(255,215,0,0.4);
}

.tnc-sub {
  font-size: 12px;
  color: #ffaaaa;
  opacity: 0.85;
}

.tnc-note {
  font-size: 12px;
  color: #ff9999;
}

/* =======================
   POPUP MODAL
========================== */
.popup {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.popup.hidden {
  display: none;
}

.popup-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(5px);
}

.popup-box {
  position: relative;
  background: linear-gradient(145deg, #fff5e6, #ffe4b5);
  width: 85%;
  max-width: 320px;
  padding: 30px 25px;
  border-radius: 24px;
  text-align: center;
  border: 3px solid #ffd700;
  box-shadow:
    0 20px 60px rgba(0,0,0,0.5),
    0 0 40px rgba(255,215,0,0.2),
    inset 0 0 30px rgba(255,215,0,0.05);
  animation: popupAppear 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popupAppear {
  0% { transform: scale(0.3) translateY(50px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.popup-coins {
  font-size: 30px;
  margin-bottom: 8px;
  animation: coinsJump 0.6s ease-out;
}

@keyframes coinsJump {
  0% { transform: translateY(20px); opacity: 0; }
  60% { transform: translateY(-8px); }
  100% { transform: translateY(0); opacity: 1; }
}

.popup-title {
  font-size: 20px;
  font-weight: 900;
  color: #8b0000;
  margin-bottom: 15px;
}

.reward-text {
  font-size: 16px;
  color: #5c3a00;
  font-weight: 700;
  line-height: 1.8;
  white-space: pre-line;
  min-height: 50px;
}

.popup-fortune {
  margin-top: 12px;
  padding: 10px 15px;
  background: linear-gradient(135deg, #8b0000, #cc0000);
  border-radius: 12px;
  color: #ffd700;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
  border: 1px solid rgba(255,215,0,0.3);
  display: none;
}

.popup-fortune.show {
  display: block;
  animation: fortuneReveal 0.5s ease-out 0.3s both;
}

@keyframes fortuneReveal {
  0% { transform: translateY(10px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

.popup-btn {
  margin-top: 18px;
  background: linear-gradient(180deg, #cc0000, #8b0000);
  color: #ffd700;
  font-size: 16px;
  font-weight: 900;
  padding: 12px 36px;
  border: 2px solid #ffd700;
  border-radius: 50px;
  cursor: pointer;
  font-family: "Noto Sans Thai", system-ui;
  box-shadow:
    0 4px 0 #5c0000,
    0 6px 15px rgba(0,0,0,0.3);
  transition: all 0.2s;
}

.popup-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #5c0000;
}

.popup-btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 6px 0 #5c0000,
    0 10px 25px rgba(139,0,0,0.4);
}

.popup-btn.btn-disabled,
.popup-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* =======================
   CONFETTI CANVAS
========================== */
.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9998;
}

/* =======================
   PROGRESS BAR (Shake meter)
========================== */
.shake-meter {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 6px;
  background: rgba(0,0,0,0.3);
  border-radius: 3px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.3s;
}

.angpao-wrapper.shaking .shake-meter {
  opacity: 1;
}

.shake-meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffd700, #ff6600);
  border-radius: 3px;
  transition: width 0.1s;
}

/* =======================
   ENTRANCE ANIMATION
========================== */
.angpao-wrapper {
  animation: entrancePop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.angpao-wrapper:nth-child(1) { animation-delay: 0.1s; }
.angpao-wrapper:nth-child(2) { animation-delay: 0.2s; }
.angpao-wrapper:nth-child(3) { animation-delay: 0.3s; }
.angpao-wrapper:nth-child(4) { animation-delay: 0.4s; }
.angpao-wrapper:nth-child(5) { animation-delay: 0.5s; }
.angpao-wrapper:nth-child(6) { animation-delay: 0.6s; }

@keyframes entrancePop {
  0% { transform: scale(0) rotateZ(-10deg); opacity: 0; }
  100% { transform: scale(1) rotateZ(0); opacity: 1; }
}

/* =======================
   SELECTED GLOW EFFECT
========================== */
.angpao-wrapper.selected {
  z-index: 100;
}

.angpao-wrapper.selected .angpao-glow {
  opacity: 1;
  background: radial-gradient(ellipse, rgba(255,215,0,0.6), transparent 70%);
  animation: selectedGlow 0.5s ease-in-out infinite alternate;
}

@keyframes selectedGlow {
  0% { transform: scale(1); }
  100% { transform: scale(1.2); }
}

/* Dim non-selected envelopes */
.angpao-wrapper.dimmed {
  opacity: 0.4;
  transform: scale(0.9);
  pointer-events: none;
  transition: all 0.5s ease;
}

/* =======================
   RESPONSIVE
========================== */
@media (max-width: 380px) {
  .angpao-wrapper {
    width: 90px;
    height: 130px;
  }
  
  .angpao-grid {
    gap: 10px;
  }
  
  .title {
    font-size: 24px;
  }
  
  .seal-circle {
    width: 42px;
    height: 42px;
  }
  
  .seal-text {
    font-size: 22px;
  }
}

/* =======================
   HIDDEN UTILITY
========================== */
.hidden {
  display: none !important;
}
