/* =====================================================
   Hero portrait as a trading card
   Front: the photo, with a holographic tilt + foil shine on hover.
   Back: trading-card-style stats. Click / tap / Enter flips it.
   Markup lives in index.html (.tcg); behaviour in tcg-card.js.
   ===================================================== */

.tcg {
  --rx: 0deg;            /* tilt, set by JS */
  --ry: 0deg;
  --mx: 50%;             /* pointer position for the shine */
  --my: 50%;
  --shine: 0;            /* 0 → 1 while hovering */
  position: relative;
  width: 100%;
  height: 100%;
  perspective: 1100px;
  container-type: inline-size;
}

.tcg__tilt {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform: rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.tcg.is-tracking .tcg__tilt { transition: transform 0.35s ease-out; }

.tcg__inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.45, 0.05, 0.2, 1);
}
.tcg.is-flipped .tcg__inner { transform: rotateY(180deg); }

.tcg__face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.tcg__face--back { transform: rotateY(180deg); }

/* The existing .portrait-frame styles carry the front; it just fills the face */
.tcg .portrait-frame { height: 100%; }

/* container-type removes the photo's intrinsic width, so give the wrapper an explicit one */
.hero-portrait:has(.tcg) { width: 100%; }

/* ---- Foil + glare (both faces) ---- */
.tcg__foil,
.tcg__glare {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 3;
  opacity: var(--shine);
  transition: opacity 0.6s ease;
}
.tcg__foil {
  background:
    repeating-linear-gradient(
      115deg,
      rgba(255, 0, 132, 0.55) 0%,
      rgba(255, 196, 0, 0.55) 7%,
      rgba(0, 255, 170, 0.55) 14%,
      rgba(0, 170, 255, 0.55) 21%,
      rgba(180, 0, 255, 0.55) 28%,
      rgba(255, 0, 132, 0.55) 35%
    );
  background-size: 300% 300%;
  background-position: var(--mx) var(--my);
  mix-blend-mode: color-dodge;
  filter: saturate(1.2) contrast(1.1);
  opacity: calc(var(--shine) * 0.1);
}
.tcg__glare {
  background: radial-gradient(
    circle at var(--mx) var(--my),
    rgba(255, 255, 255, 0.22) 0%,
    rgba(255, 255, 255, 0.05) 30%,
    transparent 60%
  );
  mix-blend-mode: overlay;
}

