/* CounterType: Terminal Arcade, full screen.
   Palette: THEME.ui in js/config.js (main.js writes it onto :root at start; the values below are the same).
   Layout: the arena canvas fills the window. #ui floats over it and is designed at 1366 x 768, then
   scaled to the window by fitUi() in main.js, so every px value below is a design px.
   Type scale: 12 / 16 / 24 / 32 / 64 px, weights 400 and 700. Spacing: 8 px grid (4 px only inside bars).
   Panels: one radius (--r, 4 px) and one border (1 px solid --line). */

* { box-sizing: border-box; }

:root {
  --bg: #060a18;
  --surface: #0b1129;
  --raised: #121a3a;
  --line: #2a3a73;
  --text: #e8edff;
  --dim: #8d9ac8;
  --phosphor: #4dff9a;
  --magenta: #ff3ea5;
  --gold: #ffc53d;
  --danger: #ff4d5e;
  --warn: #ff8a3d;
  --info: #7ce3ff;
  --track: #18224a;
  --you: #f1f3f8;          /* your identity color (set by main.js from the Fighter screen) */
  --you-letters: #4ade80;  /* your correct letters */
  --foe: #e8737d;          /* the bot's identity color for this match */
  --r: 4px;
  --border: 1px solid var(--line);
  --font: "Cascadia Mono", Consolas, "SF Mono", Menlo, "DejaVu Sans Mono", "Courier New", monospace;
  --t12: 12px; --t16: 16px; --t24: 24px; --t32: 32px; --t64: 64px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  /* A dark outline for text that sits over the scenery. */
  --outline: 0 2px 0 rgba(var(--outline-rgb), 0.95), 0 -1px 0 rgba(var(--outline-rgb), 0.95), 1px 0 0 rgba(var(--outline-rgb), 0.95), -1px 0 0 rgba(var(--outline-rgb), 0.95), 0 0 8px rgba(var(--outline-rgb), 0.85);
  --panel-bg: rgba(11, 17, 41, 0.9);
  --hud-bg: var(--panel-bg);   /* HUD panels only: main.js sets it from the HUD opacity setting */
  --bg-rgb: 6, 10, 24; --surface-rgb: 11, 17, 41; --raised-rgb: 18, 26, 58; --line-rgb: 42, 58, 115; --text-rgb: 232, 237, 255;
  --phosphor-rgb: 77, 255, 154; --magenta-rgb: 255, 62, 165; --gold-rgb: 255, 197, 61; --outline-rgb: 2, 4, 12;
  --ult-dim: #a8862a; --extra: #a8323e;
}

html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--t16);
  user-select: none; -webkit-user-select: none;
}

/* The arena: edge to edge, no frame. main.js sizes the backing store to the window times the pixel ratio. */
#arena { position: fixed; left: 0; top: 0; width: 100vw; height: 100vh; display: block; background: var(--bg); }

/* Everything over the arena. main.js sets its width, height and scale (fitUi). */
#ui { position: fixed; left: 0; top: 0; width: 1366px; height: 768px; transform-origin: 0 0; pointer-events: none; }
#ui button, #overlay, #modal, #typing-box { pointer-events: auto; }
#ui button { font-family: var(--font); color: var(--text); }
#ui .btn.primary, #ui .mbtn.primary { color: var(--bg); }

/* ---------- Buttons: one shape, tactile states ---------- */
.btn, .mbtn, .icon-btn, .key, .seg, .fighter-chip, .pick {
  cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: transform 0.15s var(--ease), border-color 0.15s var(--ease), background 0.15s var(--ease), filter 0.15s var(--ease);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 24px;
  font-size: var(--t16); font-weight: 700; letter-spacing: 2px; text-transform: uppercase; white-space: nowrap;
  background: var(--surface); border: var(--border); border-radius: var(--r);
}
.btn:hover, .mbtn:hover, .icon-btn:hover, .key:hover, .seg:hover, .fighter-chip:hover { border-color: var(--dim); background: var(--raised); }
.btn:active, .mbtn:active, .icon-btn:active, .key:active, .seg:active, .fighter-chip:active, .pick:active { transform: translateY(1px) scale(0.98); }
.btn.primary, .mbtn.primary { background: var(--phosphor); border-color: var(--phosphor); color: var(--bg); }
.btn.primary:hover, .mbtn.primary:hover { background: var(--phosphor); filter: brightness(1.12); }
.btn.primary kbd, .mbtn.primary kbd { background: rgba(var(--bg-rgb), 0.85); border-color: rgba(var(--bg-rgb), 0.85); color: var(--phosphor); }
.btn-row { display: flex; gap: 16px; justify-content: center; }

kbd {
  display: inline-block; min-width: 24px; padding: 0 8px;
  font: 700 var(--t12)/24px var(--font); text-align: center; letter-spacing: 0;
  color: var(--text); background: var(--raised); border: var(--border); border-radius: var(--r);
}

.icon-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 8px;
  background: var(--panel-bg); border: var(--border); border-radius: var(--r); color: var(--text);
}
.icon-btn svg { width: 24px; height: 24px; display: block; }
.icon-btn.on { border-color: var(--magenta); }

/* ---------- Top bar (menus only) ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 64px; padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(rgba(var(--bg-rgb), 0.85), rgba(var(--bg-rgb), 0));
  z-index: 3; /* above the menu overlay, under the modals */
}
#ui:not(.idle) #topbar { display: none; }
.fighter-chip {
  display: inline-flex; align-items: center; gap: 12px; height: 40px; padding: 0 16px 0 8px;
  background: var(--panel-bg); border: var(--border); border-radius: var(--r);
  font-size: var(--t12); letter-spacing: 1px; color: var(--dim);
}
.chip-swatch { width: 24px; height: 24px; border-radius: var(--r); background: var(--you); box-shadow: 0 0 0 1px var(--line); }
.chip-name { font-size: var(--t16); font-weight: 700; letter-spacing: 2px; color: var(--you); }
.chip-weapon b { color: var(--text); }
.icons { display: flex; gap: 8px; }

/* ---------- In-fight HUD: at the edges, the center stays clear ---------- */
#hud { position: absolute; inset: 0; }
#ui.idle #hud { visibility: hidden; }
#ui.idle #pause-btn { display: none; }
.side {
  --id: var(--you);
  position: absolute; bottom: 16px; width: 432px; padding: 12px 16px;
  background: var(--hud-bg); border: var(--border); border-radius: var(--r);
  border-bottom: 4px solid var(--id);
}
.side.left { left: 16px; }
.side.right { right: 16px; --id: var(--foe); }

/* Top: the HP plates, each from its screen edge to the clock. */
.hptop { --id: var(--you); position: absolute; top: 12px; width: calc(50% - 192px); padding: 8px 16px 10px; background: var(--hud-bg); border: var(--border); border-radius: var(--r); border-top: 4px solid var(--id); }
.hptop.left { left: 16px; }
.hptop.right { right: 16px; --id: var(--foe); }
.nameplate { display: flex; justify-content: space-between; align-items: flex-end; }
.right .nameplate { flex-direction: row-reverse; }
.who { display: flex; flex-direction: column; padding-left: 8px; border-left: 4px solid var(--id); }
.right .who { padding: 0 8px 0 0; border-left: 0; border-right: 4px solid var(--id); text-align: right; }
.pname { font-size: var(--t16); font-weight: 700; line-height: 16px; letter-spacing: 2px; color: var(--id); }
.pweapon { margin-top: 4px; font-size: var(--t12); line-height: 12px; letter-spacing: 1px; color: var(--dim); }
.hpnum { font-size: var(--t24); font-weight: 700; line-height: 24px; font-variant-numeric: tabular-nums; }

