/* ============================================================================
   ShibFighter — presentation layer
   One stylesheet. Everything is driven off a small token set at :root so a
   character's colour can flood its whole side of the HUD from one --ui value.
   Sizes use clamp() rather than breakpoints wherever a value can scale
   continuously — a 360px phone and a 1920px desktop then get the same
   composition instead of two hand-tuned ones that drift apart.
   ========================================================================= */

:root {
  --hud-band: clamp(96px, 18vh, 220px);    /* read by the camera via #hudprobe */
  --bg:      #05060c;
  --ink:     #eef4ff;
  --dim:     #8a93ab;
  --neon:    #7fd4ff;
  --gold:    #ffcc33;
  --bad:     #ff5f5f;
  --panel:   rgba(10, 14, 26, .74);
  --edge:    rgba(127, 212, 255, .30);
  --ui:      #7fd4ff;             /* per-side override */

  --arcade:  'Arial Black', 'Segoe UI Black', 'Helvetica Neue', Impact,
             system-ui, sans-serif;
  --ui-font: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: var(--ui-font);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none; touch-action: none;
}

#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

#hudprobe {
  position: fixed; top: 0; left: 0; width: 0;
  height: var(--hud-band); visibility: hidden; pointer-events: none;
}

#flash {
  position: fixed; inset: 0; background: #fff; opacity: 0;
  pointer-events: none; z-index: 60; mix-blend-mode: screen;
}

/* No z-index here on purpose. With one, #ui becomes a stacking context and
   #screens (z 40) is trapped inside it — the touch pad (z 30, a body child)
   then paints over the character-select and pause menus and swallows taps. */
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui button, #ui input, #ui .card { pointer-events: auto; }

/* ---------------------------------------------------------------- boot ---- */
#boot {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-content: center; justify-items: center; gap: 18px;
  background:
    radial-gradient(120% 80% at 50% 30%, #101a35 0%, #05060c 62%);
}
.bootmark {
  font: 900 clamp(26px, 7vw, 54px)/1 var(--arcade);
  letter-spacing: .04em; transform: skewX(-8deg);
  color: var(--ink); text-shadow: 0 0 26px rgba(127,212,255,.45);
}
.bootmark em { font-style: normal; color: var(--gold); }
.bootbar {
  width: min(62vw, 340px); height: 8px; border-radius: 99px;
  background: rgba(255,255,255,.09);
  border: 1px solid var(--edge); overflow: hidden;
}
/* NO TRANSITION ON THE WIDTH. It had `width .28s ease`, and boot is the one
   moment in the app when the compositor is busiest -- decoding two atlases, a
   stage and three music beds. The document timeline never advanced: sampled
   every 20 ms for the whole of boot, the fill read 10.2% of 340 px at every
   single sample, including while the label already said "ready", and then
   #boot was removed. The bar showed no progress at all. Six discrete steps is
   what a loading bar honestly is; a transition it cannot run is not polish. */
.bootbar i {
  display: block; height: 100%; width: 8%;
  background: linear-gradient(90deg, var(--neon), var(--gold));
  box-shadow: 0 0 14px var(--neon);
}
.bootmsg { font-size: 12px; letter-spacing: .18em; text-transform: uppercase;
           color: var(--dim); }

/* ===========================================================================
   HUD
   ========================================================================= */
/* Scrim. The stages are deliberately bright — a moon lit by Earth, a casino in
   neon — and white-on-bright is unreadable. One gradient behind the whole band
   costs nothing and makes the HUD legible on every stage instead of on some. */
/* `--hud-scrim` is written every resize by measureSafeArea() from the HUD's
   REAL bottom edge; `--hud-band` is only the CSS guess it falls back to before
   the first measure. The guess is a vh clamp and the HUD is not a vh tall: it
   ran 14.8 px short at 844x390 (bars poking out of the bottom of their own
   scrim) and 67 px long at 1080p (a dark bar over nothing). It is deliberately
   a SECOND variable -- #hudprobe's height is `--hud-band`, and measureSafeArea
   reads that probe, so writing the measurement back into it would ratchet the
   band upwards on every resize and never let it shrink again. */
#hud::before {
  content: ''; position: fixed; left: 0; right: 0;
  top: 0; height: var(--hud-scrim, var(--hud-band)); pointer-events: none;
  background: linear-gradient(180deg, rgba(3,5,12,.86) 0%, rgba(3,5,12,.72) 46%,
                                      rgba(3,5,12,.34) 74%, rgba(3,5,12,0) 100%);
}
#hud {
  position: absolute; top: calc(var(--safe-t) + clamp(6px, 1.4vw, 16px));
  left:  calc(var(--safe-l) + clamp(6px, 1.6vw, 22px));
  right: calc(var(--safe-r) + clamp(6px, 1.6vw, 22px));
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: start; gap: clamp(6px, 1.4vw, 18px);
  pointer-events: none;
}

