/* Padel 2D: estilo da marca (cores e fontes) para o lobby, a barra do jogo e o painel de ajuste.
   Fontes: Russo One (títulos), Rubik (textos e botões), Press Start 2P (placar e códigos).
   A quadra, os bonecos e a zona de toque são desenhados no canvas (src/render.js), não aqui. */
:root {
  color-scheme: dark;
  --noite: #0F1630; --noite-2: #16204A; --noite-3: #0B1128; --borda: #2A3A7A; --borda-2: #22306A;
  --azul: #1E3FBF; --bola: #D4F23C; --saque: #FF6B3D; --vidro: #BFE6F2; --linha: #F5F7FA; --apagado: #6E7FB0;
  --ok: #3DD6A0;
  --f-titulo: 'Russo One', 'Arial Black', system-ui, sans-serif;
  --f-texto: 'Rubik', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --f-pixel: 'Press Start 2P', ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--noite);
  color: var(--linha);
  font-family: var(--f-texto);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0);
  background: #1b1f27;
}

/* Barra única no rodapé: voltar, dropdown de cenário e ícones. */
#bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0));
  background: var(--noite-3);
  border-top: 1px solid var(--noite-2);
}

#scenario {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1.5px solid var(--borda);
  background: var(--noite);
  color: var(--linha);
}

#bar button[hidden] { display: none; }

button {
  font: inherit;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1.5px solid var(--borda);
  background: var(--noite-2);
  color: var(--linha);
  touch-action: manipulation;
}
button:active { background: var(--borda); }
button.active { background: var(--bola); border-color: var(--bola); color: var(--noite); }
button.icon { padding: 5px 0; width: 40px; height: 36px; font-size: 16px; line-height: 1.2; text-align: center; color: var(--vidro); }
button.icon.active { color: var(--noite); }
button.wa { color: #25d366; display: inline-flex; align-items: center; justify-content: center; }

#stage {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#stats {
  position: absolute;
  right: 6px;
  top: 4px;
  pointer-events: none;
  font: 11px ui-monospace, Menlo, Consolas, monospace;
  color: rgba(255, 255, 255, 0.85);
  white-space: pre;
  text-align: right;
  text-shadow: 0 1px 2px #000;
}

/* ---------- Painel de ajuste ---------- */
#tuning {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: auto;
  background: var(--noite-3);
  overflow-y: auto;
  padding: 0 14px calc(20px + env(safe-area-inset-bottom, 0));
  z-index: 10;
  font-size: 13px;
}
#tuning[hidden] { display: none; }

.tuning-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  /* Congelado no topo enquanto a lista rola; cobre a margem lateral do painel e traz a folga do
     recorte da tela (o painel não tem padding em cima). */
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0 -14px 8px;
  padding: calc(12px + env(safe-area-inset-top, 0)) 14px 10px;
  background: var(--noite-3);
  border-bottom: 1px solid var(--noite-2);
}
.tuning-lock-hint { flex-basis: 100%; }
.tuning-header strong { margin-right: auto; font-family: var(--f-titulo); font-weight: 400; font-size: 20px; }
.tuning-header button { border-radius: 999px; padding: 7px 12px; border-color: var(--vidro); background: transparent; }

.tuning-io { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 10px; }
.tuning-io[hidden] { display: none; }
.tuning-io textarea {
  width: 100%;
  font: 11px ui-monospace, Menlo, Consolas, monospace;
  background: var(--noite);
  color: var(--linha);
  border: 1.5px solid var(--borda);
  border-radius: 10px;
  padding: 8px;
  resize: vertical;
}
.tuning-hint { font-size: 11px; color: var(--vidro); }
.tuning-io-buttons { display: flex; gap: 6px; }

.tuning-group {
  margin: 18px 0 8px;
  font-family: var(--f-pixel);
  font-weight: 400;
  color: var(--bola);
  text-transform: uppercase;
  font-size: 9px;
  letter-spacing: 0.04em;
  line-height: 1.6;
}

