/* ==========================================================================
   TelaJunto — estilo
   Fundo escuro com gradiente animado e padrao de baloes de conversa;
   paineis em vidro (glass) por cima.
   ========================================================================== */

:root {
  --bg: #0a0c14;
  --glass: rgba(255, 255, 255, 0.045);
  --glass-2: rgba(255, 255, 255, 0.075);
  --glass-3: rgba(255, 255, 255, 0.11);
  --line: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.16);
  --fg: #eef0f7;
  --muted: #9aa0b8;
  --accent: #7c8cff;
  --accent-2: #5865f2; /* blurple do Discord */
  --teal: #22d3ee;
  --pink: #ec4899;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

/* O JS liga/desliga tudo com o atributo `hidden`. Sem isto, qualquer classe
   com `display: grid/flex` venceria o [hidden] e o elemento continuaria na
   tela (foi o que aconteceu com a home embaixo da sala e com o "Conectando…"
   por cima do video). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--fg);
  font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
/* O fundo fica so no <html>: se o <body> tambem tivesse, ele pintaria por
   cima do .bg (z-index negativo) e esconderia o gradiente. */
html { background: var(--bg); }
body { background: transparent; }

a { color: var(--accent); }
h1, h2 { margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 700; }

button, input, select { font: inherit; }

/* ------------------------------- fundo ---------------------------------- */

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background:
    radial-gradient(1200px 700px at 80% -10%, rgba(88, 101, 242, 0.22), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(34, 211, 238, 0.14), transparent 60%),
    var(--bg);
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
  will-change: transform;
  animation: float 22s ease-in-out infinite alternate;
}
.b1 { width: 560px; height: 560px; background: #5865f2; top: -180px; left: -140px; }
.b2 { width: 520px; height: 520px; background: #22d3ee; right: -200px; top: 15%; animation-delay: -7s; animation-duration: 26s; }
.b3 { width: 620px; height: 620px; background: #ec4899; bottom: -300px; left: 28%; animation-delay: -13s; animation-duration: 30s; opacity: .32; }
@keyframes float {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(90px, 60px, 0) scale(1.12); }
}

/* Padrao de baloes de conversa: dois baloes por tile, bem sutil. */
.bubbles {
  position: absolute;
  inset: 0;
  opacity: 0.07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='260' height='260' viewBox='0 0 260 260' fill='none' stroke='white' stroke-width='2'><path d='M30 60h90a16 16 0 0 1 16 16v34a16 16 0 0 1-16 16H72l-22 18v-18H30a16 16 0 0 1-16-16V76a16 16 0 0 1 16-16z'/><path d='M150 160h70a14 14 0 0 1 14 14v26a14 14 0 0 1-14 14h-10v16l-20-16h-40a14 14 0 0 1-14-14v-26a14 14 0 0 1 14-14z'/><circle cx='60' cy='93' r='3' fill='white'/><circle cx='76' cy='93' r='3' fill='white'/><circle cx='92' cy='93' r='3' fill='white'/><path d='M166 187h40M166 200h26' stroke-linecap='round'/></svg>");
  background-size: 260px 260px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,.9), rgba(0,0,0,.35));
}
.grain {
  position: absolute;
  inset: 0;
  opacity: 0.05;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

@media (prefers-reduced-motion: reduce) {
  .blob { animation: none; }
}

/* ------------------------------- vidro ---------------------------------- */

.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--shadow);
}

/* ------------------------------- views ---------------------------------- */

.view { height: 100%; }
/* !important: #view-home e #view-room definem display:grid por id, que
   venceria o [hidden] e deixaria as duas telas visiveis, uma embaixo da outra. */
.view[hidden] { display: none !important; }
.centered { display: grid; place-items: center; padding: 1.5rem; }

.muted { color: var(--muted); }
.fineprint { font-size: .8125rem; color: var(--muted); margin: 1rem 0 0; }

