:root {
  --bg: #07090d;
  --panel: #10141c;
  --panel-2: #161c27;
  --line: #262f3f;
  --text: #e6ebf3;
  --muted: #8b96a8;
  --accent: #4fa3ff;
  --accent-2: #9b6bff;
  --danger: #ff6b6b;
  --ok: #6fd391;
  --warn: #ffc65c;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { overflow: hidden; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }

#canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; outline: none; background: #000; }

/* ---------------------------------------------------------------- screens -- */
.screen {
  position: fixed; inset: 0; z-index: 2; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: max(40px, 8vh) 16px 32px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(79,163,255,0.16), transparent 60%),
    radial-gradient(900px 500px at 100% 110%, rgba(155,107,255,0.12), transparent 60%),
    var(--bg);
}
.screen > * { width: 100%; max-width: 560px; }

.brand { text-align: center; }
.logo {
  margin: 0; font-size: clamp(34px, 8vw, 58px); line-height: 1; letter-spacing: 0.06em; font-weight: 800;
  font-style: italic;
  background: linear-gradient(180deg, #e9f3ff 10%, #7fb8ff 55%, #2f6fd8 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 18px rgba(79,163,255,0.35));
}
.logo span { letter-spacing: 0.1em; }
.brand.small .logo { font-size: 30px; }
.tagline { margin: 10px auto 0; color: var(--muted); max-width: 440px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { margin: 0 0 6px; font-size: 20px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }

input:not([type]), input[type="text"], #nick, #nick2, #inviteUrl, #snapName {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; outline: none;
}
input:focus-visible { border-color: var(--accent); }

.modes { display: grid; gap: 10px; }
.mode {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 16px 18px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; transition: border-color .15s, transform .05s, background .15s;
}
.mode:hover:not(:disabled) { border-color: #3b4a63; background: var(--panel-2); }
.mode:active:not(:disabled) { transform: translateY(1px); }
.mode:disabled { opacity: 0.5; cursor: default; }
.mode.accent { border-color: rgba(79,163,255,0.55); background: linear-gradient(180deg, rgba(79,163,255,0.14), rgba(79,163,255,0.04)); }
.mode-title { font-size: 18px; font-weight: 650; }
.mode-sub { color: var(--muted); font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #3b4a63; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06111f; font-weight: 650; }
.btn.primary:disabled { opacity: 0.5; cursor: default; }
.btn.ghost { background: transparent; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }

.match-head { display: flex; gap: 14px; align-items: center; }
.match-title { font-weight: 650; font-size: 17px; }
.match-status { color: var(--muted); min-height: 1.5em; }
.invite { display: flex; gap: 8px; margin-top: 14px; }
.match-actions { display: flex; justify-content: flex-end; margin-top: 12px; }

.stats { text-align: center; color: var(--muted); font-size: 13px; min-height: 1.5em; margin: 0; }
.stats b { color: var(--text); font-weight: 600; }
.links { display: flex; justify-content: center; gap: 4px 18px; flex-wrap: wrap; }
.link { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; }
.link:hover { color: var(--text); }
.load-state { text-align: center; color: var(--muted); font-size: 13px; margin: 0; }
.notice { background: rgba(255,198,92,0.1); border: 1px solid rgba(255,198,92,0.35); color: #ffe2a8;
  border-radius: var(--radius); padding: 12px 14px; white-space: pre-wrap; }

/* ---------------------------------------------------------------- overlays -- */
.cover { position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; background: #000; color: var(--text); padding: 16px; text-align: center; }
.cover.dim { background: rgba(0,0,0,0.6); backdrop-filter: blur(3px); }
.prep-vs { font-size: 20px; font-weight: 650; }
.prep-vs .vs { color: var(--accent); margin: 0 10px; font-style: italic; }
.pause { display: flex; flex-direction: column; gap: 10px; min-width: min(300px, 90vw); text-align: center; }

.spinner { width: 30px; height: 30px; flex: none; border: 3px solid #2a3343; border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.9s linear infinite; }
.spinner.big { width: 42px; height: 42px; }
.spinner.done { animation: none; border-color: var(--ok); }
@keyframes spin { to { transform: rotate(360deg); } }

.hud { position: fixed; left: 10px; top: 10px; z-index: 3; font-size: 12px; color: #a9e2bd;
  background: rgba(0,0,0,0.55); padding: 4px 9px; border-radius: 6px; pointer-events: none; }
.hud.warn { color: var(--warn); }
.hud.bad { color: var(--danger); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 6;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 16px;
  max-width: calc(100vw - 32px); box-shadow: 0 8px 30px rgba(0,0,0,0.5); }

.menu-btn { position: fixed; right: 10px; top: 10px; z-index: 3; width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--line); background: rgba(16,20,28,0.7); cursor: pointer; opacity: 0; transition: opacity .2s; }
body:hover .menu-btn, .menu-btn:focus-visible { opacity: 1; }
@media (hover: none) { .menu-btn { opacity: 0.8; } }

/* ---------------------------------------------------------------- dialogs -- */
.dialog { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; }
.dialog::backdrop { background: rgba(0,0,0,0.6); }
.dialog form { padding: 18px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dialog-head h2 { margin: 0; font-size: 20px; }
.close { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 8px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 6px 0 14px; overflow-x: auto; }
.tabs button { background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 12px;
  color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab { display: none; }
.tab.active { display: block; }
.toggle { display: flex; gap: 10px; align-items: flex-start; color: var(--text); font-size: 15px; margin: 10px 0; cursor: pointer; }
.toggle input { margin-top: 4px; accent-color: var(--accent); }
.toggle small { display: block; color: var(--muted); font-size: 13px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.keys { width: 100%; border-collapse: collapse; font-size: 14px; }
.keys th, .keys td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.keys th { color: var(--muted); font-weight: 500; }
.pad-status { background: var(--panel-2); border-radius: 8px; padding: 8px 12px; color: var(--muted); }
.pad-status.on { color: var(--ok); }
.dialog h3 { font-size: 15px; margin: 18px 0 4px; }

@media (max-width: 480px) {
  .screen { padding-top: 28px; }
  .invite { flex-wrap: wrap; }
}

/* ------------------------------------------------------- versus select -- */
.select {
  --p1: #ff4d5e; --p2: #3d8bff;
  position: fixed; inset: 0; z-index: 3; outline: none; overflow: hidden;
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 10px 20px; padding: 44px 24px 12px;
  user-select: none; -webkit-user-select: none;
}
.sel-bg { position: absolute; inset: 0; z-index: -1;
  background:
    linear-gradient(105deg, rgba(255,77,94,0.22) 0 30%, transparent 30.2% 69.8%, rgba(61,139,255,0.22) 70%),
    repeating-linear-gradient(105deg, rgba(255,255,255,0.025) 0 2px, transparent 2px 14px),
    radial-gradient(800px 500px at 50% 45%, #141a28, #05070b 75%); }
.sel-top { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: center; gap: 16px; }
.sel-title { font-size: clamp(20px, 3.2vw, 34px); font-weight: 900; font-style: italic; letter-spacing: 0.12em;
  text-transform: uppercase; background: linear-gradient(180deg, #fff, #9cc6ff 60%, #4a7fe0);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 12px rgba(79,163,255,0.4)); }
.sel-round { color: var(--warn); font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }

.sel-side { grid-row: 2; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; min-width: 0; text-align: center; }
.sel-side.p1 { grid-column: 1; --pc: var(--p1); }
.sel-side.p2 { grid-column: 3; --pc: var(--p2); }
.sel-player { font-weight: 700; display: flex; align-items: center; gap: 8px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel-player .tag, .sel-help .c1, .sel-help .c2 { font-weight: 900; font-style: italic; color: var(--pc); }
.sel-help .c1 { color: var(--p1); } .sel-help .c2 { color: var(--p2); }
.sel-player .tag { font-size: 22px; text-shadow: 0 0 12px var(--pc); }
.sel-player .me { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.sel-portrait { width: min(22vw, 30vh, 240px); aspect-ratio: 1; position: relative;
  filter: drop-shadow(0 0 28px hsl(var(--h) 80% 50% / 0.45)); animation: sel-pop 0.25s ease-out; }
.sel-portrait::after { content: ""; position: absolute; inset: -6%; border-radius: 50%;
  border: 2px solid var(--pc); opacity: 0.6; transform: skewX(-8deg); }
.sel-portrait svg { width: 100%; height: 100%; display: block; }
.sel-fighter { font-size: clamp(22px, 3vw, 38px); font-weight: 900; font-style: italic; text-transform: uppercase;
  letter-spacing: 0.04em; line-height: 1.05; text-shadow: 0 2px 0 rgba(0,0,0,0.6), 0 0 18px hsl(var(--h) 80% 50% / 0.5); }
.sel-fighter small, .sel-name small { display: block; font-size: 0.45em; letter-spacing: 0.2em; color: var(--muted); font-style: normal; }
.sel-state { font-size: 13px; font-weight: 800; letter-spacing: 0.2em; text-transform: uppercase; color: var(--muted);
  padding: 3px 14px; border-radius: 3px; transform: skewX(-12deg); border: 1px solid var(--line); }
.sel-state.ready { color: #fff; background: var(--pc); border-color: transparent; box-shadow: 0 0 18px var(--pc);
  animation: sel-pop 0.2s ease-out; }

.sel-grid { grid-column: 2; grid-row: 2; align-self: center; display: grid; grid-template-columns: repeat(14, 1fr);
  gap: 6px; width: min(46vw, calc((100vh - 170px) * 7 / 7), 620px); }
.select.stage-mode .sel-grid { width: min(46vw, calc((100vh - 290px) * 7 / 7), 620px); }
.sel-cell { grid-column: span 2; position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 6px; cursor: pointer;
  background: linear-gradient(160deg, hsl(var(--h) 40% 18%), #0b0e15 70%); overflow: hidden;
  transform: skewX(-6deg); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08); transition: transform 0.08s; }
.sel-cell { container-type: inline-size; }
@container (max-width: 54px) { .sel-name { display: none; } .sel-cell svg { margin-top: 11%; } }
.sel-cell svg { width: 78%; height: 78%; margin: 4% auto 0; display: block; transform: skewX(6deg); }
.sel-name { position: absolute; left: 0; right: 0; bottom: 0; padding: 2px 3px 3px; font-size: clamp(8px, 0.85vw, 11px);
  font-weight: 800; text-transform: uppercase; line-height: 1.05; transform: skewX(6deg);
  background: linear-gradient(transparent, rgba(0,0,0,0.85) 40%); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sel-name small { display: none; }
.sel-tag { position: absolute; top: 2px; font-size: 10px; font-weight: 900; font-style: italic; padding: 0 4px;
  border-radius: 3px; color: #fff; display: none; transform: skewX(6deg); }
.sel-tag.t1 { left: 3px; background: var(--p1); } .sel-tag.t2 { right: 3px; background: var(--p2); }
.sel-cell.c1, .sel-cell.l1 { box-shadow: inset 0 0 0 3px var(--p1), 0 0 16px var(--p1); z-index: 1; }
.sel-cell.c2, .sel-cell.l2 { box-shadow: inset 0 0 0 3px var(--p2), 0 0 16px var(--p2); z-index: 1; }
.sel-cell.c1.c2, .sel-cell.c1.l2, .sel-cell.l1.c2 { box-shadow: inset 3px 3px 0 0 var(--p1), inset -3px -3px 0 0 var(--p2), 0 0 16px #b06bff; }
.sel-cell.c1 .t1, .sel-cell.l1 .t1, .sel-cell.c2 .t2, .sel-cell.l2 .t2 { display: block; }
.sel-cell.l1, .sel-cell.l2 { transform: skewX(-6deg) scale(1.06); }
.sel-cell.taken:not(.l1.l2) { filter: saturate(0.6); }
.sel-cell.flash::before { content: ""; position: absolute; inset: 0; background: #fff; animation: sel-flash 0.35s ease-out forwards; }
.sel-cell.shake { animation: sel-shake 0.3s; }
.select.stage-mode .sel-grid { opacity: 0.35; pointer-events: none; }

.sel-stages { grid-column: 1 / -1; grid-row: 3; text-align: center; animation: sel-pop 0.2s ease-out; }
.sel-stage-title { font-weight: 800; letter-spacing: 0.15em; text-transform: uppercase; margin-bottom: 8px; color: var(--warn); }
.sel-stage-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.sel-stage { width: 92px; padding: 0 0 6px; border: 0; border-radius: 6px; cursor: pointer; font-weight: 800; font-size: 12px;
  text-transform: uppercase; background: #0d1119; transform: skewX(-6deg); box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.sel-stage:disabled { cursor: default; color: inherit; }
.sel-stage-art { display: block; height: 46px; margin-bottom: 5px;
  background: repeating-linear-gradient(90deg, hsl(var(--h) 60% 40% / 0.5) 0 2px, transparent 2px 10px),
    linear-gradient(180deg, hsl(var(--h) 50% 12%), hsl(var(--h) 70% 38%)); }
.sel-stage.random .sel-stage-art { background: conic-gradient(from 0deg, #ff4d5e, #ffc65c, #6fd391, #3d8bff, #9b6bff, #ff4d5e); opacity: 0.7; }
.sel-stage.cur { box-shadow: inset 0 0 0 3px var(--p1), 0 0 14px var(--p1); }
.sel-stage.chosen { box-shadow: inset 0 0 0 3px #fff, 0 0 18px #fff; }

.sel-vs { position: absolute; inset: 0; z-index: 2; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  background: radial-gradient(circle at 50% 50%, #0b0f18, #000 80%); animation: sel-fade 0.25s ease-out; }
.sel-vs-a, .sel-vs-b { text-align: center; }
.sel-vs-a { animation: sel-in-l 0.35s ease-out; } .sel-vs-b { animation: sel-in-r 0.35s ease-out; }
.sel-vs svg { width: min(26vw, 260px); height: auto; }
.sel-vs .n { font-size: clamp(26px, 4vw, 52px); font-weight: 900; font-style: italic; text-transform: uppercase; }
.sel-vs-a .n { color: var(--p1); text-shadow: 0 0 24px var(--p1); } .sel-vs-b .n { color: var(--p2); text-shadow: 0 0 24px var(--p2); }
.sel-vs .who { color: var(--muted); }
.sel-vs-mark { font-size: clamp(60px, 10vw, 140px); font-weight: 900; font-style: italic; padding: 0 2vw;
  background: linear-gradient(180deg, #fff, #ffd36b 50%, #ff7a2f); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 24px rgba(255,160,60,0.6)); animation: sel-pop 0.4s ease-out; }
.sel-vs-load { position: absolute; left: 0; right: 0; bottom: 8vh; display: flex; gap: 10px; justify-content: center;
  align-items: center; color: var(--muted); }
.sel-vs-load .spinner { width: 18px; height: 18px; }

.sel-help { grid-column: 1 / -1; grid-row: 4; display: flex; flex-wrap: wrap; gap: 6px 22px; justify-content: center;
  color: var(--muted); font-size: 12px; }
.sel-help kbd { display: inline-block; min-width: 18px; padding: 0 4px; margin-right: 2px; border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 4px; font: 11px/16px system-ui, sans-serif; text-align: center; color: var(--text); }

@keyframes sel-pop { from { transform: scale(0.9); opacity: 0.4; } }
@keyframes sel-flash { from { opacity: 0.9; } to { opacity: 0; } }
@keyframes sel-shake { 25% { translate: -5px 0; } 75% { translate: 5px 0; } }
@keyframes sel-fade { from { opacity: 0; } }
@keyframes sel-in-l { from { transform: translateX(-40vw); } }
@keyframes sel-in-r { from { transform: translateX(40vw); } }

@media (max-aspect-ratio: 1/1) {
  .select { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    padding: 44px 16px 10px; gap: 8px 12px; }
  .sel-side { grid-row: 2; gap: 4px; } .sel-side.p2 { grid-column: 2; }
  .sel-portrait { width: min(24vw, 15vh); }
  .sel-fighter { font-size: 18px; }
  .sel-state { font-size: 11px; }
  .sel-grid, .select.stage-mode .sel-grid { grid-column: 1 / -1; grid-row: 3; justify-self: center; gap: 4px;
    width: min(100%, calc((100vh - 330px) * 7 / 7)); }
  .select.stage-mode .sel-grid { width: min(100%, calc((100vh - 430px) * 7 / 7)); }
  .sel-stages { grid-row: 4; } .sel-help { grid-row: 5; gap: 4px 12px; }
  .sel-stage { width: 58px; font-size: 10px; } .sel-stage-art { height: 30px; }
  .sel-top { justify-content: flex-end; }
  .sel-title { font-size: 17px; }
}
@media (max-height: 620px) and (min-aspect-ratio: 1/1) {
  .select { padding-top: 40px; gap: 6px 14px; }
  .sel-title { font-size: 18px; }
  .sel-portrait { width: min(20vw, 24vh); }
  .sel-fighter { font-size: 20px; }
  .sel-player .tag { font-size: 17px; }
  .sel-side { gap: 4px; }
  .sel-grid { width: min(46vw, calc((100vh - 130px) * 7 / 7), 620px); gap: 4px; }
  .select.stage-mode .sel-grid { width: min(46vw, calc((100vh - 210px) * 7 / 7), 620px); }
  .sel-stage-row { flex-wrap: nowrap; gap: 5px; }
  .sel-stage { width: 58px; font-size: 9px; } .sel-stage-art { height: 26px; margin-bottom: 3px; }
  .sel-stage-title { margin-bottom: 4px; font-size: 12px; }
  .sel-help { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) { .select *, .select { animation: none !important; transition: none !important; } }

/* Portrait capture: the game stays visible under a small status bar. */
#preparing.capture { inset: auto 0 0 0; padding: 14px; flex-direction: row; justify-content: center;
  background: rgba(0,0,0,0.75); }
#preparing.capture .spinner.big { width: 22px; height: 22px; }

/* Fighter portraits rendered by the game (transparent background). */
.sel-cell img.portrait { width: 100%; height: 100%; object-fit: cover; object-position: 50% 15%; display: block;
  transform: skewX(6deg) scale(1.15); }
.sel-portrait.has-img { aspect-ratio: 6 / 5; width: min(26vw, 36vh, 300px); }
.sel-portrait.has-img::after { border-radius: 10px; inset: -3%; }
.sel-portrait img.portrait { width: 100%; height: 100%; object-fit: contain; display: block; }
.sel-vs .pic { display: flex; justify-content: center; }
.sel-vs .pic img.portrait { width: min(30vw, 340px); height: auto; }
@media (max-aspect-ratio: 1/1) { .sel-portrait.has-img { width: min(30vw, 18vh * 6 / 5); } }
