:root {
  --bg: #070a12;
  --surface: #0d121f;
  --surface-2: #131a2b;
  --hover: #1b2439;
  --line: rgb(148 163 204 / .14);
  --line-strong: rgb(148 163 204 / .26);
  --text: #e8ecf8;
  --muted: #8b95b3;
  --cyan: #22d3ee;
  --violet: #8b5cf6;
  --gradient: linear-gradient(135deg, var(--cyan), var(--violet));
  --speaking: #34e5a4;
  --danger: #ff4d6d;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

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

body {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}
ul { list-style: none; }
h1 { font-size: 26px; letter-spacing: -.02em; }
h2 { font-size: 17px; letter-spacing: -.01em; }

/* ---------- Controles ---------- */

button, input, select {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 9px 14px;
  transition: background-color .15s, border-color .15s, box-shadow .15s, filter .15s;
}
input, select { width: 100%; background: var(--bg); }
input:focus, select:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgb(34 211 238 / .15); }
button { background: var(--surface-2); cursor: pointer; font-weight: 500; white-space: nowrap; }
button:hover { background: var(--hover); }
button:disabled { opacity: .45; cursor: default; }
button.primary { border: 0; background: var(--gradient); color: #050814; font-weight: 700; }
button.primary:hover { filter: brightness(1.12); box-shadow: 0 0 24px rgb(34 211 238 / .35); }
button.danger { border-color: rgb(255 77 109 / .45); background: rgb(255 77 109 / .12); color: #ff8fa3; }
button.danger:hover { background: rgb(255 77 109 / .22); }
button.active { border-color: var(--danger); color: #ff8fa3; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
input[type="range"] { padding: 0; border: 0; box-shadow: none; accent-color: var(--cyan); }

svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.muted { color: var(--muted); }
.hint { font-size: 12px; }
.error { color: #ff8fa3; }
.error:empty { display: none; }
.grow { flex: 1; min-width: 0; }
.grow strong, .grow small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grow small { color: var(--muted); font-size: 12px; }

.logo { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; background: var(--gradient); color: #050814; box-shadow: 0 0 18px rgb(34 211 238 / .35); }
.logo svg { stroke-width: 2.4; }
.logo.big { width: 52px; height: 52px; border-radius: 15px; }
.logo.big svg { width: 28px; height: 28px; }

.avatar { width: 28px; height: 28px; flex: none; display: grid; place-items: center; border-radius: 9px; color: #fff; font-size: 13px; font-weight: 700; text-transform: uppercase; }

.live { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; background: var(--danger); color: #fff; font: 700 10px/1.5 var(--mono); letter-spacing: .08em; white-space: nowrap; }
.live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #fff; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Barra lateral ---------- */

#sidebar { width: 284px; flex: none; display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.brand { height: 64px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 18px; border-bottom: 1px solid var(--line); font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.section-title { display: flex; justify-content: space-between; align-items: center; padding: 16px 12px 6px 18px; color: var(--muted); font: 600 11px var(--mono); letter-spacing: .12em; text-transform: uppercase; }

button.icon { position: relative; flex: none; width: 32px; height: 32px; padding: 0; display: grid; place-items: center; background: transparent; border-color: transparent; color: var(--muted); }
button.icon:hover { background: var(--hover); color: var(--text); }
button.icon.active { color: var(--danger); background: rgb(255 77 109 / .14); }
button.icon.active::after { content: ""; position: absolute; width: 22px; height: 2px; background: currentColor; transform: rotate(-45deg); }
#new-room-button { font-size: 20px; }

#channels { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 10px; }
#rooms-empty { padding: 8px; }
.channel { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px; border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--muted); text-align: left; }
button.channel:hover { background: var(--hover); border-color: var(--line); color: var(--text); }
.channel.current { background: linear-gradient(90deg, rgb(34 211 238 / .14), rgb(139 92 246 / .08)); border-color: rgb(34 211 238 / .28); color: var(--text); }
.channel.current svg { color: var(--cyan); }
.channel-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.timer { color: var(--speaking); font: 11px var(--mono); }

.members { padding: 4px 0 10px 18px; }
.members li { display: flex; align-items: center; gap: 10px; padding: 5px 8px; border-radius: 10px; color: var(--muted); user-select: none; }
#people li { color: var(--text); }
#people li:hover { background: var(--hover); }
#people li .avatar { transition: box-shadow .12s; }
#people li.speaking { background: rgb(52 229 164 / .08); }
#people li.speaking .avatar { box-shadow: 0 0 0 2px var(--speaking), 0 0 14px rgb(52 229 164 / .6); }
.person-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 11px; color: var(--muted); }
.status:empty { display: none; }
.flags { display: flex; align-items: center; gap: 5px; }
.flags svg { width: 14px; height: 14px; color: var(--muted); }
.flags .live { font-size: 9px; padding: 1px 6px; }
.flags .live::before { display: none; }
.off { position: relative; display: grid; place-items: center; }
.off::after { content: ""; position: absolute; width: 17px; height: 2px; background: var(--danger); transform: rotate(-45deg); }

#user-bar { display: flex; align-items: center; gap: 2px; margin: 10px; padding: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; }
#user-bar .avatar { width: 34px; height: 34px; margin-right: 8px; border-radius: 11px; }

/* ---------- Área principal ---------- */

#content {
  flex: 1;
  min-width: 0;
  display: flex;
  background:
    radial-gradient(900px 420px at 80% -10%, rgb(139 92 246 / .16), transparent 70%),
    radial-gradient(700px 400px at 0% 100%, rgb(34 211 238 / .11), transparent 70%),
    linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / 40px 40px,
    var(--bg);
}
#lobby, #call { flex: 1; min-width: 0; min-height: 0; }
#lobby { display: grid; place-items: center; padding: 24px; overflow-y: auto; }
.card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 10px; padding: 32px; background: rgb(13 18 31 / .92); border: 1px solid var(--line-strong); border-radius: 20px; box-shadow: 0 30px 80px rgb(0 0 0 / .45); }
.card label { margin-top: 4px; }
.card button { margin-top: 8px; padding: 11px; }

#call { display: flex; flex-direction: column; }
.call-header { height: 64px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 24px; border-bottom: 1px solid var(--line); background: rgb(13 18 31 / .75); }
.call-header h2 { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-header h2::before { content: "# "; color: var(--cyan); }
.chip { padding: 3px 10px; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--muted); font: 11px var(--mono); white-space: nowrap; }
#notice { padding: 12px 24px 0; }

#call-body { flex: 1; min-height: 0; display: flex; }
#stage { flex: 1; min-width: 0; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; padding: 20px 24px; }

#toggle-chat { margin-left: auto; display: flex; align-items: center; gap: 8px; padding: 6px 14px; }
.badge { min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font: 700 11px/18px var(--mono); }
#chat { width: 300px; flex: none; min-height: 0; display: flex; flex-direction: column; margin: 16px 16px 0 0; background: rgb(13 18 31 / .94); border: 1px solid var(--line-strong); border-radius: 16px; overflow: hidden; }
#chat header { display: flex; justify-content: space-between; align-items: center; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); }
#close-chat { font-size: 20px; }
#messages { flex: 1; min-height: 0; overflow-y: auto; list-style: none; padding: 10px 12px; display: flex; flex-direction: column; gap: 12px; }
#messages:empty::before { content: "Nenhuma mensagem ainda. Elas somem quando a sala fica vazia."; color: var(--muted); font-size: 12px; }
#messages li { display: flex; gap: 10px; }
#messages li > div:last-child { min-width: 0; }
#messages time { margin-left: 6px; color: var(--muted); font: 11px var(--mono); }
#messages p { white-space: pre-wrap; overflow-wrap: anywhere; }
#chat-error { padding: 0 12px; font-size: 12px; }
#chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
#chat-form input { min-width: 0; }

#send-stats.warning { color: #fbbf24; border-color: #fbbf24; }
#watch-title, #watch-stats { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#watch-title { flex-basis: 90px; }
#watch-stats { font-family: var(--mono); font-size: 11px; }

.check { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.check input { width: auto; accent-color: var(--cyan); }

#watch { flex: 1; min-height: 320px; display: flex; flex-direction: column; background: #000; border: 1px solid var(--line-strong); border-radius: 16px; overflow: hidden; box-shadow: 0 0 40px rgb(34 211 238 / .12); }
.watch-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface); }
.watch-bar button { padding: 6px 12px; font-size: 13px; }
.screen { position: relative; flex: 1; min-height: 0; }
.screen video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; cursor: zoom-in; }
#watch-loading { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }

#streams { flex: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
#streams:empty { display: none; }
.stream { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; transition: border-color .15s, transform .15s; }
.stream:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.stream.watching { border-color: var(--cyan); box-shadow: 0 0 22px rgb(34 211 238 / .22); }
.preview { position: relative; aspect-ratio: 16 / 9; display: grid; place-items: center; overflow: hidden; background: radial-gradient(circle at 50% 40%, rgb(139 92 246 / .3), transparent 65%), var(--bg); }
.preview .avatar { width: 64px; height: 64px; border-radius: 20px; font-size: 26px; }
.preview video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.preview .live { position: absolute; top: 10px; left: 10px; }
.stream footer { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.stream footer button { padding: 7px 14px; font-size: 13px; }

/* quem está assistindo vê os cartões menores, abaixo da tela */
#watch:not([hidden]) + #streams { grid-template-columns: repeat(auto-fill, minmax(260px, 320px)); }
#watch:not([hidden]) + #streams .preview { display: none; }

#no-screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 32px 12px; }
#no-screen svg { width: 56px; height: 56px; stroke-width: 1.2; color: var(--cyan); filter: drop-shadow(0 0 14px rgb(34 211 238 / .55)); margin-bottom: 8px; }
#no-screen strong { font-size: 17px; }

#voice-panel { flex: none; align-self: center; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; max-width: calc(100% - 32px); margin-bottom: 16px; padding: 10px 14px; background: rgb(19 26 43 / .95); border: 1px solid var(--line-strong); border-radius: 18px; box-shadow: 0 18px 50px rgb(0 0 0 / .5); }
.voice-status { padding-right: 8px; max-width: 160px; }
.voice-status strong, .voice-status small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-status strong { color: var(--speaking); font-size: 13px; }
.voice-status small { color: var(--muted); font: 11px var(--mono); }
.quality span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
#quality { width: auto; font-size: 13px; }

/* ---------- Janelas ---------- */

dialog { margin: auto; width: min(430px, calc(100% - 32px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--text); border: 1px solid var(--line-strong); border-radius: 20px; padding: 24px; box-shadow: 0 30px 80px rgb(0 0 0 / .6); }
dialog::backdrop { background: rgb(3 5 11 / .75); backdrop-filter: blur(4px); }
dialog form { display: flex; flex-direction: column; gap: 10px; }
#meter { position: relative; height: 10px; flex: none; background: var(--bg); border-radius: 999px; overflow: hidden; }
#meter-level { height: 100%; width: 0; background: linear-gradient(90deg, var(--speaking), var(--cyan)); }
#meter-threshold { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; }

#person-menu { position: fixed; z-index: 10; width: 232px; display: flex; flex-direction: column; gap: 8px; padding: 14px; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 14px; box-shadow: 0 16px 40px rgb(0 0 0 / .6); overflow-wrap: anywhere; }

@media (max-width: 820px) {
  #sidebar { width: 232px; }
  .voice-status { display: none; }
}

/* em janelas estreitas o chat fica por cima da área das telas */
@media (max-width: 1000px) {
  #call-body { position: relative; }
  #chat { position: absolute; z-index: 5; top: 0; right: 0; bottom: 0; }
}