#hud .side { display: grid; gap: 5px; min-width: 0; }
#hud .side.p2 { justify-items: end; }

/* name plate ---------------------------------------------------------------*/
#hud .plate {
  display: flex; align-items: center; gap: 8px;
  filter: drop-shadow(0 3px 8px rgba(0,0,0,.6));
}
#hud .p2 .plate { flex-direction: row-reverse; }
#hud .p2 .plate > div { text-align: right; }
#hud .face {
  width: clamp(30px, 5.6vw, 54px); height: clamp(30px, 5.6vw, 54px);
  object-fit: cover; object-position: 50% 18%;
  border: 2px solid var(--ui); border-radius: 6px;
  background: #0a0f1e;
  box-shadow: 0 0 14px color-mix(in srgb, var(--ui) 55%, transparent);
  clip-path: polygon(0 0, 100% 0, 100% 84%, 84% 100%, 0 100%);
}
#hud .nm {
  font: 900 clamp(13px, 2.2vw, 21px)/1 var(--arcade);
  letter-spacing: .03em; transform: skewX(-8deg); display: inline-block;
  text-shadow: 0 2px 6px #000, 0 0 14px rgba(0,0,0,.9);
}
/* The character, when the big slot is holding a person's name instead. Sized
   and dimmed so a plate reads "rinrin.shib (SHIB)" as one line with an
   obvious primary, and clamped so a long name cannot push the bar around. */
#hud .ch {
  font: 700 clamp(8px, 1.15vw, 11px)/1 var(--ui-font);
  letter-spacing: .14em; opacity: .8; margin-left: .45em;
  vertical-align: 2px; white-space: nowrap;
}
#hud .ch:empty { display: none; }
#hud .ch::before { content: '('; }
#hud .ch::after  { content: ')'; }
#hud .nm {
  max-width: min(42vw, 320px); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
}
#hud .tag {
  font: 700 9px/1 var(--ui-font); letter-spacing: .16em;
  color: #05060c; background: var(--ui); padding: 2px 5px;
  border-radius: 3px; vertical-align: 3px;
}

/* health -------------------------------------------------------------------*/
#hud .hpwrap {
  position: relative; width: 100%;
  height: clamp(12px, 1.9vw, 20px);
  background: linear-gradient(180deg, #0d1428, #060a15);
  border: 2px solid rgba(255,255,255,.20);
  border-radius: 3px; overflow: hidden;
  transform: skewX(-14deg);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.08), 0 3px 10px rgba(0,0,0,.55);
}
#hud .hpwrap > i { position: absolute; top: 0; bottom: 0; display: block; }
#hud .p1 .hpwrap > i { right: 0; }      /* P1 drains toward the centre */
#hud .p2 .hpwrap > i { left: 0; }
/* The chip trail is ALREADY lerped in JS (`hud.js` eases `_chip` by dt*2.2 and
   writes the width every frame). The CSS transition on top of it was a second
   animation of the same value, on the document timeline -- which stalls. */
#hud .chip { width: 100%; background: var(--bad); opacity: .85; }
#hud .hp   { width: 100%; }
#hud .hp.low { animation: hplow .5s steps(2, end) infinite; }
/* recoverable damage: sits between the chip trail and the live health, so the
   stack reads chip (what you lost) / recoverable (what you get back) / health */
#hud .rec { background: var(--ui); opacity: 0; filter: saturate(.35) brightness(1.6); }
#hud .rec.on { opacity: .5; }
/* three bars. Two hairlines rather than three boxes: the bar still drains as
   one continuous thing, which is what the eye tracks, and the segments only
   tell you how much of a fight is left. */
#hud .hpwrap > u.seg { position: absolute; top: 0; bottom: 0; width: 2px;
  left: 33.33%; background: rgba(0,0,0,.55); pointer-events: none; z-index: 3; }
#hud .hpwrap > u.seg.two { left: 66.66%; }
/* guard ---------------------------------------------------------------------
   A second, thinner bar under the health. It is deliberately quiet while full:
   a bar that shouts when nothing has happened teaches the eye to ignore it. */
/* `width: 100%` is not decoration. `.side.p2` sets `justify-items: end` so the
   PLATE and the ki row right-align, and a grid item with no in-flow content
   then sizes to fit-content -- which for this wrapper (its only child is
   absolutely positioned) is ZERO. P2's guard meter rendered 0 px wide at every
   viewport tested and simply did not exist on screen; `.hpwrap` escaped only
   because it happens to declare a width. */
#hud .gdwrap { position: relative; width: 100%; height: 5px; margin-top: 3px;
  background: rgba(255,255,255,.07); border-radius: 3px; overflow: hidden;
  opacity: .35; }
