:root {
  --bg-0: #0d0e12;
  --bg-1: #14161b;
  --bg-2: #1b1d23;
  --bg-3: #23262e;
  --bg-4: #2c3039;
  --bg-hover: rgba(255, 255, 255, 0.05);
  --bg-active: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.07);
  --text: #e7e9ee;
  --text-2: #b5bac4;
  --muted: #868c99;
  --accent: #7c5cff;
  --accent-hover: #6a4af0;
  --accent-soft: rgba(124, 92, 255, 0.16);
  --ok: #3fcf8e;
  --speak: #3fcf8e;
  --warn: #f0b232;
  --danger: #ef4b5b;
  --danger-hover: #d63b4b;
  --mention: rgba(240, 178, 50, 0.1);
  --radius: 8px;
  --rail-w: 72px;
  --side-w: 248px;
  --members-w: 240px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', Ubuntu, sans-serif;
  --mono: ui-monospace, 'SFMono-Regular', 'JetBrains Mono', Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg-2);
  color: var(--text);
  font: 15px/1.4 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
#root { height: 100dvh; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: #7fb3ff; text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
[hidden] { display: none !important; }
.icon { flex-shrink: 0; display: block; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
* { scrollbar-width: thin; scrollbar-color: var(--bg-4) transparent; }

/* ---------- splash & auth ---------- */
.splash { height: 100%; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); font-weight: 700; letter-spacing: 0.2em; }
.splash img { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(0.92); opacity: 0.7; } }