.hpbar { position: relative; margin-top: 6px; height: 28px; background: var(--track); border: var(--border); overflow: hidden; transform: skewX(-20deg); }
.right .hpbar { transform: scaleX(-1) skewX(-20deg); }
.hpghost { position: absolute; top: 0; left: 0; height: 100%; width: 100%; background: var(--text); opacity: 0.45; }
.hpfill { position: relative; height: 100%; width: 100%; background: var(--phosphor); transition: width 0.1s linear; }
.right .hpfill { background: var(--foe); }
.hpfill.low, .right .hpfill.low { background: var(--warn); }
.hpfill.crit, .right .hpfill.crit { background: var(--danger); }

.stats { position: relative; margin-top: 8px; display: flex; align-items: flex-end; gap: 16px; height: 32px; }
.side.right .stats { flex-direction: row-reverse; }
.stat { display: flex; align-items: baseline; gap: 4px; font-size: var(--t12); letter-spacing: 1px; color: var(--dim); white-space: nowrap; }
.stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.wpm b { font-size: var(--t32); line-height: 32px; }
.power { position: static; } /* the COUNTER badge is placed on the panel's top edge */
.power b { font-size: var(--t24); line-height: 24px; }
.stun { align-self: center; font-size: var(--t16); font-weight: 700; letter-spacing: 2px; color: var(--danger); }
/* COUNTER badge: sits on the panel's top edge and takes no space in the stats row. */
.healtag { margin-left: 8px; font-size: var(--t12); line-height: 24px; font-weight: 700; letter-spacing: 1px; color: var(--phosphor); font-variant-numeric: tabular-nums; }
.countertag { position: absolute; top: -11px; left: 24px; visibility: hidden; padding: 0 8px; border-radius: var(--r); font-size: var(--t12); line-height: 20px; letter-spacing: 1px; font-weight: 700; color: var(--bg); background: var(--magenta); white-space: nowrap; }
.side.right .countertag { left: auto; right: 24px; }
.countertag.on { visibility: visible; }

.meters { margin-top: 8px; display: flex; align-items: center; gap: 16px; height: 16px; }
.side.right .meters { flex-direction: row-reverse; }
.combo { display: flex; align-items: center; gap: 8px; font-size: var(--t12); color: var(--dim); }
.side.right .combo { flex-direction: row-reverse; }
.combo b { display: inline-block; min-width: 32px; font-size: var(--t16); color: var(--id); font-variant-numeric: tabular-nums; }
.combo.pop b { animation: pop 0.25s var(--ease); }
@keyframes pop { from { transform: scale(1.5); } to { transform: scale(1); } }
.combo.broke b { animation: broke 0.4s ease-out; }
@keyframes broke { 0% { color: var(--danger); transform: translateX(-4px); } 25% { transform: translateX(4px); } 50% { transform: translateX(-2px); } 100% { transform: none; } }
.pips { display: flex; gap: 4px; }
.side.right .pips { flex-direction: row-reverse; }
.pip { width: 16px; height: 12px; background: var(--track); transform: skewX(-20deg); }
.pip.on { background: var(--id); }
.pip.half { background: linear-gradient(90deg, var(--id) 50%, var(--track) 50%); } /* the typo rule takes half a word of streak at a time */

.ultrow { flex: 1; display: flex; align-items: center; gap: 8px; font-size: var(--t12); letter-spacing: 1px; color: var(--dim); }
.side.right .ultrow { flex-direction: row-reverse; }
.ultbar { flex: 1; height: 12px; background: var(--track); overflow: hidden; transform: skewX(-20deg); }
.side.right .ultbar { transform: scaleX(-1) skewX(-20deg); }
.ultfill { height: 100%; width: 0; background: var(--gold); opacity: 0.55; }
.ultfill.ready { opacity: 1; }
.ulttext { min-width: 128px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.side.right .ulttext { text-align: right; }
.ulttext.ready { color: var(--gold); font-weight: 700; animation: pulse 0.5s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: 0.6; } to { opacity: 1; } }

/* Top center: the fight clock and your edge, a tug-of-war rope. The knot slides toward whoever is winning. */
#center {
  position: absolute; top: 12px; left: 50%; width: 352px; margin-left: -176px; padding: 6px 16px 8px;
  text-align: center; background: var(--hud-bg); border: var(--border); border-radius: var(--r);
}
#timer { font-size: var(--t32); font-weight: 700; line-height: 32px; text-shadow: var(--outline); letter-spacing: 2px; font-variant-numeric: tabular-nums; }
#tug { position: relative; height: 24px; margin-top: 4px; }
#tug::before { content: ""; position: absolute; left: 0; right: 0; top: 9px; height: 6px; background: var(--track); }
#tug-mid { position: absolute; left: 50%; top: 2px; width: 2px; height: 20px; margin-left: -1px; background: var(--line); }
#tug-fill { position: absolute; top: 9px; height: 6px; left: 50%; width: 0; background: var(--dim); }
#tug-knot { position: absolute; top: 2px; left: 50%; width: 12px; height: 20px; margin-left: -6px; background: var(--text); transform: skewX(-20deg); transition: left 0.15s linear; }
#tug.lead #tug-fill, #tug.lead #tug-knot { background: var(--you); }
#tug.trail #tug-fill, #tug.trail #tug-knot { background: var(--foe); }
#tug-row { display: flex; justify-content: center; align-items: baseline; gap: 8px; margin-top: 4px; }
#tug-val { min-width: 80px; font-size: var(--t24); font-weight: 700; line-height: 24px; font-variant-numeric: tabular-nums; }
#tug-label, #tug-unit { font-size: var(--t12); letter-spacing: 2px; color: var(--dim); }

/* Pause sits inside the clock panel, at the right end of the edge row, so it never crowds the HP numbers
   or covers the word plates. */
#pause-btn { position: absolute; top: 98px; left: calc(50% + 176px - 58px); height: 28px; padding: 0 6px; gap: 4px; }
#pause-btn svg { width: 16px; height: 16px; }
#pause-btn kbd { min-width: 0; padding: 0 4px; line-height: 18px; }

#countdown {
  position: absolute; left: 0; right: 0; bottom: 48px;
  text-align: center; font-size: var(--t64); line-height: 64px; font-weight: 700; letter-spacing: 4px; color: var(--text);
  pointer-events: none; text-shadow: 3px 0 0 var(--magenta), -3px 0 0 rgba(var(--phosphor-rgb), 0.6), var(--outline);
}
#ui.classic #countdown { bottom: 216px; }

