:root {
  --bg-0: #1e1f22;
  --bg-1: #2b2d31;
  --bg-2: #313338;
  --bg-3: #383a40;
  --bg-hover: #3f4147;
  --text: #f2f3f5;
  --text-2: #b5bac1;
  --text-3: #80848e;
  --accent: #5865f2;
  --accent-2: #4752c4;
  --green: #23a55a;
  --red: #da373c;
  --red-2: #a12828;
  --radius: 10px;
  font-family: "gg sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg-0); color: var(--text); overflow: hidden; }
body { font-size: 14px; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.spacer { flex: 1; }
a { color: #00a8fc; }
svg { width: 20px; height: 20px; display: block; }

/* ---------- botões ---------- */
.btn {
  border: 0; border-radius: 6px; padding: 9px 16px; background: var(--bg-3); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 500;
  transition: background .15s;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--bg-3); }
.danger-text { color: #f23f42; }
.icon-btn {
  border: 0; background: transparent; color: var(--text-2); width: 32px; height: 32px; border-radius: 6px;
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.off { color: #f23f42; }
.icon-btn.danger:hover { color: #f23f42; }

/* ---------- login ---------- */
.auth {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at top left, #3c45a5 0%, transparent 55%),
              radial-gradient(ellipse at bottom right, #7a2f6b 0%, transparent 50%), var(--bg-0);
}
.auth-card {
  width: min(420px, 100%); background: var(--bg-2); border-radius: 14px; padding: 32px;
  display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.auth-logo {
  width: 56px; height: 56px; border-radius: 16px; margin: 0 auto; background: var(--accent);
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><path d='M9 13a7 7 0 0 1 14 0v4a3 3 0 0 1-3 3h-1v-7h3a6 6 0 0 0-12 0h3v7h-1a3 3 0 0 1-3-3z' fill='white'/></svg>");
  background-size: 70%; background-position: center; background-repeat: no-repeat;
}
.auth-card h1 { margin: 0; text-align: center; font-size: 24px; }
.auth-card > p { margin: 0; text-align: center; }
.auth-card .reg-only { display: none; }
.auth-card.register .reg-only { display: flex; }
.auth-card.register.no-invite .invite-field { display: none; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-2); letter-spacing: .02em; }
label.check { flex-direction: row; align-items: center; text-transform: none; font-weight: 500; font-size: 14px; }
input:not([type=checkbox]):not([type=range]), select {
  background: var(--bg-0); border: 1px solid transparent; border-radius: 6px; padding: 10px 12px; outline: none;
  text-transform: none; font-weight: 400; font-size: 15px; letter-spacing: 0; width: 100%;
}
input:focus, select:focus { border-color: var(--accent); }
.auth-error { color: #fa777c; margin: 0; min-height: 0; font-size: 13px; }
.auth-error:empty { display: none; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 260px 1fr 340px; height: 100vh; height: 100dvh; }
.app.chat-closed { grid-template-columns: 260px 1fr 0; }
.app.chat-closed .chat { display: none; }

.sidebar { background: var(--bg-1); display: flex; flex-direction: column; min-height: 0; }
.server-head {
  height: 48px; padding: 0 8px 0 16px; display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--bg-0); flex: none;
}
.channel-list { padding: 12px 8px; overflow-y: auto; flex: 1; min-height: 0; }
.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-3); padding: 4px 8px; letter-spacing: .02em; }
.section-label.spaced, .spaced { margin-top: 18px; }

.channel {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 6px; cursor: pointer;
  color: var(--text-3); font-weight: 500; font-size: 15px; position: relative;
}
.channel:hover { background: var(--bg-hover); color: var(--text-2); }
.channel.viewing { background: var(--bg-3); color: var(--text); }
.channel.in-voice { color: var(--text); }
.channel .ch-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel .ch-actions { display: none; gap: 2px; }
.channel:hover .ch-actions { display: flex; }
.channel .ch-actions .icon-btn { width: 24px; height: 24px; }
.channel .ch-actions svg { width: 16px; height: 16px; }
.channel.unread::before {
  content: ""; position: absolute; left: -8px; width: 8px; height: 8px; border-radius: 0 4px 4px 0; background: var(--text);
}
.channel.unread .ch-name { color: var(--text); font-weight: 600; }
.members { padding: 2px 0 6px 28px; }
.member {
  display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 6px; color: var(--text-2); cursor: default;
}
.member:hover { background: var(--bg-hover); }
.member .m-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.member .m-icons { display: flex; gap: 2px; color: var(--text-3); align-items: center; }
.member .m-icons svg { width: 15px; height: 15px; }
.member .m-icons .red { color: #f23f42; }
.live-badge { background: var(--red); color: #fff; font-size: 10px; font-weight: 800; padding: 1px 5px; border-radius: 8px; letter-spacing: .03em; }

.avatar {
  border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex: none;
  background-size: cover; background-position: center; position: relative; user-select: none;
  transition: box-shadow .1s;
}
.speaking > .avatar, .avatar.speaking { box-shadow: 0 0 0 2px var(--bg-1), 0 0 0 4px var(--green); }

.online-box { padding: 8px; border-top: 1px solid var(--bg-0); max-height: 30%; overflow-y: auto; flex: none; }
.online-user { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 6px; }
.online-user .ou-text { display: flex; flex-direction: column; min-width: 0; }
.online-user .ou-text small { color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot-online::after {
  content: ""; position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--green); border: 3px solid var(--bg-1);
}

.voice-status {
  display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 12px;
  border-top: 1px solid var(--bg-0); background: #232428; flex: none;
}
.vs-title { color: var(--green); font-weight: 700; font-size: 13px; }
.vs-channel { color: var(--text-2); font-size: 12px; }

.user-panel { display: flex; align-items: center; gap: 2px; padding: 8px; background: #232428; flex: none; }
.user-chip {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; border: 0; background: transparent;
  padding: 4px; border-radius: 6px; cursor: pointer; text-align: left;
}
.user-chip:hover { background: var(--bg-hover); }
.user-chip-text { display: flex; flex-direction: column; min-width: 0; }
.user-chip-text b, .user-chip-text small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip-text small { color: var(--text-3); font-size: 12px; }

/* ---------- palco ---------- */
.stage-wrap { background: var(--bg-2); display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.stage-head { height: 48px; display: flex; align-items: center; padding: 0 12px 0 16px; border-bottom: 1px solid var(--bg-0); flex: none; gap: 8px; }
.stage-title { font-weight: 700; font-size: 15px; }
.stage { flex: 1; min-height: 0; padding: 16px; display: grid; gap: 10px; align-content: center; justify-content: center;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, var(--tile-w, 1fr))); }
.stage.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; }
.stage.empty h2 { margin: 0; }
.join-cards { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.join-card {
  background: var(--bg-1); border: 0; border-radius: var(--radius); padding: 16px; width: 200px; cursor: pointer;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-start; text-align: left; transition: transform .12s, background .12s;
}
.join-card:hover { background: var(--bg-3); transform: translateY(-2px); }
.join-card b { font-size: 16px; }
.join-card .jc-avatars { display: flex; min-height: 28px; }
.join-card .jc-avatars .avatar { margin-right: -6px; border: 2px solid var(--bg-1); }

.tile {
  position: relative; background: var(--bg-0); border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9;
  display: grid; place-items: center; cursor: pointer; min-width: 0; outline: 3px solid transparent; outline-offset: -3px;
  transition: outline-color .1s;
}
.tile.speaking { outline-color: var(--green); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; position: absolute; inset: 0; background: #000; }
.tile.screen video { object-fit: contain; }
.tile.self.cam video { transform: scaleX(-1); }
.tile { container-type: inline-size; }
.tile .tile-avatar { position: relative; z-index: 0; width: 100%; display: grid; place-items: center; }
.tile .tile-avatar .avatar { width: min(96px, 24cqw) !important; height: min(96px, 24cqw) !important; font-size: min(38px, 9.6cqw) !important; }
.tile.screen .tile-avatar .avatar { width: min(56px, 16cqw) !important; height: min(56px, 16cqw) !important; font-size: min(22px, 6.4cqw) !important; }
.tile .label {
  position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.6); padding: 4px 8px; border-radius: 6px;
  font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; z-index: 2; max-width: calc(100% - 16px);
}
.tile .label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .label svg { width: 15px; height: 15px; color: #f23f42; flex: none; }
.tile .tile-tools { position: absolute; right: 8px; top: 8px; display: none; gap: 4px; z-index: 2; }
.tile:hover .tile-tools { display: flex; }
.tile .tile-tools .icon-btn { background: rgba(0,0,0,.6); color: #fff; }
.tile:fullscreen { border-radius: 0; }
.tile:fullscreen video { object-fit: contain; }

.stage.focus { grid-template-columns: 1fr; grid-template-rows: 1fr auto; align-content: stretch; }
.stage.focus .tile.focused { aspect-ratio: auto; grid-row: 1; min-height: 0; }
.stage.focus .strip { grid-row: 2; display: flex; gap: 10px; justify-content: center; overflow-x: auto; }
.stage.focus .strip .tile { width: 180px; flex: none; }

.controls {
  display: flex; gap: 12px; justify-content: center; padding: 12px 16px 16px; flex: none;
}
.ctl {
  width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--bg-3); color: var(--text);
  display: grid; place-items: center; cursor: pointer; transition: background .15s, transform .1s;
}
.ctl svg { width: 22px; height: 22px; }
.ctl:hover { background: var(--bg-hover); }
.ctl:active { transform: scale(.95); }
.ctl.on { background: #fff; color: #111; }
.ctl.off { background: #4e2a2c; color: #f23f42; }
.ctl.danger { background: var(--red); color: #fff; }
.ctl.danger:hover { background: var(--red-2); }

/* ---------- chat ---------- */
.chat { background: var(--bg-2); border-left: 1px solid var(--bg-0); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head { height: 48px; display: flex; align-items: center; gap: 6px; padding: 0 16px; border-bottom: 1px solid var(--bg-0); font-weight: 700; flex: none; }
.chat-head .hash { color: var(--text-3); font-size: 20px; font-weight: 400; }
.messages { flex: 1; overflow-y: auto; padding: 12px 0; min-height: 0; }
.msg { display: flex; gap: 12px; padding: 2px 16px; }
.msg:hover { background: #2e3035; }
.msg.first { margin-top: 12px; padding-top: 4px; }
.msg .msg-gutter { width: 36px; flex: none; }
.msg .msg-body { min-width: 0; flex: 1; }
.msg .msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg .msg-head b { font-weight: 600; }
.msg .msg-head time { color: var(--text-3); font-size: 11px; }
.msg .msg-text { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.4; color: #dbdee1; }
.empty-chat { color: var(--text-3); text-align: center; padding: 32px 16px; }
.composer { padding: 0 16px 16px; flex: none; }
.composer input { background: var(--bg-3) !important; padding: 12px 14px !important; border-radius: 8px !important; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--bg-2); border-radius: 12px; width: min(720px, 100%); max-height: 92vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 24px; }
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-body { padding: 8px 24px 16px; overflow-y: auto; display: grid; grid-template-columns: 240px 1fr; gap: 24px; }
.modal-foot { display: flex; padding: 16px 24px; background: var(--bg-1); gap: 8px; }
.profile-preview { background: var(--bg-0); border-radius: 10px; overflow: hidden; align-self: start; padding-bottom: 16px; }
.pp-banner { height: 70px; }
.pp-avatar { margin: -40px 0 0 16px; width: max-content; border-radius: 50%; border: 6px solid var(--bg-0); }
.pp-name { font-size: 20px; font-weight: 700; padding: 8px 16px 0; overflow-wrap: anywhere; }
.pp-user { color: var(--text-2); padding: 0 16px; }
.pp-status { color: var(--text); padding: 10px 16px 0; font-size: 13px; overflow-wrap: anywhere; }
.profile-form { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.profile-form .row { display: flex; gap: 8px; }
.profile-form label.btn { text-transform: none; font-size: 14px; color: var(--text); flex-direction: row; letter-spacing: 0; }
.field-label { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-2); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 0; cursor: pointer; outline: 2px solid transparent; outline-offset: 2px; }
.swatch.sel { outline-color: #fff; }
details summary { cursor: pointer; color: var(--text-2); font-weight: 600; margin-bottom: 10px; }
details label { margin-bottom: 10px; }

/* ---------- popover / toasts ---------- */
.popover { position: fixed; z-index: 60; background: #111214; border-radius: 8px; padding: 12px; width: 220px; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
.popover .vp-name { font-weight: 700; margin-bottom: 10px; }
.popover input[type=range] { width: 100%; accent-color: var(--accent); }
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 70; pointer-events: none; }
.toast { background: #111214; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.5); animation: toast-in .2s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- celular / tela estreita ---------- */
@media (max-width: 980px) {
  .app, .app.chat-closed { grid-template-columns: 220px 1fr; }
  .chat { position: fixed; right: 0; top: 0; bottom: 0; width: min(340px, 100%); z-index: 20; box-shadow: -8px 0 24px rgba(0,0,0,.4); }
  .app:not(.chat-open-mobile) .chat { display: none; }
}
@media (max-width: 640px) {
  .app, .app.chat-closed { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 42vh; }
  .online-box { display: none; }
  .stage { padding: 8px; }
  .modal-body { grid-template-columns: 1fr; }
  .ctl { width: 46px; height: 46px; }
}
