:root {
  --bg: #14121c;
  --panel: #1d1a29;
  --line: #2e2a40;
  --text: #ece9f6;
  --muted: #9a94b3;
  --accent: #3ddc97;
  --warn: #ffb547;
  --bad: #ff5d6c;
  --btn: #2a2639;
  --btn-down: #45405e;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }

.shell {
  min-height: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bar { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.brand { color: var(--muted); letter-spacing: .02em; white-space: nowrap; }
.brand b { color: var(--text); }
.who { color: var(--text); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.players { display: flex; gap: 6px; margin-left: auto; }
.players span {
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.players span.on { border-color: var(--accent); color: var(--accent); }
.players span.me { font-weight: 700; }
.stats { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; min-width: 150px; text-align: right; }
.stats.warn { color: var(--warn); }
.stats.bad { color: var(--bad); }

.screen-wrap {
  position: relative;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  aspect-ratio: 3 / 2;
  width: 100%;
  max-height: calc(100vh - 150px);
  margin: 0 auto;
}
#screen {
  width: 100%; height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: rgba(20, 18, 28, .88);
  text-align: center; padding: 16px;
}
.overlay[hidden] { display: none; }
.overlay h1 { margin: 0; font-size: 22px; }
.overlay p { margin: 0 0 8px; color: var(--muted); max-width: 420px; }

button {
  font: inherit; color: var(--text); background: var(--btn);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #06281a; border: 0; font-weight: 700; padding: 12px 28px; font-size: 16px; }
button.ghost { background: transparent; }

.foot { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 8px; }

@media (max-width: 480px) {
  .bar { gap: 8px; font-size: 13px; flex-wrap: wrap; }
  .brand { display: none; }
  .stats { min-width: 0; }
}

/* Comandos táteis: só em ecrãs de toque */
.touch { display: none; }
@media (pointer: coarse) {
  .foot .keys { display: none; }
  .touch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "sh sh" "pad ab" "meta meta";
    gap: 14px 8px;
    user-select: none; -webkit-user-select: none; touch-action: none;
  }
  .touch button { touch-action: none; padding: 0; font-weight: 700; }
  .touch button.down-state { background: var(--btn-down); }
  .shoulders { grid-area: sh; display: flex; justify-content: space-between; }
  .shoulders button { width: 96px; height: 40px; border-radius: 10px 10px 6px 6px; }
  .pad {
    grid-area: pad; justify-self: start;
    display: grid; grid-template: repeat(3, 52px) / repeat(3, 52px);
  }
  .pad .up { grid-area: 1 / 2; } .pad .left { grid-area: 2 / 1; }
  .pad .right { grid-area: 2 / 3; } .pad .down { grid-area: 3 / 2; }
  .ab { grid-area: ab; justify-self: end; align-self: center; display: flex; gap: 14px; transform: rotate(-18deg); }
  .ab button { width: 64px; height: 64px; border-radius: 50%; font-size: 18px; }
  .meta { grid-area: meta; display: flex; justify-content: center; gap: 16px; }
  .meta button { width: 84px; height: 30px; border-radius: 999px; font-size: 12px; font-weight: 600; }
  .screen-wrap { max-height: 46vh; }
}
