/* Trading-card face (Pokémon-style layout, Fourth Wing dressing). Sized in container units so it scales as one object. */
.tcg {
  --w: min(92vw, 400px);
  position: relative; z-index: 1;
  width: var(--w); aspect-ratio: 63 / 88;
  container-type: inline-size;
  border: 0; padding: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  --mx: 50%; --my: 50%; --hyp: 0;
}
/* The 3D flip lives on an inner box, not on the <button>: Firefox wraps button children in an anonymous box, which
   breaks preserve-3d (the back then showed a mirrored front and the WebGL art vanished). */
.tcg__flip {
  display: block; position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.9s cubic-bezier(.2, .8, .2, 1);
  transform: rotateY(calc(var(--flip, 0) * 180deg)) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
}
.tcg[aria-pressed='true'] { --flip: 1; }
.tcg.is-tilting .tcg__flip { transition: transform 0.12s ease-out; }
/* belt and braces for engines that mis-cull: swap face visibility at the half-way point of the flip */
.tcg__front { transition: visibility 0s linear 0.3s; }
.tcg__back { visibility: hidden; transition: visibility 0s linear 0.3s; }
.tcg[aria-pressed='true'] .tcg__front { visibility: hidden; }
.tcg[aria-pressed='true'] .tcg__back { visibility: visible; }
.deck .tcg { --w: 100%; }

.tcg__face {
  /* Firefox: mix-blend-mode descendants flatten the preserve-3d context unless each face is its own group (D1) */
  isolation: isolate;
  position: absolute; inset: 0; border-radius: 4.6cqw; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 2.5cqw 7cqw rgba(0, 0, 0, 0.65), 0 0 9cqw color-mix(in srgb, var(--dragon-accent) 22%, transparent);
}

