:root {
  --bg: #0b0d12;
  --panel: #151922;
  --line: #262c3a;
  --text: #e8ebf2;
  --muted: #8b93a7;
  --accent: #3ddc84;
  --warn: #ffb020;
  --bad: #ff7083;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
header h1 { font-size: 17px; margin: 0; letter-spacing: .02em; }
header .grow { flex: 1; }
main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.layout { display: grid; grid-template-columns: 1fr 320px; gap: 16px; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.panel h2 { font-size: 13px; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; letter-spacing: .06em; }
.panel + .panel { margin-top: 12px; }
.stage { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 16/9; }
.stage video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.stage .overlay {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  color: var(--muted); pointer-events: none; padding: 20px;
}
.hud {
  position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 8px; flex-wrap: wrap;
  pointer-events: none;
}
.chip {
  background: rgba(0,0,0,.6); border: 1px solid rgba(255,255,255,.12); border-radius: 999px;
  padding: 3px 10px; font-size: 12px; color: var(--text); white-space: nowrap;
}
.chip.ok { border-color: var(--accent); color: var(--accent); }
.chip.warn { border-color: var(--warn); color: var(--warn); }
.chip.bad { border-color: var(--bad); color: var(--bad); }
button {
  font: inherit; color: var(--text); background: #232a39; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
button:hover { background: #2c3446; }
button.primary { background: var(--accent); color: #062312; border-color: transparent; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { border-color: var(--bad); color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
input {
  font: inherit; color: var(--text); background: #0f1218; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
label { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 4px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.big { font-size: 22px; font-weight: 700; }
ol.queue { margin: 0; padding-left: 20px; }
ol.queue li.me { color: var(--accent); font-weight: 600; }
.turn {
  border: 2px solid var(--accent); border-radius: 10px; padding: 12px; text-align: center;
  background: rgba(61,220,132,.08);
}
.keys { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 13px; }
.keys kbd {
  font: 12px ui-monospace, monospace; background: #0f1218; border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 5px; justify-self: start;
}
.pad { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.pad span { font-size: 11px; padding: 2px 6px; border-radius: 4px; background: #0f1218; color: var(--muted); }
.pad span.on { background: var(--accent); color: #062312; }
[hidden] { display: none !important; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: #232a39; border: 1px solid var(--warn); color: var(--text); border-radius: 10px;
  padding: 10px 16px; max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.err { color: var(--bad); margin-top: 8px; min-height: 1.2em; font-size: 13px; }

/* ---------- tela cheia ---------- */
.stage:fullscreen, .stage.fake-full {
  width: 100vw; height: 100vh; height: 100dvh; aspect-ratio: auto; border-radius: 0;
}
.stage.fake-full { position: fixed; inset: 0; z-index: 50; }
.stage:fullscreen .hud, .stage.fake-full .hud { justify-content: center; top: 6px; }
.stage:fullscreen .hud .chip:not(#chipTurn):not(#chipRtt),
.stage.fake-full .hud .chip:not(#chipTurn):not(#chipRtt) { display: none; }

/* ---------- controle de Xbox na tela ---------- */
.touchpad {
  position: absolute; inset: 0; z-index: 5; user-select: none; -webkit-user-select: none;
  touch-action: none; -webkit-touch-callout: none; pointer-events: none;
  --u: min(9vmin, 64px); /* tamanho de um botão */
}
.touchpad > * { pointer-events: auto; position: absolute; }
.tp-b {
  width: var(--u); height: var(--u); border-radius: 50%; padding: 0;
  background: rgba(20,24,32,.42); border: 2px solid rgba(255,255,255,.35); color: rgba(255,255,255,.9);
  font: 700 calc(var(--u) * .34)/1 system-ui, sans-serif; touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.tp-b:hover { background: rgba(20,24,32,.42); }
.tp-b.on { background: rgba(255,255,255,.55); color: #000; }
.tp-sm { width: calc(var(--u) * .78); height: calc(var(--u) * .78); font-size: calc(var(--u) * .3); }
.tp-join { width: auto; border-radius: 999px; padding: 0 14px; background: var(--accent); color: #062312; border: 0; }
.tp-sh { top: 10px; display: flex; gap: 8px; }
.tp-sh .tp-b { width: calc(var(--u) * 1.6); border-radius: 12px; height: calc(var(--u) * .8); }
.tp-left { left: max(12px, env(safe-area-inset-left)); }
.tp-right { right: max(12px, env(safe-area-inset-right)); flex-direction: row; }
.tp-mid { top: 46px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; }
.tp-stick {
  width: calc(var(--u) * 2.3); height: calc(var(--u) * 2.3); border-radius: 50%;
  background: rgba(20,24,32,.3); border: 2px solid rgba(255,255,255,.25); touch-action: none;
}
.tp-knob {
  position: absolute; left: 50%; top: 50%; width: 46%; height: 46%; margin: -23% 0 0 -23%;
  border-radius: 50%; background: rgba(255,255,255,.45); pointer-events: none;
}
.tp-ls { left: max(24px, env(safe-area-inset-left)); bottom: calc(var(--u) * 1.9); }
.tp-l3 { left: calc(max(24px, env(safe-area-inset-left)) + var(--u) * 2.3); bottom: calc(var(--u) * 3.6); }
.tp-dpad { left: calc(max(24px, env(safe-area-inset-left)) + var(--u) * 2.6); bottom: 14px;
  width: calc(var(--u) * 2.4); height: calc(var(--u) * 2.4); }
.tp-dpad .tp-b { position: absolute; border-radius: 10px; width: calc(var(--u) * .8); height: calc(var(--u) * .8); }
.tp-dpad .up { left: 33%; top: 0; } .tp-dpad .down { left: 33%; bottom: 0; }
.tp-dpad .left { left: 0; top: 33%; } .tp-dpad .right { right: 0; top: 33%; }
.tp-rs { right: calc(max(24px, env(safe-area-inset-right)) + var(--u) * 3.6); bottom: 14px; }
.tp-r3 { right: calc(max(24px, env(safe-area-inset-right)) + var(--u) * 4.4); bottom: calc(var(--u) * 2.9); }
.tp-abxy { right: max(24px, env(safe-area-inset-right)); bottom: calc(var(--u) * 1.4);
  width: calc(var(--u) * 3.1); height: calc(var(--u) * 3.1); }
.tp-abxy .tp-b { position: absolute; }
.tp-abxy .y { left: 50%; top: 0; transform: translateX(-50%); color: #ffd84d; }
.tp-abxy .a { left: 50%; bottom: 0; transform: translateX(-50%); color: #5fe08f; }
.tp-abxy .x { left: 0; top: 50%; transform: translateY(-50%); color: #6fb0ff; }
.tp-abxy .b { right: 0; top: 50%; transform: translateY(-50%); color: #ff7a7a; }
.tp-abxy .tp-b.on { color: #000; }
.touchpad.off .tp-b:not(#tpExit):not(#tpJoin):not(#tpSound), .touchpad.off .tp-stick { opacity: .35; }
@media (orientation: portrait) {
  .touchpad { --u: min(11vw, 56px); }
}
.picker { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; z-index: 10; padding: 16px; }
.picker-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px;
  width: min(980px, 100%); max-height: 90vh; overflow: auto; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.picker-item { display: flex; flex-direction: column; gap: 6px; padding: 8px; text-align: left; }
.picker-item img { width: 100%; aspect-ratio: 16/9; object-fit: contain; background: #000; border-radius: 6px; }
.picker-item span { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
td { padding: 4px 2px; border-bottom: 1px solid var(--line); }
