:root {
  --bg-deep:      #1a1b1e;
  --bg:           #26272b;
  --bg-soft:      #2f3035;
  --bg-hover:     #3a3b41;
  --tile:         #101114;
  --border:       #3a3b41;
  --text:         #e6e7ea;
  --text-dim:     #9ca0a8;
  --accent:       #5b6ef5;
  --accent-hover: #4a5de0;
  --danger:       #ed4245;
  --danger-hover: #d63a3d;
  --success:      #35c46a;
  --warn:         #e5a13a;
  --radius:       10px;
  --radius-lg:    14px;
  --shadow:       0 8px 28px rgba(0, 0, 0, .45);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
button:disabled { opacity: .45; cursor: not-allowed; }
input, select { font-family: inherit; }

.screen { display: none; height: 100dvh; }
.screen.active { display: flex; }

/* ---------- Lobby ---------- */

#lobby {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
}

.lobby-inner { width: 100%; max-width: 880px; }

.brand {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 6px;
}
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: grid; place-items: center;
  font-size: 22px; flex-shrink: 0;
}
.brand h1 { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.lobby-sub { color: var(--text-dim); font-size: 14px; margin-bottom: 26px; }

.field { margin-bottom: 22px; }
.field label {
  display: block; font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-dim); margin-bottom: 8px;
}
.name-row { display: flex; gap: 10px; }
.name-row input {
  flex: 1; min-width: 0;
  background: var(--tile); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 12px 14px; font-size: 15px; outline: none;
  transition: border-color .15s;
}
.name-row input:focus { border-color: var(--accent); }
.btn-dice {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0 16px; font-size: 18px; transition: background .15s;
}
.btn-dice:hover { background: var(--bg-hover); }

.rooms { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }

.room-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px; text-align: left; display: flex; flex-direction: column; gap: 6px;
  transition: border-color .15s, background .15s, transform .1s;
}
.room-card:hover:not(:disabled) { border-color: var(--accent); background: var(--bg-soft); transform: translateY(-2px); }
.room-card:disabled { opacity: .5; }
.room-card .rc-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.room-card h3 { font-size: 15px; font-weight: 600; }
.room-card p { font-size: 13px; color: var(--text-dim); line-height: 1.4; }
.badge {
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: var(--bg-soft); color: var(--text-dim); white-space: nowrap;
}
.badge.live { background: rgba(53, 196, 106, .15); color: var(--success); }
.badge.full { background: rgba(237, 66, 69, .15); color: var(--danger); }
.room-card .who {
  font-size: 12px; color: var(--text-dim); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 16px;
}

/* ---------- Sala ---------- */

#room { flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar .room-name { font-weight: 600; font-size: 15px; }
.topbar .room-meta { font-size: 12px; color: var(--text-dim); }
.topbar .spacer { flex: 1; }

.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; }
.conn-dot.on { background: var(--success); }
.conn-dot.bad { background: var(--danger); }

.stage { flex: 1; display: flex; min-height: 0; }

.grid-wrap { flex: 1; padding: 14px; overflow: hidden; min-width: 0; }
.grid {
  display: grid; gap: 12px; height: 100%;
  grid-auto-rows: 1fr;
}

.tile {
  position: relative; background: var(--tile); border-radius: var(--radius-lg);
  overflow: hidden; border: 2px solid transparent; min-height: 0;
  transition: border-color .12s;
}
.tile.speaking { border-color: var(--success); }
.tile.is-screen { border-color: var(--accent); }

.tile video {
  width: 100%; height: 100%; object-fit: contain; display: block; background: #000;
}
.tile video.cover { object-fit: cover; }
.tile video.mirror { transform: scaleX(-1); }
.tile.no-video video { display: none; }

.avatar {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center; flex-direction: column; gap: 10px;
}
.tile.no-video .avatar { display: flex; }
.avatar .circle {
  width: 84px; height: 84px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: grid; place-items: center; font-size: 30px; font-weight: 700;
  transition: box-shadow .12s;
}
.tile.speaking .avatar .circle { box-shadow: 0 0 0 5px rgba(53, 196, 106, .35); }

