.match-card {
  --match-card-ink: #f7efd5;
  --match-card-gold: #f5d778;
  --match-card-violet: #8d5ac7;
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 0.35rem;
  inline-size: var(--match-card-width, 7.5rem);
  min-inline-size: 0;
  color: var(--match-card-ink);
  font: inherit;
  isolation: isolate;
  transition: transform 160ms ease, filter 160ms ease;
}

.match-card__stage {
  position: relative;
  overflow: hidden;
  aspect-ratio: 0.68;
  min-inline-size: 0;
  border: 2px solid #9b6bd1;
  border-radius: 48% 48% 0.7rem 0.7rem / 19% 19% 0.7rem 0.7rem;
  background:
    radial-gradient(ellipse at 50% 10%, rgb(210 162 255 / 34%), transparent 58%),
    linear-gradient(150deg, #462769, #211637 64%, #120d20);
  box-shadow: inset 0 0 0 2px #29183e, 0 0.35rem 0 #160e25, 0 0.55rem 1rem rgb(0 0 0 / 25%);
}

.match-card__stage::after {
  position: absolute;
  z-index: 2;
  inset: 0.26rem;
  border: 1px solid rgb(240 211 255 / 52%);
  border-radius: inherit;
  content: "";
  pointer-events: none;
}

.match-card__art {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(155deg, #47245f, #241331);
}

.match-card__image {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
  object-position: center 28%;
}

.match-card__image[hidden] { display: none; }

.match-card__art-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgb(241 210 255 / 55%);
  font-size: 2rem;
  text-shadow: 0 0 1rem #c58dff;
}

.match-card__image { position: relative; z-index: 1; }

.match-card__value {
  position: absolute;
  z-index: 3;
  inset-block-start: 0.25rem;
  inset-inline-start: 50%;
  display: grid;
  min-inline-size: 2.35rem;
  min-block-size: 2.35rem;
  padding: 0.25rem 0.45rem;
  place-items: center;
  transform: translateX(-50%) rotate(45deg);
  border: 2px solid #120d20;
  border-radius: 0.35rem;
  outline: 1px solid #b68ae2;
  background: linear-gradient(145deg, #3c205f, #1e1334);
  box-shadow: 0 0.15rem 0.55rem rgb(0 0 0 / 65%);
  color: var(--match-card-gold);
  font-size: 1.15rem;
  font-weight: 850;
  line-height: 1;
  text-shadow: 0 1px 2px #160d25;
  white-space: nowrap;
}

.match-card__value-label { display: inline-block; transform: rotate(-45deg); }

.match-card__metadata {
  position: absolute;
  z-index: 3;
  inset-inline: 0.28rem;
  inset-block-end: 0.28rem;
  display: grid;
  gap: 0.12rem;
  padding: 0.4rem 0.3rem 0.32rem;
  border: 1px solid rgb(198 157 234 / 68%);
  border-radius: 0.35rem;
  background: linear-gradient(180deg, rgb(38 20 57 / 82%), #241331 36%);
  text-align: center;
  text-shadow: 0 1px 2px #100a18;
}

.match-card__name {
  overflow: hidden;
  color: #fff4d1;
  font-size: 0.8rem;
  font-weight: 750;
  line-height: 1.12;
  text-overflow: ellipsis;
}

.match-card__type,
.match-card__flipped,
.match-card__state {
  color: #e3cff4;
  font-size: 0.61rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  line-height: 1.2;
  text-transform: uppercase;
}

.match-card__flipped { color: #ffe09a; }
.match-card__state { color: #dac2fb; }

.match-card__rules {
  max-block-size: 5.5em;
  margin: 0.1rem 0 0;
  overflow: auto;
  color: #f3eafc;
  font-size: 0.68rem;
  line-height: 1.25;
  text-align: start;
}

.match-card__select,
.match-card__inspect {
  position: relative;
  z-index: 4;
  min-block-size: 1.9rem;
  border: 1px solid #8e69ae;
  border-radius: 0.35rem;
  background: #21152e;
  color: #f4e9ff;
  cursor: pointer;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
}

.match-card__select:hover:not(:disabled),
.match-card__inspect:hover {
  border-color: #f2d987;
  background: #39234f;
}

.match-card__select:disabled {
  border-color: #554561;
  color: #afa3b9;
  cursor: not-allowed;
  opacity: 0.8;
}

.match-card__select:focus-visible,
.match-card__inspect:focus-visible {
  z-index: 5;
  outline: 3px solid #fff0a6;
  outline-offset: 3px;
}

.match-card__inspect { inline-size: 100%; }

/* The card face selects; the sibling button below it opens details. */
.match-card--hand .match-card__select {
  position: absolute;
  inset: 0 0 2.25rem;
  min-block-size: 0;
  border: 0;
  border-radius: 48% 48% 0.7rem 0.7rem / 19% 19% 0.7rem 0.7rem;
  background: transparent;
  color: transparent;
  font-size: 0;
}
.match-card--hand .match-card__select:hover:not(:disabled) { background: transparent; }
.match-card--hand .match-card__select:disabled { background: transparent; color: transparent; }

.match-card--hand:hover:not(:has(button:disabled)),
.match-card.is-selected {
  z-index: 6;
  transform: translateY(-0.35rem);
}

.match-card.is-selected .match-card__stage {
  border-color: #f1d879;
  box-shadow: inset 0 0 0 2px #503b70, 0 0 0 2px #f5da7d, 0 0 1.1rem rgb(106 192 255 / 62%);
}

.match-card:focus-within .match-card__stage {
  border-color: #d8c0ff;
  box-shadow: inset 0 0 0 2px #503b70, 0 0 0 2px #d8c0ff, 0 0 1rem rgb(175 126 255 / 48%);
}

.match-card:focus-within.is-selected .match-card__stage {
  border-color: #fff0a6;
  box-shadow: inset 0 0 0 2px #503b70, 0 0 0 3px #f5da7d, 0 0 1.2rem rgb(106 192 255 / 65%);
}

.match-card.is-flipped .match-card__image { filter: grayscale(0.88) brightness(0.66); }
.match-card.is-flipped .match-card__value { color: #fff0be; }
.match-card--pending .match-card__stage { border-color: #b88be5; }
.match-card--inspection .match-card__stage { aspect-ratio: 0.72; }
.match-card--inspection .match-card__name { font-size: 0.95rem; }

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .match-card--hand:hover:not(:has(button:disabled)) { filter: drop-shadow(0 0 0.5rem rgb(116 190 255 / 40%)); }
}

@media (prefers-reduced-motion: reduce) {
  .match-card { transition: none; }
}
