:root {
  --void: #04060b;
  --hull: #0c1220;
  --hull-line: #1b2540;
  --gold: #e2b04a;
  --gold-dim: #8a6a2a;
  --blue: #3b8cff;
  --red: #e5433a;
  --neutral: #8b93a7;
  --text: #d9dee8;
  --text-dim: #8b93a7;

  --display: "Saira Condensed", "Arial Narrow", sans-serif;
  --body: "Saira", system-ui, sans-serif;

  --card-radius: 4.2%;
  --flip-ms: 700ms;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--void);
  color: var(--text);
  font-family: var(--body);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Backdrop: a faint nebula and a scatter of stars ---------- */
.space {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 45% at 85% 10%, rgb(226 176 74 / 0.10), transparent 70%),
    radial-gradient(ellipse 50% 50% at 5% 90%, rgb(59 140 255 / 0.08), transparent 70%),
    radial-gradient(1px 1px at 20% 30%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 60%, #fff6 50%, transparent 51%),
    radial-gradient(1px 1px at 40% 80%, #fff5 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 90% 40%, #fff7 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 15%, #fff4 50%, transparent 51%),
    var(--void);
  background-size: 100% 100%, 100% 100%, 380px 380px, 290px 290px, 450px 450px, 520px 520px, 340px 340px, auto;
}

/* ---------- Header ---------- */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
  padding: 1.25rem clamp(1rem, 4vw, 3.5rem);
  border-bottom: 1px solid var(--hull-line);
  background: rgb(4 6 11 / 0.7);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--gold);
  text-decoration: none;
}
.brand-logo {
  display: block;
  width: 4.25rem;
  height: 4.25rem;
  margin: -0.5rem 0;
  object-fit: contain;
  filter: drop-shadow(0 0 10px rgb(226 176 74 / 0.25));
}
.brand-sub {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.1rem;
  color: var(--text-dim);
  line-height: 1;
  padding-left: 0.6rem;
  border-left: 1px solid var(--hull-line);
}

.standings { display: flex; gap: 0.5rem; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--hull-line);
  border-radius: 3px;
  background: var(--hull);
  color: var(--text-dim);
  font: 500 0.95rem/1 var(--body);
  cursor: pointer;
  transition: color 150ms, border-color 150ms, background 150ms;
}
.chip:hover { color: var(--text); }
.chip[aria-pressed="true"] { color: var(--text); border-color: var(--gold-dim); }
.chip--blue[aria-pressed="true"] { border-color: var(--blue); background: rgb(59 140 255 / 0.12); }
.chip--red[aria-pressed="true"] { border-color: var(--red); background: rgb(229 67 58 / 0.12); }
.chip .count { font-variant-numeric: tabular-nums; opacity: 0.7; }
.pip { width: 0.6rem; height: 0.6rem; border-radius: 2px; }
.chip--blue .pip { background: var(--blue); }
.chip--red .pip { background: var(--red); }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

/* ---------- Intro ---------- */
main { padding: 0 clamp(1rem, 4vw, 3.5rem) 5rem; }