#hud .gdwrap.spent { opacity: 1; }
/* NO TRANSITION. `transition: width .10s linear` on a bar whose width is
   rewritten from the model every single frame does nothing but lag it -- and
   on the document timeline it does not lag, it STOPS. Driven down in steps and
   sampled against the model it held: the guard bar read 40% while the fighter
   was at 16%, and 40% again at 4%, one blocked heavy from a break. Up to 36
   points high, on the one bar whose whole job is to say "you are about to be
   opened". The health bar was fine because it has no transition; the chip
   trail above it and the boot bar and the select cards were all the same
   defect. */
#hud .gdwrap > i { position: absolute; top: 0; bottom: 0; display: block;
  background: linear-gradient(180deg, #cfe4ff, #6fa8dc); }
#hud .p1 .gdwrap > i { right: 0; }
#hud .p2 .gdwrap > i { left: 0; }
#hud .gd.low { background: linear-gradient(180deg, #ffe08a, #ff9f1a);
  animation: hplow .4s steps(2, end) infinite; }
@keyframes hplow { 50% { filter: brightness(2.1) saturate(.4); } }

/* meter --------------------------------------------------------------------*/
#hud .kirow { display: flex; align-items: center; gap: 4px; }
#hud .p2 .kirow { flex-direction: row-reverse; }
#hud .kirow i {
  --f: 0; --kc: var(--ui);
  position: relative; display: block;
  width: clamp(20px, 3.6vw, 42px); height: clamp(5px, .8vw, 9px);
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.20);
  transform: skewX(-20deg); overflow: hidden;
}
#hud .kirow i::after {
  content: ''; position: absolute; inset: 0;
  transform-origin: left; transform: scaleX(var(--f));
  background: linear-gradient(90deg, var(--kc), #fff);
  box-shadow: 0 0 8px var(--kc);
}
#hud .p2 .kirow i::after { transform-origin: right; }
#hud .kirow.max i { animation: kimax .45s ease-in-out infinite alternate; }
@keyframes kimax { to { box-shadow: 0 0 14px var(--kc); filter: brightness(1.5); } }
#hud .lvl {
  font: 900 clamp(10px, 1.5vw, 14px)/1 var(--arcade); color: var(--ui);
  min-width: 1ch; text-shadow: 0 0 8px currentColor;
}

/* centre column ------------------------------------------------------------*/
#hud .mid { display: grid; justify-items: center; gap: 5px; }
#hud .rounds { display: flex; align-items: center; gap: 4px; }
#hud .rounds em { width: 8px; }
#hud .rd {
  width: clamp(8px, 1.2vw, 12px); height: clamp(8px, 1.2vw, 12px);
  border-radius: 50%; background: rgba(6,10,20,.85);
  border: 2px solid rgba(255,255,255,.65);
  box-shadow: 0 1px 4px rgba(0,0,0,.9);
}
#hud .rd.on { background: var(--gold); border-color: #fff6cf;
              box-shadow: 0 0 10px var(--gold); }
#hud .timerplate {
  min-width: clamp(46px, 7vw, 76px); text-align: center;
  padding: 2px 8px 3px;
  font: 900 clamp(20px, 3.6vw, 40px)/1.05 var(--arcade);
  font-variant-numeric: tabular-nums;
  background: var(--panel); border: 2px solid var(--edge);
  border-radius: 4px; backdrop-filter: blur(6px);
  clip-path: polygon(6% 0, 94% 0, 100% 100%, 0 100%);
  text-shadow: 0 0 16px rgba(127,212,255,.5);
}
#hud .timerplate.low { color: var(--bad); border-color: var(--bad);
  animation: tlow .5s steps(2, end) infinite; }
@keyframes tlow { 50% { filter: brightness(1.9); } }

/* combo + banner -----------------------------------------------------------*/
#combo {
  position: absolute; left: clamp(10px, 6vw, 90px);
  /* the third term is a FLOOR under the HUD, not a new position: on a desktop
     the 30% term still wins and nothing moves. Without it the counter sat 10.7
     px inside P1's meter row at 844x390. */
  top: max(30%, calc(var(--safe-t) + clamp(150px, 21vh, 250px)),
           calc(var(--hud-scrim, var(--hud-band)) + 10px));
  opacity: 0; transform: skewX(-10deg) scale(.7);
  /* grow RIGHTWARD. With the default centre origin the 1.12 pop pushed the
     left edge to -3.9 px at 844x390 and -2.2 px at 740x360, clipping the
     leading digit off the screen at exactly the moment it is worth reading. */
  transform-origin: 0 50%;
  pointer-events: none; text-align: left; line-height: .9;
}
#combo b {
  font: 900 clamp(34px, 8vw, 84px)/.85 var(--arcade); color: var(--gold);
  display: block; text-shadow: 0 0 22px rgba(255,204,51,.65), 3px 4px 0 #2a1a00;
}
#combo small { display: block; margin-top: .28em;
  font: 900 clamp(10px, 1.7vw, 17px)/1 var(--arcade);
  letter-spacing: .26em; color: var(--ink);
  text-shadow: 0 2px 8px #000; }

