/* ==========================================================================
   BATTLEGROUND: arcade fighting-game theme
   One dark theme. Pure CSS: gradients, clip-path, shadows, keyframes.
   Fonts (Google Fonts, load in <head> of index.html):
     Bungee          chunky display: logo, names, buttons
     Press Start 2P  pixel: tiny HUD labels and tags (kept >= 10px)
     Chakra Petch    readable body copy
   Sections
     0  Tokens + base          5  HUD (health bars, round badge)
     1  Screen texture         6  Loading screen (arena)
     2  Buttons               7  Result screen (K.O. / winner)
     3  Input screen          8  Error dialog
     4  BattleDex             9  Responsive   10 Reduced motion
   ========================================================================== */

/* ---------- 0. Tokens + base ---------- */
@property --rot { syntax: '<angle>'; inherits: false; initial-value: 0deg; }

:root {
  --ink: #05041a;          /* deepest background / outlines */
  --bg: #0b0925;
  --panel: #14123a;
  --panel-2: #1d1a55;
  --line: #2f2b86;
  --text: #f4f1ff;         /* 15:1 on --panel */
  --muted: #b9b5e8;        /* 8:1 on --panel */
  --red: #ff4a2e;          /* team A */
  --orange: #ff9a1f;
  --cyan: #38f0ff;         /* team B */
  --blue: #1fb6ff;
  --gold: #ffd23f;         /* highlights + winner */
  --danger: #c1180f;
  --f-display: 'Bungee', Impact, 'Arial Black', sans-serif;
  --f-pixel: 'Press Start 2P', ui-monospace, monospace;
  --f-body: 'Chakra Petch', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --burst: polygon(50.0% 0.0%,56.7% 20.8%,71.7% 5.0%,68.7% 26.5%,89.1% 18.8%,77.0% 37.0%,98.7% 38.9%,80.0% 50.0%,98.7% 61.1%,77.0% 63.0%,89.1% 81.2%,68.7% 73.5%,71.7% 95.0%,56.7% 79.2%,50.0% 100.0%,43.3% 79.2%,28.3% 95.0%,31.3% 73.5%,10.9% 81.2%,23.0% 63.0%,1.3% 61.1%,20.0% 50.0%,1.3% 38.9%,23.0% 37.0%,10.9% 18.8%,31.3% 26.5%,28.3% 5.0%,43.3% 20.8%);
  --snap: cubic-bezier(.2, .9, .3, 1);      /* punchy, no float */
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { overflow-x: hidden; }

body {
  margin: 0;
  color: var(--text);
  font-family: var(--f-body);
  font-size: 1.0625rem;
  line-height: 1.5;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(255, 74, 46, .30), transparent 55%),
    radial-gradient(ellipse at 50% 112%, rgba(31, 182, 255, .26), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.screen:focus { outline: none; }

/* ---------- 1. Screen texture (decorative, pointer-events none) ---------- */
/* Sunburst rays + halftone dots, faded toward the edges */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    repeating-conic-gradient(from 0deg at 50% 16%, rgba(255, 210, 63, .07) 0 5deg, transparent 5deg 10deg),
    radial-gradient(rgba(255, 255, 255, .08) 1px, transparent 1.6px) 0 0 / 7px 7px;
  -webkit-mask-image: radial-gradient(ellipse at 50% 22%, #000 0, transparent 72%);
          mask-image: radial-gradient(ellipse at 50% 22%, #000 0, transparent 72%);
}
/* CRT scanlines over everything */
body::after {
  content: ""; position: fixed; inset: 0; z-index: 100; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, .16) 0 1px, transparent 1px 3px);
}

/* ---------- Layout: screens stacked in one grid cell ---------- */
#app {
  position: relative; z-index: 1;
  display: grid;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1rem 4rem;
}
#app > .screen { grid-area: 1 / 1; min-width: 0; }
.screen[hidden] { display: none; }

