/* Pack Opener. Uses the site tokens from /css/styles.css. */

.po { padding-top: 112px; padding-bottom: 56px; }
.po-head h1 { font-size: clamp(2.2rem, 5vw, 3.4rem); letter-spacing: -0.03em; }
.po-lede { margin-top: 10px; max-width: 56ch; color: var(--muted); font-size: 1.05rem; }

.po-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 28px;
  margin-top: 32px;
  align-items: start;
}

/* ── Setup ──────────────────────────────────────────────── */
.po-setup { display: grid; gap: 24px; position: sticky; top: 96px; }
.po-step__title {
  display: flex; align-items: center; gap: 10px;
  font-size: 1rem; font-weight: 600; margin-bottom: 12px;
}
.po-step__title span {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  font-family: var(--font-mono); font-size: 0.75rem;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent);
}

.po-types { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.po-type {
  position: relative; display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; transition: border-color 0.2s, background-color 0.2s;
}
.po-type input { position: absolute; opacity: 0; pointer-events: none; }
.po-type:hover { border-color: var(--border-strong); }
.po-type:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--bg-2)); box-shadow: 0 0 0 1px var(--accent) inset; }
.po-type:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.po-type__pack { grid-row: 1 / span 2; width: 18px; height: 30px; border-radius: 3px; background: linear-gradient(160deg, var(--p1), var(--p2)); box-shadow: inset 0 3px 0 rgba(255,255,255,.25), inset 0 -3px 0 rgba(255,255,255,.25); }
.po-type__name { font-weight: 600; font-size: 0.95rem; }
.po-type__count { font-size: 0.75rem; color: var(--muted); font-family: var(--font-mono); }
.po-type-blurb { margin-top: 10px; font-size: 0.85rem; color: var(--muted); min-height: 2.6em; }