.tile-bar {
  position: absolute; left: 8px; bottom: 8px; right: 8px;
  display: flex; align-items: center; gap: 6px;
  pointer-events: none;
}
.tile-name {
  background: rgba(0, 0, 0, .68); backdrop-filter: blur(6px);
  padding: 4px 10px; border-radius: 6px; font-size: 12.5px; font-weight: 500;
  max-width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile-icons { display: flex; gap: 4px; }
.tile-icon {
  background: rgba(0, 0, 0, .68); backdrop-filter: blur(6px);
  width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; font-size: 12px;
}
.tile-icon.muted { color: var(--danger); }

.tile-vol {
  position: absolute; top: 8px; right: 8px;
  display: flex; align-items: center; gap: 6px;
  background: rgba(0, 0, 0, .7); backdrop-filter: blur(6px);
  padding: 5px 9px; border-radius: 8px;
  opacity: 0; transition: opacity .15s;
}
.tile:hover .tile-vol { opacity: 1; }
.tile-vol input { width: 74px; accent-color: var(--accent); cursor: pointer; }
.tile-vol .vlabel { font-size: 11px; color: var(--text-dim); width: 30px; text-align: right; }

/* ---------- acoes do tile ---------- */

.tile-acts {
  position: absolute; top: 8px; right: 8px;
  display: flex; gap: 4px;
  opacity: 0; transition: opacity .15s; z-index: 3;
}
.tile:hover .tile-acts, .tile:focus-within .tile-acts { opacity: 1; }
.tile-act {
  width: 28px; height: 28px; border-radius: 7px;
  background: rgba(0, 0, 0, .72); backdrop-filter: blur(6px);
  display: grid; place-items: center; font-size: 13px; line-height: 1;
  transition: background .13s;
}
.tile-act:hover { background: var(--accent); }

/* O volume desce quando as acoes ocupam o canto, para nao se sobreporem. */
.tile:hover .tile-vol { opacity: 1; top: 44px; }

/* ---------- modo destaque ---------- */

/*
 * O tile destacado ocupa toda a largura e a altura restante; as miniaturas
 * quebram para a linha de baixo, numa faixa de altura fixa. flex-wrap com
 * width:100% no destaque e o que produz a quebra sem precisar de um wrapper
 * extra no DOM.
 */
.grid.spotlight-mode {
  display: flex !important;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 12px;
}

.grid.spotlight-mode .tile.is-spot {
  flex: 1 1 100%;
  width: 100%;
  min-height: 0;
  /* Altura = tudo menos a faixa de miniaturas e o gap. */
  height: calc(100% - 124px);
  /* O destaque vem primeiro visualmente; as miniaturas descem para baixo dele
     sem depender da ordem de insercao no DOM. */
  order: 0;
}

/* Sem miniaturas (so o destaque na sala), ele ocupa a altura inteira. */
.grid.spotlight-mode .tile.is-spot:only-child { height: 100%; }

.grid.spotlight-mode .tile.is-thumb {
  flex: 0 0 auto;
  width: 198px;
  height: 112px;
  order: 1;
}

/* Numa miniatura pequena, so o nome cabe. */
.grid.spotlight-mode .tile.is-thumb .tile-vol,
.grid.spotlight-mode .tile.is-thumb .tile-stats { display: none; }
.grid.spotlight-mode .tile.is-thumb .tile-name { font-size: 11px; padding: 3px 7px; }
.grid.spotlight-mode .tile.is-thumb .avatar .circle { width: 46px; height: 46px; font-size: 17px; }
.grid.spotlight-mode .tile.is-thumb .tile-act { width: 24px; height: 24px; font-size: 11px; }

/* A tela compartilhada em destaque nunca deve ser cortada. */
.grid.spotlight-mode .tile.is-spot video { object-fit: contain; }

/* Em tela cheia o tile ocupa tudo e o video usa contain para nao cortar. */
.tile:fullscreen { border-radius: 0; border: none; background: #000; }
.tile:fullscreen video { object-fit: contain; }
.tile:fullscreen .tile-name { font-size: 14px; }

.tile-stats {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0, 0, 0, .7); backdrop-filter: blur(6px);
  padding: 4px 8px; border-radius: 6px; font-size: 10.5px; color: var(--text-dim);
  font-variant-numeric: tabular-nums; opacity: 0; transition: opacity .15s;
}
.tile:hover .tile-stats { opacity: 1; }

/* ---------- Painel lateral ---------- */

.side {
  width: 300px; flex-shrink: 0; background: var(--bg);
  border-left: 1px solid var(--border); display: none; flex-direction: column;
}
.side.open { display: flex; }
.side-head {
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-dim); display: flex; justify-content: space-between; align-items: center;
}
.side-body { flex: 1; overflow-y: auto; padding: 12px; }

