:root {
  --page: #1e1f22;
  --card: #2b2d31;
  --call: #000;
  --tile: #1e1f22;
  --dock: #111214;
  --btn: #2b2d31;
  --btn-h: #3f4147;
  --text: #f2f3f5;
  --muted: #949ba4;
  --accent: #5865f2;
  --accent-h: #4752c4;
  --green: #23a559;
  --red: #da373c;
  --red-h: #a12828;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--page);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; margin-left: 8px; }

/* ---------- Entrada ---------- */
.join { height: 100%; display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%; max-width: 420px; background: var(--card);
  padding: 32px; border-radius: 12px; display: flex; flex-direction: column; gap: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.card h1 { margin: 0; font-size: 28px; }
.sub { margin: 0; color: var(--muted); font-size: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--muted); }
input[type=text], input:not([type]) {
  background: var(--page); border: 1px solid transparent; color: var(--text);
  padding: 10px 12px; border-radius: 6px; font-size: 15px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.row { display: flex; gap: 8px; }
.error { color: #ff7b7f; min-height: 18px; margin: 0; font-size: 13px; }

/* ---------- Botões ---------- */
button {
  border: 0; border-radius: 6px; padding: 10px 16px; font-size: 14px; font-weight: 600;
  color: var(--text); cursor: pointer; transition: background .15s, transform .05s;
  font-family: inherit;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: var(--accent); }
.primary:hover { background: var(--accent-h); }
.ghost { background: var(--btn); }
.ghost:hover { background: var(--btn-h); }

/* ---------- Sala ---------- */
.app { height: 100%; display: flex; flex-direction: column; background: var(--call); }
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--page); border-bottom: 1px solid #000;
}
.room-info { display: flex; align-items: center; gap: 8px; }
.stage { flex: 1; min-height: 0; padding: 12px; }

/* Grade de participantes (como o Discord) */
.grid {
  width: 100%; height: 100%;
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; align-content: center;
}
.tile {
  position: relative; flex: 0 0 auto;
  width: var(--tw, 320px); height: var(--th, 180px);
  background: var(--tile); border-radius: 12px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
/* anel verde de quem está falando */
.tile::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  border: 3px solid transparent; pointer-events: none; z-index: 5; transition: border-color .1s;
}
.tile.speaking::after { border-color: var(--green); }
.tile:fullscreen { width: 100vw !important; height: 100vh !important; border-radius: 0; }
.tile:fullscreen::after { display: none; }

.person .avatar {
  height: 42%; aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 700;
  font-size: calc(var(--th, 180px) * .2);
  user-select: none;
}
.person video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; background: #000; }
.person.cam-on video { display: block; }
.person.cam-on .avatar { display: none; }
.person.self video { transform: scaleX(-1); }

.name {
  position: absolute; left: 8px; bottom: 8px; z-index: 4; max-width: calc(100% - 16px);
  background: rgba(0,0,0,.65); padding: 3px 9px; border-radius: 6px; font-size: 13px;
  display: flex; align-items: center; gap: 6px;
}
.name .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { display: none; font-size: 12px; }
.person.mic-off .badge.mic { display: inline; }
.person.conn-bad .badge.warn { display: inline; }

/* Tile de transmissão */
.stream { background: #111214; }
.stream video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; display: none; }
.stream.watching video, .stream.own video { display: block; }
.placeholder { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 8px; }
.placeholder .big { font-size: calc(var(--th, 180px) * .22); line-height: 1; }
.placeholder .ptxt { color: var(--muted); font-size: 13px; }
.stream.watching .placeholder, .stream.own .placeholder { display: none; }

.overlay {
  position: absolute; inset: 0; z-index: 3; display: none; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 16px;
  background: rgba(0,0,0,.72); font-size: 14px;
}
.stream.connecting .overlay, .stream.stalled .overlay { display: flex; }
.overlay .rbtn { display: none; }
.stream.stalled .overlay .rbtn { display: inline-block; }
.spin {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.2); border-top-color: #fff; animation: spin 0.9s linear infinite;
}
.stream.stalled .spin { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.live-label {
  position: absolute; left: 10px; top: 10px; z-index: 4; display: none; align-items: center; gap: 8px;
  background: rgba(0,0,0,.65); padding: 4px 10px; border-radius: 6px; font-size: 13px; max-width: calc(100% - 20px);
}
.stream.watching .live-label, .stream.own .live-label { display: flex; }
.live-label .dot { width: 8px; height: 8px; background: var(--red); border-radius: 50%; flex: 0 0 auto; }
.live-label .stats { color: #b5bac1; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4; padding: 10px 12px;
  display: none; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap;
  background: linear-gradient(transparent, rgba(0,0,0,.8)); opacity: 0; transition: opacity .2s;
}
.stream.watching .bar, .stream.own .bar { display: flex; }
.stream:hover .bar, .stream:fullscreen .bar, .stream.stalled .bar { opacity: 1; }
.bar input[type=range] { width: 100px; accent-color: var(--accent); }
.bar button { padding: 6px 10px; background: rgba(255,255,255,.15); font-size: 13px; }
.bar button:hover { background: rgba(255,255,255,.28); }
.bar .stopw, .bar .stops { background: rgba(218,55,60,.85); }
.bar .stopw:hover, .bar .stops:hover { background: var(--red); }
.bar .viewers { margin-right: auto; font-size: 13px; }

/* Modo foco: ao assistir uma transmissão, ela ocupa a tela e o pessoal vai para baixo */
.grid.focus { align-content: flex-start; overflow-y: auto; }
.grid.focus .tile { --th: 112px; width: 200px; height: 112px; }
.grid.focus .tile.stream.watching {
  order: -1; flex: 1 1 100%; width: auto; --th: 400px;
  height: calc(100% - 128px); min-height: 260px;
}
.grid.focus.multi .tile.stream.watching { flex: 1 1 calc(50% - 8px); }
.grid.focus .stream .ptxt { display: none; }
.grid.focus .person .avatar { font-size: 24px; }
.grid.focus .name { font-size: 11px; left: 4px; bottom: 4px; padding: 2px 6px; }
.grid.focus .tile.stream:fullscreen { width: 100vw !important; height: 100vh !important; }

/* ---------- Dock inferior ---------- */
.dock-wrap { position: relative; display: flex; justify-content: center; padding: 8px 12px 14px; }
.dock { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; padding: 8px; background: var(--dock); border-radius: 14px; }
.dbtn { height: 44px; min-width: 48px; border-radius: 10px; background: var(--btn); font-size: 16px; padding: 0 14px; }
.dbtn:hover { background: var(--btn-h); }
.dbtn.off { background: var(--red); }
.dbtn.off:hover { background: var(--red-h); }
.dbtn.on { background: #fff; color: #111; }
.dbtn.live { background: var(--red); }
.dbtn.live:hover { background: var(--red-h); }
.dbtn.leave { background: var(--red); }
.dbtn.leave:hover { background: var(--red-h); }
.split { display: flex; gap: 2px; }
.split .wide { border-radius: 10px 0 0 10px; }
.split .caret { border-radius: 0 10px 10px 0; min-width: 34px; padding: 0 8px; }

.menu {
  position: absolute; bottom: 72px; z-index: 20; width: min(340px, 92vw);
  background: var(--dock); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.6);
}
select {
  background: var(--page); color: var(--text); border: 1px solid transparent;
  padding: 9px 10px; border-radius: 6px; font-size: 14px; width: 100%;
}
.check { flex-direction: row; align-items: center; gap: 8px; text-transform: none; font-size: 13px; font-weight: 500; color: var(--text); }

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); max-width: min(560px, 92vw);
  background: #111214; padding: 10px 16px; border-radius: 8px; font-size: 14px; text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.5); z-index: 30;
}
