[data-pack-reveal] {
  position: relative;
  isolation: isolate;
}

[data-pack-reveal] .reveal-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  justify-content: center;
  align-items: start;
  gap: clamp(12px, 2vw, 28px);
  width: min(100%, 1040px);
  margin-inline: auto;
  padding: 22px clamp(4px, 2vw, 30px) 42px;
}

button[data-pack-card]:not(.pack-flip-card) { visibility: hidden; }

[data-pack-reveal] button.pack-flip-card {
  --pack-foil-color: #c8bda9;
  --pack-foil-strength: .22;
  --pack-light-x: 50%;
  --pack-light-y: 50%;
  --pack-layout-angle: var(--pack-fan-angle);
  position: relative;
  z-index: 0;
  min-width: 0;
  width: 100%;
  aspect-ratio: .697;
  height: auto;
  min-height: 0;
  display: block;
  overflow: visible;
  container-type: inline-size;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  color: inherit;
  font: inherit;
  text-align: start;
  perspective: 1050px;
  touch-action: pan-y pinch-zoom;
  user-select: none;
  transform: translateY(var(--pack-fan-y)) rotate(var(--pack-layout-angle));
  cursor: pointer;
}

[data-pack-reveal] button.pack-flip-card[data-pack-rarity='rare'] { --pack-foil-color: #a6ece0; --pack-foil-strength: .34; }
[data-pack-reveal] button.pack-flip-card[data-pack-rarity='epic'] { --pack-foil-color: #d4affc; --pack-foil-strength: .48; }
[data-pack-reveal] button.pack-flip-card[data-pack-rarity='legendary'] { --pack-foil-color: #ffdb85; --pack-foil-strength: .62; }
[data-pack-reveal] button.pack-flip-card[data-pack-rarity='mythic'] { --pack-foil-color: #ffc4b3; --pack-foil-strength: .74; }

[data-pack-reveal] button.pack-flip-card:is(:hover, :focus-visible) {
  z-index: 2;
  filter: none;
  box-shadow: none;
}

[data-pack-reveal] button.pack-flip-card:focus-visible {
  outline: 2px solid #ffdea0;
  outline-offset: 7px;
  border-radius: 9px;
}

[data-pack-dealing] button.pack-flip-card {
  animation: pack-deal-flight 640ms cubic-bezier(.18,.68,.22,1) var(--pack-deal-delay) both;
}

@keyframes pack-deal-flight {
  0% { opacity: 0; transform: translate(var(--pack-deal-x), var(--pack-deal-y)) rotate(var(--pack-deal-tilt)) scale(.26); }
  31% { opacity: 1; }
  100% { opacity: 1; transform: translateY(var(--pack-fan-y)) rotate(var(--pack-layout-angle)); }
}

.pack-deal-halo {
  position: absolute;
  z-index: 0;
  width: min(90%, 860px);
  aspect-ratio: 1.5;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, #fff3c574 0%, #efad4b53 11%, #f3b55726 23%, transparent 60%),
    radial-gradient(ellipse at center, transparent 35%, #ffe1a84d 38% 39%, transparent 44% 49%, #86d4c838 50%, transparent 53%);
  animation: pack-deal-halo 720ms ease-out both;
}

@keyframes pack-deal-halo {
  0% { opacity: .96; transform: translate(-50%, -50%) scale(.24); }
  33% { opacity: .72; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.18); }
}

.pack-flip-unit {
  position: absolute;
  inset: 0;
  display: block;
  transform-style: preserve-3d;
  transform: rotateY(180deg);
  transition: transform 590ms cubic-bezier(.23,.68,.28,1.02);
}

[data-pack-card][data-pack-revealed='true'] .pack-flip-unit {
  transform: translateY(-4px) rotateX(var(--pack-tilt-x, 0deg)) rotateY(var(--pack-tilt-y, 0deg));
  transition-duration: 530ms;
}

[data-pack-card][data-pack-revealed='true']:hover .pack-flip-unit { transition-duration: 360ms; }

.pack-flip-front, .pack-flip-back {
  position: absolute;
  inset: 0;
  display: block;
  overflow: hidden;
  isolation: isolate;
  border-radius: clamp(5px, 4.2cqw, 12px);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background-color: #201713;
  box-shadow: 0 10px 21px #0905038c;
}

.pack-flip-front {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  border: 1px solid var(--pack-foil-color);
  transform: translateZ(.1px);
}

.pack-flip-front > :is(.card-art, .pack-card-art) {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  aspect-ratio: auto;
}

.pack-flip-front > :is(.card-copy, .pack-card-copy) { position: relative; z-index: 2; width: 100%; }
.pack-flip-front img { -webkit-user-drag: none; }

[data-pack-flash] .pack-flip-front::after {
  content: '';
  position: absolute;
  inset: 0 0 29%;
  z-index: 4;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 34%, var(--pack-foil-color) 46%, #fff6db 50%, transparent 63%);
  background-size: 260% 100%;
  mix-blend-mode: screen;
  mask-image: linear-gradient(#000 70%, transparent);
  animation: pack-foil-pass 530ms ease-out both;
}

@keyframes pack-foil-pass {
  0% { opacity: 0; background-position: 100%; }
  23% { opacity: .63; }
  100% { opacity: 0; background-position: 0%; }
}

.pack-flip-back {
  display: grid;
  place-items: center;
  transform: rotateY(180deg) translateZ(.1px);
  border: 1px solid #bd8c51;
  background:
    linear-gradient(144deg, #fbd39316 0 8%, transparent 27% 65%, #fac2802b 78%, transparent 95%),
    repeating-radial-gradient(ellipse at center, #f6cf8430 0 .6px, transparent .6px 5px),
    repeating-conic-gradient(from 45deg at 50% 50%, #eec17c12 0deg 2deg, transparent 2deg 6deg),
    radial-gradient(ellipse at 50% 31%, #683d23, #321b19 62%, #16141b 100%);
  box-shadow: inset 0 0 0 3px #160e12, inset 0 0 0 4px #d6a86c8c, inset 0 0 30px #080711, 0 13px 22px #080605ae;
}

.pack-flip-back::before, .pack-flip-back::after {
  content: '';
  position: absolute;
  pointer-events: none;
  inset: 6.5% 8%;
  border: 1px solid #eec18064;
  border-radius: clamp(3px, 2.8cqw, 8px);
  background:
    radial-gradient(circle at 0 0, #dfbe86 0 2px, transparent 3px),
    radial-gradient(circle at 100% 0, #dfbe86 0 2px, transparent 3px),
    radial-gradient(circle at 0 100%, #dfbe86 0 2px, transparent 3px),
    radial-gradient(circle at 100% 100%, #dfbe86 0 2px, transparent 3px);
}

.pack-flip-back::after {
  inset: 11% 13%;
  border-color: #e6b77934;
  border-style: double;
  background: radial-gradient(ellipse, transparent 39%, #110a1466 69%);
}

.pack-flip-ornament {
  position: absolute;
  width: 69%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid #fbd3969c;
  background:
    repeating-conic-gradient(from 15deg, #fae7ad61 0deg 1deg, transparent 1deg 15deg),
    repeating-radial-gradient(circle, #f5c57840 0 1px, transparent 1px 4px);
  mask-image: radial-gradient(circle, transparent 0 38%, #000 40% 65%, transparent 67% 72%, #000 73%);
  box-shadow: 0 0 32px #e487372e;
}

.pack-flip-crest {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 37%;
  aspect-ratio: 1;
  border: 1px solid #efb875;
  border-radius: 10%;
  color: #fff0bb;
  font: 900 clamp(22px, 21cqw, 62px)/1 var(--serif, serif);
  text-shadow: 0 1px #9d5b32, 0 2px 12px #ffbb5c4f;
  background: radial-gradient(ellipse, #bf794754, #241514b8 78%), linear-gradient(140deg, #9b533b, #4e1d23);
  box-shadow: inset 0 0 0 3px #e7b17456, 0 0 0 4px #10081367, 0 0 0 5px #e1a76483, 0 0 42px #f88b4136;
}

[data-pack-card]:not([data-pack-revealed='true']):is(:hover, :focus-visible) .pack-flip-back {
  border-color: #ffe5a6;
  box-shadow: inset 0 0 0 3px #160e12, inset 0 0 0 4px #f4c4898c, 0 0 25px #ffd37032, 0 11px 23px #080605ae;
}

.pack-flip-foil {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
  mask-image: linear-gradient(#000 0 66%, transparent 90%);
  mix-blend-mode: screen;
  opacity: var(--pack-foil-strength);
  background:
    radial-gradient(ellipse 66% 48% at var(--pack-light-x) var(--pack-light-y), #fff1bc8c 0, transparent 67%),
    repeating-linear-gradient(23deg, #ffdba64d 0 .7px, transparent .7px 4px),
    repeating-linear-gradient(116deg, #e3abed 0%, #93dff3 12%, #a0f1df 22%, #fce98d 32%, #ffb1bd 41%, #e3abed 50%) var(--pack-light-x) var(--pack-light-y) / 310% 290%;
  transition: opacity 280ms ease;
}

[data-pack-card]:not(:hover) .pack-flip-foil { opacity: calc(var(--pack-foil-strength) * .38); }
[data-pack-card][data-pack-rarity='common'] .pack-flip-foil {
  background: radial-gradient(ellipse 50% 42% at var(--pack-light-x) var(--pack-light-y), #fff6d2ac, transparent 72%);
}

[data-pack-card][data-pack-rarity='mythic'] .pack-flip-front { box-shadow: 0 0 22px #ffa4e24a, 0 10px 21px #0905038c; }

.pack-flip-sparks {
  position: fixed;
  z-index: 32;
  width: 0;
  height: 0;
  pointer-events: none;
}

.pack-flip-sparks::before {
  content: '';
  position: absolute;
  inset: 0 auto auto 0;
  width: var(--pack-ring-radius);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 1px solid var(--pack-spark-color);
  border-radius: 50%;
  box-shadow: 0 0 21px var(--pack-spark-color), inset 0 0 16px var(--pack-spark-color);
  animation: pack-flip-ring 620ms ease-out both;
}

@keyframes pack-flip-ring {
  from { opacity: .85; scale: .45; }
  to { opacity: 0; scale: 3.2; }
}

.pack-flip-spark {
  position: absolute;
  width: var(--pack-spark-size);
  height: calc(var(--pack-spark-size) * 2.3);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  background: var(--pack-spark-color);
  box-shadow: 0 0 7px var(--pack-spark-color);
  animation: pack-flip-spark var(--pack-spark-life) cubic-bezier(.12,.55,.27,.97) both;
}

@keyframes pack-flip-spark {
  from { opacity: .95; transform: translate(0, 0) rotate(0); }
  to { opacity: 0; transform: translate(var(--pack-spark-x), var(--pack-spark-y)) rotate(var(--pack-spark-angle)) scale(.4); }
}

[data-pack-flare]:not([hidden]) {
  position: absolute;
  z-index: 4;
  inset: 10px auto auto 50%;
  transform: translateX(-50%);
  display: block;
  width: max-content;
  max-width: 100%;
  padding: 6px 22px;
  pointer-events: none;
  color: #fff2bd;
  border-block: 1px solid #f4cb7a87;
  background: linear-gradient(90deg, #1d142526, #27182df4 21% 79%, #1d142526);
  font: 800 clamp(15px, 2.2vw, 26px)/1.35 var(--serif, serif);
  letter-spacing: .08em;
  text-align: center;
  text-shadow: 0 0 14px #f8a75c8c;
  animation: pack-flare-entry 425ms cubic-bezier(.17,.64,.2,1) both;
}

[data-pack-flare][data-pack-flare-rarity='mythic'] { color: #ffdefa; border-color: #f5a4d4aa; text-shadow: 0 0 14px #f78bba; }
@keyframes pack-flare-entry { from { opacity: 0; translate: 0 6px; } to { opacity: 1; } }

.pack-flip-live {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  white-space: nowrap;
  clip-path: inset(50%);
}

@media (max-width: 580px) {
  [data-pack-reveal] .reveal-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: min(100%, 360px);
    gap: 14px 9px;
    padding: 14px 10px 25px;
  }
  [data-pack-reveal] button.pack-flip-card { grid-column: span 2; --pack-fan-y: 0px !important; --pack-layout-angle: calc(var(--pack-fan-angle) / 2); }
  [data-pack-reveal] button.pack-flip-card:last-child:nth-child(odd) { grid-column: 2 / span 2; }
}

@media (prefers-reduced-motion: reduce) {
  [data-pack-reveal] button.pack-flip-card, .pack-flip-unit, [data-pack-flare] { transition: none !important; animation: none !important; }
  .pack-flip-sparks, .pack-deal-halo, [data-pack-flash] .pack-flip-front::after { display: none; }
}