/* ---------- Typing box (Classic view, Monkeytype style), bottom center between the panels ---------- */
#typing-box { display: none; position: absolute; bottom: 16px; left: 50%; width: 438px; margin-left: -219px; padding: 16px 24px; }
#ui.classic:not(.idle) #typing-box { display: block; }
#words { height: 138px; overflow: hidden; position: relative; font-size: 28px; }
#words-inner { position: relative; transition: transform 0.12s ease-out; }
.word { display: inline-block; line-height: 46px; margin-right: 14px; vertical-align: top; color: var(--dim); }
.word .ok { color: var(--text); }
.word .bad { color: var(--danger); }
.word .extra { color: var(--extra); }
.word.wrong { border-bottom: 2px solid var(--danger); line-height: 44px; }
.word.ult { color: var(--ult-dim); }
.word.ult::before { content: "ULT "; font-size: var(--t12); color: var(--gold); letter-spacing: 2px; vertical-align: top; }
.word.ult .ok { color: var(--gold); }
.word.ult .bad { color: var(--danger); }
#caret {
  position: absolute;
  width: 3px; height: 34px;
  background: var(--magenta);
  transition: left 0.07s linear, top 0.1s ease-out;
  animation: blink 1s steps(2, start) infinite;
}
#caret.typing { animation: none; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Over-head view: the word plates are on the canvas; a thin progress line sits at the bottom ---------- */
#word-progress { display: none; position: absolute; bottom: 24px; left: 50%; width: 400px; margin-left: -200px; height: 6px; background: var(--track); border: var(--border); overflow: hidden; }
#word-progress-fill { height: 100%; width: 0; background: var(--you-letters); transition: width 0.07s linear; }
#word-progress-fill.ult { background: var(--gold); }
#ui:not(.classic):not(.idle) #word-progress { display: block; }

/* ---------- Menus: panels floating over the live arena ---------- */
.panel { background: var(--panel-bg); border: var(--border); border-radius: var(--r); }
#overlay {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  padding: 72px 24px 16px;
  background: rgba(var(--bg-rgb), 0.72) repeating-linear-gradient(0deg, var(--scan, rgba(0, 0, 0, 0.18)) 0 1px, transparent 1px 3px);
}
#overlay.hidden { display: none; }
/* Title: keep the middle of the arena clear for the sparring loop; darken only the two sides. */
#overlay[data-screen="title"] {
  justify-content: space-between;
  background: linear-gradient(90deg, rgba(var(--bg-rgb), 0.8) 0, rgba(var(--bg-rgb), 0.1) 32%, rgba(var(--bg-rgb), 0.1) 66%, rgba(var(--bg-rgb), 0.8) 100%);
}
.screen { display: none; }
#overlay[data-screen="title"] #scr-title,
#overlay[data-screen="howto"] #scr-howto,
#overlay[data-screen="online"] #scr-online,
#overlay[data-screen="fighter"] #scr-fighter,
#overlay[data-screen="creator"] #scr-creator,
#overlay[data-screen="result"] #scr-result,
#overlay[data-screen="stats"] #scr-stats { display: grid; }
.screen-title { margin: 0; font-size: var(--t24); font-weight: 700; letter-spacing: 4px; text-transform: uppercase; }
.row-label { font-size: var(--t12); letter-spacing: 2px; color: var(--dim); text-transform: uppercase; padding-left: 8px; border-left: 4px solid transparent; }
.row-label.active { color: var(--text); border-left-color: var(--magenta); }

/* The key line: every chip is a button. */
#keyline { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; font-size: var(--t12); color: var(--dim); }
.key {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; white-space: nowrap;
  font-size: var(--t12); font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--dim); background: var(--panel-bg); border: var(--border); border-radius: var(--r);
}
.key b { color: var(--text); font-weight: 400; }

/* Selectable cards: bots and fighters. Selected = magenta border on a raised panel. */
.pick { border: var(--border); border-radius: var(--r); background: var(--surface); }
.pick:hover { border-color: var(--dim); background: var(--raised); }
.pick.sel { border-color: var(--magenta); background: var(--raised); box-shadow: inset 4px 0 0 var(--magenta); }

/* Title: big stacked buttons on the left, opponents on the right, the sparring loop in the middle. */
#scr-title { width: 100%; flex: 1; grid-template-columns: 352px 1fr 432px; align-items: center; gap: 24px; min-height: 0; }
#title-left { display: grid; gap: 24px; align-content: center; }
.logo { margin: 0; font-size: var(--t64); line-height: 64px; font-weight: 700; letter-spacing: 8px; text-shadow: var(--outline); }
.logo span { display: block; }
.logo .l1 { color: var(--text); text-shadow: 4px 0 0 var(--magenta), var(--outline); }
.logo .l2 { color: var(--phosphor); text-shadow: 4px 0 0 rgba(var(--magenta-rgb), 0.55), var(--outline); }
#title-menu { display: grid; gap: 8px; }
.mbtn {
  display: flex; justify-content: space-between; align-items: center; height: 56px; padding: 0 16px 0 24px;
  font-size: var(--t24); font-weight: 700; letter-spacing: 4px; text-transform: uppercase; text-align: left;
  background: var(--panel-bg); border: var(--border); border-radius: var(--r);
}
.mbtn:hover { transform: translateX(4px); }
.mbtn.primary { height: 96px; font-size: var(--t64); letter-spacing: 8px; }
.mbtn .sub { display: block; font-size: var(--t12); letter-spacing: 1px; font-weight: 400; text-transform: none; }
.mbtn.primary .sub { color: rgba(var(--bg-rgb), 0.8); }

#title-left { grid-column: 1; }
#title-bots { grid-column: 3; padding: 16px; display: grid; gap: 8px; align-self: center; max-height: calc(100% - 16px); overflow-y: auto; }
.card-label { display: flex; justify-content: space-between; font-size: var(--t12); letter-spacing: 2px; color: var(--dim); text-transform: uppercase; }
.bot-opt {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  min-height: 56px; padding: 6px 12px; text-align: left; color: var(--dim); font-size: var(--t12);
}
.bot-opt .bname { display: block; font-size: var(--t16); font-weight: 700; color: var(--text); letter-spacing: 1px; }
.bot-opt .bname i { margin-left: 12px; font-style: normal; font-size: var(--t12); font-weight: 400; letter-spacing: 0; color: var(--dim); }
.bot-opt .bstyle { display: block; margin-top: 2px; }
.bot-opt .beat { text-align: right; line-height: 1.2; }
.bot-opt .beat b { display: block; font-size: var(--t24); color: var(--text); font-variant-numeric: tabular-nums; }
.bot-opt.match .bname { color: var(--info); }

/* How to play */
#scr-howto { width: 960px; max-height: 640px; overflow-y: auto; padding: 24px; grid-template-columns: 1fr 1fr; gap: 16px 32px; align-content: start; }
#scr-howto .screen-title, #scr-howto .btn-row, #scr-howto .lead, #scr-howto .cols, #scr-howto .legend { grid-column: 1 / -1; }
#scr-howto .lead { margin: 0; font-size: var(--t16); line-height: 1.5; color: var(--dim); max-width: 80ch; }
#scr-howto .lead b { color: var(--text); }
#scr-howto .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 32px; }
.group h3 { margin: 0 0 8px; font-size: var(--t16); font-weight: 700; color: var(--text); padding-left: 8px; border-left: 4px solid var(--magenta); }
.group p { margin: 0 0 8px; font-size: var(--t12); line-height: 1.6; color: var(--dim); max-width: 60ch; }
.group p b { color: var(--text); }
.group.ult h3 { border-left-color: var(--gold); }
.legend { padding-top: 12px; border-top: var(--border); }
.legend h3 { margin: 0 0 8px; font-size: var(--t16); font-weight: 700; }
.legend dl { margin: 0; display: grid; grid-template-columns: 160px 1fr; gap: 4px 16px; font-size: var(--t12); line-height: 1.6; }
.legend dt { color: var(--text); font-weight: 700; letter-spacing: 1px; }
.legend dd { margin: 0; color: var(--dim); }

