.ccard-frame {
  --card-accent: #8b9098;
  --card-glow: rgba(139, 144, 152, .22);
  --card-backlight: rgba(139, 144, 152, .38);
  --card-edge-glow: rgba(139, 144, 152, .42);
  --card-shape: url('/public/assets/cards-battle/card-front.png');
  --card-preview-side: 12.5%;
  --card-preview-left: 10.85%;
  --card-preview-size: 77.05%;
  --card-preview-offset: 11.5%;
  position: relative;
  width: min(100%, 300px);
  aspect-ratio: 0.7;
  perspective: 1100px;
  user-select: none;
  touch-action: pan-y;
  isolation: isolate;
}

.ccard-frame::before {
  content: "";
  position: absolute;
  inset: -8% -12% -7%;
  z-index: 0;
  border-radius: 28% / 18%;
  background:
    radial-gradient(ellipse at center, var(--card-backlight) 0 28%, var(--card-glow) 42%, transparent 76%),
    radial-gradient(ellipse at 50% 74%, var(--card-glow) 0 30%, transparent 68%);
  filter: blur(20px);
  opacity: 0;
  pointer-events: none;
  transform: scale(.98);
  transition: opacity .18s ease, transform .18s ease;
}

.ccard-frame--uncommon,
.ccard-frame--rare,
.ccard-frame--epic,
.ccard-frame--legendary {
  --card-frame-glow-opacity: .95;
}

.ccard-frame--uncommon::before,
.ccard-frame--rare::before,
.ccard-frame--epic::before,
.ccard-frame--legendary::before {
  opacity: var(--card-frame-glow-opacity);
}

.ccard-frame--rare::before,
.ccard-frame--epic::before,
.ccard-frame--legendary::before {
  inset: -10% -14% -9%;
  filter: blur(23px);
}

.ccard-frame--legendary::before {
  --card-frame-glow-opacity: 1;
  filter: blur(26px);
  transform: scale(1.02);
  animation: ccard-frame-legendary-glow 3s ease-in-out infinite;
}

.ccard-frame--uncommon .ccard::before,
.ccard-frame--rare .ccard::before,
.ccard-frame--epic .ccard::before,
.ccard-frame--legendary .ccard::before {
  filter:
    drop-shadow(0 0 10px var(--card-edge-glow))
    drop-shadow(0 0 22px var(--card-glow));
}

.ccard-frame--rare .ccard::before,
.ccard-frame--epic .ccard::before,
.ccard-frame--legendary .ccard::before {
  filter:
    drop-shadow(0 0 12px var(--card-edge-glow))
    drop-shadow(0 0 30px var(--card-glow));
}

.ccard-frame--legendary .ccard::before {
  filter:
    drop-shadow(0 0 14px var(--card-edge-glow))
    drop-shadow(0 0 36px var(--card-glow));
}

.ccard {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-sizing: border-box;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #f4f8ff;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  transform-style: preserve-3d;
  transition: transform .12s ease-out, opacity .2s ease;
  will-change: transform;
}

.ccard::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: var(--card-shape) center / 100% 100% no-repeat;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  transform: translateZ(0);
}

.ccard-frame[data-active="true"] .ccard::before {
  filter: brightness(1.08);
}

.ccard::before,
.ccard__surface,
.ccard__shine {
  -webkit-mask-image: var(--card-shape);
  -webkit-mask-position: center;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
  -webkit-mask-mode: alpha;
  mask-image: var(--card-shape);
  mask-mode: alpha;
  mask-position: center;
  mask-repeat: no-repeat;
  mask-size: 100% 100%;
}

.ccard__surface {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 0;
  pointer-events: none;
  transform: translateZ(0);
}

.ccard__shine {
  position: absolute;
  inset: 0;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 0%), rgba(255, 255, 255, .16), transparent 45%);
  transition: opacity .2s;
}

.ccard-frame:hover .ccard__shine,
.ccard-frame.is-tilting .ccard__shine { opacity: 1; }

.ccard__media {
  position: relative;
  flex: none;
  width: var(--card-preview-size);
  aspect-ratio: 1;
  overflow: hidden;
  box-sizing: border-box;
  margin: var(--card-preview-offset) 0 0 var(--card-preview-left);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 8px;
  background: #0e071b;
  transform: translateZ(40px);
}

.ccard__thumb,
.ccard__live {
  width: 100%;
  height: 100%;
  display: block;
  box-sizing: border-box;
  border: 0;
  border-radius: 0;
  background: transparent;
  image-rendering: pixelated;
}

.ccard__world,
.ccard__rarity {
  position: absolute;
  top: 7px;
  z-index: 2;
  padding: 4px 7px;
  border-radius: 4px;
  background: rgba(14, 7, 27, .88);
  font-family: "Micro 5", sans-serif;
  font-size: 18px;
  line-height: 1;
}

.ccard__world { left: 7px; }
.ccard__rarity {
  right: 7px;
  color: var(--card-accent);
  font-family: "pixel-ttf", sans-serif;
  font-size: 14px;
  letter-spacing: .5px;
}

.ccard__body {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: flex-start;
  gap: 7px;
  box-sizing: border-box;
  padding: 10px var(--card-preview-side) 12px;
  transform: translateZ(26px);
}