#banner {
  position: absolute; inset: 0; display: grid; place-content: center;
  font: 900 clamp(34px, 9vw, 108px)/1 var(--arcade);
  letter-spacing: .04em; transform: skewX(-8deg);
  opacity: 0; pointer-events: none; text-align: center;
  text-shadow: 0 0 34px currentColor, 4px 5px 0 rgba(0,0,0,.75);
}

/* ===========================================================================
   SCREENS  (menu / controls / select / pause / result)
   ========================================================================= */
#screens {
  position: absolute; inset: 0; z-index: 40;
  /* flex + auto margins, not place-items:center. A centred grid whose child is
     taller than the box splits the overflow above AND below, and the part above
     is unreachable — at 844x390 the CONTROLS heading and the START button were
     both off-screen with no scrollbar. */
  display: flex; align-items: flex-start; justify-content: center;
  pointer-events: auto;
  background:
    radial-gradient(130% 90% at 50% 40%, rgba(9,14,32,.62), rgba(3,4,10,.93));
  backdrop-filter: blur(3px);
  padding: calc(var(--safe-t) + 12px) 14px calc(var(--safe-b) + 12px);
  overflow-y: auto; overscroll-behavior: contain;
}
#screens .scr { display: none; }
#screens .scr.on {
  display: grid; justify-items: center; gap: clamp(10px, 2.2vh, 26px);
  width: min(940px, 100%); text-align: center; margin: auto 0;
  /* Transform-only, no opacity, no fill-mode. Measured: under a saturated
     compositor Chromium leaves a freshly started animation at currentTime 0
     indefinitely, so an `opacity: 0` first keyframe hides the screen forever.
     Frozen at t=0 this one merely sits 14px low, which nobody can see. */
  animation: scrin .32s cubic-bezier(.2,.9,.3,1);
}
@keyframes scrin { from { transform: translateY(14px) scale(.985); } }

#screens h1 {
  margin: 0; font: 900 clamp(38px, 11vw, 104px)/.92 var(--arcade);
  letter-spacing: .02em; transform: skewX(-8deg);
  text-shadow: 0 0 40px rgba(127,212,255,.42), 5px 6px 0 rgba(0,0,0,.7);
}
#screens h1 em { font-style: normal; display: block; color: var(--gold);
  text-shadow: 0 0 40px rgba(255,204,51,.45), 5px 6px 0 rgba(0,0,0,.7); }
#screens h2 {
  margin: 0; font: 900 clamp(20px, 4.4vw, 40px)/1 var(--arcade);
  letter-spacing: .06em; transform: skewX(-8deg);
  text-shadow: 0 0 26px rgba(127,212,255,.35);
}
#screens .sub {
  margin: -6px 0 0; font-size: clamp(11px, 1.6vw, 14px);
  letter-spacing: .42em; text-indent: .42em; color: var(--neon);
  text-transform: uppercase;
}
#screens [data-rsub] {
  font: 900 clamp(22px, 4vw, 40px)/1 var(--arcade);
  letter-spacing: .12em; text-indent: 0; color: var(--ink);
  text-shadow: 0 0 20px rgba(127,212,255,.4);
}
#screens .arch {
  margin: 0; min-height: 2.4em; max-width: 30ch;
  font-size: clamp(12px, 1.7vw, 15px); line-height: 1.5; color: var(--dim);
}
#screens .hint { margin: 0; max-width: 52ch; color: var(--dim);
  font-size: clamp(11px, 1.6vw, 14px); line-height: 1.6; }

/* buttons ------------------------------------------------------------------*/
#screens .btns { display: flex; flex-wrap: wrap; gap: 12px;
  justify-content: center; align-items: center; }
#screens .btns.col { flex-direction: column; }
#screens button {
  font-family: var(--arcade); font-weight: 900; letter-spacing: .10em;
  cursor: pointer; border-radius: 4px; transform: skewX(-10deg);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
#screens button > * { display: inline-block; transform: skewX(10deg); }
#screens .big {
  font-size: clamp(16px, 2.6vw, 26px); padding: .62em 1.9em;
  color: #04070f; border: none;
  background: linear-gradient(160deg, #ffe08a, var(--gold) 42%, #e59a00);
  box-shadow: 0 5px 0 #7a4f00, 0 10px 26px rgba(255,180,0,.32);
}
#screens .big:hover, #screens .big:focus-visible {
  transform: skewX(-10deg) translateY(-2px);
  box-shadow: 0 7px 0 #7a4f00, 0 14px 34px rgba(255,180,0,.48); outline: none; }
