/* The unopened pack and its opening animation.
   Swap the foil background for real pack art later.

   Opening sequence (all timed here, see also the timings in js/main.js):
     0.00s  pack shakes harder and harder, glowing
     0.90s  top strip tears off, light rays shoot out
     1.25s  pack drops away, white flash, sparks
     1.55s  cards fly out of where the pack was                          */

.pack-stage {
  --foil:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.35), transparent 45%),
    repeating-linear-gradient(135deg, rgba(255,255,255,.08) 0 14px, transparent 14px 28px),
    linear-gradient(160deg, #ff9a3c, #e8452f 60%, #b3202f);
  /* jagged foil edges and the torn line (strip height = 64px) */
  --crimp-top: 0 12px, 5% 0, 10% 12px, 15% 0, 20% 12px, 25% 0, 30% 12px, 35% 0, 40% 12px, 45% 0, 50% 12px, 55% 0, 60% 12px, 65% 0, 70% 12px, 75% 0, 80% 12px, 85% 0, 90% 12px, 95% 0, 100% 12px;
  --crimp-bottom: 100% calc(100% - 12px), 95% 100%, 90% calc(100% - 12px), 85% 100%, 80% calc(100% - 12px), 75% 100%, 70% calc(100% - 12px), 65% 100%, 60% calc(100% - 12px), 55% 100%, 50% calc(100% - 12px), 45% 100%, 40% calc(100% - 12px), 35% 100%, 30% calc(100% - 12px), 25% 100%, 20% calc(100% - 12px), 15% 100%, 10% calc(100% - 12px), 5% 100%, 0 calc(100% - 12px);
  --tear-lr: 0 60px, 10% 68px, 20% 60px, 30% 68px, 40% 60px, 50% 68px, 60% 60px, 70% 68px, 80% 60px, 90% 68px, 100% 60px;
  --tear-rl: 100% 60px, 90% 68px, 80% 60px, 70% 68px, 60% 60px, 50% 68px, 40% 60px, 30% 68px, 20% 60px, 10% 68px, 0 60px;

  position: relative;
  width: 220px;
  height: 310px;
  /* shadow lives here because the jagged clip-path would cut it off */
  filter: drop-shadow(0 22px 28px rgba(0, 0, 0, 0.55));
  animation: float 3.2s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}

/* light rays (hidden until the tear) */
.pack-rays {
  position: absolute;
  z-index: 0;
  left: 50%;
  top: 12%;
  width: 640px;
  height: 640px;
  margin: -320px 0 0 -320px;
  pointer-events: none;
  opacity: 0;
  background: repeating-conic-gradient(rgba(255, 232, 160, 0.75) 0 7deg, transparent 7deg 24deg);
  -webkit-mask-image: radial-gradient(circle, #000 0%, transparent 66%);
          mask-image: radial-gradient(circle, #000 0%, transparent 66%);
}

.pack-shaker { position: relative; z-index: 1; width: 100%; height: 100%; transition: transform 0.2s; }
.pack-stage:not(.opening):not(.empty) .pack-shaker:hover { transform: scale(1.05) rotate(-2deg); }

.pack {
  position: absolute;
  inset: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
  border: 0;
  cursor: pointer;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  font-family: var(--font-display);
  background: var(--foil);
  clip-path: polygon(var(--crimp-top), var(--crimp-bottom));
}
.pack::before {                           /* inner frame line */
  content: "";
  position: absolute;
  inset: 22px 14px;
  border: 3px solid rgba(255, 255, 255, 0.45);
  border-radius: 10px;
}
.pack::after {                            /* light sweeping across the foil */
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.5) 50%, transparent 65%);
  transform: translateX(-120%);
  animation: sweep 3.6s ease-in-out infinite;
}
@keyframes sweep {
  0%, 55% { transform: translateX(-120%); }
  100%    { transform: translateX(120%); }
}

.pack-title { position: relative; font-size: 5rem; line-height: 1; text-shadow: 0 5px 0 rgba(0, 0, 0, 0.28); }
.pack-sub {
  position: relative;
  align-self: stretch;
  margin: 0.4rem 0 0;
  padding: 0.25rem 0;
  font-size: 1.5rem;
  background: rgba(0, 0, 0, 0.28);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}
.pack-count { position: relative; font-family: var(--font-body); font-weight: 800; font-size: 0.9rem; opacity: 0.9; margin-top: 1.1rem; }

/* The strip that gets torn off the top */
.pack-top {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 68px;
  pointer-events: none;
  background: var(--foil);
  background-size: 220px 310px;
  background-position: 0 0;
  clip-path: polygon(var(--crimp-top), var(--tear-rl));
  transform-origin: 0% 100%;
}

/* ---------- Opening sequence ---------- */
.pack-stage.opening { animation-play-state: paused; }
.opening .pack::after { animation: none; }

.opening .pack-shaker { animation: shake 0.9s ease-in forwards; }
@keyframes shake {
  0%   { transform: rotate(0) scale(1);                    filter: brightness(1); }
  12%  { transform: rotate(-2deg) translateX(-2px) scale(1.01); }
  24%  { transform: rotate(3deg) translateX(3px) scale(1.03); }
  36%  { transform: rotate(-4deg) translateX(-4px) scale(1.05); filter: brightness(1.2); }
  48%  { transform: rotate(5deg) translateX(5px) scale(1.07); }
  60%  { transform: rotate(-6deg) translateX(-6px) scale(1.09); filter: brightness(1.4); }
  72%  { transform: rotate(7deg) translateX(7px) scale(1.11); }
  84%  { transform: rotate(-7deg) translateX(-6px) scale(1.13); filter: brightness(1.6); }
  100% { transform: rotate(0) scale(1.14);                 filter: brightness(1.8); }
}

/* at 0.9s the body gets a torn top edge, then at 1.25s it falls away */
.opening .pack {
  animation:
    body-tear 0.02s 0.9s forwards,
    body-drop 0.45s ease-in 1.25s forwards;
}
@keyframes body-tear { to { clip-path: polygon(var(--tear-lr), var(--crimp-bottom)); } }
@keyframes body-drop {
  to { transform: translateY(70px) scale(0.85); opacity: 0; }
}

.opening .pack-top { animation: tear 0.7s cubic-bezier(.2,.6,.3,1) 0.9s forwards; }
@keyframes tear {
  to { transform: translate(90px, -230px) rotate(52deg); opacity: 0; }
}

.opening .pack-rays { animation: rays 1.1s ease-out 0.9s forwards; }
@keyframes rays {
  0%   { opacity: 0;   transform: scale(0.2) rotate(0deg); }
  25%  { opacity: 1; }
  100% { opacity: 0.85; transform: scale(1.5) rotate(40deg); }
}

/* ---------- No free packs left ---------- */
.pack-stage.empty { animation: none; filter: grayscale(1) brightness(0.6) drop-shadow(0 18px 20px rgba(0, 0, 0, 0.5)); }
.pack-stage.empty .pack { cursor: not-allowed; }
.pack-stage.empty .pack::after { animation: none; }

/* Reduced motion: skip the show */
@media (prefers-reduced-motion: reduce) {
  .pack-stage, .pack::after { animation: none; }
  .opening .pack-shaker, .opening .pack, .opening .pack-top, .opening .pack-rays { animation: none; }
  .opening .pack { opacity: 0; }
}
