/* Pack opener: the full-screen reveal after opening packs on /skins (pack-opener.js).
   Rarity colours are the site's (store.css / arena.css). No rays behind any art: light comes from
   soft radial glows, rings and sparks only. */

.po-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #f0ece6;
    font-family: 'HwyGothic', Arial, sans-serif;
    overflow: hidden;
    /* fast clicking must never select text or start a native image drag */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    --po-gold: #c9a96e;
    --po-cream: #eddfc0;
}

.po-overlay img {
    -webkit-user-drag: none;
    user-drag: none;
    pointer-events: none;
}

.po-backdrop {
    position: absolute;
    inset: 0;
    /* opaque: a full takeover, the site chrome must not show through */
    background:
        radial-gradient(ellipse 60% 50% at 50% 42%, rgba(201, 169, 110, 0.16), rgba(0, 0, 0, 0) 70%),
        radial-gradient(ellipse 85% 75% at 50% 45%, #24170a 0%, #0b0804 62%, #020101 100%);
    animation: po-fade-in 0.3s ease-out;
}

/* vignette: art always reads against a dark rim, whatever the light show does */
.po-backdrop::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    box-shadow: inset 0 0 180px 40px rgba(0, 0, 0, 0.85);
}

.po-flash {
    position: absolute;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    background: radial-gradient(circle at 50% 50%, var(--po-flash, #fff) 0%, rgba(0, 0, 0, 0) 70%);
}

.po-flash.on { animation: po-flash 0.7s ease-out; }

@keyframes po-flash {
    0% { opacity: var(--po-flash-a, 0.4); }
    100% { opacity: 0; }
}

@keyframes po-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.po-hint {
    font-size: 0.8rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: rgba(237, 223, 192, 0.72);
    text-align: center;
}

.po-hint-pulse { animation: po-pulse 1.8s ease-in-out infinite; color: var(--po-gold); }

@keyframes po-pulse {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}

/* ── 1 · the pack ─────────────────────────────────────────── */
.po-pack {
    position: relative;
    z-index: 2;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.po-stage-pack .po-pack { display: flex; }

.po-pack-btn {
    position: relative;
    height: auto;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    animation: po-bob 2.6s ease-in-out infinite;
}

/* keyboard focus: a brighter glow on the pack itself, not a box drawn around it */
.po-pack-btn:focus { outline: none; }
.po-pack-btn:focus-visible .po-pack-img {
    filter: drop-shadow(0 18px 40px rgba(0, 0, 0, 0.7)) drop-shadow(0 0 40px rgba(237, 223, 192, 0.65));
}

/* The whole pack always shows: fitted inside the screen with room for the name, hint and count
   badge (global img max-height:100% would otherwise tie it to the button) */
.po-pack-img {
    display: block;
    width: auto;
    height: auto;
    max-width: min(78vw, 400px);
    max-height: calc(100vh - 200px);
    max-height: calc(100dvh - 200px);
    object-fit: contain;
    filter: drop-shadow(0 18px 40px rgba(0, 0, 0, 0.7)) drop-shadow(0 0 30px rgba(255, 170, 40, 0.35));
    transition: transform 0.25s ease, filter 0.25s ease;
}

.po-pack-img-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 240px;
    height: 300px;
    font-size: 5rem;
    color: var(--po-gold);
}

.po-pack-btn:hover .po-pack-img {
    transform: scale(1.04) rotate(-1.5deg);
    filter: drop-shadow(0 18px 40px rgba(0, 0, 0, 0.7)) drop-shadow(0 0 46px rgba(255, 190, 60, 0.6));
}

.po-pack-count {
    position: absolute;
    right: -6px;
    top: -6px;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 1.1rem;
    font-weight: bold;
    color: #1a1208;
    background: linear-gradient(135deg, var(--po-cream), var(--po-gold));
    box-shadow: 0 0 16px rgba(201, 169, 110, 0.6);
}

.po-pack-name {
    font-family: 'DragonSlayer', serif;
    font-size: 1.6rem;
    letter-spacing: 1px;
    color: var(--po-cream);
    text-shadow: 0 0 18px rgba(201, 169, 110, 0.45);
    text-align: center;
}

@keyframes po-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

/* Tearing: a hard shake, then the pack bursts out of view */
.po-tearing .po-pack-btn { animation: po-tear 0.65s cubic-bezier(0.5, 0, 0.8, 0.4) forwards; }
.po-tearing .po-hint-pulse, .po-tearing .po-pack-name { opacity: 0; transition: opacity 0.2s; }

@keyframes po-tear {
    0% { transform: translate(0, 0) rotate(0); }
    12% { transform: translate(-6px, 2px) rotate(-3deg); }
    24% { transform: translate(6px, -2px) rotate(3deg); }
    36% { transform: translate(-7px, 1px) rotate(-4deg); }
    48% { transform: translate(7px, -1px) rotate(4deg) scale(1.04); }
    70% { transform: scale(1.18); opacity: 1; filter: brightness(1.8); }
    100% { transform: scale(1.6); opacity: 0; filter: brightness(3); }
}

/* ── 2 · the table ────────────────────────────────────────── */
.po-table {
    position: relative;
    z-index: 2;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: 100%;
    height: 100%;
    padding: 24px 16px 20px;
    box-sizing: border-box;
}

.po-stage-table .po-table { display: flex; }

.po-table-head {
    flex: 0 0 auto;
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 14px;
    max-width: 100%;
}

.po-table-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: 'DragonSlayer', serif;
    font-size: 1.35rem;
    letter-spacing: 1px;
    color: var(--po-cream);
}

.po-table-mult { font-family: 'HwyGothic', Arial, sans-serif; font-size: 0.9rem; color: var(--po-gold); }

.po-progress {
    flex-shrink: 0;
    padding: 3px 10px;
    border: 1px solid rgba(201, 169, 110, 0.4);
    border-radius: 999px;
    font-size: 0.78rem;
    letter-spacing: 1px;
    color: rgba(237, 223, 192, 0.7);
}

.po-progress b { color: var(--po-cream); }

.po-table-hint { flex: 0 0 auto; min-height: 1.2em; margin-top: -6px; }
.po-finished .po-table-hint { visibility: hidden; }

.po-grid {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: grid;
    gap: 12px;
    justify-content: center;
    align-content: safe center;
    /* fit() sizes cards to fit; if the floor size still cannot, scroll here, never past the window */
    overflow-x: hidden;
    overflow-y: auto;
    padding: 6px 4px;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: rgba(201, 169, 110, 0.4) transparent;
}

.po-actions {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    min-height: 56px;
}

.po-actions .po-btn { display: none; }
.po-dealt:not(.po-finished) .po-reveal-all { display: inline-flex; }
.po-finished .po-again,
.po-finished .po-done { display: inline-flex; }

.po-btn {
    align-items: center;
    justify-content: center;
    height: auto;
    min-width: 180px;
    padding: 16px 30px;
    border-radius: 12px;
    font-family: 'HwyGothic', Arial, sans-serif;
    font-size: 1rem;
    font-weight: bold;
    letter-spacing: 3px;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.po-btn:hover { transform: translateY(-2px); }

.po-btn-gold {
    border: none;
    color: #1a1208;
    background: linear-gradient(135deg, var(--po-cream), var(--po-gold) 60%, #a8844a);
    box-shadow: 0 0 22px rgba(201, 169, 110, 0.4);
}

.po-btn-gold:hover { box-shadow: 0 0 32px rgba(237, 223, 192, 0.55); }

.po-btn-ghost {
    border: 1px solid rgba(201, 169, 110, 0.65);
    color: var(--po-cream);
    background: rgba(12, 9, 5, 0.6);
}

.po-btn-ghost:hover { background: rgba(201, 169, 110, 0.16); }

.po-btn:focus-visible { outline: 2px solid var(--po-cream); outline-offset: 3px; }

/* ── a card ───────────────────────────────────────────────── */
.po-card.r-COMMON   { --po-rar: #9e9e9e; --po-glow: 0; }
.po-card.r-UNCOMMON { --po-rar: #4caf50; --po-glow: 1; }
.po-card.r-RARE     { --po-rar: #2196f3; --po-glow: 2; }
.po-card.r-EPIC     { --po-rar: #ab47bc; --po-glow: 3; }
.po-card.r-ANCIENT  { --po-rar: #ff9800; --po-glow: 4; }

.po-card {
    position: relative;
    width: var(--po-card-w, 180px);
    height: calc(var(--po-card-w, 180px) * 7 / 5);
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    perspective: 900px;
    opacity: 0;
    touch-action: manipulation;
}

/* dealt face down, one after another */
.po-stage-table .po-card { animation: po-deal 0.42s cubic-bezier(0.2, 0.8, 0.3, 1.1) forwards; animation-delay: calc(var(--deal) * 60ms); }

@keyframes po-deal {
    0% { opacity: 0; transform: translateY(40vh) rotate(-12deg) scale(0.6); }
    100% { opacity: 1; transform: none; }
}

.po-card:focus { outline: none; }
.po-card:focus-visible { outline: 2px solid var(--po-cream); outline-offset: 4px; border-radius: 10px; }
.po-card.flipped { cursor: zoom-in; }

.po-card-inner {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(0.3, 0.7, 0.3, 1);
}

.po-card.flipped .po-card-inner { transform: rotateY(180deg); }
.po-card:not(.flipped):hover .po-card-inner { transform: translateY(-4px) rotate(-1deg); }

.po-card-back,
.po-card-front {
    position: absolute;
    inset: 0;
    border-radius: 10px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    overflow: hidden;
}

.po-card-back {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(201, 169, 110, 0.4);
    background: radial-gradient(ellipse at 50% 40%, #2e2111, #0d0904 75%);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.6);
}

.po-card-back img { width: 72%; opacity: 0.85; }

/* The true-rarity hint on the back (RARE and up only): a breathing edge glow in that colour */
.po-card.po-hinted .po-card-back {
    border-color: var(--po-rar);
    animation: po-hint 1.6s ease-in-out infinite;
}

@keyframes po-hint {
    0%, 100% { box-shadow: 0 8px 22px rgba(0, 0, 0, 0.6), 0 0 6px var(--po-rar); }
    50% { box-shadow: 0 8px 22px rgba(0, 0, 0, 0.6), 0 0 calc(10px + var(--po-glow) * 6px) var(--po-rar); }
}

.po-card-front {
    display: flex;
    flex-direction: column;
    transform: rotateY(180deg);
    border: 2px solid var(--po-rar);
    background: radial-gradient(ellipse at 50% 35%, #2a1d0c, #0b0703 80%);
}

.po-card.flipped .po-card-front {
    box-shadow: 0 0 calc(var(--po-glow) * 10px) var(--po-rar), 0 8px 22px rgba(0, 0, 0, 0.6);
}

.po-card-art {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    font-size: 2.4rem;
    color: var(--po-rar);
}

.po-card-art img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.po-card-label {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 8px 8px;
    background: rgba(0, 0, 0, 0.55);
    text-align: center;
}

.po-card-name {
    font-size: 0.72rem;
    letter-spacing: 1px;
    line-height: 1.2;
    color: var(--po-cream);
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow-wrap: anywhere;
}

.po-card-rarity {
    font-size: 0.62rem;
    font-weight: bold;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--po-rar);
}

.po-small .po-card-name { display: none; }
.po-tiny .po-card-label { display: none; }
.po-tiny .po-card-back img { width: 84%; }

/* The flip lands: a ring of light in the card's colour, wider with each rarity */
.po-card.po-burst::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 12px;
    pointer-events: none;
    border: 2px solid var(--po-rar);
    opacity: 0;
    animation: po-ring calc(0.5s + var(--po-glow) * 0.15s) ease-out;
}

.po-card.r-COMMON.po-burst::after { animation: none; }

@keyframes po-ring {
    0% { opacity: 0.9; transform: scale(1); }
    100% { opacity: 0; transform: scale(calc(1.1 + var(--po-glow) * 0.08)); }
}

.po-card.r-EPIC.flipped .po-card-inner,
.po-card.r-ANCIENT.flipped .po-card-inner { animation: po-pop 0.7s ease-out 0.3s; }

@keyframes po-pop {
    0% { transform: rotateY(180deg) scale(1); }
    40% { transform: rotateY(180deg) scale(1.12); }
    100% { transform: rotateY(180deg) scale(1); }
}

/* sparks fly out of the card's centre */
.po-sparks {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0;
    height: 0;
    pointer-events: none;
    z-index: 3;
}

.po-sparks i,
.po-ancient-sparks i {
    position: absolute;
    width: var(--sz, 4px);
    height: var(--sz, 4px);
    margin: calc(var(--sz, 4px) / -2);
    border-radius: 50%;
    background: radial-gradient(circle, #fff6d8 0%, var(--po-rar, #ffbf00) 60%, rgba(0, 0, 0, 0) 75%);
    box-shadow: 0 0 8px var(--po-rar, #ffbf00);
    animation: po-spark var(--dur, 900ms) cubic-bezier(0.1, 0.7, 0.3, 1) forwards;
}

@keyframes po-spark {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; }
}

.po-shake { animation: po-shake 0.45s ease-out; }

@keyframes po-shake {
    0%, 100% { transform: translate(0, 0); }
    20% { transform: translate(-5px, 2px); }
    40% { transform: translate(5px, -2px); }
    60% { transform: translate(-3px, 1px); }
    80% { transform: translate(3px, -1px); }
}

/* ── 3 · ANCIENT: the whole screen ────────────────────────── */
.po-ancient {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px 16px;
    box-sizing: border-box;
    background: rgba(6, 3, 0, 0.88);
    cursor: pointer;
    --po-rar: #ff9800;
}

.po-ancient-on .po-ancient { display: flex; animation: po-fade-in 0.35s ease-out; }

.po-ancient-glow {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at 50% 45%, rgba(255, 190, 70, 0.55) 0%, rgba(255, 120, 20, 0.2) 30%, rgba(0, 0, 0, 0) 62%);
    animation: po-glow 2.4s ease-in-out infinite;
}

@keyframes po-glow {
    0%, 100% { opacity: 0.75; transform: scale(0.96); }
    50% { opacity: 1; transform: scale(1.04); }
}

.po-ancient-sparks {
    position: absolute;
    left: 50%;
    top: 45%;
    width: 0;
    height: 0;
    pointer-events: none;
}

.po-ancient-sparks i { --sz: 6px; }

.po-ancient-card {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(70vw, 340px, calc(55vh * 5 / 7));
    aspect-ratio: 5 / 7;
    padding: 10px;
    box-sizing: border-box;
    border: 3px solid #ff9800;
    border-radius: 16px;
    background: radial-gradient(ellipse at 50% 35%, #3a2508, #0b0703 80%);
    box-shadow: 0 0 40px rgba(255, 152, 0, 0.8), 0 0 120px rgba(255, 152, 0, 0.35);
    font-size: 5rem;
    color: #ff9800;
    animation: po-ancient-in 0.9s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.po-ancient-card img { width: 100%; height: 100%; object-fit: contain; }

@keyframes po-ancient-in {
    0% { opacity: 0; transform: scale(0.3) rotate(-8deg); }
    60% { opacity: 1; transform: scale(1.08) rotate(1deg); }
    100% { transform: none; }
}

.po-ancient-rarity {
    position: relative;
    font-size: 1rem;
    font-weight: bold;
    letter-spacing: 8px;
    text-transform: uppercase;
    color: #ff9800;
    text-shadow: 0 0 18px rgba(255, 152, 0, 0.9);
}

.po-ancient-name {
    position: relative;
    max-width: 90vw;
    font-family: 'DragonSlayer', serif;
    font-size: clamp(1.6rem, 6vw, 2.6rem);
    letter-spacing: 1px;
    text-align: center;
    color: #ffd27a;
    text-shadow: 0 0 22px rgba(255, 170, 40, 0.8);
}

.po-ancient-ok { position: relative; margin-top: 6px; }

/* ── inspect a revealed card ─────────────────────────────────
   Hover: a panel beside the card that never takes the pointer (the next card stays clickable).
   Pinned (touch / keyboard): centred over a dim layer; any tap closes it. */
.po-inspect { display: none; }
.po-inspect.r-COMMON   { --po-rar: #9e9e9e; --po-glow: 0; }
.po-inspect.r-UNCOMMON { --po-rar: #4caf50; --po-glow: 1; }
.po-inspect.r-RARE     { --po-rar: #2196f3; --po-glow: 2; }
.po-inspect.r-EPIC     { --po-rar: #ab47bc; --po-glow: 3; }
.po-inspect.r-ANCIENT  { --po-rar: #ff9800; --po-glow: 4; }

.po-inspecting .po-inspect {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 6;
    pointer-events: none;
}

.po-inspect-panel {
    position: absolute;
    width: min(340px, 40vw, calc((100vh - 170px) * 5 / 7 + 28px));
    padding: 14px 14px 16px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--po-rar);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(30, 22, 12, 0.97), rgba(10, 7, 4, 0.98));
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.75), 0 0 calc(8px + var(--po-glow) * 8px) var(--po-rar);
    text-align: center;
    animation: po-inspect-in 0.16s ease-out;
}

@keyframes po-inspect-in {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: none; }
}

.po-inspect-art {
    width: 100%;
    aspect-ratio: 5 / 7;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    color: var(--po-rar);
}

.po-inspect-art img { width: 100%; height: 100%; max-height: none; object-fit: contain; }

.po-inspect-rarity {
    margin-top: 4px;
    font-size: 0.72rem;
    font-weight: bold;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--po-rar);
}

.po-inspect-name {
    font-family: 'DragonSlayer', serif;
    font-size: 1.25rem;
    line-height: 1.15;
    letter-spacing: 0.5px;
    color: var(--po-cream);
    overflow-wrap: anywhere;
}

.po-inspect-type {
    font-size: 0.72rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: rgba(237, 223, 192, 0.6);
}

.po-inspect-pinned {
    background: rgba(4, 3, 1, 0.78);
    cursor: pointer;
}

.po-inspecting .po-inspect.po-inspect-pinned { pointer-events: auto; }

.po-inspect-pinned .po-inspect-panel {
    left: 50%;
    top: 50%;
    width: min(360px, 86vw, calc((100vh - 190px) * 5 / 7 + 28px));
    transform: translate(-50%, -50%);
    animation: none;
}

/* ── phones ───────────────────────────────────────────────── */
@media (max-width: 767px) {
    .po-table { padding: 16px 10px 14px; gap: 10px; }
    .po-table-name { font-size: 1.1rem; }
    .po-btn { min-width: 0; flex: 1 1 140px; padding: 14px 18px; font-size: 0.9rem; letter-spacing: 2px; }
    .po-pack-name { font-size: 1.3rem; }
}

/* ── reduced motion: the same reveal, without the movement ── */
@media (prefers-reduced-motion: reduce) {
    .po-backdrop,
    .po-pack-btn,
    .po-hint-pulse,
    .po-card.po-hinted .po-card-back,
    .po-ancient-glow,
    .po-ancient-card,
    .po-shake,
    .po-card.r-EPIC.flipped .po-card-inner,
    .po-card.r-ANCIENT.flipped .po-card-inner,
    .po-card.po-burst::after,
    .po-inspect-panel {
        animation: none;
    }

    .po-tearing .po-pack-btn { animation: none; opacity: 0; transition: opacity 0.2s; }
    .po-stage-table .po-card { animation: po-fade-in 0.2s forwards; animation-delay: 0s; }
    .po-card-inner { transition: none; }
    .po-card:not(.flipped):hover .po-card-inner { transform: none; }
    .po-card.po-hinted .po-card-back { box-shadow: 0 8px 22px rgba(0, 0, 0, 0.6), 0 0 14px var(--po-rar); }
    .po-sparks, .po-ancient-sparks { display: none; }
}
