:root {
  --bg-0: #0c0d10;
  --bg-1: #14161b;
  --bg-2: #1b1e25;
  --bg-3: #23272f;
  --bg-4: #2c313b;
  --line: #2a2f39;
  --text: #e8eaf0;
  --text-2: #b4bac7;
  --muted: #7f8798;
  --accent: #ff7a1a;
  --accent-2: #ff9447;
  --accent-soft: rgba(255, 122, 26, 0.14);
  --accent-glow: rgba(255, 122, 26, 0.35);
  --danger: #ef5350;
  --success: #3fbf6f;
  --warning: #f5b642;
  --radius: 8px;
  --rail-w: 72px;
  --side-w: 248px;
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.4;
  background: var(--bg-2); color: var(--text); overflow: hidden;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--accent-2); }
[hidden] { display: none !important; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::selection { background: var(--accent-soft); }

/* ---------- generic ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius); font-weight: 600; font-size: 14px;
  background: var(--bg-4); color: var(--text); transition: background .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #363c48; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: #1a0d02; }
.btn-primary:hover { background: var(--accent-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #ff6b68; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--bg-3); color: var(--text); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-link { background: none; color: var(--accent-2); padding: 0; font-weight: 500; }
.btn-link:hover { text-decoration: underline; background: none; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.input, textarea.input, select.input {
  width: 100%; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--bg-0); color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 70px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab { padding: 8px 12px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-2); border-bottom-color: var(--accent); }
.tab.tab-cta { margin-left: auto; color: var(--accent-2); }
.tab.tab-cta.active { color: #1a0d02; background: var(--accent); border-radius: 6px 6px 0 0; border-bottom-color: var(--accent); }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; }
.pill { display: inline-block; padding: 2px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.pill-owner { background: var(--accent-soft); color: var(--accent-2); }
.pill-admin { background: rgba(63, 191, 111, .15); color: var(--success); }
.divider { height: 1px; background: var(--line); margin: 12px 0; }
.icon { width: 20px; height: 20px; fill: currentColor; flex-shrink: 0; }
.icon-sm { width: 16px; height: 16px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { color: var(--text); background: var(--bg-3); }
.icon-btn.active { color: var(--accent-2); }
.icon-btn.danger:hover { color: var(--danger); }

/* ---------- avatar ---------- */
.avatar {
  position: relative; width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; color: #fff;
  background: var(--bg-4); overflow: visible; user-select: none;
}
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar.lg { width: 40px; height: 40px; font-size: 16px; }
.avatar.xl { width: 80px; height: 80px; font-size: 30px; }
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }
.avatar .dot {
  position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--muted); border: 3px solid var(--bg-1);
}
.avatar .dot.on { background: var(--success); }
.avatar.speaking { box-shadow: 0 0 0 2px var(--success); }