.card {
  width: min(30rem, 100%);
  border-radius: var(--radius-lg);
  padding: 2rem;
  text-align: center;
}
.hero { padding: 2.75rem 2.25rem; }
.brand { display: flex; align-items: center; justify-content: center; gap: .75rem; }
.brand h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(90deg, #fff, #c7ccff 60%, #9ee8f5);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-mark { font-size: 2.25rem; line-height: 1; filter: drop-shadow(0 6px 18px rgba(124, 140, 255, .45)); }
.brand.small { gap: .5rem; font-weight: 700; }
.brand.small .brand-mark { font-size: 1.3rem; }
.tagline { color: var(--muted); font-size: 1.02rem; margin: .9rem auto 1.5rem; max-width: 30rem; }

.avatar-lg { width: 72px; height: 72px; border-radius: 50%; }
.avatar-sm { width: 30px; height: 30px; border-radius: 50%; flex: none; background: var(--glass-2); }
.avatar-xs { width: 22px; height: 22px; border-radius: 50%; flex: none; background: var(--glass-2); }

/* ------------------------------- botoes --------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  border: 1px solid var(--line-2);
  background: var(--glass-2);
  color: var(--fg);
  border-radius: var(--radius);
  padding: .625rem 1rem;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
}
.btn:hover { background: var(--glass-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: progress; }

.btn-sm { padding: .35rem .65rem; font-size: .8125rem; border-radius: 10px; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--glass-2); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(88, 101, 242, .35);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: rgba(248, 113, 113, .08); border-color: rgba(248, 113, 113, .3); color: #ffb4b4; }
.btn-danger:hover { background: rgba(248, 113, 113, .16); }
.btn-discord {
  background: var(--accent-2);
  border-color: transparent;
  color: #fff;
  width: 100%;
  padding: .85rem 1rem;
  font-weight: 600;
  box-shadow: 0 8px 26px rgba(88, 101, 242, .4);
}
.btn-discord:hover { background: #6b76f5; }

.btn-control[data-on="true"] { border-color: var(--accent); background: rgba(124, 140, 255, .18); }
.btn-control .ico { font-size: 1.05rem; }

.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

/* ------------------------------- inputs --------------------------------- */

input[type="text"], input[type="password"] {
  width: 100%;
  background: rgba(0, 0, 0, .25);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  color: var(--fg);
  padding: .7rem .85rem;
  min-width: 0;
}
input::placeholder { color: #737a94; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.stack { display: flex; flex-direction: column; gap: .55rem; margin-top: .9rem; }
.row { display: flex; gap: .5rem; margin-top: 1rem; }
.row input { flex: 1; }

.select {
  background: rgba(0, 0, 0, .25);
  border: 1px solid var(--line-2);
  color: var(--fg);
  border-radius: var(--radius);
  padding: .625rem .6rem;
}

.tag {
  display: inline-block;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: .15rem .45rem;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--muted);
}
.tag.admin { color: #ffd28a; border-color: rgba(251, 191, 36, .4); background: rgba(251, 191, 36, .1); }
.tag.owner { color: #b8f5d9; border-color: rgba(52, 211, 153, .4); background: rgba(52, 211, 153, .1); }
.tag.live { color: #fff; background: var(--pink); border-color: transparent; }

/* ------------------------------- topbar --------------------------------- */

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .6rem 1rem;
  border-left: none;
  border-right: none;
  border-top: none;
  border-radius: 0;
  box-shadow: none;
}
.who { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.who-text { line-height: 1.2; }
.who-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-handle { font-size: .75rem; color: var(--muted); }
.room-id { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.room-id strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.05rem; }
.lock { font-size: .9rem; cursor: help; }
.lock[hidden] { display: none; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; box-shadow: 0 0 0 3px rgba(255,255,255,.05); }
.dot.ok { background: var(--ok); box-shadow: 0 0 12px rgba(52, 211, 153, .6); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

/* -------------------------------- home ---------------------------------- */

#view-home { display: grid; grid-template-rows: auto 1fr; grid-template-areas: "top" "main"; }

.home {
  grid-area: main;
  padding: 1.5rem;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
  overflow: auto;
}
.channels { min-width: 0; }
.channels-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .25rem; }
.channels-title { display: flex; align-items: baseline; gap: .9rem; }
.channels-title h2 { font-size: 1.35rem; font-weight: 800; }
.hint-line { margin: 0 0 1rem; font-size: .85rem; }
.status { display: inline-flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--muted); }

.channel-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr));
  gap: .8rem;
}
.channel {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform .15s, border-color .15s, background .15s;
}
.channel:hover { transform: translateY(-2px); border-color: var(--line-2); background: var(--glass-2); }
.channel.live { border-color: rgba(236, 72, 153, .45); box-shadow: 0 0 0 1px rgba(236, 72, 153, .15), var(--shadow); }
.channel-main {
  all: unset;
  cursor: pointer;
  display: block;
  padding: 1rem 1.05rem .9rem;
  flex: 1;
  color: var(--fg);
  text-decoration: none;
}
.channel-main:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: var(--radius-lg); }
.channel-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.channel-name { font-weight: 700; font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-meta { display: flex; flex-wrap: wrap; gap: .3rem .8rem; margin-top: .45rem; color: var(--muted); font-size: .8rem; }
.channel-faces { display: flex; margin-top: .6rem; }
.channel-faces .avatar-xs { margin-right: -6px; border: 2px solid #12141f; }
.channel-actions { padding: 0 .75rem .75rem; display: flex; justify-content: flex-end; }

.empty { border-radius: var(--radius-lg); padding: 2.5rem 1.5rem; text-align: center; }
.empty p { margin: .2rem 0; }
.empty-icon { font-size: 2.4rem; margin-bottom: .4rem; }

/* -------------------------------- sala ---------------------------------- */

#view-room {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "top  top"
    "side main"
    "ctrl ctrl";
  gap: 0;
}

.sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  padding: .75rem 0 .75rem .75rem;
  min-height: 0;
}
.people-panel, .chat-panel {
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.people-panel { flex: 0 1 auto; max-height: 46%; }
.chat-panel { flex: 1 1 0; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .7rem .9rem .5rem;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.count { background: var(--glass-3); border-radius: 999px; padding: 0 .5rem; font-size: .72rem; color: var(--fg); }

.people { list-style: none; margin: 0; padding: 0 .5rem .5rem; overflow-y: auto; }
.person {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .45rem .5rem;
  border-radius: 12px;
  border: 1px solid transparent;
  position: relative;
}
.person .avatar-sm { transition: box-shadow .12s; }
.person.speaking .avatar-sm { box-shadow: 0 0 0 2px var(--ok), 0 0 14px rgba(52, 211, 153, .55); }
.person-text { flex: 1; min-width: 0; line-height: 1.15; }
.person-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.person-name em { color: var(--muted); font-style: normal; font-size: .78rem; }
.person-tags { display: flex; gap: .3rem; margin-top: .15rem; }
.badges { display: flex; gap: .25rem; align-items: center; }
.badge { font-size: .9rem; opacity: .85; }
.badge.share { filter: drop-shadow(0 0 5px var(--pink)); }
.kick {
  opacity: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: .1rem .3rem;
  border-radius: 8px;
}
.person:hover .kick, .kick:focus { opacity: 1; }
.kick:hover { color: var(--bad); background: rgba(248, 113, 113, .12); }

/* chat */
.chat { list-style: none; margin: 0; padding: .25rem .75rem; overflow-y: auto; flex: 1; scroll-behavior: smooth; }
.chat-item { display: flex; gap: .55rem; padding: .3rem 0; font-size: .9rem; animation: pop .18s ease-out; }
.chat-item .body { min-width: 0; overflow-wrap: anywhere; }
.chat-from { font-weight: 600; }
.chat-time { color: var(--muted); font-size: .72rem; margin-left: .4rem; }
.chat-text.jumbo { font-size: 2rem; line-height: 1.15; }
.chat-notice { text-align: center; font-size: .76rem; color: var(--muted); padding: .25rem 0; }
.chat-notice.bad { color: #ffb4b4; }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.chat-form { display: flex; gap: .4rem; padding: .5rem .6rem .6rem; border-top: 1px solid var(--line); align-items: center; }
.chat-form input { flex: 1; padding: .55rem .7rem; border-radius: 12px; }
.emote-btn { font-size: 1.1rem; padding: .3rem .45rem; }

.emote-picker {
  margin: 0 .6rem;
  padding: .5rem;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: rgba(10, 12, 20, .85);
  max-height: 11rem;
  overflow-y: auto;
}
.emote-picker[hidden] { display: none; }
.emote-group { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: .25rem .2rem; }
.emote-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(2rem, 1fr)); gap: .15rem; }
.emote {
  all: unset;
  cursor: pointer;
  text-align: center;
  font-size: 1.25rem;
  line-height: 2rem;
  border-radius: 8px;
}
.emote:hover { background: var(--glass-3); transform: scale(1.15); }
.emote[title]::after { content: none; }

/* palco */
.stage-wrap {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: .75rem;
  gap: .6rem;
}
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: rgba(0, 0, 0, .55);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.stage-empty { text-align: center; padding: 2rem; max-width: 34rem; }
.stage-empty p { margin: .25rem 0; }
.stage-empty-icon { font-size: 3rem; margin-bottom: .5rem; }

/* mosaico: N tiles em grade; colunas definidas inline pelo JS (ceil(sqrt(N))) */
.tiles {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 4px;
  padding: 4px;
  grid-auto-rows: 1fr;
  align-items: stretch;
}
.tiles:empty { display: none; }
.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  display: grid;
  place-items: center;
}
.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.tile.mirror video { transform: scaleX(-1); }
.tile-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .45rem .6rem;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .7));
  opacity: 0;
  transition: opacity .15s;
}
.tile:hover .tile-bar, .tile:focus-within .tile-bar, .tile.waiting .tile-bar { opacity: 1; }
.tile-label { font-size: .8125rem; font-weight: 600; text-shadow: 0 1px 3px rgba(0,0,0,.8); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-actions { display: flex; gap: .3rem; flex: none; }
.tile-btn {
  background: rgba(0, 0, 0, .55);
  border: 1px solid var(--line-2);
  color: var(--fg);
  border-radius: 8px;
  padding: .2rem .5rem;
  cursor: pointer;
  font-size: .85rem;
}
.tile-btn:hover { background: var(--glass-3); }
.tile-wait { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: .9rem; background: rgba(0,0,0,.4); }
/* Sem isso o display:grid acima vence o [hidden] e o aviso fica por cima do video. */
.tile-wait[hidden] { display: none; }
.tile:fullscreen { border-radius: 0; }
.tile:fullscreen video { object-fit: contain; }

/* quem esta transmitindo */
.sharers { display: flex; flex-wrap: wrap; gap: .5rem; min-height: 0; }
.sharers:empty { display: none; }
.sharer {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  padding: .4rem .7rem .4rem .45rem;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--glass-2);
  color: var(--fg);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.sharer:hover { background: var(--glass-3); }
.sharer.active { border-color: var(--pink); background: rgba(236, 72, 153, .15); }
.sharer .play { font-size: .75rem; color: var(--muted); }
.sharer.active .play { color: #ffc2dd; }

/* controles */
.controls {
  grid-area: ctrl;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  flex-wrap: wrap;
  padding: .7rem;
  border-left: none;
  border-right: none;
  border-bottom: none;
  border-radius: 0;
  box-shadow: none;
}

/* -------------------------------- rodape --------------------------------- */

.credits {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: .55rem 1rem calc(.55rem + env(safe-area-inset-bottom));
  text-align: center;
  font-size: .78rem;
  color: var(--muted);
  background: linear-gradient(180deg, transparent, rgba(8, 9, 14, .85));
  pointer-events: none;
  z-index: 5;
}
.credits strong { color: var(--fg); font-weight: 600; }
.credits a {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  color: #a9b4ff;
  text-decoration: none;
  vertical-align: middle;
}
.credits a:hover { color: #fff; text-decoration: underline; }
/* Dentro da sala o rodape e a barra de controles; o credito sai de cena. */
body[data-view="room"] .credits { display: none; }
/* Na tela de login e de canais, deixa espaco para o rodape nao cobrir nada. */
body[data-view="home"] .home { padding-bottom: 3.5rem; }

/* -------------------------------- avisos --------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 5.5rem;
  transform: translateX(-50%);
  border-radius: var(--radius);
  padding: .65rem 1rem;
  max-width: min(32rem, 90vw);
  z-index: 40;
  background: rgba(16, 18, 28, .85);
}
.toast[hidden] { display: none; }
.unmute-audio {
  position: fixed;
  top: 4rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--warn);
  color: #201a04;
  border: none;
  border-radius: 999px;
  padding: .5rem 1rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 30;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(5, 6, 12, .7);
  backdrop-filter: blur(6px);
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal h2 { font-size: 1.25rem; margin: .5rem 0; }
.modal .error { color: var(--bad); }

/* ------------------------------- responsivo ------------------------------ */

@media (max-width: 960px) {
  .channels-head { flex-wrap: wrap; }
  #view-room {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(38vh, 1fr) minmax(0, 18rem) auto;
    grid-template-areas: "top" "main" "side" "ctrl";
  }
  .sidebar { flex-direction: row; padding: 0 .75rem .75rem; }
  .people-panel { max-height: none; flex: 0 0 42%; }
  .controls .lbl { display: none; }
  .who-text, #me-role { display: none; }
}