/* ---------- front ---------- */
.tcg__front {
  padding: 3.4cqw;
  /* outer gilded border */
  background:
    linear-gradient(135deg, #f6e3a1 0%, #b88a2c 18%, #f3d98b 34%, #8a6420 52%, #e9c874 70%, #a47a26 86%, #f6e3a1 100%);
}
.tcg__inner {
  position: relative; height: 100%; border-radius: 2.4cqw; overflow: hidden;
  display: flex; flex-direction: column;
  background:
    radial-gradient(120% 60% at 50% 0%, color-mix(in srgb, var(--dragon-accent) 30%, transparent), transparent 60%),
    linear-gradient(170deg, color-mix(in srgb, var(--dragon) 70%, #2a2230), #0d0b10 75%);
  box-shadow: inset 0 0 0 0.6cqw rgba(20, 14, 8, 0.85), inset 0 0 0 0.9cqw rgba(243, 217, 139, 0.55);
  color: #efe6cf;
}
.tcg__top { padding: 2.6cqw 3.4cqw 1.2cqw; display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 0 2cqw; }
.tcg__stage {
  grid-column: 1 / -1; justify-self: start;
  font-family: var(--display); font-size: 2.5cqw; letter-spacing: 0.14em; text-transform: uppercase;
  padding: 0.5cqw 2cqw; border-radius: 999px; margin-bottom: 1.2cqw;
  background: linear-gradient(90deg, rgba(243, 217, 139, 0.9), rgba(184, 138, 44, 0.9)); color: #1d140a;
}
.tcg__name { margin: 0; font-family: var(--display); font-weight: 700; font-size: 8.6cqw; line-height: 1; letter-spacing: 0.04em; color: #fff4d6; text-shadow: 0 0.4cqw 0 rgba(0, 0, 0, 0.6); text-transform: none; }
.tcg__name::after { display: none; }
.tcg__type { display: flex; align-items: center; gap: 1.4cqw; font-family: var(--display); font-size: 2.7cqw; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold-hi); }
.tcg__gem { width: 6.4cqw; height: 6.4cqw; border-radius: 50%; display: grid; place-items: center; color: #fff6dc;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--dragon-accent) 70%, #fff), var(--dragon) 55%, #000 100%);
  box-shadow: 0 0 0 0.5cqw #c9a24a, 0 0 2.4cqw color-mix(in srgb, var(--dragon-accent) 70%, transparent); }
.tcg__gem svg { width: 4.2cqw; height: 4.2cqw; }

.tcg__art {
  position: relative; margin: 0 3.4cqw; flex: 1 1 0; min-height: 38cqw; overflow: hidden; border-radius: 0.8cqw;
  box-shadow: 0 0 0 0.6cqw #20160a, 0 0 0 1.1cqw #d9b45a, 0 0 0 1.4cqw #6b4c16, 0 1.4cqw 3cqw rgba(0, 0, 0, 0.6);
  background: #050407;
}
.tcg__art img, .tcg__art canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tcg__art img { transform: scale(1.04); transition: transform 0.4s; transform-origin: 50% 40%;
  translate: calc((var(--mx) - 50%) * -0.04) calc((var(--my) - 50%) * -0.04); }
.tcg__art canvas.fx { mix-blend-mode: screen; pointer-events: none; }
.tcg__art[data-living] img { object-position: 50% var(--focus-y, 50%); }
.tcg__art canvas.living { z-index: 0; }
.tcg__art.is-living img { visibility: hidden; }
.tcg__art canvas.fx { z-index: 1; }
.tcg__strip { margin: 2.2cqw 3.4cqw 0; padding: 0.8cqw 2cqw; text-align: center; font-style: italic; font-size: 2.7cqw;
  background: linear-gradient(90deg, transparent, rgba(243, 217, 139, 0.85), transparent); color: #1d140a; font-weight: 600; }

.tcg__mid { flex: none; display: flex; flex-direction: column; }
.tcg__body { padding: 1.6cqw 4cqw 0; display: flex; flex-direction: column; gap: 1cqw; }
.tcg__ability, .tcg__move { display: grid; grid-template-columns: auto 1fr auto; gap: 0 2cqw; align-items: baseline; }
.tcg__ability .label { font-family: var(--display); font-size: 2.4cqw; letter-spacing: 0.12em; color: #fff; background: linear-gradient(90deg, #8b1e1e, #b8322a); padding: 0.3cqw 1.6cqw; border-radius: 0.6cqw; }
.tcg__ability .nm, .tcg__move .nm { font-family: var(--display); font-weight: 700; font-size: 3.5cqw; letter-spacing: 0.02em; color: #ffe9b0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tcg__ability p, .tcg__move p { grid-column: 1 / -1; margin: 0.3cqw 0 0; font-size: 2.85cqw; line-height: 1.3; color: #e2d7bd; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tcg__move { padding-top: 1cqw; border-top: 0.25cqw solid rgba(243, 217, 139, 0.25); }
.tcg__move .cost { display: flex; gap: 0.6cqw; }
.tcg__move .cost i { width: 3.8cqw; height: 3.8cqw; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff1b8, #c9a24a 60%, #6b4c16); box-shadow: 0 0 0 0.3cqw #20160a; }
.tcg__move .bk { font-family: var(--display); font-size: 2.6cqw; letter-spacing: 0.1em; color: var(--gold-hi); border: 0.25cqw solid rgba(243, 217, 139, 0.5); border-radius: 999px; padding: 0 1.4cqw; }
.tcg__foot { flex: none; padding: 1.4cqw 4cqw 2.2cqw; }
.tcg__stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; border-top: 0.25cqw solid rgba(243, 217, 139, 0.35); padding-top: 1cqw; }
.tcg__stats div { font-size: 2.6cqw; line-height: 1.2; color: #efe6cf; }
.tcg__stats span { display: block; font-family: var(--display); font-size: 2cqw; letter-spacing: 0.14em; color: var(--muted); text-transform: uppercase; }
.tcg__flavor { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin: 1cqw 0 0; font-style: italic; font-size: 2.6cqw; line-height: 1.25; color: #cfc4a8; text-align: right; }
.tcg__set { display: flex; justify-content: space-between; align-items: center; margin-top: 1.2cqw; font-family: var(--display); font-size: 2.1cqw; letter-spacing: 0.1em; color: var(--muted); }
.tcg__set .sigil { display: inline-flex; align-items: center; gap: 1cqw; }
.tcg__set svg { width: 3.4cqw; height: 3.4cqw; color: var(--gold); }
.tcg__rarity { color: var(--gold-hi); }

/* ---------- holo + glare (pointer / gyroscope / idle shimmer) ---------- */
.tcg__holo, .tcg__glare { position: absolute; inset: 0; pointer-events: none; border-radius: inherit; z-index: 5; }
.tcg__holo {
  mix-blend-mode: color-dodge; opacity: calc(var(--holo, 0.35) * (0.06 + var(--hyp) * var(--hyp) * 0.9));
  background:
    repeating-linear-gradient(115deg, hsl(0 90% 60% / .35) 0%, hsl(45 90% 60% / .35) 4%, hsl(120 80% 55% / .3) 8%, hsl(200 90% 60% / .35) 12%, hsl(280 80% 60% / .35) 16%, hsl(360 90% 60% / .35) 20%),
    repeating-linear-gradient(25deg, rgba(255,255,255,0) 0 1.6cqw, rgba(255,255,255,0.08) 1.6cqw 1.9cqw);
  background-size: 300% 300%, 100% 100%;
  background-position: var(--mx) var(--my), 0 0;
  filter: brightness(0.8) contrast(1.3) saturate(1.2);
}
.tcg__glare { mix-blend-mode: overlay; opacity: calc(0.2 + var(--hyp) * 0.6);
  background: radial-gradient(farthest-corner circle at var(--mx) var(--my), rgba(255, 250, 230, 0.75) 0%, rgba(255, 255, 255, 0.15) 30%, rgba(0, 0, 0, 0.35) 90%); }
/* rarity: how much foil */
.tcg[data-rarity='legendary'] { --holo: 0.85; }
.tcg[data-rarity='legendary'] .tcg__holo { background:
    radial-gradient(circle, rgba(255,255,255,0.9) 0 0.18cqw, transparent 0.3cqw) 0 0 / 3.1cqw 3.1cqw,
    repeating-linear-gradient(115deg, hsl(0 90% 60% / .4) 0%, hsl(45 90% 60% / .4) 4%, hsl(120 80% 55% / .35) 8%, hsl(200 90% 60% / .4) 12%, hsl(280 80% 60% / .4) 16%, hsl(360 90% 60% / .4) 20%) var(--mx) var(--my) / 300% 300%; }
.tcg[data-rarity='rare'] { --holo: 0.6; }
.tcg[data-rarity='uncommon'] { --holo: 0.4; }
.tcg[data-rarity='common'] { --holo: 0.22; }
.tcg[data-rarity='unrecorded'] { --holo: 0.3; }
.tcg[data-rarity='unrecorded'] .tcg__front { background: linear-gradient(135deg, #8a8a96, #3a3a44 40%, #b0b0bc 70%, #4a4a54); }

/* ---------- back (uniform Codex back) ---------- */
.tcg__back {
  transform: rotateY(180deg);
  padding: 3.4cqw;
  background: linear-gradient(135deg, #f6e3a1, #8a6420 40%, #f3d98b 60%, #6b4c16);
}
.tcg__back .tcg__inner { display: grid; place-items: center; text-align: center;
  background:
    radial-gradient(circle at 50% 45%, rgba(201, 162, 74, 0.25), transparent 45%),
    repeating-conic-gradient(from 0deg at 50% 45%, rgba(201, 162, 74, 0.06) 0 6deg, transparent 6deg 12deg),
    linear-gradient(160deg, #1b1310, #07060a 70%); }
.tcg__back .emblem { width: 52cqw; color: var(--gold); filter: drop-shadow(0 0 3cqw rgba(201, 162, 74, 0.5)); }
.tcg__back .title { font-family: var(--display); font-size: 5.4cqw; letter-spacing: 0.22em; color: var(--gold-hi); margin-top: 4cqw; }
.tcg__back .sub { font-style: italic; font-size: 3cqw; color: var(--muted); margin-top: 1cqw; }

/* the collection deck: face-down until revealed */
.collect { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; margin: 8px 0 0; color: var(--parchment-2); font-family: var(--display); font-size: 0.8rem; letter-spacing: 0.12em; text-transform: uppercase; }
.collect button { font: inherit; background: var(--ink); color: var(--gold-hi); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; cursor: pointer; }
.collect progress { width: 140px; accent-color: var(--gold); }
@keyframes reveal-flash { 0% { box-shadow: 0 0 0 0 rgba(255, 230, 150, 0.9); } 100% { box-shadow: 0 0 0 40px rgba(255, 230, 150, 0); } }
.tcg.just-revealed .tcg__front { animation: reveal-flash 0.9s ease-out; }

@media (prefers-reduced-motion: reduce) {
  .tcg__flip, .tcg__front, .tcg__back { transition: none; }
  .tcg__art img { translate: none; }
}

/* ---------- back: set number + rarity foil per tier (SPEC_v2 F1 / §8 Cards) ---------- */
.tcg__back[data-tier='legendary'] { background: conic-gradient(from 210deg at 50% 50%, #f6e3a1, #ffd2f0, #b8e6ff, #d9ffcf, #f6e3a1, #c08a2e, #fff0b8, #f6e3a1); }
.tcg__back[data-tier='rare'] { background: linear-gradient(135deg, #fff1bf, #c9952e 30%, #fff6d6 52%, #9a6c1c 74%, #f3d98b); }
.tcg__back[data-tier='uncommon'] { background: linear-gradient(135deg, #f2f6fa, #8b98a8 32%, #e9eef4 55%, #5e6a78 78%, #d4dbe3); }
.tcg__back[data-tier='common'] { background: linear-gradient(135deg, #f1cfa4, #8c5a2c 36%, #e7bb86 58%, #6b4020); }
.tcg__back[data-tier='unrecorded'] { background: linear-gradient(135deg, #dfe2f0, #5b5f78 34%, #c3c7dc 58%, #3c3f54); }
.tcg__back-foil {
  position: absolute; inset: 0; pointer-events: none; mix-blend-mode: color-dodge; opacity: var(--back-foil, 0.1);
  background: repeating-linear-gradient(120deg, hsl(0 90% 60% / .35) 0%, hsl(50 90% 60% / .35) 5%, hsl(130 80% 55% / .3) 10%, hsl(200 90% 60% / .35) 15%, hsl(280 80% 60% / .35) 20%, hsl(360 90% 60% / .35) 25%) var(--mx) var(--my) / 300% 300%;
}
.tcg__back[data-tier='legendary'] { --back-foil: 0.55; }
.tcg__back[data-tier='rare'] { --back-foil: 0.3; }
.tcg__back[data-tier='uncommon'] { --back-foil: 0.16; }
.tcg__back-number { margin-top: 3.4cqw; font-family: var(--display); font-size: 3.4cqw; letter-spacing: 0.24em; color: var(--gold-hi); }
.tcg__back-tier { margin-top: 1.2cqw; font-size: 3.2cqw; letter-spacing: 0.4em; color: var(--gold); }
.tcg__back[data-tier='legendary'] .tcg__back-tier { color: #ffe08a; text-shadow: 0 0 2cqw rgba(255, 214, 120, 0.8); }
.tcg__back[data-tier='rare'] .tcg__back-tier { color: #cfe4ff; text-shadow: 0 0 1.6cqw rgba(150, 200, 255, 0.7); }
.tcg__back[data-tier='unrecorded'] .tcg__back-tier { color: #c9cde6; }

/* ---------- artist's-interpretation mark (canon art.interpretation; the note itself is never rendered) ---------- */
.tcg__interp {
  font-style: italic; text-transform: none; letter-spacing: 0.03em; white-space: nowrap;
  color: #d9dcec; border: 0.25cqw solid rgba(217, 220, 236, 0.45); border-radius: 999px; padding: 0.15cqw 1.4cqw;
}

/* ---------- just added from a pack ---------- */
.tcg.is-new::before {
  content: ''; position: absolute; inset: -5%; z-index: -1; border-radius: 8cqw; pointer-events: none;
  background: radial-gradient(closest-side, rgba(255, 214, 120, 0.55), rgba(255, 214, 120, 0.15) 60%, transparent);
  animation: new-glow 2.8s ease-in-out infinite;
}
.tcg.is-new::after {
  content: 'New'; position: absolute; top: 4.4cqw; right: -1.6cqw; z-index: 6; pointer-events: none;
  padding: 0.8cqw 3.4cqw 0.8cqw 3cqw; border-radius: 1cqw 0 0 1cqw;
  font-family: var(--display); font-weight: 700; font-size: 3.2cqw; letter-spacing: 0.2em; text-transform: uppercase; color: #1d140a;
  background: linear-gradient(180deg, #fff1bf, #e0b552 60%, #b88a2c);
  box-shadow: 0 1cqw 2.4cqw rgba(0, 0, 0, 0.5), 0 0 3cqw rgba(255, 214, 120, 0.5);
}
@keyframes new-glow { 0%, 100% { opacity: 0.55; transform: scale(0.98); } 50% { opacity: 1; transform: scale(1.02); } }
@media (prefers-reduced-motion: reduce) { .tcg.is-new::before { animation: none; } }
.tcg.fly-in { animation: fly-in 0.95s cubic-bezier(.2, .85, .25, 1.05) both; }
@keyframes fly-in {
  0% { opacity: 0; transform: translate3d(0, -42vh, 0) scale(0.35) rotate(-8deg); }
  60% { opacity: 1; }
  100% { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .tcg.fly-in { animation: none; } }
