/* =======================
   PIGGY HUT
   Warm Farm/Cute Theme
========================== */

/* --- RESET & BASE --- */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --piggy-pink: #ff6b8a;
  --piggy-hot: #ff3366;
  --piggy-light: #ffb6c8;
  --piggy-gold: #ffc107;
  --farm-brown: #8b5e3c;
  --warm-bg: #1a0f1e;
}

body {
  background: radial-gradient(ellipse at 50% 20%, #2d1535 0%, #1a0f1e 40%, #0f0a14 100%);
  font-family: "Kanit", "Fredoka", sans-serif;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  padding-bottom: 40px;
  color: #f0d8e0;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(255, 107, 138, 0.04) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255, 182, 200, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(255, 193, 7, 0.02) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='30' cy='30' r='1.5' fill='rgba(255,182,200,0.03)'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* --- FLOATING SPARKLE DOTS --- */
.sparkle-bg {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 1; overflow: hidden;
}
.sparkle-dot {
  position: absolute;
  width: 4px; height: 4px; border-radius: 50%;
  background: radial-gradient(circle, #ffb6c8, #ff6b8a88, transparent);
  box-shadow: 0 0 6px 2px rgba(255, 107, 138, 0.3);
  animation: sparkleFloat linear infinite;
  opacity: 0;
}
.sd-1 { left: 10%; bottom: -10px; animation-duration: 9s; width: 3px; height: 3px; }
.sd-2 { left: 25%; bottom: -10px; animation-duration: 7s; animation-delay: 1s; width: 5px; height: 5px; }
.sd-3 { left: 40%; bottom: -10px; animation-duration: 10s; animation-delay: 2s; }
.sd-4 { left: 55%; bottom: -10px; animation-duration: 8s; animation-delay: 0.5s; width: 3px; height: 3px; }
.sd-5 { left: 70%; bottom: -10px; animation-duration: 11s; animation-delay: 3s; width: 6px; height: 6px; }
.sd-6 { left: 85%; bottom: -10px; animation-duration: 7.5s; animation-delay: 1.5s; }
.sd-7 { left: 15%; bottom: -10px; animation-duration: 12s; animation-delay: 4s; width: 3px; height: 3px; }
.sd-8 { left: 60%; bottom: -10px; animation-duration: 9.5s; animation-delay: 2.5s; width: 5px; height: 5px; }

@keyframes sparkleFloat {
  0% { transform: translateY(0) translateX(0) scale(1); opacity: 0; }
  10% { opacity: 0.7; }
  50% { opacity: 0.5; }
  100% { transform: translateY(-100vh) translateX(25px) scale(0); opacity: 0; }
}

/* --- AMBIENT PARTICLES --- */
.ambient-particles { position: fixed; inset: 0; pointer-events: none; z-index: 1; }
.ambient-particle {
  position: absolute; border-radius: 50%;
  animation: ambientDrift linear infinite; opacity: 0;
}
@keyframes ambientDrift {
  0% { transform: translateY(0) translateX(0) scale(0); opacity: 0; }
  15% { opacity: 0.6; transform: scale(1); }
  85% { opacity: 0.25; }
  100% { transform: translateY(-60vh) translateX(35px) scale(0); opacity: 0; }
}

/* --- WRAPPER --- */
.wrapper {
  width: 100%; max-width: 500px;
  padding: 20px 16px 30px;
  position: relative; z-index: 10;
}

/* --- HEADER --- */
.header-section { text-align: center; margin-bottom: 8px; padding: 20px 0 10px; }
.header-ornament {
  font-size: 16px;
  letter-spacing: 12px; margin-bottom: 8px;
  opacity: 0.7; animation: ornamentPulse 3s ease-in-out infinite;
}
@keyframes ornamentPulse {
  0%, 100% { opacity: 0.5; letter-spacing: 12px; }
  50% { opacity: 0.9; letter-spacing: 18px; }
}

.title {
  font-family: "Fredoka", "Kanit", sans-serif;
  font-size: 2.6rem; font-weight: 700;
  background: linear-gradient(135deg, #ff6b8a, #ffb6c8, #ffc107, #ffb6c8, #ff6b8a);
  background-size: 300% 300%;
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: titleShimmer 4s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(255, 107, 138, 0.4));
  line-height: 1.2; margin-bottom: 8px;
}
@keyframes titleShimmer {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.subtitle {
  font-family: "Kanit", sans-serif; font-size: 0.95rem;
  color: #c89aaa; letter-spacing: 1px; opacity: 0.8;
}

/* --- PIGGY DIVIDER --- */
.piggy-divider {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; margin: 12px 0 20px;
}
.divider-line { flex: 1; height: 2px; opacity: 0.4; }
.divider-line.left { background: linear-gradient(90deg, transparent, var(--piggy-pink)); }
.divider-line.right { background: linear-gradient(90deg, var(--piggy-pink), transparent); }
.piggy-icon {
  animation: piggyBounce 2s ease-in-out infinite;
  filter: drop-shadow(0 0 10px rgba(255, 107, 138, 0.5));
}
@keyframes piggyBounce {
  0%, 100% { transform: scale(1) translateY(0); }
  50% { transform: scale(1.1) translateY(-4px); }
}

/* --- TAP HINT --- */
.tap-hint {
  text-align: center; font-size: 0.95rem; color: #c89aaa;
  padding: 8px; margin-bottom: 16px;
  animation: hintPulse 2s ease-in-out infinite;
}
.tap-hint.hidden { display: none; }
.tap-icon { font-size: 1.2rem; display: inline-block; animation: tapBounce 1s ease-in-out infinite; }
@keyframes tapBounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes hintPulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }

/* =======================================
   HUTS GRID
======================================= */
.huts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  padding: 10px;
  margin-bottom: 20px;
}

/* --- HUT CARD --- */
.hut-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: transform 0.3s ease;
  border-radius: 16px;
  padding: 10px 8px;
  background: transparent;
  border: none;
  box-shadow: none;
}

.hut-card:hover {
  transform: translateY(-8px) scale(1.07);
}

.hut-card:active {
  transform: translateY(-2px) scale(0.97);
}

.hut-card.disabled {
  pointer-events: none;
  opacity: 0.25;
  filter: grayscale(0.7) brightness(0.4);
  transform: scale(0.88);
  transition: all 0.5s ease;
}

.hut-card.selected {
  animation: selectedBounce 0.8s ease-in-out;
}

@keyframes selectedBounce {
  0% { transform: scale(1); }
  25% { transform: scale(1.15) rotate(-3deg); }
  50% { transform: scale(0.95) rotate(2deg); }
  75% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* Hut image container */
.hut-img-wrap {
  position: relative;
  width: 85px;
  height: 100px;
  z-index: 2;
  animation: hutWobble 3s ease-in-out infinite;
}

.hut-card:nth-child(1) .hut-img-wrap { animation-delay: 0s; }
.hut-card:nth-child(2) .hut-img-wrap { animation-delay: 0.5s; }
.hut-card:nth-child(3) .hut-img-wrap { animation-delay: 1s; }
.hut-card:nth-child(4) .hut-img-wrap { animation-delay: 1.5s; }
.hut-card:nth-child(5) .hut-img-wrap { animation-delay: 0.3s; }
.hut-card:nth-child(6) .hut-img-wrap { animation-delay: 0.8s; }

@keyframes hutWobble {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-3px) rotate(1deg); }
  75% { transform: translateY(-2px) rotate(-1deg); }
}