#screens .big:active { transform: skewX(-10deg) translateY(3px);
  box-shadow: 0 2px 0 #7a4f00; }
#screens .ghost {
  font-size: clamp(12px, 1.8vw, 17px); padding: .58em 1.5em;
  color: var(--ink); background: rgba(255,255,255,.05);
  border: 2px solid var(--edge);
}
#screens .ghost:hover, #screens .ghost:focus-visible {
  background: rgba(127,212,255,.16); border-color: var(--neon);
  transform: skewX(-10deg) translateY(-2px); outline: none; }

/* wallet row ---------------------------------------------------------------*/
#screens .who {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  justify-content: center; min-height: 2em;
}
#screens button.small {
  font-size: clamp(10px, 1.4vw, 13px); padding: .45em 1.1em;
}
#screens .whoname {
  font: 700 clamp(11px, 1.7vw, 15px)/1 var(--ui-font);
  letter-spacing: .10em; color: var(--dim); max-width: 26ch;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* a resolved name is the point of the whole row, so it gets the gold and the
   hex it replaced stays dim -- the difference is visible without reading it */
#screens .whoname.named { color: var(--gold); letter-spacing: .06em; }

/* character cards ----------------------------------------------------------*/
#screens .cards {
  display: flex; flex-wrap: wrap; gap: clamp(8px, 1.6vw, 20px);
  justify-content: center; width: 100%;
}
#screens .card {
  --ui: var(--neon);
  position: relative; padding: 0; overflow: hidden;
  flex: 0 0 auto;
  width: clamp(96px, 24vw, 190px); aspect-ratio: 3 / 4;
  background: linear-gradient(180deg, #0d1428, #060a14);
  border: 3px solid rgba(255,255,255,.14); border-radius: 8px;
  transform: none; cursor: pointer;
  transition: transform .16s cubic-bezier(.2,1.4,.4,1),
              border-color .16s ease, box-shadow .16s ease;
}
#screens .card img, #screens .card canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 12%;
}
/* These two opacities are the CROSS-FADE between the still portrait and the
   live idle animation, and screens.js drives them from its own rAF -- the same
   loop that draws the sprite. They were `transition: opacity .2s ease`, and
   the transition never ran: sampled every 40 ms across a selection change, the
   DESELECTED card sat at canvas 1.00 / img 1.00 (fully lit, both layers) and
   the NEWLY SELECTED one at canvas 0.00 / img 0.18 (a dark silhouette) for the
   whole 600 ms of the trace and beyond. Neither transition advanced by a
   single step. This is the same document-timeline stall that hud.js documents
   for the banner and the combo counter, and it has the same answer: animate
   from the frame loop, which cannot desynchronise from what it is drawing.
   The values below are the pre-script fallback; inline styles win. */
#screens .card canvas { object-fit: contain; object-position: 50% 100%;
  opacity: 0; }
#screens .card.sel canvas { opacity: 1; }
#screens .card.sel img { opacity: .18; filter: saturate(.4); }
/* ON THE CARD, NOT ON `.sel`.
   `.card.sel { transition: none }` only suppresses the transition while the
   class is ON. Take `.sel` away and the card falls back to `#screens .card`'s
   own `transition: transform .16s, border-color .16s, box-shadow .16s`, so the
   card you clicked AWAY from kept its lift, its accent border and its glow:
   `getAnimations()` returned six running CSSTransitions on the deselected card
   and none on the selected one, and it took 520-1130 ms to clear against a
   declared 160 ms. The lift is a discrete state change, not a journey, and a
   transform transition stalls on the document timeline exactly like the
   opacity one did. */
#screens .card { transition: none; }
#screens .card::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, transparent 48%, rgba(4,6,14,.92) 100%);
}
#screens .card .nm {
  position: absolute; left: 0; right: 0; bottom: 6px; z-index: 2;
  font: 900 clamp(13px, 2.2vw, 22px)/1 var(--arcade);
  letter-spacing: .06em; transform: skewX(-8deg); color: #fff;
  text-shadow: 0 2px 10px #000;
}
#screens .card:hover { transform: translateY(-4px); border-color: var(--ui); }
#screens .card.sel {
  border-color: var(--ui);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ui) 45%, transparent),
              0 12px 34px color-mix(in srgb, var(--ui) 34%, transparent);
  transform: translateY(-6px) scale(1.04);
}
#screens .card.sel .nm { color: var(--ui); }
#screens .card.locked {
  display: grid; place-content: center; gap: 6px; cursor: default;
  border-style: dashed; border-color: rgba(255,255,255,.14); opacity: .5;
}
#screens .card.locked:hover { transform: none; border-color: rgba(255,255,255,.14); }
#screens .card.locked::after { display: none; }
#screens .card .q { font: 900 clamp(30px, 6vw, 56px)/1 var(--arcade);
  color: var(--dim); }