.chat-msg { margin-bottom: 12px; font-size: 13.5px; line-height: 1.45; word-break: break-word; }
.chat-msg .who { font-weight: 600; font-size: 12px; color: var(--accent); display: block; margin-bottom: 2px; }
.chat-msg.sys { color: var(--text-dim); font-style: italic; font-size: 12.5px; }
.chat-form { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.chat-form input {
  flex: 1; min-width: 0; background: var(--tile); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: 9px 12px; font-size: 13.5px; outline: none;
}
.chat-form input:focus { border-color: var(--accent); }

.plist-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; font-size: 13.5px; }
.plist-item:hover { background: var(--bg-soft); }
.plist-item .circle {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.plist-item .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist-item .picons { display: flex; gap: 5px; font-size: 12px; color: var(--text-dim); }
.plist-item .picons .off { color: var(--danger); }

/* ---------- Barra de controles ---------- */

.controls {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 16px; background: var(--bg); border-top: 1px solid var(--border);
  flex-shrink: 0; flex-wrap: wrap;
}

.ctrl {
  width: 50px; height: 50px; border-radius: 50%;
  background: var(--bg-soft); display: grid; place-items: center;
  font-size: 19px; transition: background .14s, transform .08s; position: relative;
}
.ctrl:hover:not(:disabled) { background: var(--bg-hover); }
.ctrl:active:not(:disabled) { transform: scale(.93); }
.ctrl.off { background: var(--danger); }
.ctrl.off:hover { background: var(--danger-hover); }
.ctrl.on { background: var(--accent); }
.ctrl.on:hover { background: var(--accent-hover); }
.ctrl.leave { background: var(--danger); width: auto; padding: 0 22px; border-radius: 25px; font-size: 14px; font-weight: 600; gap: 8px; display: flex; align-items: center; }
.ctrl.leave:hover { background: var(--danger-hover); }
.ctrl.wide { width: auto; padding: 0 18px; border-radius: 25px; font-size: 14px; gap: 8px; display: flex; align-items: center; }

.ctrl-group { display: flex; align-items: center; gap: 6px; }
.ctrl-sep { width: 1px; height: 30px; background: var(--border); margin: 0 4px; }

.master-vol { display: flex; align-items: center; gap: 8px; padding: 0 6px; }
.master-vol input { width: 92px; accent-color: var(--accent); cursor: pointer; }

.tip {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  background: #000; color: #fff; font-size: 11.5px; padding: 5px 9px; border-radius: 6px;
  white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 30;
}
.ctrl:hover .tip { opacity: 1; }

/* ---------- Modal ---------- */

.modal-bg {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .72);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); width: 100%; max-width: 480px; max-height: 88vh;
  display: flex; flex-direction: column;
}
.modal-head {
  padding: 18px 20px 14px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-head h2 { font-size: 17px; font-weight: 600; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

.sel-group { margin-bottom: 18px; }
.sel-group:last-child { margin-bottom: 0; }
.sel-group label {
  display: block; font-size: 11px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-dim); margin-bottom: 7px;
}
.sel-group select {
  width: 100%; background: var(--tile); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 10px 12px; font-size: 14px; outline: none; cursor: pointer;
}
.sel-group select:focus { border-color: var(--accent); }
.sel-hint { font-size: 12px; color: var(--text-dim); margin-top: 6px; line-height: 1.45; }

.meter { height: 7px; background: var(--tile); border-radius: 4px; overflow: hidden; margin-top: 9px; }
.meter > i { display: block; height: 100%; width: 0%; background: var(--success); transition: width .07s linear; }

.btn {
  padding: 10px 18px; border-radius: 8px; font-size: 14px; font-weight: 600;
  background: var(--bg-soft); transition: background .14s;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.block { width: 100%; }

.radio-list { display: flex; flex-direction: column; gap: 8px; }
.radio-item {
  display: flex; align-items: center; gap: 11px; padding: 12px 14px;
  background: var(--tile); border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer; transition: border-color .14s, background .14s; text-align: left;
}
.radio-item:hover { border-color: var(--accent); background: var(--bg-soft); }
.radio-item.sel { border-color: var(--accent); background: rgba(91, 110, 245, .1); }
.radio-item .ri-ico { font-size: 21px; flex-shrink: 0; }
.radio-item .ri-txt strong { display: block; font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.radio-item .ri-txt span { font-size: 12.5px; color: var(--text-dim); line-height: 1.4; }

.toast-wrap {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: calc(100% - 32px); max-width: 460px;
}
.toast {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 9px;
  padding: 11px 16px; font-size: 13.5px; box-shadow: var(--shadow);
  animation: drop .2s ease; text-align: center;
}
.toast.err { border-color: var(--danger); color: #ffb9ba; }
.toast.ok  { border-color: var(--success); }
@keyframes drop { from { opacity: 0; transform: translateY(-10px); } }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (max-width: 860px) {
  .side { position: absolute; right: 0; top: 0; bottom: 0; z-index: 50; box-shadow: var(--shadow); }
  .master-vol input { width: 64px; }
  .topbar .room-meta { display: none; }
}
@media (max-width: 560px) {
  .controls { gap: 7px; padding: 11px 8px; }
  .ctrl { width: 45px; height: 45px; font-size: 17px; }
  .master-vol { display: none; }
  .grid-wrap { padding: 8px; }
  .rooms { grid-template-columns: 1fr; }
}