.hut-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.4))
          drop-shadow(0 0 8px rgba(255, 107, 138, 0.15));
  transition: filter 0.3s;
}

.hut-card:hover .hut-img-wrap img {
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.4))
          drop-shadow(0 0 16px rgba(255, 182, 200, 0.35))
          brightness(1.15);
}

/* Hut number label */
.hut-number {
  margin-top: 6px;
  font-family: "Fredoka", "Kanit", sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: #ffb6c8;
  text-shadow: 0 0 8px rgba(255, 107, 138, 0.3);
  opacity: 0.8;
  z-index: 2;
}

/* Glow underneath hut */
.hut-glow {
  width: 50px; height: 12px;
  background: radial-gradient(ellipse, rgba(255, 107, 138, 0.3), transparent 70%);
  border-radius: 50%;
  margin-top: -2px;
  z-index: 1;
  animation: glowPulse 3s ease-in-out infinite;
}

@keyframes glowPulse {
  0%, 100% { opacity: 0.4; transform: scaleX(1); }
  50% { opacity: 0.8; transform: scaleX(1.3); }
}

/* =======================================
   HATCH AREA — Hut Opening Phase
======================================= */
.hatch-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0 10px;
  margin-bottom: 20px;
  transition: opacity 0.5s, max-height 0.5s;
}