/* ---------- 2. Buttons ---------- */
.btn {
  min-height: 48px;
  padding: .7rem 1.3rem;
  font-family: var(--f-display);
  font-size: 1rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text);
  background: linear-gradient(var(--panel-2), var(--panel));
  border: 3px solid var(--cyan);
  border-radius: 6px;
  box-shadow: 0 5px 0 #000, 0 0 16px rgba(56, 240, 255, .25);
  cursor: pointer;
  transition: transform .08s var(--snap), box-shadow .08s var(--snap), filter .08s;
}
.btn:hover { filter: brightness(1.2); transform: translateY(-2px); box-shadow: 0 7px 0 #000, 0 0 22px rgba(56, 240, 255, .45); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #000; }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: grayscale(.6); transform: none; }

/* Primary = gold, dark text (12:1) */
.btn-primary {
  color: #1a0b00;
  background: linear-gradient(#fff3a0, var(--gold) 40%, var(--orange));
  border-color: #fff6d8;
  box-shadow: 0 5px 0 #9a3a00, 0 8px 0 #000, 0 0 24px rgba(255, 170, 0, .5);
}
.btn-primary:hover { box-shadow: 0 7px 0 #9a3a00, 0 10px 0 #000, 0 0 34px rgba(255, 170, 0, .75); }
.btn-primary:active { box-shadow: 0 1px 0 #9a3a00, 0 3px 0 #000; }

.btn-small {
  min-height: 44px; padding: .35rem .9rem;
  font-family: var(--f-body); font-weight: 700; font-size: .85rem; letter-spacing: .06em;
  border-width: 2px; box-shadow: 0 3px 0 #000;
}
.btn-danger { background: var(--danger); border-color: #ff8a7a; color: #fff; }

/* ---------- 3. Input screen: character select ---------- */
.site-header { text-align: center; padding: 1.75rem 0 .5rem; }
.kicker {
  margin: 0 0 1rem;
  font-family: var(--f-pixel); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--gold);
  animation: blink 1.1s steps(2, jump-none) infinite;
}
.logo { margin: 0; line-height: 1; transform: rotate(-3deg); animation: logo-slam .55s var(--snap) both; }
.logo-text {
  position: relative; display: inline-block;
  font-family: var(--f-display); text-transform: uppercase;
  font-size: clamp(1.95rem, 9.2vw, 6rem); letter-spacing: .01em;
  background: linear-gradient(#fffbd0 0, var(--gold) 35%, var(--orange) 62%, var(--red) 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
/* Outline + hard extrusion + glow live on a copy behind the gradient lettering */
.logo-text::before {
  content: attr(data-text);
  position: absolute; inset: 0; z-index: -1;
  -webkit-text-fill-color: #12082e; color: #12082e;
  -webkit-text-stroke: .16em #12082e; paint-order: stroke fill;
  text-shadow: 0 .06em 0 #b3261a, 0 .12em 0 #7a1409, 0 .18em 0 #12082e, 0 0 .5em rgba(255, 74, 46, .75);
}
.tagline {
  display: inline-block; margin: 1.6rem 0 0; padding: .45rem 1.3rem;
  font-family: var(--f-pixel); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase;
  color: #fff; background: linear-gradient(90deg, var(--red), #c1180f);
  border: 3px solid #fff6d8; box-shadow: 4px 4px 0 #000;
  transform: skewX(-12deg);
}

/* The face-off row: slot A | VS | slot B */
#fight-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 1.25rem 1.5rem;
  margin-top: 2.75rem;
}
#form-error, #fight-btn { grid-column: 1 / -1; }

.slot {
  --team: var(--red); --team-2: var(--orange); --team-dark: #4a1210; --team-glow: rgba(255, 74, 46, .45);
  position: relative;
  display: flex; flex-direction: column; gap: .7rem;
  padding: 1.25rem 1rem 1rem;
  background: linear-gradient(165deg, var(--team-dark), #0d0b2b 72%);
  border: 4px solid var(--team);
  border-radius: 8px;
  box-shadow: 0 0 0 3px #000, 7px 7px 0 3px #000, 0 0 30px var(--team-glow);
}
.slot-a { transform: rotate(-1.2deg); animation: slot-in-left .5s var(--snap) .1s both; }
.slot-b {
  --team: var(--blue); --team-2: var(--cyan); --team-dark: #0b2b57; --team-glow: rgba(31, 182, 255, .45);
  transform: rotate(1.2deg); animation: slot-in-right .5s var(--snap) .1s both;
}
.slot-tag {
  position: absolute; top: -17px; left: 14px;
  padding: .35rem .6rem;
  font-family: var(--f-pixel); font-size: .65rem; letter-spacing: .08em;
  color: #12082e; background: var(--team-2); border: 3px solid #000; box-shadow: 3px 3px 0 #000;
}
.slot-b .slot-tag { left: auto; right: 14px; }

.field label {
  font-family: var(--f-pixel); font-size: .7rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--team-2);
}
.field { display: flex; flex-direction: column; gap: .5rem; }

/* Character portrait placeholder: silhouette + big "?" */
.portrait {
  position: relative; display: grid; place-items: center; height: 124px; overflow: hidden;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, .06) 0 8px, transparent 8px 16px),
    radial-gradient(ellipse at 50% 115%, var(--team) 0, transparent 68%),
    #0b0925;
  border: 3px solid #000; border-radius: 4px;
  box-shadow: inset 0 0 0 2px var(--team);
}
.portrait svg { height: 112%; width: auto; margin-top: 18px; fill: #0b0925; stroke: var(--team-2); stroke-width: 3; opacity: .95; }
.slot-b .portrait svg { transform: scaleX(-1); }
.portrait-q {
  position: absolute; font-family: var(--f-display); font-size: 3rem; line-height: 1; color: #fff;
  text-shadow: 0 3px 0 var(--team), 0 6px 0 #000;
  animation: q-bob 1.2s steps(2, jump-none) infinite;
}

/* Arcade name-entry field */
input[type="text"] {
  width: 100%;
  padding: .95rem .85rem;
  font-family: var(--f-pixel); font-size: .8rem; letter-spacing: .04em; text-transform: uppercase;
  color: #fff; caret-color: var(--gold);
  background: var(--ink);
  border: 3px solid #000; border-radius: 4px;
  box-shadow: inset 0 0 0 2px var(--team, var(--blue)), inset 0 5px 14px rgba(0, 0, 0, .7);
}
input[type="text"]::placeholder { color: #9a96cf; opacity: 1; text-transform: none; }   /* 6:1 on --ink */
input[type="text"]:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px;
  box-shadow: inset 0 0 0 2px var(--gold), inset 0 5px 14px rgba(0, 0, 0, .7), 0 0 20px rgba(255, 210, 63, .55);
}

/* Big VS between the slots */
.vs-divider {
  position: relative; isolation: isolate; text-align: center;
  font-family: var(--f-display); font-size: clamp(2.8rem, 6vw, 5rem); line-height: 1;
  color: var(--gold); letter-spacing: .02em;
  -webkit-text-stroke: .08em #12082e; paint-order: stroke fill;
  text-shadow: 0 .06em 0 #b3261a, 0 .12em 0 #12082e;
  animation: vs-slam .5s var(--snap) .35s both, vs-pulse 1.4s ease-in-out 1s infinite;
}
.vs-divider::before {
  content: ""; position: absolute; z-index: -1; left: 50%; top: 50%;
  width: 2.5em; height: 2.5em; margin: -1.25em 0 0 -1.25em;
  background: radial-gradient(circle, var(--red) 0, #7a1409 70%);
  clip-path: var(--burst);
  animation: burst-spin 10s linear infinite;
}

/* Inline error strip */
.error {
  margin: 0; padding: .7rem 1rem .7rem 3rem; position: relative;
  color: #fff; background: #3a0b16; border: 3px solid var(--red); border-radius: 6px;
  box-shadow: 4px 4px 0 #000; font-weight: 600;
}
.error::before {
  content: "!"; position: absolute; left: .8rem; top: 50%; transform: translateY(-50%);
  width: 1.7rem; height: 1.7rem; display: grid; place-items: center;
  font-family: var(--f-display); color: #12082e; background: var(--gold); border-radius: 50%;
}
.error[hidden] { display: none; }

/* FIGHT! call to action */
#fight-btn {
  justify-self: center; width: min(100%, 460px); margin-top: .75rem; min-height: 72px;
  font-size: clamp(1.7rem, 6vw, 2.4rem); letter-spacing: .08em;
  -webkit-text-stroke: 0;
  animation: fight-pulse 1.3s ease-in-out infinite;
}
#fight-btn:hover { animation-play-state: paused; }
#fight-btn:disabled { animation: none; }

/* ---------- 4. BattleDex: fight record / trophy shelf ---------- */
.battledex {
  position: relative;
  margin-top: 3.5rem; padding: 1.5rem 1.25rem 1.25rem;
  background: linear-gradient(180deg, rgba(20, 18, 58, .92), rgba(8, 6, 32, .92));
  border: 4px solid var(--line); border-radius: 8px;
  box-shadow: 0 0 0 3px #000, 7px 7px 0 3px #000;
}
.battledex-head {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem 1rem; flex-wrap: wrap;
  margin-bottom: 1rem; padding-bottom: .9rem;
  border-bottom: 3px dashed var(--line);
}
.battledex h2 {
  display: flex; align-items: center; gap: .7rem; margin: 0;
  font-family: var(--f-display); font-size: clamp(1.4rem, 4.5vw, 2rem); letter-spacing: .03em; text-transform: uppercase;
  color: var(--gold); text-shadow: 0 3px 0 #7a3600, 0 5px 0 #000;
}
.battledex h2 svg { width: 1.5em; height: 1.5em; flex: none; fill: var(--gold); stroke: #12082e; stroke-width: 2; filter: drop-shadow(0 2px 0 #000); }
.battledex-sub { display: block; font-family: var(--f-pixel); font-size: .6rem; letter-spacing: .1em; color: var(--muted); text-shadow: none; margin-top: .4rem; }
.battledex-clear { display: flex; align-items: center; }
.clear-confirm {
  display: inline-flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .5rem .75rem; font-weight: 600; font-size: .95rem;
  background: #3a0b16; border: 3px solid var(--red); border-radius: 6px; box-shadow: 3px 3px 0 #000;
}
.clear-confirm[hidden], #clear-btn[hidden] { display: none; }

.notice {
  position: relative; margin: 0 0 1rem; padding: .6rem .9rem .6rem 2.8rem;
  font-size: .95rem; font-weight: 600; color: #fff;
  background: #3a2a05; border: 3px solid var(--gold); border-radius: 6px;
}
.notice::before {
  content: "!"; position: absolute; left: .7rem; top: 50%; transform: translateY(-50%);
  width: 1.6rem; height: 1.6rem; display: grid; place-items: center;
  font-family: var(--f-display); color: #12082e; background: var(--gold);
  clip-path: polygon(50% 0, 100% 100%, 0 100%); padding-top: .35rem; font-size: .8rem;
}
.notice[hidden], .battledex .empty[hidden] { display: none; }

/* Empty state: unlit trophy shelf */
.battledex .empty {
  display: flex; align-items: center; justify-content: center; gap: .9rem; flex-wrap: wrap;
  margin: 0; padding: 1.75rem 1rem; text-align: center;
  font-weight: 600; color: var(--muted);
  background: repeating-linear-gradient(135deg, rgba(255, 255, 255, .03) 0 10px, transparent 10px 20px);
  border: 3px dashed var(--line); border-radius: 6px;
}
.battledex .empty svg { width: 2.6rem; height: 2.6rem; fill: none; stroke: var(--line); stroke-width: 3; flex: none; }

/* Entries: trading cards / fight records */
.battledex-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 1.1rem;
  counter-reset: dex;
}
.dex-entry {
  counter-increment: dex;
  position: relative; display: flex; flex-direction: column; gap: .7rem;
  padding: 2.4rem 1rem 1rem;
  background: linear-gradient(160deg, #24206b, #120f36 70%);
  border: 3px solid var(--gold); border-radius: 6px;
  box-shadow: 0 0 0 2px #000, 6px 6px 0 2px #000, inset 0 0 0 3px #12082e, inset 0 0 0 5px rgba(255, 210, 63, .35);
}
.dex-entry::before {   /* record number, top right */
  content: "REC " counter(dex, decimal-leading-zero);
  content: "REC " counter(dex, decimal-leading-zero) / "";
  position: absolute; top: .75rem; right: .9rem;
  font-family: var(--f-pixel); font-size: .6rem; letter-spacing: .06em; color: var(--gold);
}
.dex-entry::after {    /* halftone sheen */
  content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: 3px;
  background: radial-gradient(rgba(255, 255, 255, .07) 1px, transparent 1.5px) 0 0 / 6px 6px;
  -webkit-mask-image: linear-gradient(135deg, #000, transparent 60%); mask-image: linear-gradient(135deg, #000, transparent 60%);
}
.dex-body { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: .45rem; position: relative; z-index: 1; }
.dex-winner {   /* winner badge ribbon */
  position: relative; margin: 0 0 .1rem; max-width: 100%; padding: .3rem .8rem .3rem 1.9rem;
  font-family: var(--f-display); font-size: 1rem; letter-spacing: .02em; line-height: 1.2;
  color: #1a0b00; background: linear-gradient(#fff3a0, var(--gold) 45%, var(--orange));
  border: 2px solid #12082e; box-shadow: 3px 3px 0 #000;
  transform: skewX(-8deg); overflow-wrap: anywhere;
}
.dex-winner::before { content: "\2605"; position: absolute; left: .55rem; top: 50%; transform: translateY(-52%); color: #b3261a; }
.dex-matchup { margin: 0; font-weight: 700; font-size: .85rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); overflow-wrap: anywhere; }
.dex-reasoning {
  margin: .2rem 0 0; padding: .6rem .75rem; font-size: .95rem; overflow-wrap: anywhere;
  background: rgba(0, 0, 0, .35); border: 2px solid rgba(255, 255, 255, .12); border-radius: 4px;
}
.dex-date { margin: .25rem 0 0; font-size: .78rem; color: #aaa6dd; }
.dex-entry .btn-small {
  position: relative; z-index: 1; align-self: flex-end; margin-top: auto;
  color: #ffb0a6; background: transparent; border-color: #ff6a5a;
}
.dex-entry .btn-small:hover { background: var(--danger); color: #fff; }

/* ---------- 5. HUD: health bars + round badge (loading + result) ---------- */
.hud {
  position: relative; z-index: 3;
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: .75rem; align-items: start; padding: 1rem 1.25rem .5rem;
}
.hud-side { display: flex; flex-direction: column; gap: .5rem; min-width: 0; }
.hud-a { --team-2: var(--orange); }
.hud-b { --team-2: var(--cyan); align-items: flex-end; text-align: right; }
.hud-name, .hud .chip {
  max-width: 100%; font-family: var(--f-pixel); font-size: .7rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--team-2); text-shadow: 2px 2px 0 #000; overflow-wrap: anywhere;
}
.hp {
  position: relative; width: 100%; height: 30px; overflow: hidden;
  background: #7d1230;                         /* "lost" health shows through */
  border: 3px solid #fff6d8; border-radius: 3px;
  box-shadow: 0 0 0 3px #000, 5px 5px 0 3px #000;
}
.hud-a .hp { transform: skewX(-14deg); }
.hud-b .hp { transform: skewX(14deg); }
.hp-fill { display: block; height: 100%; transform-origin: left center; background: linear-gradient(#fff6a0 0, var(--gold) 38%, var(--orange) 100%); }
.hud-b .hp-fill { transform-origin: right center; background: linear-gradient(#d4fcff 0, var(--cyan) 38%, var(--blue) 100%); }
.hp::after {   /* segment ticks */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(90deg, transparent 0 22px, rgba(0, 0, 0, .35) 22px 24px);
}
.hud-badge {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 104px; height: 74px; margin-top: -.15rem; color: #12082e; text-align: center;
  background: #fff6d8; clip-path: polygon(14% 0, 86% 0, 100% 50%, 86% 100%, 14% 100%, 0 50%);
}
.hud-badge::before {
  content: ""; position: absolute; inset: 4px; z-index: 0;
  background: linear-gradient(#fff3a0, var(--gold) 45%, var(--orange));
  clip-path: polygon(14% 0, 86% 0, 100% 50%, 86% 100%, 14% 100%, 0 50%);
}
.hud-round, .hud-timer { position: relative; z-index: 1; }
.hud-round { font-family: var(--f-pixel); font-size: .55rem; letter-spacing: .04em; text-transform: uppercase; }
.hud-timer { font-family: var(--f-display); font-size: 1.7rem; line-height: 1.1; }

/* ---------- 6. Loading screen: the arena ---------- */
#screen-loading { --dx: 150px; }
.stage {
  position: relative; overflow: hidden; isolation: isolate;
  display: grid; grid-template-rows: auto 1fr auto;
  min-height: clamp(460px, 74vh, 680px);
  margin-top: 1.5rem;
  background: #150a3f;
  border: 4px solid #fff6d8; border-radius: 8px;
  box-shadow: 0 0 0 4px #000, 8px 8px 0 4px #000, 0 0 50px rgba(255, 74, 46, .35);
}
.stage::after {   /* impact flash on each hit */
  content: ""; position: absolute; inset: 0; z-index: 4; pointer-events: none; background: #fff; opacity: 0;
  animation: impact-flash 1.6s linear infinite;
}
.stage-world { position: absolute; inset: 0; z-index: 0; animation: stage-shake 1.6s linear infinite; }
.stage-sky {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 50% 66%, rgba(255, 110, 60, .5), transparent 55%),
    linear-gradient(#0f0733 0, #2b0f55 50%, #7a1f5c 100%);
}
.spot {   /* spotlight cones */
  position: absolute; top: -12%; width: 46%; height: 112%;
  clip-path: polygon(46% 0, 54% 0, 100% 100%, 0 100%);
  transform-origin: 50% 0; mix-blend-mode: screen;
  animation: spot-sway 4.2s ease-in-out infinite alternate;
}
.spot-a { left: 2%;  background: linear-gradient(rgba(255, 154, 31, .55), transparent 80%); }
.spot-b { right: 2%; background: linear-gradient(rgba(56, 240, 255, .5), transparent 80%); animation-delay: -2.1s; }

/* Crowd silhouettes made from repeating radial gradients (heads + shoulders) */
.crowd { position: absolute; left: -10%; right: -10%; bottom: 33%; height: 84px; }
.crowd-back {
  bottom: 34%; height: 70px; opacity: .75;
  background:
    radial-gradient(circle at 50% 22px, #1a0c46 0 10px, transparent 10.5px) 0 0 / 31px 100% repeat-x,
    radial-gradient(ellipse 15px 24px at 50% 100%, #1a0c46 0 98%, transparent 100%) 0 0 / 31px 100% repeat-x;
  animation: crowd-sway 3s ease-in-out infinite alternate;
}
.crowd-front {
  background:
    radial-gradient(circle, var(--gold) 0 2px, transparent 3px) 14px 6px / 97px 70px repeat-x,   /* phone lights */
    radial-gradient(circle at 50% 28px, #06041a 0 13px, transparent 13.5px) 0 0 / 43px 100% repeat-x,
    radial-gradient(ellipse 20px 30px at 50% 100%, #06041a 0 98%, transparent 100%) 0 0 / 43px 100% repeat-x,
    linear-gradient(#06041a, #06041a) bottom / 100% 20px no-repeat;
  animation: crowd-bounce .8s steps(2, jump-none) infinite;
}
.floor {
  position: absolute; left: 0; right: 0; bottom: 0; height: 34%; overflow: hidden;
  background: linear-gradient(#2a1470, #0d0630);
  border-top: 4px solid var(--gold); box-shadow: 0 -6px 24px rgba(255, 210, 63, .45);
}
.floor::before {   /* perspective grid, scrolling toward camera */
  content: ""; position: absolute; left: -60%; right: -60%; top: 0; height: 260%;
  background:
    repeating-linear-gradient(90deg, rgba(56, 240, 255, .45) 0 2px, transparent 2px 70px),
    repeating-linear-gradient(0deg, rgba(56, 240, 255, .45) 0 2px, transparent 2px 44px);
  transform-origin: 50% 0; transform: perspective(220px) rotateX(62deg);
  animation: floor-scroll 1.6s linear infinite;
}

.arena {
  position: relative; z-index: 2; grid-row: 2;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: .75rem 1.25rem; padding: 0 1rem; max-width: 100%; margin-top: -3rem;
  font-family: var(--f-display); font-size: clamp(1.5rem, 5.6vw, 3.3rem); line-height: 1.05; text-transform: uppercase;
  animation: stage-shake 1.6s linear infinite;
}
.fighter {
  display: inline-block; flex: 0 1 auto; min-width: 0; max-width: 44%; text-align: center; overflow-wrap: anywhere;
  -webkit-text-stroke: .1em #12082e; paint-order: stroke fill;
}
.fighter-left  { color: #ffb347; text-shadow: 0 .08em 0 #b3261a, 0 .14em 0 #12082e, 0 0 .5em rgba(255, 74, 46, .8); animation: charge-left 1.6s cubic-bezier(.6, 0, .2, 1) infinite; }
.fighter-right { color: #6fe3ff; text-shadow: 0 .08em 0 #0b4fa8, 0 .14em 0 #12082e, 0 0 .5em rgba(31, 182, 255, .8); animation: charge-right 1.6s cubic-bezier(.6, 0, .2, 1) infinite; }
.clash {
  position: relative; z-index: 2; flex: none; font-size: 1.3em; letter-spacing: .06em; color: var(--gold);
  -webkit-text-stroke: .08em #12082e; paint-order: stroke fill;
  text-shadow: 0 .06em 0 #b3261a, 0 .12em 0 #12082e;
  animation: clash-flash 1.6s ease-in-out infinite;
}
.clash::before {   /* impact starburst */
  content: ""; position: absolute; z-index: -1; left: 50%; top: 50%;
  width: 3.4em; height: 3.4em; margin: -1.7em 0 0 -1.7em;
  background: radial-gradient(circle, #fff 0, var(--gold) 35%, var(--red) 72%);
  clip-path: var(--burst); transform: scale(0);
  animation: burst 1.6s ease-out infinite;
}
.clash::after {    /* shockwave ring */
  content: ""; position: absolute; z-index: -1; left: 50%; top: 50%;
  width: 2.6em; height: 2.6em; margin: -1.3em 0 0 -1.3em; border: .12em solid #fff; border-radius: 50%;
  opacity: 0; animation: ring 1.6s ease-out infinite;
}
.loading-note {
  position: relative; z-index: 3; grid-row: 3; justify-self: center;
  max-width: calc(100% - 2rem); margin: 0 1rem 1.1rem; padding: .55rem 1.1rem; text-align: center;
  font-weight: 600; color: var(--text);
  background: rgba(5, 4, 26, .9); border: 3px solid var(--cyan); border-radius: 6px; box-shadow: 4px 4px 0 #000;
  animation: pulse-text 1.6s ease-in-out infinite;
}
/* Health bars flicker/trade hits while waiting. 3.2s = two clash cycles */
.stage .hud-a .hp-fill { animation: hp-hit-a 3.2s linear infinite; }
.stage .hud-b .hp-fill { animation: hp-hit-b 3.2s linear infinite; }
.hud-timer { animation: timer-glow 1.6s ease-in-out infinite; }

/* ---------- 7. Result screen: K.O. / winner ---------- */
.screen-result {
  position: fixed; inset: 0; z-index: 10;
  display: flex; padding: 1.25rem; overflow-x: hidden; overflow-y: auto;
  background:
    radial-gradient(circle at 50% 30%, #3a1230 0, transparent 60%),
    radial-gradient(circle at 50% 120%, rgba(31, 182, 255, .35), transparent 55%),
    #0a0820;
}
.screen-result[hidden] { display: none; }
.screen-result::before {   /* rotating victory rays */
  content: ""; position: fixed; inset: 0; pointer-events: none;
  background: repeating-conic-gradient(from var(--rot) at 50% 36%, rgba(255, 210, 63, .14) 0 6deg, transparent 6deg 14deg);
  -webkit-mask-image: radial-gradient(circle at 50% 36%, #000, transparent 72%);
          mask-image: radial-gradient(circle at 50% 36%, #000, transparent 72%);
  animation: rays-spin 40s linear infinite;
}
.result-card {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; gap: 1rem;
  width: 100%; max-width: 860px; margin: auto; text-align: center;
}
.result-hud { padding: 0; }
.chip { display: inline-block; }
.result-hud .chip { font-size: .8rem; line-height: 1.5; }
.hud .chip.is-winner { color: var(--gold); }
.hud .chip.is-winner::before { content: "\2605 "; }
.hud .chip.is-loser { color: #9f9bd0; text-decoration: line-through; text-decoration-thickness: 2px; }
/* Winner's bar full, loser's drains to empty (chip precedes its bar) */
.chip.is-loser + .hp .hp-fill { transform: scaleX(0); animation: hp-drain .7s cubic-bezier(.7, 0, .3, 1) .35s both; }

/* Winner pose */
.podium { position: relative; isolation: isolate; padding: 1rem 0 .5rem; }
.podium::before {
  content: ""; position: absolute; z-index: -1; left: 50%; top: 50%; width: min(100%, 700px); aspect-ratio: 2 / 1;
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse, rgba(255, 210, 63, .38), transparent 66%);
}
.result-label {
  display: inline-flex; align-items: center; gap: .6rem; margin: 0;
  font-family: var(--f-pixel); font-size: clamp(.8rem, 2.6vw, 1.1rem); letter-spacing: .14em; text-transform: uppercase;
  color: var(--gold); text-shadow: 3px 3px 0 #000;
  animation: fade-in .4s ease-out 1s both;
}
.result-label svg { width: 1.8em; height: 1.8em; fill: var(--gold); stroke: #12082e; stroke-width: 2; filter: drop-shadow(2px 2px 0 #000); animation: victory-bob .6s steps(2, jump-none) 1.2s infinite; }
.winner-name {
  margin: .4rem 0 0;
  font-family: var(--f-display); font-size: clamp(2.2rem, 9vw, 5rem); line-height: 1.05; text-transform: uppercase;
  color: var(--gold); overflow-wrap: anywhere;
  -webkit-text-stroke: .06em #12082e; paint-order: stroke fill;
  text-shadow: 0 .04em 0 #c46a00, 0 .08em 0 #a14d00, 0 .12em 0 #7a3600, 0 .16em 0 #12082e, 0 0 .5em rgba(255, 210, 63, .75);
  animation: winner-pop .7s var(--snap) 1.1s both, victory-bob .6s steps(2, jump-none) 1.9s infinite;
}
.ko {   /* K.O.! slam, plays first then leaves */
  position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; pointer-events: none;
  animation: ko-show 1.35s linear both;
}
.ko-text {
  position: relative; isolation: isolate; font-family: var(--f-display); line-height: 1;
  font-size: clamp(5rem, 24vw, 15rem); color: #fff; text-transform: uppercase;
  -webkit-text-stroke: .08em #12082e; paint-order: stroke fill;
  text-shadow: 0 .06em 0 var(--red), 0 .12em 0 #7a1409, 0 .18em 0 #12082e, 0 0 .4em rgba(255, 74, 46, .9);
}
.ko-text::before {
  content: ""; position: absolute; z-index: -1; left: 50%; top: 50%; width: 1.9em; height: 1.6em; transform: translate(-50%, -50%);
  background: radial-gradient(circle, #fff 0, var(--gold) 38%, var(--red) 72%);
  clip-path: var(--burst);
}

/* Judge's ruling dialogue box */
.dialogue {
  position: relative; margin-top: .9rem; padding: 1.6rem 1.25rem 1rem; text-align: left;
  background: linear-gradient(#1b1757, #0d0a2e);
  border: 4px solid #fff6d8; border-radius: 6px;
  box-shadow: 0 0 0 4px #000, 8px 8px 0 4px #000, 0 0 36px rgba(56, 240, 255, .3);
  animation: fade-in .4s ease-out 1.1s both;
}
.dialogue-tag {
  position: absolute; top: -.95rem; left: 1rem; padding: .4rem .7rem;
  font-family: var(--f-pixel); font-size: .6rem; letter-spacing: .08em; text-transform: uppercase;
  color: #12082e; background: var(--gold); border: 3px solid #000; box-shadow: 3px 3px 0 #000;
}
.reasoning { margin: 0; min-height: 5.6em; font-size: clamp(1.02rem, 2.4vw, 1.2rem); line-height: 1.6; color: #fff; }
#reasoning-typed::after { content: "\25AE"; margin-left: .15em; color: var(--cyan); animation: blink .8s steps(2, jump-none) infinite; }
.skip-btn {
  display: block; min-height: 40px; margin: .4rem 0 0 auto; padding: .35rem .8rem;
  font-family: var(--f-pixel); font-size: .6rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--cyan); background: transparent; border: 2px solid var(--cyan); border-radius: 4px; cursor: pointer;
}
.skip-btn:hover { color: #12082e; background: var(--cyan); }
.skip-btn[hidden] { display: none; }
.result-actions {
  display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; margin-top: .6rem;
  animation: fade-in .4s ease-out 1.3s both;
}

/* ---------- 8. Error dialog: "Down for the count!" ---------- */
.dialog {
  width: min(92vw, 460px); padding: 0; overflow: visible; color: var(--text);
  background: #120f3a; border: 4px solid var(--red); border-radius: 8px;
  box-shadow: 0 0 0 4px #000, 9px 9px 0 4px #000, 0 0 60px rgba(255, 74, 46, .55);
}
.dialog[open] { display: block; animation: dialog-pop .3s cubic-bezier(.2, 1.4, .4, 1) both; }
.dialog::backdrop { background: radial-gradient(circle, rgba(255, 59, 48, .2), rgba(5, 4, 26, .9) 70%); }
.dialog::before {   /* hazard stripe */
  content: ""; display: block; height: 16px;
  background: repeating-linear-gradient(-45deg, var(--gold) 0 14px, #12082e 14px 28px);
  border-bottom: 4px solid #000;
}
.dialog-body { padding: 1.25rem 1.5rem 1.5rem; text-align: center; }
.dialog-stars { position: relative; width: 120px; height: 34px; margin: 0 auto .35rem; }
.dialog-stars span { position: absolute; left: 50%; top: 50%; margin: -.6em 0 0 -.5em; font-size: 1.4rem; line-height: 1; color: var(--gold); animation: dizzy 1.4s linear infinite; }
.dialog-stars span:nth-child(2) { animation-delay: -.47s; }
.dialog-stars span:nth-child(3) { animation-delay: -.93s; }
.dialog-kicker { margin: 0 0 .5rem; font-family: var(--f-pixel); font-size: .62rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.dialog h2 {
  margin: 0 0 1rem; font-family: var(--f-display); font-size: clamp(1.6rem, 6vw, 2.1rem); line-height: 1.1; text-transform: uppercase;
  color: #ff5a4a; -webkit-text-stroke: .06em #12082e; paint-order: stroke fill;
  text-shadow: 0 .05em 0 #7a1409, 0 .1em 0 #12082e;
}
.dialog #error-message {
  margin: 0 0 1.4rem; padding: .85rem 1rem; overflow-wrap: anywhere; font-weight: 500;
  background: rgba(0, 0, 0, .4); border: 2px dashed var(--line); border-radius: 4px;
}
.dialog-actions { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

/* ---------- 9. Responsive: 360px up ---------- */
@media (max-width: 720px) {
  #fight-form { grid-template-columns: minmax(0, 1fr); gap: 1.4rem; margin-top: 2.25rem; }
  .vs-divider { font-size: 3.2rem; margin: .4rem 0; }
  .slot-a, .slot-b { transform: none; }
  .slot { display: grid; grid-template-columns: 84px minmax(0, 1fr); column-gap: .9rem; row-gap: .5rem; padding: 1.4rem .9rem .9rem; }
  .slot .portrait { grid-row: 1 / span 2; height: 100%; min-height: 96px; }
  .portrait-q { font-size: 2.2rem; }
  .slot .field-label, .slot > label { grid-column: 2; align-self: end; }
  .slot > input { grid-column: 2; align-self: start; }
  .battledex { padding: 1.25rem .9rem; margin-top: 2.5rem; }
  .battledex-list { grid-template-columns: minmax(0, 1fr); }
  #screen-loading { --dx: 46px; }
  .stage { min-height: 520px; }
  .hud { padding: .75rem .75rem .25rem; gap: .5rem; }
  .hud-badge { width: 84px; height: 62px; }
  .hud-timer { font-size: 1.35rem; }
  .hud-name, .hud .chip { font-size: .6rem; }
  .hp { height: 24px; }
  .arena { margin-top: -1rem; }
  .fighter { max-width: 100%; }
  .loading-note { font-size: .95rem; }
  .result-actions .btn { flex: 1 1 100%; }
  .dialog-actions .btn { flex: 1 1 100%; }
}
@media (max-width: 400px) {
  .logo-text { font-size: 1.85rem; }
}

/* ---------- 10. Reduced motion: clean static layout ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  /* loading: static face-off, bars full, small burst behind VS, no ring/flash */
  .fighter-left, .fighter-right { transform: none; opacity: 1; }
  .clash::before { transform: scale(.85); }
  .clash::after, .stage::after { display: none; }
  /* result: skip the K.O. slam, show everything at once, no blinking cursor */
  .ko { display: none; }
  #reasoning-typed::after { content: none; }
}
@media (hover: none) { .btn:hover { transform: none; } }

/* ---------- Keyframes ---------- */
@keyframes blink      { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes fade-in    { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse-text { 0%, 100% { opacity: .75; } 50% { opacity: 1; } }
@keyframes logo-slam  { from { opacity: 0; transform: rotate(-3deg) scale(1.7); } to { opacity: 1; transform: rotate(-3deg) scale(1); } }
@keyframes slot-in-left  { from { opacity: 0; translate: -60px 0; } to { opacity: 1; translate: 0 0; } }
@keyframes slot-in-right { from { opacity: 0; translate: 60px 0; } to { opacity: 1; translate: 0 0; } }
@keyframes vs-slam    { from { opacity: 0; scale: 2.4; } to { opacity: 1; scale: 1; } }
@keyframes vs-pulse   { 0%, 100% { scale: 1; } 50% { scale: 1.08; } }
@keyframes burst-spin { to { transform: rotate(360deg); } }
@keyframes q-bob      { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes fight-pulse {
  0%, 100% { scale: 1;    box-shadow: 0 5px 0 #9a3a00, 0 8px 0 #000, 0 0 24px rgba(255, 170, 0, .5); }
  50%      { scale: 1.04; box-shadow: 0 5px 0 #9a3a00, 0 8px 0 #000, 0 0 52px rgba(255, 190, 40, .95); }
}
/* loading: one clash cycle = 1.6s, impact at 38% */
@keyframes charge-left {
  0%   { transform: translateX(calc(var(--dx) * -1.5)) rotate(-8deg) scale(.9); opacity: .15; }
  30%  { transform: translateX(calc(var(--dx) * .2)) rotate(3deg) scale(1.05); opacity: 1; }
  38%  { transform: translateX(calc(var(--dx) * .45)) rotate(5deg) scale(1.14); }
  48%  { transform: translateX(calc(var(--dx) * -.1)) rotate(-2deg) scale(1); }
  64%  { transform: translateX(calc(var(--dx) * -.55)) rotate(-4deg); }
  100% { transform: translateX(calc(var(--dx) * -1.5)) rotate(-8deg) scale(.9); opacity: .15; }
}
@keyframes charge-right {
  0%   { transform: translateX(calc(var(--dx) * 1.5)) rotate(8deg) scale(.9); opacity: .15; }
  30%  { transform: translateX(calc(var(--dx) * -.2)) rotate(-3deg) scale(1.05); opacity: 1; }
  38%  { transform: translateX(calc(var(--dx) * -.45)) rotate(-5deg) scale(1.14); }
  48%  { transform: translateX(calc(var(--dx) * .1)) rotate(2deg) scale(1); }
  64%  { transform: translateX(calc(var(--dx) * .55)) rotate(4deg); }
  100% { transform: translateX(calc(var(--dx) * 1.5)) rotate(8deg) scale(.9); opacity: .15; }
}
@keyframes clash-flash {
  0%, 30% { transform: scale(.6); opacity: .35; color: var(--red); }
  38%     { transform: scale(1.6); opacity: 1; color: #fff; }
  55%     { transform: scale(1.1); opacity: 1; color: var(--gold); }
  100%    { transform: scale(.6); opacity: .35; }
}
@keyframes burst   { 0%, 30% { transform: scale(0) rotate(0); } 38% { transform: scale(1.25) rotate(14deg); } 56% { transform: scale(.7) rotate(22deg); opacity: .8; } 70%, 100% { transform: scale(0) rotate(30deg); } }
@keyframes ring    { 0%, 36% { transform: scale(.3); opacity: 0; } 38% { opacity: 1; } 62%, 100% { transform: scale(2.4); opacity: 0; } }
@keyframes impact-flash { 0%, 36%, 50%, 100% { opacity: 0; } 38% { opacity: .28; } }
@keyframes stage-shake {
  0%, 34%, 52%, 100% { transform: translate(0, 0); }
  38% { transform: translate(-6px, 4px); } 42% { transform: translate(6px, -4px); }
  46% { transform: translate(-4px, -2px); } 50% { transform: translate(3px, 2px); }
}
@keyframes spot-sway    { from { transform: rotate(-7deg); } to { transform: rotate(7deg); } }
@keyframes crowd-sway   { from { transform: translateX(-14px); } to { transform: translateX(14px); } }
@keyframes crowd-bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes floor-scroll { to { background-position: 0 44px, 0 44px; } }
@keyframes timer-glow   { 0%, 100% { text-shadow: none; } 50% { text-shadow: 0 0 10px rgba(255, 255, 255, .9); } }
/* hit points: A is hit at 19% (first clash), B at 69% (second clash) */
@keyframes hp-hit-a { 0%, 19% { transform: scaleX(1); } 22% { transform: scaleX(.66); } 28% { transform: scaleX(.7); } 34% { transform: scaleX(.64); } 60% { transform: scaleX(.64); } 96%, 100% { transform: scaleX(1); } }
@keyframes hp-hit-b { 0%, 69% { transform: scaleX(1); } 72% { transform: scaleX(.6); } 78% { transform: scaleX(.66); } 84% { transform: scaleX(.58); } 94% { transform: scaleX(.58); } 100% { transform: scaleX(1); } }
/* result */
@keyframes hp-drain   { from { transform: scaleX(1); } }
@keyframes ko-show {
  0%   { opacity: 0; transform: scale(3) rotate(-10deg); }
  8%   { opacity: 1; transform: scale(1) rotate(-6deg); }
  14%  { transform: translate(-8px, 5px) rotate(-6deg); }
  20%  { transform: translate(8px, -5px) rotate(-6deg); }
  26%  { transform: translate(0, 0) rotate(-6deg); }
  72%  { opacity: 1; transform: scale(1.04) rotate(-6deg); visibility: visible; }
  100% { opacity: 0; transform: scale(1.5) rotate(-6deg); visibility: hidden; }
}
@keyframes winner-pop { from { opacity: 0; transform: scale(.25); } to { opacity: 1; transform: scale(1); } }
@keyframes victory-bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -6px; } }
@keyframes rays-spin  { to { --rot: 360deg; } }
@keyframes dialog-pop { from { opacity: 0; transform: scale(.6) rotate(-3deg); } to { opacity: 1; transform: none; } }
@keyframes dizzy {
  0%, 100% { transform: translate(44px, 0) scale(1); }
  25%      { transform: translate(0, 10px) scale(1.25); }
  50%      { transform: translate(-44px, 0) scale(1); }
  75%      { transform: translate(0, -10px) scale(.7); }
}

/* ---------- Crowd posters (loading screen) ---------- */
/* Signs sit behind the crowd so the sticks look held; slots are filled by app.js */
.posters { position: absolute; inset: 0; pointer-events: none; }
.poster {
  position: absolute; left: var(--x, 2%);
  bottom: calc(33% + 52px + var(--lift, 0px));
  width: 17%; max-width: 150px; min-width: 96px;
  transform-origin: 50% 100%;
  animation: poster-wave 1.2s ease-in-out var(--delay, 0s) infinite alternate;
}
.poster > span {
  display: grid; place-items: center; min-height: 3.1rem; padding: .35rem .4rem;
  font-family: var(--f-display); font-size: .62rem; line-height: 1.15; letter-spacing: .02em;
  text-align: center; text-transform: uppercase; overflow-wrap: anywhere;
  color: var(--pc-text, #12082e); background: var(--pc, #fff6d8);
  border: 3px solid #12082e; box-shadow: 3px 3px 0 #000;
}
.poster::after {   /* the stick */
  content: ""; display: block; width: 6px; height: 60px; margin: 0 auto;
  background: #7a4a1a; border: 2px solid #12082e; border-top: 0;
}
.poster-c1 { --pc: #fff6d8; }
.poster-c2 { --pc: var(--gold); }
.poster-c3 { --pc: #ff8a7a; }
.poster-c4 { --pc: #8ff3ff; }
@keyframes poster-wave {
  from { transform: rotate(calc(var(--tilt, 0deg) - 3deg)); }
  to   { transform: rotate(calc(var(--tilt, 0deg) + 3deg)); }
}
@media (max-width: 720px) {
  .poster { width: 31%; max-width: none; min-width: 0; }
  .poster > span { font-size: .55rem; min-height: 2.6rem; }
  .poster { left: var(--xm, 1%); }
}
