:root {
  --bg-rail: #1e1f22;
  --bg-side: #2b2d31;
  --bg-main: #313338;
  --bg-elevated: #383a40;
  --bg-elevated-2: #3f4147;
  --border: #26272b;
  --text: #f2f3f5;
  --text-muted: #949ba4;
  --text-faint: #6d7079;
  --brand: #5865f2;
  --brand-strong: #4752c4;
  --brand-soft: rgba(88, 101, 242, 0.16);
  --success: #23a55a;
  --warning: #faa61a;
  --danger: #f23f43;
  --danger-strong: #d43a3f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-rail);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }
h1, h2 { margin: 0; }
button { font-family: inherit; }

/* ================= JOIN SCREEN ================= */

/* :not([hidden]) garante que o atributo hidden do HTML realmente esconda
   a tela — um seletor de ID com "display" fixo, sem essa guarda, ganha do
   [hidden] do navegador e a tela de entrada nunca some de verdade. */
#join-screen:not([hidden]) {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: var(--bg-main);
}

.join-card { width: 100%; max-width: 380px; text-align: center; }
.join-mark { font-size: 26px; font-weight: 700; margin-bottom: 8px; }
.join-sub { color: var(--text-muted); font-size: 15px; margin-bottom: 28px; line-height: 1.5; }

.field { text-align: left; margin-bottom: 16px; }
.field label {
  display: block; font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.03em; color: var(--text-muted); margin-bottom: 8px;
}
.field input {
  width: 100%; padding: 11px 12px; border-radius: 4px; border: 1px solid var(--border);
  background: var(--bg-rail); color: var(--text); font-size: 15px; outline: none;
}
.field input:focus { border-color: var(--brand); }
.field input.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.field input::placeholder { color: var(--text-faint); }

.btn-primary {
  width: 100%; padding: 12px; border-radius: 4px; border: none;
  background: var(--brand); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: var(--brand-strong); }
.join-hint { margin-top: 18px; font-size: 13px; color: var(--text-faint); }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ================= CALL SCREEN ================= */

#call-screen { min-height: 100vh; }

.app-shell {
  display: grid;
  grid-template-columns: 232px 1fr 280px;
  height: 100vh;
}

/* ---- left: voice sidebar ---- */

.voice-sidebar { background: var(--bg-side); display: flex; flex-direction: column; min-height: 0; }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { font-size: 15px; font-weight: 700; }

.invite-btn {
  width: 26px; height: 26px; border-radius: 4px; border: none; background: transparent;
  color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.invite-btn:hover { background: var(--bg-elevated); color: var(--text); }
.invite-btn svg { width: 16px; height: 16px; }
.invite-btn.copied { color: var(--success); }

.channel-list { padding: 12px 8px; flex: 1; overflow-y: auto; }
.channel-group-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em;
  color: var(--text-faint); padding: 4px 8px; margin-bottom: 2px;
}
.voice-channel {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 4px;
  color: var(--text); font-size: 14px; font-weight: 600; background: var(--bg-elevated);
}
.voice-channel svg { width: 16px; height: 16px; color: var(--success); flex-shrink: 0; }

.voice-members { padding: 4px 8px 10px 22px; display: flex; flex-direction: column; gap: 8px; }
.voice-member { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-muted); }
.voice-member .avatar-wrap { position: relative; flex-shrink: 0; }
.voice-member .avatar { width: 22px; height: 22px; font-size: 10px; }
.voice-member.talking { color: var(--text); }
.voice-member.talking .avatar-wrap .avatar { box-shadow: 0 0 0 2px var(--success); }
.voice-member .conn-note { font-size: 11px; color: var(--warning); margin-left: 2px; }
.voice-member-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.kick-btn {
  flex-shrink: 0; width: 20px; height: 20px; border-radius: 4px; border: none;
  background: transparent; color: var(--text-faint); cursor: pointer;
  display: none; align-items: center; justify-content: center;
}
.kick-btn svg { width: 12px; height: 12px; }
.kick-btn:hover { background: rgba(242, 63, 67, 0.15); color: var(--danger); }
.voice-member:hover .kick-btn { display: flex; }

