:root {
  --bg: #313338;
  --side: #2b2d31;
  --side-alt: #1e1f22;
  --userbar: #232428;
  --ink: #f2f3f5;
  --muted: #949ba4;
  --faint: #6d6f78;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --line: #1f2023;
  --input: #383a40;
  --hover: #35373c;
  --active: #404249;
  --green: #23a55a;
  --red: #f23f43;
  --yellow: #f0b232;
  --vvh: 100dvh;
  color-scheme: dark;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.ico, .icon-btn svg, [data-icon] svg { display: block; }

.gate {
  min-height: var(--vvh);
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background: linear-gradient(#1e1f22, #2b2d31 55%, #111214);
}
.card {
  width: min(460px, 100%);
  background: var(--side);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 24px 22px;
  display: grid;
  gap: 12px;
  text-align: center;
}
.mark {
  width: 60px; height: 60px; margin: 0 auto; border-radius: 20px;
  background: var(--accent); color: white; display: grid; place-items: center;
}
.card h1 { margin: 0; font-size: 32px; }
.card p { margin: 0; color: var(--muted); }
.card label { color: var(--faint); font-size: 11px; font-weight: 800; letter-spacing: .04em; text-align: left; }
.card input, .dialog input {
  width: 100%; border: 0; background: var(--side-alt); border-radius: 8px; padding: 12px; outline: none; text-align: left;
}
.card input:focus, .dialog input:focus { box-shadow: 0 0 0 1px var(--accent); }
.hint {
  display: flex; gap: 8px; align-items: flex-start; text-align: left;
  background: var(--side-alt); border-radius: 8px; padding: 8px 10px; color: var(--accent);
}
.hint p { font-size: 12px; }
.card button, .dialog-actions button, #copy-invite, .stage-bar button, .stage-picks button {
  border: 0; border-radius: 6px; min-height: 40px; font-weight: 700;
}
#enter { background: var(--accent); color: white; }
#enter:hover { background: var(--accent-hover); }
.status { min-height: 1.2em; color: var(--red); }

.room { height: var(--vvh); position: relative; background: var(--bg); }
.chat-col {
  height: var(--vvh);
  min-width: 0;
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr) auto;
  padding-bottom: calc(52px + env(safe-area-inset-bottom));
}
.room.in-call .chat-col { padding-bottom: calc(112px + env(safe-area-inset-bottom)); }
.thread { min-height: 0; display: flex; flex-direction: column; }
.messages { flex: 1; min-height: 0; overflow: auto; padding: 16px 16px 8px; }