.hatch-area.hidden {
  display: none;
}

.hatch-egg-container {
  position: relative;
  width: 160px;
  height: 200px;
  cursor: pointer;
  margin-bottom: 12px;
}

.hatch-egg-container img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 25px rgba(0, 0, 0, 0.4))
          drop-shadow(0 0 20px rgba(255, 107, 138, 0.2));
  transition: filter 0.2s;
}

/* Idle wobble for hut */
.hatch-egg-container.idle {
  animation: hutIdle 2s ease-in-out infinite;
}

@keyframes hutIdle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(2deg); }
  75% { transform: rotate(-2deg); }
}

/* Shake on tap */
.hatch-egg-container.shaking {
  animation: hutShake 0.12s ease-in-out infinite alternate;
}

@keyframes hutShake {
  0% { transform: translateX(-5px) rotate(-3deg); }
  25% { transform: translateX(5px) rotate(3deg); }
  50% { transform: translateX(-4px) rotate(-2deg); }
  75% { transform: translateX(4px) rotate(2deg); }
  100% { transform: translateX(0) rotate(0); }
}

/* Intensive shake before open */
.hatch-egg-container.intense-shake {
  animation: intenseShake 0.06s ease-in-out infinite alternate;
}

@keyframes intenseShake {
  0% { transform: translateX(-7px) rotate(-5deg) scale(1.05); }
  25% { transform: translateX(7px) rotate(5deg) scale(1.08); }
  50% { transform: translateX(-5px) rotate(-4deg) scale(1.06); }
  75% { transform: translateX(5px) rotate(4deg) scale(1.07); }
  100% { transform: translateX(0) rotate(0) scale(1.1); }
}

/* Hut open away */
.hatch-egg-container.hatching {
  animation: hutBurnBurst 0.7s ease-out forwards;
}

@keyframes hutBurnBurst {
  0% { transform: scale(1.1); opacity: 1; }
  30% { transform: scale(1.2) translateY(-20px); filter: brightness(0.2) sepia(1) hue-rotate(-50deg); opacity: 0.9; }
  100% { transform: scale(0.5) translateY(-50px); filter: brightness(0) blur(10px); opacity: 0; }
}

/* Fire overlay on top of hut */
  .burn-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
  }

  .burn-overlay.visible {
    opacity: 1;
  }

  .burn-flame {
    position: absolute;
    bottom: 20px;
    width: 20px; height: 35px;
    background: radial-gradient(ellipse at bottom, rgba(255,180,0,0.8) 0%, rgba(255,80,0,0.6) 40%, rgba(255,0,0,0.3) 80%, transparent 100%);
    border-radius: 50% 50% 20% 20%;
    filter: blur(2px);
    opacity: 0;
    transform-origin: center bottom;
    animation: flameFlicker 0.4s infinite alternate ease-in-out;
    mix-blend-mode: screen;
  }
  
  @keyframes flameFlicker {
    0% { transform: scale(1) translateX(0px); opacity: 0.7; }
    50% { transform: scale(1.1) translateX(2px); opacity: 0.9; }
    100% { transform: scale(0.9) translateX(-2px); opacity: 1; }
}