.ccard__author {
  position: absolute;
  left: 7px;
  bottom: 7px;
  z-index: 2;
  max-width: calc(100% - 14px);
  box-sizing: border-box;
  padding: 4px 7px;
  overflow: hidden;
  border-radius: 4px;
  background: rgba(14, 7, 27, .88);
  color: #f4f8ff;
  font-family: "pixel-ttf", sans-serif;
  font-size: 14px;
  line-height: 1;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ccard__stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.ccard__stat {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 4px 3px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-family: "pixel-ttf", sans-serif;
}

.ccard__stat small { color: #77808d; font-size: 14px; letter-spacing: .5px; }
.ccard__stat strong { max-width: 100%; color: #f4f8ff; font-size: 14px; font-weight: 400; letter-spacing: .5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ccard__stat--timer small {
  color: #f4f8ff;
}
.ccard__stat--timer strong {
  color: #f4f8ff;
  font-size: 16px;
}

.ccard-frame--uncommon,
.ccard--uncommon { --card-accent: #72ae62; --card-glow: rgba(114,174,98,.28); --card-backlight: rgba(114,174,98,.58); --card-edge-glow: rgba(114,174,98,.72); }
.ccard-frame--rare,
.ccard--rare {
  --card-accent: #58aedd;
  --card-glow: rgba(88,174,221,.32);
  --card-backlight: rgba(88,174,221,.64);
  --card-edge-glow: rgba(88,174,221,.78);
  --card-shape: url('/public/assets/cards-battle/card-front-prime.png');
}
.ccard-frame--epic,
.ccard--epic {
  --card-accent: #f6bc57;
  --card-glow: rgba(246,188,87,.36);
  --card-backlight: rgba(246,188,87,.68);
  --card-edge-glow: rgba(246,188,87,.82);
  --card-shape: url('/public/assets/cards-battle/card-front-gold.png');
}
.ccard-frame--legendary,
.ccard--legendary {
  --card-accent: #d66bff;
  --card-glow: rgba(239,110,91,.42);
  --card-backlight: rgba(214,107,255,.72);
  --card-edge-glow: rgba(214,107,255,.86);
  --card-shape: url('/public/assets/cards-battle/card-front-lega.png');
}

.ccard--rare .ccard__surface::after,
.ccard--epic .ccard__surface::after,
.ccard--legendary .ccard__surface::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  transition: opacity .2s ease, background-position .25s ease-out;
}

/* Rare — a soft cool glare that tracks the pointer. */
.ccard--rare .ccard__surface::after {
  opacity: 1;
  background: linear-gradient(108deg,
    rgba(150, 215, 255, 0) 35%,
    rgba(150, 215, 255, .06) 46%,
    rgba(225, 245, 255, .28) 50%,
    rgba(150, 215, 255, .06) 54%,
    rgba(150, 215, 255, 0) 65%);
  background-size: 240% 240%;
  background-position: var(--mx, 50%) var(--my, 50%);
}

/* Epic — golden foil: a bright highlight that slides with the pointer/tilt
   (like the legendary holo, but stays gold instead of cycling the spectrum). */
.ccard--epic .ccard__surface::after {
  opacity: 1;
  background: linear-gradient(120deg,
    rgba(246, 188, 87, 0) 35%,
    rgba(246, 188, 87, .1) 46%,
    rgba(246, 188, 87, .55) 50%,
    rgba(246, 188, 87, .1) 54%,
    rgba(246, 188, 87, 0) 65%);
  background-size: 220% 220%;
  background-position: var(--mx, 50%) var(--my, 50%);
}

/* Legendary — seamless animated rainbow holo + a glare that follows the pointer. */
.ccard--legendary::before { animation: ccard-legendary-pulse 2.4s ease-in-out infinite; }
.ccard--legendary .ccard__thumb,
.ccard--legendary .ccard__live { background: #190b19; }
.ccard--legendary .ccard__surface::after {
  opacity: .62;
  background:
    linear-gradient(125deg,
      rgba(255, 80, 170, .62),
      rgba(255, 150, 70, .62),
      rgba(255, 95, 175, .62),
      rgba(150, 110, 255, .62),
      rgba(80, 140, 255, .62),
      rgba(225, 70, 205, .62)),
    linear-gradient(305deg,
      rgba(120, 150, 255, .5),
      rgba(255, 255, 255, 0) 45%,
      rgba(255, 90, 200, .5));
  background-size: 240% 240%, 200% 200%;
  background-position: var(--mx, 50%) var(--my, 50%);
  background-blend-mode: screen;
  animation: ccard-legendary-foil 7s linear infinite;
}
.ccard--legendary .ccard__surface::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background: linear-gradient(108deg,
    rgba(255, 255, 255, 0) 38%,
    rgba(255, 255, 255, .07) 47%,
    rgba(255, 255, 255, .38) 50%,
    rgba(255, 255, 255, .07) 53%,
    rgba(255, 255, 255, 0) 62%);
  background-size: 240% 240%;
  background-position: var(--mx, 50%) var(--my, 50%);
  transition: background-position .25s ease-out;
}

.ccard--back {
  --card-shape: url('/public/assets/cards-battle/card.png');
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

@keyframes ccard-legendary-pulse {
  0%, 100% {
    filter:
      brightness(1)
      drop-shadow(0 0 14px var(--card-edge-glow))
      drop-shadow(0 0 36px var(--card-glow));
  }
  50% {
    filter:
      brightness(1.08)
      drop-shadow(0 0 14px var(--card-edge-glow))
      drop-shadow(0 0 36px var(--card-glow));
  }
}

@keyframes ccard-legendary-foil {
  0%, 100% { filter: hue-rotate(-22deg) saturate(1.5); }
  50% { filter: hue-rotate(22deg) saturate(1.5); }
}

@keyframes ccard-frame-legendary-glow {
  0%, 100% { opacity: .82; transform: scale(.98); }
  50% { opacity: 1; transform: scale(1.04); }
}

@media (prefers-reduced-motion: reduce) {
  .ccard, .ccard-frame::before, .ccard--legendary::before, .ccard--legendary .ccard__surface::before, .ccard--legendary .ccard__surface::after { animation: none !important; transition: none !important; }
}
