/* Palpedia TCG — Pack Opener (tcg/pack-opener.html).
   The scene: a sealed foil pack you tear open by dragging, a burst of card
   backs, and a one-by-one pedestal reveal with anime.js choreography.
   Utilities (console, toggle, history, trial decks) are kept from the previous
   shared sheet. Everything is prefixed with body.tcg-hub-page. */

/* ---------- Loading / error states ---------- */

body.tcg-hub-page .tcg-collection-state {
  padding: 3rem 0;
  color: var(--muted, #9fb5b7);
  text-align: center;
}

body.tcg-hub-page .tcg-collection-state--error a {
  color: var(--cyan, #62e7ed);
}

/* ---------- Local buttons ---------- */

body.tcg-hub-page .tcg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem 1rem;
  background: rgba(98, 231, 237, .08);
  border: 1px solid color-mix(in srgb, var(--cyan, #62e7ed) 45%, transparent);
  clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
  color: var(--cyan, #62e7ed);
  font-family: "Exo", system-ui, sans-serif;
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: background 180ms var(--ease-out, cubic-bezier(.22, 1, .36, 1)), color 180ms var(--ease-out, cubic-bezier(.22, 1, .36, 1));
}

body.tcg-hub-page .tcg-btn:hover:not(:disabled),
body.tcg-hub-page .tcg-btn:focus-visible:not(:disabled) {
  background: rgba(98, 231, 237, .18);
  color: var(--cyan-soft, #a6fbf6);
}

body.tcg-hub-page .tcg-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

body.tcg-hub-page .tcg-btn[hidden] {
  display: none;
}

body.tcg-hub-page .tcg-btn--primary {
  background: var(--cyan, #62e7ed);
  border-color: var(--cyan, #62e7ed);
  color: #07151b;
}

body.tcg-hub-page .tcg-btn--primary:hover:not(:disabled),
body.tcg-hub-page .tcg-btn--primary:focus-visible:not(:disabled) {
  background: var(--cyan-soft, #a6fbf6);
  color: #07151b;
}

/* ---------- The scene ---------- */

body.tcg-hub-page .tcg-scene {
  position: relative;
  min-height: clamp(30rem, 58vw, 40rem);
  margin-top: 1rem;
  background:
    radial-gradient(ellipse 70% 55% at 50% 38%, rgba(98, 231, 237, .08), transparent 70%),
    radial-gradient(ellipse 100% 100% at 50% 110%, rgba(242, 184, 75, .05), transparent 55%),
    linear-gradient(180deg, rgba(6, 18, 24, .6), rgba(4, 12, 17, .85));
  border: 1px solid var(--line, rgba(166, 217, 224, .18));
  clip-path: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  overflow: hidden;
  perspective: 1200px;
  touch-action: pan-y;
}

body.tcg-hub-page .tcg-scene__controls {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  gap: .5rem;
  z-index: 6;
}

/* ---------- The sealed foil pack ---------- */

body.tcg-hub-page .tcg-foil-pack {
  position: absolute;
  left: 50%;
  top: 46%;
  width: min(220px, 52vw);
  aspect-ratio: 608 / 1280;
  translate: -50% -50%;
  cursor: grab;
  z-index: 5;
  filter: drop-shadow(0 24px 44px rgba(0, 0, 0, .6));
  animation: tcg-pack-float 3.4s ease-in-out infinite;
}

body.tcg-hub-page .tcg-foil-pack:active {
  cursor: grabbing;
}

body.tcg-hub-page .tcg-foil-pack:focus-visible {
  outline: 2px solid var(--cyan, #62e7ed);
  outline-offset: 6px;
}

@keyframes tcg-pack-float {
  0%, 100% { transform: translateY(0) rotateZ(-.6deg); }
  50% { transform: translateY(-10px) rotateZ(.6deg); }
}

/* The two tear pieces are built by JS as clones of this inner composition. */

body.tcg-hub-page .tcg-foil-pack__art,
body.tcg-hub-page .tcg-foil-pack__piece-art {
  position: absolute;
  inset: 0;
  border-radius: 2.6% / 1.3%;
  overflow: hidden;
  background: #05080c;
}

body.tcg-hub-page .tcg-foil-pack__art img,
body.tcg-hub-page .tcg-foil-pack__piece-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

body.tcg-hub-page .tcg-foil-pack__shine {
  position: absolute;
  inset: 0;
  z-index: 5;
  border-radius: inherit;
  background: linear-gradient(115deg, transparent 32%, rgba(255, 244, 214, .22) 46%, rgba(255, 244, 214, .05) 52%, transparent 64%);
  background-size: 260% 100%;
  background-position: 120% 0;
  animation: tcg-pack-shine 3.8s var(--ease-out, cubic-bezier(.22, 1, .36, 1)) infinite;
  pointer-events: none;
}

@keyframes tcg-pack-shine {
  0% { background-position: 120% 0; }
  55%, 100% { background-position: -140% 0; }
}

body.tcg-hub-page .tcg-foil-pack__hint {
  position: absolute;
  left: 50%;
  top: calc(100% + .9rem);
  translate: -50% 0;
  white-space: nowrap;
  color: var(--muted, #9fb5b7);
  font-size: .78rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  animation: tcg-pack-hint 1.8s ease-in-out infinite;
  pointer-events: none;
}

body.tcg-hub-page .tcg-foil-pack__hint span {
  color: var(--cyan, #62e7ed);
}

@keyframes tcg-pack-hint {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}

/* Tear pieces (JS clones the composition into .tcg-foil-pack__piece wrappers) */

body.tcg-hub-page .tcg-foil-pack__piece {
  position: absolute;
  inset: 0;
  will-change: transform;
}

body.tcg-hub-page .tcg-foil-pack__seam {
  position: absolute;
  left: -4%;
  right: -4%;
  top: 20%;
  height: 10px;
  z-index: 6;
  background: linear-gradient(90deg, transparent, rgba(255, 244, 214, .95) 50%, transparent);
  filter: blur(3px) drop-shadow(0 0 18px rgba(242, 184, 75, .9));
  opacity: 0;
  pointer-events: none;
}

/* ---------- Flash on burst ---------- */

body.tcg-hub-page .tcg-scene__flash {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: radial-gradient(circle at 50% 42%, rgba(255, 248, 224, .98), rgba(242, 184, 75, .5) 34%, transparent 68%);
  opacity: 0;
  pointer-events: none;
}

/* ---------- The stage: arc of card backs ---------- */

body.tcg-hub-page .tcg-scene__stage {
  position: absolute;
  left: 0;
  right: 0;
  bottom: clamp(3.6rem, 8vw, 5.4rem);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(.3rem, 1.2vw, .9rem);
  padding: 0 clamp(.5rem, 2vw, 2rem);
  z-index: 4;
}

body.tcg-hub-page .tcg-scene-card {
  position: relative;
  width: clamp(76px, 10.5vw, 128px);
  aspect-ratio: 607 / 849;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform: rotateZ(var(--fan, 0deg));
  transform-style: preserve-3d;
  transition: translate 240ms var(--ease-out, cubic-bezier(.22, 1, .36, 1)), width 320ms var(--ease-out, cubic-bezier(.22, 1, .36, 1));
}

/* Structure cards are landscape: once open, the slot widens to their real shape. */
body.tcg-hub-page .tcg-scene-card.is-open.is-landscape {
  width: clamp(150px, 20vw, 240px);
  aspect-ratio: 744 / 532;
}

body.tcg-hub-page .tcg-scene-card:not(.is-open):hover,
body.tcg-hub-page .tcg-scene-card:not(.is-open):focus-visible {
  translate: 0 -12px;
}

body.tcg-hub-page .tcg-scene-card:focus-visible {
  outline: 2px solid var(--cyan, #62e7ed);
  outline-offset: 4px;
}

body.tcg-hub-page .tcg-scene-card__inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

body.tcg-hub-page .tcg-scene-card__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 4.5% / 3.2%;
  overflow: hidden;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .5);
}

body.tcg-hub-page .tcg-scene-card__face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

body.tcg-hub-page .tcg-scene-card__face--front {
  transform: rotateY(180deg);
  background: #07151b;
}

body.tcg-hub-page .tcg-scene-card.is-open {
  cursor: default;
}

body.tcg-hub-page .tcg-scene-card.is-open .tcg-scene-card__inner {
  transform: rotateY(180deg);
}

body.tcg-hub-page .tcg-scene-card.is-open .tcg-scene-card__face {
  box-shadow: 0 6px 16px rgba(0, 0, 0, .42);
}

body.tcg-hub-page .tcg-scene-card__rarity {
  position: absolute;
  right: .3rem;
  bottom: .3rem;
  z-index: 2;
  padding: .08rem .4rem;
  background: rgba(7, 21, 27, .88);
  border: 1px solid color-mix(in srgb, var(--cyan, #62e7ed) 55%, transparent);
  clip-path: polygon(4px 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%, 0 4px);
  color: var(--cyan, #62e7ed);
  font-size: .58rem;
  font-weight: 700;
}

body.tcg-hub-page .tcg-scene-card.is-chase .tcg-scene-card__rarity {
  border-color: color-mix(in srgb, var(--amber, #f2b84b) 70%, transparent);
  color: var(--amber, #f2b84b);
}

body.tcg-hub-page .tcg-scene-card__new {
  position: absolute;
  top: .3rem;
  left: .3rem;
  z-index: 2;
  padding: .08rem .4rem;
  background: rgba(7, 21, 27, .92);
  border: 1px solid color-mix(in srgb, var(--cyan, #62e7ed) 65%, transparent);
  clip-path: polygon(4px 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%, 0 4px);
  color: var(--cyan, #62e7ed);
  font-size: .55rem;
  font-weight: 800;
  letter-spacing: .1em;
  pointer-events: none;
}

body.tcg-hub-page .tcg-scene-card.is-chase .tcg-scene-card__new {
  border-color: color-mix(in srgb, var(--amber, #f2b84b) 70%, transparent);
  color: var(--amber, #f2b84b);
}

/* ---------- The pedestal + hero reveal ---------- */

body.tcg-hub-page .tcg-scene__pedestal {
  position: absolute;
  left: 50%;
  top: 42%;
  translate: -50% -50%;
  width: min(300px, 62vw);
  aspect-ratio: 607 / 849;
  z-index: 7;
  pointer-events: none;
}

body.tcg-hub-page .tcg-scene__spotlight {
  position: absolute;
  inset: -32% -45%;
  background: radial-gradient(ellipse 50% 50% at 50% 50%, rgba(98, 231, 237, .2), transparent 68%);
}

body.tcg-hub-page .tcg-scene__pulse {
  position: absolute;
  inset: -3%;
  border: 2px solid rgba(98, 231, 237, .65);
  border-radius: 5% / 3.6%;
  opacity: 0;
}

body.tcg-hub-page .tcg-scene-hero {
  position: absolute;
  z-index: 9;
  transform-style: preserve-3d;
  will-change: transform;
  cursor: pointer;
}

body.tcg-hub-page .tcg-scene-hero .tcg-scene-card__face--front::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, .5) 46%, rgba(105, 217, 230, .22) 52%, transparent 66%);
  background-size: 280% 100%;
  background-position: 130% 0;
  mix-blend-mode: screen;
  opacity: 0;
}

body.tcg-hub-page .tcg-scene-hero.is-chase .tcg-scene-card__face--front {
  box-shadow: 0 0 0 2px rgba(242, 184, 75, .85), 0 0 44px rgba(242, 184, 75, .55), 0 24px 54px rgba(0, 0, 0, .6);
}

body.tcg-hub-page .tcg-scene-hero.is-swept .tcg-scene-card__face--front::after {
  opacity: 1;
  transition: background-position 620ms var(--ease-out, cubic-bezier(.22, 1, .36, 1));
  background-position: -150% 0;
}

body.tcg-hub-page .tcg-scene-spark {
  position: absolute;
  z-index: 10;
  width: 7px;
  height: 7px;
  background: linear-gradient(135deg, #ffe9b0, var(--amber, #f2b84b));
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  pointer-events: none;
}

/* ---------- Progress dots ---------- */

body.tcg-hub-page .tcg-scene__progress {
  position: absolute;
  left: 1rem;
  bottom: 1.15rem;
  display: flex;
  gap: .45rem;
  z-index: 6;
}

body.tcg-hub-page .tcg-scene__progress i {
  width: .55rem;
  height: .55rem;
  border: 1px solid rgba(98, 231, 237, .5);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  transition: background 240ms var(--ease-out, cubic-bezier(.22, 1, .36, 1));
}

body.tcg-hub-page .tcg-scene__progress i.is-lit {
  background: var(--cyan, #62e7ed);
  box-shadow: 0 0 10px rgba(98, 231, 237, .8);
}

body.tcg-hub-page .tcg-scene__progress i.is-chase-lit {
  background: var(--amber, #f2b84b);
  border-color: rgba(242, 184, 75, .8);
  box-shadow: 0 0 10px rgba(242, 184, 75, .8);
}

/* ---------- Summary / actions / feedback ---------- */

body.tcg-hub-page .tcg-pack-summary {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: 1rem;
}

body.tcg-hub-page .tcg-pack-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  margin-top: 1.1rem;
}

body.tcg-hub-page .tcg-pack-actions[hidden] {
  display: none;
}

body.tcg-hub-page .tcg-pack-feedback {
  margin: .8rem 0 0;
  color: var(--cyan, #62e7ed);
  font-size: .86rem;
}

body.tcg-hub-page .tcg-pack-feedback a {
  color: var(--cyan-soft, #a6fbf6);
}

/* ---------- Console (product panel) ---------- */

body.tcg-hub-page .tcg-pack-console {
  display: grid;
  grid-template-columns: minmax(160px, 240px) minmax(0, 1fr);
  gap: clamp(1rem, 2.5vw, 2rem);
  align-items: center;
  padding: clamp(1rem, 2vw, 1.5rem);
}

body.tcg-hub-page .tcg-pack-console__cover {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .45);
}

body.tcg-hub-page .tcg-pack-console__body h3 {
  margin: 0 0 .4rem;
  color: var(--text, #edf7f5);
  font-size: clamp(1.05rem, 1.6vw, 1.3rem);
}

body.tcg-hub-page .tcg-pack-console__body p {
  margin: 0 0 .9rem;
  color: var(--muted, #9fb5b7);
  font-size: .9rem;
  line-height: 1.55;
}

body.tcg-hub-page .tcg-pack-odds {
  margin-top: .9rem;
  font-size: .76rem !important;
}

body.tcg-hub-page .tcg-pack-odds strong {
  color: var(--amber, #f2b84b);
}

/* Toggle "Add to my collection on open" */

body.tcg-hub-page .tcg-pack-toggle {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  margin-top: .8rem;
  padding: .45rem .75rem;
  background: rgba(98, 231, 237, .05);
  border: 1px solid var(--line, rgba(166, 217, 224, .2));
  clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
  color: var(--muted, #9fb5b7);
  font-size: .8rem;
  cursor: pointer;
  transition: border-color 180ms var(--ease-out, cubic-bezier(.22, 1, .36, 1)), color 180ms var(--ease-out, cubic-bezier(.22, 1, .36, 1));
}

body.tcg-hub-page .tcg-pack-toggle:hover {
  border-color: color-mix(in srgb, var(--cyan, #62e7ed) 45%, transparent);
  color: var(--text, #edf7f5);
}

body.tcg-hub-page .tcg-pack-toggle input {
  appearance: none;
  width: 2rem;
  height: 1.1rem;
  margin: 0;
  flex: 0 0 auto;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--cyan, #62e7ed) 45%, transparent);
  background: rgba(7, 21, 27, .8);
  position: relative;
  cursor: pointer;
  transition: background 180ms var(--ease-out, cubic-bezier(.22, 1, .36, 1));
}

body.tcg-hub-page .tcg-pack-toggle input::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 2px;
  width: .78rem;
  height: .78rem;
  border-radius: 50%;
  background: var(--muted, #9fb5b7);
  transform: translateY(-50%);
  transition: left 180ms var(--ease-out, cubic-bezier(.22, 1, .36, 1)), background 180ms var(--ease-out, cubic-bezier(.22, 1, .36, 1));
}

body.tcg-hub-page .tcg-pack-toggle input:checked {
  background: rgba(98, 231, 237, .3);
}

body.tcg-hub-page .tcg-pack-toggle input:checked::before {
  left: calc(100% - .78rem - 2px);
  background: var(--cyan, #62e7ed);
  box-shadow: 0 0 10px rgba(98, 231, 237, .7);
}

body.tcg-hub-page .tcg-pack-toggle input:focus-visible {
  outline: 2px solid var(--cyan, #62e7ed);
  outline-offset: 2px;
}

/* ---------- History + thumbs + trial decks ---------- */

body.tcg-hub-page .tcg-pack-history {
  display: grid;
  gap: .8rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

body.tcg-hub-page .tcg-pack-history > li {
  padding: .7rem .9rem;
}

body.tcg-hub-page .tcg-pack-history__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .8rem;
  margin-bottom: .5rem;
  color: var(--text, #edf7f5);
  font-size: .86rem;
  font-weight: 700;
}

body.tcg-hub-page .tcg-pack-history__head small {
  color: var(--muted, #9fb5b7);
  font-weight: 400;
}

body.tcg-hub-page .tcg-thumb-strip {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
}

body.tcg-hub-page .tcg-thumb {
  position: relative;
  display: block;
  width: 58px;
  text-decoration: none;
}

body.tcg-hub-page .tcg-thumb img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 4.5% / 3.2%;
  box-shadow: 0 4px 10px rgba(0, 0, 0, .4);
  transition: transform 160ms var(--ease-out, cubic-bezier(.22, 1, .36, 1));
}

body.tcg-hub-page .tcg-thumb:hover img,
body.tcg-hub-page .tcg-thumb:focus-visible img {
  transform: translateY(-2px);
}

body.tcg-hub-page .tcg-thumb span {
  position: absolute;
  right: .1rem;
  bottom: .1rem;
  padding: 0 .3rem;
  background: rgba(7, 21, 27, .85);
  color: var(--cyan, #62e7ed);
  font-size: .55rem;
  font-weight: 700;
}

body.tcg-hub-page .tcg-trial-decks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

body.tcg-hub-page .tcg-trial-deck {
  padding: clamp(1rem, 2vw, 1.4rem);
}

body.tcg-hub-page .tcg-trial-deck__head {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: .9rem;
  align-items: center;
  margin-bottom: .9rem;
}

body.tcg-hub-page .tcg-trial-deck__head img {
  width: 100%;
  height: auto;
  border-radius: 5px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .4);
}

body.tcg-hub-page .tcg-trial-deck__head h3 {
  margin: 0 0 .25rem;
  color: var(--text, #edf7f5);
  font-size: 1.02rem;
}

body.tcg-hub-page .tcg-trial-deck__head p {
  margin: 0;
  color: var(--muted, #9fb5b7);
  font-size: .8rem;
  line-height: 1.5;
}

body.tcg-hub-page #packStageSection {
  scroll-margin-top: 8.5rem;
}

/* ---------- Responsive / motion ---------- */

@media (max-width: 860px) {
  body.tcg-hub-page .tcg-pack-console {
    grid-template-columns: 1fr;
  }

  body.tcg-hub-page .tcg-pack-console__cover {
    max-width: 220px;
    margin: 0 auto;
  }
}

@media (max-width: 640px) {
  body.tcg-hub-page .tcg-scene {
    min-height: 30rem;
  }

  body.tcg-hub-page .tcg-scene__controls {
    left: 1rem;
    right: 1rem;
    justify-content: flex-end;
  }

  body.tcg-hub-page .tcg-scene__progress {
    bottom: 1.3rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.tcg-hub-page .tcg-foil-pack,
  body.tcg-hub-page .tcg-foil-pack__shine,
  body.tcg-hub-page .tcg-foil-pack__hint {
    animation: none;
  }

  body.tcg-hub-page .tcg-scene-card,
  body.tcg-hub-page .tcg-thumb img,
  body.tcg-hub-page .tcg-pack-toggle,
  body.tcg-hub-page .tcg-pack-toggle input,
  body.tcg-hub-page .tcg-pack-toggle input::before {
    transition: none;
  }
}