/* Booster colours, used by the picker swatches and the big pack. */
[data-type="play"] { --p1: #0f766e; --p2: #5b21b6; --p3: #5eead4; }
[data-type="draft"] { --p1: #1e3a8a; --p2: #9f1239; --p3: #93c5fd; }
[data-type="set"] { --p1: #166534; --p2: #1e40af; --p3: #86efac; }
[data-type="collector"] { --p1: #18181b; --p2: #a16207; --p3: #fcd34d; }

.po-search {
  width: 100%; padding: 10px 14px; margin-bottom: 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text); font: inherit; font-size: 0.92rem;
}
.po-search:focus { outline: none; border-color: var(--accent); }
.po-sets {
  list-style: none; margin: 0; padding: 4px; max-height: 340px; overflow-y: auto; overscroll-behavior: contain;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-2);
}
.po-sets:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.po-sets li[data-code] {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 0.9rem;
}
.po-sets li[data-code]:hover { background: var(--surface-hover); }
.po-sets li[aria-selected="true"] { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.po-sets img { width: 22px; height: 22px; object-fit: contain; filter: var(--icon-filter, invert(1)); opacity: 0.85; }
.po-sets__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.po-sets__meta { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); }
.po-sets__empty { padding: 14px; color: var(--muted); font-size: 0.9rem; }

/* Light theme: set icons are black SVGs, so only dark mode inverts them. */
:root[data-theme="light"] { --icon-filter: none; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) { --icon-filter: none; } }

/* ── Stage ──────────────────────────────────────────────── */
.po-stage {
  position: relative; min-height: 560px; padding: 32px 20px; border-radius: var(--radius);
  border: 1px solid var(--border);
  background:
    radial-gradient(70% 55% at 50% 30%, color-mix(in srgb, var(--accent-2) 12%, transparent), transparent 70%),
    var(--bg-2);
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}

.po-pack {
  position: relative; width: min(240px, 62vw); aspect-ratio: 0.58;
  filter: drop-shadow(0 26px 30px rgba(0, 0, 0, 0.45));
  transition: transform 0.45s var(--ease), opacity 0.45s;
}
.po-pack__top, .po-pack__body, .po-pack__crimp { position: absolute; left: 0; right: 0; background: linear-gradient(160deg, var(--p1), var(--p2)); }
.po-pack__body { top: 0; bottom: 0; border-radius: 6px; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 22% 14px 16%; text-align: center; color: #fff; }
/* Foil sheen that drifts across the wrapper. */
.po-pack__body::after {
  content: ""; position: absolute; inset: -40%;
  background: linear-gradient(115deg, transparent 40%, rgba(255,255,255,.28) 48%, rgba(255,255,255,.05) 54%, transparent 60%);
  animation: po-sheen 4.5s ease-in-out infinite;
}
@keyframes po-sheen { from { transform: translateX(-35%); } to { transform: translateX(35%); } }
/* Crimped seals: top strip tears off; bottom stays. */
.po-pack__top { top: 0; height: 13%; z-index: 2; border-radius: 6px 6px 0 0; clip-path: polygon(0 0, 100% 0, 100% 78%, 95% 100%, 90% 78%, 85% 100%, 80% 78%, 75% 100%, 70% 78%, 65% 100%, 60% 78%, 55% 100%, 50% 78%, 45% 100%, 40% 78%, 35% 100%, 30% 78%, 25% 100%, 20% 78%, 15% 100%, 10% 78%, 5% 100%, 0 78%); }
.po-pack__top::after, .po-pack__crimp::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(90deg, rgba(255,255,255,.22) 0 2px, transparent 2px 6px); }
.po-pack__crimp { bottom: 0; height: 7%; z-index: 2; border-radius: 0 0 6px 6px; }
.po-pack__icon { width: 46%; aspect-ratio: 1; object-fit: contain; filter: invert(1) drop-shadow(0 2px 6px rgba(0,0,0,.4)); }
.po-pack__set { font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; line-height: 1.15; text-transform: uppercase; letter-spacing: 0.02em; text-shadow: 0 2px 8px rgba(0,0,0,.4); }
.po-pack__type { font-size: 0.8rem; font-weight: 600; color: var(--p3); text-transform: uppercase; letter-spacing: 0.1em; }
.po-pack__count { font-family: var(--font-mono); font-size: 0.72rem; opacity: 0.75; }

.po-pack.is-loading { animation: po-shake 0.5s ease-in-out infinite; }
@keyframes po-shake { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-2.5deg); } 75% { transform: rotate(2.5deg); } }
.po-pack.is-torn .po-pack__top { animation: po-tear 0.55s var(--ease) forwards; }
@keyframes po-tear {
  0% { transform: none; }
  30% { transform: translate(-4%, -10%) rotate(-4deg); }
  100% { transform: translate(70%, -260%) rotate(24deg); opacity: 0; }
}
.po-pack.is-open { transform: translateY(40px) scale(0.92); opacity: 0; }

.po-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.po-status { min-height: 1.4em; color: var(--muted); font-size: 0.9rem; text-align: center; }
body.po-busy .po-type, body.po-busy .po-sets li { pointer-events: none; opacity: 0.6; }

