/* Sala de vídeo + tabuleiro (prefixo rm-). Desktop: tabuleiro grande à esquerda, vídeos e painel à direita.
   Celular: vídeos em linha no topo, tabuleiro embaixo. */
.rm-room { max-width: 1280px; margin: 0 auto; }
.rm-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.rm-head-l { display: flex; align-items: center; gap: 12px; min-width: 0; }
.rm-head-r { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rm-title { font-family: var(--font-display); font-weight: 700; font-size: 18px; line-height: 1.2; }
.rm-live { width: 10px; height: 10px; border-radius: 50%; background: #e5484d; flex: none; animation: rm-pulse 1.8s infinite; }
@keyframes rm-pulse { 0% { box-shadow: 0 0 0 0 rgba(229, 72, 77, .55); } 70% { box-shadow: 0 0 0 9px rgba(229, 72, 77, 0); } 100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0); } }
.rm-join { margin-bottom: 12px; }
.rm-join:empty { display: none; }
.rm-joinbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rm-joinbar > .grow { flex: 1 1 260px; }

.rm-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; grid-template-areas: "main videos" "main side"; gap: 16px 20px; align-items: start; }
.rm-main { grid-area: main; min-width: 0; }
.rm-videos { grid-area: videos; }
.rm-side { grid-area: side; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.rm-board { display: flex; justify-content: center; }
.rm-board .board-wrap { width: 100%; max-width: min(680px, calc(100vh - 200px)); }
.rm-ro .rm-board .board { pointer-events: none; }
.rm-tools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.rm-tools[hidden] { display: none; }
.rm-tip { flex-basis: 100%; }
.rm-moves { max-height: 200px; margin-top: 8px; }

/* Miniaturas de vídeo */
.rm-videos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.rm-videos:empty { display: none; }
.rm-tile { position: relative; aspect-ratio: 16 / 10; background: #16171a; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.rm-tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .25s; }
.rm-tile.me video { transform: scaleX(-1); }
.rm-tile.me.screen video { transform: none; }
.rm-tile.screen video { object-fit: contain; background: #000; }
.rm-tile.has-video video { opacity: 1; }
.rm-tile-ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; }
.rm-tile-ph .avatar { width: 48px; height: 48px; font-size: 18px; background: #3a3b41; color: #fff; }
.rm-tile.has-video .rm-tile-ph { display: none; }
.rm-tile-bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 6px; padding: 5px 8px; background: linear-gradient(transparent, rgba(0, 0, 0, .65)); color: #fff; font-size: 12px; }
.rm-tile-bar b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rm-tile-ic .ico { width: 14px; height: 14px; color: #ffb3b3; }
.rm-conn { width: 8px; height: 8px; border-radius: 50%; background: #999; flex: none; }
.rm-conn.ok { background: #35c46a; }
.rm-conn.wait { background: #ffc21a; animation: rm-blink 1s infinite; }
.rm-conn.bad { background: #e5484d; }
@keyframes rm-blink { 50% { opacity: .3; } }

/* Controles de mídia */
.rm-ctrl { display: flex; gap: 6px; flex-wrap: wrap; }
.rm-ctrl .btn.on { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.rm-chan { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-left: 6px; vertical-align: middle; }
.rm-chan.off { background: var(--bad); }

/* Participantes e conversa */
.rm-people, .rm-chat { padding: 14px; }
.rm-people-list { display: flex; flex-direction: column; gap: 6px; }
.rm-person { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.rm-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); flex: none; }
.rm-dot.ok { background: var(--ok); }
.rm-dot.wait { background: var(--warn); }
.rm-chat-log { max-height: 160px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; font-size: 14px; }
.rm-msg.me b { color: var(--accent); }
.rm-chat-btns { display: flex; flex-wrap: wrap; gap: 4px; }
.rm-note { display: flex; gap: 6px; align-items: flex-start; }
.rm-note .ico { width: 16px; height: 16px; flex: none; margin-top: 2px; }

/* Escolher posição de uma aula */
.rm-pick { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.rm-pick-it { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 10px; cursor: pointer; font: inherit; color: var(--text); display: flex; gap: 8px; align-items: center; }
.rm-pick-it:hover { background: var(--surface-2); }

/* Painel da partida (dentro da coluna lateral de /partida/:id) */
.rm-game { padding: 12px; }
.rm-game-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.rm-game-videos { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 8px; }
.rm-game .rm-join:empty { display: none; }

@media (max-width: 900px) {
  .rm-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "videos" "main" "side"; gap: 12px; }
  .rm-videos { display: flex; overflow-x: auto; gap: 8px; padding-bottom: 4px; scroll-snap-type: x mandatory; }
  .rm-tile { flex: 0 0 150px; aspect-ratio: 4 / 3; scroll-snap-align: start; }
  .rm-board .board-wrap { max-width: min(100%, calc(100vh - 260px)); }
  .rm-tip { display: none; }
  .rm-moves { max-height: 140px; }
}

/* Sala de jogo */
.rm-pbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; min-height: 44px; }
.rm-pname { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.rm-swatch { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--text-2); flex: none; }
.rm-swatch.w { background: #fff; } .rm-swatch.b { background: #111; }
.rm-match .clock { font-size: 20px; min-width: 84px; }
.rm-result { margin-top: 8px; }
.rm-mcard { color: var(--text); text-decoration: none !important; border-left: 4px solid var(--brand); }
.rm-mcard:hover { background: var(--surface-2); }

/* Situação da conexão escrita no quadro (diagnóstico) e botão de liberar o som no celular */
.rm-tile-st { position: absolute; top: 6px; right: 8px; font-size: 11px; color: #fff; background: rgba(0, 0, 0, .55); padding: 1px 6px; border-radius: 6px; z-index: 1; }
.rm-tile-st:empty { display: none; }
.rm-sound { width: 100%; margin-bottom: 8px; justify-content: center; }

/* Partida online: sem "acompanhamento" de rolagem do navegador; no celular o vídeo é uma faixa compacta acima do tabuleiro */
.play-noanchor, .play-noanchor body { overflow-anchor: none; }
@media (max-width: 980px) {
  .play-layout .rm-game-cam { margin-bottom: 8px; }
  .play-layout .rm-game { padding: 8px; }
  .play-layout .rm-game-head { display: none; }
  .play-layout .rm-game-videos { margin-bottom: 6px; }
  .play-layout .rm-game-videos .rm-tile { aspect-ratio: 4 / 3; max-height: 30vh; }
  .play-layout .rm-game .rm-ctrl { gap: 6px; }
  .play-layout .rm-game .rm-ctrl .btn { padding: 5px 9px; font-size: 12px; }
}

/* Controles de câmera/microfone: toque rápido (sem atraso de duplo toque no iPhone) */
.rm-ctrl .btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.rm-ctrl .btn i[data-ic] { display: inline-flex; font-style: normal; }
.rm-ctrl .btn:not(.on):is([data-cam],[data-mic]) { color: var(--bad); }

/* Celular: mesa compacta. Vídeos numa faixa (adversário maior, depois você e quem assiste), tabuleiro logo abaixo */
@media (max-width: 900px) {
  .rm-ctrl .btn { min-width: 44px; min-height: 40px; justify-content: center; padding: 6px 10px; }
  .rm-ctrl .btn > span { display: none; }
  .rm-match .rm-ctrl [data-leave] > span { display: inline; font-size: 12px; } /* mesa: o botão de sair com o nome, para ninguém procurar */
  .rm-ctrl .btn .ico { width: 20px; height: 20px; }
  .rm-match .rm-head { flex-wrap: nowrap; margin-bottom: 8px; gap: 8px; }
  .rm-match .rm-head-l { flex: 1; min-width: 0; }
  .rm-match .rm-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .rm-match .rm-head-r .rm-ctrl { flex-wrap: nowrap; gap: 4px; }
  .rm-match .rm-grid { gap: 8px; }
  .rm-match .rm-videos { gap: 6px; scroll-snap-type: none; }
  .rm-match .rm-tile { flex: 0 0 26vw; max-width: 130px; aspect-ratio: auto; height: min(22vh, 170px); border-radius: 10px; }
  .rm-match .rm-tile.seat { flex-basis: 40vw; max-width: 200px; }
  .rm-match .rm-tile-bar { font-size: 11px; padding: 3px 6px; }
  .rm-match .rm-tile-ph .avatar { width: 36px; height: 36px; font-size: 14px; }
  .rm-match .rm-tile-st { font-size: 10px; top: 4px; right: 4px; }
  .rm-match .rm-pbar { min-height: 36px; padding: 2px 0; }
  .rm-match .rm-board .board-wrap { max-width: 100%; }
  .rm-match [data-online] { text-decoration: underline; }
}

/* Barra de vantagem (Stockfish) e rating em jogo */
.advbar { display: flex; align-items: center; gap: 6px; margin: 2px 0 6px; font-size: 12px; font-weight: 800; }
.advbar[hidden] { display: none; }
.advbar-l, .advbar-r { min-width: 34px; font-variant-numeric: tabular-nums; }
.advbar-r { text-align: right; }
.advbar-track { position: relative; flex: 1; height: 10px; border-radius: 6px; overflow: hidden; background: #2b2c30; box-shadow: inset 0 0 0 1px rgba(127, 127, 127, .35); }
.advbar-track.wk { background: #f1f1f1; }
.advbar-track i { position: absolute; left: 0; top: 0; bottom: 0; transition: width .35s; }
.advbar-track i.w { background: #f1f1f1; } .advbar-track i.b { background: #2b2c30; }
.advbar-mid { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 2px; background: var(--brand); opacity: .8; }
.stakes { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; margin-top: 6px; }
.stk { display: inline-flex; gap: 5px; align-items: center; }
.stk-r { font-weight: 800; }
.stk-w, .stk-d, .stk-l { padding: 0 5px; border-radius: 5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stk-w { background: var(--ok-bg); color: var(--ok); } .stk-d { background: var(--surface-2); } .stk-l { background: rgba(229, 72, 77, .12); color: var(--bad); }
/* Mesa com fila */
.rm-queue { padding: 14px; }
.rm-qlist { margin: 0 0 8px; padding-left: 22px; font-size: 14px; }
.rm-qlist li { padding: 2px 0; }
.rm-queue-act:empty { display: none; }
@media (max-width: 900px) { .rm-head-r [data-invite] > span { display: none; } .rm-head-r [data-invite] { min-height: 40px; } }
/* mesa no celular: com o botão Amigos, o título fica numa linha e os botões na de baixo (sem um por cima do outro) */
@media (max-width: 900px) {
  .rm-match .rm-head:has([data-friends]) { flex-wrap: wrap; }
  .rm-match .rm-head:has([data-friends]) .rm-head-l { flex: 1 1 100%; }
  .rm-match .rm-head:has([data-friends]) .rm-head-r { flex: 1 1 100%; flex-wrap: wrap; gap: 4px; }
  .rm-head-r [data-friends] { min-height: 40px; }
}

/* aviso fixo: minha câmera ou meu microfone está desligado */
.rm-mediawarn { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; border-color: var(--bad); background: rgba(229, 72, 77, .12); }
.rm-mediawarn .grow { flex: 1 1 200px; } .rm-mediawarn .ico { width: 16px; height: 16px; vertical-align: -3px; }
.rm-game .rm-mediawarn { margin-bottom: 8px; font-size: 13px; padding: 8px 10px; }
