/* ==========================================================================
   TRADING CARDS v3 — seven rarity identities driven by CSS variables.
   .tcard is a size container (container-type:inline-size, 5:7); every inner size is in cqw
   (1cqw = 1% of the card's width), so one markup scales from a 150px tile to a 400px hero.

   Variables (set per rarity by /theme/frames, per border by .fr-<id>; admin editable):
     --c1 --c2 --c3   main / shade / highlight colour      --glow --gsz   glow colour / size
     --spd            rarity animation speed               --bsp          border animation speed
     --holo           holographic strength 0..1            --tilt         3D tilt strength
     --bw             frame thickness (cqw)                --k            duration factor = 1/(spd*bsp)
     --play           running|paused for the frame/foil    --fxp          running|paused for the heavy fx layers

   Cheap by design (see docs/BORDERS.md):
     • only transform / translate / rotate / scale / opacity are animated (compositor only, no layout, no paint)
     • --play follows the rarity's animation mode (always | live | hover | off); --fxp is on hover and hero cards only
     • big grids throttle themselves: with more than 12 cards in a grid only the hovered card animates
     • body.fx-lite (user setting) and prefers-reduced-motion switch every animation and fx layer off
     • tilt without JS: 165 invisible hover zones (11 x 15) that are SIBLINGS in front of the card (a.tcw > b ... + .tcard);
       "zone:hover ~ .tcard" sets --rx/--ry/--gx/--gy. No :has(), and the zones do not rotate with the card. The same --gx/--gy
       move the foil, the specular light (a fixed gradient moved by translate) and the parallax of the art (depth)
   ========================================================================== */