/* Online private room */
#scr-online { width: 560px; padding: 20px 24px; gap: 12px; align-content: start; grid-auto-rows: max-content; }
#online-status { min-height: 24px; font-size: var(--t16); line-height: 1.5; color: var(--text); }
#online-room {
  display: grid; gap: 8px; padding: 10px 16px;
  background: rgba(var(--surface-rgb), 0.45); border-left: 4px solid var(--info); border-radius: var(--r);
  font-size: var(--t12); color: var(--dim);
}
#online-room b { display: block; font-size: var(--t32); letter-spacing: 8px; color: var(--phosphor); }
#online-room code { color: var(--text); overflow-wrap: anywhere; }
/* The room code and invite link can be selected with the mouse and copied; the rest of the game stays unselectable. */
.selectable { user-select: text; -webkit-user-select: text; cursor: text; }
.selectable::selection { background: var(--magenta); color: var(--bg); }
.copy-row { display: flex; flex-wrap: wrap; gap: 8px; }
.online-join { display: flex; gap: 8px; align-items: stretch; }
.online-join .seg { height: 48px; min-width: 88px; }
.online-join input {
  flex: 1; min-width: 0; user-select: text; -webkit-user-select: text; height: 48px; padding: 0 16px; color: var(--text); background: var(--surface);
  border: var(--border); border-radius: var(--r); font: 700 var(--t24) var(--font);
  letter-spacing: 6px; text-transform: uppercase; outline: none;
}
.online-join input:focus { border-color: var(--magenta); box-shadow: inset 4px 0 0 var(--magenta); }
#scr-online .btn-row { flex-wrap: wrap; justify-content: flex-start; }

/* Loadout: your fighter large on the left, the pickers on the right. */
#scr-fighter { grid-template-columns: 448px 544px; gap: 16px; align-items: stretch; }
#loadout-stage { position: relative; padding: 0; overflow: hidden; display: grid; background: var(--surface); }
#fighter-preview { width: 446px; height: 520px; display: block; }
#loadout-tag { position: absolute; left: 16px; right: 16px; bottom: 16px; display: flex; justify-content: space-between; align-items: baseline; text-shadow: var(--outline); }
#fighter-name { font-size: var(--t24); font-weight: 700; letter-spacing: 4px; }
#fighter-wname { font-size: var(--t16); font-weight: 700; letter-spacing: 2px; }
#loadout-side { padding: 24px; display: grid; gap: 16px; align-content: start; }
#chars { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 1fr; gap: 8px; }
.char-new { border-style: dashed; }
.char-new b { color: var(--green, var(--text)); }
.char { position: relative; padding: 8px 12px; text-align: left; display: grid; gap: 2px; align-content: start; color: var(--dim); }
.char b { font-size: var(--t12); letter-spacing: 1px; color: var(--text); }
.char span { font-size: var(--t12); color: var(--dim); }
.char.saved::after { content: ""; position: absolute; right: 8px; top: 8px; width: 4px; height: 4px; background: var(--dim); }
#fighter-info { display: grid; gap: 4px; font-size: var(--t12); line-height: 1.5; color: var(--dim); padding-left: 8px; min-height: 40px; }
#fighter-btns { justify-content: flex-end; margin-top: 8px; }

/* Result screen */
#scr-result { width: 704px; gap: 12px; }
#ko-card { padding: 12px 24px 8px; text-align: center; }
#ko-title { font-size: var(--t64); line-height: 64px; font-weight: 700; letter-spacing: 8px; }
#ko-title.win { color: var(--phosphor); text-shadow: 4px 0 0 var(--magenta); }
#ko-title.lose { color: var(--danger); text-shadow: 4px 0 0 rgba(var(--text-rgb), 0.25); }
#ko-sub { margin-top: 4px; font-size: var(--t12); letter-spacing: 2px; color: var(--dim); }
#result-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rcol { padding: 8px 16px; border-top: 4px solid var(--id); }
.rcol h3 { margin: 0 0 8px; font-size: var(--t16); letter-spacing: 2px; color: var(--id); }
.rcol dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; font-size: var(--t12); }
.rcol dt { color: var(--dim); }
.rcol dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
#wpm-chart { padding: 8px 16px; }
#wpm-chart svg { display: block; width: 100%; margin-top: 8px; overflow: visible; }
#wpm-chart svg.speed, .blk svg.speed { height: 64px; }
#wpm-chart svg.hpline { height: 22px; margin-top: 4px; }
#wpm-chart .chart-head { display: flex; justify-content: space-between; font-size: var(--t12); color: var(--dim); }
#wpm-chart .key-i { display: inline-flex; align-items: center; gap: 8px; margin-left: 16px; }
#wpm-chart .key-i i { display: inline-block; width: 16px; height: 2px; }
#result-bots { padding: 8px; display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
#result-bots .card-label { grid-column: 1 / -1; padding-left: 4px; }
.bot-chip { height: 40px; padding: 0 4px; display: grid; place-content: center; text-align: center; font-size: var(--t12); color: var(--dim); line-height: 1.2; }
.bot-chip b { color: var(--text); font-size: var(--t12); letter-spacing: 1px; }

/* ---------- Modals: pause, settings, confirm ---------- */
#modal {
  position: absolute; inset: 0; z-index: 4; display: flex; align-items: center; justify-content: center;
  background: rgba(var(--bg-rgb), 0.88) repeating-linear-gradient(0deg, var(--scan, rgba(0, 0, 0, 0.18)) 0 1px, transparent 1px 3px);
}
#modal.hidden { display: none; }
.modal { display: none; padding: 24px; }
#modal[data-top="pause"] #mod-pause,
#modal[data-top="settings"] #mod-settings,
#modal[data-top="confirm"] #mod-confirm { display: grid; }
#mod-pause { width: 416px; gap: 8px; }
#mod-pause .screen-title { margin-bottom: 8px; }
#mod-pause .mbtn { height: 56px; font-size: var(--t24); }
#mod-pause .mbtn.primary { height: 72px; font-size: var(--t32); }
.modal-note { margin: 8px 0 0; font-size: var(--t12); line-height: 1.6; color: var(--dim); }
#mod-confirm { width: 448px; gap: 16px; }
#mod-confirm p { margin: 0; font-size: var(--t12); line-height: 1.6; color: var(--dim); }

#mod-settings { width: 896px; height: min(672px, calc(100% - 32px)); gap: 16px; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; }
#mod-settings .btn-row { justify-content: flex-end; }
#mod-settings > * { min-width: 0; }
.tabs { display: flex; gap: 2px; border-bottom: var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; flex: 0 0 auto; gap: 6px; height: 44px; padding: 0 8px; margin-bottom: -1px;
  font-size: 14px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--dim);
  background: transparent; border: 1px solid transparent; border-radius: var(--r) var(--r) 0 0; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.sel { color: var(--text); background: var(--raised); border-color: var(--line); border-bottom-color: var(--raised); box-shadow: inset 0 3px 0 var(--magenta); }
