:root {
  --bg: #313338;
  --side: #2b2d31;
  --dark: #1e1f22;
  --text: #f2f3f5;
  --muted: #949ba4;
  --blurple: #5865f2;
  --blurple-h: #4752c4;
  --green: #23a559;
  --red: #da373c;
  --red-h: #a12828;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 "Segoe UI", system-ui, -apple-system, sans-serif;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: #ff8a8d; margin: 0; }

/* Botões e campos */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 6px;
  padding: 10px 16px;
  background: #4e5058;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn:hover { background: #6d6f78; }
.btn.primary { background: var(--blurple); }
.btn.primary:hover { background: var(--blurple-h); }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: var(--red-h); }
.btn.on { background: var(--green); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn .ti { font-size: 20px; line-height: 1; }
.btn.small .ti { font-size: 15px; }

.quality {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--dark); border-radius: 6px; padding: 0 4px 0 12px;
  color: var(--muted); font-size: 13px; font-weight: 600;
}
.quality .ti { font-size: 18px; }
.quality select { background: transparent; padding: 10px 8px; color: var(--text); font-weight: 600; }
.quality select option { background: var(--dark); }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid #00a8fc; outline-offset: 2px; }

input, select {
  width: 100%;
  background: var(--dark);
  color: var(--text);
  border: 0;
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
}
select { width: auto; cursor: pointer; }

/* Lobby */
.lobby {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(60rem 36rem at 15% -10%, rgb(88 101 242 / .28), transparent 60%),
    radial-gradient(48rem 32rem at 105% 110%, rgb(35 165 89 / .16), transparent 60%),
    var(--dark);
}
.card {
  width: min(440px, 100%);
  background: rgb(43 45 49 / .86);
  border: 1px solid rgb(255 255 255 / .07);
  border-radius: 18px;
  padding: 32px;
  display: grid;
  gap: 18px;
  box-shadow: 0 24px 60px rgb(0 0 0 / .45);
  backdrop-filter: blur(10px);
}
.card p { margin: 0; }