#screens .card.locked .nm { position: static; font-size: clamp(9px, 1.4vw, 12px);
  letter-spacing: .18em; color: var(--dim); }

/* versus card --------------------------------------------------------------*/
/* Every animation here is TRANSFORM-ONLY, with no opacity keyframe and no
   fill-mode, for the reason `.scr.on` documents above: under a saturated
   compositor Chromium leaves a freshly started animation parked at
   currentTime 0. An `opacity: 0` first keyframe would then hide the versus
   card permanently. Frozen at t=0 these merely start slightly offset or a
   touch small, which reads as a still frame rather than as a broken screen. */
#screens .vsrow {
  display: flex; align-items: center; justify-content: center;
  gap: clamp(6px, 2vw, 28px); width: 100%;
}
#screens .vside {
  --ui: var(--neon);
  display: grid; justify-items: center; gap: 6px;
  flex: 0 1 auto; min-width: 0;
}
#screens .vport {
  width: clamp(104px, 26vw, 236px); aspect-ratio: 3 / 4;
  overflow: hidden; border-radius: 8px;
  border: 3px solid var(--ui);
  background: linear-gradient(180deg, #0d1428, #060a14);
  box-shadow: 0 0 30px -6px var(--ui), inset 0 0 40px -18px var(--ui);
}
#screens .vport img {
  width: 100%; height: 100%; object-fit: cover; object-position: 50% 12%;
  /* the right-hand fighter faces the left one, the way the two stand in the
     fight -- an unmirrored pair both look off the same edge of the screen */
}
#screens .vside.r .vport img { transform: scaleX(-1); }
#screens .vnm {
  font: 900 clamp(15px, 3vw, 30px)/1 var(--arcade);
  letter-spacing: .08em; color: var(--ui); transform: skewX(-8deg);
  text-shadow: 0 0 22px currentColor, 3px 4px 0 rgba(0,0,0,.7);
}
#screens .vtok {
  font-size: clamp(9px, 1.3vw, 12px); letter-spacing: .24em;
  text-indent: .24em; color: var(--dim); text-transform: uppercase;
}
#screens .vbolt {
  flex: 0 0 auto;
  font: 900 clamp(26px, 7vw, 68px)/1 var(--arcade);
  letter-spacing: .02em; color: var(--gold); transform: skewX(-8deg);
  text-shadow: 0 0 38px rgba(255,204,51,.55), 4px 5px 0 rgba(0,0,0,.75);
}
#screens .vsrow.go .vside[data-vs="a"] { animation: vsl .40s cubic-bezier(.15,.85,.25,1); }
#screens .vsrow.go .vside[data-vs="b"] { animation: vsr .40s cubic-bezier(.15,.85,.25,1); }
#screens .vsrow.go .vbolt { animation: vsb .34s .16s cubic-bezier(.2,1.6,.4,1); }
@keyframes vsl { from { transform: translateX(-14%); } }
@keyframes vsr { from { transform: translateX(14%); } }
@keyframes vsb { from { transform: skewX(-8deg) scale(.72); } }
@media (prefers-reduced-motion: reduce) {
  #screens .vsrow.go .vside[data-vs="a"],
  #screens .vsrow.go .vside[data-vs="b"],
  #screens .vsrow.go .vbolt { animation: none; }
}

/* rankings -----------------------------------------------------------------*/
#screens .ranked {
  font: 700 9px/1 var(--ui-font); letter-spacing: .16em;
  color: #05060c; background: var(--gold); padding: 3px 6px; border-radius: 3px;
}
#screens .board {
  width: 100%; max-height: 52vh; overflow-y: auto; overscroll-behavior: contain;
}
#screens table.ranks {
  width: 100%; border-collapse: collapse;
  font: 700 clamp(10px, 1.5vw, 13px)/1.5 var(--ui-font);
}
#screens table.ranks th {
  position: sticky; top: 0; z-index: 1;
  padding: 6px 8px; text-align: left; letter-spacing: .14em;
  color: var(--dim); background: #070b16;
  border-bottom: 2px solid var(--edge);
}
#screens table.ranks td {
  padding: 6px 8px; border-bottom: 1px solid rgba(255,255,255,.06);
  color: var(--ink);
}
#screens table.ranks th.n, #screens table.ranks td.n,
#screens table.ranks th.r, #screens table.ranks td.r { text-align: right; }
#screens table.ranks td.r { color: var(--dim); width: 3ch; }
/* the name is the column that has to hold a long .shib without shoving the
   numbers off the right-hand edge, so it takes all the slack and ellipsises */