.top, .server-head, .drawer-head {
  display: flex; align-items: center; gap: 8px;
  min-height: 52px; padding: 0 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
}
.server-head, .drawer-head { background: var(--side); }
.server-head strong { flex: 1; font-size: 16px; }
.channel-hash { color: var(--muted); display: grid; }
#channel-name { font-size: 16px; white-space: nowrap; }
.vbar { width: 1px; height: 16px; background: var(--line); }
.topic { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topic.bad { color: var(--red); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.conn-dot.live { background: var(--green); }
.pill, #copy-invite {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--side-alt); color: var(--ink); padding: 0 10px; border-radius: 14px; min-height: 28px; border: 0;
}
.pill svg { color: var(--green); }

.icon-btn {
  width: 32px; height: 32px; border: 0; border-radius: 4px; background: transparent; color: var(--muted);
  display: grid; place-items: center; flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn.danger, .icon-btn.on { color: var(--red); }
.icon-btn.live { color: var(--green); }
.icon-btn.tiny { width: 22px; height: 22px; }

.msg { display: grid; grid-template-columns: 40px 1fr; gap: 12px; padding: 2px 8px; margin-top: 16px; }
.msg.grouped { margin-top: 0; }
.msg.system { display: block; text-align: center; color: var(--faint); font-size: 13px; font-style: italic; margin: 8px 0; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: white; font-weight: 700; font-size: 14px;
}
.avatar.lg { width: 72px; height: 72px; font-size: 28px; border: 6px solid var(--side); margin-top: -36px; }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.speaking { box-shadow: 0 0 0 2px var(--side), 0 0 0 4px var(--green); }
.msg.grouped .avatar { visibility: hidden; height: 0; }
.who { font-weight: 600; margin-right: 8px; }
.when { color: var(--faint); font-size: 12px; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; line-height: 1.35; color: var(--ink); }
.file {
  margin-top: 6px; background: var(--side-alt); border-radius: 8px; padding: 12px;
  display: grid; gap: 6px; max-width: 420px; border: 1px solid var(--line);
}
.file strong { color: #00a8fc; }
.file button, .user button.watch {
  justify-self: start; display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 4px; background: var(--input); color: white; min-height: 32px; padding: 0 10px;
}
.progress { color: var(--muted); font-size: 13px; padding: 0 8px 6px; }

.composer { padding: 0 16px 24px; background: var(--bg); }
.composer-row {
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--input); border-radius: 8px; padding: 4px 8px 4px 4px;
}
.plus {
  width: 44px; height: 44px; display: grid; place-items: center; color: var(--muted); position: relative; flex: none;
}
.plus input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.composer textarea {
  flex: 1; resize: none; max-height: 120px; background: transparent; border: 0; padding: 12px 4px; outline: none;
}

.shade { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 4; }
.drawer {
  position: fixed; top: 0; bottom: 0; width: min(300px, 88vw);
  background: var(--side); z-index: 5; display: flex; flex-direction: column;
  padding-bottom: calc(60px + env(safe-area-inset-bottom));
}
.room.in-call .drawer { padding-bottom: calc(120px + env(safe-area-inset-bottom)); }
.drawer.left { left: 0; }
.drawer.right { right: 0; }
.drawer-head strong { flex: 1; color: var(--faint); font-size: 12px; letter-spacing: .04em; }
#channel-list, #user-list { overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 1px; }
.section-label {
  display: flex; align-items: center; gap: 6px;
  color: var(--faint); font-size: 11px; font-weight: 800; letter-spacing: .04em;
  padding: 16px 8px 4px;
}
.section-label span { flex: 1; }
.chan-row { display: flex; align-items: center; border-radius: 4px; min-height: 34px; position: relative; }
.chan-row:hover { background: var(--hover); }
.chan {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  min-height: 34px; padding: 0 8px; border: 0; border-radius: 4px; background: transparent;
  color: var(--muted); text-align: left; font-size: 15px;
}
.chan.active { background: var(--active); color: var(--ink); font-weight: 600; }
.chan.voice-on { background: #2d3c30; color: var(--green); font-weight: 600; }
.chan-x { color: var(--muted); display: none; }
.chan-row:hover .chan-x, .chan-row:focus-within .chan-x { display: grid; }
.voice-member {
  margin-left: 12px; min-height: 30px; display: flex; align-items: center; gap: 8px;
  padding: 0 8px; border-radius: 4px; color: var(--ink); font-size: 13px;
}
.voice-member:hover { background: var(--hover); }
.voice-member .dot {
  width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--faint); flex: none;
}
.voice-member.speaking { color: var(--green); }
.voice-member.speaking .dot { background: var(--green); border-color: var(--green); }
.voice-member .badge, .live-pill {
  display: inline-flex; align-items: center; gap: 3px;
  height: 16px; padding: 0 4px; border-radius: 3px; background: #1e3a29; color: var(--green);
  border: 1px solid var(--green); font-size: 10px; font-weight: 800;
}
.user { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 4px 8px; border-radius: 6px; }
.user:hover { background: var(--hover); }
.avatar-wrap { position: relative; width: 32px; height: 32px; flex: none; }
.avatar-wrap .avatar { width: 32px; height: 32px; }
.avatar-wrap .status {
  position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--green); border: 2px solid var(--side);
}
.user .meta { display: grid; min-width: 0; }
.user .meta small, .muted { color: var(--muted); font-size: 12px; }
.you { color: var(--faint); font-size: 11px; font-weight: 500; margin-left: 4px; }

.voice-panel {
  position: fixed; left: 0; right: 0; bottom: calc(52px + env(safe-area-inset-bottom));
  z-index: 6; background: #1e2229; border-top: 1px solid var(--line); padding: 8px 8px 6px;
}
.voice-row { display: flex; align-items: center; gap: 8px; }
.voice-speaker { color: var(--green); display: grid; }
.voice-meta { flex: 1; min-width: 0; display: grid; }
.voice-meta strong { color: var(--green); font-size: 12px; }
.voice-meta span { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mic-meter { height: 2px; margin-top: 6px; background: var(--line); border-radius: 1px; overflow: hidden; }
#mic-meter { display: block; height: 100%; width: 0; background: var(--green); }
.user-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; height: calc(52px + env(safe-area-inset-bottom));
  padding: 0 8px env(safe-area-inset-bottom); background: var(--userbar); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 2px;
}
.me {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  border: 0; background: transparent; border-radius: 4px; padding: 4px; text-align: left;
}
.me:hover { background: var(--hover); }
.me-text { display: grid; min-width: 0; }
.me-text strong, .me-text small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text strong { font-size: 13px; }
.me-text small { color: var(--muted); font-size: 11px; }
.user-dock .status { border-color: var(--userbar); }

.stage {
  display: flex; flex-direction: column; max-height: 46%; min-height: 180px;
  background: #111214; border-bottom: 1px solid var(--line);
}
.stage.fit { max-height: none; flex: 1; min-height: 0; }
.thread:has(.stage.fit:not([hidden])) .messages { flex: 0 0 88px; }
.stage-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #1e1f22; }
.stage-bar strong { font-size: 13px; white-space: nowrap; }
.stage-picks { display: flex; gap: 6px; flex: 1; min-width: 0; overflow: auto; }
.stage-bar button, .stage-picks button { background: var(--input); color: white; padding: 0 10px; }
.stage-picks button.on { background: var(--green); }
.stage-frame { position: relative; flex: 1; min-height: 120px; background: black; display: grid; }
.stage-frame img, .stage-frame video { width: 100%; height: 100%; object-fit: contain; }
#local-preview { display: none; }
.stage.local #local-preview { display: block; }
.stage.local.has-remote #local-preview {
  position: absolute; width: 28%; height: 30%; right: 8px; bottom: 8px;
  border: 2px solid #2f3136; border-radius: 8px; object-fit: cover; background: black;
}
#viewer-img:not([src]), #viewer-img[src=""] { display: none; }
#viewer-wait { margin: 0; align-self: center; justify-self: center; color: var(--muted); }