/* ---- The hit area: a real button over the whole card ---- */
.tcg__toggle {
  position: absolute;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tcg__toggle:focus-visible { outline: 3px solid var(--teal); outline-offset: 4px; }

/* Easter-egg hint: a small card icon in the corner. Hidden until hover on desktop,
   faint on touch screens (no hover there), gone once flipped. */
.tcg__hint {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(10, 22, 40, 0.55);
  color: #fff;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.4s ease 0.15s, transform 0.4s ease 0.15s;
}
.tcg__hint svg { width: 15px; height: 15px; }
.tcg:hover .tcg__hint,
.tcg__toggle:focus-visible ~ .tcg__tilt .tcg__hint { opacity: 0.85; transform: none; }
@media (hover: none) { .tcg__hint { opacity: 0.6; transform: none; } }
.tcg.is-flipped .tcg__hint { opacity: 0 !important; }

/* ---- Card back ---- */
.tcg__back {
  --foil: linear-gradient(135deg, var(--book-1, #2dd4bf), var(--book-2, #38bdf8) 35%, var(--book-3, #a78bfa) 65%, var(--book-4, #fb923c));
  height: 100%;
  padding: 2.6cqw;
  background: var(--foil);
  box-shadow: var(--shadow-lg);
  font-size: 3.15cqw;           /* everything scales with the card */
  line-height: 1.3;
  color: var(--text);
}
.tcg__panel {
  display: flex;
  flex-direction: column;
  gap: 2cqw;
  height: 100%;
  padding: 3.4cqw 4cqw 3cqw;
  border-radius: calc(var(--radius-lg) - 6px);
  background:
    radial-gradient(circle at 100% 0%, var(--teal-soft) 0%, transparent 55%),
    var(--surface);
  overflow: hidden;
}

.tcg__head { display: flex; align-items: flex-end; justify-content: space-between; gap: 3cqw; }
.tcg__stage {
  display: block;
  margin-bottom: 0.6cqw;
  font-size: 2.5cqw;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teal);
}
.tcg__name {
  margin: 0;
  font-family: 'Fraunces', serif;
  font-size: 6.4cqw;
  font-weight: 700;
  line-height: 1;
  color: var(--text-strong);
}
.tcg__xp {
  display: flex;
  align-items: baseline;
  gap: 1cqw;
  white-space: nowrap;
  font-family: 'Fraunces', serif;
  color: var(--text-strong);
}
.tcg__xp small { font-family: 'Inter', sans-serif; font-size: 2.4cqw; font-weight: 700; letter-spacing: 0.06em; color: var(--text-dim); }
.tcg__xp strong { font-size: 6.4cqw; line-height: 1; }
.tcg__type {
  display: inline-grid;
  place-items: center;
  width: 6.4cqw;
  height: 6.4cqw;
  border-radius: 50%;
  background: var(--foil);
  color: #0a1628;
  align-self: center;
}
.tcg__type svg { width: 62%; height: 62%; }

.tcg__info {
  margin: 0;
  padding: 1.1cqw 2.4cqw;
  border-radius: 2cqw;
  background: var(--bg-2);
  border: 1px solid var(--border);
  font-size: 2.6cqw;
  font-style: italic;
  color: var(--text-dim);
  text-align: center;
}

.tcg__moves { display: flex; flex-direction: column; gap: 1.8cqw; margin: 0; padding: 0; list-style: none; }
.tcg__move { display: grid; grid-template-columns: 11cqw 1fr auto; column-gap: 2.2cqw; align-items: baseline; }
.tcg__cost { display: flex; justify-content: flex-start; gap: 0.7cqw; transform: translateY(0.4cqw); }
.tcg__cost i {
  display: block;
  width: 3.2cqw;
  height: 3.2cqw;
  border-radius: 50%;
  background: var(--foil);
  box-shadow: inset 0 0 0 0.4cqw rgba(255, 255, 255, 0.35);
}
.tcg__move-name { font-weight: 700; font-size: 3.6cqw; color: var(--text-strong); }
.tcg__dmg { font-family: 'Fraunces', serif; font-weight: 700; font-size: 4.4cqw; color: var(--text-strong); }
.tcg__move p { grid-column: 2 / -1; margin: 0.4cqw 0 0; font-size: 2.9cqw; color: var(--text-muted); }

.tcg__stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1.4cqw 4cqw; margin: 0; padding: 1.8cqw 0 0; border-top: 1px solid var(--border); }
.tcg__stat { display: grid; grid-template-columns: 1fr auto; gap: 0.6cqw 2cqw; align-items: center; }
.tcg__stat dt { font-size: 2.6cqw; font-weight: 600; color: var(--text-muted); }
.tcg__stat dd { margin: 0; font-size: 2.6cqw; font-weight: 700; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.tcg__bar { grid-column: 1 / -1; height: 1.3cqw; border-radius: 99px; background: var(--bg-2); overflow: hidden; }
.tcg__bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--foil);
  transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.35s;
}
.tcg.is-flipped .tcg__bar span { width: var(--v); }

.tcg__wrr { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2cqw; margin: 0; padding: 1.6cqw 0 0; border-top: 1px solid var(--border); text-align: center; }
.tcg__wrr div { display: flex; flex-direction: column; gap: 0.3cqw; }
.tcg__wrr dt { font-size: 2.2cqw; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim); }
.tcg__wrr dd { margin: 0; font-size: 2.7cqw; font-weight: 600; color: var(--text-strong); }

.tcg__flavor { margin: auto 0 0; font-family: 'Fraunces', serif; font-size: 2.9cqw; font-style: italic; color: var(--text-muted); }
.tcg__foot { display: flex; justify-content: space-between; font-size: 2.2cqw; font-weight: 600; letter-spacing: 0.06em; color: var(--text-dim); }

/* A foil sweep plays across the card each time it flips (nice on touch, where there's no hover) */
.tcg__sweep {
  position: absolute;
  inset: 0;
  z-index: 4;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.28) 48%, rgba(255, 255, 255, 0.0) 60%);
  background-size: 250% 100%;
  background-position: 120% 0;
  mix-blend-mode: overlay;
}
.tcg.is-sweeping .tcg__sweep { animation: tcg-sweep 0.9s ease-out 0.35s; }
@keyframes tcg-sweep { from { background-position: 120% 0; } to { background-position: -40% 0; } }

/* A bit bigger on phones so the card text stays readable */
@media (max-width: 960px) {
  .hero-portrait:has(.tcg) { max-width: min(100%, 360px); }
}

@media (prefers-reduced-motion: reduce) {
  .tcg__tilt { transform: none !important; transition: none; }
  .tcg__inner { transition: none; }
  .tcg__face { transition: opacity 0.2s ease; }
  .tcg.is-flipped .tcg__inner { transform: none; }
  .tcg__face--back { transform: none; opacity: 0; }
  .tcg.is-flipped .tcg__face--back { opacity: 1; }
  .tcg.is-flipped .tcg__face--front { opacity: 0; }
  .tcg__bar span { transition: none; }
  .tcg.is-sweeping .tcg__sweep { animation: none; }
}