.mini-mute {
  position: absolute; bottom: -2px; right: -2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--danger); border: 2px solid var(--bg-side);
  display: flex; align-items: center; justify-content: center;
}
.mini-mute svg { width: 7px; height: 7px; color: #fff; }

.sidebar-user { display: flex; flex-direction: column; gap: 8px; padding: 10px 8px; background: var(--bg-rail); }
.sidebar-user-top { display: flex; align-items: center; gap: 8px; }
.sidebar-user .avatar { width: 32px; height: 32px; font-size: 13px; }
.sidebar-user-info { line-height: 1.25; min-width: 0; }
.sidebar-user-info .name { font-size: 13px; font-weight: 600; }
.sidebar-user-info .status { font-size: 11px; color: var(--success); }
.sidebar-user-actions { display: flex; gap: 4px; justify-content: space-between; }

.icon-btn {
  flex: 1; height: 30px; border-radius: 4px; border: none; background: transparent;
  color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg-elevated); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.is-active { background: rgba(242, 63, 67, 0.15); color: var(--danger); }
.icon-btn.hangup { color: var(--danger); }
.icon-btn.hangup:hover { background: rgba(242, 63, 67, 0.14); }

/* ---- avatars ---- */

.avatar {
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; flex-shrink: 0;
}

/* ---- main call area ---- */

.call-main { background: var(--bg-main); display: flex; flex-direction: column; min-height: 0; }

.call-header {
  display: flex; align-items: center; gap: 8px; padding: 12px 18px;
  border-bottom: 1px solid var(--border); font-weight: 700; font-size: 15px;
}
.call-header svg { width: 17px; height: 17px; color: var(--text-faint); }

#quality-select {
  margin-left: auto; background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 6px 8px; font-size: 13px; font-weight: 500;
}

.call-body { flex: 1; position: relative; overflow-y: auto; display: flex; flex-direction: column; }

.grid-view {
  flex-wrap: wrap; align-content: center; justify-content: center; gap: 28px;
  padding: 40px; width: 100%; display: flex; flex: 1;
}

.voice-tile { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 140px; }
.voice-tile .avatar-wrap { position: relative; }
.voice-tile .avatar { width: 96px; height: 96px; font-size: 32px; transition: box-shadow 0.15s; }
.voice-tile.talking .avatar { box-shadow: 0 0 0 3px var(--success); }
.voice-tile-name { font-size: 14px; font-weight: 600; }

.volume-row { display: flex; align-items: center; gap: 6px; width: 100%; color: var(--text-faint); }
.volume-row svg { width: 13px; height: 13px; flex-shrink: 0; }
.volume-slider {
  flex: 1; height: 3px; appearance: none; -webkit-appearance: none;
  background: var(--bg-elevated-2); border-radius: 999px; outline: none; cursor: pointer;
}
.volume-slider::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none; width: 11px; height: 11px; border-radius: 50%;
  background: var(--brand); cursor: pointer;
}
.volume-slider::-moz-range-thumb {
  width: 11px; height: 11px; border-radius: 50%; background: var(--brand); border: none; cursor: pointer;
}