.set-rows { display: grid; grid-auto-rows: max-content; gap: 8px; min-height: 0; overflow-y: auto; align-content: start; padding: 0 8px 24px 0;
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 24px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 24px), transparent); }
/* Scroll panels share one thin themed scrollbar, so it is clear when there is more below. */
.set-rows, #scr-howto, #scr-stats, #scr-result { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.set-rows::-webkit-scrollbar, #scr-howto::-webkit-scrollbar, #scr-stats::-webkit-scrollbar, #scr-result::-webkit-scrollbar { width: 8px; }
.set-rows::-webkit-scrollbar-thumb, #scr-howto::-webkit-scrollbar-thumb, #scr-stats::-webkit-scrollbar-thumb, #scr-result::-webkit-scrollbar-thumb { background: var(--line); border-radius: var(--r); }
.set-row {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 16px; min-height: 56px; padding: 8px 12px;
  border-left: 4px solid transparent; border-radius: var(--r); background: rgba(var(--raised-rgb), 0.4);
}
.set-row.focus { border-left-color: var(--magenta); background: var(--raised); }
.set-row .lbl { font-size: var(--t16); font-weight: 700; }
.set-row .lbl { min-width: 0; }
.set-row .hint { display: block; margin-top: 4px; max-width: 54ch; font-size: var(--t12); color: var(--dim); font-weight: 400; }
.segs { display: inline-flex; gap: 4px; }
.seg {
  height: 36px; min-width: 64px; padding: 0 12px; font-size: var(--t12); font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: var(--dim); background: var(--surface); border: var(--border); border-radius: var(--r);
}
.seg.sel { color: var(--bg); background: var(--magenta); border-color: var(--magenta); }
.keys-table { width: 100%; border-collapse: collapse; font-size: var(--t12); color: var(--dim); }
.keys-table td { padding: 6px 8px; border-bottom: 1px solid rgba(var(--line-rgb), 0.5); vertical-align: middle; }
.keys-table td:first-child { width: 160px; color: var(--text); }
.keys-table kbd { margin-right: 4px; }

#toast {
  position: absolute; z-index: 5; left: 50%; bottom: 96px; transform: translateX(-50%); max-width: 640px; padding: 12px 16px;
  font-size: var(--t12); line-height: 1.5; color: var(--text); background: var(--surface); border: 1px solid var(--warn); border-radius: var(--r);
  opacity: 0; transition: opacity 0.2s var(--ease); pointer-events: none;
}
#toast.on { opacity: 1; }

/* ---------- Settings: rows, sliders, theme and custom tabs ---------- */
.set-head { margin-top: 8px; padding-left: 8px; border-left: 4px solid var(--magenta); font-size: var(--t12); font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--text); }
.set-head .tag { margin-left: 8px; color: var(--gold); letter-spacing: 1px; }
.set-note { margin: 0; font-size: var(--t12); line-height: 1.6; color: var(--dim); }
.set-note.inline { flex: 1; }
.rng { display: inline-flex; align-items: center; gap: 12px; }
.rng input[type="range"], .bg-sl input[type="range"] { width: 200px; accent-color: var(--magenta); cursor: pointer; }
.rng output, .bg-sl output { min-width: 64px; text-align: right; font-size: var(--t12); font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }
.seg:disabled { opacity: 0.4; cursor: default; }
.seg.danger:hover { border-color: var(--danger); color: var(--danger); }
.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.preset { display: grid; gap: 4px; padding: 8px; text-align: left; cursor: pointer; background: var(--surface); border: var(--border); border-radius: var(--r); font-family: var(--font); color: var(--text); }
.preset:hover { border-color: var(--dim); background: var(--raised); }
.preset.sel { border-color: var(--magenta); background: var(--raised); }
.preset b { font-size: var(--t12); letter-spacing: 1px; }
.preset .pn { font-size: 11px; line-height: 1.3; color: var(--dim); }
.preset .sw { display: flex; height: 16px; border: var(--border); }
.preset .sw i { flex: 1; }
.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.slot { display: flex; align-items: center; gap: 8px; font-size: var(--t12); color: var(--dim); cursor: pointer; }
.slot input[type="color"] { width: 40px; height: 32px; padding: 0; border: var(--border); border-radius: var(--r); background: var(--surface); cursor: pointer; }
.code-row { display: flex; align-items: center; gap: 8px; }
.code-row input[type="text"], #css-box { flex: 1; min-width: 0; padding: 8px; font: var(--t12)/1.5 var(--font); color: var(--text); background: var(--surface); border: var(--border); border-radius: var(--r); user-select: text; -webkit-user-select: text; }
#css-box { width: 100%; resize: vertical; }
.code-row input[type="text"]:focus, #css-box:focus, .slot input:focus-visible, .rng input:focus-visible { outline: 2px solid var(--magenta); outline-offset: 1px; }
.filebtn { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text); }
.filebtn input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.bg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; align-items: center; }
.bg-label, .bg-sl > span { font-size: var(--t12); color: var(--dim); }
.bg-sl { display: grid; grid-template-columns: 88px 1fr auto; align-items: center; gap: 8px; }
.bg-sl input[type="range"] { width: 100%; }
/* Theme and Custom tabs: the screen behind stays visible, so the panel sits left and lighter. */
#modal.preview { justify-content: flex-start; padding-left: 24px; background: rgba(var(--bg-rgb), 0.15); }
#modal.preview #mod-settings { background: rgba(var(--surface-rgb), 0.94); }

/* ---------- Result extras ---------- */
#result-extra { padding: 8px 16px; }
.extra { margin: 0; display: grid; grid-template-columns: auto auto 1fr; gap: 4px 24px; font-size: var(--t12); }
.extra > div { display: flex; gap: 8px; align-items: baseline; }
.extra .wide { grid-column: 1 / -1; }
.extra dt { color: var(--dim); }
.extra dd { margin: 0; font-weight: 700; }
.chart-empty, .empty { padding: 16px; font-size: var(--t12); color: var(--dim); text-align: center; }
.empty.big { font-size: var(--t16); line-height: 1.6; padding: 48px 24px; }
.key-i { display: inline-flex; align-items: center; gap: 8px; margin-left: 16px; font-size: var(--t12); color: var(--dim); }
.key-i i { display: inline-block; width: 16px; height: 2px; }
.key-i i.dash { height: 0; border-top: 2px dashed currentColor; background: none !important; opacity: 0.7; }
.key-i i.tick { width: 2px; height: 10px; background: var(--danger); }
.key-i i.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--you); }
.hover-wrap { position: relative; }
.hover-wrap .sp { position: relative; }
.ylab { position: absolute; left: 4px; font-size: var(--t12); line-height: 14px; color: var(--dim); pointer-events: none; }
.hover-wrap .cross { display: none; position: absolute; top: 0; bottom: 0; width: 1px; background: var(--dim); pointer-events: none; }
.hover-wrap .tip { display: none; position: absolute; top: -4px; transform: translateY(-100%); padding: 4px 8px; font-size: var(--t12); white-space: nowrap; color: var(--text); background: var(--surface); border: var(--border); border-radius: var(--r); pointer-events: none; z-index: 2; }

