/* Reset enxuto + tipografia fluida + componentes usados em todas as telas. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* O atributo `hidden` do HTML só tem especificidade de seletor de atributo
   (0,1,0) na folha de estilos do navegador — qualquer classe nossa que
   também defina `display` (`.screen`, `.btn`, etc.) tem prioridade de
   origem sobre a UA stylesheet e silenciosamente "reaparece" o elemento.
   Esta regra garante que `hidden` sempre vence, em qualquer elemento. */
[hidden] {
  display: none !important;
}

html {
  /* Tipografia fluida: legível tanto num celular pequeno quanto numa TV
     vista de longe, sem precisar de media queries para cada salto. */
  font-size: clamp(15px, 1vw + 10px, 20px);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg-gradient), var(--bg);
  background-repeat: no-repeat;
  background-attachment: fixed;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

a {
  color: var(--accent);
}

img {
  max-width: 100%;
  display: block;
}

::selection {
  background: var(--primary);
  color: var(--primary-contrast);
}

/* --- Layout -------------------------------------------------------- */

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 4vw, 3rem);
  gap: clamp(1rem, 3vw, 2rem);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

/* --- Componentes ----------------------------------------------------- */

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 1.1rem;
  padding: clamp(1rem, 3vw, 1.75rem);
  box-shadow: var(--shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.85em 1.6em;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 0.85rem;
  background: var(--primary);
  color: var(--primary-contrast);
  text-decoration: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  box-shadow: 0 4px 0 var(--primary-dark);
}

.btn:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--primary-dark);
}

.btn:disabled {
  box-shadow: none;
}

.btn-secondary {
  background: var(--bg-elevated-2);
  color: var(--text);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  box-shadow: none;
}

.btn-block {
  width: 100%;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  /* Sem isso, um <select> com uma opção de texto longo (ex: nome de
   * torneio comprido) usa esse texto como largura MÍNIMA do campo — e
   * como flex/grid não deixam um item encolher abaixo do próprio
   * conteúdo por padrão, isso empurra o formulário inteiro (e até o
   * grid ao redor) mais largo que a tela, cortando/vazando texto no
   * mobile. `min-width: 0` deixa o campo encolher de verdade; o próprio
   * <select>/input> então trunca o texto que não cabe, em vez de forçar
   * tudo ao redor a crescer. */
  min-width: 0;
}

.field label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

.input,
select.input,
textarea.input {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  padding: 0.75em 1em;
  font-size: 1.05rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  /* Correção na raiz do mesmo bug de `.field` acima: um <select> com uma
   * opção de texto comprido (nome de tema musical, nome de torneio) tem
   * essa string como largura mínima intrínseca — sem `min-width: 0` isso
   * empurra QUALQUER wrapper flex ao redor (mesmo um `<div
   * style="display:flex">` sem classe nenhuma, que não herda a correção
   * de `.field`) mais largo que a tela, em vez do próprio campo truncar o
   * texto que não cabe. Corrigido aqui, no elemento raiz do problema, pra
   * cobrir todo caso (atual ou futuro) de uma vez. */
  min-width: 0;
}

.input:focus,
select.input:focus,
textarea.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 35%, transparent);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.3em 0.75em;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--bg-elevated-2);
  color: var(--text-muted);
}

.badge-live {
  background: color-mix(in srgb, var(--success) 25%, transparent);
  color: var(--success);
}

.text-muted {
  color: var(--text-muted);
}

.error-message {
  color: var(--danger);
  font-weight: 600;
  font-size: 0.95rem;
  min-height: 1.4em;
}

.pin-display {
  font-size: clamp(2.5rem, 9vw, 6rem);
  font-weight: 900;
  letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- Animações --------------------------------------------------------- */

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.85) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes shake {
  10%,
  90% {
    transform: translateX(-2px);
  }
  20%,
  80% {
    transform: translateX(4px);
  }
  30%,
  50%,
  70% {
    transform: translateX(-8px);
  }
  40%,
  60% {
    transform: translateX(8px);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

@keyframes bounce-in {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
  60% {
    opacity: 1;
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

.anim-pop-in {
  animation: pop-in 0.35s cubic-bezier(0.2, 0.8, 0.3, 1.1) both;
}

.anim-fade-in {
  animation: fade-in 0.4s ease both;
}

.anim-shake {
  animation: shake 0.4s ease;
}

.anim-pulse {
  animation: pulse 1.4s ease-in-out infinite;
}

.anim-bounce-in {
  animation: bounce-in 0.5s cubic-bezier(0.2, 0.8, 0.3, 1.2) both;
}

/* --- Rodapé de assinatura (admin + jogador) ---------------------------- */

.app-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  padding: 0.35rem 0.75rem calc(0.35rem + env(safe-area-inset-bottom));
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  line-height: 1.3;
  text-align: center;
  color: var(--text-muted);
}

.app-footer-brand {
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
}

.app-footer-contact {
  white-space: nowrap;
}

/* Vazio (sem conteúdo) até version.js preencher — nunca ocupa espaço nem
 * aparece quebrado enquanto isso não acontece (ex: dev local, onde
 * version.json nunca existe). */
.app-footer-version {
  white-space: nowrap;
  opacity: 0.7;
}
.app-footer-version:empty {
  display: none;
}

/* Telas bem estreitas: quebra em duas linhas em vez de espremer/cortar. */
@media (max-width: 360px) {
  .app-footer {
    flex-direction: column;
    gap: 0.05rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Grid compacto de chips de participante (ver shared/rosterChips.js) --
 * Reaproveitado pelo lobby/carência do jogador e pelo lobby/carência do
 * apresentador — layout único em vez de 4 listas separadas. Substitui a
 * lista empilhada (1 por linha) por vários chips por linha, sem esconder
 * nenhum nome (só compacta o LAYOUT, ver MISSAO.md). */
.roster-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  max-height: 40vh;
  overflow-y: auto;
  padding: 0.1rem;
}

.roster-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  background: var(--bg-elevated);
  font-weight: 600;
  font-size: 0.85rem;
  max-width: 100%;
}

.roster-chip-avatar {
  font-size: 1rem;
  flex-shrink: 0;
}

.roster-chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 8.5rem;
}

.roster-chip-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--success);
  flex-shrink: 0;
}