.share-indicator {
  position: absolute; bottom: -4px; right: -4px; width: 30px; height: 30px; border-radius: 50%;
  background: var(--brand); border: 3px solid var(--bg-main); display: flex; align-items: center; justify-content: center;
}
.share-indicator svg { width: 14px; height: 14px; color: #fff; }

.watch-btn {
  position: absolute; bottom: -34px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 5px; padding: 5px 12px; border-radius: 999px;
  background: var(--brand); color: #fff; font-size: 12px; font-weight: 600; cursor: pointer;
  white-space: nowrap; border: none;
}
.watch-btn:hover { background: var(--brand-strong); }
.watch-btn svg { width: 12px; height: 12px; }
.voice-tile.sharing { margin-bottom: 26px; }

.mic-badge {
  position: absolute; bottom: -2px; right: -2px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--danger); border: 3px solid var(--bg-main); display: flex; align-items: center; justify-content: center;
}
.mic-badge svg { width: 12px; height: 12px; color: #fff; }

.conn-note { font-size: 12px; color: var(--warning); }

/* ---- watch mode: shared screen in focus ---- */

.share-hero {
  position: relative; background: #1a1b1e; border-radius: 8px; overflow: hidden;
  margin: 20px 28px 0; aspect-ratio: 16 / 9; flex-shrink: 0;
}
.share-hero video { width: 100%; height: 100%; object-fit: contain; background: #000; }

.share-badge {
  position: absolute; top: 12px; left: 12px; display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px; background: rgba(16, 17, 19, 0.75); backdrop-filter: blur(6px);
  font-size: 13px; font-weight: 600;
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.back-to-grid {
  position: absolute; top: 12px; right: 12px; display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 4px; background: rgba(16, 17, 19, 0.75); border: none;
  color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer;
}
.back-to-grid:hover { background: rgba(16, 17, 19, 0.9); }
.back-to-grid svg { width: 14px; height: 14px; }

/* while watching, the tile grid becomes a filmstrip below the stage */
.call-body.watching .grid-view {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  overflow-x: auto;
  justify-content: flex-start;
  align-content: flex-start;
  padding: 16px 28px 28px;
  gap: 14px;
}
.call-body.watching .voice-tile { flex: 0 0 76px; width: 76px; gap: 6px; }
.call-body.watching .voice-tile .avatar { width: 52px; height: 52px; font-size: 18px; }
.call-body.watching .voice-tile-name { font-size: 12px; }
.call-body.watching .voice-tile.sharing { margin-bottom: 0; }
.call-body.watching .watch-btn, .call-body.watching .conn-note, .call-body.watching .volume-row { display: none; }

/* ---- floating control pill ---- */

.control-pill {
  position: sticky; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; padding: 8px; border-radius: 12px;
  background: var(--bg-elevated); box-shadow: 0 8px 24px rgba(0,0,0,0.35); z-index: 10;
  margin: auto auto 20px;
}
.pill-btn {
  width: 44px; height: 44px; border-radius: 8px; border: none; background: transparent;
  color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.pill-btn:hover { background: var(--bg-elevated-2); }
.pill-btn svg { width: 20px; height: 20px; }
.pill-btn.is-active { background: rgba(242, 63, 67, 0.18); color: var(--danger); }
.pill-btn.hangup { background: var(--danger); }
.pill-btn.hangup:hover { background: var(--danger-strong); }

/* ---- chat rail ---- */

.chat-rail { border-left: 1px solid var(--border); background: var(--bg-side); display: flex; flex-direction: column; min-height: 0; }
.chat-header { padding: 16px 18px; border-bottom: 1px solid var(--border); font-size: 14px; font-weight: 700; color: var(--text-muted); }
.chat-log { list-style: none; margin: 0; padding: 16px 18px; flex: 1; overflow-y: auto; font-size: 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-log li { word-wrap: break-word; line-height: 1.4; }
.chat-log li strong { color: var(--text); }
.chat-log li.system-msg { color: var(--text-faint); font-style: italic; font-size: 13px; }

.chat-form { display: flex; gap: 8px; padding: 14px; border-top: 1px solid var(--border); }
.chat-form input {
  flex: 1; padding: 10px 12px; border-radius: 4px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); font-size: 13.5px; outline: none;
}
.chat-form input:focus { border-color: var(--brand); }
.chat-form input::placeholder { color: var(--text-faint); }

.send-btn {
  width: 38px; height: 38px; border-radius: 4px; border: none; background: var(--brand);
  color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
}
.send-btn:hover { background: var(--brand-strong); }
.send-btn svg { width: 16px; height: 16px; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .voice-sidebar, .chat-rail { display: none; }
}

/* ---- botão secundário (tela de entrada) ---- */

.btn-secondary {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px; border-radius: 4px; border: 1px solid var(--border);
  background: transparent; color: var(--text-muted); font-size: 14px; font-weight: 600;
  cursor: pointer; margin-top: 10px;
}
.btn-secondary:hover { background: var(--bg-elevated); color: var(--text); }
.btn-secondary svg { width: 16px; height: 16px; }

/* ---- modal de configurações ---- */

/* :not([hidden]) de novo — mesmo motivo do #join-screen: um "display" fixo
   no seletor, sem essa guarda, ganha do atributo hidden do HTML e o modal
   nunca fecha de verdade (aparece por cima de tudo desde o carregamento). */
.modal-overlay:not([hidden]) {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

.modal-panel {
  width: 100%; max-width: 380px;
  background: var(--bg-side); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 700; margin: 0; }

.modal-body { padding: 18px 16px; display: flex; flex-direction: column; gap: 14px; }
.modal-body .field { margin-bottom: 0; }
.modal-body select {
  width: 100%; padding: 10px 12px; border-radius: 4px; border: 1px solid var(--border);
  background: var(--bg-rail); color: var(--text); font-size: 14px;
}

.level-meter {
  height: 8px; border-radius: 999px; background: var(--bg-rail); overflow: hidden;
}
.level-meter-bar {
  height: 100%; width: 0%; background: var(--success);
  transition: width 0.08s linear;
}

/* ---- timer da chamada ---- */

.call-timer {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12px; font-weight: 500; color: var(--text-faint);
}

/* ---- reações rápidas ---- */

.reaction-bar {
  display: flex; justify-content: center; gap: 6px;
  padding-bottom: 4px;
}
.reaction-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--bg-elevated); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.reaction-btn:hover { background: var(--bg-elevated-2); transform: scale(1.08); }

.floating-reaction {
  position: absolute; top: -6px; left: 50%; transform: translateX(-50%);
  font-size: 26px; pointer-events: none;
  animation: float-up-fade 1.3s ease-out forwards;
}
@keyframes float-up-fade {
  0% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -44px) scale(1.3); }
}

/* ---- apelido local ---- */

.nickname-btn {
  flex-shrink: 0; width: 20px; height: 20px; border-radius: 4px; border: none;
  background: transparent; color: var(--text-faint); cursor: pointer;
  display: none; align-items: center; justify-content: center;
}
.nickname-btn svg { width: 12px; height: 12px; }
.nickname-btn:hover { background: var(--bg-elevated-2); color: var(--text); }
.voice-member:hover .nickname-btn { display: flex; }