/* ---------- Stats page ---------- */
#scr-stats { width: 1120px; max-height: 664px; overflow-y: auto; padding: 24px; gap: 16px; align-content: start; }
.st-head { display: flex; justify-content: space-between; align-items: center; }
.st-head .btn { height: 40px; }
.sub { margin: 0; font-size: var(--t12); color: var(--dim); }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.filters .fl { margin: 0 8px 0 16px; font-size: var(--t12); letter-spacing: 1px; text-transform: uppercase; color: var(--dim); }
.filters .fl:first-child { margin-left: 0; }
.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.tile { display: grid; gap: 2px; padding: 8px 12px; background: rgba(var(--raised-rgb), 0.5); border: var(--border); border-radius: var(--r); }
.tile .tl { font-size: var(--t12); letter-spacing: 1px; text-transform: uppercase; color: var(--dim); }
.tile b { font-size: var(--t24); line-height: 32px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tile .ts { font-size: var(--t12); color: var(--dim); }
.blk { padding: 12px 16px; background: rgba(var(--raised-rgb), 0.35); border: var(--border); border-radius: var(--r); }
.blk h3 { margin: 0 0 8px; font-size: var(--t16); }
.blk h3.mt { margin-top: 16px; }
.blk h4 { margin: 0 0 8px; font-size: var(--t12); letter-spacing: 1px; text-transform: uppercase; color: var(--dim); }
.blk-head, .chart-head, .journey-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 8px; font-size: var(--t12); color: var(--dim); }
.blk-head h3 { margin: 0; color: var(--text); }
.blk-head .segs { flex-wrap: wrap; justify-content: flex-end; }
.blk .chart-head { color: var(--dim); }
.journey-head .gain { font-weight: 700; font-size: var(--t16); }
.gain.up { color: var(--phosphor); }
.gain.down { color: var(--warn); }
.blk svg.journey { display: block; width: 100%; height: 220px; }
.blk svg.hpline { display: block; width: 100%; height: 40px; margin-top: 4px; }
.blk svg.speed { display: block; width: 100%; height: 120px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--t12); font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 6px 8px; text-align: left; border-bottom: 1px solid rgba(var(--line-rgb), 0.5); }
.tbl th { color: var(--dim); font-weight: 400; }
.tbl .th { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; letter-spacing: 1px; }
.tbl .th:hover, .tbl .th.on { color: var(--text); }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover { background: var(--raised); }
.tbl td.w { color: var(--phosphor); font-weight: 700; }
.tbl td.l { color: var(--warn); font-weight: 700; }
.kv { margin: 0; display: grid; gap: 6px; font-size: var(--t12); }
.kv > div { display: flex; justify-content: space-between; gap: 16px; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.says { margin: 12px 0 0; font-size: var(--t12); line-height: 1.6; color: var(--text); }
.note { margin: 8px 0 0; font-size: var(--t12); color: var(--dim); }
.words { margin: 0; font-size: var(--t12); line-height: 1.6; color: var(--text); }
.kb-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; align-items: start; }
svg.kbd { display: block; width: 100%; height: auto; }
.legend-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 8px; font-size: var(--t12); color: var(--dim); }
.legend-row .note { margin: 0; }
.grad-key { display: inline-flex; align-items: center; gap: 8px; }
.grad { display: inline-block; width: 96px; height: 8px; border: var(--border); }
.weak { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: var(--t12); }
.weak li { display: grid; grid-template-columns: 24px 1fr 48px 1.2fr; align-items: center; gap: 8px; }
.weak li.empty { display: block; padding: 0; text-align: left; }
.weak .bar { height: 8px; background: var(--track); }
.weak .bar i { display: block; height: 100%; background: var(--danger); }
.weak .num { text-align: right; font-variant-numeric: tabular-nums; }
.weak .ws { color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
svg.cal { display: block; width: 100%; max-width: 560px; height: auto; }

/* ---------- Frame rate overlay ---------- */
#perf { position: absolute; z-index: 6; right: 16px; bottom: 16px; padding: 4px 8px; font-size: var(--t12); font-variant-numeric: tabular-nums; color: var(--text); background: rgba(var(--bg-rgb), 0.8); border: var(--border); border-radius: var(--r); pointer-events: none; }
#perf.hidden { display: none; }


/* Reduce motion: the system setting, or the game setting (main.js adds .reduce-motion to #ui). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after { animation: none !important; transition: none !important; }

/* Online ping badge */
#ping-badge { position: fixed; right: 10px; bottom: 8px; z-index: 30; padding: 2px 8px; font: 600 11px/1.6 ui-monospace, Consolas, monospace;
  letter-spacing: .04em; color: #cfd6e4; background: rgba(10,12,18,.7); border: 1px solid rgba(255,255,255,.14); pointer-events: none; }
#ping-badge[hidden] { display: none; }
#ping-badge[data-q="good"] { color: #7be39a; }
#ping-badge[data-q="fair"] { color: #f2c35b; }
#ping-badge[data-q="bad"] { color: #ff7b72; }

/* ---------- Modes: offline menu, match rules, round banner ---------- */
#title-bots.hidden { display: none; }
.mbtn.mode { height: 48px; font-size: var(--t16); }
.mbtn.mode.sel { border-color: var(--magenta); background: var(--raised); box-shadow: inset 4px 0 0 var(--magenta); }
.bot-opt.locked { opacity: 0.55; }
.optrows { display: grid; gap: 8px; }
.optrow { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 8px; background: var(--surface); border: var(--border); border-radius: var(--r); }
.optrow .lbl { font-size: var(--t12); font-weight: 700; letter-spacing: 1px; color: var(--text); text-transform: uppercase; }
.optrow .hint { display: block; margin-top: 2px; font-size: var(--t12); font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--dim); }
.optrow .segs { flex-wrap: wrap; justify-content: flex-end; }
.optrow .seg { min-width: 40px; height: 32px; padding: 0 8px; }
.opt-note { margin: 0; font-size: var(--t12); line-height: 1.6; color: var(--dim); }
.opt-note b { color: var(--text); }
#online-rules { display: grid; gap: 8px; }
#round-tag { font-size: var(--t12); font-weight: 700; letter-spacing: 2px; color: var(--dim); text-transform: uppercase; text-shadow: var(--outline); min-height: 16px; }
#round-banner {
  position: absolute; z-index: 4; left: 50%; top: 38%; transform: translate(-50%, -50%); text-align: center; padding: 16px 32px;
  background: var(--panel-bg); border: var(--border); border-radius: var(--r); pointer-events: none;
}
#round-banner.hidden { display: none; }
#round-banner b { display: block; font-size: var(--t32); letter-spacing: 6px; color: var(--phosphor); text-shadow: var(--outline); }
#round-banner span { display: block; margin-top: 8px; font-size: var(--t16); color: var(--text); letter-spacing: 2px; }
.optrow .lbl { flex: 1 1 0; min-width: 0; }
.optrow .segs { flex: 0 0 auto; flex-wrap: nowrap; }
.optrow .seg { min-width: 32px; padding: 0 6px; }
.optrows.compact .hint { display: none; }
.optrows.compact .optrow { padding: 4px 8px; }
.optrows.compact .seg { height: 28px; }
#title-bots .bot-opt { min-height: 48px; padding: 4px 12px; }
#title-bots { gap: 6px; }
#scr-online { max-height: calc(100% - 16px); overflow-y: auto; }


