/* =====================================================================
   Nascent Accretion — arcade "character select" stage
   ---------------------------------------------------------------------
   The artwork is black ink on white paper. The .ink treatment below
   inverts it to light-on-black and uses mix-blend-mode: screen so the
   black disappears into the stage, leaving glowing line art.
   NOTE: screen blending only works if no ancestor of the image creates
   a stacking context (no opacity / transform / filter / z-index on
   .stage, .arena, .fighter, .center ...). Animate the <img> itself.
   ===================================================================== */

:root {
  --bg: #07070d;
  --text: #ecebf5;
  --muted: #8b8aa6;
  --line: #34344f;
  --p1: #ff3d57;
  --p2: #2fb6ff;
  --gold: #ffcf3a;
  --font: 'Orbitron', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font);
  background:
    radial-gradient(ellipse 80% 55% at 50% 110%, #24164a 0%, transparent 70%),
    radial-gradient(ellipse 60% 40% at 50% -10%, #12122a 0%, transparent 70%),
    var(--bg);
  overflow-x: hidden;
}

/* Shared ink treatment for the scanned artwork */
.fighter-art img,
.profile img,
.placard img,
.title img {
  filter: invert(1) hue-rotate(180deg) contrast(1.35);
  mix-blend-mode: screen;
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* perspective floor grid */
.stage::before {
  content: '';
  position: absolute;
  left: -50%;
  right: -50%;
  bottom: 0;
  height: 70vh;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(124, 92, 255, .32) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124, 92, 255, .32) 1px, transparent 1px);
  background-size: 64px 64px;
  transform: perspective(420px) rotateX(62deg);
  transform-origin: 50% 100%;
  -webkit-mask-image: linear-gradient(to top, #000 0%, transparent 75%);
          mask-image: linear-gradient(to top, #000 0%, transparent 75%);
}

/* CRT scanlines */
.stage::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, .22) 0 1px, transparent 1px 3px);
}

.p1 { --c: var(--p1); }
.p2 { --c: var(--p2); }

/* ---------- HUD ---------- */

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: clamp(10px, 2vw, 24px);
  padding: 16px clamp(16px, 3vw, 40px) 0;
}

.bar { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.bar.p2 { align-items: flex-end; }

.bar-name {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--c);
  min-height: 1em;
}

.bar-track {
  width: 100%;
  height: 18px;
  overflow: hidden;
  background: #3a0d16;
  border: 2px solid var(--text);
  box-shadow: 0 0 0 2px #000, 0 0 14px color-mix(in srgb, var(--c) 35%, transparent);
  transform: skewX(-18deg);
}
.bar.p2 .bar-track { transform: skewX(18deg); }

.bar-fill {
  height: 100%;
  background: linear-gradient(to bottom, #fff48a 0%, var(--gold) 45%, #e39500 100%);
  transform-origin: 100% 50%;               /* P1 drains toward the edge, like the arcade */
  animation: fill 1.1s cubic-bezier(.2, .8, .2, 1);
}
.bar.p2 .bar-fill { transform-origin: 0 50%; }

@keyframes fill { from { transform: scaleX(0); } }

.timer {
  min-width: 2.4ch;
  font-size: clamp(1.8rem, 4vw, 3rem);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  text-shadow: 0 0 14px rgba(255, 207, 58, .45), 3px 3px 0 #000;
}

/* ---------- arena layout ---------- */

.arena {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 560px) minmax(0, 1fr);
  grid-template-areas: "p1 center p2";
  align-items: end;
  gap: clamp(12px, 2vw, 32px);
  padding: 12px clamp(16px, 3vw, 40px) 28px;
}

/* ---------- fighters ---------- */

.fighter {
  grid-area: p1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}
.fighter.p2 { grid-area: p2; align-items: flex-end; }

.fighter-art {
  position: relative;
  width: 100%;
  height: clamp(260px, 58vh, 640px);
}

/* coloured spotlight + floor ring behind each fighter */
.fighter-art::before,
.fighter-art::after {
  content: '';
  position: absolute;
  z-index: -1;
  pointer-events: none;
}
.fighter-art::before {
  left: 0; right: 0; bottom: 0; height: 80%;
  background: radial-gradient(ellipse 50% 60% at 50% 100%, color-mix(in srgb, var(--c) 30%, transparent), transparent 75%);
}
.fighter-art::after {
  left: 15%; right: 15%; bottom: -10px; height: 22px;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--c) 55%, transparent), transparent);
}

.fighter-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: 50% 100%;
  animation: idle 3.4s ease-in-out infinite;
}
/* P2 faces left. The name placard is a separate image, so it stays readable. */
.p2 .fighter-art img { scale: -1 1; }

.fighter.enter .fighter-art img {
  animation: enter .7s cubic-bezier(.2, .9, .25, 1), idle 3.4s ease-in-out .7s infinite;
}
.p1 { --from: -45vw; }
.p2 { --from: 45vw; }

@keyframes enter {
  from { translate: var(--from) 0; opacity: 0; }
  to   { translate: 0 0; opacity: 1; }
}
@keyframes idle {
  0%, 100% { translate: 0 0; }
  50%      { translate: 0 -7px; }
}