.tuning-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 6px;
  border-radius: 10px;
  background: rgba(22, 32, 74, 0.55);
  border: 1.5px solid transparent;
}
.tuning-row input[type="range"] { grid-column: 1 / -1; width: 100%; touch-action: pan-y; accent-color: var(--bola); }
/* Controles travados até um toque na linha (evita mudar valores ao rolar a tela). */
.tuning-row input, .tuning-row select { pointer-events: none; opacity: 0.6; }
.tuning-row.armed input, .tuning-row.armed select { pointer-events: auto; opacity: 1; }
.tuning-row.armed { background: var(--noite-2); border-color: var(--bola); }
.tuning-row select {
  grid-column: 1 / -1;
  font: inherit;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1.5px solid var(--borda);
  background: var(--noite);
  color: var(--linha);
}
.tuning-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--bola); }
.tuning-row output { font-family: var(--f-pixel); font-size: 9px; color: var(--bola); }
#bar button:disabled { opacity: 0.35; }

/* ---------- Lobby (index.html) ---------- */
/* O jogo trava a rolagem da página inteira; o lobby rola normalmente. */
html.lobby-page, html.lobby-page body { overflow: auto; height: auto; min-height: 100%; overscroll-behavior: auto; }
html.lobby-page input, html.lobby-page select { -webkit-user-select: text; user-select: text; }
.lobby-body { overflow: auto; height: auto; min-height: 100vh; background: var(--noite); }
#lobby-app { max-width: 560px; margin: 0 auto; padding: calc(14px + env(safe-area-inset-top, 0)) 16px calc(24px + env(safe-area-inset-bottom, 0)); font-size: 14px; line-height: 1.45; }
#lobby-app h1 { margin: 18px 0 18px; text-align: center; font-weight: 400; }
#lobby-app h1 .logo { display: block; height: 120px; width: auto; margin: 0 auto 10px; }
.wordmark { font-family: var(--f-titulo); font-weight: 400; font-size: 26px; letter-spacing: 0.5px; }
.wordmark span { color: var(--bola); }
#lobby-app h2 { font-family: var(--f-titulo); font-weight: 400; font-size: 18px; color: var(--linha); margin: 0 0 10px; }
.screen[hidden] { display: none; }
.card { background: var(--noite-2); border: 0; border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.card label { display: block; margin: 10px 0; color: var(--vidro); font-size: 13px; }
.card label input[type="text"], .card label input[type="number"], .card label input[type="password"], .card label select, .card .row > select, #code-input {
  display: block; width: 100%; margin-top: 6px; font: inherit; font-size: 15px; padding: 11px 12px; border-radius: 10px;
  border: 1.5px solid var(--borda); background: var(--noite); color: var(--linha); box-sizing: border-box;
}
.card label input:focus, .card label select:focus, #code-input:focus { outline: none; border-color: var(--bola); }
#code-input { margin-top: 0; font-family: var(--f-pixel); font-size: 12px; letter-spacing: 3px; color: var(--bola); }
#code-input::placeholder { font-family: var(--f-texto); font-size: 13px; letter-spacing: 0; text-transform: none; color: var(--apagado); }
.card label.check { display: flex; align-items: center; gap: 10px; color: var(--linha); }
.card label[hidden] { display: none; }
/* Caixa "Pública" desenhada como interruptor, só com CSS. */
.card label.check input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: none; width: 44px; height: 24px; margin: 0; border-radius: 999px;
  background: var(--borda); position: relative; cursor: pointer; transition: background 0.15s;
}
.card label.check input[type="checkbox"]::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--linha); transition: transform 0.15s;
}
.card label.check input[type="checkbox"]:checked { background: var(--bola); }
.card label.check input[type="checkbox"]:checked::after { transform: translateX(20px); background: var(--noite); }
.field > span { display: block; color: var(--vidro); font-size: 13px; margin: 10px 0 8px; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row > input { flex: 1; min-width: 0; }
.wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.hint { color: var(--vidro); font-size: 12px; }
#lobby-app button, #lobby-app .primary, #lobby-app .ghost {
  font: inherit; font-weight: 500; padding: 11px 16px; border-radius: 999px; border: 1.5px solid var(--vidro); background: transparent; color: var(--linha); cursor: pointer; white-space: nowrap;
}
#lobby-app button.primary { background: var(--bola); border-color: var(--bola); color: var(--noite); }
#lobby-app button.ghost { background: transparent; }
#lobby-app button:disabled { opacity: 0.4; cursor: default; }
#lobby-app button:focus-visible { outline: 2px solid var(--bola); outline-offset: 2px; }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.topbar .who { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar .who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
#lobby-app .topbar button { padding: 7px 12px; font-size: 13px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--borda-2); }
.list li:last-child { border-bottom: none; }
.list strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
/* Cada quadra aberta num quadro próprio. */
#court-list li { background: var(--noite); border: 1.5px solid var(--borda); border-radius: 12px; padding: 12px; margin-top: 10px; }
#court-list li:last-child { border-bottom: 1.5px solid var(--borda); }
#lobby-app #court-list li button { padding: 8px 14px; font-size: 13px; }
#btn-new-court { flex: none; }
#code-form { margin-top: 0; }
#lobby-app #btn-new-court { padding: 11px 14px; }
#lobby-app #code-form button { padding: 11px 14px; }
.card .row > select { margin-top: 0; flex: 1; min-width: 0; }
/* Celular estreito: "Criar quadra" ocupa a linha de cima e o código fica embaixo, sem cortar o texto. */
@media (max-width: 374px) {
  #btn-new-court { flex: 1 1 100%; }
  #screen-lobby .card > .row:first-child { flex-wrap: wrap; }
}
#court-empty { margin: 12px 0 0; }
/* Quadra na lista: cadeado, nome e pessoas/vagas; formato, bots e dono; etiqueta do nível mínimo (em breve). */
.court-item { min-width: 0; }
.court-line1 { display: flex; align-items: center; gap: 8px; }
.court-line1 svg { flex: none; }
.court-line1 strong { flex: 1; min-width: 0; }
.court-count { flex: none; font-family: var(--f-pixel); font-size: 10px; color: var(--bola); }
.court-line2 { color: var(--vidro); font-size: 12px; margin-top: 4px; }
.court-line3 { margin-top: 8px; }
.tag-soon { display: inline-block; border: 1.5px dashed #3A4A85; color: var(--apagado); border-radius: 999px; padding: 3px 9px; font-size: 11px; line-height: 1.3; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--noite); flex: none; }
.avatar.big { width: 96px; height: 96px; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--noite-2); padding: 0; }
#lobby-app .swatch { padding: 0; border: 3px solid var(--noite-2); }
#lobby-app .swatch.on { border-color: var(--linha); }
.swatch.on { border-color: var(--linha); }
/* Vagas da quadra desenhadas como uma quadra vista de cima. */
.slots { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.team-label { font-size: 12px; color: var(--vidro); text-align: center; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#lobby-app .swap { padding: 5px 10px; font-size: 12px; font-weight: 400; border-color: var(--borda); color: var(--vidro); }
#lobby-app .swap[hidden] { display: none; }
.slot small { display: block; text-transform: uppercase; letter-spacing: 0.04em; font-size: 10px; }
.slot-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: var(--azul); padding: 8px; border-left: 4px solid var(--vidro); border-right: 4px solid var(--vidro); }
.slot-row[data-team="b"] { border-top: 4px solid var(--vidro); border-radius: 12px 12px 0 0; margin-bottom: -8px; }
.slot-row[data-team="a"] { border-bottom: 4px solid var(--vidro); border-radius: 0 0 12px 12px; margin-top: -8px; }
.net-line { height: 4px; background: var(--linha); border-left: 4px solid var(--vidro); border-right: 4px solid var(--vidro); margin: 0; box-sizing: content-box; padding: 0; position: relative; z-index: 1; }
#lobby-app .slot { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 10px; border: 1.5px dashed var(--vidro); background: rgba(15, 22, 48, 0.35); color: var(--linha); text-align: left; font: inherit; font-weight: 400; white-space: normal; min-height: 64px; }
.slot .avatar { width: 48px; height: 48px; background: transparent; }
#lobby-app .slot.taken { border-style: solid; border-color: var(--noite-2); background: var(--noite-2); }
#lobby-app .slot.free { border-color: var(--bola); color: var(--bola); }
#lobby-app .slot.mine { border-color: var(--bola); border-style: solid; box-shadow: 0 0 0 2px rgba(212, 242, 60, 0.35); }
#lobby-app .slot:disabled { opacity: 0.9; cursor: default; }
#court-code { font-family: var(--f-pixel); font-size: 16px; color: var(--bola); flex: 1; letter-spacing: 2px; }
#lobby-app #btn-wa { width: 42px; height: 42px; padding: 0; border-radius: 50%; border: 0; background: #25d366; color: var(--noite); flex: none; }
#lobby-app #btn-copy-code { padding: 8px 12px; font-size: 13px; }
#toasts { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0)); display: flex; flex-direction: column; gap: 8px; z-index: 20; }
.toast { display: flex; align-items: center; gap: 8px; background: var(--noite-2); border: 1.5px solid var(--borda); border-radius: 12px; padding: 10px 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45); }
.toast span { flex: 1; }
.version { text-align: center; font-family: var(--f-pixel); font-size: 8px; color: var(--apagado); margin-top: 18px; line-height: 1.6; }
.bar-title { flex: 1; font-size: 13px; color: var(--vidro); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#bar a.icon { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; width: 40px; height: 36px; border-radius: 10px; border: 1.5px solid var(--borda); background: var(--noite-2); color: var(--vidro); font-size: 16px; }
#bar a.icon[hidden] { display: none; }

/* Tablet e telas largas: o lobby e a quadra usam mais largura. */
@media (min-width: 760px) {
  #lobby-app { max-width: 720px; }
  #screen-lobby, #screen-court { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; align-items: start; }
  #screen-lobby[hidden], #screen-court[hidden] { display: none; }
  #screen-lobby > .topbar, #screen-court > .topbar { grid-column: 1 / -1; }
  #screen-login .card { max-width: 440px; margin-left: auto; margin-right: auto; }
}
#lobby-app #login-form .row button.primary { flex: 1; padding: 14px 16px; font-size: 16px; }

/* Entrada: botões de conta no visual de cada provedor (Google escuro, Apple branco, Facebook azul) e,
   abaixo de um "ou", o formulário de visitante. */
.auth-card .hint { margin: -4px 0 12px; }
.auth-buttons { display: flex; flex-direction: column; gap: 10px; }
#lobby-app .auth-btn { display: flex; align-items: center; gap: 12px; width: 100%; height: 46px; padding: 0 14px; border-radius: 10px; font: 500 15px var(--f-texto); cursor: pointer; }
#lobby-app .auth-btn span:last-child { flex: 1; text-align: center; padding-right: 32px; }
.auth-ico { display: inline-flex; flex: none; width: 20px; height: 20px; }
.auth-ico svg { width: 20px; height: 20px; }
#lobby-app .auth-google { background: #131314; color: #E3E3E3; border: 1px solid #8E918F; }
#lobby-app .auth-apple { background: #FFFFFF; color: #000000; border: 1px solid #FFFFFF; }
#lobby-app .auth-facebook { background: #1877F2; color: #FFFFFF; border: 1px solid #1877F2; }
#lobby-app .auth-btn:active { filter: brightness(1.15); }
#auth-status:empty { display: none; }
#auth-status { margin: 10px 0 0; color: var(--bola); }
.divider { display: flex; align-items: center; gap: 12px; margin: 2px 0 12px; color: var(--apagado); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--borda-2); }
#login-form > .hint { margin: -4px 0 4px; }
#auth-account .row { margin-top: 6px; flex-wrap: wrap; }
#auth-account .hint { margin: 0; }
#lobby-app button.danger { border-color: var(--saque); color: var(--saque); }
@media (min-width: 760px) {
  #screen-login .divider { max-width: 440px; margin-left: auto; margin-right: auto; }
}
