/* Mesmos tokens do app de desktop (tema escuro): trilho < sidebar < canvas; entradas mais escuras que o entorno. */
:root {
  --rail: #1e1f22;
  --stage: #1e1f22;
  --sidebar: #2b2d31;
  --canvas: #313338;
  --input: #1e1f22;
  --hover: #35373c;
  --active: #404249;
  --text: #dbdee1;
  --muted: #949ba4;
  --header: #f2f3f5;
  --blurple: #5865f2;
  --blurple-hover: #4752c4;
  --green: #23a55a;
  --yellow: #f0b232;
  --red: #f23f42;
  --red-button: #da373c;
  --radius-sm: 4px;
  --radius-md: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--rail);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
a { color: #8ea1ff; }
h1, h2 { margin: 0; color: var(--header); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--header); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.spacer { flex: 1; }

.screen { min-height: 100dvh; }

/* ---------- entrada ---------- */
.join { display: grid; place-items: center; padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)); }
.card { width: 100%; max-width: 480px; background: var(--canvas); border-radius: var(--radius-md); padding: 24px; display: grid; gap: 14px; }
.card h1 { font-size: 24px; }
.card p { margin: 0; line-height: 1.5; }
.notice { background: var(--blurple-hover); color: #fff; border-radius: var(--radius-sm); padding: 10px 12px; }
.field { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; min-width: 0; }
.field-label { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--muted); padding: 0; }
.field input[type="text"], .field input[type="password"], .chat-form input {
  width: 100%; min-height: 44px; background: var(--input); border: 1px solid transparent; border-radius: var(--radius-sm); padding: 0 12px; font-size: 16px;
}
.field input:focus, .chat-form input:focus { border-color: var(--blurple); outline: none; }
.rooms { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.room-card { display: grid; gap: 2px; text-align: left; min-height: 56px; padding: 10px 12px; background: transparent; border: 1px solid var(--active); border-radius: var(--radius-sm); cursor: pointer; }
.room-card:hover { background: var(--hover); }
.room-card.selected { background: var(--active); border-color: var(--blurple); }
.choice { display: flex; gap: 10px; align-items: flex-start; min-height: 44px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.choice:hover { background: var(--hover); }
.choice input { margin-top: 4px; accent-color: var(--blurple); }
.choice span { display: grid; gap: 2px; }
.choice small { color: var(--muted); }
.status { min-height: 1.4em; color: var(--muted); }
.status.error { color: var(--red); }

.btn { min-height: 44px; padding: 0 16px; border: 0; border-radius: var(--radius-sm); background: var(--active); font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--blurple); color: #fff; }
.btn.primary:hover { background: var(--blurple-hover); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13px; }

/* ---------- sala ---------- */
.room { display: grid; grid-template-rows: auto 1fr auto; height: 100dvh; background: var(--stage); }
.bar { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: var(--safe-top) 12px 0; background: var(--stage); }
.bar h1 { font-size: 16px; }
.body { position: relative; min-height: 0; display: grid; }
.stage { display: grid; gap: 8px; padding: 8px; overflow: auto; align-content: start; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.stage[data-count="1"] { grid-template-columns: 1fr; align-content: stretch; }

.tile { position: relative; display: grid; grid-template-rows: 1fr auto; background: var(--sidebar); border-radius: var(--radius-md); padding: 4px; min-height: 180px; aspect-ratio: 16 / 9; border: 2px solid transparent; }
.stage[data-count="1"] .tile { aspect-ratio: auto; }
.tile.speaking { border-color: var(--green); }
.tile-media { position: relative; min-height: 0; display: grid; place-items: center; overflow: hidden; border-radius: var(--radius-sm); }
.tile-media video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile-media video.contain { object-fit: contain; }
.tile-media video.mirror { transform: scaleX(-1); }
.placeholder { display: grid; gap: 10px; justify-items: center; text-align: center; color: var(--muted); padding: 8px; }
.tile-label { display: flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 4px; }
.tile-name { font-weight: 600; font-size: 13px; color: var(--header); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-actions { margin-left: auto; display: flex; gap: 2px; }
.badge.live { background: var(--red-button); color: #fff; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: var(--radius-sm); }
.signal { display: inline-flex; color: var(--green); }
.signal[data-q="poor"] { color: var(--yellow); }
.signal[data-q="lost"] { color: var(--red); }

.avatar { display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 700; flex: none; }
.icon { display: inline-flex; }
.icon-btn { position: relative; display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text); cursor: pointer; }
.tile-actions .icon-btn { width: 32px; height: 32px; }
.icon-btn:hover { background: var(--hover); }
.icon-btn.danger { color: var(--red); }
.count-badge { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--red-button); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

.controls { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 10px 12px calc(12px + var(--safe-bottom)); background: var(--stage); flex-wrap: wrap; }
.icon-btn.round { width: 52px; height: 52px; border-radius: 50%; background: var(--sidebar); }
.icon-btn.round:hover { background: var(--active); }
.icon-btn.round.active { background: var(--header); color: var(--stage); }
.icon-btn.round.leave { background: var(--red-button); color: #fff; }
.icon-btn.round.leave:hover { background: #a12828; }

/* gavetas: folha inferior no celular, painel lateral em tela larga */
.drawer { position: absolute; left: 0; right: 0; bottom: 0; height: 70%; display: grid; grid-template-rows: auto 1fr auto; background: var(--canvas); border-radius: var(--radius-md) var(--radius-md) 0 0; box-shadow: 0 -4px 24px rgb(0 0 0 / 0.4); z-index: 5; }
.drawer#drawer-people { grid-template-rows: auto 1fr; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 16px; }
.drawer-title { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.people { list-style: none; margin: 0; padding: 0 12px 12px; overflow: auto; display: grid; gap: 12px; align-content: start; }
.person { background: var(--sidebar); border-radius: var(--radius-md); padding: 10px; display: grid; gap: 8px; }
.person-head { display: flex; align-items: center; gap: 10px; }
.person-head.speaking .avatar { box-shadow: 0 0 0 2px var(--green); }
.person-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.slider-row { display: grid; grid-template-columns: 90px 1fr 44px; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.slider-row input { width: 100%; accent-color: var(--blurple); min-height: 32px; }
.slider-value { text-align: right; }

.chat-list { overflow: auto; padding: 4px 16px; display: grid; align-content: start; gap: 2px; }
.msg { display: flex; gap: 10px; margin-top: 12px; }
.msg.cont { margin: 0 0 0 46px; }
.msg-head { display: flex; gap: 8px; align-items: baseline; }
.msg-head time { font-size: 11px; color: var(--muted); }
.msg-text { overflow-wrap: anywhere; white-space: pre-wrap; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.chat-form { display: flex; gap: 8px; padding: 12px 12px calc(12px + var(--safe-bottom)); }
.chat-form input { flex: 1; }

/* Tela larga: a gaveta vira uma coluna ao lado do palco (empurra os vídeos em vez de cobri-los) */
@media (min-width: 900px) {
  .body { grid-template-columns: minmax(0, 1fr) auto; }
  .drawer { position: static; width: 360px; height: auto; border-radius: 0; box-shadow: none; }
}

/* ---------- celular como câmera / microfone ---------- */
.companion { display: grid; grid-template-rows: auto 1fr auto auto; height: 100dvh; }
.comp-preview { display: grid; place-items: center; padding: 8px; min-height: 0; }
.comp-preview video { max-width: 100%; max-height: 100%; border-radius: var(--radius-md); background: #000; }
.meter { height: 10px; margin: 0 24px; background: var(--input); border-radius: var(--radius-sm); overflow: hidden; }
.meter-bar { height: 100%; width: 0; background: var(--green); transition: width 80ms linear; }
.companion .muted { padding: 8px 16px; }

.banner { position: fixed; left: 12px; right: 12px; bottom: calc(84px + var(--safe-bottom)); display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--blurple-hover); color: #fff; padding: 10px 12px; border-radius: var(--radius-md); z-index: 20; }
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%); max-width: calc(100% - 24px); background: #111214; color: var(--header); padding: 10px 14px; border-radius: var(--radius-md); z-index: 30; }

@media (prefers-reduced-motion: reduce) { .meter-bar { transition: none; } }