.modal { position: fixed; inset: 0; z-index: 8; display: grid; place-items: center; padding: 16px; }
.modal-back { position: absolute; inset: 0; background: rgba(0,0,0,.75); }
.settings-card, .dialog {
  position: relative; z-index: 1; background: var(--side); color: var(--ink);
  border-radius: 8px; width: min(880px, 100%); max-height: min(640px, 100%);
  display: grid; grid-template-columns: 220px 1fr; overflow: hidden;
}
.dialog { width: min(440px, 100%); grid-template-columns: 1fr; padding: 20px; gap: 12px; }
.dialog h2, .settings-main h2 { margin: 0 0 8px; font-size: 20px; }
.settings-nav { background: var(--side-alt); padding: 16px 8px; display: flex; flex-direction: column; gap: 2px; }
.settings-nav p { margin: 12px 8px 4px; color: var(--faint); font-size: 11px; font-weight: 800; letter-spacing: .04em; }
.settings-nav button {
  border: 0; background: transparent; color: var(--muted); text-align: left; border-radius: 4px; min-height: 34px; padding: 0 10px;
}
.settings-nav button.on, .settings-nav button:hover { background: var(--hover); color: var(--ink); }
.leave { margin-top: auto; color: var(--red) !important; }
.settings-main { position: relative; padding: 48px 28px 24px; overflow: auto; background: var(--side); }
.esc {
  position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border-radius: 50%;
  border: 2px solid var(--muted); background: transparent; color: var(--muted); font-size: 10px; font-weight: 800;
}
.banner { height: 100px; border-radius: 8px; background: var(--accent); padding: 0 16px; }
.profile-nick { font-size: 20px; font-weight: 700; margin: 8px 0; }
.tune { display: grid; gap: 12px; margin: 12px 0; }
.tune label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 700; }
.tune input { width: 100%; accent-color: var(--accent); }
.invite-row { display: flex; gap: 8px; align-items: center; background: var(--side-alt); border-radius: 8px; padding: 8px; }
.invite-row code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#copy-invite { background: var(--accent); color: white; }
.kinds { display: flex; gap: 8px; }
.kind { flex: 1; border: 0; border-radius: 6px; min-height: 40px; background: var(--side-alt); color: var(--muted); font-weight: 700; }
.kind.on { background: var(--accent); color: white; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions button { padding: 0 14px; background: var(--input); color: white; }
.dialog-actions .danger, #delete-confirm { background: var(--red); }
.dialog label { color: var(--faint); font-size: 11px; font-weight: 800; letter-spacing: .04em; }

.mobile-only { display: grid; }
@media (hover: none) {
  .chan-x { display: grid; }
}
@media (max-width: 720px) {
  .settings-card { grid-template-columns: 1fr; overflow: auto; }
  .settings-nav { flex-direction: row; flex-wrap: wrap; }
  .leave { margin-top: 0; }
  .vbar, .topic, .pill { display: none; }
}
@media (min-width: 900px) {
  .room {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr) 240px;
    grid-template-rows: minmax(0, 1fr) auto 52px;
  }
  .chat-col { grid-column: 2; grid-row: 1 / span 3; height: 100%; padding-bottom: 0; }
  #channels { grid-column: 1; grid-row: 1; }
  #voice-panel { grid-column: 1; grid-row: 2; }
  #user-dock { grid-column: 1; grid-row: 3; }
  #users { grid-column: 3; grid-row: 1 / span 3; }
  .mobile-only, .shade, #open-users { display: none !important; }
  #room:not([hidden]) .drawer {
    position: static; width: auto; height: 100%; display: flex !important; padding-bottom: 0;
  }
  .voice-panel, .user-dock { position: static; height: auto; width: auto; z-index: auto; right: auto; left: auto; bottom: auto; }
  .user-dock { height: 52px; }
  .top { background: var(--bg); }
}