/* ---------- How to play: short steps, then plain lists ---------- */
#scr-howto { width: min(960px, 100%); }
#scr-howto .sec, #scr-howto .steps, #scr-howto .fine { grid-column: 1 / -1; }
/* The Back button stays in view while the guide scrolls. */
#scr-howto > .btn-row { position: sticky; bottom: -24px; z-index: 1; margin: 0 -24px -24px; padding: 12px 24px; background: var(--surface); border-top: var(--border); }
#scr-howto .sec { margin: 8px 0 0; padding-top: 12px; border-top: var(--border); font-size: var(--t16); letter-spacing: 3px; text-transform: uppercase; }
.steps { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 32px; }
.step { display: grid; grid-template-columns: 32px 1fr; gap: 12px; align-items: start; }
.step .num { display: grid; place-items: center; width: 32px; height: 32px; font-size: var(--t16); color: var(--bg); background: var(--magenta); border-radius: var(--r); }
.step.ult .num { background: var(--gold); }
.step h4 { margin: 0 0 4px; font-size: var(--t16); }
.step p { margin: 0; font-size: var(--t12); line-height: 1.6; color: var(--dim); max-width: 56ch; }
.fine { margin: 0; font-size: var(--t12); line-height: 1.6; color: var(--dim); opacity: 0.8; }
#scr-howto .legend { padding-top: 0; border-top: 0; }
#scr-howto .legend dl, .legend { display: grid; grid-template-columns: 140px 1fr; gap: 6px 16px; margin: 0; font-size: var(--t12); line-height: 1.6; }
#scr-howto dl.legend { display: grid; }

/* ---------- Brawl menu: the controls card ---------- */
.ctl { display: grid; grid-template-columns: minmax(80px, auto) 1fr; gap: 4px 12px; margin: 0; font-size: var(--t12); }
.ctl.two { grid-template-columns: 80px 1fr 1fr; }
.ctl dt { color: var(--dim); text-transform: uppercase; letter-spacing: 1px; }
.ctl dd { margin: 0; color: var(--text); }

/* ---------- Brawl: the fight ---------- */
#bhud { display: none; position: absolute; inset: 0; pointer-events: none; }
#ui.brawl #bhud { display: block; }
#ui.brawl #hud, #ui.brawl #typing-box, #ui.brawl #word-progress { display: none !important; }
.bh-side { --id: var(--you); position: absolute; top: 12px; width: calc(50% - 112px); padding: 8px 16px 10px; background: var(--hud-bg); border: var(--border); border-top: 4px solid var(--id); border-radius: var(--r); }
.bh-side.left { left: 16px; }
.bh-side.right { right: 16px; --id: var(--foe); }
.bh-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: var(--t12); font-weight: 700; letter-spacing: 3px; color: var(--id); text-transform: uppercase; }
.bh-side.right .bh-name { text-align: right; }
.bh-bar { position: relative; height: 20px; margin-top: 6px; background: var(--track); border: var(--border); overflow: hidden; }
.bh-bar i { position: absolute; top: 0; bottom: 0; left: 0; width: 100%; }
.bh-side.right .bh-bar i { left: auto; right: 0; }
.bh-ghost { background: var(--danger); opacity: 0.55; }
.bh-fill { background: var(--phosphor); transition: width 0.08s linear; }
.bh-hp { position: absolute; top: 0; left: 8px; right: 8px; line-height: 18px; font-size: var(--t12); color: var(--bg); text-align: left; mix-blend-mode: normal; }
.bh-side.right .bh-hp { text-align: right; }
.bh-meter { position: relative; height: 10px; margin-top: 6px; background: var(--track); border: var(--border); }
.bh-meter i { position: absolute; top: 0; bottom: 0; left: 0; width: 0; background: var(--ult-dim); }
.bh-side.right .bh-meter i { left: auto; right: 0; }
.bh-meter.ready i { background: var(--gold); }
.bh-meter span { position: absolute; top: -1px; left: 6px; right: 6px; font-size: 8px; line-height: 12px; letter-spacing: 2px; color: var(--text); opacity: 0.0; }
.bh-meter.ready span { opacity: 1; color: var(--bg); }
.bh-side.right .bh-meter span { text-align: right; }
.bh-mid { position: absolute; top: 12px; left: 50%; width: 192px; margin-left: -96px; padding: 8px 8px 10px; text-align: center; background: var(--hud-bg); border: var(--border); border-radius: var(--r); }
.bh-clock { font-size: var(--t32); font-weight: 700; line-height: 36px; min-height: 36px; font-variant-numeric: tabular-nums; }
.bh-tag { min-height: 16px; font-size: var(--t12); font-weight: 700; letter-spacing: 2px; color: var(--dim); text-transform: uppercase; }
.bh-pause { position: absolute; top: 96px; right: 16px; pointer-events: auto; }
#ui.brawl #countdown { bottom: auto; top: 30%; }

/* Brawl result */
#scr-bresult { width: 560px; gap: 12px; }
#bko { padding: 12px 24px 12px; text-align: center; }
#bko .ko-title { font-size: var(--t64); line-height: 64px; font-weight: 700; letter-spacing: 8px; }
#bko .ko-title.win { color: var(--phosphor); text-shadow: 4px 0 0 var(--magenta); }
#bko .ko-title.lose { color: var(--danger); text-shadow: 4px 0 0 rgba(var(--text-rgb), 0.25); }
#bko .ko-sub { margin-top: 4px; font-size: var(--t12); letter-spacing: 2px; color: var(--dim); }
.bcols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
#overlay[data-screen="bresult"] #scr-bresult { display: grid; }

/* Brawl touch controls: a pad with diagonals on the left, three punches over three kicks on the right, small shortcut buttons above.
   Sized from the screen (vmin), so it fits a phone held either way. */
#touch { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: space-between; align-items: flex-end; gap: 8px;
  padding: 0 max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); pointer-events: none; touch-action: none; }
