:root {
  --bg: #0b0c0f;
  --panel: #121419;
  --raise: #181b21;
  --line: #23262e;
  --line-2: #2e323b;
  --text: #e8e9ec;
  --dim: #9a9ea8;
  --faint: #60646e;
  --p1: #e5484d;
  --p2: #3e8bf0;
  --ok: #46a758;
  --warn: #d6a13b;
  --bad: #e5484d;
  --gap: 12px;
  --bar-h: 46px;
  --match-h: 96px;
  --side-w: 236px;
  --display: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", Impact, sans-serif;
  /* The 4:3 screen fills the height left under both header rows (minus controls, status line and padding); the sidebars take the rest. */
  --stage-w: min(calc((100vh - var(--bar-h) - var(--match-h) - 94px) * 4 / 3), calc(100vw - 2 * var(--side-w) - 4 * var(--gap)));
  --cols: minmax(var(--side-w), 1fr) var(--stage-w) minmax(var(--side-w), 1fr);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 13px/1.4 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--raise); padding: 1px 4px; border-radius: 3px; }
.p1 { --seat: var(--p1); }
.p2 { --seat: var(--p2); }

.btn {
  height: 30px; padding: 0 11px; border-radius: 4px; border: 1px solid var(--line-2); background: var(--raise);
  font-weight: 500; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; text-decoration: none;
}
.btn:hover:not(:disabled) { background: #20242c; border-color: #3a3f4a; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn svg { width: 14px; height: 14px; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover:not(:disabled) { background: #fff; }
.btn.small { height: 26px; padding: 0 9px; font-size: 12px; }

.btn.ghost { background: transparent; border-color: transparent; color: var(--dim); }
.btn.ghost:hover:not(:disabled) { background: var(--raise); border-color: var(--line-2); color: var(--text); }

/* App bar: site controls only, kept thin so the match owns the header. */
.appbar {
  height: var(--bar-h); display: flex; align-items: center; gap: 16px; padding: 0 var(--gap);
  background: #08090b; border-bottom: 1px solid var(--line);
}
.brand {
  flex: none; display: flex; align-items: center; gap: 8px; text-decoration: none;
  font: italic 800 19px/1 var(--display); letter-spacing: 0.04em; text-transform: uppercase;
}
.brand-mark { width: 18px; height: 14px; background: linear-gradient(90deg, var(--p1) 0 50%, var(--p2) 50% 100%); clip-path: polygon(30% 0, 100% 0, 70% 100%, 0 100%); }
.search { flex: 1; max-width: 640px; margin: 0 auto; display: flex; gap: 6px; min-width: 0; }
.search input {
  flex: 1; min-width: 0; height: 30px; padding: 0 10px; border-radius: 4px;
  background: var(--panel); border: 1px solid var(--line-2); outline: none;
}
.search input::placeholder { color: var(--faint); }
.search input:focus { border-color: #5a5f6b; }
.app-actions { flex: none; display: flex; gap: 2px; }

/* Homepage, shown when the address has no replay. The class is set from a head script so the player never paints first. */
html.is-home .home { display: block !important; }
html.is-finder .finder { display: block !important; }
html.is-home .matchup,
html.is-home .layout,
html.is-home .comments,
html.is-finder .matchup,
html.is-finder .layout,
html.is-finder .comments,
html.is-finder .home { display: none !important; }
.home, .finder { max-width: 1180px; margin: 0 auto; padding: 28px var(--gap) 64px; }
.home-lead h1 { margin: 0 0 8px; font: italic 800 44px/0.95 var(--display); letter-spacing: 0.03em; text-transform: uppercase; }
.home-lead p { margin: 0 0 22px; color: var(--dim); }
.home-live { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
.boards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: start; }
.finder-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.finder-bar input, .finder-bar select {
  height: 30px; padding: 0 10px; border-radius: 4px; background: var(--panel); border: 1px solid var(--line-2); outline: none;
}
.finder-bar input { flex: 1; min-width: 140px; }
.sorts { display: flex; flex-wrap: wrap; gap: 6px; }
.sorts a {
  height: 30px; padding: 0 10px; display: inline-flex; align-items: center; border-radius: 4px; text-decoration: none;
  border: 1px solid var(--line-2); background: var(--raise); font: 700 12px/1 var(--display); letter-spacing: 0.06em; text-transform: uppercase;
}
.sorts a.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.finder-more { margin-top: 12px; }
.board { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.board h2 { margin: 0; padding: 12px 16px; border-bottom: 1px solid var(--line); font: 700 13px/1 var(--display); letter-spacing: 0.08em; text-transform: uppercase; }
.board ol { list-style: none; margin: 0; padding: 0; }
.board a.bout {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 4px 18px; align-items: center;
  padding: 10px 16px; text-decoration: none; border-bottom: 1px solid var(--line);
}
.board a.bout.has-n { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto; }
.board a.bout:hover { background: var(--raise); }
.board .plate { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.board .plate.p1 { align-items: flex-end; text-align: right; }
.board .who { display: flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; }
.board .plate.p1 .who { flex-direction: row-reverse; }
.board .name {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 800 22px/1 var(--display); text-transform: uppercase; letter-spacing: 0.02em;
}
.board .name.p1 { color: color-mix(in srgb, var(--p1) 78%, #fff); }
.board .name.p2 { color: color-mix(in srgb, var(--p2) 72%, #fff); }
.board .badge { flex: none; width: 20px; height: 20px; display: block; }
.board .flag { flex: none; font-size: 16px; line-height: 1; }
.board .where {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12px; color: var(--dim);
}
.board .core {
  display: grid; grid-template-columns: 2.4ch auto 2.4ch; grid-template-rows: auto auto;
  justify-items: center; align-items: center; column-gap: 8px; min-width: 8.5rem; padding: 4px 12px;
  background: #050506; clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 100%, 0 100%);
}
.board .core:not(.scored) {
  display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 0; background: none; clip-path: none;
}
.board .score { font: italic 800 28px/1 var(--display); font-variant-numeric: tabular-nums; color: #fff; }
.board .score.p1 { color: color-mix(in srgb, var(--p1) 70%, #fff); }
.board .score.p2 { color: color-mix(in srgb, var(--p2) 65%, #fff); }
.board .score.lead { color: #fff; }
.board .vs { font: 800 13px/1 var(--display); letter-spacing: 0.1em; color: #fff; }
.board .sub {
  grid-column: 1 / -1; font: 700 11px/1 var(--display); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--faint); white-space: nowrap;
}
.board .n { display: flex; flex-direction: column; align-items: flex-end; min-width: 3.2rem; }
.board .n b { font: italic 800 22px/1 var(--display); }
.board .n small { font: 700 10px/1 var(--display); letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }
.board .empty, .board p.empty { padding: 16px 14px; margin: 0; color: var(--faint); }
.board .more {
  display: block; padding: 10px 12px; text-align: center; text-decoration: none; color: var(--dim);
  font: 700 12px/1 var(--display); letter-spacing: 0.08em; text-transform: uppercase;
}
.board .more:hover { color: var(--text); background: var(--raise); }
.boards a.bout, .boards a.bout.has-n { gap: 2px 6px; padding: 8px; }
.boards .who { gap: 4px; }
.boards .name { font-size: 15px; }
.boards .badge { width: 14px; height: 14px; }
.boards .flag { font-size: 12px; }
.boards .where { display: none; }
.boards .core { min-width: 0; column-gap: 3px; padding: 2px 4px; }
.boards .score { font-size: 18px; }
.boards .vs { font-size: 10px; }
.boards .sub { font-size: 9px; letter-spacing: 0.04em; white-space: normal; text-align: center; line-height: 1.15; }
.boards .n { min-width: 2.4rem; }
.boards .n b { font-size: 16px; }
.boards .n small { font-size: 8px; }
@media (max-width: 900px) {
  .boards { grid-template-columns: 1fr; }
  .boards .name { font-size: 18px; }
  .boards .where { display: block; }
  .boards .score { font-size: 22px; }
  .boards .sub { font-size: 11px; white-space: nowrap; }
}
@media (max-width: 720px) {
  .home { padding: 18px 10px 40px; }
  .home-lead h1 { font-size: 32px; }
  .home-lead p { margin-bottom: 16px; }
  .board a.bout, .board a.bout.has-n {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 2px 8px; padding: 10px;
  }
  .board .name { font-size: 16px; }
  .board .badge { width: 16px; height: 16px; }
  .board .flag { font-size: 14px; }
  .finder .where { display: none; }
  .board .core { min-width: 0; column-gap: 4px; padding: 2px 6px; }
  .board .score { font-size: 22px; }
  .board .vs { font-size: 11px; }
  .board .sub { white-space: normal; text-align: center; max-width: 7.5rem; line-height: 1.2; }
  .board .n { grid-column: 1 / -1; flex-direction: row; align-items: baseline; gap: 6px; justify-content: flex-end; }
  .board .n b { font-size: 16px; }
}

/* Match bar: the score sits in the middle, each fighter's plate grows outward from it. */
.matchup {
  height: var(--match-h); display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--p1) 16%, transparent), transparent 38%, transparent 62%, color-mix(in srgb, var(--p2) 16%, transparent)),
    #0d0e12;
  border-bottom: 1px solid var(--line); position: relative; overflow: hidden;
}
.fighter { min-width: 0; display: flex; align-items: center; gap: 16px; padding: 0 28px; position: relative; }
.fighter::after {
  content: ""; position: absolute; bottom: 0; height: 3px; width: 100%;
  background: linear-gradient(var(--edge), var(--seat), transparent 85%);
}
.fighter.p1 { --edge: to left; justify-content: flex-end; }
.fighter.p2 { --edge: to right; }
.fighter.p1::after { right: 0; }
.fighter.p2::after { left: 0; }
.fighter.p1 .avatar { order: 2; }
.fighter.p1 .fighter-text { align-items: flex-end; text-align: right; }
.avatar {
  flex: none; width: 64px; height: 64px; display: grid; place-items: center; overflow: hidden; position: relative;
  background: var(--raise); border: 2px solid var(--seat); border-radius: 50%;
  font: 800 22px/1 var(--display); color: var(--dim);
  box-shadow: 0 0 24px color-mix(in srgb, var(--seat) 35%, transparent);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar img:not([hidden]) + span { display: none; }
.fighter-text { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.fighter-name { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; }
.fighter.p1 .fighter-name { flex-direction: row-reverse; }
.fighter .name {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none;
  font: 800 30px/1 var(--display); text-transform: uppercase; letter-spacing: 0.01em;
}
.fighter a.name[href]:hover { color: var(--seat); }
.badge { flex: none; width: 26px; height: 26px; display: block; }
.rank-tag {
  flex: none; height: 18px; padding: 0 5px; display: inline-flex; align-items: center; gap: 4px;
  font: 800 14px/1 var(--display); color: var(--text); border: 1px solid var(--line-2); border-radius: 2px;
}
.rank-tag small { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); }
.fighter-sub { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--dim); white-space: nowrap; }
.fighter.p1 .fighter-sub { flex-direction: row-reverse; }
.fighter-sub .flag { font-size: 16px; line-height: 1; }
.fighter-sub .char { color: var(--text); font-weight: 600; }
.fighter-sub .char:not(:empty)::before { content: "·"; color: var(--faint); margin-right: 8px; }
.fighter.p1 .fighter-sub .char:not(:empty)::before { content: none; }
.fighter.p1 .fighter-sub .char:not(:empty)::after { content: "·"; color: var(--faint); margin-left: 8px; }
.fighter-stats { display: flex; gap: 10px; font-size: 12px; color: var(--faint); white-space: nowrap; overflow: hidden; max-width: 100%; }
.fighter-stats:empty { display: none; }
.fighter-stats b { color: var(--dim); font-weight: 600; font-variant-numeric: tabular-nums; }

.score-core {
  display: grid; grid-template-columns: 84px auto 84px; grid-template-rows: 1fr auto; align-items: stretch;
  background: #050506; padding: 0 22px; position: relative;
  clip-path: polygon(0 0, 100% 0, calc(100% - 22px) 100%, 22px 100%);
}
.sb-num {
  display: grid; place-items: center; position: relative; margin: 10px 0 0;
  font: italic 800 52px/1 var(--display); font-variant-numeric: tabular-nums; color: #fff;
  background: color-mix(in srgb, var(--seat) 55%, #050506);
}
.sb-num.p1 { clip-path: polygon(14px 0, 100% 0, 100% 100%, 0 100%); }
.sb-num.p2 { clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 100%, 0 100%); }
.sb-num.lead { background: var(--seat); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.sb-num.bump { animation: bump 0.9s ease-out; }
@keyframes bump {
  0% { transform: scale(1); filter: brightness(1); }
  15% { transform: scale(1.12); filter: brightness(1.6); }
  100% { transform: scale(1); filter: brightness(1); }
}
.sb-mid { min-width: 84px; margin-top: 10px; padding: 0 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: #111216; }
.sb-ft { font: 800 22px/1 var(--display); letter-spacing: 0.06em; color: #fff; }
.sb-game { font: 700 12px/1 var(--display); letter-spacing: 0.14em; text-transform: uppercase; color: var(--warn); white-space: nowrap; }
.sb-game:empty { display: none; }
.sb-meta {
  grid-column: 1 / -1; display: flex; justify-content: center; gap: 8px; padding: 5px 0 6px;
  font: 600 11px/1 var(--display); letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); white-space: nowrap;
}
.sb-meta #mb-game { color: var(--text); }
.sb-meta #mb-meta:empty { display: none; }
.sb-meta #mb-meta:not(:empty)::before { content: "·"; margin-right: 8px; color: var(--faint); }

/* Body: sidebars run the full height beside the screen. */
.layout {
  display: grid; grid-template-columns: var(--cols); gap: var(--gap); padding: var(--gap);
  height: calc(100dvh - var(--bar-h) - var(--match-h)); min-height: 520px; align-items: stretch;
}
.center { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.side { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.side-head { height: 34px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--line); color: var(--dim); font-size: 12px; min-width: 0; }
.side-head span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-tag { flex: none; padding: 2px 6px; font: 800 12px/1 var(--display); letter-spacing: 0.06em; color: var(--seat); border: 1px solid color-mix(in srgb, var(--seat) 50%, transparent); border-radius: 2px; }

/* Game and set results over the stage */
.game-banner {
  position: absolute; left: 50%; top: 14%; transform: translateX(-50%); z-index: 3; pointer-events: none;
  display: flex; align-items: center; gap: 10px; padding: 8px 16px 8px 12px; max-width: calc(100% - 24px); overflow: hidden; white-space: nowrap;
  background: rgba(7, 8, 10, 0.92); border: 1px solid var(--line-2); border-left: 4px solid var(--seat); border-radius: 4px;
  font-weight: 600; font-size: 15px; animation: banner 3.2s ease forwards;
}
.game-banner b { color: var(--seat); }
.game-banner .score { font: 700 15px ui-monospace, Menlo, monospace; color: var(--dim); }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -10px); }
  8%, 85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -6px); }
}
.winner-card { --seat: var(--text); width: 380px; max-width: 100%; flex: none; overflow: hidden; border: 1px solid var(--line-2); border-radius: 6px; background: #0d0e12; box-shadow: 0 22px 48px rgba(0, 0, 0, 0.55), 0 0 0 1px color-mix(in srgb, var(--seat) 55%, transparent); }
.winner-card.p1 { --seat: var(--p1); }
.winner-card.p2 { --seat: var(--p2); }
.overlay.celebrate:not(.settled) .winner-card { animation: winner-in 0.48s cubic-bezier(0.2, 1.35, 0.32, 1) both; }
@keyframes winner-in {
  0% { opacity: 0; transform: translateY(16px) scale(0.9); }
  62% { opacity: 1; transform: translateY(0) scale(1.035); }
  100% { opacity: 1; transform: none; }
}
.winner-card .kicker {
  height: 34px; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--seat); color: #fff; font: italic 800 22px/1 var(--display); letter-spacing: 0.22em; text-transform: uppercase;
}
.winner-card .kicker::before, .winner-card .kicker::after { content: ""; width: 22px; height: 2px; background: rgba(255, 255, 255, 0.75); }
.winner-card .body {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 20px 14px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--seat) 28%, transparent), transparent 62%),
    #0d0e12;
}
.winner-card .crest {
  width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; position: relative; overflow: hidden;
  border: 3px solid var(--seat); background: var(--raise);
  font: 800 28px/1 var(--display); color: var(--dim);
  box-shadow: 0 0 28px color-mix(in srgb, var(--seat) 50%, transparent);
}
.winner-card .crest img { width: 100%; height: 100%; object-fit: cover; }
.winner-card .who {
  margin: 0; width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  font: italic 800 clamp(20px, 12cqi, 42px)/0.9 var(--display) !important; letter-spacing: 0.02em; text-transform: uppercase;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}
.winner-card .who img { width: 30px; height: 30px; flex: none; }
.winner-card .where { color: var(--dim); font-size: 13px; }
.winner-card .final { display: grid; grid-template-columns: 72px 28px 72px; align-items: stretch; margin-top: 2px; }
.winner-card .final .p1, .winner-card .final .p2 {
  display: grid; place-items: center; height: 52px; color: #fff;
  font: italic 800 40px/1 var(--display); font-variant-numeric: tabular-nums;
}
.winner-card .final .p1 { background: color-mix(in srgb, var(--p1) 58%, #050506); clip-path: polygon(10px 0, 100% 0, 100% 100%, 0 100%); }
.winner-card .final .p2 { background: color-mix(in srgb, var(--p2) 58%, #050506); clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 100%, 0 100%); }
.winner-card .final .win { background: var(--seat); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.winner-card .final .dash { display: grid; place-items: center; background: #111216; color: var(--faint); font: italic 800 22px/1 var(--display); }
.winner-card .live { height: 14px; margin: 2px 0 0; color: var(--warn); font: 700 12px/1 var(--display); letter-spacing: 0.16em; text-transform: uppercase; }
.overlay.celebrate {
  background: radial-gradient(ellipse at 50% 46%, rgba(8, 9, 12, 0.78) 0%, rgba(8, 9, 12, 0.38) 48%, rgba(8, 9, 12, 0.12) 100%);
}
.overlay.celebrate .overlay-card { width: min(400px, 100%); }
.winner-card { width: min(380px, 100%); container-type: inline-size; }
.overlay-card { position: relative; z-index: 1; width: min(400px, 100%); max-width: 100%; min-width: 0; justify-self: center; }
.confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
@container (max-width: 340px) {
  .winner-card .kicker { height: 26px; font-size: 15px; letter-spacing: 0.14em; }
  .winner-card .kicker::before, .winner-card .kicker::after { width: 12px; }
  .winner-card .body { gap: 4px; padding: 8px 12px 8px; }
  .winner-card .crest { width: 52px; height: 52px; font-size: 18px; }
  .winner-card .where { display: none; }
  .winner-card .final { grid-template-columns: 52px 18px 52px; }
  .winner-card .final .p1, .winner-card .final .p2 { height: 36px; font-size: 26px; }
  .winner-card .live { height: 12px; }
}
@container stage (max-height: 340px) {
  .overlay { padding: 6px; }
  .winner-card .kicker { height: 22px; font-size: 13px; letter-spacing: 0.12em; }
  .winner-card .body { gap: 2px; padding: 6px 8px; }
  .winner-card .crest { width: 40px; height: 40px; font-size: 16px; }
  .winner-card .who { font-size: 22px !important; }
  .winner-card .where, .winner-card .live { display: none; }
  .winner-card .final { grid-template-columns: 44px 14px 44px; }
  .winner-card .final .p1, .winner-card .final .p2 { height: 28px; font-size: 22px; }
  .overlay-card .actions { margin-top: 2px; }
  .overlay-card .actions .btn { height: 26px; padding: 0 8px; font-size: 12px; }
}

/* Player box */
.player-box {
  width: 100%; margin: 0 auto;
  background: #000; border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
  display: flex; flex-direction: column;
}
.stage { position: relative; aspect-ratio: 4 / 3; width: 100%; background: #000; container-type: size; container-name: stage; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.player-box:fullscreen { width: 100vw; border: 0; border-radius: 0; justify-content: center; }
.player-box:fullscreen .stage { width: min(100vw, calc((100vh - 40px) * 4 / 3)); margin: 0 auto; }

.controls {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; min-height: 40px; height: auto; padding: 4px 8px;
  background: var(--panel); border-top: 1px solid var(--line);
}
.icon-btn { width: 28px; height: 28px; border-radius: 4px; border: 0; background: transparent; display: grid; place-items: center; color: var(--text); flex: none; }
.icon-btn:hover:not(:disabled) { background: var(--raise); }
.icon-btn svg { width: 16px; height: 16px; }
#btn-play .icon-pause { display: none; }
#btn-play.is-playing .icon-play { display: none; }
#btn-play.is-playing .icon-pause { display: block; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
#btn-share-bar { background: var(--text); color: var(--bg); }
#btn-share-bar:hover:not(:disabled) { background: #fff; }
#btn-share-bar:disabled { opacity: 0.4; }
.stage .timeline {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; height: 48px;
  display: flex; align-items: flex-end; cursor: pointer;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0));
}
.stage .time {
  position: absolute; left: 8px; bottom: 16px; z-index: 1; padding: 0;
  color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85); pointer-events: none;
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap;
}
.timeline .track {
  position: relative; width: 100%; height: 4px; margin: 0 0 8px; border-radius: 0;
  background: rgba(255, 255, 255, 0.28); overflow: visible;
}
.timeline:hover .track { height: 6px; margin-bottom: 7px; }
/* The pale bar is bytes already in hand. The white bar is the frame on screen. */
.timeline .loaded { position: absolute; inset: 0 auto 0 0; background: rgba(255, 255, 255, 0.42); width: 0; }
.timeline .played { position: absolute; inset: 0 auto 0 0; background: #fff; width: 0; }
.timeline .playhead {
  position: absolute; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45); pointer-events: none;
}
.timeline.is-live .playhead { box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45), 0 0 0 4px rgba(255, 255, 255, 0.28); }
.timeline .hover-time {
  position: absolute; bottom: 22px; transform: translateX(-50%); font: 11px ui-monospace, Menlo, monospace;
  background: rgba(0, 0, 0, 0.82); color: #fff; border: 0; padding: 1px 5px; border-radius: 3px; pointer-events: none;
}
.timeline .mark {
  position: absolute; top: 0; width: 18px; height: 100%; margin-left: -9px;
  background: transparent; cursor: ew-resize; touch-action: none; z-index: 2;
}
.timeline .mark::before {
  content: ""; position: absolute; left: 8px; bottom: 4px; width: 2px; height: 18px; border-radius: 1px; background: var(--p1);
}
.timeline .mark::after {
  content: ""; position: absolute; left: 5px; bottom: 18px; width: 8px; height: 8px; border-radius: 2px; background: var(--p1);
}
.timeline .mark.out::before, .timeline .mark.out::after { background: var(--p2); }
#export-dialog[open] {
  position: fixed; top: max(12px, calc(var(--bar-h) + 8px)); bottom: auto; margin: 0 auto; height: fit-content;
  max-height: calc(100dvh - var(--bar-h) - 96px); overflow: auto; z-index: 30;
}
.segmented { display: flex; border: 1px solid var(--line-2); border-radius: 4px; overflow: hidden; flex: none; }
.segmented button { border: 0; background: transparent; padding: 3px 7px; font: 11px ui-monospace, Menlo, monospace; color: var(--dim); }
.segmented button + button { border-left: 1px solid var(--line-2); }
.segmented button.on { background: var(--raise); color: var(--text); }
.volume { display: flex; align-items: center; flex: none; }
.volume input[type="range"] { width: 64px; accent-color: var(--text); }

.overlay { position: absolute; inset: 0; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 16px; background: rgba(11, 12, 15, 0.86); overflow: hidden; }
.overlay.clear { background: transparent; pointer-events: none; }
.overlay-card { max-width: 380px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.overlay-card h2 { margin: 0; font-size: 15px; font-weight: 600; }
.overlay-card p { margin: 0; color: var(--dim); }
.overlay-card .actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 6px; }
.overlay-card .err { width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid var(--bad); color: var(--bad); display: grid; place-items: center; font-weight: 700; }
.big-play { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); display: grid; place-items: center; }
.big-play:hover { background: #fff; }
.big-play svg { width: 22px; height: 22px; margin-left: 3px; }
.big-play.again svg { margin-left: 0; }
.spinner { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--text); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress-mini { width: 200px; height: 3px; border-radius: 2px; background: var(--line-2); overflow: hidden; }
.progress-mini div { height: 100%; width: 0; background: var(--text); }
.buffer-chip { position: absolute; top: 8px; left: 8px; padding: 2px 8px; border-radius: 3px; background: rgba(0, 0, 0, 0.8); border: 1px solid var(--line-2); font-size: 11px; color: var(--warn); }
.stage-cues { position: absolute; top: 8px; right: 8px; z-index: 5; display: flex; align-items: center; gap: 6px; }
.comment-cue {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 9px 0 7px;
  border: 0; border-radius: 6px; background: rgba(8, 9, 11, 0.9); color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28); font: 600 12px/1 Inter, system-ui, sans-serif;
}
.like-cue { padding: 0 8px; }
.like-cue.on { color: var(--p1); }
.like-cue.on svg { fill: var(--p1); stroke: var(--p1); }
.comment-cue:hover { background: #17191e; }
.comment-cue svg { width: 14px; height: 14px; display: block; }
.comment-cue-icon { position: relative; display: grid; }
.comment-cue-dot { display: none; position: absolute; top: -3px; right: -3px; width: 7px; height: 7px; border-radius: 50%; background: var(--p1); box-shadow: 0 0 0 2px rgba(8, 9, 11, 0.9); }
.comment-cue.is-empty .comment-cue-dot { display: block; }
.comment-cue-badge {
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--p1); color: #fff;
  font: 700 10px/16px Inter, system-ui, sans-serif; text-align: center;
}
.comments.comments-pulse .comments-inner { animation: comments-pulse 1s ease; }
@keyframes comments-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--p1) 65%, transparent); }
  100% { box-shadow: 0 0 0 12px transparent; }
}

.statusline { margin: 0; display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--faint); padding: 0 2px; }
#status { color: var(--dim); }
#status.error { color: var(--bad); }

/* Pad */
.pad-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pad-panel:has(.fold[aria-expanded="false"]) { flex: none; }
.pad { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 14px 12px; }
.gate { position: relative; flex: none; width: 68px; height: 68px; border-radius: 50%; background: var(--bg); border: 1px solid var(--line-2); }
.gate::before, .gate::after { content: ""; position: absolute; background: var(--line); }
.gate::before { left: 50%; top: 8px; bottom: 8px; width: 1px; }
.gate::after { top: 50%; left: 8px; right: 8px; height: 1px; }
.stick-trail { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.stick-trail path { fill: none; stroke: var(--seat); stroke-width: 5; stroke-linecap: round; opacity: 0; }
.ball {
  position: absolute; left: 50%; top: 50%; z-index: 1; pointer-events: none;
  width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%;
  background: #3a3f4a; border: 1px solid #4a505c;
}
.ball.on { background: var(--seat); border-color: var(--seat); }
.buttons { display: grid; grid-template-columns: repeat(3, 24px); gap: 6px; }
.buttons.neo { grid-template-columns: repeat(4, 24px); }
.key {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg); border: 1px solid var(--line-2); font: 600 9px ui-monospace, Menlo, monospace; color: var(--faint);
}
.key.on { background: var(--c); border-color: var(--c); color: #0b0c0f; }

.fold {
  width: 100%; flex: none; display: flex; align-items: center; justify-content: space-between; height: 30px; padding: 0 12px;
  border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--dim); font-size: 12px;
}
.fold:hover { color: var(--text); }
.fold svg { width: 14px; height: 14px; transition: transform 0.15s; }
.fold[aria-expanded="false"] svg { transform: rotate(-90deg); }
.log {
  list-style: none; margin: 0; padding: 0 0 4px; border-top: 1px solid var(--line);
  flex: 1; min-height: 120px; overflow: hidden;
  font: 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.fold[aria-expanded="false"] + .log { display: none; }
.log li { display: grid; grid-template-columns: 30px 18px 1fr; align-items: center; gap: 6px; height: 21px; padding: 0 12px; }
.log li:first-child { background: var(--raise); }
.log .n { color: var(--faint); text-align: right; font-variant-numeric: tabular-nums; }
.log .dir { color: var(--text); text-align: center; font-size: 13px; }
.log .dir.neutral { color: var(--faint); }
.log .ks { display: flex; gap: 3px; }
.log .k { min-width: 18px; height: 15px; padding: 0 3px; border-radius: 2px; display: grid; place-items: center; font-size: 9px; font-weight: 700; background: var(--c); color: #0b0c0f; }
.log .k.sys { background: var(--line-2); color: var(--dim); }
.log:empty::before { content: "No inputs yet"; display: block; padding: 10px 12px; color: var(--faint); font-family: inherit; }

/* Sheets (dialogs) */
.sheet {
  width: min(460px, calc(100vw - 32px)); padding: 0; border-radius: 8px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line-2); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin: 0; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.share .copy-row { display: flex; gap: 6px; padding: 14px 16px 8px; }
.share .copy-row input {
  flex: 1; min-width: 0; height: 30px; padding: 0 10px; border-radius: 4px; background: var(--bg);
  border: 1px solid var(--line-2); font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; outline: none;
}
.check { display: flex; align-items: center; gap: 8px; padding: 0 16px 12px; color: var(--dim); cursor: pointer; }
.check input { accent-color: var(--text); margin: 0; }
.check b { color: var(--text); font: 500 12px ui-monospace, Menlo, monospace; }
.targets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 4px 16px 16px; }
.share-brand {
  height: 44px; border: 0; border-radius: 6px; color: #fff; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; cursor: pointer;
}
.share-brand svg { width: 18px; height: 18px; flex: none; }
.share-brand.reddit { background: #ff4500; }
.share-brand.discord { background: #5865f2; }
.share-brand.x { background: #000; box-shadow: inset 0 0 0 1px #2f3336; }
.share-brand.whatsapp { background: #25d366; }
.share-brand:hover { filter: brightness(1.08); }
.clip { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.clip p { margin: 0; color: var(--dim); }
.clip .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.clip b { font: 500 12px ui-monospace, Menlo, monospace; color: var(--text); }
.clip .actions { display: flex; justify-content: flex-end; gap: 8px; }
.clip a { color: var(--text); }

.comments { padding: 0 var(--gap) 28px; }
.comments-inner { max-width: 720px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.comments-head { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.comments-head h2 { margin: 0; font: 700 13px/1 var(--display); letter-spacing: 0.08em; text-transform: uppercase; }
.comments-head .me { display: inline-flex; align-items: center; gap: 8px; color: var(--dim); }
.comments-head .me img, .comment img, .mention-menu img { border-radius: 50%; display: block; background: var(--raise); }
.btn.discord-login { background: #5865f2; border-color: #5865f2; color: #fff; }
.btn.discord-login:hover { filter: brightness(1.08); background: #5865f2; }
#comment-list { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow: auto; }
.comment-empty { padding: 16px 12px; color: var(--dim); }
.comment { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.comment .who { grid-column: 1; display: flex; align-items: center; gap: 8px; min-width: 0; text-decoration: none; }
.comment .who img { width: 28px; height: 28px; flex: none; }
.comment .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.comment .handle, .mention-menu .handle { color: var(--faint); font-weight: 400; margin-left: 6px; }
.comment-meta { grid-column: 2; grid-row: 1; display: flex; align-items: center; gap: 8px; }
.comment time { color: var(--faint); font-size: 12px; }
.comment p { grid-column: 1 / -1; margin: 0; white-space: pre-wrap; word-break: break-word; }
.comment-delete { border: 0; background: transparent; color: var(--faint); font-size: 12px; padding: 0; }
.comment-delete:hover { color: var(--text); }
.time-tag, .mention { display: inline; margin: 0 1px; padding: 0 4px; border-radius: 3px; border: 0; font: inherit; font-weight: 600; }
.time-tag { background: var(--raise); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.time-tag:hover { background: #20242c; }
.mention { color: var(--p2); text-decoration: none; }
.comment-compose { position: relative; padding: 10px 12px 0; }
.comment-compose textarea {
  width: 100%; min-height: 68px; resize: vertical; padding: 8px; border-radius: 4px;
  background: var(--bg); border: 1px solid var(--line-2); outline: none;
}
.comment-compose textarea:focus { border-color: #5a5f6b; }
.mention-menu {
  position: absolute; left: 12px; right: 12px; bottom: calc(100% - 10px); z-index: 2;
  background: var(--raise); border: 1px solid var(--line-2); border-radius: 4px; overflow: hidden;
}
.mention-menu button { width: 100%; display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 0; background: transparent; text-align: left; }
.mention-menu button:hover { background: #20242c; }
.comment-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px 10px; }
#comment-count { margin-left: auto; color: var(--faint); font-size: 12px; }

.toast { position: fixed; left: 50%; bottom: 18px; transform: translate(-50%, 12px); opacity: 0; background: var(--raise); border: 1px solid var(--line-2); padding: 7px 12px; border-radius: 4px; transition: all 0.15s; z-index: 60; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Narrower screens: the screen spans the page, both input panels sit under it. */
@media (max-width: 1180px) {
  :root { --cols: 1fr 1fr; --match-h: 84px; }
  .fighter { padding: 0 16px; gap: 12px; }
  .avatar { width: 52px; height: 52px; font-size: 18px; }
  .fighter .name { font-size: 24px; color: var(--text); }
  .fighter-stats { display: none; }
  .score-core { grid-template-columns: 68px auto 68px; padding: 0 18px; }
  .sb-num { font-size: 42px; }
  .layout { height: auto; min-height: 0; }
  .center { grid-column: 1 / -1; grid-row: 1; }
  .log { flex: none; height: 180px; }
}
@media (max-width: 1180px) and (min-height: 820px) {
  .player-box { width: min(100%, calc((100dvh - var(--bar-h) - var(--match-h) - 220px) * 4 / 3), 960px); margin-inline: auto; }
}
@media (max-width: 760px) {
  :root { --bar-h: 44px; --match-h: 58px; }
  .appbar { gap: 8px; padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left)); }
  .brand { font-size: 0; gap: 0; }
  .search input, .search .btn, #btn-share { height: 32px; }
  .avatar, .fighter-sub, .rank-tag { display: none; }
  .fighter { padding: 0 8px; gap: 6px; }
  .fighter .name { font-size: 18px; letter-spacing: 0; }
  .badge { width: 16px; height: 16px; }
  .fighter-name { gap: 4px; }
  .score-core { grid-template-columns: 34px auto 34px; padding: 0 8px; clip-path: none; }
  .sb-num { font-size: 26px; margin: 4px 0 0; }
  .sb-num.p1, .sb-num.p2 { clip-path: none; }
  .sb-mid { min-width: 40px; margin-top: 4px; padding: 0 4px; }
  .sb-ft { font-size: 15px; }
  .sb-game { font-size: 10px; letter-spacing: 0.08em; }
  .sb-meta { display: none; }
  /* Both sticks share one row under the picture. */
  .layout { grid-template-columns: 1fr 1fr; padding: 8px; }
  .side.p1 { grid-column: 1; grid-row: 2; }
  .side.p2 { grid-column: 2; grid-row: 2; }
  .pad { flex-direction: column; gap: 8px; padding: 10px 6px; }
  .side-head { height: 30px; padding: 0 8px; gap: 6px; }
  /* History stays on a wide screen. On a phone the sticks are the readout. */
  .fold, .log { display: none; }
  .volume input[type="range"], .statusline .keys { display: none; }
  .controls { flex-wrap: wrap; padding-bottom: max(4px, env(safe-area-inset-bottom)); justify-content: center; }
  #btn-restart, #speed, .volume, #btn-full, #btn-export, #btn-share-bar { order: 6; }
  #speed { flex: 1 1 auto; justify-content: center; }
  .controls::after { content: ""; order: 5; flex-basis: 100%; height: 0; }
}
/* Short phone: shrink the picture only. The transport stays the full width. */
@media (max-width: 760px) and (max-height: 700px) {
  .stage {
    width: min(100%, calc((100dvh - var(--bar-h) - var(--match-h) - 300px) * 4 / 3));
    margin-inline: auto;
  }
}
@media (pointer: coarse) and (max-width: 1180px) {
  .icon-btn { width: 36px; height: 36px; }
  .stage .timeline { height: 52px; }
  .segmented button { padding: 6px 9px; }
}
/* Short landscape: keep the picture and the transport on screen, and drop the tall input panels. */
@media (max-height: 520px) {
  :root { --bar-h: 40px; --match-h: 46px; }
  .appbar { gap: 8px; padding: 0 8px; }
  .brand { font-size: 0; gap: 0; }
  .search input, .search .btn, #btn-share { height: 28px; }
  .avatar, .fighter-sub, .fighter-stats, .rank-tag, .sb-meta, .sb-game, .statusline { display: none; }
  .fighter { padding: 0 8px; gap: 6px; }
  .fighter .name { font-size: 16px; color: var(--text); }
  .badge { width: 16px; height: 16px; }
  .matchup { height: var(--match-h); }
  .score-core { grid-template-columns: 32px auto 32px; padding: 0 6px; clip-path: none; }
  .sb-num { font-size: 24px; margin: 0; }
  .sb-num.p1, .sb-num.p2 { clip-path: none; }
  .sb-mid { min-width: 36px; margin: 0; padding: 0 4px; }
  .sb-ft { font-size: 14px; }
  .layout {
    height: calc(100dvh - var(--bar-h) - var(--match-h));
    min-height: 0; grid-template-columns: 1fr; padding: 6px; overflow: hidden;
  }
  .center { grid-column: auto; grid-row: auto; height: 100%; min-height: 0; gap: 0; }
  .side { display: none; }
  .player-box {
    width: min(100%, calc((100dvh - var(--bar-h) - var(--match-h) - 52px) * 4 / 3));
    max-height: 100%; margin-inline: auto;
  }
  .controls { flex-wrap: nowrap; min-height: 36px; padding: 2px 6px; }
  #btn-restart, #btn-mute { display: none; }
  #speed { flex: none; order: 0; }
  #speed button[data-speed="0.5"] { display: none; }
  .segmented button { padding: 4px 6px; }
  .volume input[type="range"] { display: none; }
}
/* Phone held sideways: the picture stays, and both sticks share one short row. */
@media (max-height: 520px) and (max-width: 900px) {
  .layout { grid-template-columns: 1fr 1fr; grid-template-rows: minmax(0, 1fr) auto; overflow: hidden; }
  .center { grid-column: 1 / -1; grid-row: 1; }
  .side { display: flex; grid-row: 2; }
  .side.p1 { grid-column: 1; }
  .side.p2 { grid-column: 2; }
  .fold, .log { display: none; }
  .side-head { height: 22px; padding: 0 6px; justify-content: center; }
  .side-head span:last-child { display: none; }
  .pad { flex-direction: row; align-items: center; gap: 8px; padding: 6px; }
  /* Six buttons stay two rows of three. Four-button games stay one row via .neo. */
  .buttons { grid-template-columns: repeat(3, 22px); }
  .buttons.neo { grid-template-columns: repeat(4, 22px); }
  .key { width: 22px; height: 22px; }
  .player-box { width: 100%; max-height: none; }
  .stage {
    width: min(100%, calc((100dvh - var(--bar-h) - var(--match-h) - 130px) * 4 / 3));
    margin-inline: auto;
  }
  .controls { flex-wrap: nowrap; }
  .controls::after { display: none; }
  #speed { flex: none; }
}