/* ---------- auth ---------- */
#auth {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(255, 122, 26, .18), transparent 60%),
              radial-gradient(900px 500px at 110% 110%, rgba(255, 122, 26, .12), transparent 60%), var(--bg-0);
}
.auth-card { width: 420px; max-width: calc(100vw - 32px); background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 32px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.auth-logo .ghost { width: 44px; height: 44px; filter: drop-shadow(0 0 14px var(--accent-glow)); }
.auth-logo h1 { margin: 0; font-size: 24px; letter-spacing: -.01em; }
.auth-logo h1 span { color: var(--accent); }
.auth-card p.tagline { color: var(--muted); margin: 0 0 22px; }
.auth-card .btn { width: 100%; margin-top: 4px; }
.auth-switch { margin-top: 16px; font-size: 13px; color: var(--muted); }
.auth-lang { position: fixed; top: 16px; right: 16px; }

/* ---------- app layout ---------- */
#app { display: flex; height: 100vh; }
#rail { width: var(--rail-w); background: var(--bg-0); display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 8px; overflow-y: auto; overflow-x: hidden; flex-shrink: 0; }
#rail::-webkit-scrollbar { width: 0; }
.rail-item { position: relative; width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; }
.rail-btn {
  width: 48px; height: 48px; border-radius: 24px; display: flex; align-items: center; justify-content: center;
  background: var(--bg-2); color: var(--text-2); font-weight: 700; font-size: 16px; transition: border-radius .18s, background .18s, color .18s; overflow: hidden;
}
.rail-btn img { width: 100%; height: 100%; object-fit: cover; }
.rail-btn:hover, .rail-item.active .rail-btn { border-radius: 16px; background: var(--accent); color: #1a0d02; }
.rail-btn.home { background: var(--bg-2); }
.rail-btn.home .ghost { width: 28px; height: 28px; }
.rail-btn.add { color: var(--success); }
.rail-btn.add:hover { background: var(--success); color: #fff; }
.rail-item::before {
  content: ''; position: absolute; left: -12px; top: 50%; transform: translateY(-50%); width: 4px; height: 0; border-radius: 0 4px 4px 0;
  background: var(--text); transition: height .18s;
}
.rail-item:hover::before { height: 20px; }
.rail-item.active::before { height: 36px; background: var(--accent); }
.rail-item.unread::before { height: 8px; }
.rail-item .badge { position: absolute; right: -4px; bottom: -4px; border: 3px solid var(--bg-0); }
.rail-sep { width: 32px; height: 2px; background: var(--bg-3); border-radius: 1px; margin: 2px 0; }
.rail-item .tip { position: absolute; left: 62px; top: 50%; transform: translateY(-50%); background: var(--bg-0); border: 1px solid var(--line); color: var(--text); padding: 6px 10px; border-radius: 6px; font-size: 13px; font-weight: 600; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .1s; z-index: 30; }
.rail-item:hover .tip { opacity: 1; }

#sidebar { width: var(--side-w); background: var(--bg-1); display: flex; flex-direction: column; flex-shrink: 0; }
.side-header { height: 48px; display: flex; align-items: center; padding: 0 12px 0 16px; border-bottom: 1px solid var(--bg-0); font-weight: 700; box-shadow: 0 1px 0 rgba(0, 0, 0, .3); cursor: pointer; }
.side-header:hover { background: var(--bg-2); }
.side-header .name { flex: 1; }
.side-body { flex: 1; overflow-y: auto; padding: 8px 8px 16px; }
.side-search { margin: 8px; }
.cat { display: flex; align-items: center; padding: 14px 4px 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.cat span { flex: 1; }
.cat .icon-btn { width: 20px; height: 20px; }
.chan {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 6px; color: var(--muted); cursor: pointer; margin-bottom: 1px; position: relative;
}
.chan:hover { background: var(--bg-3); color: var(--text-2); }
.chan.active { background: var(--bg-4); color: var(--text); }
.chan.unread { color: var(--text); font-weight: 600; }
.chan.unread::before { content: ''; position: absolute; left: -8px; top: 50%; transform: translateY(-50%); width: 4px; height: 8px; border-radius: 0 4px 4px 0; background: var(--text); }
.chan .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan .actions { display: none; gap: 2px; }
.chan:hover .actions { display: flex; }
.chan .actions .icon-btn { width: 22px; height: 22px; }
.voice-users { padding: 2px 0 4px 26px; }
.voice-user { display: flex; align-items: center; gap: 8px; padding: 3px 8px; border-radius: 6px; color: var(--text-2); font-size: 14px; }
.voice-user:hover { background: var(--bg-3); }
.voice-user .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-user .icon { width: 14px; height: 14px; color: var(--muted); }
.voice-user .icon.off { color: var(--danger); }

.dm-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px; color: var(--text-2); cursor: pointer; margin-bottom: 1px; }
.dm-item:hover { background: var(--bg-3); color: var(--text); }
.dm-item.active { background: var(--bg-4); color: var(--text); }
.dm-item.unread { color: var(--text); font-weight: 600; }
.dm-item .meta { flex: 1; min-width: 0; }
.dm-item .sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.dm-item .close { display: none; }
.dm-item .badge { flex-shrink: 0; }

.voice-panel { background: var(--bg-0); border-top: 1px solid var(--line); padding: 8px 10px; }
.voice-panel .status { display: flex; align-items: center; gap: 8px; color: var(--success); font-weight: 700; font-size: 13px; }
.voice-panel .status.connecting { color: var(--warning); }
.voice-panel .sub { color: var(--muted); font-size: 12px; margin-left: 24px; }
.voice-panel .row { margin-top: 6px; }

.user-panel { height: 56px; background: var(--bg-0); display: flex; align-items: center; gap: 8px; padding: 0 8px; }
.user-panel .info { flex: 1; min-width: 0; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.user-panel .info:hover { background: var(--bg-2); }
.user-panel .info .n { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-panel .info .s { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-panel .icon-btn.off { color: var(--danger); }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg-2); }
.main-header { height: 48px; display: flex; align-items: center; gap: 8px; padding: 0 16px; border-bottom: 1px solid var(--bg-0); box-shadow: 0 1px 0 rgba(0, 0, 0, .3); flex-shrink: 0; }
.main-header .title { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.main-header .title .icon { color: var(--muted); }
.main-header .topic { color: var(--muted); font-size: 14px; border-left: 1px solid var(--line); padding-left: 12px; margin-left: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.main-header .spacer { flex: 1; }
.main-header .search-box { width: 200px; }
.main-header .search-box .input { padding: 6px 10px; font-size: 13px; }

.messages { flex: 1; overflow-y: auto; padding: 16px 0 8px; display: flex; flex-direction: column; }
.messages .spacer { flex: 1; }
.chan-intro { padding: 16px; }
.chan-intro .big { width: 68px; height: 68px; border-radius: 50%; background: var(--bg-4); display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.chan-intro .big .icon { width: 40px; height: 40px; color: var(--text); }
.chan-intro h2 { margin: 0 0 4px; font-size: 26px; }
.chan-intro p { margin: 0; color: var(--muted); }
.day-sep { display: flex; align-items: center; gap: 8px; margin: 14px 16px 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.day-sep::before, .day-sep::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.load-more { text-align: center; padding: 8px; }

.msg { position: relative; display: flex; gap: 14px; padding: 2px 16px 2px 16px; margin-top: 14px; }
.msg.compact { margin-top: 0; padding-top: 1px; padding-bottom: 1px; }
.msg:hover { background: rgba(0, 0, 0, .15); }
.msg.mention { background: rgba(255, 122, 26, .07); box-shadow: inset 2px 0 0 var(--accent); }
.msg.mention:hover { background: rgba(255, 122, 26, .11); }
.msg.editing { background: var(--bg-3); }
.msg .avatar { margin-top: 2px; width: 40px; height: 40px; font-size: 16px; cursor: pointer; }
.msg.compact .gutter { width: 40px; flex-shrink: 0; text-align: right; font-size: 10px; color: var(--muted); opacity: 0; padding-top: 4px; }
.msg.compact:hover .gutter { opacity: 1; }
.msg .body { flex: 1; min-width: 0; }
.msg .head { display: flex; align-items: baseline; gap: 8px; }
.msg .author { font-weight: 700; cursor: pointer; }
.msg .author:hover { text-decoration: underline; }
.msg .time { font-size: 12px; color: var(--muted); }
.msg .content { white-space: pre-wrap; word-wrap: break-word; color: var(--text-2); }
.msg .content .edited { font-size: 11px; color: var(--muted); }
.msg .content code { font-family: var(--mono); background: var(--bg-0); padding: 1px 4px; border-radius: 4px; font-size: 13px; }
.msg .content pre { background: var(--bg-0); border: 1px solid var(--line); padding: 8px 10px; border-radius: 6px; overflow-x: auto; margin: 4px 0; }
.msg .content pre code { background: none; padding: 0; }
.msg .content .mention { background: var(--accent-soft); color: var(--accent-2); padding: 0 3px; border-radius: 3px; font-weight: 600; }
.msg .reply-ref { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 2px; }
.msg .reply-ref::before { content: ''; width: 24px; height: 10px; border-left: 2px solid var(--line); border-top: 2px solid var(--line); border-radius: 6px 0 0 0; margin-left: 18px; margin-top: 8px; }
.msg .reply-ref b { color: var(--text-2); }
.msg .reply-ref span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 400px; cursor: pointer; }
.msg .reply-ref span:hover { color: var(--text); }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.attachments img { max-width: 400px; max-height: 300px; border-radius: 8px; cursor: zoom-in; display: block; }
.att-file { display: flex; align-items: center; gap: 10px; background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; max-width: 400px; }
.att-file .icon { color: var(--accent); width: 28px; height: 28px; flex-shrink: 0; }
.att-file .att-meta { min-width: 0; }
.att-file a { display: block; max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file a { font-weight: 600; }
.att-file .size { color: var(--muted); font-size: 12px; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction { display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px; border-radius: 6px; background: var(--bg-3); border: 1px solid transparent; font-size: 13px; }
.reaction:hover { border-color: var(--line); }
.reaction.mine { background: var(--accent-soft); border-color: var(--accent); }
.msg-actions { position: absolute; right: 16px; top: -14px; display: none; background: var(--bg-1); border: 1px solid var(--line); border-radius: 6px; padding: 2px; gap: 2px; box-shadow: 0 4px 12px rgba(0, 0, 0, .4); z-index: 5; }
.msg:hover .msg-actions { display: flex; }
.msg-actions .icon-btn { width: 28px; height: 28px; }
.edit-box textarea { width: 100%; }
.edit-box .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.emoji-pop { position: fixed; background: var(--bg-1); border: 1px solid var(--line); border-radius: 8px; padding: 6px; display: grid; grid-template-columns: repeat(8, 32px); gap: 2px; z-index: 20; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); }
.emoji-pop button { width: 32px; height: 32px; border-radius: 6px; font-size: 20px; }
.emoji-pop button:hover { background: var(--bg-3); }

.typing { height: 22px; padding: 0 16px; font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.typing .dots span { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--text-2); margin-right: 2px; animation: blink 1.2s infinite; }
.typing .dots span:nth-child(2) { animation-delay: .2s; }
.typing .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .2; } 30% { opacity: 1; } }

.composer { padding: 0 16px 16px; }
.composer .reply-bar, .composer .att-bar { background: var(--bg-3); border-radius: 8px 8px 0 0; padding: 6px 12px; font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.composer .reply-bar + .box, .composer .att-bar + .box { border-radius: 0 0 8px 8px; }
.composer .att-bar { flex-wrap: wrap; }
.composer .att-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg-4); border-radius: 6px; padding: 4px 8px; }
.composer .att-chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; }
.composer .box { display: flex; align-items: flex-end; background: var(--bg-3); border-radius: 8px; padding: 4px 8px 4px 4px; }
.composer textarea { flex: 1; background: none; border: 0; outline: none; resize: none; padding: 10px 8px; max-height: 240px; min-height: 44px; line-height: 1.4; }
.composer .icon-btn { margin-bottom: 6px; }
.composer .icon-btn.send { color: var(--accent); }

#members { width: var(--side-w); background: var(--bg-1); overflow-y: auto; padding: 16px 8px; flex-shrink: 0; }
.member { display: flex; align-items: center; gap: 10px; padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.member:hover { background: var(--bg-3); }
.member.off { opacity: .45; }
.member .meta { min-width: 0; flex: 1; }
.member .n { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.member .n.owner { color: var(--accent-2); }
.member .s { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .crown { color: var(--accent); width: 14px; height: 14px; }

/* ---------- home / friends ---------- */
.friends-page { flex: 1; overflow-y: auto; padding: 16px 24px; }
.friends-page .cat { padding-left: 0; }
.friend-row { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-top: 1px solid var(--line); }
.friend-row:hover { background: var(--bg-3); border-radius: 8px; }
.friend-row .meta { flex: 1; min-width: 0; }
.friend-row .n { font-weight: 700; }
.friend-row .s { font-size: 12px; color: var(--muted); }
.friend-row .icon-btn { background: var(--bg-1); border-radius: 50%; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }
.empty .ghost { width: 90px; height: 90px; opacity: .25; margin-bottom: 12px; }
.add-friend-box { background: var(--bg-3); border-radius: 10px; padding: 16px; margin-bottom: 8px; }
.add-friend-box .row .input { flex: 1; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .7); display: flex; align-items: center; justify-content: center; z-index: 100; animation: fade .12s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 480px; max-width: calc(100vw - 32px); max-height: calc(100vh - 32px); background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 24px 60px rgba(0, 0, 0, .6); display: flex; flex-direction: column; animation: pop .14s; }
.modal.wide { width: 760px; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
.modal-head { padding: 18px 22px 8px; display: flex; align-items: center; gap: 10px; }
.modal-head h2 { margin: 0; font-size: 20px; flex: 1; }
.modal-body { padding: 8px 22px 18px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; background: var(--bg-1); border-radius: 0 0 14px 14px; display: flex; justify-content: flex-end; gap: 8px; }
.settings-layout { display: flex; min-height: 420px; }
.settings-nav { width: 180px; padding-right: 16px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.settings-nav button { text-align: left; padding: 8px 10px; border-radius: 6px; color: var(--text-2); font-weight: 600; }
.settings-nav button:hover { background: var(--bg-3); color: var(--text); }
.settings-nav button.active { background: var(--bg-4); color: var(--text); }
.settings-nav button.danger { color: var(--danger); }
.settings-content { flex: 1; padding-left: 20px; min-width: 0; }
.settings-content h3 { margin: 0 0 14px; font-size: 17px; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.list-row .meta { flex: 1; min-width: 0; }
.list-row .n { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.list-row .s { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row select { width: auto; }
.icon-upload { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.invite-box { display: flex; gap: 8px; }
.invite-box .input { flex: 1; font-family: var(--mono); }
.profile-card { text-align: center; padding: 8px 0; }
.profile-card .avatar { margin: 0 auto 10px; }
.profile-card h3 { margin: 0; }
.profile-card .u { color: var(--muted); }
.profile-card .st { margin: 8px 0 14px; color: var(--text-2); }
.profile-card .row { justify-content: center; }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .9); display: flex; align-items: center; justify-content: center; z-index: 200; cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 6px; }

/* ---------- toasts ---------- */
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 300; pointer-events: none; }
.toast { background: var(--bg-1); border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); font-size: 14px; animation: pop .15s; }
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }

.welcome { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: 24px; }
.welcome .ghost { width: 120px; height: 120px; filter: drop-shadow(0 0 30px var(--accent-glow)); margin-bottom: 20px; }
.welcome h2 { color: var(--text); margin: 0 0 6px; }

/* ---------- responsive ---------- */
#app { height: 100dvh; }
#backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 35; opacity: 0; pointer-events: none; transition: opacity .18s; }
body.drawer-open #backdrop, body.members-open #backdrop { opacity: 1; pointer-events: auto; }
.msg .content, .msg .reply-ref span, .dm-item .meta, .member .meta { overflow-wrap: anywhere; }
.mobile-only { display: none !important; }

@media (max-width: 1100px) {
  #members { position: fixed; right: 0; top: 0; bottom: 0; z-index: 40; width: min(300px, 85vw); transform: translateX(105%); transition: transform .2s; box-shadow: -8px 0 24px rgba(0,0,0,.5); }
  body.members-open #members { transform: none; }
  #members[hidden] { display: block !important; }
  body.members-open #members[hidden] { transform: none; }
}

@media (max-width: 760px) {
  :root { --side-w: min(300px, calc(100vw - 96px)); }
  .mobile-only { display: inline-flex !important; }
  .desktop-only { display: none !important; }
  /* servers rail + channel list live in one off-canvas drawer; the chat gets the whole screen */
  #rail { position: fixed; left: 0; top: 0; bottom: 0; z-index: 41; transform: translateX(-100%); transition: transform .2s; }
  #sidebar { position: fixed; left: var(--rail-w); top: 0; bottom: 0; z-index: 41; transform: translateX(-130%); transition: transform .2s; box-shadow: 8px 0 24px rgba(0,0,0,.5); }
  body.drawer-open #rail, body.drawer-open #sidebar { transform: none; }
  #main { width: 100vw; }
  .main-header { padding: 0 8px; gap: 4px; height: 52px; }
  .main-header .title { min-width: 0; flex: 1; }
  .main-header .title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .main-header .topic { display: none; }
  .main-header .spacer { display: none; }
  .main-header .search-box { display: none; }
  .main-header.search-open .search-box { display: block; position: absolute; left: 8px; right: 8px; top: 52px; z-index: 5; width: auto; }
  .main-header.search-open .search-box .input { padding: 10px 12px; font-size: 16px; background: var(--bg-1); box-shadow: 0 8px 20px rgba(0,0,0,.5); }
  .main-header { position: relative; }
  .icon-btn { width: 40px; height: 40px; }
  .messages { padding-top: 10px; }
  .msg { padding: 3px 12px; gap: 10px; margin-top: 12px; }
  .msg .avatar { width: 36px; height: 36px; font-size: 14px; }
  .msg.compact .gutter { display: none; }
  .msg.compact { padding-left: 58px; }
  .msg .head { flex-wrap: wrap; gap: 6px; }
  .msg .reply-ref::before { margin-left: 8px; width: 16px; }
  .msg .reply-ref span { max-width: 55vw; }
  .attachments img { max-width: 100%; max-height: 260px; }
  .att-file { max-width: 100%; }
  .att-file a { max-width: calc(100vw - 120px); }
  /* no hover on touch: a tap on the message reveals its actions */
  .msg-actions { display: none; top: -16px; right: 8px; }
  .msg:hover .msg-actions { display: none; }
  .msg.touched .msg-actions { display: flex; }
  .msg.touched { background: rgba(0, 0, 0, .18); }
  .msg-actions .icon-btn { width: 36px; height: 36px; }
  .emoji-pop { grid-template-columns: repeat(6, 40px); }
  .emoji-pop button { width: 40px; height: 40px; font-size: 22px; }
  .composer { padding: 0 8px calc(8px + env(safe-area-inset-bottom)); }
  .composer textarea { font-size: 16px; min-height: 42px; padding: 9px 6px; }
  .composer .box { padding: 3px 4px; }
  .typing { padding: 0 12px; font-size: 12px; }
  .chan-intro { padding: 12px; }
  .chan-intro h2 { font-size: 22px; }
  .chan-intro .big { width: 56px; height: 56px; }
  .day-sep { margin: 12px 12px 4px; }
  .user-panel { height: auto; min-height: 60px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
  .side-header { height: 52px; }
  .chan { padding: 9px 8px; }
  .dm-item { padding: 8px; }
  .friends-page { padding: 8px 12px; }
  .tabs { overflow-x: auto; scrollbar-width: none; gap: 0; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; padding: 10px 10px; font-size: 14px; }
  .friend-row { padding: 10px 4px; gap: 10px; }
  .friend-row .icon-btn { width: 40px; height: 40px; }
  .add-friend-box .row { flex-wrap: wrap; }
  .add-friend-box .row .btn { width: 100%; }
  /* modals go full screen */
  .modal-back { align-items: stretch; justify-content: stretch; }
  .modal, .modal.wide { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; border: 0; }
  .modal-head { padding: 14px 16px 6px; }
  .modal-head h2 { font-size: 18px; }
  .modal-body { padding: 6px 16px 16px; flex: 1; }
  .modal-foot { border-radius: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; }
  .settings-layout { flex-direction: column; min-height: 0; }
  .settings-nav { width: auto; flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 0 0 8px; gap: 4px; scrollbar-width: none; }
  .settings-nav::-webkit-scrollbar { display: none; }
  .settings-nav button { white-space: nowrap; }
  .settings-nav .grow { display: none; }
  .settings-content { padding-left: 0; padding-top: 12px; }
  .list-row { flex-wrap: wrap; }
  .list-row .meta { flex-basis: 100%; }
  .list-row select { flex: 1; }
  .grid2 { grid-template-columns: 1fr; }
  .invite-box { flex-direction: column; }
  .profile-card .row { flex-wrap: wrap; }
  .profile-card .row .btn { flex: 1; }
  .call-panel { margin: 8px 8px 0; padding: 12px 10px; }
  .call-people { gap: 20px; }
  .call-panel .avatar.xl { width: 64px; height: 64px; font-size: 24px; }
  .call-btn { width: 48px; height: 48px; }
  .incoming-call { left: 10px; right: 10px; top: calc(10px + env(safe-area-inset-top)); min-width: 0; }
  #toast-root { left: 10px; right: 10px; transform: none; bottom: calc(80px + env(safe-area-inset-bottom)); }
  .toast { text-align: center; }
  .lightbox img { max-width: 100vw; max-height: 100dvh; border-radius: 0; }
  .auth-card { padding: 24px 18px; }
  .auth-lang { top: 10px; right: 10px; }
  .welcome .ghost { width: 90px; height: 90px; }
  .welcome .row { flex-wrap: wrap; justify-content: center; }
}

/* ---------- voice settings ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
.range { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 3px; background: var(--bg-4); outline: none; margin: 8px 0; }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg-1); cursor: pointer; box-shadow: 0 0 0 2px var(--accent-soft); }
.range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg-1); cursor: pointer; }
.meter { position: relative; height: 12px; border-radius: 6px; background: var(--bg-0); border: 1px solid var(--line); margin: 10px 0 6px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--muted); transition: width .06s linear; border-radius: 6px; }
.meter-fill.hot { background: var(--success); }
.meter-thr { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--accent); }
.voice-panel .ptt { font-size: 11px; color: var(--warning); margin-left: 24px; }

/* ---------- calls ---------- */
.call-panel { margin: 12px 16px 0; background: linear-gradient(180deg, var(--bg-1), var(--bg-0)); border: 1px solid var(--line); border-radius: 12px; padding: 18px 16px 14px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.call-people { display: flex; gap: 32px; }
.call-person { display: flex; flex-direction: column; align-items: center; gap: 6px; opacity: .45; position: relative; }
.call-person.in { opacity: 1; }
.call-person .n { font-weight: 600; font-size: 13px; }
.call-person .icon.off { position: absolute; right: -4px; top: 58px; color: var(--danger); background: var(--bg-0); border-radius: 50%; padding: 2px; }
.call-status { color: var(--text-2); font-size: 14px; min-height: 20px; }
.call-timer { font-variant-numeric: tabular-nums; color: var(--success); font-weight: 700; }
.call-actions { display: flex; gap: 12px; align-items: center; }
.call-btn { width: 44px; height: 44px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--bg-4); color: var(--text); transition: background .15s, transform .05s; }
.call-btn:hover { background: #363c48; }
.call-btn:active { transform: scale(.95); }
.call-btn.off { background: var(--bg-3); color: var(--danger); }
.call-btn.accept { background: var(--success); color: #fff; }
.call-btn.accept:hover { background: #4ccf7d; }
.call-btn.decline { background: var(--danger); color: #fff; }
.call-btn.decline:hover { background: #ff6b68; }
.incoming-call { position: fixed; top: 16px; right: 16px; z-index: 250; display: flex; align-items: center; gap: 12px; background: var(--bg-1); border: 1px solid var(--accent); border-radius: 14px; padding: 12px 14px; box-shadow: 0 16px 40px rgba(0,0,0,.6), 0 0 0 4px var(--accent-soft); animation: ringpulse 1.3s infinite; min-width: 300px; }
@keyframes ringpulse { 0%, 100% { box-shadow: 0 16px 40px rgba(0,0,0,.6), 0 0 0 0 var(--accent-soft); } 50% { box-shadow: 0 16px 40px rgba(0,0,0,.6), 0 0 0 8px var(--accent-soft); } }
.incoming-call .n { font-weight: 700; cursor: pointer; }
.incoming-call .s { font-size: 12px; color: var(--accent-2); }
.msg.call-msg { align-items: center; gap: 10px; margin-top: 10px; }
.msg.call-msg .call-ico { width: 40px; height: 40px; border-radius: 50%; background: var(--bg-3); display: flex; align-items: center; justify-content: center; color: var(--success); flex-shrink: 0; }
.msg.call-msg.missed .call-ico, .msg.call-msg.declined .call-ico { color: var(--danger); }
.msg.call-msg .content { color: var(--text-2); }
.msg.call-msg .time { font-size: 12px; color: var(--muted); margin-left: 6px; }

/* ---------- screen streaming ---------- */
.live { display: inline-flex; align-items: center; padding: 1px 6px; border-radius: 4px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 800; letter-spacing: .06em; line-height: 16px; cursor: pointer; flex-shrink: 0; }
.live:hover { filter: brightness(1.1); }
.live.on { outline: 2px solid #fff3; }
.icon-btn.streaming, .call-btn.streaming { color: var(--danger); }
.call-person .live { margin-top: 4px; }
#main { position: relative; }
#stream-view { position: absolute; right: 16px; bottom: 96px; width: min(46%, 640px); aspect-ratio: 16 / 9; background: #000; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; z-index: 30; box-shadow: 0 16px 40px rgba(0,0,0,.6); display: flex; flex-direction: column; }
#stream-view.big { left: 16px; right: 16px; top: 60px; bottom: 96px; width: auto; aspect-ratio: auto; }
#stream-view video { flex: 1; width: 100%; height: 100%; min-height: 0; object-fit: contain; background: #000; }
#stream-view .sv-head { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: linear-gradient(180deg, rgba(0,0,0,.75), transparent); opacity: 0; transition: opacity .15s; z-index: 1; }
#stream-view:hover .sv-head, #stream-view.big .sv-head { opacity: 1; }
#stream-view .sv-name { font-weight: 700; font-size: 13px; text-shadow: 0 1px 2px #000; }
#stream-view .icon-btn { color: #fff; }
@media (max-width: 760px) { #stream-view { left: 8px; right: 8px; width: auto; bottom: 90px; } #stream-view.big { top: 56px; } }

/* ---------- settings dialog: constant height, about rows ---------- */
.modal.settings { height: min(680px, calc(100vh - 32px)); }
.modal.settings .modal-body { flex: 1; overflow-y: auto; }
.modal.settings .settings-layout { min-height: 100%; }
.about-rows { display: flex; flex-direction: column; gap: 10px; font-size: 15px; }
.about-rows > div { display: grid; grid-template-columns: 150px 1fr; gap: 12px; align-items: baseline; }
.about-rows span { color: var(--muted); }
.about-rows b { font-weight: 600; word-break: break-all; }
@media (max-width: 760px) { .modal.settings { height: 100dvh; } }

/* ---------- context menus ---------- */
.ctx-menu { position: fixed; z-index: 400; min-width: 230px; background: var(--bg-0); border: 1px solid var(--line); border-radius: 10px; padding: 6px; box-shadow: 0 12px 32px rgba(0,0,0,.6); animation: pop .1s; }
.ctx-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 6px; color: var(--text-2); font-weight: 600; font-size: 13px; text-align: left; position: relative; }
.ctx-item:hover { background: var(--bg-3); color: var(--text); }
.ctx-item.danger { color: var(--danger); }
.ctx-item .chev { margin-left: auto; transform: rotate(-90deg); }
.ctx-item .icon-sm { width: 16px; height: 16px; flex-shrink: 0; }
.ctx-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.ctx-sub { display: none; position: absolute; left: 100%; top: -6px; min-width: 180px; background: var(--bg-0); border: 1px solid var(--line); border-radius: 10px; padding: 6px; box-shadow: 0 12px 32px rgba(0,0,0,.6); }
.ctx-sub.open, .ctx-item.has-sub:hover > .ctx-sub { display: block; }
.ctx-volume { padding: 8px 10px 6px; font-size: 13px; color: var(--text-2); }
.ctx-volume .range { margin: 8px 0 2px; }
.voice-user .srv .icon { color: var(--danger); }
.pill-timeout { background: rgba(228, 141, 145, .15); color: var(--danger); }
.composer .timeout-box { align-items: center; gap: 8px; padding: 12px; color: var(--muted); }
@media (max-width: 760px) { .ctx-menu { left: 8px !important; right: 8px; min-width: 0; } .ctx-sub { position: static; display: none; box-shadow: none; border: 0; padding-left: 20px; } .ctx-item.has-sub:hover > .ctx-sub { display: none; } .ctx-sub.open { display: block; } }

/* ---------- profile actions ---------- */
.profile-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 4px; }
.profile-actions .btn { width: 100%; padding: 11px 8px; font-size: 14px; white-space: nowrap; }
.profile-actions .btn-remove { color: var(--danger); }
.profile-actions .btn-remove:hover { background: rgba(228, 141, 145, .12); }
@media (max-width: 400px) { .profile-actions { grid-template-columns: 1fr; } }

/* friend code in the add-friend box */
.add-friend-box .my-code { margin-top: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.add-friend-box .my-code code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 1px; background: var(--bg-3); padding: 4px 10px; border-radius: 6px; color: var(--text); font-weight: 700; }

/* "Download desktop app" link under the auth card */
.auth-download { display: inline-flex; align-items: center; gap: 8px; margin: 18px auto 0; padding: 9px 16px; border-radius: 10px; color: var(--text-2); font-weight: 600; font-size: 13px; border: 1px solid var(--line); background: var(--bg-1, rgba(255,255,255,.02)); text-decoration: none; transition: background .12s, color .12s; }
.auth-download:hover { background: var(--bg-3); color: var(--text); }
.auth-download .icon { width: 16px; height: 16px; }
#auth { flex-direction: column; }
