/* =============================================================
   COFFRES / CADEAUX — Modale d'ouverture style Brawl Stars
   ============================================================= */

.giftbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 200000;
  display: none;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.giftbox-overlay.active { display: flex; }

.giftbox-stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  --rarity-color: #888;
  --rarity-glow: rgba(180,180,200,0.7);
}

/* ============== Background : flare radial ============== */
.giftbox-bg-flare {
  position: absolute;
  inset: -20%;
  background: radial-gradient(circle at center,
    var(--rarity-glow) 0%,
    rgba(0,0,0,0) 55%);
  opacity: 0.18;
  pointer-events: none;
  transition: opacity 0.6s ease;
}
.giftbox-stage[data-phase="charging"] .giftbox-bg-flare,
.giftbox-stage[data-phase="explode"] .giftbox-bg-flare,
.giftbox-stage[data-phase="reveal"] .giftbox-bg-flare {
  opacity: 0.5;
}
.giftbox-stage[data-rarity="legendary"] .giftbox-bg-flare {
  animation: bgFlarePulse 1.6s ease-in-out infinite;
}
@keyframes bgFlarePulse {
  0%, 100% { opacity: 0.35; }
  50%      { opacity: 0.7; }
}

/* ============== Faisceau de lumiere vertical (legendary) ============== */
.giftbox-light-shaft {
  position: absolute;
  top: -10%;
  left: 50%;
  transform: translateX(-50%) scaleY(0);
  width: 220px;
  height: 130%;
  background: linear-gradient(to bottom,
    rgba(255,255,255,0) 0%,
    var(--rarity-glow) 35%,
    var(--rarity-glow) 65%,
    rgba(255,255,255,0) 100%);
  filter: blur(6px);
  opacity: 0;
  transform-origin: top center;
  pointer-events: none;
  transition: opacity 0.4s ease;
  mix-blend-mode: screen;
}
.giftbox-stage[data-rarity="epic"] .giftbox-light-shaft,
.giftbox-stage[data-rarity="legendary"] .giftbox-light-shaft {
  display: block;
}
.giftbox-stage[data-rarity="legendary"][data-phase="charging"] .giftbox-light-shaft,
.giftbox-stage[data-rarity="epic"][data-phase="charging"] .giftbox-light-shaft {
  opacity: 0.7;
  transform: translateX(-50%) scaleY(1);
  animation: shaftPulse 1.3s ease-in-out infinite;
}
@keyframes shaftPulse {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 0.9; }
}

/* ============== Rayons rotatifs derriere le coffre ============== */
.giftbox-rays {
  position: absolute;
  width: 800px;
  height: 800px;
  background: conic-gradient(from 0deg,
    transparent 0deg, var(--rarity-glow) 8deg, transparent 16deg,
    transparent 30deg, var(--rarity-glow) 38deg, transparent 46deg,
    transparent 60deg, var(--rarity-glow) 68deg, transparent 76deg,
    transparent 90deg, var(--rarity-glow) 98deg, transparent 106deg,
    transparent 120deg, var(--rarity-glow) 128deg, transparent 136deg,
    transparent 150deg, var(--rarity-glow) 158deg, transparent 166deg,
    transparent 180deg, var(--rarity-glow) 188deg, transparent 196deg,
    transparent 210deg, var(--rarity-glow) 218deg, transparent 226deg,
    transparent 240deg, var(--rarity-glow) 248deg, transparent 256deg,
    transparent 270deg, var(--rarity-glow) 278deg, transparent 286deg,
    transparent 300deg, var(--rarity-glow) 308deg, transparent 316deg,
    transparent 330deg, var(--rarity-glow) 338deg, transparent 346deg);
  filter: blur(10px);
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
  mix-blend-mode: screen;
}
.giftbox-stage[data-phase="reveal"] .giftbox-rays,
.giftbox-stage[data-phase="explode"] .giftbox-rays {
  opacity: 0.18;
  animation: raysSpin 12s linear infinite;
}
.giftbox-stage[data-rarity="legendary"][data-phase="reveal"] .giftbox-rays {
  opacity: 0.35;
  animation: raysSpin 8s linear infinite;
}
@keyframes raysSpin {
  to { transform: rotate(360deg); }
}