@keyframes spin { to { rotate: 360deg; } }
@keyframes sweep { from { transform: translateX(-140%) skewX(-18deg); } to { transform: translateX(260%) skewX(-18deg); } }
@keyframes twinkle { 0%, 100% { opacity: 0; transform: scale(.2) rotate(0); } 50% { opacity: 1; transform: scale(1) rotate(45deg); } }
@keyframes halo { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@keyframes foil { from { transform: translateX(-9%); } to { transform: translateX(9%); } }
@keyframes floaty { 0%, 100% { translate: 0 0; } 50% { translate: 0 -9px; } }

/* ---- Card ----------------------------------------------------------------------------- */
/* .tcw is the (link) wrapper: it owns the hover state and the pointer zones; .tcard inside it is the part that tilts.
   The zones are siblings placed BEFORE the card (see cards-tilt.css), so no :has() is needed and the hit areas do not rotate with the card. */
.tcw { position: relative; display: block; color: inherit; text-decoration: none; }
.tcw:hover { z-index: 3; }
.tcw > b { position: absolute; z-index: 6; display: block; }
.tcard {
    --rx: 0deg; --ry: 0deg; --gx: 50%; --gy: 50%;
    --c1: #d9935a; --c2: #6b3f1d; --c3: #f0b987; --glow: rgba(217, 147, 90, .3); --gsz: 5;
    --zd: 1; --spd: 1; --bsp: 1; --holo: 0; --tilt: 1; --bw: 2.2; --play: paused; --fxp: paused;
    --k: calc(1 / (var(--spd) * var(--bsp)));
    position: relative; display: block; width: 100%; aspect-ratio: 5 / 7; container-type: inline-size; transform-style: flat;
    border-radius: 6% / 4.3%; color: #fff; text-decoration: none;
    transform: none; /* at rest the card is flat: a perspective + preserve-3d layer drew thin dark tile seams across the art on some GPUs */
    transition: transform .26s cubic-bezier(.25,.6,.3,1);
    box-shadow: 0 10px 22px rgba(0, 0, 0, .55), 0 0 calc(var(--gsz) * 2.4px) -5px var(--glow);
}
.tcard.live, .tcard.has-cvb, .tcard.has-bx { transform-style: preserve-3d; transform: perspective(900px) rotateX(calc(var(--rx) * var(--tilt))) rotateY(calc(var(--ry) * var(--tilt))); }
.tcw:hover>.tcard { color: #fff; z-index: 3; transform-style: preserve-3d; transform: perspective(900px) translateY(-6px) scale(1.035) rotateX(calc(var(--rx) * var(--tilt))) rotateY(calc(var(--ry) * var(--tilt))); }
.tcard::after { content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; opacity: 0; transition: opacity .3s; box-shadow: 0 14px 26px rgba(0, 0, 0, .6), 0 0 calc(var(--gsz) * 3px) 0 var(--glow); }
.tcw:hover>.tcard::after { opacity: 1; }
.tcard * { box-sizing: border-box; }

/* animation modes (class am-* from the rarity settings) */
.tcard.am-always { --play: running; }
.tcw:hover>.tcard, .tcard.live { --play: running; --fxp: running; }
.tcard.am-off, .tcw:hover>.tcard.am-off, .tcard.am-off.live { --play: paused; --fxp: paused; }
.tcard.is-locked, .tcw:hover>.tcard.is-locked { --play: paused !important; --fxp: paused !important; }
/* dense grids: more than 12 cards -> only the hovered card animates */
.card-grid:has(> .cell:nth-child(13)) .tcw:not(:hover)>.tcard:not(.live) { --play: paused !important; --fxp: paused !important; }
/* spotlight: inside a .spot container (showcases, the border test page) only the card under the pointer animates; the others rest,
   so the browser spends its time on the card being tilted. One :has() on the container, evaluated when a card is entered or left. */
.spot:has(.tcw:hover) .tcw:not(:hover) > .tcard { --play: paused !important; --fxp: paused !important; }

/* aura: a breathing glow behind Legendary and above */
.tcard.r-legendary::before, .tcard.r-mythic::before, .tcard.r-exclusive::before, .tcard.r-ultimate::before {
    content: ""; position: absolute; inset: -1cqw; z-index: -1; border-radius: 7.4% / 5.3%; pointer-events: none; opacity: .5;
    box-shadow: 0 0 calc(var(--gsz) * 1.3cqw) calc(var(--gsz) * .12cqw) var(--glow);
    animation: halo calc(2.8s * var(--k)) ease-in-out infinite; animation-play-state: var(--play);
}

.tc-shell { position: absolute; inset: 0; border-radius: inherit; overflow: hidden; background: #000; }

/* ---- Frame (ring) per rarity ---------------------------------------------------------- */
.tc-ring { position: absolute; left: 50%; top: 50%; width: 190%; aspect-ratio: 1; translate: -50% -50%; rotate: 0deg; background: linear-gradient(145deg, var(--c3), var(--c1) 30%, var(--c2) 62%, var(--c1)); }
.r-rare .tc-ring { background: repeating-linear-gradient(90deg, rgba(255, 255, 255, .16) 0 .3%, transparent .3% .85%), linear-gradient(145deg, var(--c3), var(--c1) 32%, var(--c2) 58%, var(--c1) 84%, var(--c3)); }
.r-epic .tc-ring { background: linear-gradient(145deg, var(--c3), var(--c1) 22%, var(--c2) 46%, var(--c1) 70%, var(--c3) 92%); }
.r-legendary .tc-ring { background: conic-gradient(var(--c1), var(--c3), var(--c2), var(--c1) 55%, var(--c3) 78%, var(--c1)); animation: spin calc(7s * var(--k)) linear infinite; animation-play-state: var(--play); }
.r-mythic .tc-ring { background: conic-gradient(var(--c1), var(--c3), var(--c2), var(--c1) 50%, var(--c3) 74%, var(--c2) 88%, var(--c1)); animation: spin calc(5s * var(--k)) linear infinite; animation-play-state: var(--play); }
.r-exclusive .tc-ring { background: conic-gradient(var(--c1), var(--c2), var(--c3), #7cffd0, var(--c1)); animation: spin calc(5.5s * var(--k)) linear infinite; animation-play-state: var(--play); }
.r-ultimate .tc-ring { background: conic-gradient(#ff3d57, var(--c1), #3ddc84, var(--c3), #a66bff, var(--c2), #ff3d57); animation: spin calc(4s * var(--k)) linear infinite; animation-play-state: var(--play); }

/* lighting: a bevel on the frame edge + a specular highlight that follows the pointer (sits under the art, so only the frame shows it) */
.tc-edge { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; overflow: hidden; opacity: 0; transition: opacity .3s; }
/* the specular spot is a FIXED gradient that is moved with translate (compositor only, glides) instead of a gradient that is repainted at every pointer step */
.tc-edge::before { content: ""; position: absolute; left: 50%; top: 50%; width: 100cqw; height: 100cqw; margin: -50cqw 0 0 -50cqw; background: radial-gradient(closest-side, rgba(255, 255, 255, .7), transparent 66%);
    translate: calc(var(--gx) - 50%) calc((var(--gy) - 50%) * 1.4); transition: translate .22s ease-out; }
.tcw:hover>.tcard .tc-edge, .tcard.live .tc-edge { opacity: .8; }
.tc-edge::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; box-shadow: inset 0 0 0 .35cqw rgba(255, 255, 255, .26), inset 0 1cqw 1.4cqw rgba(255, 255, 255, .2), inset 0 -1.4cqw 1.8cqw rgba(0, 0, 0, .4); }

.tc-body { position: absolute; inset: calc(var(--bw) * 1cqw); border-radius: 3.9cqw; overflow: hidden; background: #0a0a0d; }
.tc-art { position: absolute; inset: 0; overflow: hidden; isolation: isolate; }
/* depth: the art drifts against the pointer a little, the name plate the other way */
.tc-art svg, .tc-art img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; object-fit: cover; max-width: none; max-height: none; inset: -2%; width: 104%; height: 104%;
    transition: inset .5s var(--ease), width .5s var(--ease), height .5s var(--ease); } /* no pointer drift: the picture stays centred in its frame */
.tcw:hover>.tcard .tc-art svg, .tcw:hover>.tcard .tc-art img { inset: -4.5%; width: 109%; height: 109%; }
.tc-shade { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(to top, rgba(0, 0, 0, .94) 0, rgba(0, 0, 0, .6) 20%, transparent 46%), linear-gradient(to bottom, rgba(0, 0, 0, .5), transparent 22%); }

.tc-tag { position: absolute; left: 3cqw; top: 3cqw; padding: 1.1cqw 2.6cqw 1.1cqw 2.2cqw; font: italic 800 4.4cqw/1 var(--body); letter-spacing: .05em; color: var(--c1); background: rgba(0, 0, 0, .72); border: .4cqw solid var(--c1); border-radius: .8cqw; }
.r-epic .tc-tag, .r-legendary .tc-tag, .r-mythic .tc-tag { background: linear-gradient(135deg, rgba(0, 0, 0, .78), color-mix(in srgb, var(--c2) 45%, #000)); }
.r-exclusive .tc-tag, .r-ultimate .tc-tag { color: #12080f; background: linear-gradient(90deg, var(--c1), var(--c2) 55%, var(--c3)); border-color: transparent; }
.tc-elem { position: absolute; right: 3cqw; top: 3cqw; width: 9cqw; height: 9cqw; display: grid; place-items: center; border-radius: 50%; color: var(--c1); background: rgba(0, 0, 0, .66); border: .4cqw solid color-mix(in srgb, var(--c1) 60%, transparent); }
.tc-elem .ico { width: 5.2cqw; height: 5.2cqw; stroke-width: 2; }

.tc-info { position: absolute; left: 3.6cqw; right: 3.6cqw; bottom: 3.2cqw; display: flex; flex-direction: column; gap: 1.1cqw; }
.tc-name { font: 400 9.4cqw/.95 var(--display); letter-spacing: .02em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 .6cqw 1.4cqw #000; }
.r-epic .tc-name, .r-legendary .tc-name, .r-mythic .tc-name, .r-exclusive .tc-name, .r-ultimate .tc-name { text-shadow: 0 .6cqw 1.4cqw #000, 0 0 3cqw color-mix(in srgb, var(--c1) 55%, transparent); }
.tc-series { font: 700 3cqw/1.2 var(--body); letter-spacing: .1em; text-transform: uppercase; color: #cbcbd4; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tc-nums { display: flex; gap: 3.2cqw; align-items: center; margin-top: .6cqw; padding-top: 1.8cqw; border-top: .3cqw solid color-mix(in srgb, var(--c1) 38%, rgba(255, 255, 255, .1)); font: 800 4.8cqw/1 var(--body); letter-spacing: .01em; }
.tc-nums span { display: inline-flex; align-items: center; gap: 1.2cqw; }
.tc-nums .ico { width: 4.6cqw; height: 4.6cqw; stroke-width: 2.2; }
.tc-nums .a .ico { color: #ff7a4a; } .tc-nums .h .ico { color: #ff5a78; } .tc-nums .s .ico { color: #ffe066; }
.tc-lvl { position: absolute; z-index: 4; left: 5cqw; bottom: 30cqw; padding: .9cqw 2.6cqw; font: 800 3.8cqw/1.2 var(--body); color: #ffe9a8; background: rgba(0, 0, 0, .85); border: .3cqw solid #b8902f; border-radius: 99px; }
.tc-qty { position: absolute; z-index: 4; right: 5cqw; bottom: 30cqw; padding: .9cqw 2.6cqw; font: 800 3.8cqw/1.2 var(--body); background: rgba(0, 0, 0, .85); border: .3cqw solid var(--line2); border-radius: 99px; }

/* ---- Holographic foil: strength = --holo (Admin > Rarities). Rainbow band follows the pointer, drifts when idle ------ */
.tc-holo { position: absolute; inset: 0; z-index: 1; overflow: hidden; border-radius: inherit; pointer-events: none; opacity: calc(var(--holo) * .3); transition: opacity .3s; }
.tcw:hover>.tcard .tc-holo, .tcard.live .tc-holo { opacity: calc(var(--holo) * .42); }
.tc-holo::before { content: ""; position: absolute; inset: -10% -60%; translate: calc((50% - var(--gx)) * .7) 0; transition: translate .25s ease-out;
    background: linear-gradient(105deg, transparent 22%, rgba(255, 61, 87, .5) 31%, rgba(255, 217, 138, .5) 39%, rgba(61, 220, 132, .45) 47%, rgba(70, 214, 255, .5) 55%, rgba(166, 107, 255, .5) 63%, transparent 74%);
    animation: foil calc(6s * var(--k)) ease-in-out infinite alternate; animation-play-state: var(--play); }
.tc-holo::after { content: none; }

/* foil sweep + glare (cheap: one translated strip, one radial gradient) */
.tc-gloss { position: absolute; inset: 0; z-index: 2; overflow: hidden; border-radius: inherit; pointer-events: none; }
.tc-gloss::before { content: ""; position: absolute; top: -10%; bottom: -10%; left: 0; width: 42%; background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .3), transparent); transform: translateX(-140%) skewX(-18deg); }
.tcw:hover>.tcard .tc-gloss::before { animation: sweep .9s var(--ease) 1 both; }
.tc-gloss::after { content: ""; position: absolute; left: 50%; top: 50%; width: 140cqw; height: 140cqw; margin: -70cqw 0 0 -70cqw; opacity: 0; background: radial-gradient(closest-side, rgba(255, 255, 255, .26), transparent 67%);
    translate: calc((var(--gx) - 50%) * .714) calc(var(--gy) - 50%); transition: opacity .3s, translate .22s ease-out; }
.tcw:hover>.tcard .tc-gloss::after { opacity: 1; }
.r-legendary .tc-body::after, .r-mythic .tc-body::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(115deg, transparent 30%, color-mix(in srgb, var(--c1) 22%, transparent) 50%, transparent 70%); }

.tc-sparks { position: absolute; inset: 0; z-index: 3; pointer-events: none; display: none; }
.r-legendary .tc-sparks, .r-mythic .tc-sparks, .r-exclusive .tc-sparks, .r-ultimate .tc-sparks { display: block; }
.tc-sparks i { position: absolute; width: 4.4cqw; height: 4.4cqw; background: #fff; clip-path: polygon(50% 0, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0 50%, 40% 40%); opacity: 0; animation: twinkle 3.2s ease-in-out infinite; animation-play-state: var(--play); }
.tc-sparks i:nth-child(1) { left: 14%; top: 24%; } .tc-sparks i:nth-child(2) { left: 78%; top: 34%; animation-delay: -1.1s; width: 3.2cqw; height: 3.2cqw; }
.tc-sparks i:nth-child(3) { left: 62%; top: 12%; animation-delay: -2.1s; } .tc-sparks i:nth-child(4) { left: 24%; top: 52%; animation-delay: -.6s; width: 3cqw; height: 3cqw; }
.r-legendary .tc-sparks i:nth-child(n+3) { display: none; }

/* 3D tilt without JavaScript: the pointer zones live in cards-tilt.css (generated by bin/build-card-css.php) */


/* locked (not owned) */
.tcard.is-locked { box-shadow: 0 8px 18px rgba(0, 0, 0, .5); }
.tcard.is-locked::before { display: none; }
.tcard.is-locked .tc-body { filter: grayscale(1) brightness(.42); }
.tcard.is-locked .tc-ring { filter: grayscale(1) brightness(.5); animation: none; }
.tcard.is-locked .tc-sparks, .tcard.is-locked .tc-body::after, .tcard.is-locked .tc-holo { display: none; }  /* the borders (.tc-fx, .tc-fxb, .tc-fxin, .tc-bx, .tc-overlay, .tc-tpl and the canvas ones) stay on unowned cards */
.tc-lock { position: absolute; z-index: 4; inset: 0; display: grid; place-items: center; pointer-events: none; }
.tc-lock span { width: 17cqw; height: 17cqw; display: grid; place-items: center; border-radius: 50%; background: rgba(0, 0, 0, .75); border: .5cqw solid rgba(255, 255, 255, .25); color: #cfcdd8; }
.tc-lock .ico { width: 8cqw; height: 8cqw; }

/* ---- Effects off: user setting "lite" and the OS reduced-motion preference ------------------------ */
body.fx-lite .tcard { --play: paused !important; --fxp: paused !important; }
body.fx-lite .tc-fx, body.fx-lite .tc-fxin, body.fx-lite .tc-holo::before { display: none; }
@media (prefers-reduced-motion: reduce) {
    .tcard, .tcard *, .tcard *::before, .tcard *::after { animation: none !important; }
    .tc-fx, .tc-fxin { display: none; }
}

/* ---- Grids / showcase ----------------------------------------------------------------------------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .4rem .2rem; }
.card-grid.small { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.card-grid > * { min-width: 0; }
/* off-screen cells are skipped by the browser; cells whose border draws outside the card must not be clipped */
.cell { display: flex; flex-direction: column; gap: .5rem; padding: 16px; }  /* no content-visibility here: it left a thin dark seam across some cards in the collection grid */
.cell:has(.has-fx) { content-visibility: visible; padding: 20px; }
.cell-cap { display: flex; justify-content: space-between; align-items: center; gap: .5rem; font-size: .76rem; color: var(--muted); padding: 0 .2rem; }
.showcase { display: flex; gap: 1rem; overflow-x: auto; scroll-snap-type: x mandatory; padding: 1.4rem 1.4rem 1.6rem; scrollbar-width: thin; scrollbar-color: #333 transparent; }
.showcase > * { flex: none; width: 210px; scroll-snap-align: start; }
.hero-card { width: min(380px, 100%); margin: 0 auto; }

/* ---- Real depth: the layers are siblings stacked in 3D space (--zd scales the distance) -------------------- */
/* only while the card is hovered / live (see above): at rest every layer is flat. Cards with a custom 3D border (canvas or spec) keep their 3D context all the time (only the layers are flattened at rest): switching the card itself between flat and 3D made the border disappear after a hover. */
.tcw:not(:hover)>.tcard:not(.live) :is(.tc-shell, .tc-fxb, .cvb, .cvb-bk, .tc-holo, .tc-overlay, .tc-tpl, .tc-fxin, .tc-gloss, .tc-sparks, .tc-fx, .tc-lock, .tc-qty, .tc-lvl) { transform: none; }

.tc-shell { transform: translateZ(0); }
.tc-holo { transform: translateZ(calc(1.2cqw * var(--zd))); }
.tc-overlay, .tc-tpl { transform: translateZ(calc(2cqw * var(--zd))); }
.tc-fxin { transform: translateZ(calc(3cqw * var(--zd))); }
.tc-gloss { transform: translateZ(calc(3.6cqw * var(--zd))); }
.tc-sparks { transform: translateZ(calc(6cqw * var(--zd))); overflow: hidden; border-radius: inherit; }
.tc-fx { transform: translateZ(calc(9cqw * var(--zd))); }
.tc-lock, .tc-qty, .tc-lvl { transform: translateZ(calc(10cqw * var(--zd))); }

.cbrief { margin-top: .4rem; font-size: .78rem; text-align: left; }
.cbrief summary { cursor: pointer; color: var(--muted, #9aa); }
.cbrief ul { margin: .3rem 0 0; padding-left: 1rem; }
.cbrief li { margin-bottom: .35rem; }
.cbrief .cb-pas { margin: .3rem 0; }

.cbrief .cb-form { margin: .3rem 0; }
.cbrief .cb-form a { text-decoration: underline; }

/* ---- thin dark seams: keep each card a single, whole-pixel painted surface (belt and braces with the flat-at-rest rule above) ---- */
.tc-body, .tc-art { backface-visibility: hidden; }
.tc-art svg, .tc-art img { backface-visibility: hidden; image-rendering: auto; }

/* alternative arts on the card page */
.alt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.alt-cell { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 36px 24px 56px; }
.alt-cell .tcw { width: 100%; max-width: 170px; }
.alt-cell.alt-on .tcard { outline: 2px solid var(--accent, #9b6bff); outline-offset: 3px; border-radius: 14px; }
.alt-cell.alt-locked b { opacity: .6; }
.alt-list { display: grid; gap: 10px; margin: 10px 0 18px; }
.alt-item { display: flex; gap: 12px; align-items: center; }
.alt-th { width: 56px; height: 78px; object-fit: cover; border-radius: 6px; }
.alt-cell.alt-locked .tcw { filter: grayscale(1) brightness(.75); }
.alt-cell b { margin-top: 8px; }