/* Energy swirl around hut during opening */
.energy-ring {
  position: absolute;
  top: 50%; left: 50%;
  width: 120px; height: 120px;
  transform: translate(-50%, -50%);
  border: 2px solid transparent;
  border-top-color: #ff4500;
  border-bottom-color: #ff8c00;
  border-radius: 50%;
  opacity: 0;
  z-index: 5;
  pointer-events: none;
}

.energy-ring.active {
  opacity: 0.6;
  animation: energySpin 1.2s linear infinite;
}

.energy-ring.ring2 {
  width: 150px; height: 150px;
  animation-direction: reverse;
  animation-duration: 1.8s;
  border-top-color: #ff8c00;
  border-bottom-color: #ff0000;
}

@keyframes energySpin {
  from { transform: translate(-50%, -50%) rotate(0deg); }
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Fire particles around hut */
.fire-particle {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 6;
}

/* Hatch progress bar */
.hatch-progress {
  width: 140px; height: 10px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 8px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

.hatch-progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--piggy-pink), var(--piggy-gold), #fff);
  border-radius: 5px;
  transition: width 0.2s ease;
  box-shadow: 0 0 12px rgba(255, 107, 138, 0.6);
}

.hatch-text {
  font-size: 0.9rem;
  color: #c89aaa;
  animation: hintPulse 2s ease-in-out infinite;
}

/* =======================================
   PIG REVEAL
======================================= */
.reveal-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
  min-height: 260px;
}

.reveal-area.hidden { display: none; }

/* =======================================
   PIG EMERGENCE CINEMATIC
======================================= */
.dragon-emergence {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0 20px;
  position: relative;
}

