/* Crate award + open theater — forked from POC `css/crate-claim.css`.
   Sealed-row chrome (.crate-entry) itself lives in panels/store.css; only the
   hidden-state guard for it is here, next to the presenter that flips it.

   Reveal juice keyframes (ccDrop*, ccPulseGlow*, ccFlash*, ccSpinRays,
   ccPopConfetti, ccSlideUpFade) are already declared globally by
   panels/store-inventory-base.css — but every *rule* that uses them there is
   scoped to .store-shop-panel / .inventory-panel / .cc-live-ref, so the theater
   re-declares its own scoped copies below exactly as the POC does. */

:root {
  --amber-deep: #d87800;
}

/* ── Sealed Inventory row: hidden means hidden ─────────────────────────────
   .crate-entry is display:grid, which beats the UA [hidden] rule. Without this
   the presenter's `entry.hidden = true` at 0 crates leaves the row on screen. */

.crate-entry[hidden] {
  display: none !important;
}

/* ── Inventory nav ×N badge (same chip DNA as .crate-entry__count) ─────────── */

.slant-nav__count {
  position: absolute;
  top: 8px;
  right: 6px;
  z-index: 2;
  box-sizing: border-box;
  min-width: 24px;
  height: 18px;
  padding: 0 5px;
  clip-path: polygon(4px 0, 100% 0, calc(100% - 4px) 100%, 0 100%);
  background: linear-gradient(180deg, var(--amber-hot, #ffc252), var(--amber-deep, #d87800));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.42);
  color: #1c1305;
  font-family: Rajdhani, sans-serif;
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 18px;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}

/* ═══ Award popup — "You've won a Crate" ═══════════════════════════════════ */

.crate-award {
  position: fixed;
  inset: 0;
  z-index: 14000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(4, 7, 10, 0.78);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms var(--store-ease, cubic-bezier(0.2, 0.75, 0.25, 1));
}
/* Opacity-0 full-screen sheet must NOT stay above the fly ghost (15000). */
.crate-award:not(.is-open) {
  z-index: 0;
  visibility: hidden;
}
.crate-award.is-open {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}
.crate-award[hidden] {
  display: none !important;
}
.crate-award__sheet {
  position: relative;
  isolation: isolate;
  width: min(380px, 100%);
  padding: 26px 24px 20px;
  clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 16px 100%, 0 calc(100% - 16px));
  background:
    radial-gradient(ellipse 70% 46% at 50% 8%, rgba(var(--amber-rgb, 255, 157, 10), 0.16), transparent 70%),
    linear-gradient(180deg, #121820, #0a0e13);
  box-shadow: inset 0 0 0 1px rgba(174, 191, 207, 0.14), 0 22px 48px rgba(0, 0, 0, 0.6);
  text-align: center;
  animation: crate-award-sheet-in 300ms var(--store-spring, cubic-bezier(0.16, 1, 0.3, 1));
}
.crate-award__sheet::before {
  content: "";
  position: absolute;
  top: 0;
  right: 16px;
  left: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--amber-hot, #ffc252), rgba(var(--amber-rgb, 255, 157, 10), 0.15) 78%, transparent);
}
@keyframes crate-award-sheet-in {
  from { opacity: 0; transform: translate3d(0, 12px, 0) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.crate-award__eyebrow {
  display: block;
  color: var(--amber, #ff9d0a);
  font-family: Rajdhani, sans-serif;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.crate-award__title {
  margin: 8px 0 0;
  color: #f4f7fa;
  font-family: Rajdhani, sans-serif;
  font-size: 27px;
  font-weight: 800;
  letter-spacing: 0.045em;
  line-height: 1;
  text-transform: uppercase;
}
.crate-award__art {
  position: relative;
  display: grid;
  place-items: center;
  width: 132px;
  height: 118px;
  margin: 18px auto 12px;
}
.crate-award__art::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -6px 4px;
  background: radial-gradient(ellipse 50% 42% at 50% 62%, rgba(var(--amber-rgb, 255, 157, 10), 0.34), transparent 72%);
  animation: crate-award-breathe 3.2s var(--store-ease, cubic-bezier(0.2, 0.75, 0.25, 1)) infinite alternate;
}
@keyframes crate-award-breathe {
  from { opacity: 0.55; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1.06); }
}
.crate-award__img {
  display: block;
  width: 96px;
  height: auto;
  animation: crate-award-bob 2.6s var(--store-ease, cubic-bezier(0.2, 0.75, 0.25, 1)) infinite alternate;
}
@keyframes crate-award-bob {
  from { transform: translateY(2px); }
  to { transform: translateY(-6px); }
}
.crate-award__count {
  position: absolute;
  top: 6px;
  right: 8px;
  min-width: 26px;
  height: 20px;
  padding: 0 6px;
  clip-path: polygon(4px 0, 100% 0, calc(100% - 4px) 100%, 0 100%);
  background: linear-gradient(180deg, var(--amber-hot, #ffc252), var(--amber-deep, #d87800));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.42);
  color: #1c1305;
  font-family: Rajdhani, sans-serif;
  font-size: 13px;
  font-weight: 800;
  line-height: 20px;
}
.crate-award__meta {
  margin: 0 0 18px;
  color: var(--muted, #858e99);
  font-family: Rajdhani, sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.crate-award__actions { display: flex; gap: 8px; }
.crate-award__actions .shop-buy-btn { flex: 2 1 0; }
.crate-award__actions .shop-buy-btn--ghost { flex: 1 1 0; }

/* ═══ Crate theater ════════════════════════════════════════════════════════ */

.crate-theater {
  position: fixed;
  inset: 0;
  z-index: 13000;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(ellipse 60% 50% at 50% 108%, rgba(var(--amber-rgb, 255, 157, 10), 0.1), transparent 70%),
    radial-gradient(ellipse 90% 70% at 50% 50%, rgba(8, 12, 17, 0.72), rgba(3, 5, 7, 0.95) 72%),
    rgba(3, 5, 7, 0.96);
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms var(--store-ease, cubic-bezier(0.2, 0.75, 0.25, 1));
}
.crate-theater.is-open { opacity: 1; pointer-events: auto; }
.crate-theater[hidden] {
  display: none !important;
}
.crate-theater__close {
  position: absolute;
  top: 20px;
  right: 22px;
  z-index: 60;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 0;
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.035));
  box-shadow: inset 0 0 0 1px rgba(180, 196, 210, 0.38);
  color: #e6ebf0;
  font-size: 14px;
  transition: box-shadow 150ms ease, color 150ms ease;
}
.crate-theater__close:hover {
  box-shadow: inset 0 0 0 1px rgba(200, 214, 226, 0.62);
  color: #fff;
}
.crate-theater__close:focus-visible {
  outline: 2px solid var(--amber-hot, #ffc252);
  outline-offset: 2px;
}

.crate-stage,
.crate-theater .purchase-reveal-box { grid-area: 1 / 1; }

.crate-stage {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 0;
  animation: crate-stage-in 420ms var(--store-spring, cubic-bezier(0.16, 1, 0.3, 1)) both;
}
.crate-stage[hidden],
.crate-theater .purchase-reveal-box[hidden] {
  display: none !important;
}
@keyframes crate-stage-in {
  from { opacity: 0; transform: translate3d(0, 18px, 0) scale(0.94); }
  to { opacity: 1; transform: none; }
}
.crate-stage__eyebrow {
  color: var(--amber, #ff9d0a);
  font-family: Rajdhani, sans-serif;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}
.crate-stage__title {
  margin: 8px 0 0;
  color: #f4f7fa;
  font-family: Rajdhani, sans-serif;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.09em;
  line-height: 1;
  text-transform: uppercase;
}

.crate-shell {
  position: relative;
  display: grid;
  place-items: center;
  width: 260px;
  height: 240px;
  margin-top: 34px;
  transform-origin: 50% 78%;
}
.crate-shell__bloom {
  position: absolute;
  inset: 8%;
  background: radial-gradient(circle at 50% 52%, rgba(255, 190, 90, 0.5), rgba(var(--amber-rgb, 255, 157, 10), 0.16) 42%, transparent 72%);
  opacity: calc(0.32 + var(--charge, 0) * 0.68);
  transform: scale(calc(0.86 + var(--charge, 0) * 0.42));
  pointer-events: none;
}
.crate-shell__img {
  position: relative;
  z-index: 2;
  display: block;
  width: 168px;
  height: auto;
}
.crate-shell__glare {
  position: absolute;
  z-index: 3;
  inset: 22% 26%;
  background: radial-gradient(circle at 50% 50%, rgba(255, 246, 214, 0.95), rgba(255, 214, 140, 0.4) 38%, transparent 68%);
  mix-blend-mode: screen;
  opacity: calc(var(--charge, 0) * var(--charge, 0) * 0.85);
  transform: scale(calc(0.5 + var(--charge, 0) * 0.7));
  pointer-events: none;
}
.crate-shell__floor {
  position: absolute;
  bottom: 6px;
  left: 50%;
  width: 260px;
  height: 40px;
  background: radial-gradient(ellipse 50% 50% at 50% 50%, rgba(255, 200, 110, 0.5), transparent 70%);
  opacity: calc(0.3 + var(--charge, 0) * 0.7);
  transform: translateX(-50%) scaleX(calc(0.8 + var(--charge, 0) * 0.5));
  pointer-events: none;
}

@keyframes crateFlashWhite {
  0% { filter: brightness(1) drop-shadow(0 0 10px var(--amber, #ff9d0a)); opacity: 1; transform: scale(1); }
  50% { filter: brightness(10) drop-shadow(0 0 50px #fff); opacity: 1; transform: scale(1.1); }
  100% { filter: brightness(1) drop-shadow(0 0 0 transparent); opacity: 0; transform: scale(1.2); }
}
.crate-shell.is-popping .crate-shell__img { animation: crateFlashWhite 0.4s ease-out forwards; }
.crate-shell.is-popping .crate-shell__glare,
.crate-shell.is-popping .crate-shell__bloom { opacity: 0; transition: opacity 240ms ease; }

.crate-theater .purchase-reveal-box {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  transform: scale(0.5) translateY(-50px);
}
.crate-theater.tier-common.is-revealed .purchase-reveal-box {
  animation: ccDropCommon 0.4s ease-out forwards;
}
.crate-theater.tier-rare.is-revealed .purchase-reveal-box {
  animation: ccDropRare 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.crate-theater.tier-epic.is-revealed .purchase-reveal-box {
  animation: ccDropEpic 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.crate-theater.tier-legendary.is-revealed .purchase-reveal-box {
  animation: ccDropLegendary 0.9s cubic-bezier(0.5, 0, 0.2, 1) forwards;
}

.crate-theater .reveal-glow {
  position: absolute;
  top: 44%;
  left: 50%;
  z-index: 0;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--reward-color, #fff) 0%, transparent 70%);
  opacity: 0.3;
  filter: blur(15px);
  transform: translate(-50%, -50%);
  animation: ccPulseGlow 4s infinite alternate;
  pointer-events: none;
}
.crate-theater.tier-epic .reveal-glow {
  width: 320px;
  height: 320px;
  opacity: 0.5;
  animation: ccPulseGlowEpic 3s infinite alternate;
}
.crate-theater.tier-legendary .reveal-glow {
  width: 460px;
  height: 460px;
  opacity: 0.7;
  background: radial-gradient(circle, #ffd700 0%, #ff4500 40%, transparent 70%);
  animation: ccPulseGlowLegendary 2.5s infinite alternate;
}

.crate-theater .flash-overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.crate-theater.tier-epic.is-popping .flash-overlay { animation: ccFlashEpic 0.8s ease-out forwards; }
.crate-theater.tier-legendary.is-popping .flash-overlay { animation: ccFlashLegendary 1.2s ease-out forwards; }

.crate-theater .legendary-rays {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 0;
  display: none;
  width: 200vmax;
  height: 200vmax;
  background: repeating-conic-gradient(
    from 0deg,
    rgba(255, 215, 0, 0.08) 0deg 5deg,
    transparent 5deg 15deg
  );
  transform: translate(-50%, -50%);
  animation: ccSpinRays 60s linear infinite;
  pointer-events: none;
}
.crate-theater.tier-legendary.is-popping .legendary-rays,
.crate-theater.tier-legendary.is-revealed .legendary-rays { display: block; }

.crate-theater .confetti-container {
  position: absolute;
  z-index: 50;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.crate-theater .confetti {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  background: var(--reward-color, #fff);
  opacity: 0;
  animation: ccPopConfetti 1s ease-out forwards;
}

.crate-theater .spin-card--hero {
  z-index: 1;
  width: 208px;
  pointer-events: none;
}
.crate-theater .spin-card--hero .spin-card__face {
  grid-template-rows: 3px 1fr;
  padding: 0 0 14px;
}
.crate-theater .spin-card--hero .spin-card__art {
  margin: 10px 8px 0;
  min-height: 168px;
}
.crate-theater .spin-card--hero .spin-card__img { width: 86%; height: 86%; }

.crate-theater .reveal-info {
  z-index: 1;
  margin-top: 18px;
  text-align: center;
}
.crate-theater .reveal-rarity {
  margin-bottom: 5px;
  color: var(--reward-color, #fff);
  font-family: Rajdhani, sans-serif;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  opacity: 0;
}
.crate-theater .reveal-name {
  margin: 0;
  color: #fff;
  font-family: Rajdhani, sans-serif;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
  text-transform: uppercase;
  opacity: 0;
}
.crate-theater .reveal-hint {
  margin: 9px 0 0;
  color: var(--muted, #858e99);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0;
}
.crate-theater.is-revealed .reveal-rarity { animation: ccSlideUpFade 0.4s forwards 0.4s; }
.crate-theater.is-revealed .reveal-name { animation: ccSlideUpFade 0.4s forwards 0.5s; }
.crate-theater.is-revealed .reveal-hint { animation: ccSlideUpFade 0.4s forwards 0.62s; }

.crate-theater .reveal-actions {
  z-index: 1;
  display: flex;
  gap: 8px;
  width: min(100%, 360px);
  margin-top: 22px;
  opacity: 0;
}
.crate-theater.is-revealed .reveal-actions { animation: ccSlideUpFade 0.4s forwards 0.6s; }
.crate-theater .reveal-actions .shop-buy-btn { flex: 1 1 0; min-height: 42px; padding-inline: 16px; }
.crate-theater .reveal-actions .shop-buy-btn--ghost { flex: 1.2 1 0; }
/* Equip is dropped when the reward carries no equippable config key. */
.crate-theater .reveal-actions .shop-buy-btn[hidden] { display: none !important; }

/* Guest held note + equal CTA pair */
body[data-lobby-account="guest"] .crate-theater .reveal-hint {
  max-width: 280px;
  margin-inline: auto;
  letter-spacing: 0.02em;
  text-transform: none;
  line-height: 1.35;
}
body[data-lobby-account="guest"] .crate-theater .reveal-actions {
  width: min(340px, calc(100vw - 48px));
}
body[data-lobby-account="guest"] .crate-theater .reveal-actions .shop-buy-btn,
body[data-lobby-account="guest"] .crate-theater .reveal-actions .shop-buy-btn--ghost {
  flex: 1 1 0;
}

/* ── Ambient loops only tick while the surface is actually up ───────────────
   Same rule as the store rail (panels/store.css): visibility:hidden stops paint
   but not an infinite animation, and both surfaces ship in the shell markup. */
.crate-award:not(.is-open) .crate-award__art::before,
.crate-award:not(.is-open) .crate-award__img,
.crate-theater:not(.is-open) .reveal-glow,
.crate-theater:not(.is-open) .legendary-rays,
.crate-theater:not(.is-open) .spin-card[data-rarity="legendary"] .spin-card__face::after {
  animation: none;
}

@media (max-width: 760px) {
  .crate-shell { width: 220px; height: 200px; }
  .crate-shell__img { width: 138px; }
  .crate-stage__title { font-size: 27px; }
  .crate-theater .spin-card--hero { width: 176px; }
}

@media (prefers-reduced-motion: reduce) {
  .crate-award__art::before,
  .crate-award__img,
  .crate-theater .legendary-rays,
  .crate-theater .reveal-glow { animation: none; }
  .crate-shell.is-popping .crate-shell__img,
  .crate-theater.tier-epic.is-popping .flash-overlay,
  .crate-theater.tier-legendary.is-popping .flash-overlay { animation: none; }
  .crate-shell.is-popping .crate-shell__img { opacity: 0; }
  .crate-stage,
  .crate-theater.tier-common.is-revealed .purchase-reveal-box,
  .crate-theater.tier-rare.is-revealed .purchase-reveal-box,
  .crate-theater.tier-epic.is-revealed .purchase-reveal-box,
  .crate-theater.tier-legendary.is-revealed .purchase-reveal-box {
    animation: none;
    opacity: 1;
    transform: none;
  }
  .crate-theater.is-revealed .reveal-rarity,
  .crate-theater.is-revealed .reveal-name,
  .crate-theater.is-revealed .reveal-hint,
  .crate-theater.is-revealed .reveal-actions {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

