/* Estádio Virtual — cliente (3D com WebGL; 2D quando não houver). Celular primeiro (retrato e paisagem), funciona no PC. */

:root {
  --fundo: #0b3b29;
  --fundo-2: #0f4a34;
  --painel: rgba(4, 24, 17, 0.92);
  --linha: rgba(255, 255, 255, 0.14);
  --texto: #f3f7f4;
  --sutil: #a9c2b6;
  --ouro: #ffd54a;
  --erro: #ff6b6b;
  --whats: #1fa855;
  --cor-a: #c8102e;
  --cor-b: #1d4ed8;
  --texto-a: #fff;
  --texto-b: #fff;
  --cor-time: #2e7d4f;
  --texto-time: #fff;
  --raio: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(120% 80% at 50% 0%, var(--fundo-2), var(--fundo) 70%) fixed, var(--fundo);
  color: var(--texto);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { margin: 0; }
h2 { font-size: 15px; font-weight: 700; color: var(--sutil); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px; }
.sutil { color: var(--sutil); font-size: 14px; margin: 6px 0; }
.erro { color: var(--erro); font-weight: 600; margin: 8px 0 0; }
.destaque { font-size: 18px; margin: 0; }

/* ---------- botões ---------- */

.botao {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 18px;
  border: 0; border-radius: var(--raio);
  font: inherit; font-weight: 800; font-size: 16px;
  color: var(--texto); text-decoration: none; cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
}
.botao:active { transform: scale(0.97); }
.botao:disabled { opacity: 0.5; cursor: default; }
.botao.principal { background: var(--ouro); color: #1b1600; }
.botao.secundario { background: rgba(255, 255, 255, 0.1); border: 1px solid var(--linha); }
.botao.whatsapp { background: var(--whats); color: #fff; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--ouro); outline-offset: 2px; }

input[type="text"] {
  width: 100%; min-height: 48px; padding: 0 14px;
  border-radius: var(--raio); border: 1px solid var(--linha);
  background: rgba(0, 0, 0, 0.35); color: var(--texto);
  font: inherit; font-size: 16px; /* 16px evita zoom automático no iOS */
}
input::placeholder { color: #7f9a8d; }

/* ---------- lobby ---------- */

#lobby { min-height: 100%; display: flex; justify-content: center; padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); }
.cartaz { width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 18px; }
.marca { font-size: 34px; font-weight: 900; letter-spacing: -0.02em; text-transform: uppercase; line-height: 1; margin-top: 8px; }
.marca span { color: var(--ouro); }
.lema { margin: -8px 0 0; color: var(--sutil); }
.bloco-lobby { background: var(--painel); border: 1px solid var(--linha); border-radius: 18px; padding: 16px; }

.lista-partidas { display: flex; flex-direction: column; gap: 10px; }
.partida {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 4px 10px;
  width: 100%; min-height: 64px; padding: 10px 12px;
  border-radius: var(--raio); border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.06); color: var(--texto);
  font: inherit; cursor: pointer; text-align: left;
}
.partida[aria-pressed="true"] { border-color: var(--ouro); background: rgba(255, 213, 74, 0.1); }
.partida .lado { display: flex; align-items: center; gap: 8px; font-weight: 800; min-width: 0; }
.partida .lado.b { justify-content: flex-end; text-align: right; }
.partida .lado span { overflow-wrap: anywhere; line-height: 1.15; }
.partida .escudo { flex: none; width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25); }
.partida .meio { text-align: center; font-size: 20px; font-weight: 900; white-space: nowrap; }
.partida .detalhe { grid-column: 1 / -1; text-align: center; color: var(--sutil); font-size: 12px; margin-top: -4px; }

.torcidas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.torcida {
  min-height: 76px; padding: 8px; border-radius: var(--raio); border: 3px solid transparent;
  font: inherit; font-weight: 900; font-size: 18px; cursor: pointer;
  overflow-wrap: anywhere; transition: transform 0.1s;
}
.torcida[aria-pressed="true"] { border-color: var(--ouro); transform: scale(1.03); box-shadow: 0 0 0 4px rgba(255, 213, 74, 0.25); }
.torcida small { display: block; font-weight: 600; font-size: 12px; opacity: 0.85; }

.botoes-entrar { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.botoes-entrar > * { flex: 1 1 160px; }
#form-entrar input { margin-top: 2px; }
.campo-link { display: flex; gap: 8px; }
.campo-link input { flex: 1; min-width: 0; font-size: 14px; }

/* ---------- estádio ---------- */

#estadio {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
  user-select: none; -webkit-user-select: none;
}

.placar {
  grid-column: 1 / -1;
  padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left));
  background: linear-gradient(#04170f, rgba(4, 23, 15, 0.92));
  border-bottom: 1px solid var(--linha);
  z-index: 3;
}
.linha-placar { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 10px; }
.nome-time { font-weight: 900; font-size: clamp(14px, 4vw, 20px); text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nome-time.a { text-align: right; }
.gols { display: flex; align-items: center; gap: 6px; }
.gols b {
  min-width: 40px; padding: 2px 8px; border-radius: 10px; text-align: center;
  font-size: clamp(24px, 7vw, 34px); font-weight: 900; line-height: 1.15; font-variant-numeric: tabular-nums;
}
#gols-a { background: var(--cor-a); color: var(--texto-a); }
#gols-b { background: var(--cor-b); color: var(--texto-b); }
.gols i { font-style: normal; font-weight: 800; color: var(--sutil); }
.linha-info { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 4px; font-size: 13px; color: var(--sutil); flex-wrap: wrap; }
#fase { color: var(--texto); font-weight: 700; }
.torcidas-info { display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.bolinha { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-left: 4px; }
#bolinha-a { background: var(--cor-a); }
#bolinha-b { background: var(--cor-b); }
.ping { font-variant-numeric: tabular-nums; }
.sair { margin-left: auto; min-height: 32px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--linha); background: transparent; color: var(--sutil); font: inherit; cursor: pointer; }
.status { margin: 6px -10px -6px; padding: 6px 10px; text-align: center; font-weight: 700; font-size: 14px; background: #8a6d00; color: #fff; }
.status.ruim { background: #9b2226; }

.palco { grid-row: 2; grid-column: 1; position: relative; min-height: 0; overflow: hidden; touch-action: none; }
#tela { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#tela:active { cursor: grabbing; }
/* camada 2D por cima do 3D (nomes, visão geral, faixas): não pega toque */
.hud { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; z-index: 1; }

.flutuante {
  position: absolute; z-index: 2;
  width: 52px; height: 52px; border-radius: 50%;
  border: 1px solid var(--linha); background: rgba(4, 24, 17, 0.85); color: var(--texto);
  display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.flutuante svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.centralizar { left: 12px; bottom: 12px; }
.centralizar svg circle:first-child { fill: currentColor; }
.abrir-chat { right: 12px; bottom: 12px; }
/* som: acima do "voltar para o meu lugar"; mudo = alto-falante com X */
.som { left: 12px; bottom: 76px; }
.som .alto-falante { fill: currentColor; }
.som .xis, .som.mudo .ondas { display: none; }
.som.mudo .xis { display: inline; }
.som.mudo { color: var(--sutil); }
.abrir-chat svg { fill: currentColor; stroke: none; }
.nao-lidas {
  position: absolute; top: -4px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--erro); color: #fff; font-size: 12px; font-weight: 800; display: grid; place-items: center;
}

.demo-barra { position: absolute; left: 8px; top: 8px; z-index: 2; display: flex; flex-wrap: wrap; gap: 6px; max-width: 55%; }
.demo-barra button { min-height: 36px; padding: 0 10px; border-radius: 10px; border: 1px dashed var(--ouro); background: rgba(0, 0, 0, 0.6); color: var(--ouro); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }

/* chat: no retrato fica por cima da arquibancada, embaixo */
.chat {
  grid-row: 2; grid-column: 1; align-self: end; z-index: 4;
  display: flex; flex-direction: column;
  height: min(55%, 420px); margin: 0 8px 8px;
  background: #06190f; border: 1px solid var(--linha); border-radius: 16px;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.5);
  user-select: text; -webkit-user-select: text;
}
.chat-topo { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 6px 14px; border-bottom: 1px solid var(--linha); }
.fechar { width: 44px; height: 44px; border: 0; background: transparent; color: var(--texto); font-size: 26px; line-height: 1; cursor: pointer; border-radius: 10px; }
.mensagens { list-style: none; margin: 0; padding: 8px 12px; flex: 1; overflow-y: auto; font-size: 15px; line-height: 1.35; overscroll-behavior: contain; }
.mensagens li { padding: 3px 0; overflow-wrap: anywhere; }
.mensagens .quem { font-weight: 800; color: var(--ouro); margin-right: 6px; }
.mensagens .minha .quem { color: #7cf3ff; }
.mensagens .aviso { color: var(--erro); font-weight: 600; }
.mensagens .sistema { color: var(--sutil); font-style: italic; }
.form-chat { display: flex; gap: 8px; padding: 8px; border-top: 1px solid var(--linha); }
.form-chat input { flex: 1; min-width: 0; }

/* rodapé de ações */
.acoes {
  grid-column: 1 / -1;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 0.9fr); gap: 6px;
  padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: linear-gradient(rgba(4, 23, 15, 0.92), #04170f);
  border-top: 1px solid var(--linha);
  z-index: 3;
}
.acao {
  position: relative;
  min-height: 60px; padding: 6px 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: var(--raio); border: 1px solid var(--linha);
  background: rgba(255, 255, 255, 0.08); color: var(--texto);
  font: inherit; font-weight: 800; font-size: 13px; cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s, background 0.15s;
}
.acao svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.acao:active, .acao.ativa { transform: scale(0.93); background: var(--cor-time); color: var(--texto-time); }
.acao.convidar { background: rgba(255, 213, 74, 0.14); border-color: rgba(255, 213, 74, 0.45); color: var(--ouro); }
.acao kbd { position: absolute; top: 4px; right: 6px; font: inherit; font-size: 10px; opacity: 0.55; }
@media (hover: none) { .acao kbd { display: none; } }

/* modais */
.modal { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, 0.6); }
.modal-caixa { width: 100%; max-width: 440px; background: #0d2a20; border: 1px solid var(--linha); border-radius: 18px; padding: 18px; }
.modal-caixa h2 { color: var(--texto); text-transform: none; letter-spacing: 0; font-size: 20px; }

/* paisagem larga e PC: chat vira coluna à direita */
@media (min-width: 900px), (orientation: landscape) and (min-width: 700px) {
  #estadio { grid-template-columns: minmax(0, 1fr) 320px; }
  #estadio.sem-chat { grid-template-columns: minmax(0, 1fr); }
  .chat { grid-row: 2; grid-column: 2; align-self: stretch; height: auto; margin: 0; border-radius: 0; border-width: 0 0 0 1px; box-shadow: none; }
  .acoes { grid-template-columns: repeat(4, minmax(0, 120px)) minmax(0, 130px); justify-content: center; }
}

/* paisagem baixa (celular deitado): placar e rodapé mais compactos */
@media (orientation: landscape) and (max-height: 500px) {
  .linha-placar { gap: 6px; }
  .gols b { font-size: 22px; min-width: 32px; }
  .nome-time { font-size: 14px; }
  .linha-info { margin-top: 2px; font-size: 12px; }
  .acao { min-height: 48px; flex-direction: row; gap: 6px; }
  .acao svg { width: 22px; height: 22px; }
  .flutuante { width: 48px; height: 48px; }
  .som { bottom: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  .acao, .botao, .torcida { transition: none; }
}
