/* Cards: layout, flip + tilt, front/back design.
   Each card gets these colors from the game (see js/ui.js):
     --rc / --rt  rarity color / text color     --dc / --dt  difficulty color / text */

.cards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.3rem;
}

.card {
  --rx: 0deg; --ry: 0deg; --mx: 50%; --my: 50%;
  position: relative;
  width: 200px;
  height: 310px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  perspective: 900px;
  animation: deal 0.8s cubic-bezier(.2,.9,.25,1.1) both;
  animation-delay: calc(var(--i) * 140ms);
}
@keyframes deal {
  0%   { transform: translate(var(--fx, 0px), var(--fy, -50px)) scale(0.3) rotate(var(--fr, 0deg)); opacity: 0; }
  15%  { opacity: 1; }
  100% { transform: none; opacity: 1; }
}
.card.static { animation: none; }

.card-tilt {
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform: rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform 0.12s linear;
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(.3,1.3,.5,1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.card:not(.flipped):hover .card-tilt { transform: translateY(-8px) rotate(1deg); }
.card.flipped { cursor: default; }

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  backface-visibility: hidden;
  overflow: hidden;
}

/* ---------- Back of the card ---------- */
.card-back {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 30% 18%, rgba(255, 255, 255, 0.3), transparent 50%),
    repeating-linear-gradient(135deg, rgba(255,255,255,.08) 0 12px, transparent 12px 24px),
    linear-gradient(160deg, #ff9a3c, #e8452f 60%, #b3202f);
  box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.28), 0 12px 26px rgba(0, 0, 0, 0.45);
}
.card-back::before {                      /* inner border line */
  content: "";
  position: absolute;
  inset: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 10px;
}
.card-back span {                         /* round emblem */
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  font-family: var(--font-display);
  font-size: 2.6rem;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  background: rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.45);
}

/* ---------- Front of the card ---------- */
.card-front {
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  padding: 9px 9px 10px;
  color: #f3efff;
  /* frame in the rarity color, dark body inside */
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.07), transparent 60%) padding-box,
    linear-gradient(#1c1748, #120e2c) padding-box,
    linear-gradient(145deg, var(--rc), color-mix(in srgb, var(--rc) 35%, #000)) border-box;
  border: 5px solid transparent;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.45);
}

/* top row: difficulty (left), rarity (right) */
.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
}
.badge {
  font-family: var(--font-display);
  font-size: 0.78rem;
  line-height: 1;
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-diff   { background: var(--dc); color: var(--dt); }
.badge-rarity { background: var(--rc); color: var(--rt); }

/* art box with the tower acronym */
.card-art {
  position: relative;
  margin-top: 9px;
  height: 116px;
  flex: none;
  border-radius: 10px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 25% 15%, rgba(255, 255, 255, 0.35), transparent 55%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.07) 0 10px, transparent 10px 20px),
    linear-gradient(155deg, color-mix(in srgb, var(--dc) 55%, #3a2fb0), #2b2285 85%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.22), inset 0 -18px 30px rgba(0, 0, 0, 0.25);
}
.art-initials {
  font-family: var(--font-display);
  font-size: calc(var(--art-size, 3) * 1rem * var(--scale, 1));
  letter-spacing: 0.01em;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.3), 0 0 18px rgba(255, 255, 255, 0.25);
}

/* tower name sits right under the box */
.card-name {
  flex: none;
  margin: 10px 3px 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.12rem;
  line-height: 1.12;
  text-align: center;
}
.card-name.long { font-size: 0.98rem; }       /* names over 30 letters */

/* creator + odds pinned to the bottom */
.card-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.card-desc { margin: 0; font-size: 0.74rem; font-weight: 600; color: rgba(243, 239, 255, 0.7); word-break: break-word; text-align: center; }
.card-desc b { font-weight: 800; color: #fff; }
.card-odds {
  margin: 0;
  padding: 3px 12px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--rc);
  background: rgba(255, 255, 255, 0.08);
}

/* soft white glare that follows the pointer */
.card-front::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 11px;                    /* inner radius: 16px frame - 5px border */
  pointer-events: none;
  background: radial-gradient(circle at var(--mx) var(--my), rgba(255, 255, 255, 0.2), transparent 45%);
  opacity: 0;
  transition: opacity 0.2s;
}
.card.flipped:hover .card-front::after { opacity: 1; }

/* ---------- Small tags on the art (NEW, ×2) ---------- */
.art-tag {
  position: absolute;
  padding: 3px 7px;
  border-radius: 6px;
  font-family: var(--font-display);
  font-size: 0.7rem;
  line-height: 1;
  text-shadow: none;
}
.tag-new   { top: 6px; left: 6px; background: #ff4f6d; color: #fff; }
.tag-count { right: 6px; bottom: 6px; background: rgba(0, 0, 0, 0.6); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .card, .card-inner, .card-tilt { animation: none; transition: none; }
}

@media (max-width: 480px) {
  .card { width: 166px; height: 262px; --scale: 0.8; }
  .card-art { height: 84px; }
  .card-name { font-size: 0.95rem; margin-top: 8px; }
  .card-name.long { font-size: 0.82rem; }
  .card-desc { font-size: 0.66rem; }
  .badge { font-size: 0.66rem; padding: 4px 8px; }
  .card-back span { width: 72px; height: 72px; font-size: 2rem; }
}