.intro { max-width: 40rem; padding: clamp(2.5rem, 7vw, 5rem) 0 clamp(2rem, 4vw, 3rem); }
.intro h1 {
  margin: 0 0 0.75rem;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(2.6rem, 7vw, 5rem);
  line-height: 0.95;
  letter-spacing: -0.01em;
  background: linear-gradient(180deg, #fff3d6 0%, var(--gold) 55%, var(--gold-dim) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.intro p { margin: 0; color: var(--text-dim); font-size: 1.1rem; max-width: 34rem; }

/* ---------- Deck ---------- */
.deck {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: clamp(2rem, 4vw, 3.5rem) clamp(1.5rem, 3vw, 2.5rem);
}
.deck > .slot { max-width: 400px; }

.slot { display: flex; flex-direction: column; gap: 0.9rem; }
.slot[hidden] { display: none; }

/* The card: outer button holds perspective, tilt layer follows the pointer,
   inner layer does the flip. Kept separate so the two never fight. */
.card {
  --rx: 0deg;
  --ry: 0deg;
  --mx: 50%;
  --my: 50%;
  --lift: 0;
  --glow: var(--neutral);

  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  perspective: 1200px;
  -webkit-tap-highlight-color: transparent;
}
.card:focus-visible { outline-offset: 6px; border-radius: 6px; }

.slot[data-side="blue"] .card { --glow: var(--blue); }
.slot[data-side="red"] .card { --glow: var(--red); }

.card-tilt {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform:
    translateY(calc(var(--lift) * -6px))
    rotateX(var(--ry))
    rotateY(var(--rx));
  transition: transform 450ms cubic-bezier(.2,.8,.2,1);
}
.card.is-tracking .card-tilt { transition: transform 80ms linear; }

.card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform var(--flip-ms) cubic-bezier(.3,1.35,.5,1);
}
.card[aria-pressed="true"] .card-inner { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face--back { transform: rotateY(180deg); --mx: var(--mxb, 50%); }

/* .art wraps each image at its own aspect ratio so the foil and shadow
   hug the printed card, not the letterbox around it. */
.art {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: var(--card-radius);
  box-shadow:
    0 calc(18px + var(--lift) * 14px) calc(40px + var(--lift) * 20px) -18px rgb(0 0 0 / 0.9),
    0 0 calc(var(--lift) * 40px) calc(var(--lift) * -6px) var(--glow);
  transition: box-shadow 450ms;
}
.art--wide { width: 100%; }
.art--tall { height: 100%; }
.art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

/* Holographic foil: a soft light where the pointer is, plus a thin
   rainbow sheen that slides across as the card turns. */
.foil {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: calc(var(--lift) * 0.55);
  transition: opacity 400ms;
  background:
    radial-gradient(circle at var(--mx) var(--my), rgb(255 255 255 / 0.30), transparent 40%),
    repeating-linear-gradient(
      115deg,
      rgb(255 0 132 / 0.0) 0%,
      rgb(255 0 132 / 0.08) calc(var(--mx) * 0.2),
      rgb(252 164 0 / 0.08) calc(var(--mx) * 0.2 + 6%),
      rgb(0 255 138 / 0.06) calc(var(--mx) * 0.2 + 12%),
      rgb(0 207 255 / 0.08) calc(var(--mx) * 0.2 + 18%),
      rgb(204 76 250 / 0.0) calc(var(--mx) * 0.2 + 26%)
    );
  background-size: 100% 100%, 240% 240%;
  background-position: center, var(--mx) var(--my);
  mix-blend-mode: color-dodge;
}

/* ---------- Generated back (cards with no back art) ---------- */
.slot { --side-c: var(--neutral); }
.slot[data-side="blue"] { --side-c: var(--blue); }
.slot[data-side="red"] { --side-c: var(--red); }

.art--generated {
  container-type: inline-size;
  width: 100%;
  aspect-ratio: 2 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 7% 7% 0; /* % not cqw: a container can't size itself in its own cqw */
  text-align: center;
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 55% at 50% 38%, color-mix(in srgb, var(--side-c) 32%, transparent), transparent 70%),
    repeating-linear-gradient(0deg, rgb(255 255 255 / 0.025) 0 1px, transparent 1px 4px),
    linear-gradient(170deg, #1a0d10 0%, #070509 60%, #0d0608 100%);
}
.slot[data-side="blue"] .art--generated {
  background:
    radial-gradient(ellipse 80% 55% at 50% 38%, color-mix(in srgb, var(--side-c) 32%, transparent), transparent 70%),
    repeating-linear-gradient(0deg, rgb(255 255 255 / 0.025) 0 1px, transparent 1px 4px),
    linear-gradient(170deg, #0b1224 0%, #05070d 60%, #070b16 100%);
}
.art--wide.art--generated { width: 100%; height: auto; }
.art--tall.art--generated { height: 100%; width: auto; }

.gb-frame {
  position: absolute;
  inset: 3.5cqw;
  border: 0.6cqw solid var(--side-c);
  border-radius: 2.5cqw;
  box-shadow:
    inset 0 0 0 1.6cqw rgb(0 0 0 / 0.55),
    inset 0 0 0 1.9cqw color-mix(in srgb, var(--side-c) 55%, transparent),
    0 0 4cqw color-mix(in srgb, var(--side-c) 40%, transparent);
  pointer-events: none;
}
.gb-top {
  display: flex;
  justify-content: space-between;
  align-self: stretch;
  font: 600 4.2cqw/1 var(--body);
  color: color-mix(in srgb, var(--side-c) 75%, white);
}
.gb-num {
  padding: 0.8cqw 2cqw;
  border: 0.35cqw solid currentColor;
  font-variant-numeric: tabular-nums;
}
.gb-mark {
  display: grid;
  place-items: center;
  width: 30cqw;
  height: 30cqw;
  margin: auto 0 6cqw;
  border-radius: 4cqw;
  background: linear-gradient(160deg, color-mix(in srgb, var(--side-c) 85%, white), var(--side-c) 45%, color-mix(in srgb, var(--side-c) 60%, black));
  box-shadow: 0 0 12cqw color-mix(in srgb, var(--side-c) 65%, transparent), inset 0 0.6cqw 0 rgb(255 255 255 / 0.35);
  font: 800 26cqw/1 var(--display);
  color: #fff;
  text-shadow: 0 0.8cqw 2cqw rgb(0 0 0 / 0.4);
}
.gb-name {
  font: 800 12cqw/0.95 var(--display);
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
  color: #fff;
}
.gb-role {
  margin-top: 1.5cqw;
  font: 500 4.4cqw/1.2 var(--body);
  color: var(--text-dim);
}
.gb-verdict {
  margin-top: 6cqw;
  padding: 1.6cqw 4cqw;
  font: 700 5.6cqw/1 var(--display);
  color: #fff;
  background: var(--side-c);
  clip-path: polygon(3cqw 0, 100% 0, calc(100% - 3cqw) 100%, 0 100%);
}
.gb-standing {
  margin: 2.5cqw 0 auto;
  font: 600 4.2cqw/1 var(--body);
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb, var(--side-c) 70%, white);
}
.gb-stripes {
  align-self: stretch;
  height: 5cqw;
  margin: 0 -2cqw 7cqw;
  background: repeating-linear-gradient(-45deg, var(--side-c) 0 2.4cqw, transparent 2.4cqw 4.8cqw);
  opacity: 0.55;
}

/* ---------- Caption under each card ---------- */
.caption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 0.25rem;
}
.caption-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1.1;
  color: var(--text);
}
.caption-role { display: block; font-family: var(--body); font-weight: 400; font-size: 0.9rem; color: var(--text-dim); }
.caption-standing {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  font-weight: 600;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
.badge {
  display: inline-grid;
  place-items: center;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 3px;
  font: 700 0.85rem/1 var(--body);
  color: #fff;
}
.slot[data-side="blue"] .caption-standing { color: var(--blue); }
.slot[data-side="blue"] .badge { background: var(--blue); }
.slot[data-side="red"] .caption-standing { color: var(--red); }
.slot[data-side="red"] .badge { background: var(--red); }
.slot[data-side="neutral"] .caption-standing { color: var(--neutral); }
.slot[data-side="neutral"] .badge { background: var(--neutral); }

.empty {
  max-width: 34rem;
  padding: 1.5rem;
  border: 1px dashed var(--hull-line);
  border-radius: 4px;
  color: var(--text-dim);
}
.empty code { color: var(--gold); }

/* ---------- Mobile + motion preferences ---------- */
@media (max-width: 560px) {
  .brand-sub { display: none; }
  .standings { width: 100%; }
  .chip { flex: 1; justify-content: center; }
  .deck > .slot { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  .card-tilt,
  .card-inner,
  .foil,
  .art { transition: none !important; }
  .card-tilt { transform: none !important; }
}
