/* ============================================================
   packrip — card rendering (shared by public + admin)
   The approved design: elongated body, slightly sharp corners, per-card
   CROP of a larger source image, aura underlay that rotates with the card,
   pointer tilt driving foil/glare via CSS custom properties.

   RARITIES (7, ascending): common grey / uncommon green / rare blue /
   epic purple / legendary gold / holo_band / holo_full. The two holo tiers
   rank above legendary and render a RAINBOW gem + rainbow aura; band shows
   an edge shine line, full a full-card shine. SHINY is a per-card FLAG
   (data-shiny="1"): platinum frame + black text + alt art — combinable
   with every rarity including the holo tiers.
   ============================================================ */

:root {
  --card-w: 212px;
  --card-h: 314px;
  --card-radius: 9px;
  --ease-soft: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-spring: cubic-bezier(0.16, 1.02, 0.3, 1.18);
}

.card {
  position: relative; width: var(--card-w); height: var(--card-h);
  perspective: 950px; cursor: pointer;
  --accent: #cfd6e0; --glow: #94a3b8;
  --pointer-x: 50%; --pointer-y: 50%; --rotate-x: 0deg; --rotate-y: 0deg; --from-center: 0;
  --background-x: 50%; --background-y: 50%;
  transition: transform .3s var(--ease-spring);
}
.card:hover, .card:focus-visible { transform: translateY(-8px) scale(1.035); outline: none; }
.card:focus-visible .frame { box-shadow: inset 0 0 0 2px #7dd3fc, 0 18px 40px rgba(0,0,0,.55); }

.card__rotator {
  position: relative; width: 100%; height: 100%;
  transform: rotateX(var(--rotate-x)) rotateY(var(--rotate-y));
  transition: transform .3s var(--ease-soft); will-change: transform;
}
.card.is-active .card__rotator { transition: transform .08s ease-out; }

/* ---------- aura: blurred SOLID underlay behind the face, rotates with the
   card, shifts opposite the pressed edge (JS sets --glow-shift-*) ---------- */
.card__glow {
  position: absolute; inset: 2%; z-index: 0; border-radius: var(--card-radius);
  background: var(--glow);
  filter: blur(22px); opacity: var(--glow-rest, .18);
  translate: var(--glow-shift-x, 0px) var(--glow-shift-y, 0px);
  transition: opacity .4s var(--ease-soft), translate .15s ease-out;
}
.card.is-active .card__glow, .card:hover .card__glow, .card:focus-visible .card__glow {
  opacity: calc(var(--glow-active, .85) * (1 + var(--from-center, 0) * .1)); }

/* rarity accents + aura strengths */
.card[data-rarity="common"]    { --accent: #cfd6e0; --glow: #94a3b8; --glow-rest: .1;  --glow-active: .4;  }
.card[data-rarity="uncommon"]  { --accent: #7fe0a0; --glow: #34d399; --glow-rest: .22; --glow-active: .55; }
.card[data-rarity="rare"]      { --accent: #6cc6f5; --glow: #38bdf8; --glow-rest: .34; --glow-active: .68; }
.card[data-rarity="epic"]      { --accent: #c9a0ff; --glow: #c084fc; --glow-rest: .48; --glow-active: .84; }
.card[data-rarity="legendary"] { --accent: #ffd766; --glow: #fbbf24; --glow-rest: .62; --glow-active: .95; }
.card[data-rarity="holo_band"],
.card[data-rarity="holo_full"] { --accent: #e6d7ff; --glow: #b06bff; --glow-rest: .7; --glow-active: 1; }
.card[data-rarity="legendary"].is-active .card__glow,
.card[data-rarity="holo_band"].is-active .card__glow,
.card[data-rarity="holo_full"].is-active .card__glow { animation: glowpulse 1.9s ease-in-out infinite; }
@keyframes glowpulse { 0%,100% { opacity: var(--glow-active); } 50% { opacity: calc(var(--glow-active) * .68); } }

/* holo tiers: RAINBOW aura */
.card[data-rarity="holo_band"] .card__glow,
.card[data-rarity="holo_full"] .card__glow {
  background: linear-gradient(130deg, #ff6b8b, #ffd36b, #6bffa3, #6bd4ff, #b06bff);
  animation: glowhue 6s linear infinite; }
@keyframes glowhue {
  from { filter: blur(22px) hue-rotate(0deg); }
  to   { filter: blur(22px) hue-rotate(360deg); } }

/* ---------- frame ---------- */
.frame {
  position: absolute; inset: 0; z-index: 1; border-radius: var(--card-radius); overflow: hidden;
  padding: 7%; display: flex; flex-direction: column; gap: 5%;
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,0) 26%),
              linear-gradient(178deg, #141822, #070a11 82%);
  border: 1px solid rgba(255,255,255,.09);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12),
              inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 22%, transparent),
              inset 0 -30px 50px rgba(0,0,0,.5), 0 18px 40px rgba(0,0,0,.55);
}
.frame::before { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background-image: repeating-linear-gradient(96deg, rgba(255,255,255,.03) 0 1px, transparent 1px 4px); opacity: .6; }

/* ---------- name row: gem carries rarity, no text label ---------- */
.frame__name { position: relative; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 1% 3%; border-bottom: 1px solid color-mix(in srgb, var(--accent) 34%, transparent); }
.frame__title { font-weight: 700; color: #f2f5fb; font-size: calc(var(--card-w) * .085);
  text-shadow: 0 1px 4px rgba(0,0,0,.7); white-space: nowrap; overflow: hidden; }
.frame__gem { width: calc(var(--card-w) * .055); aspect-ratio: 1; flex: none; border-radius: 2px; transform: rotate(45deg);
  background: linear-gradient(135deg, #fff 0%, var(--accent) 48%, color-mix(in srgb, var(--accent) 50%, #000) 100%);
  box-shadow: 0 0 9px color-mix(in srgb, var(--accent) 75%, transparent), inset 0 0 3px rgba(255,255,255,.85); }
/* holo tiers: rainbow gem */
.card[data-rarity="holo_band"] .frame__gem,
.card[data-rarity="holo_full"] .frame__gem {
  background: conic-gradient(from 210deg, #ff6b8b, #ffd36b, #6bffa3, #6bd4ff, #b06bff, #ff6b8b);
  box-shadow: 0 0 10px rgba(214,178,255,.85), inset 0 0 3px rgba(255,255,255,.9);
  animation: gemhue 4s linear infinite; }
@keyframes gemhue { to { filter: hue-rotate(360deg); } }

/* ---------- art window: per-card CROP of a larger source, ABOVE the holo
   layer so shine never covers the illustration ---------- */
.frame__art { position: relative; z-index: 5; flex: 1; min-height: 0; border-radius: 5px; overflow: hidden;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 26%, transparent), inset 0 0 0 3px rgba(0,0,0,.55), inset 0 0 40px rgba(0,0,0,.5); }
.frame__art img {
  width: 100%; height: 100%; display: block;
  object-fit: cover; object-position: var(--crop-pos, 50% 50%);
  transform: scale(var(--crop-zoom, 1)); transform-origin: var(--crop-pos, 50% 50%);
}
.frame__art--empty { display: grid; place-items: center; background: #0a0e18;
  color: rgba(232,235,242,.3); font-size: 12px; letter-spacing: .1em; }

/* ---------- footer: type + optional flavor, no rarity label ---------- */
.frame__foot { position: relative; z-index: 5; display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  padding: 3% 1% 0; border-top: 1px solid rgba(255,255,255,.08); min-height: 0; }
.frame__flavor { font-style: italic; font-size: calc(var(--card-w) * .052); line-height: 1.25; color: rgba(232,235,242,.72);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.frame__type { font-size: calc(var(--card-w) * .048); letter-spacing: .2em; text-transform: uppercase; color: rgba(232,235,242,.55); }

/* ============================================================
   HOLO shine — rainbow foil on the frame (holo tiers only); text and lines
   sit directly over it via z-order, the art is excluded via z-order
   ============================================================ */
.frame__holo { position: absolute; inset: 0; z-index: 4; display: none; opacity: 0; pointer-events: none;
  mix-blend-mode: screen;
  background-image:
    repeating-linear-gradient(112deg,
      #ff6b8b 0%, #ffd36b 14%, #6bffa3 28%, #6bd4ff 42%, #b06bff 56%, #ff6bd4 70%, #ff6b8b 84%),
    repeating-linear-gradient(90deg, rgba(0,0,0,.28) 0 2px, rgba(255,255,255,.05) 2px 4px);
  background-size: 220% 220%, 100% 100%;
  background-position: var(--background-x) var(--background-y), center;
  background-blend-mode: overlay;
  filter: saturate(calc(1.1 + (var(--holo-intensity, 1) - 1) * 1.4)) contrast(1.1);
  transition: opacity .3s var(--ease-soft); }
.card[data-rarity="holo_band"] .frame__holo { display: block;
  opacity: calc((.22 + var(--from-center, 0) * .55) * var(--holo-intensity, 1)); }
.card[data-rarity="holo_full"] .frame__holo { display: block;
  opacity: calc((.12 + var(--from-center, 0) * .34) * var(--holo-intensity, 1)); }

/* band tier: a THIN shine line along the card edge */
.card[data-rarity="holo_band"] .frame__holo { padding: 5px;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask-composite: exclude; }

/* ============================================================
   SHINY flag — platinum/silver body, black text; combinable with any rarity
   ============================================================ */
.card[data-shiny="1"] .frame {
  background: linear-gradient(160deg, #eef1f5 0%, #b7c0cb 44%, #dbe1e8 72%, #aab4bf 100%);
  border-color: rgba(0,0,0,.18);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7),
              inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 30%, transparent),
              inset 0 -26px 44px rgba(90,100,115,.35), 0 18px 40px rgba(0,0,0,.55); }
.card[data-shiny="1"] .frame::before { opacity: .18; }
.card[data-shiny="1"] .frame__title { color: #0c0f14; text-shadow: 0 1px 0 rgba(255,255,255,.4); }
.card[data-shiny="1"] .frame__type { color: rgba(20,24,30,.65); }
.card[data-shiny="1"] .frame__flavor { color: rgba(20,24,30,.78); }
.card[data-shiny="1"] .frame__name { border-bottom-color: rgba(0,0,0,.28); }
.card[data-shiny="1"] .frame__foot { border-top-color: rgba(0,0,0,.16); }
.card[data-shiny="1"] .frame__art { box-shadow: inset 0 0 0 1px rgba(0,0,0,.25), inset 0 0 0 3px rgba(220,226,233,.6), inset 0 0 30px rgba(0,0,0,.35); }
/* shiny WITHOUT a holo tier gets a subtle silver sheen of its own */
.card[data-shiny="1"]:not([data-rarity="holo_band"]):not([data-rarity="holo_full"]) .frame__holo {
  display: block; mix-blend-mode: overlay;
  background-image: repeating-linear-gradient(112deg,
    #6b7280 0%, #ffffff 12%, #9aa4b0 24%, #ffffff 36%, #8a939e 48%, #ffffff 60%, #6b7280 72%);
  background-size: 220% 220%; background-blend-mode: normal;
  filter: contrast(1.2) brightness(1.05);
  opacity: calc(.35 + var(--from-center, 0) * .5); }

/* ---------- glare: pointer-tracked spotlight ---------- */
.frame__glare { position: absolute; inset: 0; z-index: 6; opacity: 0; pointer-events: none; border-radius: var(--card-radius);
  background: radial-gradient(circle at var(--pointer-x) var(--pointer-y), rgba(255,255,255,.7) 0%, rgba(255,255,255,.18) 12%, transparent 46%);
  mix-blend-mode: overlay; transition: opacity .3s var(--ease-soft); }
.card.is-active .frame__glare { opacity: calc(.32 + var(--from-center, 0) * .5); }

/* legendary: slow travelling gold sheen on the frame */
.card[data-rarity="legendary"] .frame::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(112deg, transparent 44%, rgba(255,236,180,.42) 50%, transparent 56%);
  background-size: 300% 300%; mix-blend-mode: overlay; animation: legsheen 5s ease-in-out infinite; }
@keyframes legsheen { 0% { background-position: 130% 0; } 60%,100% { background-position: -30% 0; } }

/* ============================================================
   VIEWER — click a card to zoom it into an inspect view. Zoom uses REAL
   layout size (fixed + px + scaled --card-w/h), never transform:scale.
   ============================================================ */
.dim { position: fixed; inset: 0; z-index: 50; background: rgba(3,4,8,.82); opacity: 0; pointer-events: none;
  transition: opacity .35s var(--ease-soft); }
.dim.is-on { opacity: 1; pointer-events: auto; }

.card.is-zoomed, .card.is-zoomed:hover { z-index: 60; cursor: default; transform: none; }
.card.is-zoomed .card__glow { opacity: var(--glow-active, .85); }

/* full-art button: inside the image container (bottom-right), only while
   zoomed, only rendered on cards flagged has_full_art by the builder */
.frame__fullbtn { position: absolute; right: 5%; bottom: 5%; z-index: 6;
  width: calc(var(--card-w) * .12); aspect-ratio: 1; padding: 0; display: none; align-items: center; justify-content: center;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, rgba(255,255,255,.25)); border-radius: 5px;
  background: rgba(6,9,15,.62); color: #eef2f8; cursor: pointer;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.card.is-zoomed .frame__fullbtn { display: flex; }
.frame__fullbtn:hover { background: rgba(24,32,48,.85); }
.frame__fullbtn svg { width: 58%; height: 58%; }

.fullart { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center;
  background: rgba(2,3,6,.88); cursor: zoom-out; }
.fullart[hidden] { display: none; }
.fullart img { max-width: 92vw; max-height: 92vh; border-radius: 8px;
  box-shadow: 0 30px 80px rgba(0,0,0,.8); }

/* dupe count badge (binder) */
.card__count { position: absolute; right: -7px; top: -7px; z-index: 7; min-width: 24px; height: 24px;
  display: grid; place-items: center; padding: 0 6px; border-radius: 999px;
  background: #7dd3fc; color: #05070c; font-size: 12px; font-weight: 800;
  box-shadow: 0 2px 8px rgba(0,0,0,.5); }

@media (prefers-reduced-motion: reduce) {
  .card, .card__rotator, .card__glow, .frame__holo, .frame__glare { transition: none !important; animation: none !important; }
}
