:root {
  --bg: #313338;
  --bg-dark: #1e1f22;
  --bg-mid: #2b2d31;
  --tile: #232428;
  --text: #f2f3f5;
  --muted: #b5bac1;
  --blurple: #5865f2;
  --green: #23a55a;
  --red: #da373c;
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: var(--text);
  font: 15px/1.4 "gg sans", "Segoe UI", system-ui, sans-serif; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
svg { width: 24px; height: 24px; fill: currentColor; }

/* ---------- Entrada ---------- */
#join { height: 100%; display: grid; place-items: center; background: var(--blurple); padding: 16px; }
.card { background: var(--bg); padding: 32px; border-radius: var(--radius); width: min(420px, 100%);
  display: flex; flex-direction: column; gap: 14px; box-shadow: 0 8px 30px #0006; }
.card h1 { margin: 0; text-align: center; font-size: 24px; }
.card p { margin: 0 0 6px; text-align: center; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; color: var(--muted); }
label.check { flex-direction: row; align-items: center; text-transform: none; font-weight: 400;
  font-size: 14px; color: var(--text); }
input:not([type]), input[type=text], select { background: var(--bg-dark); color: var(--text); border: 0;
  border-radius: 4px; padding: 10px; font: inherit; text-transform: none; font-weight: 400; }
input[type=range] { width: 100%; accent-color: var(--blurple); }
.primary { background: var(--blurple); padding: 10px 16px; border-radius: 4px; font-weight: 600; }
.primary:hover { background: #4752c4; }
.ghost { background: transparent; padding: 8px 14px; border-radius: 4px; }
.ghost:hover { background: #ffffff14; }
.live { background: var(--red); padding: 10px 18px; border-radius: 4px; font-weight: 700; }

.error { margin: 0; color: #f38688; font-size: 14px; text-align: center; }
.link { background: none; color: var(--muted); font-size: 13px; padding: 2px; align-self: center; }
.link:hover { color: var(--text); text-decoration: underline; }
.download { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 4px;
  background: var(--bg-dark); color: var(--text); text-decoration: none; }
.download:hover { background: #ffffff0f; }
.download svg { color: var(--green); flex: none; }
.download span { display: flex; flex-direction: column; }
.download small { color: var(--muted); font-size: 12px; }

/* ---------- Chamada ---------- */
#app { height: 100%; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: #000; }
header svg { color: var(--muted); }
.spacer { flex: 1; }

#grid { flex: 1; min-height: 0; padding: 8px 16px; display: grid; gap: 8px; align-content: center;
  grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); overflow: auto; }
#grid.has-focus { align-content: stretch;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  grid-template-rows: minmax(0, 1fr); grid-auto-rows: 130px; }
#grid.has-focus .tile { aspect-ratio: auto; }
#grid.has-focus .tile.focused { grid-column: 1 / -1; grid-row: 1; }

.tile { position: relative; aspect-ratio: 16 / 9; background: var(--tile); border-radius: var(--radius);
  overflow: hidden; outline: 3px solid transparent; outline-offset: -3px; transition: outline-color .1s;
  cursor: pointer; }
.tile.speaking { outline-color: var(--green); }
.tile video { width: 100%; height: 100%; display: block; object-fit: cover; background: #000; }
.tile.screen video { object-fit: contain; }
.tile.mirror video { transform: scaleX(-1); }
.tile .avatar { position: absolute; inset: 0; display: grid; place-items: center; }
.tile .avatar span { width: 80px; height: 80px; border-radius: 50%; display: grid; place-items: center;
  font-size: 34px; font-weight: 700; background: var(--blurple); }
.tile.has-video .avatar { display: none; }
.tile:not(.has-video) video { display: none; }

.tile .label { position: absolute; left: 8px; bottom: 8px; padding: 3px 8px; border-radius: 4px;
  background: #000a; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; max-width: calc(100% - 60px); }
.tile .label .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .label svg { width: 16px; height: 16px; color: var(--red); }
.badge { background: var(--red); border-radius: 3px; padding: 0 4px; font-size: 11px; font-weight: 800; }
.tile .stats { position: absolute; left: 8px; top: 8px; padding: 4px 8px; border-radius: 4px; background: #000b;
  font: 11px/1.45 ui-monospace, Consolas, monospace; white-space: pre; pointer-events: none; }
.tile .fs { position: absolute; right: 8px; bottom: 8px; background: #000a; border-radius: 4px;
  padding: 4px; opacity: 0; transition: opacity .15s; }
.tile:hover .fs { opacity: 1; }
.tile .fs svg { width: 20px; height: 20px; display: block; }
.tile:fullscreen { border-radius: 0; }
.tile:fullscreen video { object-fit: contain; }

/* ---------- Controles ---------- */
.controls { display: flex; justify-content: center; gap: 12px; padding: 12px 16px 18px; background: #000; flex-wrap: wrap; }
.ctl { position: relative; width: 56px; height: 56px; border-radius: 50%; background: var(--bg-mid);
  display: grid; place-items: center; }
.ctl:hover { background: #3a3c42; }
.ctl.active { background: var(--green); }
.ctl.off::after { content: ""; position: absolute; width: 30px; height: 3px; background: var(--red);
  transform: rotate(-45deg); border-radius: 2px; box-shadow: 0 0 0 2px var(--bg-mid); }
.ctl.danger { background: var(--red); }
.ctl.danger:hover { background: #a12d2f; }

/* ---------- Diálogos ---------- */
dialog { background: var(--bg); color: var(--text); border: 0; border-radius: var(--radius); padding: 24px;
  width: min(480px, calc(100% - 32px)); }
dialog::backdrop { background: #000b; }
dialog form { display: flex; flex-direction: column; gap: 16px; }
dialog h2 { margin: 0; font-size: 20px; }
.row { display: flex; justify-content: flex-end; gap: 8px; }
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.presets button { background: var(--bg-dark); padding: 10px 6px; border-radius: 6px; border: 2px solid transparent;
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
.presets button small { color: var(--muted); font-size: 11px; }
.presets button.sel { border-color: var(--blurple); background: #5865f222; }

/* ---------- Admin / menu de participante ---------- */
label .opt { text-transform: none; font-weight: 400; }
input[type=password] { background: var(--bg-dark); color: var(--text); border: 0; border-radius: 4px;
  padding: 10px; font: inherit; }
.tile .crown { display: none; font-size: 13px; }
.tile.is-admin .crown { display: inline; }
.tile .more { position: absolute; right: 8px; top: 8px; background: #000a; border-radius: 4px;
  padding: 0 8px 4px; font-size: 18px; line-height: 1.2; opacity: 0; transition: opacity .15s; }
.tile:hover .more { opacity: 1; }
.ctl.locked { box-shadow: 0 0 0 2px var(--red) inset; }
#tileMenu { position: fixed; z-index: 20; min-width: 200px; background: #111214; border-radius: 6px;
  padding: 6px; box-shadow: 0 8px 24px #000a; display: flex; flex-direction: column; }
#tileMenu .menu-title { padding: 6px 8px; font-size: 12px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tileMenu button { background: transparent; text-align: left; padding: 8px; border-radius: 3px; font-size: 14px; }
#tileMenu button:hover { background: var(--blurple); }
#tileMenu button.danger { color: #f38688; }
#tileMenu button.danger:hover { background: var(--red); color: #fff; }
#tileMenu .vol { padding: 6px 8px 10px; }

#toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); background: var(--bg-dark);
  padding: 10px 16px; border-radius: 6px; box-shadow: 0 4px 16px #0008; opacity: 0; transition: opacity .2s;
  pointer-events: none; z-index: 10; }
#toast.show { opacity: 1; }