.auth {
  min-height: 100%; display: grid; place-items: center; padding: 24px 16px; overflow: auto; height: 100%;
  background: radial-gradient(1000px 600px at 10% -10%, rgba(124, 92, 255, 0.25), transparent 60%),
              radial-gradient(800px 500px at 110% 110%, rgba(94, 230, 193, 0.12), transparent 60%), var(--bg-1);
}
.auth-card { width: 100%; max-width: 420px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4); }
.auth-logo { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 8px; font-size: 22px; font-weight: 800; letter-spacing: 0.06em; }
.auth-sub { text-align: center; color: var(--muted); margin: 0 0 22px; }
.auth-invite { display: flex; gap: 12px; align-items: center; background: var(--accent-soft); border-radius: 10px; padding: 12px; margin-bottom: 18px; }
.auth-tabs { display: flex; gap: 6px; background: var(--bg-1); padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.auth-tabs button { flex: 1; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.auth-tabs button.active { background: var(--bg-3); color: var(--text); }
.pending-spinner { width: 44px; height: 44px; margin: 18px auto 6px; border-radius: 50%; border: 4px solid var(--bg-4); border-top-color: var(--text); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.auth-foot { margin-top: 18px; color: var(--muted); font-size: 12px; text-align: center; display: flex; gap: 6px; justify-content: center; align-items: center; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-2); margin-bottom: 6px; }
.input, .select, textarea.input {
  width: 100%; background: var(--bg-0); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; outline: none; transition: border-color 0.15s;
}
.input:focus, .select:focus { border-color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.error-text { color: var(--danger); font-size: 14px; min-height: 1em; margin: 4px 0 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius); font-weight: 600; background: var(--accent); color: #fff;
  transition: background 0.15s, opacity 0.15s; white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--bg-4); color: var(--text); }
.btn.secondary:hover { background: #363a45; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: var(--danger-hover); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.ok { background: var(--ok); color: #06281a; }

.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 6px; color: var(--text-2); position: relative; }
.icon-btn > .badge { position: absolute; top: -4px; right: -4px; border: 2px solid var(--bg-0); box-sizing: content-box; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.active { color: var(--text); background: var(--bg-active); }
.icon-btn.off { color: var(--danger); }

/* ---------- avatars ---------- */
.avatar { border-radius: 50%; object-fit: cover; display: inline-grid; place-items: center; color: #fff; font-weight: 700; flex-shrink: 0; user-select: none; background: var(--bg-4); }
.avatar-wrap { position: relative; display: inline-block; flex-shrink: 0; line-height: 0; }
.status-dot { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%; border: 3px solid var(--bg-1); background: #6b7180; box-sizing: content-box; }
.status-dot.online { background: var(--ok); }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: var(--rail-w) var(--side-w) minmax(0, 1fr) auto; height: 100%; }
.rail { background: var(--bg-0); padding: 12px 0; display: flex; flex-direction: column; align-items: center; gap: 8px; overflow-y: auto; scrollbar-width: none; }
.rail::-webkit-scrollbar { display: none; }
.rail-sep { width: 32px; height: 2px; background: var(--bg-3); border-radius: 2px; margin: 2px 0; flex-shrink: 0; }
.rail-item { position: relative; width: 48px; height: 48px; flex-shrink: 0; }
.rail-btn {
  width: 48px; height: 48px; border-radius: 50%; background: var(--bg-2); color: var(--text); display: grid; place-items: center;
  font-weight: 700; font-size: 16px; overflow: hidden; transition: border-radius 0.15s, background 0.15s;
}
.rail-btn img { width: 100%; height: 100%; object-fit: cover; }
.rail-item:hover .rail-btn, .rail-item.active .rail-btn { border-radius: 16px; background: var(--accent); color: #fff; }
.rail-item.rail-home:hover .rail-btn, .rail-item.rail-home.active .rail-btn { background: #fff; }
.rail-item.add .rail-btn { color: var(--ok); }
.rail-item.add:hover .rail-btn { background: var(--ok); color: #06281a; }
.rail-pill { position: absolute; left: -12px; top: 50%; width: 8px; height: 0; background: #fff; border-radius: 0 4px 4px 0; transform: translateY(-50%); transition: height 0.15s; }
.rail-item.unread .rail-pill { height: 8px; }
.rail-item:hover .rail-pill { height: 20px; }
.rail-item.active .rail-pill { height: 40px; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 800; display: inline-grid; place-items: center; }
.rail-item .badge { position: absolute; right: -4px; bottom: -4px; border: 3px solid var(--bg-0); height: 24px; min-width: 24px; border-radius: 12px; box-sizing: border-box; }

.sidebar { background: var(--bg-1); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.side-head { height: 52px; flex-shrink: 0; display: flex; align-items: center; padding: 0 12px 0 16px; font-weight: 700; border-bottom: 1px solid var(--border); gap: 6px; }
button.side-head { width: 100%; text-align: left; }
button.side-head:hover { background: var(--bg-hover); }
.side-head .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-list { flex: 1; overflow-y: auto; padding: 8px 8px 16px; }
.side-cat { display: flex; align-items: center; justify-content: space-between; padding: 16px 6px 4px 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.side-cat .icon-btn { width: 20px; height: 20px; }

.chan { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; color: var(--muted); cursor: pointer; position: relative; min-height: 34px; }
.chan:hover { background: var(--bg-hover); color: var(--text-2); }
.chan.active { background: var(--bg-active); color: var(--text); }
.chan.unread { color: var(--text); font-weight: 600; }
.chan.unread::before { content: ''; position: absolute; left: -8px; width: 4px; height: 8px; background: #fff; border-radius: 0 4px 4px 0; }
.chan .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan .chan-tools { display: none; }
.chan:hover .chan-tools { display: flex; }
.chan .chan-tools .icon-btn { width: 22px; height: 22px; }
.chan-sub { font-size: 12px; color: var(--muted); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.voice-users { padding: 2px 0 6px 30px; }
.voice-user { display: flex; align-items: center; gap: 8px; padding: 3px 6px; border-radius: 6px; color: var(--text-2); font-size: 14px; }
.voice-user:hover { background: var(--bg-hover); }
.voice-user .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-user .flags { display: flex; gap: 3px; color: var(--muted); }
.voice-user .flags .off { color: var(--danger); }
.live-tag { background: var(--danger); color: #fff; font-size: 10px; font-weight: 800; padding: 1px 5px; border-radius: 4px; letter-spacing: 0.04em; }
.avatar.speaking, .speaking > .avatar { box-shadow: 0 0 0 2px var(--bg-1), 0 0 0 4px var(--speak); }

.voice-panel { border-top: 1px solid var(--border); padding: 10px 10px 8px; background: var(--bg-1); }
.voice-panel .status { color: var(--ok); font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.voice-panel .status.connecting { color: var(--warn); }
.voice-panel .where { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.voice-panel .where:hover { text-decoration: underline; }
.voice-panel .controls { display: flex; gap: 6px; margin-top: 8px; }
.voice-panel .controls .icon-btn { flex: 1; height: 34px; background: var(--bg-3); }
.voice-panel .controls .icon-btn.active { background: var(--accent); color: #fff; }
.voice-panel .controls .icon-btn.hang { color: #fff; background: var(--danger); }

.user-panel { height: 56px; flex-shrink: 0; background: var(--bg-0); display: flex; align-items: center; gap: 4px; padding: 0 8px; }
.user-panel .me { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; padding: 4px; border-radius: 6px; cursor: pointer; }
.user-panel .me:hover { background: var(--bg-hover); }
.user-panel .who { min-width: 0; line-height: 1.2; }
.user-panel .who div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 600; }
.user-panel .who small { color: var(--muted); font-size: 12px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-panel .status-dot { border-color: var(--bg-0); }

.content { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-2); }
.content-head { height: 52px; flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 0 8px 0 16px; border-bottom: 1px solid var(--border); }
.content-head .title { font-weight: 700; display: flex; align-items: center; gap: 6px; min-width: 0; white-space: nowrap; }
.content-head .topic { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-left: 1px solid var(--border); padding-left: 12px; margin-left: 4px; min-width: 0; flex: 1; }
.content-head .spacer { flex: 1; }
.content-head .nav-toggle { display: none; }
.content-body { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.update-bar { background: var(--accent); color: #fff; font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 12px; padding: 5px 12px; flex-wrap: wrap; }
.update-bar .btn { background: #fff; color: #222; }
.offline-bar { background: var(--warn); color: #241a00; font-weight: 600; font-size: 13px; text-align: center; padding: 4px; }

.members { width: var(--members-w); background: var(--bg-1); overflow-y: auto; padding: 8px 8px 16px; }
.members .side-cat { padding-top: 14px; }
.member { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--text-2); }
.member:hover { background: var(--bg-hover); color: var(--text); }
.member.offline { opacity: 0.45; }
.member .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-icon { color: var(--warn); }
.role-icon.admin { color: #7fb3ff; }

/* ---------- home ---------- */
.home { flex: 1; overflow-y: auto; padding: 24px; }
.home h2 { margin: 0 0 6px; }
.home .sub { color: var(--muted); margin: 0 0 20px; }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.person { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--bg-1); border-radius: 10px; border: 1px solid var(--border); }
.person .grow div { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .grow small { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- chat ---------- */
.messages { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0 0 12px; overscroll-behavior: contain; }
.chan-intro { padding: 32px 16px 12px; }
.chan-intro .big-icon { width: 64px; height: 64px; border-radius: 50%; background: var(--bg-4); display: grid; place-items: center; margin-bottom: 10px; }
.chan-intro h1 { margin: 0 0 4px; font-size: 26px; }
.chan-intro p { margin: 0; color: var(--muted); }
.load-more { text-align: center; color: var(--muted); padding: 12px; font-size: 13px; }
.day-sep { display: flex; align-items: center; gap: 8px; margin: 16px 16px 4px; color: var(--muted); font-size: 12px; font-weight: 600; }
.day-sep::before, .day-sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.msg { position: relative; padding: 2px 48px 2px 72px; min-height: 22px; }
.msg.head { margin-top: 14px; padding-top: 4px; }
.msg:hover { background: rgba(0, 0, 0, 0.12); }
.msg.mentioned { background: var(--mention); box-shadow: inset 2px 0 0 var(--warn); }
.msg.highlight { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } }
.msg > .avatar, .msg > .avatar-wrap { position: absolute; left: 16px; top: 6px; cursor: pointer; }
.msg.has-reply > .avatar { top: 28px; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-author { font-weight: 600; cursor: pointer; }
.msg-author:hover { text-decoration: underline; }
.msg-time { color: var(--muted); font-size: 12px; }
.msg .side-time { position: absolute; left: 0; width: 64px; text-align: right; color: var(--muted); font-size: 11px; top: 5px; opacity: 0; }
.msg:hover .side-time { opacity: 1; }
.msg-body { color: var(--text); word-wrap: break-word; overflow-wrap: anywhere; white-space: normal; }
.msg-body.jumbo { font-size: 44px; line-height: 1.2; }
.msg-body .edited { color: var(--muted); font-size: 11px; margin-left: 4px; }
.msg-body code { font-family: var(--mono); background: var(--bg-0); padding: 1px 4px; border-radius: 4px; font-size: 0.9em; }
.msg-body pre { background: var(--bg-0); border: 1px solid var(--border); border-radius: 6px; padding: 10px; margin: 6px 0; overflow-x: auto; max-width: 100%; }
.msg-body pre code { background: none; padding: 0; white-space: pre; }
.msg-body .quote { border-left: 4px solid var(--bg-4); padding: 0 0 0 10px; margin: 2px 0; color: var(--text-2); }
.mention { background: var(--accent-soft); color: #c6b8ff; border-radius: 4px; padding: 0 2px; font-weight: 500; }
.mention.mention-me { background: rgba(240, 178, 50, 0.22); color: #ffd98a; }
.spoiler { background: #0b0c0f; color: transparent; border-radius: 4px; cursor: pointer; transition: color 0.1s; }
.spoiler.shown { color: inherit; background: var(--bg-4); }
.msg-reply { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin: 0 0 2px -2px; cursor: pointer; min-width: 0; }
.msg-reply::before { content: ''; position: absolute; left: 34px; top: 12px; width: 30px; height: 10px; border-left: 2px solid var(--bg-4); border-top: 2px solid var(--bg-4); border-top-left-radius: 6px; }
.msg-reply b { color: var(--text-2); white-space: nowrap; }
.msg-reply span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-reply:hover span { color: var(--text); }

.msg-tools { position: absolute; right: 12px; top: -14px; display: none; background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); z-index: 2; }
.msg:hover .msg-tools, .msg.tools-open .msg-tools { display: flex; }
.msg-tools .icon-btn { width: 32px; height: 30px; border-radius: 0; }
.msg-tools .icon-btn.danger:hover { color: var(--danger); }

.attachments { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; align-items: flex-start; }
.att-img { max-width: min(420px, 100%); max-height: 320px; border-radius: 8px; cursor: zoom-in; display: block; background: var(--bg-3); min-width: 40px; min-height: 40px; object-fit: contain; }
.att-video { max-width: min(480px, 100%); max-height: 360px; border-radius: 8px; background: #000; }
.att-audio { width: min(420px, 100%); }
.att-file { display: flex; align-items: center; gap: 10px; background: var(--bg-1); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; max-width: min(420px, 100%); }
.att-file .grow a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file small { color: var(--muted); }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 8px; background: var(--bg-3); border: 1px solid transparent; font-size: 14px; }
.reaction:hover { border-color: var(--bg-4); }
.reaction.mine { background: var(--accent-soft); border-color: var(--accent); }
.reaction .n { font-size: 13px; font-weight: 600; color: var(--text-2); }

.edit-box textarea { width: 100%; resize: none; background: var(--bg-3); border: 0; border-radius: 8px; padding: 8px 10px; outline: none; max-height: 300px; }
.edit-box .hint { font-size: 12px; }

.typing { height: 22px; padding: 0 16px; font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; flex-shrink: 0; overflow: hidden; white-space: nowrap; }
.typing .dots { display: inline-flex; gap: 3px; }
.typing .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--text-2); animation: blink 1.2s infinite; }
.typing .dots i:nth-child(2) { animation-delay: 0.2s; }
.typing .dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.3; } 30% { opacity: 1; } }

.composer { padding: 0 16px 4px; flex-shrink: 0; }
.composer-box { background: var(--bg-3); border-radius: 10px; }
.composer-row { display: flex; align-items: flex-end; gap: 4px; padding: 0 6px; }
.composer-row .icon-btn { width: 40px; height: 44px; }
.composer textarea { flex: 1; min-width: 0; resize: none; border: 0; outline: none; background: transparent; padding: 12px 4px; max-height: 40vh; line-height: 1.4; }
.composer-reply { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 13px; color: var(--text-2); background: var(--bg-1); border-radius: 10px 10px 0 0; }
.composer-reply .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads { display: flex; gap: 8px; padding: 10px 10px 0; overflow-x: auto; }
.upload-chip { position: relative; width: 120px; flex-shrink: 0; background: var(--bg-1); border-radius: 8px; padding: 8px; font-size: 12px; }
.upload-chip img { width: 100%; height: 72px; object-fit: cover; border-radius: 6px; display: block; }
.upload-chip .file-ph { height: 72px; display: grid; place-items: center; color: var(--muted); }
.upload-chip .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 4px; }
.upload-chip .bar { height: 3px; background: var(--bg-4); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.upload-chip .bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width 0.1s; }
.upload-chip.done .bar i { background: var(--ok); }
.upload-chip.failed .bar i { background: var(--danger); width: 100% !important; }
.upload-chip .rm { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; background: var(--danger); color: #fff; display: grid; place-items: center; }
.drop-overlay { position: absolute; inset: 0; background: rgba(124, 92, 255, 0.25); border: 3px dashed var(--accent); border-radius: 12px; display: grid; place-items: center; font-size: 20px; font-weight: 700; z-index: 5; pointer-events: none; margin: 8px; }

/* ---------- voice view ---------- */
.voice-view { flex: 1; min-height: 0; display: flex; flex-direction: column; background: #0b0c10; }
.voice-grid { flex: 1; min-height: 0; padding: 16px; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); grid-auto-rows: minmax(160px, 1fr); overflow-y: auto; align-content: center; }
.tile { position: relative; background: var(--bg-2); border-radius: 12px; overflow: hidden; display: grid; place-items: center; min-height: 160px; border: 2px solid transparent; transition: border-color 0.1s; }
.tile.speaking { border-color: var(--speak); }
.tile video { width: 100%; height: 100%; object-fit: contain; background: #000; position: absolute; inset: 0; }
.tile.mirror video { transform: scaleX(-1); }
.tile .tile-name { position: absolute; left: 8px; bottom: 8px; background: rgba(0, 0, 0, 0.6); padding: 3px 8px; border-radius: 6px; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; max-width: calc(100% - 16px); }
.tile .tile-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .tile-tools { position: absolute; right: 8px; top: 8px; display: none; gap: 4px; }
.tile:hover .tile-tools { display: flex; }
.tile .tile-tools .icon-btn { background: rgba(0, 0, 0, 0.6); color: #fff; }
.tile .conn { position: absolute; left: 8px; top: 8px; font-size: 12px; color: var(--warn); background: rgba(0, 0, 0, 0.6); padding: 2px 6px; border-radius: 6px; }
.tile .conn.failed { color: var(--danger); }
.tile.stream { background: #0e0f13; border: 1px solid var(--border); }
.tile.stream.live { grid-column: span 2; }
.tile.stream .stream-card { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--text-2); text-align: center; padding: 16px; }
.tile.stream .stream-card b { color: var(--text); }
.tile .stream-live { position: absolute; right: 8px; top: 8px; }
.tile.stream:hover .stream-live { display: none; }
.tile .tile-tools .btn.small { padding: 5px 10px; background: rgba(0, 0, 0, 0.65); color: #fff; }
button.live-tag { border: 0; cursor: pointer; }
.tile .secure { position: absolute; left: 8px; top: 8px; font-size: 12px; color: var(--ok); background: rgba(0, 0, 0, 0.6); padding: 3px 7px; border-radius: 6px; display: flex; gap: 4px; align-items: center; z-index: 1; }
.tile .secure:hover { background: rgba(0, 0, 0, 0.85); }
.code-pop { padding: 16px; width: 300px; }
.code-pop .code-emoji { white-space: nowrap; font-size: 26px; text-align: center; margin: 12px 0 6px; letter-spacing: 2px; word-spacing: 4px; }
.code-pop .hint { margin: 0; }
.voice-panel .status.failed { color: var(--danger); }
.voice-bar { display: flex; justify-content: center; gap: 12px; padding: 14px; flex-wrap: wrap; }
.round-btn { width: 52px; height: 52px; border-radius: 50%; background: var(--bg-3); color: var(--text); display: grid; place-items: center; }
.round-btn:hover { background: var(--bg-4); }
.round-btn.active { background: var(--accent); color: #fff; }
.round-btn.off { background: #3a2026; color: var(--danger); }
.round-btn.hang { background: var(--danger); color: #fff; }
.round-btn.hang:hover { background: var(--danger-hover); }
.round-btn.join { width: auto; border-radius: 26px; padding: 0 24px; background: var(--ok); color: #06281a; font-weight: 700; gap: 8px; display: inline-flex; align-items: center; }
.voice-join { flex: 1; display: grid; place-content: center; justify-items: center; gap: 14px; text-align: center; padding: 16px; }
.voice-join .who { display: flex; gap: -8px; }
.call-panel { background: #0b0c10; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; max-height: 55%; }
.call-panel .voice-grid { grid-auto-rows: minmax(120px, 1fr); padding: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.call-panel .tile { min-height: 120px; }
.call-panel .voice-bar { padding: 8px; }
.call-panel .round-btn { width: 44px; height: 44px; }

/* ---------- popovers, menus, modals ---------- */
.layer { position: fixed; inset: 0; z-index: 50; }
.popover { position: fixed; z-index: 60; background: var(--bg-1); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); min-width: 200px; max-width: calc(100vw - 16px); }
.menu { padding: 6px; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 6px; color: var(--text-2); text-align: left; font-size: 14px; }
.menu button:hover { background: var(--accent); color: #fff; }
.menu button.danger { color: var(--danger); }
.menu button.danger:hover { background: var(--danger); color: #fff; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 2px; }
.profile { width: 300px; overflow: hidden; }
.profile .banner { height: 64px; }
.profile .body { padding: 0 16px 16px; }
.profile .avatar-wrap { margin-top: -36px; border: 6px solid var(--bg-1); border-radius: 50%; }
.profile h3 { margin: 6px 0 0; }
.profile .uname { color: var(--muted); font-size: 14px; }
.profile .role-line { display: flex; align-items: center; gap: 6px; margin: 10px 0; font-size: 13px; color: var(--text-2); }
.profile .actions { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.profile .vol { margin-top: 10px; font-size: 13px; color: var(--text-2); }
.profile .vol input { width: 100%; accent-color: var(--accent); }
.emoji-picker { display: grid; grid-template-columns: repeat(8, 36px); gap: 2px; padding: 8px; min-width: 0; }
.emoji-picker button { width: 36px; height: 36px; font-size: 22px; border-radius: 6px; }
.emoji-picker button:hover { background: var(--bg-3); }

.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7); z-index: 70; display: grid; place-items: center; padding: 16px; animation: fade 0.12s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--bg-2); border-radius: 14px; width: 100%; max-width: 460px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); animation: pop 0.15s; }
.modal.wide { max-width: 760px; }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } }
.modal-head { padding: 20px 20px 8px; display: flex; align-items: flex-start; gap: 12px; }
.modal-head h2 { margin: 0; font-size: 20px; flex: 1; }
.modal-body { padding: 8px 20px 16px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; background: var(--bg-1); border-radius: 0 0 14px 14px; display: flex; justify-content: flex-end; gap: 8px; }
.choice { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 10px; background: var(--bg-1); border: 1px solid var(--border); width: 100%; text-align: left; margin-bottom: 8px; }
.choice:hover { background: var(--bg-3); }
.choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.choice .grow small { display: block; color: var(--muted); }
.copy-row { display: flex; gap: 8px; background: var(--bg-0); border-radius: 8px; padding: 4px 4px 4px 12px; align-items: center; }
.copy-row input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; padding: 8px 0; }

.settings { display: grid; grid-template-columns: 190px 1fr; min-height: 420px; }
.settings-nav { background: var(--bg-1); padding: 12px 8px; border-radius: 14px 0 0 14px; display: flex; flex-direction: column; gap: 2px; }
.settings-nav button { text-align: left; padding: 8px 10px; border-radius: 6px; color: var(--text-2); display: flex; gap: 8px; align-items: center; }
.settings-nav button:hover { background: var(--bg-hover); color: var(--text); }
.settings-nav button.active { background: var(--bg-active); color: var(--text); }
.settings-nav button.danger { color: var(--danger); }
.settings-nav .sep { height: 1px; background: var(--border); margin: 6px 4px; }
.settings-main { padding: 20px 24px; overflow-y: auto; max-height: calc(100dvh - 32px); position: relative; }
.settings-main h3 { margin: 0 0 16px; }
.settings-close { position: absolute; top: 12px; right: 12px; }
.avatar-edit { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 8px; background: var(--bg-1); margin-bottom: 6px; }
.list-row .grow small { color: var(--muted); display: block; }
.mono { font-family: var(--mono); }
.danger-zone { border: 1px solid rgba(239, 75, 91, 0.4); border-radius: 10px; padding: 14px; margin-top: 24px; }
.danger-zone h4 { margin: 0 0 6px; color: var(--danger); }
.danger-zone p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }

.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.88); z-index: 80; display: grid; place-items: center; padding: 24px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: calc(100dvh - 80px); border-radius: 6px; }
.lightbox .open { position: absolute; bottom: 16px; color: var(--text-2); font-size: 14px; }

.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--bg-4); color: var(--text); padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); font-size: 14px; transition: opacity 0.3s, transform 0.3s; pointer-events: auto; }
.toast-error { background: #5a1d26; }
.toast-warn { background: #57431a; }
.toast-ok { background: #17452f; }
.toast.hide { opacity: 0; transform: translateY(-8px); }

.incoming-call { position: fixed; top: 16px; right: 16px; z-index: 90; background: var(--bg-1); border: 1px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); display: flex; flex-direction: column; align-items: center; gap: 10px; width: 240px; animation: pop 0.2s; }
.incoming-call .who { font-weight: 700; }
.incoming-call small { color: var(--muted); }
.incoming-call .avatar { animation: ring 1.2s infinite; }
@keyframes ring { 0%, 100% { box-shadow: 0 0 0 0 rgba(63, 207, 142, 0.6); } 70% { box-shadow: 0 0 0 14px rgba(63, 207, 142, 0); } }

.backdrop { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .members { display: none; }
  .app.show-members .members { display: block; position: fixed; right: 0; top: 0; bottom: 0; z-index: 40; box-shadow: -8px 0 30px rgba(0, 0, 0, 0.5); }
  .app.show-members .backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, 0.5); }
}

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail, .sidebar { position: fixed; top: 0; bottom: 0; z-index: 40; transform: translateX(calc(-100% - var(--rail-w) - 24px)); transition: transform 0.2s ease; visibility: hidden; }
  .app.show-nav .rail, .app.show-nav .sidebar { visibility: visible; }
  .rail { left: 0; width: var(--rail-w); }
  .sidebar { left: var(--rail-w); width: min(var(--side-w), calc(100vw - var(--rail-w) - 24px)); }
  .app.show-nav .rail, .app.show-nav .sidebar { transform: none; }
  .app.show-nav .backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, 0.5); }
  .content-head { padding-left: 4px; }
  .content-head .nav-toggle { display: inline-grid; }
  .content-head .topic { display: none; }
  .msg { padding-left: 60px; padding-right: 12px; }
  .msg > .avatar, .msg > .avatar-wrap { left: 10px; }
  .msg .side-time { width: 54px; }
  .msg-tools { right: 6px; }
  .composer { padding: 0 8px 4px; padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .settings { grid-template-columns: 1fr; }
  .settings-nav { border-radius: 14px 14px 0 0; flex-direction: row; overflow-x: auto; }
  .settings-nav .sep { display: none; }
  .settings-nav button { white-space: nowrap; }
  .settings-main { max-height: none; }
  .modal.wide { max-height: calc(100dvh - 16px); overflow: auto; }
  .voice-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); padding: 10px; }
  .tile.stream.live { grid-column: 1 / -1; }
  .home { padding: 16px; }
  .incoming-call { left: 16px; right: 16px; width: auto; }
}

@media (hover: none) and (pointer: coarse) {
  .tile .tile-tools { display: flex; }
  .tile .stream-live { display: none; }
  .msg-tools { display: none !important; }
  .msg.tools-open .msg-tools { display: flex !important; }
  .chan .chan-tools { display: flex; }
}