/* ============== La boite ============== */
.giftbox-box-wrap {
  position: relative;
  width: 320px;
  height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.giftbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 12px 24px rgba(0,0,0,0.7))
          drop-shadow(0 0 24px var(--rarity-glow));
  transition: filter 0.3s ease, transform 0.3s ease;
}

/* Phase: await-tap — flotte doucement */
.giftbox-stage[data-phase="await-tap"] .giftbox-img,
.giftbox-stage[data-phase=""] .giftbox-img {
  animation: boxFloat 2.4s ease-in-out infinite;
}
@keyframes boxFloat {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50%      { transform: translateY(-15px) rotate(2deg); }
}

/* Phase: buildup — tremblement leger */
.giftbox-stage[data-phase="buildup"] .giftbox-img {
  animation: boxShakeLight 0.12s linear infinite;
}
@keyframes boxShakeLight {
  0%   { transform: translate(-2px, 0)  rotate(-1deg); }
  25%  { transform: translate(2px, -1px) rotate(1deg); }
  50%  { transform: translate(-1px, 1px) rotate(-2deg); }
  75%  { transform: translate(1px, 0)  rotate(2deg); }
  100% { transform: translate(-2px, -1px) rotate(-1deg); }
}

/* Phase: charging — tremblement intense + glow pulsant */
.giftbox-stage[data-phase="charging"] .giftbox-img {
  animation: boxShakeHard 0.08s linear infinite,
             boxGlowPulse 0.6s ease-in-out infinite;
}
@keyframes boxShakeHard {
  0%   { transform: translate(-5px, -2px) rotate(-3deg); }
  20%  { transform: translate(5px, 3px)   rotate(4deg); }
  40%  { transform: translate(-3px, 4px)  rotate(-4deg); }
  60%  { transform: translate(4px, -3px)  rotate(3deg); }
  80%  { transform: translate(-4px, 2px)  rotate(-2deg); }
  100% { transform: translate(3px, -2px)  rotate(2deg); }
}
@keyframes boxGlowPulse {
  0%, 100% { filter: drop-shadow(0 12px 24px rgba(0,0,0,0.7))
                     drop-shadow(0 0 32px var(--rarity-glow)); }
  50%      { filter: drop-shadow(0 12px 24px rgba(0,0,0,0.7))
                     drop-shadow(0 0 80px var(--rarity-glow))
                     drop-shadow(0 0 50px var(--rarity-glow)); }
}

/* Phase: explode — disparition flash */
.giftbox-stage[data-phase="explode"] .giftbox-box-wrap {
  animation: boxExplode 0.7s cubic-bezier(0.6, 0, 0.4, 1) forwards;
}
@keyframes boxExplode {
  0%   { transform: scale(1) rotate(0deg); opacity: 1; filter: brightness(1); }
  20%  { transform: scale(1.5) rotate(-8deg); opacity: 1; filter: brightness(2.5); }
  60%  { transform: scale(2.2) rotate(15deg); opacity: 0.6; filter: brightness(3); }
  100% { transform: scale(2.8) rotate(0deg); opacity: 0; filter: brightness(1); }
}

/* Phase: reveal/done — coffre cache */
.giftbox-stage[data-phase="reveal"] .giftbox-box-wrap,
.giftbox-stage[data-phase="done"] .giftbox-box-wrap {
  display: none;
}

/* ============== Pulse halo derriere le coffre ============== */
.giftbox-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, var(--rarity-glow) 0%, transparent 70%);
  opacity: 0.6;
  pointer-events: none;
  transform: scale(0.9);
}
.giftbox-stage[data-phase="charging"] .giftbox-pulse {
  animation: pulseHalo 0.8s ease-in-out infinite;
}
@keyframes pulseHalo {
  0%, 100% { transform: scale(0.9); opacity: 0.6; }
  50%      { transform: scale(1.4); opacity: 0.9; }
}

/* ============== Tag rarete au dessus du coffre ============== */
.giftbox-rarity-tag {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 22px;
  border-radius: 18px;
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.6);
  border: 2px solid rgba(255,255,255,0.3);
  white-space: nowrap;
  transition: opacity 0.4s ease;
}