.emerge-wrap {
  position: relative;
  width: 260px;
  height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Radial aura behind pig */
.emerge-aura {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  animation: auraAppear 0.8s ease-out 0.6s forwards, auraPulse 2s ease-in-out 1.4s infinite alternate;
}
@keyframes auraAppear {
  from { opacity: 0; transform: scale(0.4); }
  to   { opacity: 0.75; transform: scale(1); }
}
@keyframes auraPulse {
  from { opacity: 0.5; transform: scale(0.92); }
  to   { opacity: 0.95; transform: scale(1.08); }
}

/* Rotating light rays */
.emerge-rays {
  position: absolute;
  inset: -40px;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transform-origin: center center;
  animation:
    raysAppear 1s cubic-bezier(0.22, 1, 0.36, 1) 0.85s forwards,
    raysSpin 9s linear 0.85s infinite,
    raysPulse 3s ease-in-out 1.85s infinite alternate;
}
@keyframes raysAppear {
  0%   { opacity: 0; transform: scale(0.35) rotate(0deg); }
  60%  { opacity: 0.8; transform: scale(1.06) rotate(20deg); }
  100% { opacity: 0.72; transform: scale(1) rotate(30deg); }
}
@keyframes raysSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes raysPulse {
  from { opacity: 0.55; }
  to   { opacity: 0.82; }
}

/* Counter-rotating inner star ring */
.emerge-rays-inner {
  position: absolute;
  inset: -40px;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transform-origin: center center;
  animation:
    raysInnerAppear 0.8s cubic-bezier(0.22, 1, 0.36, 1) 1.1s forwards,
    raysSpinReverse 5.5s linear 1.1s infinite,
    raysPulse 2.5s ease-in-out 1.9s infinite alternate-reverse;
}
@keyframes raysInnerAppear {
  0%   { opacity: 0; transform: scale(0.2) rotate(0deg); }
  70%  { opacity: 0.9; transform: scale(1.08) rotate(-18deg); }
  100% { opacity: 0.75; transform: scale(1) rotate(-22deg); }
}
@keyframes raysSpinReverse {
  from { transform: rotate(0deg); }
  to   { transform: rotate(-360deg); }
}

/* Pig image emerging */
.emerge-dragon-img {
  position: relative;
  z-index: 2;
  width: 230px;
  height: 230px;
  object-fit: contain;
  animation: pigEmerge 1.3s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes pigEmerge {
  0%   { transform: scale(0.04) translateY(40px); opacity: 0;   filter: brightness(12) blur(35px) saturate(3); }
  20%  { transform: scale(0.3)  translateY(20px); opacity: 1;   filter: brightness(6) blur(14px); }
  55%  { transform: scale(0.88) translateY(-6px);               filter: brightness(2.5) blur(4px); }
  80%  { transform: scale(1.1)  translateY(-10px);              filter: brightness(1.4) blur(0); }
  100% { transform: scale(1)    translateY(0);                  filter: brightness(1) blur(0); }
}

/* Name */
.emerge-name {
  margin-top: 14px;
  font-family: "Fredoka", "Kanit", sans-serif;
  font-size: 1.7rem; font-weight: 700;
  text-align: center;
  letter-spacing: 1px;
  opacity: 0;
  animation: slideUpFade 0.65s ease-out 1.05s forwards;
}

/* Rarity badge */
.emerge-rarity {
  margin-top: 7px;
  font-family: "Kanit", sans-serif;
  font-size: 0.85rem; letter-spacing: 3px; text-transform: uppercase;
  padding: 4px 18px;
  border: 1px solid;
  border-radius: 20px;
  opacity: 0;
  animation: slideUpFade 0.65s ease-out 1.3s forwards;
}

/* Stars */
.emerge-stars {
  display: flex; gap: 4px;
  justify-content: center;
  margin-top: 10px;
  opacity: 0;
  animation: slideUpFade 0.5s ease-out 1.5s forwards;
}
.emerge-stars span {
  display: inline-block;
  font-size: 1.3rem;
  animation: starPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes starPop {
  from { transform: scale(0) rotate(-30deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}

@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =======================================
   PIG REVEAL (popup area)
======================================= */
.dragon-reveal {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: pigRevealAnim 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pigRevealAnim {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(5deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); }
}

.dragon-reveal img {
  width: 200px; height: 200px;
  object-fit: contain;
  filter: drop-shadow(0 0 40px var(--dragon-glow, rgba(255, 107, 138, 0.6)));
}

.dragon-reveal .dragon-name {
  margin-top: 14px;
  font-family: "Fredoka", "Kanit", sans-serif;
  font-size: 1.4rem; font-weight: 700;
  text-shadow: 0 0 20px var(--dragon-glow, rgba(255, 107, 138, 0.6));
}

/* Magic ring burst on open */
.magic-ring {
  position: absolute;
  top: 50%; left: 50%;
  width: 20px; height: 20px;
  border: 3px solid var(--piggy-pink);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  z-index: 30;
  pointer-events: none;
  animation: magicRingExpand 0.8s ease-out forwards;
}

@keyframes magicRingExpand {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 1; border-width: 4px; }
  100% { transform: translate(-50%, -50%) scale(10); opacity: 0; border-width: 1px; }
}

/* =======================================
   EXPLOSION & PARTICLES
======================================= */
.hatch-explosion {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 100;
}

.hatch-particle {
  position: absolute; border-radius: 50%; pointer-events: none;
}

.shell-fragment {
  position: absolute; z-index: 5; pointer-events: none;
  animation: shellFly 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes shellFly {
  0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) rotate(var(--rot)) scale(0.3); }
}

.screen-flash {
  position: fixed; inset: 0; z-index: 99;
  pointer-events: none;
  animation: screenFlash 0.6s ease-out forwards;
}

@keyframes screenFlash {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* =======================================
   INFO SECTION
======================================= */
.info-section {
  background: linear-gradient(135deg, rgba(40, 20, 45, 0.9), rgba(30, 15, 35, 0.8));
  border: 1px solid rgba(255, 107, 138, 0.15);
  border-radius: 16px; padding: 20px;
  margin-top: 10px; text-align: center;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 182, 200, 0.1);
}
.info-header {
  font-family: "Fredoka", "Kanit", sans-serif;
  font-size: 1.1rem; color: var(--piggy-pink);
  margin-bottom: 12px;
  text-shadow: 0 0 10px rgba(255, 107, 138, 0.3);
}
.info-body { font-size: 0.85rem; line-height: 1.8; color: #c89aaa; }
.gold-text { color: var(--piggy-gold); font-weight: bold; text-shadow: 0 0 8px rgba(255, 193, 7, 0.4); }
.info-highlight { color: #f0d8e0; font-weight: bold; }
.info-sub { font-size: 0.8rem; color: #8a6a7a; }

/* =======================================
   POPUP MODAL
======================================= */
.popup { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.popup.hidden { display: none; }

.popup-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  animation: backdropFadeIn 0.3s ease;
}
@keyframes backdropFadeIn { from { opacity: 0; } to { opacity: 1; } }

.popup-box {
  position: relative;
  background: linear-gradient(160deg, #2d1535 0%, #1a0f1e 50%, #251030 100%);
  border: 2px solid rgba(255, 107, 138, 0.3);
  border-radius: 24px; padding: 32px 24px;
  width: 100%; max-width: 380px; text-align: center;
  animation: popupAppear 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  box-shadow: 0 0 40px rgba(255, 107, 138, 0.15), 0 0 80px rgba(255, 182, 200, 0.05),
              inset 0 1px 0 rgba(255, 182, 200, 0.2);
  overflow: hidden;
}
.popup-box::before {
  content: '';
  position: absolute; top: -50%; left: -50%; width: 200%; height: 200%;
  background: conic-gradient(from 0deg, transparent, rgba(255, 107, 138, 0.04), transparent, rgba(255, 193, 7, 0.04), transparent);
  animation: popupRotateGlow 6s linear infinite;
  z-index: 0;
}
@keyframes popupRotateGlow { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes popupAppear {
  from { transform: scale(0.5) translateY(40px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.popup-dragon {
  position: relative; z-index: 1;
  margin-bottom: 16px;
}
.popup-dragon img {
  width: 160px; height: 160px; object-fit: contain;
  filter: drop-shadow(0 0 30px var(--dragon-glow, rgba(255, 107, 138, 0.6)));
}

.popup-title {
  position: relative; z-index: 1;
  font-family: "Fredoka", "Kanit", sans-serif;
  font-size: 1.5rem; font-weight: 700; margin-bottom: 6px;
  background: linear-gradient(135deg, var(--piggy-pink), var(--piggy-gold));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.popup-rarity {
  position: relative; z-index: 1;
  font-size: 0.85rem; letter-spacing: 3px; text-transform: uppercase;
  margin-bottom: 12px; padding: 4px 16px;
  display: inline-block; border-radius: 20px;
  border: 1px solid rgba(255, 107, 138, 0.3);
  background: rgba(255, 107, 138, 0.05);
}
.popup-reward {
  position: relative; z-index: 1;
  font-family: "Fredoka", "Kanit", sans-serif;
  font-size: 2rem; font-weight: 900;
  color: var(--piggy-gold); margin: 12px 0;
  text-shadow: 0 0 20px rgba(255, 193, 7, 0.5);
  animation: rewardPulse 1.5s ease-in-out infinite;
}
@keyframes rewardPulse {
  0%, 100% { transform: scale(1); text-shadow: 0 0 20px rgba(255, 193, 7, 0.5); }
  50% { transform: scale(1.05); text-shadow: 0 0 30px rgba(255, 193, 7, 0.8); }
}
.popup-desc {
  position: relative; z-index: 1;
  font-size: 0.85rem; color: #c89aaa;
  margin-bottom: 20px; line-height: 1.6; font-style: italic;
}
.popup-btn {
  position: relative; z-index: 1;
  background: linear-gradient(135deg, var(--piggy-pink), var(--piggy-hot));
  color: #fff; border: none;
  padding: 14px 40px;
  font-family: "Fredoka", "Kanit", sans-serif;
  font-size: 1rem; font-weight: 700;
  border-radius: 50px;
  cursor: pointer; transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(255, 51, 102, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  letter-spacing: 1px;
}
.popup-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(255, 51, 102, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.popup-btn:active { transform: translateY(0); }

/* =======================================
   CONFETTI & STARS
======================================= */
.confetti-canvas {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 999;
  width: 100%; height: 100%;
}
.rarity-stars { display: flex; justify-content: center; gap: 4px; margin-bottom: 8px; position: relative; z-index: 1; }
.rarity-star {
  font-size: 1.2rem;
  -webkit-text-fill-color: initial;
  animation: starPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  opacity: 0; transform: scale(0);
}
.rarity-star:nth-child(1) { animation-delay: 0.1s; }
.rarity-star:nth-child(2) { animation-delay: 0.2s; }
.rarity-star:nth-child(3) { animation-delay: 0.3s; }
.rarity-star:nth-child(4) { animation-delay: 0.4s; }
.rarity-star:nth-child(5) { animation-delay: 0.5s; }

/* Sparkles */
.sparkle {
  position: absolute; width: 4px; height: 4px;
  background: var(--piggy-pink); border-radius: 50%;
  pointer-events: none; z-index: 50;
  animation: sparkleAnim 0.6s ease-out forwards;
}
@keyframes sparkleAnim {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--sx), var(--sy)) scale(0); opacity: 0; }
}

/* =======================================
   POST-GAME RESULT CARD
======================================= */
.result-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 20px 32px;
  animation: popupAppear 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.result-card-img {
  width: 180px;
  height: 180px;
  object-fit: contain;
}
.result-card-name {
  margin-top: 16px;
  font-family: "Fredoka", "Kanit", sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
}
.result-card-rarity {
  margin-top: 6px;
  font-family: "Kanit", sans-serif;
  font-size: 0.82rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  padding: 4px 16px;
  border: 1px solid;
  border-radius: 20px;
}
.result-card-reward {
  margin-top: 14px;
  font-family: "Fredoka", "Kanit", sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--piggy-gold);
}
.result-card-stars {
  margin-top: 8px;
  font-size: 1.2rem;
  letter-spacing: 2px;
}

/* =======================================
   REWARD TABLE BUTTON
======================================= */
.reward-table-btn {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 500;
  background: linear-gradient(135deg, rgba(45, 21, 53, 0.92), rgba(26, 15, 30, 0.92));
  color: var(--piggy-pink);
  border: 1px solid rgba(255, 107, 138, 0.45);
  padding: 8px 16px;
  font-family: "Fredoka", "Kanit", sans-serif;
  font-size: 0.82rem; font-weight: 600;
  border-radius: 50px;
  cursor: pointer; transition: all 0.25s ease;
  letter-spacing: 0.5px;
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 16px rgba(255, 107, 138, 0.12), 0 1px 4px rgba(0,0,0,0.5);
}
.reward-table-btn:hover {
  background: linear-gradient(135deg, rgba(60, 25, 70, 0.95), rgba(35, 18, 45, 0.95));
  border-color: rgba(255, 107, 138, 0.9);
  box-shadow: 0 0 32px rgba(255, 107, 138, 0.4), 0 2px 8px rgba(0,0,0,0.5);
  transform: translateY(-2px) scale(1.04);
}
.reward-table-btn:active { transform: translateY(0) scale(0.97); }

/* =======================================
   REWARD TABLE MODAL
======================================= */
.reward-modal {
  position: fixed; inset: 0; z-index: 1100;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.reward-modal.hidden { display: none; }

.reward-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(10px);
  animation: backdropFadeIn 0.25s ease;
}

.reward-modal-box {
  position: relative; z-index: 1;
  background: linear-gradient(160deg, #2d1535 0%, #1a0f1e 60%, #251030 100%);
  border: 1.5px solid rgba(255, 107, 138, 0.3);
  border-radius: 20px;
  width: 100%; max-width: 420px;
  max-height: 88vh;
  display: flex; flex-direction: column;
  animation: popupAppear 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 0 50px rgba(255, 107, 138, 0.12), 0 0 100px rgba(255, 182, 200, 0.05);
  overflow: hidden;
}

.reward-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(255, 107, 138, 0.15);
  flex-shrink: 0;
}
.reward-modal-title {
  font-family: "Fredoka", "Kanit", sans-serif;
  font-size: 1.1rem; font-weight: 700;
  background: linear-gradient(135deg, var(--piggy-pink), var(--piggy-gold));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  letter-spacing: 1px;
}
.reward-modal-close {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #aaa; border-radius: 50%;
  width: 32px; height: 32px; font-size: 0.9rem;
  cursor: pointer; transition: all 0.2s ease;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.reward-modal-close:hover { background: rgba(255, 60, 60, 0.2); color: #ff6060; border-color: rgba(255, 60, 60, 0.4); }

.reward-modal-body {
  overflow-y: auto; padding: 12px 14px 18px;
  scrollbar-width: thin; scrollbar-color: rgba(255, 107, 138, 0.3) transparent;
}
.reward-modal-body::-webkit-scrollbar { width: 4px; }
.reward-modal-body::-webkit-scrollbar-thumb { background: rgba(255, 107, 138, 0.3); border-radius: 4px; }

/* Individual reward rows */
.reward-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px;
  border-radius: 12px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: background 0.2s;
}
.reward-row:hover { background: rgba(255, 107, 138, 0.06); border-color: rgba(255, 107, 138, 0.15); }
.reward-row.is-loss { opacity: 0.65; }

.reward-row-img {
  width: 48px; height: 48px; object-fit: contain;
  filter: drop-shadow(0 0 6px var(--row-glow, rgba(255,107,138,0.4)));
  flex-shrink: 0;
}
.reward-row-info { flex: 1; min-width: 0; }
.reward-row-name {
  font-family: "Kanit", sans-serif; font-size: 0.9rem; font-weight: 600;
  color: #f0d8e0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reward-row-element {
  font-size: 0.72rem; color: #8a6a7a; margin-top: 1px;
}
.reward-row-rarity {
  font-size: 0.7rem; letter-spacing: 1px;
  padding: 2px 8px; border-radius: 20px;
  border: 1px solid; background: rgba(0,0,0,0.2);
  white-space: nowrap; flex-shrink: 0;
}
.reward-row-amount {
  font-family: "Fredoka", "Kanit", sans-serif; font-weight: 800;
  font-size: 1rem; text-align: right;
  white-space: nowrap; flex-shrink: 0;
  min-width: 64px;
}
.reward-row.is-loss .reward-row-amount { color: #888; }

/* =======================================
   RESPONSIVE
======================================= */
@media (max-width: 380px) {
  .huts-grid { gap: 10px; padding: 5px; }
  .hut-img-wrap { width: 68px; height: 85px; }
  .title { font-size: 2rem; }
  .hatch-egg-container { width: 130px; height: 165px; }
}
@media (min-width: 600px) {
  .huts-grid { gap: 24px; }
  .hut-img-wrap { width: 100px; height: 120px; }
  .hatch-egg-container { width: 180px; height: 230px; }
}