.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { margin: 0; font: 800 32px/1 "Sora", "Segoe UI", system-ui, sans-serif; letter-spacing: -.02em; }
.logo {
  width: 46px; height: 46px; flex: none;
  display: block;
  border-radius: 14px;
  box-shadow: 0 8px 20px rgb(88 101 242 / .45);
}
.tagline { color: var(--muted); font-size: 15px; line-height: 1.5; }
.invited {
  display: flex; align-items: center; gap: 8px;
  width: fit-content; max-width: 100%;
  background: rgb(88 101 242 / .16); color: #c9cdfb;
  border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600;
}
.invited span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.field { display: grid; gap: 8px; }
.field > span { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.input {
  display: flex; align-items: center; gap: 10px;
  background: var(--dark);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0 6px 0 14px;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus-within { border-color: var(--blurple); box-shadow: 0 0 0 3px rgb(88 101 242 / .25); }
.input > .ti { color: var(--muted); font-size: 19px; }
.input input { flex: 1; min-width: 0; background: transparent; padding: 13px 0; font-size: 16px; outline: none; }
.icon-btn {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 36px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); font-size: 20px; cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: #35373c; color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid #00a8fc; }

.btn.big { padding: 14px 18px; font-size: 16px; border-radius: 10px; }

.perks {
  list-style: none; margin: 2px 0 0; padding: 18px 0 0;
  border-top: 1px solid rgb(255 255 255 / .07);
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  color: var(--muted); font-size: 13px;
}
.perks li { display: inline-flex; align-items: center; gap: 6px; }
.perks .ti { font-size: 17px; color: #8b93f8; }

/* App */
/* As colunas usam as mesmas unidades nos dois estados (264px minmax(0,1fr) ↔ 0px minmax(0,1fr)) para o
   navegador conseguir animar a transição do menu lateral. */
.app {
  height: 100%; height: 100dvh; display: grid;
  grid-template-columns: 264px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  transition: grid-template-columns .3s cubic-bezier(.4, 0, .2, 1);
}

.sidebar {
  background: var(--side); display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  transition: opacity .22s ease .05s, visibility 0s;
}
/* o conteúdo mantém a largura própria: durante a animação ele é cortado, não espremido */
.sidebar > * { min-width: 264px; }
/* Menu lateral recolhível: o botão de fechar fica no menu e o de abrir flutua no palco */
.room-title { position: relative; }
.sidebar-toggle { position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; font-size: 19px; }
.stage { position: relative; }
.sidebar-open {
  position: absolute; top: 12px; left: 12px; z-index: 5;
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 8px; border: 1px solid rgb(255 255 255 / .1);
  background: rgb(30 31 34 / .88); color: var(--text); font-size: 21px; cursor: pointer;
  backdrop-filter: blur(6px); transition: background .15s;
}
.sidebar-open:hover { background: rgb(53 55 60 / .95); }
.sidebar-open:focus-visible { outline: 2px solid #00a8fc; outline-offset: 2px; }
.app.sidebar-collapsed { grid-template-columns: 0px minmax(0, 1fr); }
/* some com fade e só depois sai da ordem de tabulação (visibility com atraso = duração da animação) */
.app.sidebar-collapsed .sidebar { opacity: 0; visibility: hidden; transition: opacity .18s ease, visibility 0s linear .3s; }
@keyframes pop-in { from { opacity: 0; transform: scale(.7) translateX(-6px); } }
.sidebar-open { animation: pop-in .26s cubic-bezier(.2, .9, .3, 1.2); }
@media (prefers-reduced-motion: reduce) {
  .app, .sidebar, .app.sidebar-collapsed .sidebar { transition: none; }
  .sidebar-open { animation: none; }
}

.room-title { padding: 16px; display: grid; gap: 6px; border-bottom: 1px solid var(--dark); }
.room-title strong { font-size: 18px; word-break: break-all; }
.section { padding: 16px 16px 6px; font-weight: 700; letter-spacing: .02em; }
.room-title, .section { flex: none; }
.members {
  list-style: none; margin: 0; padding: 0 8px 8px;
  flex: 1; min-height: 0; overflow-y: auto; /* só a lista rola */
  scrollbar-width: thin; scrollbar-color: #1a1b1e transparent;
}
.members li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px; }
.members li:hover { background: #35373c; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
  font-weight: 700; color: #fff;
}
.mute-icon { color: #f23f43; font-size: 17px; flex: none; }
.members .icon-btn.eye { width: 28px; height: 28px; font-size: 17px; flex: none; }

/* Não selecionar texto / abrir menu nativo ao segurar */
.members li, .tile, #micBtn { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* Voltando para a sala (F5): sem tela de entrada, só um aviso discreto */
.rejoin { display: none; }
html.rejoining #lobby { display: none; }
html.rejoining .rejoin {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-content: center; justify-items: center; gap: 12px;
  color: var(--muted); font-weight: 600;
}
html.rejoining .rejoin .ti { font-size: 32px; color: var(--blurple); }

.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 3s; } }

/* Aviso: clique para liberar áudio/vídeo (autoplay bloqueado) */
.unlock {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 1500;
  display: inline-flex; align-items: center; gap: 8px;
  max-width: calc(100% - 24px);
  background: var(--blurple); color: #fff; border: 0; border-radius: 999px;
  padding: 10px 18px; font: inherit; font-weight: 600; cursor: pointer;
  box-shadow: 0 8px 24px rgb(0 0 0 / .45);
}
.unlock:hover { background: var(--blurple-h); }
.unlock .ti { font-size: 20px; }

/* Modal de confirmação */
.modal {
  position: fixed; inset: 0; z-index: 2000;
  display: grid; place-items: center; padding: 16px;
  background: rgb(0 0 0 / .62); backdrop-filter: blur(3px);
  animation: fade .12s ease-out;
}
.modal-card {
  width: min(400px, 100%);
  background: var(--bg); border: 1px solid rgb(255 255 255 / .08);
  border-radius: 16px; padding: 24px;
  display: grid; gap: 10px; justify-items: start;
  box-shadow: 0 24px 60px rgb(0 0 0 / .55);
  animation: pop .14s ease-out;
}
.modal-card h2 { margin: 0; font-size: 20px; }
.modal-card p { margin: 0; line-height: 1.5; }
.modal-icon {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 12px; background: rgb(218 55 60 / .16); color: #ff8a8d; font-size: 24px;
  margin-bottom: 4px;
}
.modal-actions { justify-self: stretch; display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.97); } }
@media (prefers-reduced-motion: reduce) { .modal, .modal-card { animation: none; } }
@media (max-width: 520px) { .modal-actions .btn { flex: 1; } }