/* ============== Particules ============== */
.giftbox-particles {
  position: absolute;
  width: 0; height: 0;
  pointer-events: none;
  z-index: 4;
}
.giftbox-particle {
  position: absolute;
  border-radius: 50%;
  animation: particleFly 1.4s cubic-bezier(0.2, 0.8, 0.4, 1) forwards;
  pointer-events: none;
}
@keyframes particleFly {
  0%   { transform: translate(0, 0) scale(0.4); opacity: 1; }
  60%  { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

/* ============== Carte de revelation ============== */
.giftbox-reveal {
  position: relative;
  z-index: 6;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  pointer-events: none;
}
.giftbox-reveal.show {
  display: flex;
}

.giftbox-reveal-card {
  position: relative;
  width: 360px;
  padding: 36px 28px 26px;
  border-radius: 22px;
  background: linear-gradient(160deg,
    rgba(20, 20, 36, 0.97),
    rgba(40, 40, 70, 0.95));
  border: 3px solid var(--rarity-color);
  text-align: center;
  transform: scale(0.4) translateY(40px);
  opacity: 0;
  transition: transform 0.6s cubic-bezier(0.2, 1.4, 0.4, 1.0),
              opacity 0.4s ease;
  --rarity-color: #888;
  --rarity-glow: rgba(180,180,200,0.7);
  box-shadow: 0 18px 60px rgba(0,0,0,0.7),
              0 0 40px var(--rarity-glow);
}
.giftbox-reveal-card.show {
  transform: scale(1) translateY(0);
  opacity: 1;
}
.giftbox-reveal-card[data-glow="legendary"] {
  animation: legendaryCardPulse 1.6s ease-in-out infinite;
}
@keyframes legendaryCardPulse {
  0%, 100% { box-shadow: 0 18px 60px rgba(0,0,0,0.7),
                         0 0 40px var(--rarity-glow); }
  50%      { box-shadow: 0 18px 60px rgba(0,0,0,0.7),
                         0 0 80px var(--rarity-glow),
                         0 0 120px var(--rarity-glow); }
}

.giftbox-reveal-glow {
  position: absolute;
  inset: -12px;
  border-radius: 24px;
  background: radial-gradient(circle, var(--rarity-glow) 0%, transparent 70%);
  filter: blur(12px);
  opacity: 0.5;
  z-index: -1;
  pointer-events: none;
}

.giftbox-reveal-img {
  width: 130px;
  height: 130px;
  object-fit: contain;
  margin: 0 auto 14px;
  display: block;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,0.6))
          drop-shadow(0 0 18px var(--rarity-glow));
  background: rgba(0,0,0,0.3);
  border-radius: 14px;
  padding: 10px;
}

.giftbox-reveal-name {
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 6px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.giftbox-reveal-sub {
  color: var(--rarity-color);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.giftbox-reveal-counter {
  color: rgba(255,255,255,0.6);
  font-size: 13px;
  font-weight: 600;
  pointer-events: auto;
}

/* ============== CTA + boutons ============== */
.giftbox-cta {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
}
.giftbox-tap-hint {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.4);
  padding: 14px 32px;
  border-radius: 30px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
  text-transform: uppercase;
  animation: hintBlink 1.4s ease-in-out infinite;
  pointer-events: none;
}
@keyframes hintBlink {
  0%, 100% { opacity: 0.7; }
  50%      { opacity: 1; }
}

.giftbox-finish-btn {
  background: linear-gradient(135deg, #FFD700, #FFA500);
  color: #000;
  border: none;
  padding: 14px 36px;
  border-radius: 28px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 10px 30px rgba(255, 215, 0, 0.5);
  transition: transform 0.2s ease;
  margin-top: 10px;
}
.giftbox-finish-btn:hover {
  transform: scale(1.06) translateY(-2px);
}

.giftbox-skip,
.giftbox-close {
  position: absolute;
  z-index: 10;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 22px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}
.giftbox-skip {
  bottom: 24px;
  right: 24px;
}
.giftbox-close {
  top: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 24px;
}
.giftbox-skip:hover,
.giftbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ============== Responsive ============== */
@media (max-width: 768px) {
  .giftbox-box-wrap { width: 240px; height: 240px; }
  .giftbox-reveal-card { width: 90%; max-width: 320px; }
  .giftbox-reveal-img { width: 100px; height: 100px; }
}