/* ── Cards ──────────────────────────────────────────────── */
.po-cards { width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 12px; perspective: 1400px; }
.po-card {
  --glow: transparent;
  position: relative; aspect-ratio: 488 / 680; padding: 0; border: 0; background: none; cursor: pointer;
  border-radius: 4.75% / 3.5%; color: inherit;
  animation: po-deal 0.5s var(--ease) both; animation-delay: calc(var(--i) * 55ms);
}
@keyframes po-deal { from { opacity: 0; transform: translateY(-60px) rotate(-6deg) scale(0.8); } }
.po-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.po-card__inner { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform 0.55s var(--ease); border-radius: inherit; }
.po-card.is-flipped .po-card__inner { transform: rotateY(180deg); }
.po-card__back, .po-card__front { position: absolute; inset: 0; border-radius: inherit; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; }
.po-card__back { background: #14100c url("/games/pack-opener/img/card-back.webp") center / cover no-repeat; box-shadow: 0 6px 16px -8px rgba(0, 0, 0, 0.6); }
.po-card:hover:not(.is-flipped) .po-card__inner { transform: translateY(-4px); }
.po-card__front { transform: rotateY(180deg); background: #111; }
.po-card__front img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Rarity glow once flipped. */
.po-card.is-flipped[data-rarity="rare"] { --glow: rgba(234, 179, 8, 0.55); }
.po-card.is-flipped[data-rarity="mythic"] { --glow: rgba(249, 115, 22, 0.75); }
.po-card.is-flipped .po-card__inner { box-shadow: 0 0 0 1px rgba(0,0,0,.2), 0 0 22px 2px var(--glow); }
.po-card.is-hit { z-index: 1; }
.po-card.is-hit .po-card__inner { animation: po-pop 0.7s var(--ease) 0.25s; }
@keyframes po-pop { 40% { transform: rotateY(180deg) scale(1.08); } }

/* Foil: a soft moving rainbow that leaves the card readable. */
.po-card[data-foil] .po-card__front::after, .po-zoom__card[data-foil]::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; mix-blend-mode: color-dodge; opacity: 0.32;
  background: linear-gradient(125deg, #ff6b6b00 10%, #ffd16655 25%, #7cff8a55 40%, #66d9ff55 55%, #c38bff55 70%, #ff6b6b00 85%);
  background-size: 250% 250%; animation: po-foil 5s linear infinite;
}
@keyframes po-foil { from { background-position: 0% 0%; } to { background-position: 250% 250%; } }

/* ── Summary ────────────────────────────────────────────── */
.po-summary {
  width: 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 20px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface);
  animation: po-deal 0.4s var(--ease) both;
}
.po-summary__label { font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.po-summary__value { font-family: var(--font-display); font-size: 2rem; font-weight: 700; line-height: 1.1; }
.po-summary__line { color: var(--muted); font-size: 0.88rem; margin-top: 4px; }
.po-summary__session { font-family: var(--font-mono); font-size: 0.75rem; }
.po-summary__btns { display: flex; gap: 10px; flex-wrap: wrap; }

.po-legal { margin-top: 28px; font-size: 0.75rem; color: var(--muted); max-width: 90ch; line-height: 1.6; }
.po-legal a { color: inherit; }

/* ── Details dialog ─────────────────────────────────────── */
.po-zoom {
  width: min(720px, calc(100vw - 32px)); max-height: calc(100svh - 32px); padding: 22px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--bg-2); color: var(--text);
  display: none; grid-template-columns: minmax(0, 300px) 1fr; gap: 22px; align-items: start;
}
.po-zoom[open] { display: grid; }
.po-zoom::backdrop { background: rgba(4, 6, 10, 0.72); backdrop-filter: blur(4px); }
.po-zoom__close { position: absolute; z-index: 2; top: 10px; right: 12px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1.3rem; line-height: 1; cursor: pointer; }
.po-zoom__card { position: relative; border-radius: 4.75% / 3.5%; overflow: hidden; aspect-ratio: 488 / 680; background: #111; }
.po-zoom__card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.po-zoom__info h2 { font-size: 1.5rem; padding-right: 36px; }
.po-zoom__tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.po-tag { font-family: var(--font-mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--muted); }
.po-tag[data-tag="rare"] { color: #eab308; border-color: #eab30866; }
.po-tag[data-tag="mythic"] { color: #f97316; border-color: #f9731666; }
.po-tag[data-tag="foil"], .po-tag[data-tag="special art"] { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent-2) 40%, transparent); }
.po-zoom__price { margin-top: 16px; font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; }
.po-zoom__artist { margin-top: 4px; color: var(--muted); font-size: 0.88rem; }
.po-zoom__btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }

/* ── Phone ──────────────────────────────────────────────── */
@media (max-width: 860px) {
  .po { padding-top: 96px; }
  .po-layout { grid-template-columns: minmax(0, 1fr); gap: 22px; }
  .po-setup { position: static; }
  .po-sets { max-height: 240px; }
  .po-stage { min-height: 0; padding: 24px 12px; }
  .po-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .po-zoom { grid-template-columns: minmax(0, 1fr); padding: 18px; overflow-y: auto; }
  .po-zoom__card { width: min(100%, 300px); justify-self: center; }
}

@media (prefers-reduced-motion: reduce) {
  .po-pack__body::after, .po-card[data-foil] .po-card__front::after, .po-zoom__card[data-foil]::after { animation: none; }
  .po-pack.is-loading, .po-card, .po-card.is-hit .po-card__inner, .po-summary { animation: none; }
  .po-card__inner, .po-pack { transition: none; }
}