/* Menu de volume */
.vol-menu {
  position: fixed; z-index: 1000;
  width: 260px; padding: 12px;
  background: #111214; border: 1px solid rgb(255 255 255 / .08);
  border-radius: 12px; box-shadow: 0 12px 32px rgb(0 0 0 / .55);
  display: grid; gap: 12px;
}
.vol-title { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vol-row { display: grid; gap: 6px; }
.vol-top { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--muted); }
.vol-pct { font-variant-numeric: tabular-nums; }
.vol-ctl { display: flex; align-items: center; gap: 8px; }
.vol-ctl .icon-btn.is-muted { color: #f23f43; }
.vol-ctl input[type="range"] {
  flex: 1; min-width: 0; height: 28px; padding: 0; background: transparent;
  accent-color: var(--blurple); cursor: pointer;
}
.avatar { transition: box-shadow .12s; }
.members li.speaking .avatar { box-shadow: 0 0 0 2px var(--side), 0 0 0 4px var(--green); }
.members .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.live {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--red); color: #fff; font-size: 10px; font-weight: 800;
  padding: 3px 6px; border-radius: 4px; letter-spacing: .04em;
}
.live .ti { font-size: 15px; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.grid {
  flex: 1;
  min-height: 0;
  padding: 16px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));
  grid-auto-rows: 1fr;
  overflow: auto;
}
.empty { grid-column: 1 / -1; display: grid; place-content: center; text-align: center; }
.empty p { margin: 4px 0; }
.grid:has(.tile:not([hidden])) .empty { display: none; }

.tile {
  position: relative;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  min-height: 200px;
}
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; cursor: pointer; }
/* Ampliar: a tela escolhida ocupa sozinha todo o espaço da grade */
.grid.has-focus { grid-template-columns: minmax(0, 1fr); }
.grid:not(:has(.tile:not([hidden]) ~ .tile:not([hidden]))) .focus-btn { display: none; } /* uma tela só: nada para ampliar */
.grid.has-focus .tile:not(.focused) { display: none; } /* o áudio continua tocando */
.grid.has-focus .tile.focused video { cursor: zoom-out; }
.tile:fullscreen { border-radius: 0; }
.tile:fullscreen video { cursor: zoom-out; }
.tile .label {
  position: absolute; left: 10px; bottom: 10px;
  background: rgb(0 0 0 / .65); padding: 3px 8px; border-radius: 4px;
  font-size: 13px; font-weight: 600;
}
.tile .tools {
  position: absolute; right: 10px; top: 10px;
  display: flex; gap: 6px; opacity: 0; transition: opacity .15s;
}
.tile:hover .tools, .tile:focus-within .tools { opacity: 1; }
@media (hover: none) { .tile .tools { opacity: 1; } } /* toque: não existe "passar o mouse" */
.tile .tools .btn { background: rgb(0 0 0 / .7); padding: 6px 10px; font-size: 12px; }
.tile .tools .btn:hover { background: rgb(0 0 0 / .9); }

.controls {
  display: flex; justify-content: center; align-items: center; gap: 10px;
  padding: 14px; background: var(--side); flex-wrap: wrap;
}

@media (max-width: 720px) {
  /* Celular: o menu fica em cima; a animação é a altura dele encolhendo */
  .app, .app.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); transition: none; }
  .sidebar { max-height: 30vh; transition: max-height .3s cubic-bezier(.4, 0, .2, 1), opacity .22s ease; }
  .sidebar > * { min-width: 0; }
  .app.sidebar-collapsed .sidebar { max-height: 0; transition: max-height .3s cubic-bezier(.4, 0, .2, 1), opacity .18s ease, visibility 0s linear .3s; }
  .grid { padding: 8px; gap: 8px; }
  .tile { min-height: 180px; }
}

@media (max-width: 520px) {
  .card { padding: 24px 20px; border-radius: 16px; }
  .brand h1 { font-size: 28px; }
  .controls { gap: 8px; padding: 10px; }
  .controls .btn { padding: 10px 12px; }
  .quality > span { display: none; } /* só o ícone, para caber */
  .members .name { font-size: 14px; }
}
