:root {
  --bg: #10161f;
  --panel: #1a2230;
  --panel-2: #212b3d;
  --border: #2c3850;
  --text: #e8ecf4;
  --muted: #97a3ba;
  --accent: #4f8cff;
  --accent-2: #35c48b;
  --danger: #ff5c6c;
  --light-sq: #f0d9b5;
  --dark-sq: #8b6b4a;
  --piece-white: #ffffff;
  --piece-white-stroke: #12151c;
  --piece-black: #14151a;
  --piece-black-stroke: #f7f7f7;
  --sel: #ffe27a;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100%;
}

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

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  background: var(--accent);
  color: white;
  transition: filter .15s ease, transform .05s ease;
}
button:hover { filter: brightness(1.1); }
button:active { transform: scale(0.98); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--danger); }
button.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
button.small { padding: 6px 10px; font-size: 12px; }

input[type="text"], input[type="password"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  width: 100%;
}
input:focus { outline: 2px solid var(--accent); }

.landing-wrap {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
}
.app-credits {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.app-credits a { color: var(--muted); }
.landing-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 420px;
}
.landing-card h1 {
  font-size: 22px;
  margin: 0 0 4px;
}
.landing-card p.sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 20px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.error-box {
  background: rgba(255,92,108,.12);
  border: 1px solid var(--danger);
  color: #ffb3ba;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ---------- APP LAYOUT ---------- */
.app {
  display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-rows: auto 1fr;
  height: 100vh;
}
.topbar {
  grid-column: 1 / 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}
.topbar .brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.topbar .brand .pawn { font-size: 20px; }
.room-code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.room-code code { color: var(--accent-2); font-weight: 700; letter-spacing: 1px; }

.main-col {
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.side-col {
  border-left: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
/* Aviso fixo no topo da tela quando um aluno novo pede para entrar --
   fica visivel mesmo sem rolar a pagina (importante no celular, onde a
   sala de espera fica mais abaixo, fora da tela inicial). */
.new-join-toast {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: var(--accent-2);
  color: #06231a;
  font-weight: 700;
  text-align: center;
  padding: 12px 16px;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
  animation: newJoinToastPulse 1s ease-in-out infinite;
}
@keyframes newJoinToastPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.25); }
}

/* Sinal visual quando um novo aluno pede para entrar na sala */
@keyframes newJoinFlash {
  0%, 100% { box-shadow: 0 0 0 0 rgba(53, 196, 139, 0); background: var(--panel); }
  15%, 55% { box-shadow: 0 0 0 4px rgba(53, 196, 139, .55); background: rgba(53, 196, 139, .12); }
}
.panel.new-join-flash {
  animation: newJoinFlash 900ms ease-in-out 3;
}
.panel h3 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

/* Video strip */
.video-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.video-tile {
  position: relative;
  flex: 0 0 auto;
  width: 112px;
  height: 84px;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.video-tile.teacher { width: 160px; height: 120px; border-color: var(--accent); }
.video-tile video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.video-tile .label {
  position: absolute;
  bottom: 6px;
  left: 8px;
  font-size: 12px;
  background: rgba(0,0,0,.55);
  padding: 2px 8px;
  border-radius: 6px;
}
.video-tile .mic-off {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 12px;
  background: rgba(255,92,108,.85);
  padding: 2px 6px;
  border-radius: 6px;
}
.video-tile.novideo::before {
  content: attr(data-initial);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 700;
  color: var(--muted);
  background: var(--panel-2);
}

.media-controls { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.media-controls .mic-volume {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.media-controls .mic-volume input[type="range"] {
  width: 110px;
  accent-color: var(--accent);
}

/* Board tabs (teacher) */
.board-tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; }
.board-tabs button.tab {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}
.board-tabs button.tab.active { background: var(--accent); border-color: var(--accent); }

.board-area { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.board-wrap { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(70vw, 480px);
  height: min(70vw, 480px);
  border: 2px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  user-select: none;
}
.board.board-mini {
  width: min(42vw, 220px);
  height: min(42vw, 220px);
  border-width: 1px;
}

/* Tabuleiro do professor em destaque, do lado do aluno -- borda bem
   visivel para deixar claro que essa e a posicao que o professor esta
   mostrando pra turma toda. */
#spotlightBoardContainer .board {
  border: 3px solid var(--accent-2);
  box-shadow: 0 0 0 4px rgba(53, 196, 139, .18), 0 0 18px rgba(53, 196, 139, .35);
}
.board.board-mini .sq { font-size: min(5vw, 24px); }
.board.board-mini .sq .coord { display: none; }

/* Multi-board layout for the teacher view */
.multiboard-layout { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.main-board-col { flex: 0 0 auto; }
.student-boards-col {
  flex: 1 1 320px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-content: flex-start;
}
.mini-board-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(44vw, 240px);
}
.mini-board-card .mini-board-name {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.mini-board-card .mini-board-controls { display: flex; gap: 6px; }
.empty-mini-hint {
  color: var(--muted);
  font-size: 13px;
  padding: 20px 10px;
}
.spotlight-btn.active { background: var(--accent-2); }
#setupModeBtn.active { background: var(--accent-2); }

.setup-palette {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-top: 4px;
  max-width: min(70vw, 480px);
}
.setup-palette .palette-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.setup-palette .palette-row-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  width: 56px;
  flex: 0 0 auto;
}
.setup-palette .palette-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.setup-palette .palette-piece {
  width: 44px;
  height: 44px;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  line-height: 1;
}
/* Fundo de cada botao imita a casa oposta a cor da peca (como no
   tabuleiro de verdade) -- e o que garante contraste: peca branca em
   fundo escuro, peca preta em fundo claro. Sem isso a peca preta ficava
   quase invisivel (fundo escuro + peca escura). */
/* Sem contorno (text-stroke) aqui: no tamanho pequeno do icone da paleta,
   o contorno da cor oposta domina visualmente o preenchimento e faz a
   peca parecer da cor errada. O fundo (claro/escuro) ja da contraste
   suficiente sozinho. */
.setup-palette .palette-piece.piece-w {
  background: var(--dark-sq);
  color: var(--piece-white);
}
.setup-palette .palette-piece.piece-b {
  background: var(--light-sq);
  color: var(--piece-black);
}
.setup-palette .palette-piece.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,140,255,.55);
}
.setup-palette .palette-erase {
  width: 42px;
  height: 42px;
  font-size: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.setup-palette .palette-erase.active {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px rgba(255,92,108,.4);
  background: rgba(255,92,108,.12);
}
.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(8vw, 42px);
  cursor: pointer;
}
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.selected { outline: 3px solid var(--sel); outline-offset: -3px; z-index: 2; }
.sq.legal::after {
  content: "";
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(53, 196, 139, .55);
}
.sq.legal.has-piece::after {
  width: 100%;
  height: 100%;
  border-radius: 0;
  background: transparent;
  box-shadow: inset 0 0 0 4px rgba(255,92,108,.75);
}
.sq .piece {
  pointer-events: none;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sq .piece.piece-w {
  color: var(--piece-white);
  -webkit-text-stroke: 1.75px var(--piece-white-stroke);
  text-stroke: 1.75px var(--piece-white-stroke);
  paint-order: stroke fill;
  filter: drop-shadow(0 1px 1.5px rgba(0,0,0,.55));
}
.sq .piece.piece-b {
  color: var(--piece-black);
  -webkit-text-stroke: 1px var(--piece-black-stroke);
  text-stroke: 1px var(--piece-black-stroke);
  paint-order: stroke fill;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.35));
}
.sq .coord {
  position: absolute;
  font-size: 10px;
  color: rgba(0,0,0,.35);
  top: 2px;
  left: 3px;
  pointer-events: none;
}