#touch.hidden { display: none; }
#touch-pad, #touch-acts { --b: clamp(40px, min(14vmin, 21vw), 84px); display: grid; gap: 5px; pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none; }
#touch-pad { grid-template: repeat(3, var(--b)) / repeat(3, var(--b)); }
#touch-pad .ul { grid-area: 1 / 1; } #touch-pad .up { grid-area: 1 / 2; } #touch-pad .ur { grid-area: 1 / 3; }
#touch-pad .left { grid-area: 2 / 1; } #touch-pad .right { grid-area: 2 / 3; }
#touch-pad .dl { grid-area: 3 / 1; } #touch-pad .down { grid-area: 3 / 2; } #touch-pad .dr { grid-area: 3 / 3; }
#touch-acts { grid-template-columns: repeat(6, calc(var(--b) * 0.5)); grid-template-rows: calc(var(--b) * 0.62) calc(var(--b) * 1.08) calc(var(--b) * 1.08); gap: 6px 5px; align-content: end; }
#touch-acts .sm { grid-column: span 2; grid-row: 1; }
#touch-acts .act { grid-column: span 3; }
#touch-acts .hp, #touch-acts .hk { grid-row: 2; } #touch-acts .lp, #touch-acts .lk { grid-row: 3; }
#touch-acts .hp, #touch-acts .lp { grid-column: 1 / span 3; } #touch-acts .hk, #touch-acts .lk { grid-column: 4 / span 3; }
#touch.lefty { flex-direction: row-reverse; }
.tb { font-family: var(--font); font-weight: 700; font-size: clamp(11px, 3vmin, 16px); letter-spacing: 1px; color: var(--text); background: rgba(var(--surface-rgb), 0.55); border: 2px solid rgba(var(--text-rgb), 0.35); border-radius: 50%; padding: 0; touch-action: none; -webkit-tap-highlight-color: transparent; }
#touch-pad .tb { border-radius: var(--r); }
#touch-pad .ul, #touch-pad .ur, #touch-pad .dl, #touch-pad .dr { opacity: 0.7; }
.tb.sm { border-radius: var(--r); font-size: clamp(9px, 2.4vmin, 13px); letter-spacing: 0; border-color: var(--magenta); }
.tb.act { border-color: var(--phosphor); display: grid; place-content: center; line-height: 1.15; }
.tb.act i { font-style: normal; font-size: clamp(8px, 2.1vmin, 11px); font-weight: 400; letter-spacing: 1px; text-transform: uppercase; opacity: 0.8; }
.tb.act b { font-size: clamp(10px, 2.7vmin, 14px); }
.tb.act.kick { border-color: var(--gold); }
.tb.on { background: var(--magenta); border-color: var(--text); color: var(--bg); }
@media (orientation: portrait) { #touch-pad, #touch-acts { --b: clamp(34px, 13.6vw, 72px); } #touch { gap: 4px; } }

/* ---------- Phones and narrow windows: main.js adds .narrow and lays the UI out at about 440 design px wide ---------- */
#ui.narrow #overlay { padding: 56px 8px 8px; overflow-y: auto; justify-content: flex-start; }
#ui.narrow #scr-title { grid-template-columns: 1fr; align-items: start; flex: none; width: 100%; gap: 12px; }
#ui.narrow #title-left { grid-column: 1; gap: 12px; }
#ui.narrow #title-bots { grid-column: 1; max-height: none; overflow: visible; }
#ui.narrow .logo { font-size: 40px; line-height: 40px; letter-spacing: 4px; }
#ui.narrow .mbtn { height: 48px; font-size: 18px; letter-spacing: 2px; }
#ui.narrow .mbtn.primary { height: 72px; font-size: 40px; letter-spacing: 4px; }
#ui.narrow #scr-howto, #ui.narrow #scr-online, #ui.narrow #scr-stats, #ui.narrow #scr-result, #ui.narrow #scr-bresult, #ui.narrow #mod-settings, #ui.narrow #mod-pause, #ui.narrow #mod-confirm { width: 100%; max-height: none; }
#ui.narrow #scr-howto { grid-template-columns: 1fr; padding: 16px; }
#ui.narrow .steps, #ui.narrow .bcols, #ui.narrow #result-cols { grid-template-columns: 1fr; }
#ui.narrow #scr-howto .legend, #ui.narrow .legend { grid-template-columns: 1fr; gap: 2px; }
#ui.narrow #scr-fighter { grid-template-columns: 1fr; }
#ui.narrow #result-bots { grid-template-columns: repeat(3, 1fr); }
#ui.narrow #modal { align-items: flex-start; overflow-y: auto; padding: 8px; }
#ui.narrow .set-row, #ui.narrow .optrow { grid-template-columns: 1fr; flex-wrap: wrap; }
#ui.narrow #mod-settings { height: auto; max-height: calc(100dvh - 16px); }
#ui.narrow .set-rows { max-height: 52dvh; }
#ui.narrow .bh-side { width: calc(50% - 24px); padding: 6px 8px; }
#ui.narrow .bh-name { letter-spacing: 1px; }
#ui.narrow .bh-mid { top: 84px; width: 140px; margin-left: -70px; }
#ui.narrow .bh-pause { top: 84px; }

#ui.narrow .chip-weapon, #ui.narrow .chip-color { display: none; }
#ui.narrow #overlay { padding-top: 64px; }

/* Fighter creator: the live fighter on the left, the form on the right. */
#scr-creator { grid-template-columns: 448px 640px; gap: 16px; align-items: stretch; max-height: calc(100dvh - 32px); }
#cr-stage { position: relative; padding: 0; overflow: hidden; display: grid; background: var(--surface); }
#creator-preview { width: 446px; height: 520px; display: block; }
#cr-side { padding: 20px; display: grid; gap: 12px; align-content: start; grid-template-rows: auto minmax(0, 1fr) auto; height: 560px; }
.cr-scroll { overflow-y: auto; display: grid; gap: 8px; align-content: start; padding-right: 8px; min-height: 0; }
.cr-row { flex-wrap: wrap; }
.cr-row .segs, .cr-bases, .cr-slots, .cr-combo, .cr-stat { display: inline-flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; align-items: center; }
.cr-bases { max-width: 330px; }
.cr-combo { max-width: 380px; }
.cr-combo .seg { height: auto; min-height: 32px; padding: 2px 6px; line-height: 1.1; font-size: var(--t12); }
.cr-stat b { min-width: 24px; text-align: center; font-size: var(--t16); }
.cr-row .seg:disabled { opacity: 0.35; cursor: default; }
#cr-name, .cr-name { height: 32px; padding: 0 8px; color: var(--text); background: var(--surface); border: var(--border); border-radius: var(--r); font: 700 var(--t12) var(--font); letter-spacing: 1px; text-transform: uppercase; outline: none; width: 150px; }
#cr-name:focus, .cr-name:focus { border-color: var(--magenta); }
#cr-side input[type="color"] { width: 56px; height: 32px; padding: 0; border: var(--border); background: var(--surface); border-radius: var(--r); cursor: pointer; }
#cr-side .btn-row { justify-content: flex-end; flex-wrap: wrap; }
#ui.narrow #scr-creator { grid-template-columns: 1fr; width: 100%; max-height: none; }
#ui.narrow #cr-stage { display: none; }
#ui.narrow #cr-side { height: auto; }
#ui.narrow .cr-scroll { max-height: 58dvh; }
#ui.narrow .cr-bases, #ui.narrow .cr-combo { max-width: none; justify-content: flex-start; }

/* Starting side: right. You stand on the right, so your HUD plates sit there and keep your colors. */
#ui.mirror .hptop.left, #ui.mirror .side.left { --id: var(--foe); }
#ui.mirror .hptop.right, #ui.mirror .side.right { --id: var(--you); }
#ui.mirror .hptop.left .hpfill { background: var(--foe); }
#ui.mirror .hptop.right .hpfill { background: var(--phosphor); }
#ui.mirror .hptop.left .hpfill.low { background: var(--warn); }
#ui.mirror .hptop.right .hpfill.low { background: var(--warn); }
#ui.mirror .hptop.left .hpfill.crit { background: var(--danger); }
#ui.mirror .hptop.right .hpfill.crit { background: var(--danger); }
