:root {
  --bg: #0a0a16;
  --panel: #14142a;
  --line: #2c2c52;
  --ink: #eceaf6;
  --dim: #a6a3c4;
  --hp: #ffd23f;
  --hp-low: #ff5a3c;
  --trail: #c83a2a;
  --meter: #3fd0ff;
  --accent: #ffd23f;
  --pixel: 'Press Start 2P', ui-monospace, monospace;
  --font: 'Space Grotesk', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 0%, #1c1a3a 0%, var(--bg) 60%) no-repeat, var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  padding: 16px 16px 64px;
  min-height: 100vh;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -60px; background: var(--accent); color: #000; padding: 8px 12px; z-index: 50; }
.skip-link:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }
button {
  background: #1e1e3c; border: 2px solid #4a4a86; border-radius: 4px;
  padding: 8px 16px; cursor: pointer; min-height: 40px;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.quiet { background: transparent; border-color: var(--line); color: var(--dim); }
button.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--dim); text-decoration: underline; }
kbd { font-family: ui-monospace, Menlo, monospace; font-size: 0.85em; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }

main { max-width: 1000px; margin: 0 auto; }

/* ── The cabinet ─────────────────────────────────────────────────────────── */
.cabinet { background: #11112a; border: 2px solid var(--line); border-radius: 12px; padding: 10px; box-shadow: 0 16px 48px #000a; }
.screen-wrap { position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 6px; background: #000; container-type: inline-size; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
.cab-foot { display: flex; gap: 16px; justify-content: flex-end; align-items: center; padding: 8px 4px 0; color: var(--dim); font-size: 0.85rem; flex-wrap: wrap; }

/* ── HUD ─────────────────────────────────────────────────────────────────── */
.hud { position: absolute; inset: 0; pointer-events: none; font-family: var(--pixel); color: #fff; text-shadow: 2px 2px 0 #000; }
.side { position: absolute; top: 3cqw; width: 40%; }
.side.p1 { left: 2.5cqw; }
.side.p2 { right: 2.5cqw; text-align: right; }
.name { font-size: max(8px, 1.8cqw); margin-bottom: 0.6cqw; }
.bar { position: relative; height: 2.6cqw; background: #2a0f12; border: 2px solid #000; box-shadow: 0 0 0 1px #fff4; }
.bar i { position: absolute; top: 0; bottom: 0; }
/* Damage eats in from the middle, toward each fighter's edge. */
.p1 .bar i { left: 0; }
.p2 .bar i { right: 0; }
.bar .trail { background: var(--trail); transition: width 0.6s ease-in 0.3s; }
.bar .fill { background: var(--hp); }
.bar .fill.low { background: var(--hp-low); }
.pips { margin-top: 0.6cqw; display: flex; gap: 0.6cqw; }
.p2 .pips { justify-content: flex-end; }
.pips span { width: 1.4cqw; height: 1.4cqw; border: 2px solid #000; background: #333; transform: rotate(45deg); }
.pips span.on { background: var(--accent); }
.clock { position: absolute; top: 2.4cqw; left: 50%; transform: translateX(-50%); font-size: max(12px, 3.6cqw); }
.meter { position: absolute; bottom: 2.5cqw; width: 26%; height: 1.6cqw; background: #0a1a2a; border: 2px solid #000; }
.meter.m1 { left: 2.5cqw; }
.meter.m2 { right: 2.5cqw; }
.meter i { position: absolute; top: 0; bottom: 0; left: 0; background: var(--meter); }
.meter.m2 i { left: auto; right: 0; }
.meter b { position: absolute; top: -2.4cqw; font-size: max(7px, 1.2cqw); font-weight: 400; color: var(--meter); opacity: 0; }
.meter.m2 b { right: 0; }
.meter.full b { opacity: 1; animation: blink 0.5s steps(2) infinite; }
.meter.full i { background: #fff; box-shadow: 0 0 8px var(--meter); }
@keyframes blink { 50% { opacity: 0.2; } }
.combo { position: absolute; top: 13cqw; font-size: max(10px, 2.4cqw); color: var(--accent); opacity: 0; transition: opacity 0.2s; }
.combo.c1 { left: 3cqw; }
.combo.c2 { right: 3cqw; }
.combo.on { opacity: 1; }
.call { position: absolute; left: 0; right: 0; top: 38%; text-align: center; font-size: max(18px, 6cqw); color: #fff; opacity: 0; transform: scale(0.8); transition: opacity 0.15s, transform 0.15s; }
.call.on { opacity: 1; transform: scale(1); }
.call small { display: block; font-size: 0.35em; margin-top: 1.2cqw; color: var(--accent); }
.score { position: absolute; top: 8.6cqw; left: 50%; transform: translateX(-50%); font-size: max(7px, 1.3cqw); color: var(--dim); }

/* ── Screens over the game ───────────────────────────────────────────────── */
.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2cqw; padding: 3cqw; text-align: center; background: #05051099;
}
.title-screen { background: linear-gradient(#05051055, #050510ee); }
.logo { font-family: var(--pixel); font-size: max(28px, 9cqw); margin: 0; color: #f2efe6; letter-spacing: 0.04em;
  text-shadow: 0.5cqw 0.5cqw 0 #8a5a2a, 1cqw 1cqw 0 #3a2a1a; }
.sub { margin: 0; color: var(--dim); font-size: max(12px, 1.8cqw); }
.press { margin: 0; color: var(--accent); font-family: var(--pixel); font-size: max(8px, 1.3cqw); }
.head { font-family: var(--pixel); font-size: max(14px, 3cqw); margin: 0; text-shadow: 2px 2px 0 #000; }
.menu { display: flex; flex-direction: column; gap: 1cqw; min-width: min(320px, 70%); }
.menu button { font-family: var(--pixel); font-size: max(9px, 1.5cqw); padding: 1.2cqw 2cqw; }
.menu button small { display: block; font-family: var(--font); font-size: 0.8em; color: var(--dim); margin-top: 4px; }
.row { display: flex; gap: 1.4cqw; flex-wrap: wrap; justify-content: center; align-items: center; }
.row label { display: inline-flex; flex-direction: column; gap: 4px; font-size: max(11px, 1.4cqw); color: var(--dim); text-align: left; }
.row select { background: #1e1e3c; border: 2px solid #4a4a86; border-radius: 4px; padding: 6px 8px; min-height: 38px; }

.select-screen { justify-content: flex-start; padding-top: 2.4cqw; gap: 1.4cqw; overflow: auto; background: #050510cc; }
.roster { display: flex; gap: 0.9cqw; flex-wrap: wrap; justify-content: center; }
.roster button { padding: 0.5cqw; min-height: 0; background: #12122a; display: flex; flex-direction: column; align-items: center; gap: 0.4cqw; }
.roster canvas { width: max(48px, 9.4cqw); aspect-ratio: 1; image-rendering: pixelated; display: block; background: #1a1a38; }
.roster span { font-family: var(--pixel); font-size: max(7px, 1.1cqw); }
.roster button[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.bio { max-width: 60ch; font-size: max(12px, 1.6cqw); min-height: 3.2em; background: #0b0b1ce6; border: 1px solid var(--line); border-radius: 6px; padding: 0.6cqw 1.6cqw; }
.bio p { margin: 0.3em 0; }
.bio b { color: var(--accent); }

.vs-screen { flex-direction: row; gap: 6cqw; background: linear-gradient(90deg, #2a0f3add, #05051088 50%, #0f2a3add); }
.vs { font-family: var(--pixel); font-size: max(24px, 7cqw); color: var(--accent); text-shadow: 3px 3px 0 #000; }
.vs-a, .vs-b { font-family: var(--pixel); font-size: max(10px, 2cqw); display: flex; flex-direction: column; align-items: center; gap: 1cqw; }
.vs-a canvas, .vs-b canvas { width: max(96px, 18cqw); aspect-ratio: 1; image-rendering: pixelated; }
.vs-stage { position: absolute; bottom: 4cqw; margin: 0; color: var(--dim); }

.online-screen { background: #050510dd; }
.on-panel { display: flex; flex-direction: column; align-items: center; gap: 1.6cqw; max-width: 60ch; }
.note { margin: 0; font-size: max(12px, 1.5cqw); color: var(--dim); background: #0b0b1ce6; border: 1px solid var(--line); border-radius: 6px; padding: 0.8cqw 1.6cqw; }
.on-join { gap: 8px; }
.on-join label { flex-direction: row; align-items: center; color: var(--dim); }
.on-join input { width: 6em; text-transform: uppercase; text-align: center; font-family: var(--pixel); background: #0d0d22; border: 2px solid #4a4a86; border-radius: 4px; padding: 6px; min-height: 40px; }
.on-status { margin: 0; font-size: max(13px, 1.8cqw); }
.on-room { margin: 0; font-family: var(--pixel); font-size: max(22px, 6cqw); color: var(--accent); letter-spacing: 0.2em; text-shadow: 3px 3px 0 #000; }
.select-status { margin: 0; color: var(--accent); font-size: max(12px, 1.5cqw); }
.net { position: absolute; bottom: 2.6cqw; left: 50%; transform: translateX(-50%); font-size: max(7px, 1.1cqw); color: var(--dim); }
.judge-says {
  position: absolute; left: 50%; top: 10.4cqw; transform: translateX(-50%);
  max-width: 70%; padding: 0.6cqw 1.4cqw; border-radius: 4px;
  background: #0b0b1ce6; border: 2px solid #c23a2c; color: #fff;
  font-family: var(--font); font-size: max(11px, 1.6cqw); text-shadow: none; white-space: nowrap;
  opacity: 0; transition: opacity 0.2s;
}
.judge-says.on { opacity: 1; }
.judge-says b { font-family: var(--pixel); font-size: 0.7em; color: #ffb3a8; margin-right: 0.6em; font-weight: 400; }
.result-score { font-family: var(--pixel); font-size: max(10px, 1.8cqw); color: var(--accent); white-space: pre-line; line-height: 1.8; }
.result-line { margin: 0; max-width: 50ch; font-size: max(12px, 1.7cqw); }
.initials { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; align-items: center; }
.initials input { width: 5em; text-transform: uppercase; text-align: center; font-family: var(--pixel); background: #0d0d22; border: 2px solid #4a4a86; border-radius: 4px; padding: 6px; min-height: 40px; }
.form-msg { width: 100%; margin: 0; min-height: 1.4em; color: var(--dim); }

.howto { max-width: 66ch; text-align: left; font-size: max(12px, 1.55cqw); background: #0b0b1ccc; padding: 1.5cqw 2.5cqw; border-radius: 6px; overflow: auto; }
.howto p { margin: 0.6em 0; }
.howto-screen { justify-content: flex-start; overflow: auto; }

/* ── Touch pad ───────────────────────────────────────────────────────────── */
/* On a touch screen: a control deck under the screen, or over it when the
   phone's turned sideways and there's no room underneath. */
.cabinet { position: relative; }
.pad { display: none; justify-content: space-between; align-items: center; padding: 14px 10px 6px; touch-action: none; user-select: none; -webkit-user-select: none; }
.pad.on { display: flex; }
.stick { width: 130px; aspect-ratio: 1; border-radius: 50%; background: #ffffff10; border: 2px solid #ffffff33; display: grid; place-items: center; touch-action: none; }
.knob { width: 40%; aspect-ratio: 1; border-radius: 50%; background: #ffffff44; }
.btns { display: grid; grid-template-columns: repeat(3, auto); gap: 12px; touch-action: none; }
.btns button { width: 62px; aspect-ratio: 1; border-radius: 50%; min-height: 0; padding: 0; font-family: var(--pixel); font-size: 14px; background: #ffffff14; border-color: #ffffff44; }
@media (orientation: landscape) and (max-height: 520px) {
  body { padding-top: 4px; }
  main { max-width: calc((100svh - 40px) * 16 / 9); }
  .cabinet { padding: 4px; }
  .pad.on { position: absolute; left: 14px; right: 14px; bottom: 34px; padding: 0; pointer-events: none; }
  .pad .stick, .pad .btns { pointer-events: auto; opacity: 0.75; }
}
.btns button.down { background: #ffd23f66; }

/* ── Below the cabinet ───────────────────────────────────────────────────── */
.board, .about { margin-top: 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; }
.board h2, .about h2 { font-family: var(--pixel); font-size: 0.95rem; margin: 0 0 12px; color: var(--accent); }
.board-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.board-tabs [role="tab"] { min-height: 36px; padding: 4px 12px; background: transparent; border-color: var(--line); color: var(--dim); }
.board-tabs [aria-selected="true"] { color: #fff; border-color: var(--accent); }
.board-list { margin: 0; padding-left: 1.8em; font-family: ui-monospace, Menlo, monospace; }
.board-list li { padding: 2px 0; }
.board-list li.me { color: var(--accent); }
.board-list li.empty { list-style: none; margin-left: -1.8em; color: var(--dim); font-family: var(--font); }
.about p { margin: 0 0 12px; color: var(--dim); }
.cast { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.cast li { background: #0f0f24; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.cast b { display: block; }
.cast span { color: var(--dim); font-size: 0.9rem; }
.foot { max-width: 1000px; margin: 24px auto 0; color: var(--dim); font-size: 0.9rem; }
.foot a { color: var(--dim); }
.leave { position: fixed; right: 16px; bottom: 16px; background: #0a0a16e6; color: var(--ink); text-decoration: none; border: 1px solid #4a4a86; border-radius: 999px; padding: 8px 16px; font-size: 0.9rem; z-index: 5; }
.leave:hover { border-color: var(--accent); }
.noscript { text-align: center; color: var(--dim); }

@media (max-width: 600px) {
  body { padding: 8px 8px 64px; }
  .cabinet { padding: 4px; border-radius: 8px; }
  .leave { position: static; display: inline-block; margin-top: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .bar .trail, .call, .combo, .judge-says { transition: none; }
  .meter.full b { animation: none; }
}

/* #card: the share image, 1200 × 630, just the screen. */
body.card { padding: 0; overflow: hidden; background: #000; }
body.card > :not(main), body.card main > :not(.cabinet), body.card .cab-foot { display: none !important; }
body.card main { max-width: none; }
body.card .cabinet { padding: 0; border: 0; border-radius: 0; box-shadow: none; }
body.card .screen-wrap { aspect-ratio: auto; height: 100vh; border-radius: 0; }
body.card #game { object-fit: cover; }