#screens table.ranks td.who {
  width: 99%; max-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; color: var(--gold);
}
#screens table.ranks tr.me td { background: rgba(127,212,255,.10); }
#screens table.ranks tr.me td.who { color: var(--neon); }

/* controls sheet -----------------------------------------------------------*/
#screens .keys {
  display: grid; gap: 8px clamp(12px, 2.5vw, 30px); justify-content: center;
  grid-template-columns: repeat(2, max-content);
}
@media (min-width: 700px) { #screens .keys { grid-template-columns: repeat(3, max-content); } }
#screens .keys > div { display: flex; align-items: center; gap: 7px; }
#screens .keys span { font-size: clamp(11px, 1.6vw, 14px); color: var(--dim);
  letter-spacing: .06em; }
#screens kbd {
  min-width: 2.1em; padding: .3em .5em; text-align: center;
  font: 700 clamp(10px, 1.5vw, 13px)/1 var(--ui-font);
  color: var(--ink); background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.22);
  border-bottom-width: 3px; border-radius: 5px;
}
#screens .vol { display: flex; align-items: center; gap: 12px;
  font: 700 11px/1 var(--ui-font); letter-spacing: .2em; color: var(--dim); }
#screens .vol input { width: min(46vw, 200px); accent-color: var(--neon); }

/* ===========================================================================
   TOUCH CONTROLS
   ========================================================================= */
#touch {
  position: fixed; inset: 0; z-index: 30; display: none;
  pointer-events: none;
}
#touch.on { display: block; }

#touch .tpad {
  position: absolute;
  left: calc(var(--safe-l) + 18px); bottom: calc(var(--safe-b) + 20px);
  width: 132px; height: 132px; border-radius: 50%;
  background: radial-gradient(circle, rgba(127,212,255,.10), rgba(6,10,20,.42));
  border: 2px solid rgba(127,212,255,.28);
  pointer-events: auto; touch-action: none;
  display: grid; place-items: center;
}
#touch .tstick {
  width: 58px; height: 58px; border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #cfeaff, #4c86b5);
  border: 2px solid rgba(255,255,255,.5);
  box-shadow: 0 4px 14px rgba(0,0,0,.55);
  transition: transform .06s linear;
}

#touch .tbtns {
  position: absolute;
  right: calc(var(--safe-r) + 16px); bottom: calc(var(--safe-b) + 16px);
  width: 208px; height: 200px; pointer-events: none;
}
#touch .tb {
  position: absolute; pointer-events: auto; touch-action: none;
  width: 64px; height: 64px; border-radius: 50%;
  font: 900 14px/1 var(--arcade); letter-spacing: .04em;
  color: #04070f; border: 2px solid rgba(255,255,255,.42);
  background: radial-gradient(circle at 34% 30%, #ffffff, #9fb6cf);
  box-shadow: 0 4px 12px rgba(0,0,0,.5);
  transition: transform .06s ease, filter .06s ease;
}
#touch .tb.hit { transform: scale(.90); filter: brightness(1.35); }
/* bottom-centre: the only part of the frame that is neither HUD, nor thumb
   cluster, nor the fighters' plane. Top-right put it on P2's portrait. */