.roster-chip-label {
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--text-muted);
}

.roster-chip-meta {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.8em;
}

.roster-chip.is-absent {
  opacity: 0.65;
}

.roster-chip.is-absent .roster-chip-dot {
  background: var(--text-muted);
}

.roster-chip.is-left {
  opacity: 0.55;
}

.roster-chip.is-left .roster-chip-dot {
  background: var(--text-muted);
}

.roster-chip-poke {
  margin-left: 0.1rem;
  padding: 0.2em 0.55em;
  border-radius: 0.5rem;
  border: none;
  background: var(--bg-elevated-2);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.roster-chip-poke:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Moderação (item 4 do lote): cor de perigo pra diferenciar visualmente de
 * "Cutucar" — é uma ação destrutiva (bloqueia reentrada nesta sala), tem que
 * ser reconhecível de longe antes mesmo de ler o texto. */
.roster-chip-remove {
  margin-left: 0.1rem;
  padding: 0.2em 0.55em;
  border-radius: 0.5rem;
  border: none;
  background: color-mix(in srgb, var(--danger) 22%, var(--bg-elevated-2));
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.roster-chip-remove:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Animação sutil de entrada quando um chip novo aparece (participante
 * entrando em tempo real) — só aplicada a chips genuinamente novos desde a
 * última montagem da tela (ver `seenTokens` em rosterChips.js), nunca ao
 * lote inteiro reaparecendo num re-render comum. Zerada globalmente pelo
 * `prefers-reduced-motion` já declarado acima. */
@keyframes roster-chip-enter {
  from {
    opacity: 0;
    transform: scale(0.6) translateY(4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.roster-chip-enter {
  animation: roster-chip-enter 0.35s ease-out;
}

/* Banner fixo de "Reconectando…" — mostrado quando o socket cai e escondido
 * quando volta. Compartilhado entre a tela do jogador e a do apresentador
 * (as duas telas em tempo real que dependem do socket vivo). Usa só a
 * variável --warning de themes.css. */
.reconnect-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  text-align: center;
  padding: 0.6rem;
  background: var(--warning);
  color: #221a00;
  font-weight: 700;
}

/* Toast não-bloqueante empilhável (public/shared/toast.js) — usado no lugar
 * de alert() nas telas em tempo real. Centralizado no topo, some sozinho. */
.toast-region {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  pointer-events: none;
  max-width: min(92vw, 30rem);
  width: max-content;
}
.toast {
  pointer-events: auto;
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius-card, 12px);
  background: var(--bg-surface-raised, #2c2140);
  color: var(--text-primary, #f5f1ea);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  box-shadow: var(--shadow-raised, 0 8px 24px rgba(0, 0, 0, 0.4));
  font-weight: 600;
  text-align: center;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast--in {
  opacity: 1;
  transform: translateY(0);
}
.toast--error {
  border-left-color: var(--danger);
}
.toast--success {
  border-left-color: var(--success);
}
@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}

/* --- RTPE Fase 3: barra global de sala ativa + contador flutuante ---------- */
.active-room-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.9rem;
  background: color-mix(in srgb, var(--accent) 18%, var(--bg-elevated));
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}
.active-room-bar__icon { font-size: 1.2rem; flex: none; }
.active-room-bar__text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; flex: 1; }
.active-room-bar__text strong { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.active-room-bar__sub { font-size: 0.78rem; color: var(--text-muted); }
.active-room-bar__btn { flex: none; white-space: nowrap; }

/* Contador flutuante arrastável — canto inferior direito por padrão. */
.active-room-widget {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 901;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: grab;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #fff;
  background: radial-gradient(circle at 30% 30%, color-mix(in srgb, var(--accent) 80%, #fff), var(--accent));
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  animation: active-room-widget-in 0.3s ease;
}
.active-room-widget:active { cursor: grabbing; }
.active-room-widget__fire { font-size: 1.2rem; line-height: 1; }
.active-room-widget__time { font-size: 0.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
@keyframes active-room-widget-in {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Quando a barra global está visível, empurra o conteúdo pra não ficar atrás. */
body:has(.active-room-bar) { padding-top: 52px; }