.board-controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.board-meta { font-size: 13px; color: var(--muted); text-align: center; }

.student-board-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
}
.student-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 13px;
}
.student-row .name { display: flex; align-items: center; gap: 8px; }
.waiting-list { display: flex; flex-direction: column; gap: 8px; }
.waiting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.waiting-item .actions { display: flex; gap: 6px; }
.empty-msg { color: var(--muted); font-size: 13px; padding: 8px 0; }

/* Chat */
.chat-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 14px; }
.chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 4px; }
.chat-msg { font-size: 13px; line-height: 1.4; }
.chat-msg .who { font-weight: 700; margin-right: 6px; }
.chat-msg.role-teacher .who { color: var(--accent); }
.chat-msg.role-student .who { color: var(--accent-2); }
.chat-msg .time { color: var(--muted); font-size: 11px; margin-left: 6px; }
.chat-input-row { display: flex; gap: 8px; margin-top: 10px; }
.chat-input-row input { flex: 1; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge.you { background: rgba(79,140,255,.15); border-color: var(--accent); color: var(--accent); }

.waiting-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  text-align: center;
  padding: 24px;
  gap: 14px;
}
.spinner {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.section-toggle { display: flex; gap: 8px; margin-bottom: 12px; }
.section-toggle button.active { background: var(--accent-2); }

footer.tiny { text-align: center; color: var(--muted); font-size: 11px; padding: 10px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  /* .topbar tem "grid-column: 1 / 3" para o layout de 2 colunas do
     desktop. Isso cria uma coluna implicita extra mesmo aqui (so 1
     coluna definida), e sem posicionamento explicito o grid preenche a
     linha 2 inteira (as duas colunas) antes de passar pra linha 3 --
     resultado: tabuleiro e chat ficavam lado a lado, sobrepostos, em vez
     de empilhados. Fixando a posicao de cada um evita essa ambiguidade. */
  .topbar { grid-column: 1; }
  .main-col { grid-column: 1; grid-row: 2; min-height: 0; }
  .side-col {
    grid-column: 1;
    grid-row: 3;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 58vh;
    overflow-y: auto;
  }
  /* No celular, "Sala de espera" e "Participantes" nao tinham limite de
     altura -- com mais de um aluno/pedido, eles cresciam e sobravam poucos
     pixels (ou nenhum) pro chat dentro da area limitada do .side-col,
     entao as mensagens ficavam praticamente invisiveis, exigindo rolar
     bastante pra achar. Agora cada lista tem seu proprio scroll interno
     curto, e o chat ganha uma altura minima garantida. */
  .side-col .waiting-list { max-height: 120px; overflow-y: auto; }
  .side-col .student-board-list { max-height: 120px; }
  .side-col .chat-panel { flex: 1 1 260px; min-height: 260px; }

  /* O tabuleiro do professor ficava desalinhado (puxado pra direita) no
     celular: ".main-board-col" tinha "flex: 0 0 auto" dentro de uma
     linha flex, entao ele so ocupava a largura do seu proprio conteudo
     em vez da largura toda -- o board-wrap (que centraliza o tabuleiro
     dentro de si) acabava centralizado dentro dessa largura menor, que
     por sua vez nao estava centralizada na tela. Forcando coluna cheia
     e centralizando o conteudo aqui resolve. */
  .multiboard-layout { flex-direction: column; align-items: center; }
  .main-board-col { width: 100%; display: flex; flex-direction: column; align-items: center; }
  .student-boards-col { width: 100%; }
}