#touch .tb-p {
  position: absolute; left: 50%; margin-left: -21px;
  bottom: calc(var(--safe-b) + 10px); top: auto; right: auto;
  width: 42px; height: 42px; font-size: 15px; color: var(--ink);
  letter-spacing: .18em; text-indent: .18em;
  background: rgba(8,12,24,.66); border-color: rgba(255,255,255,.38);
}
#touch .tb-l { right: 74px; bottom: 4px;
  background: radial-gradient(circle at 34% 30%, #fff, #7fd4ff); }
#touch .tb-h { right: 4px;  bottom: 46px;
  background: radial-gradient(circle at 34% 30%, #fff, #ffcc33); }
#touch .tb-s { right: 40px; bottom: 116px;
  background: radial-gradient(circle at 34% 30%, #fff, #ff7ad9); }
#touch .tb-b { right: 140px; bottom: 40px; width: 56px; height: 56px;
  font-size: 12px; background: radial-gradient(circle at 34% 30%, #fff, #9fe08a); }
#touch .tb-j { right: 112px; bottom: 112px; width: 56px; height: 56px;
  font-size: 11px; }
#touch .tb-d { right: 178px; bottom: 108px; width: 52px; height: 52px;
  font-size: 11px; }

/* ---------------------------------------------------------------- adapt --- */
/* Short landscape phones: the pad and buttons must not eat the fighters. */
/* Short landscape (a phone held sideways) is the natural way to hold a fighting
   game, so the menus have to fit in ~390px of height. Cards are sized off the
   viewport height there, not its width — sized off width they pushed START off
   the bottom of the character-select screen. */
@media (max-height: 560px) {
  #screens { padding-top: calc(var(--safe-t) + 8px); padding-bottom: calc(var(--safe-b) + 8px); }
  #screens .scr.on { gap: 8px; }
  #screens h1 { font-size: clamp(28px, 8vh, 54px); }
  #screens h2 { font-size: clamp(15px, 4.6vh, 26px); }
  #screens .card { width: auto; height: min(45vh, 190px); }
  #screens .arch { min-height: 1.4em; font-size: 12px; }
  #screens .big { font-size: clamp(13px, 3.8vh, 20px); padding: .5em 1.5em; }
  #screens .ghost { font-size: clamp(11px, 3vh, 15px); padding: .45em 1.1em; }
  #screens .keys { gap: 4px 14px; }
  #screens .hint { display: none; }
}

@media (max-height: 460px) {
  #touch .tpad  { width: 100px; height: 100px; bottom: calc(var(--safe-b) + 6px); }
  #touch .tstick { width: 44px; height: 44px; }
  /* flatter cluster: at 390px tall the fighters occupy y 100-330, so a stack
     that reaches 168px up from the bottom sits on top of them */
  #touch .tbtns { width: 210px; height: 122px; bottom: calc(var(--safe-b) + 6px); }
  #touch .tb    { width: 52px; height: 52px; font-size: 11px; }
  #touch .tb-l { right: 62px; bottom: 0; }
  #touch .tb-h { right: 4px;  bottom: 30px; }
  #touch .tb-s { right: 34px; bottom: 68px; }
  #touch .tb-b { right: 122px; bottom: 24px; width: 48px; height: 48px; }
  #touch .tb-j { right: 100px; bottom: 72px; width: 46px; height: 46px; }
  #touch .tb-d { right: 160px; bottom: 62px; width: 44px; height: 44px; }
  #combo { top: calc(var(--hud-scrim, var(--hud-band)) + 10px); left: 14px; }
}
/* Portrait phones: keep the select grid two-up rather than one-up. */
@media (max-width: 430px) {
  #screens .cards { gap: 8px; }
  #screens .card  { width: clamp(96px, 29vw, 132px); }
  #screens .keys  { gap: 6px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  #screens .scr.on { animation: none; }
  #hud .hp.low, #hud .timerplate.low, #hud .kirow.max i { animation: none; }
}

/* ---------------------------------------------------------------- rotate ---
   Two fighters 4.8 world units apart cannot be framed at a 0.46 aspect without
   shrinking them to a hundred pixels. Rather than ship an unplayable portrait
   mode, ask for the width — and say the right thing depending on whether the
   viewer has a device to turn or a window to resize. */
#rotate {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-content: center; justify-items: center; gap: 14px;
  text-align: center; padding: 24px;
  background: radial-gradient(120% 90% at 50% 40%, #101a35, #04060d 70%);
}
#rotate[hidden] { display: none; }
.rotmark { font-size: clamp(48px, 16vw, 92px); line-height: 1; color: var(--neon);
  text-shadow: 0 0 30px rgba(127,212,255,.5);
  animation: rot 2.4s cubic-bezier(.6,0,.3,1) infinite; }
@keyframes rot { 0%,55% { transform: rotate(0); } 75%,100% { transform: rotate(90deg); } }
.rothead { margin: 0; font: 900 clamp(17px, 5vw, 30px)/1.1 var(--arcade);
  letter-spacing: .07em; transform: skewX(-8deg); }
.rotsub  { margin: 0; font-size: clamp(11px, 3vw, 14px); letter-spacing: .2em;
  text-transform: uppercase; color: var(--dim); max-width: 24ch; line-height: 1.6; }
@media (prefers-reduced-motion: reduce) { .rotmark { animation: none; } }

/* ---------------------------------------------------------------- debug
   The instrument (F1 / backtick). Deliberately not reachable from any player
   control: it has no button, no menu entry and no touch target, and the keys
   are absent from KEYMAP. */
#dbg{
  position:fixed; inset:auto 0 0 0; z-index:60; pointer-events:none;
  display:flex; gap:14px; align-items:flex-end; padding:10px 12px;
  font:11px/1.35 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  color:#d8e4ff; text-shadow:0 1px 2px #000, 0 0 8px #000;
}
#dbg .dcol{ white-space:pre; background:rgba(4,7,16,.62); border:1px solid rgba(140,180,255,.22);
  border-radius:6px; padding:6px 8px; backdrop-filter:blur(2px); }
#dbg .dinp{ margin-left:auto; max-height:46vh; overflow:hidden;
  display:flex; flex-direction:column-reverse; }