.fighter-id {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}
.p2 .fighter-id { align-items: flex-end; }

.tag {
  font-size: .7rem;
  font-weight: 900;
  letter-spacing: .15em;
  padding: 3px 8px;
  color: #000;
  background: var(--c);
}

.profile {
  width: clamp(72px, 8vw, 116px);
  aspect-ratio: 1;
  overflow: hidden;
  border: 2px solid var(--c);
  box-shadow: 0 0 0 2px #000, 0 0 18px color-mix(in srgb, var(--c) 45%, transparent);
}
.profile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.profile img.is-fallback { object-position: 50% 0; }
/* app.js mirrors whichever profile would otherwise face away from the middle */
.profile img.is-mirrored { scale: -1 1; }

.placard {
  display: flex;
  align-items: center;
  min-height: 34px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--c);
}
.placard img {
  display: block;
  height: clamp(20px, 2.2vw, 30px);
  width: auto;
}
.placard-text {
  font-size: clamp(1rem, 1.8vw, 1.4rem);
  font-weight: 900;
  letter-spacing: .28em;
  text-transform: uppercase;
}

/* ---------- center column ---------- */

.center {
  grid-area: center;
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 0;
}

.vs {
  font: 900 clamp(3.2rem, 8vw, 6.5rem)/1 var(--font);
  letter-spacing: .04em;
  padding: 0 .1em;
  border: 0;
  cursor: pointer;
  background: linear-gradient(180deg, #fff 0%, var(--gold) 50%, #ff6a1a 100%);
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
  filter: drop-shadow(3px 4px 0 #000) drop-shadow(0 0 22px rgba(255, 120, 40, .45));
  transform: skewX(-10deg);
  transition: transform .15s;
}
.vs:hover { transform: skewX(-10deg) scale(1.06); }
.vs:focus-visible { outline: 2px solid var(--gold); outline-offset: 6px; }

.title { margin: 14px 0 0; line-height: 0; }
.title img { width: min(100%, 460px); height: auto; }

.subtitle {
  margin: 14px 0 24px;
  font-size: .72rem;
  letter-spacing: .4em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- menu tiles ---------- */

.menu {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 20px 10px;
  width: 100%;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  text-decoration: none;
  outline: none;
}

.tile-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  max-width: 84px;
  aspect-ratio: 1;
  border: 2px solid var(--line);
  background:
    /* corner ticks, a nod to the original button art */
    linear-gradient(var(--tick), var(--tick)) 6px 6px / 12px 2px no-repeat,
    linear-gradient(var(--tick), var(--tick)) 6px 6px / 2px 12px no-repeat,
    linear-gradient(var(--tick), var(--tick)) calc(100% - 6px) 6px / 12px 2px no-repeat,
    linear-gradient(var(--tick), var(--tick)) calc(100% - 6px) 6px / 2px 12px no-repeat,
    linear-gradient(var(--tick), var(--tick)) 6px calc(100% - 6px) / 12px 2px no-repeat,
    linear-gradient(var(--tick), var(--tick)) 6px calc(100% - 6px) / 2px 12px no-repeat,
    linear-gradient(var(--tick), var(--tick)) calc(100% - 6px) calc(100% - 6px) / 12px 2px no-repeat,
    linear-gradient(var(--tick), var(--tick)) calc(100% - 6px) calc(100% - 6px) / 2px 12px no-repeat,
    linear-gradient(160deg, #17172c, #0a0a14);
  --tick: #4a4a6a;
  transition: transform .12s, border-color .12s, box-shadow .12s, background-color .12s;
}

.tile svg {
  width: 44%;
  height: 44%;
  fill: none;
  stroke: #b9b8d3;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke .12s;
}

.tile-label {
  font-size: .62rem;
  font-weight: 500;
  letter-spacing: .1em;
  line-height: 1.3;
  text-transform: uppercase;
  transition: color .12s;
}

.cursor {
  position: absolute;
  top: -10px;
  left: -10px;
  padding: 2px 5px;
  font-size: .58rem;
  font-weight: 900;
  letter-spacing: .05em;
  color: #000;
  background: var(--p1);
  opacity: 0;
  transition: opacity .12s;
}

.tile:hover .tile-frame,
.tile:focus-visible .tile-frame {
  --tick: var(--p1);
  border-color: var(--p1);
  transform: translateY(-3px);
  box-shadow: 0 0 0 2px #000, 0 0 20px color-mix(in srgb, var(--p1) 55%, transparent);
}
.tile:hover svg,
.tile:focus-visible svg { stroke: #fff; }
.tile:hover .tile-label,
.tile:focus-visible .tile-label { color: var(--text); }
.tile:hover .cursor,
.tile:focus-visible .cursor { opacity: 1; }

.tile:active .tile-frame {
  transform: translateY(0) scale(.95);
  background-color: color-mix(in srgb, var(--p1) 25%, transparent);
  box-shadow: 0 0 0 2px #000, 0 0 30px color-mix(in srgb, var(--p1) 80%, transparent);
}

/* ---------- footer bits ---------- */

/* "Play versus" — the way into the fighting game */
.play {
  margin-top: 28px;
  padding: 14px 26px;
  font: 900 1rem/1 var(--font);
  letter-spacing: .24em;
  text-transform: uppercase;
  text-decoration: none;
  color: #000;
  background: linear-gradient(180deg, #fff48a 0%, var(--gold) 45%, #ff8a1a 100%);
  border: 2px solid #000;
  box-shadow: 0 0 0 2px var(--gold), 0 0 26px rgba(255, 170, 40, .55);
  transform: skewX(-10deg);
  transition: transform .12s, box-shadow .12s;
}
.play:hover,
.play:focus-visible {
  transform: skewX(-10deg) scale(1.05);
  box-shadow: 0 0 0 2px #fff, 0 0 36px rgba(255, 170, 40, .8);
  outline: none;
}
.play kbd {
  margin-left: 10px;
  padding: 1px 6px;
  font: inherit;
  font-size: .7em;
  border: 1px solid currentColor;
  opacity: .7;
}
.play + .rematch { margin-top: 16px; }

.rematch {
  margin-top: 28px;
  padding: 10px 18px;
  font: 700 .72rem/1 var(--font);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--gold);
  background: transparent;
  border: 2px solid color-mix(in srgb, var(--gold) 60%, transparent);
  cursor: pointer;
  transition: background-color .12s, color .12s;
}
.rematch:hover,
.rematch:focus-visible { background: var(--gold); color: #000; outline: none; }
.rematch kbd {
  margin-left: 8px;
  padding: 1px 5px;
  font: inherit;
  border: 1px solid currentColor;
  opacity: .7;
}

/* 2D / 3D toggle — a two-position switch under "New challenger" */
.dimension {
  display: inline-flex;
  align-items: center;
  margin-top: 12px;
  padding: 0;
  font: 700 .72rem/1 var(--font);
  letter-spacing: .2em;
  color: var(--muted);
  background: transparent;
  border: 2px solid var(--line);
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s;
}
.dimension span {
  padding: 9px 14px;
  transition: background-color .12s, color .12s;
}
.dimension kbd {
  margin: 0 10px 0 4px;
  padding: 1px 5px;
  font: inherit;
  border: 1px solid currentColor;
  opacity: .7;
}
.dimension[aria-pressed="false"] .dim-2d,
.dimension[aria-pressed="true"] .dim-3d { background: var(--p2); color: #000; }
.dimension:hover,
.dimension:focus-visible {
  border-color: var(--p2);
  box-shadow: 0 0 14px color-mix(in srgb, var(--p2) 45%, transparent);
  outline: none;
}
.dimension.is-loading { cursor: progress; }
.dimension.is-loading .dim-3d { animation: blink .6s steps(2) infinite; }
.dimension:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; border-color: var(--line); }
@keyframes blink { 50% { color: var(--p2); } }

/* 3D fighters: canvas sits where the art was; the CSS spotlight stays behind it */
.fighter-3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  cursor: pointer;
}
.mode-3d .fighter-3d { display: block; }
.mode-3d .fighter-art img { visibility: hidden; }

.footer {
  margin-top: 22px;
  font-size: .62rem;
  letter-spacing: .15em;
  color: var(--muted);
}
.footer a {
  color: inherit;
  text-decoration: none;
  padding: 2px 4px;
  transition: color .12s, text-shadow .12s;
}
.footer a:hover,
.footer a:focus-visible {
  color: var(--gold);
  text-shadow: 0 0 10px rgba(255, 207, 58, .6);
  outline: none;
}

/* ---------- announcer ---------- */

.announcer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.announcer span {
  font-size: clamp(3rem, 12vw, 9rem);
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
  animation: announce .9s ease-out forwards;
}
.announcer .round {
  color: #fff;
  text-shadow: 4px 5px 0 #000, 0 0 30px rgba(120, 90, 255, .8);
}
.announcer .fight {
  background: linear-gradient(180deg, #fff 0%, var(--gold) 45%, #ff4a1a 100%);
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
  filter: drop-shadow(4px 5px 0 #000) drop-shadow(0 0 30px rgba(255, 90, 30, .6));
  transform: skewX(-10deg);
}
@keyframes announce {
  0%   { opacity: 0; scale: 1.8; }
  20%  { opacity: 1; scale: 1; }
  80%  { opacity: 1; scale: 1; }
  100% { opacity: 0; scale: 1.05; }
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .arena {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "p1 p2"
      "center center";
  }
  .fighter-art { height: clamp(200px, 38vh, 380px); }
  .center { margin-top: 12px; }
}

@media (max-width: 520px) {
  .hud { padding-top: 12px; }
  .bar-name { font-size: .62rem; letter-spacing: .12em; }
  .bar-track { height: 12px; }
  .menu { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .placard img { height: 18px; }
  .placard-text { font-size: .9rem; letter-spacing: .18em; }
  .subtitle { letter-spacing: .25em; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
