:root {
  color-scheme: dark;
  --bg-rail: #131a2a;
  --bg-side: #1a2338;
  --bg-chat: #202b42;
  --bg-input: #283350;
  --bg-float: #0d1322;
  --bg-hover: rgba(96, 130, 200, 0.16);
  --bg-active: rgba(96, 130, 200, 0.3);
  --bg-msg-hover: rgba(0, 0, 0, 0.14);
  --border: rgba(0, 0, 0, 0.3);
  --text: #d5dcf0;
  --text-strong: #eef2fd;
  --muted: #8e9cbd;
  --faint: #5f6d8f;
  --accent: #6c5ef5;
  --accent-hover: #5a4be0;
  --green: #23a55a;
  --red: #f23f43;
  --link: #00a8fc;
  --panel: #182136;
  --bg-elevated: #1a2338;
  --border-soft: #34426a;
  --border-strong: #3d4f78;
  --border-focus: #4c5f94;
  --icon-muted: #a2aec9;
  --accent-soft: rgba(108, 94, 245, 0.18);
  --accent-text: #c9c4ff;
  --on-accent: #fff;
  --on-danger: #fff;
  --danger-text: #ff9da1;
  --focus-ring: var(--accent-text);
  --radius: 10px;
  --font: "Noto Sans", "Segoe UI", "Helvetica Neue", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, ui-monospace, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { zoom: var(--ui-zoom, 1); }
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg-rail); color: var(--text);
  font: 15px/1.375 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.hidden, [hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger-text); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-soft); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

.btn {
  border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 9px 15px; font-weight: 600;
  background: var(--bg-side); color: var(--text-strong); transition: background .15s;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-focus); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: #b92e38; border-color: transparent; color: var(--on-danger); }
.btn.danger:hover { background: #a12828; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }

label { display: block; text-transform: uppercase; font-size: 12px; font-weight: 700; color: var(--icon-muted); margin: 14px 0 0; letter-spacing: .02em; }
input {
  display: block; width: 100%; margin-top: 8px; padding: 10px;
  background: var(--bg-rail); border: 0; border-radius: 4px; outline: none;
  text-transform: none; font-weight: 400; letter-spacing: 0; font-size: 15px;
}
input:focus { box-shadow: 0 0 0 2px var(--accent); }

.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: 8px; background: transparent; color: var(--icon-muted);
}
.icon-btn:hover { color: var(--text-strong); background: var(--bg-hover); }
.icon-btn.active { color: var(--text-strong); }
.icon-btn.small { width: 24px; height: 24px; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.small svg { width: 16px; height: 16px; }

.login {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background:
    radial-gradient(900px 560px at 18% 12%, var(--accent-soft), transparent 70%),
    var(--bg-rail);
}
.login-card {
  width: 100%; max-width: 440px; padding: 32px;
  background: var(--bg-side); border: 1px solid var(--border-soft); border-radius: 16px; box-shadow: 0 18px 48px rgba(0,0,0,.22);
  text-align: center;
}
.login-card label { text-align: left; }
.login-card h1 { color: var(--text-strong); font-size: 24px; margin: 8px 0 4px; }
.login-card .btn { margin-top: 8px; }
.login-logo { width: 64px; height: 64px; }
.fine { font-size: 12px; color: var(--faint); margin: 16px 0 0; }

.app {
  position: fixed; left: 0; right: 0; top: var(--vvt, 0px); height: var(--vvh, 100%);
  display: grid; grid-template-columns: 72px 240px minmax(0, 1fr) auto; grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  padding-top: var(--safe-top);
}

@media (min-width: 821px) {
  [data-ui-zoom] .app { grid-template-columns: 72px min(240px, 29%) minmax(0, 1fr) auto; }
  [data-ui-zoom] .members { width: min(240px, calc(28vw / var(--ui-zoom))); }
}

.rail {
  background: var(--bg-rail); overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px 0 calc(12px + var(--safe-bottom)); scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.space-list { display: contents; }
.rail-sep { width: 32px; height: 2px; border-radius: 1px; background: var(--border-soft); flex: none; }
.rail-item {
  position: relative; flex: none; width: 48px; height: 48px; padding: 0; border: 0;
  border-radius: 50%; background: var(--bg-chat); color: var(--text);
  display: grid; place-items: center; transition: border-radius .15s, background .15s;
}
.rail-item > .avatar, .rail-item > img { width: 48px; height: 48px; border-radius: inherit; font-size: 18px; }
.rail-item:hover, .rail-item.active { border-radius: 16px; }
.rail-item.home { background: transparent; }
.rail-item.add .rail-icon { font-size: 26px; font-weight: 300; color: var(--green); line-height: 1; }
.rail-item.add:hover { background: var(--green); }
.rail-item.add:hover .rail-icon { color: #fff; }
.rail-item .pill {
  position: absolute; left: -16px; top: 50%; width: 8px; height: 0; margin-top: 0;
  background: var(--accent-text); border-radius: 0 4px 4px 0; transition: height .15s, margin-top .15s;
}
.rail-item.unread .pill { height: 8px; margin-top: -4px; }
.rail-item:hover .pill { height: 20px; margin-top: -10px; }
.rail-item.active .pill { height: 40px; margin-top: -20px; }
.rail-item .badge { position: absolute; right: -4px; bottom: -4px; box-shadow: 0 0 0 3px var(--bg-rail); }
.rail-item[data-tip]:hover::after {
  content: attr(data-tip); position: fixed; left: 80px; transform: translateY(0);
  background: var(--bg-float); color: var(--text-strong); padding: 6px 10px; border-radius: 4px;
  font-size: 14px; font-weight: 600; white-space: nowrap; pointer-events: none; z-index: 50;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
}

.sidebar { background: var(--bg-side); display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.sidebar-header {
  height: 56px; flex: none; padding: 0 16px; display: flex; align-items: center;
  font-weight: 600; color: var(--text-strong); border-bottom: 1px solid var(--border-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.channel-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 8px 16px; }
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 8px 4px; font-size: 12px; font-weight: 700; letter-spacing: .02em;
  text-transform: uppercase; color: var(--muted);
}
.section-title button { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 2px; }
.section-title button:hover { color: var(--text-strong); }
.home-section-title { gap: 4px; padding: 12px 0 3px; }
.home-section-title .home-section-toggle {
  display: flex; align-items: center; flex: 1; gap: 8px; min-height: 32px; padding: 4px 8px;
  border-radius: 6px; font: inherit; letter-spacing: inherit; text-transform: inherit; text-align: left;
}
.home-section-title .home-section-add { flex: none; width: 32px; height: 32px; border-radius: 6px; }
.home-section-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-section-title button:hover, .home-section-title button:focus-visible { background: var(--bg-hover); }
.home-section-arrow {
  width: 6px; height: 6px; flex: none; border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor; transform: rotate(-45deg);
}
.home-section-toggle[aria-expanded="true"] .home-section-arrow { transform: translateY(-1px) rotate(45deg); }
.home-dm-search { width: calc(100% - 16px); margin: 2px 8px 5px; padding: 7px 9px; }
@media (hover: none) {
  .home-section-title .home-section-toggle { min-height: 40px; }
  .home-section-title .home-section-add { width: 40px; height: 40px; }
}
.channel {
  position: relative; display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 6px 8px; margin: 2px 0; border: 0; border-radius: 8px; background: none;
  color: var(--muted); text-align: left; min-height: 34px;
}
.channel:hover { background: var(--bg-hover); color: var(--text-strong); }
.channel.active { background: var(--accent-soft); color: var(--text-strong); }
.channel.active .hash { color: var(--accent-text); }
.channel.unread { color: var(--text-strong); font-weight: 600; }
.channel.unread::before {
  content: ""; position: absolute; left: -8px; top: 50%; width: 4px; height: 8px; margin-top: -4px;
  background: var(--accent-text); border-radius: 0 4px 4px 0;
}
.channel .hash { width: 20px; flex: none; color: var(--icon-muted); display: grid; place-items: center; }
.channel .hash svg { width: 20px; height: 20px; }
.channel .avatar { width: 32px; height: 32px; font-size: 13px; }
.channel .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel.invite { flex-wrap: wrap; cursor: default; }
.invite-actions { display: flex; gap: 6px; width: 100%; padding-left: 40px; }
.invite-actions .btn { padding: 4px 10px; font-size: 13px; }
.empty-hint { color: var(--faint); font-size: 13px; padding: 8px; }
.badge {
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--red); color: var(--badge-text, #171117); font-size: 11px; font-weight: 700;
  display: inline-grid; place-items: center;
}
.badge.grey { background: var(--border-strong); }

.user-panel {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 8px 8px calc(8px + var(--safe-bottom)); background: var(--panel);
  border-top: 1px solid var(--border-soft);
}
.user-panel .avatar { width: 32px; height: 32px; font-size: 13px; position: relative; overflow: visible; }
.user-panel .who { flex: 1; min-width: 0; line-height: 1.2; }
.user-panel .who b { display: block; font-size: 14px; color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-panel .who small { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot {
  position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 0 3px var(--panel);
}
.status-dot.offline { background: #80848e; }

.chat { background: var(--bg-chat); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-header {
  height: 56px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--border-soft); z-index: 1; min-width: 0;
}
.chat-header h2 { margin: 0; font-size: 16px; color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: none; max-width: 40%; }
.chat-icon { color: var(--icon-muted); display: grid; place-items: center; }
.chat-icon svg { width: 24px; height: 24px; }
.chat-icon .avatar { width: 24px; height: 24px; font-size: 11px; }
.chat-topic {
  flex: 1; min-width: 0; color: var(--muted); font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding-left: 12px; margin-left: 4px; border-left: 1px solid var(--border-soft);
}
.chat-topic:empty { border: 0; }
.header-actions { display: flex; gap: 6px; margin-left: auto; flex: none; }
#message-search-btn, #pinned-messages-btn { color: var(--icon-muted); }
#message-search-btn:hover, #pinned-messages-btn:hover { color: var(--text-strong); }
#room-settings-btn { border: 1px solid var(--border-soft); }
#room-settings-btn:hover { border-color: var(--border-focus); }
.status-banner { background: #f0b232; color: #211806; font-size: 13px; font-weight: 600; padding: 6px 16px; text-align: center; }

.messages { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 16px 0 8px; overscroll-behavior: contain; }
.messages .welcome { padding: 16px 16px 8px; }
.welcome .big-icon { width: 68px; height: 68px; border-radius: 50%; background: var(--bg-input); display: grid; place-items: center; color: var(--accent-text); margin-bottom: 8px; }
.welcome .big-icon svg { width: 42px; height: 42px; }
.welcome .big-icon.avatar { font-size: 26px; }
.welcome h3 { font-size: 30px; margin: 8px 0; color: var(--text-strong); line-height: 1.2; }
.welcome p { color: var(--muted); margin: 0; }
.loading-more { text-align: center; color: var(--faint); font-size: 13px; padding: 8px; }

.day-divider { display: flex; align-items: center; margin: 24px 16px 8px; color: var(--muted); font-size: 12px; font-weight: 600; }
.day-divider::before, .day-divider::after { content: ""; flex: 1; height: 1px; background: var(--border-soft); }
.day-divider span { padding: 0 6px; }

.msg { position: relative; padding: 2px 48px 2px 72px; min-height: 22px; margin-top: 17px; }
.msg.cont { margin-top: 0; }
.msg:hover { background: var(--bg-msg-hover); }
.msg > .avatar { position: absolute; left: 16px; top: 4px; width: 40px; height: 40px; font-size: 16px; cursor: default; }
.msg .meta { display: flex; align-items: baseline; gap: 8px; }
.msg .author { font-weight: 600; color: var(--text-strong); }
.msg .meta > .author { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.msg .meta > .ts { flex: none; white-space: nowrap; }
.chat-pronouns {
  flex: 0 1 auto; min-width: 0; max-width: min(36vw, 180px); padding: 1px 5px;
  border-radius: 5px; background: var(--accent-soft); color: var(--text);
  font-size: 11px; line-height: 1.35; unicode-bidi: isolate;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg .ts { font-size: 12px; color: var(--muted); }
.msg .hover-ts {
  position: absolute; left: 0; width: 72px; text-align: center; top: 4px;
  font-size: 11px; color: var(--muted); visibility: hidden;
}
.msg:hover .hover-ts { visibility: visible; }
.msg .body { white-space: normal; word-wrap: break-word; overflow-wrap: anywhere; color: var(--text); user-select: text; -webkit-user-select: text; }
.msg .body.emoji-only { font-size: 32px; line-height: 1.3; }
.msg .body.notice { color: var(--muted); }
.msg .body.emote { font-style: italic; }
.msg .body.dim { color: var(--muted); font-style: italic; font-size: 14px; }
.msg .body .edited { font-size: 10px; color: var(--muted); margin-left: 4px; }
.msg .body a { color: var(--link); text-decoration: none; }
.msg .body a:hover { text-decoration: underline; }
.msg .body a.matrix-mention { padding: 1px 4px; border-radius: 4px; background: var(--accent-soft); color: var(--accent-text); }
.msg .body code { font-family: var(--mono); font-size: 85%; background: var(--bg-side); border-radius: 3px; padding: 2px 4px; }
.msg .body pre { background: var(--bg-side); border: 1px solid var(--bg-rail); border-radius: 4px; padding: 8px; margin: 4px 0; overflow-x: auto; max-width: 100%; }
.msg .body pre code { background: none; padding: 0; font-size: 13px; }
.msg.pending .body { color: var(--muted); }
.msg.failed .body { color: var(--red); }
.msg.highlight { background: rgba(250, 168, 26, .08); box-shadow: inset 2px 0 0 #f0b232; }
.msg.system { color: var(--muted); font-size: 14px; padding-top: 2px; padding-bottom: 2px; margin-top: 4px; display: flex; gap: 8px; align-items: baseline; }
.msg.system .sys-icon { position: absolute; left: 28px; color: var(--green); }
.msg.system .ts { margin-left: 4px; }

.msg .reply-ref {
  position: relative; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted);
  margin-bottom: 2px; white-space: nowrap; overflow: hidden; cursor: pointer;
}
.msg .reply-ref::before {
  content: ""; position: absolute; left: -36px; top: 50%; width: 28px; height: 10px;
  border-left: 2px solid var(--border-strong); border-top: 2px solid var(--border-strong); border-top-left-radius: 6px;
}
.msg .reply-ref .avatar { width: 16px; height: 16px; font-size: 8px; flex: none; }
.msg .reply-ref b { color: var(--text-strong); font-weight: 600; flex: none; }
.msg .reply-ref span { overflow: hidden; text-overflow: ellipsis; }

.media-image-preview {
  position: relative; display: block; margin-top: 4px; border-radius: 8px; background: var(--bg-side);
  max-width: min(400px, 100%); overflow: hidden;
}
.media-image-preview img { display: block; width: 100%; height: 100%; object-fit: contain; }
.image-preview-open {
  display: block; width: 100%; height: 100%; border: 0; padding: 0; background: transparent; cursor: zoom-in;
}
.image-preview-open:focus-visible { outline-offset: -2px; }
.msg .file {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 4px; padding: 10px 14px;
  background: var(--bg-side); border: 1px solid var(--bg-rail); border-radius: 8px; max-width: 100%;
}
.msg .file svg { width: 28px; height: 28px; color: var(--icon-muted); flex: none; }
.msg .file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--link); }

.msg-actions {
  position: absolute; right: 16px; top: -16px; display: none; z-index: 2;
  background: var(--bg-chat); border: 1px solid var(--border-soft); border-radius: 6px; padding: 2px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.msg:hover .msg-actions { display: flex; }
.msg-actions .icon-btn { width: 30px; height: 30px; }
.msg-actions .icon-btn.danger:hover { color: var(--red); }
.message-pin-indicator {
  display: inline-flex; gap: 4px; align-items: center; color: var(--accent-text); font-size: 11px;
}
.message-pin-indicator svg { display: block; width: 13px; height: 13px; }
.timeline-history-toolbar {
  position: sticky; top: 0; z-index: 3; display: flex; gap: 8px; flex-wrap: wrap;
  align-items: center; justify-content: space-between; margin: 0 12px 6px; padding: 8px 12px;
  background: var(--bg-side); border: 1px solid var(--border-soft); border-radius: 8px; color: var(--muted);
}
.timeline-history-toolbar .btn { padding: 6px 10px; }
.msg.message-jump-target { background: var(--accent-soft); box-shadow: inset 2px 0 var(--accent); }

.composer-wrap { position: relative; flex: none; padding: 0 16px calc(20px + var(--safe-bottom)); }
.mention-picker {
  position: absolute; z-index: 8; inset-inline: 16px; bottom: calc(100% + 6px);
  width: min(380px, calc(100% - 32px)); max-height: min(260px, calc(36vh / var(--ui-zoom, 1))); overflow-y: auto;
  padding: 4px; border: 1px solid var(--border-soft); border-radius: 10px;
  background: var(--bg-float); box-shadow: 0 8px 24px rgba(0, 0, 0, .26);
}
.mention-option {
  display: flex; align-items: center; gap: 9px; width: 100%; min-height: 42px;
  padding: 5px 8px; border: 0; border-radius: 6px; background: transparent;
  color: var(--text); text-align: left;
}
.mention-option:hover, .mention-option[aria-selected="true"] { background: var(--bg-hover); }
.mention-option .avatar { width: 30px; height: 30px; font-size: 12px; }
.mention-identity { flex: 1; min-width: 0; }
.mention-identity > * { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mention-identity small, .mention-status { color: var(--muted); }
.mention-status:not(:empty) { padding: 7px 8px; font-size: 13px; }
.typing-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 2px 8px 4px; font-size: 12px; color: var(--muted); min-height: 18px;
}
.typing-bar b { color: var(--text-strong); font-weight: 600; }
.typing-dots { letter-spacing: 2px; animation: typing-pulse 1.4s ease-in-out infinite; }
@keyframes typing-pulse { 0%, 60%, 100% { opacity: .35; } 30% { opacity: 1; } }
.reply-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--bg-side); border-radius: 8px 8px 0 0; padding: 8px 12px; font-size: 13px; color: var(--muted);
}
.reply-bar b { color: var(--text-strong); }
.reply-bar:not(.hidden) + .composer { border-top-left-radius: 0; border-top-right-radius: 0; }
.composer {
  display: flex; align-items: flex-end; gap: 2px; background: var(--bg-input);
  border: 1px solid var(--border-soft); border-radius: 12px; padding: 0 6px;
}
.composer:focus-within { border-color: var(--border-focus); box-shadow: 0 0 0 2px var(--accent-soft); }
.composer-textarea-wrap { position: relative; flex: 1; min-width: 0; }
.composer textarea {
  position: relative; display: block; width: 100%; min-width: 0; resize: none; border: 0; outline: none; background: transparent;
  padding: 11px 0; height: 44px; min-height: 44px; max-height: calc(40vh / var(--ui-zoom, 1));
  overflow: hidden; line-height: 22px; color: var(--text);
}
.composer-mention-mirror {
  position: absolute; inset: 0 auto 0 0; overflow: hidden; pointer-events: none;
  color: transparent; font: inherit; line-height: 22px;
}
.composer-mention-paint {
  padding: 11px 0 11px 6px; white-space: pre-wrap; overflow-wrap: break-word; tab-size: 8;
}
.composer-mention-chip {
  background: var(--accent-soft); border-radius: 3px;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.composer textarea::placeholder { color: var(--faint); text-overflow: ellipsis; }
.composer .icon-btn { flex: 0 0 auto; }
.composer .send { margin: 6px 0; color: var(--icon-muted); }
.composer textarea:disabled { cursor: not-allowed; }

.members { width: 240px; min-height: 0; background: var(--bg-side); overflow-y: auto; }
.app.members-hidden .members { display: none; }
.members-inner { padding: 8px 8px 16px; }
.members-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 37px; padding: 0 4px 4px 8px; border-bottom: 1px solid var(--border-soft);
}
.members-header .section-title { margin: 0; padding: 0; }
.members-header .icon-btn { flex: none; }
@media (pointer: coarse) {
  .members-header .icon-btn { width: 44px; height: 44px; }
}
.member { display: flex; align-items: center; gap: 12px; padding: 6px 8px; border-radius: 4px; color: var(--muted); cursor: pointer; }
.member:hover { background: var(--bg-hover); color: var(--text); }
.member .avatar { width: 32px; height: 32px; font-size: 13px; }
.member .mname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  flex: none; border-radius: 50%; display: grid; place-items: center; overflow: hidden;
  color: #fff; font-weight: 600; background-size: cover; background-position: center; user-select: none;
  text-transform: uppercase;
}

.backdrop { display: none; }
.loading {
  position: absolute; inset: 0; z-index: 40; background: var(--bg-rail);
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted);
}
.loading-logo { width: 80px; height: 80px; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-6deg); } }

.modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.7); display: grid; place-items: center; padding: 16px; }
.modal {
  width: 100%; max-width: 460px; max-height: calc(100vh / var(--ui-zoom, 1) - 32px); overflow-y: auto;
  background: var(--bg-chat); border: 1px solid var(--border-soft); border-radius: 16px; padding: 24px; box-shadow: 0 16px 48px rgba(0,0,0,.32);
}
.modal h2 { margin: 0 0 4px; color: var(--text-strong); font-size: 22px; text-align: center; }
.modal > div > p { text-align: center; }
.modal .field-row { display: flex; gap: 8px; align-items: flex-end; }
.modal .field-row label { flex: 1; }
.modal .field-row .btn { flex: none; }
.modal .group { padding: 12px 0; border-top: 1px solid var(--border-soft); }
.modal .group:first-of-type { border-top: 0; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); z-index: 70;
  background: var(--bg-float); color: var(--text-strong); padding: 10px 16px; border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5); font-size: 14px; max-width: calc(100vw / var(--ui-zoom, 1) - 32px);
}

.mobile-only { display: none; }

@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .mobile-only { display: inline-grid; }
  .rail, .sidebar {
    position: fixed; top: var(--safe-top); bottom: 0; z-index: 30;
    transform: translateX(-340px); transition: transform .2s ease;
  }
  .rail {
    left: 0; width: 60px;
    padding: 10px 0 calc(10px + var(--safe-bottom)); gap: 8px;
  }
  .sidebar {
    left: 60px; width: min(236px, calc(100vw - 72px));
    border-right: 1px solid var(--border-soft); box-shadow: 8px 0 24px rgba(0, 0, 0, .35);
  }
  .app.nav-open .rail, .app.nav-open .sidebar { transform: none; }
  .chat { grid-column: 1; grid-row: 1; height: 100%; }
  .rail-item { width: 40px; height: 40px; }
  .rail-item > .avatar, .rail-item > img { width: 40px; height: 40px; font-size: 15px; }
  .rail-item .pill { left: -10px; }
  .rail-item.active .pill { height: 40px; margin-top: -20px; }
  .rail-item .badge { box-shadow: 0 0 0 2px var(--bg-rail); }
  .rail-sep { width: 26px; }
  .rail-item.add .rail-icon { font-size: 22px; }
  .sidebar-header { height: 48px; padding: 0 12px; font-size: 15px; }
  .channel-list { padding: 6px 10px 16px; scrollbar-width: none; }
  .channel-list::-webkit-scrollbar { display: none; }
  .section-title { padding: 14px 8px 6px; font-size: 11px; letter-spacing: .06em; color: var(--faint); }
  .section-title button { font-size: 16px; }
  .channel { min-height: 40px; padding: 5px 8px; border-radius: 6px; gap: 10px; }
  .channel .hash { width: 18px; }
  .channel .hash svg { width: 18px; height: 18px; }
  .channel .avatar { width: 28px; height: 28px; font-size: 12px; }
  .channel.unread::before { left: -10px; }
  .invite-actions { padding-left: 38px; }
  .user-panel { padding: 8px 10px calc(8px + var(--safe-bottom)); gap: 10px; }
  .user-panel .avatar { width: 30px; height: 30px; font-size: 12px; }
  .members {
    position: fixed; top: var(--safe-top); bottom: 0; right: 0; z-index: 30; width: min(260px, 80vw);
    border-left: 1px solid var(--border-soft); box-shadow: -8px 0 24px rgba(0, 0, 0, .35);
    transform: translateX(calc(100% + 40px)); transition: transform .2s ease;
  }
  .app.members-hidden .members { display: block; }
  .app.members-open .members { transform: none; }
  .backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.5); }
  .app.nav-open .backdrop, .app.members-open .backdrop { display: block; }
  .chat-topic { display: none; }
  .chat-header { height: 52px; padding: 0 6px 0 12px; }
  .chat-header h2 { max-width: none; flex: 1; font-size: 16px; }
  .chat-header .icon-btn { width: 38px; height: 38px; }
  .header-actions { gap: 2px; }
  .msg { padding-right: 16px; padding-left: 60px; }
  .msg > .avatar { width: 36px; height: 36px; font-size: 14px; left: 12px; top: 3px; }
  .msg .meta { gap: 6px; }
  .msg .ts { font-size: 11px; }
  .welcome .big-icon { width: 56px; height: 56px; }
  .welcome .big-icon svg { width: 34px; height: 34px; }
  .welcome .big-icon.avatar { font-size: 22px; }
  .welcome h3 { font-size: 24px; }
  .composer-wrap { padding: 0 12px calc(8px + var(--safe-bottom)); }
  .members { width: min(240px, 80vw); }
  .rail-item[data-tip]:hover::after { display: none; }
}

.composer .attach { margin: 6px 0; width: 32px; height: 32px; color: var(--icon-muted); }
.composer .attach svg { width: 22px; height: 22px; }
.composer textarea { padding-left: 6px; }
.gif-head .gif-toggle {
  width: auto; height: 28px; padding: 0 9px; font-size: 12px; font-weight: 800;
  letter-spacing: .04em; border: 1px solid var(--border-strong); border-radius: 8px; color: var(--icon-muted);
}
.gif-head .gif-toggle.active { color: var(--text-strong); border-color: var(--border-focus); }
.picker-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.theme-scroll {
  position: relative; max-height: min(310px, calc(42vh / var(--ui-zoom, 1)));
  overflow: hidden auto; overscroll-behavior: contain; scrollbar-gutter: stable;
  margin-top: 12px; padding: 8px;
  background: var(--bg-chat); border: 1px solid var(--border-soft); border-radius: 12px;
}
.theme-scroll:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.theme-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.theme-card {
  display: flex; flex-direction: column; min-width: 0; gap: 8px; padding: 8px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius); background: var(--bg-side); color: var(--text); text-align: left;
}
.home-background-picker { margin-top: 16px; }
.home-background-picker h3 { margin: 0 0 8px; color: var(--text-strong); font-size: 14px; }
.home-background-scroll {
  max-height: min(220px, calc(32vh / var(--ui-zoom, 1))); overflow: hidden auto;
  overscroll-behavior: contain; scrollbar-gutter: stable;
  padding: 6px; border: 1px solid var(--border-soft); border-radius: 10px;
}
.home-background-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 100px), 1fr)); gap: 6px; }
.home-background-swatch {
  display: block; width: 100%; aspect-ratio: 16 / 8; border-radius: 5px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 0, var(--accent-soft), transparent 95%), var(--bg-chat);
}
.home-background-swatch img { display: block; width: 100%; height: 100%; object-fit: cover; }
.home-background-status:empty { display: none; }
.theme-card:hover { background: var(--bg-hover); }
.theme-card[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.theme-swatch { display: flex; width: 100%; height: 28px; border: 1px solid var(--border-soft); border-radius: 6px; overflow: hidden; }
.theme-swatch i { flex: 1; }
.theme-name { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.theme-name::before {
  content: ""; flex: none; width: 12px; height: 12px; box-sizing: border-box;
  border: 1px solid var(--icon-muted); border-radius: 50%;
}
.theme-card[aria-pressed="true"] .theme-name { color: var(--text-strong); }
.theme-card[aria-pressed="true"] .theme-name::before {
  border: 3px solid var(--accent-text);
}

.modal:has(.message-discovery-dialog) { max-width: 690px; }
.message-discovery-room { text-align: center; margin: 0 0 14px; overflow-wrap: anywhere; }
.message-search-form { display: flex; gap: 8px; }
.message-search-form input { flex: 1; min-width: 0; }
.message-search-form .btn { flex: none; }
.message-discovery-dialog > [role="status"]:empty { display: none; }
.message-discovery-list {
  margin: 12px 0 0; padding: 0; display: grid; gap: 6px; list-style: none;
}
.message-discovery-list:empty { display: none; }
.message-discovery-result {
  min-width: 0; width: 100%; display: grid; gap: 4px; padding: 10px 12px; text-align: start;
  border: 1px solid var(--border-soft); border-radius: 8px; background: var(--bg-side);
}
.message-discovery-result:hover {
  border-color: var(--border-focus); background: var(--accent-soft);
}
.message-discovery-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.message-discovery-meta b { color: var(--text-strong); overflow-wrap: anywhere; }
.message-discovery-meta :is(time, small) { color: var(--muted); font-size: 12px; }
.message-discovery-snippet {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
  overflow: hidden; overflow-wrap: anywhere; white-space: pre-line;
}
.modal:has(.pinned-messages-dialog), .pinned-messages-dialog {
  max-height: min(510px, calc(100vh / var(--ui-zoom, 1) - 32px));
  max-height: min(510px, calc(100dvh / var(--ui-zoom, 1) - 32px));
}
.modal:has(.pinned-messages-dialog) { max-width: 510px; padding: 0; overflow: hidden; }
.pinned-messages-dialog { display: flex; flex-direction: column; }
.pinned-messages-header { flex: none; padding: 14px 16px 10px; }
.pinned-messages-header h2 { font-size: 18px; text-align: start; }
.pinned-messages-header p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pinned-messages-scroll {
  flex: 0 1 auto; min-height: 0; overflow: hidden auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent;
  scrollbar-gutter: stable; padding: 2px 16px 12px;
}
.pinned-messages-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); }
.pinned-messages-scroll:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.pinned-messages-scroll > [role="status"]:empty { display: none; }
.pinned-messages-scroll .message-discovery-list { margin: 0; }
.pinned-messages-scroll .message-discovery-result { padding: 8px 10px; }
.pinned-messages-scroll .message-discovery-snippet { -webkit-line-clamp: 2; }
.pinned-messages-footer {
  flex: none; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  border-top: 1px solid var(--border-soft); background: var(--bg-chat);
  padding: 10px 16px max(10px, var(--safe-bottom));
}
.pinned-messages-footer .btn { font-size: 13px; padding: 7px 12px; }
.pinned-messages-footer .btn:last-child { margin-inline-start: auto; }
.message-pin-row { display: flex; align-items: center; gap: 8px; }
.message-pin-row > :first-child { flex: 1; min-width: 0; }
.message-pin-row .btn { flex: none; }
.modal:has(.room-settings-dialog) { max-width: 760px; }
.room-settings-dialog { container-type: inline-size; }
.room-settings-dialog h2, .modal .room-settings-name { text-align: start; }
.room-settings-name { color: var(--muted); margin: 4px 0 18px; overflow-wrap: anywhere; }
.room-settings-dialog .room-settings-row { grid-template-columns: auto minmax(0, 1fr); align-items: start; }
.room-settings-dialog .room-settings-row .btn { grid-column: 2; justify-self: start; max-width: 100%; }
@container (min-width: 560px) {
  .room-settings-dialog .room-settings-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.room-settings-list { display: grid; gap: 10px; }
.room-settings-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px;
  border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--bg-side); padding: 12px;
}
.room-settings-icon {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-text); border-radius: 8px;
}
.room-settings-icon svg { width: 18px; height: 18px; }
.room-settings-icon.encrypted { color: var(--green); }
.room-settings-icon.leave { background: var(--bg-input); color: var(--danger-text); }
.room-settings-copy h3 { color: var(--text-strong); font-size: 14px; margin: 0 0 3px; }
.room-settings-copy p { color: var(--muted); font-size: 13px; margin: 0; }
.room-settings-row .btn { padding: 7px 10px; font-size: 13px; }
.btn.danger-outline { color: var(--danger-text); }
.btn.danger-outline:hover { border-color: var(--danger-text); }
@media (max-width: 480px) {
  .room-settings-row { grid-template-columns: auto minmax(0, 1fr); }
  .room-settings-row .btn { grid-column: 2; justify-self: start; }
}

.security-banner {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px; font-size: 13px;
  background: var(--bg-side); border-bottom: 1px solid var(--bg-rail); color: var(--text);
}
.security-banner svg { width: 18px; height: 18px; flex: none; color: #f0b232; }
.security-banner span { flex: 1; min-width: 0; }
.security-banner > span:first-child { flex: none; display: grid; }
.security-banner .btn { padding: 5px 12px; font-size: 13px; flex: none; }
.security-banner .icon-btn { flex: none; width: 28px; height: 28px; }
.msg .body.utd { display: flex; gap: 6px; align-items: baseline; color: var(--muted); font-style: italic; font-size: 14px; }
.role-badge { display: inline-grid; place-items: center; vertical-align: middle; cursor: help; }
.role-badge svg { width: 14px; height: 14px; }
.msg .meta .role-badge { margin-left: -2px; }
.member-group-title { justify-content: flex-start; gap: 6px; }
.member-group-title .role-badge { flex: none; }
.link-preview {
  font-family: var(--mono); font-size: 13px; background: var(--bg-rail); border-radius: 6px; padding: 10px 12px;
  color: var(--link); overflow-wrap: anywhere; user-select: all; -webkit-user-select: all;
}
.link-host { color: var(--text-strong); }
.msg .shield { display: inline-grid; place-items: center; vertical-align: middle; cursor: help; margin-left: 2px; }
.msg .shield svg { width: 14px; height: 14px; }
.msg .shield.red { color: var(--red); }
.msg .shield.grey { color: var(--muted); }
.msg > .shield { position: absolute; right: 18px; top: 4px; }
.msg .body.utd svg { width: 14px; height: 14px; flex: none; position: relative; top: 2px; }
.msg .body.utd a { color: var(--link); font-style: normal; cursor: pointer; }

.sec-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.sec-row .dot { width: 10px; height: 10px; border-radius: 50%; background: #80848e; flex: none; }
.sec-row .dot.ok { background: var(--green); }
.sec-row .dot.warn { background: #f0b232; }
.sec-row div { flex: 1; min-width: 0; }
.sec-row b { display: block; color: var(--text-strong); font-weight: 600; }
.sec-row small { color: var(--muted); }
.recovery-key {
  font-family: var(--mono); font-size: 15px; letter-spacing: .04em; word-spacing: .3em;
  background: var(--bg-rail); border-radius: 6px; padding: 14px; margin: 12px 0; color: var(--text-strong);
  user-select: all; -webkit-user-select: all; text-align: center; line-height: 1.7;
}
.tabs { display: flex; gap: 4px; margin: 12px 0 4px; border-bottom: 1px solid var(--border-soft); }.tabs button {
  border: 0; background: none; color: var(--muted); padding: 8px 12px; font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--text-strong); border-bottom-color: var(--accent); }
.add-pane { display: flex; flex-direction: column; gap: 14px; padding: 16px 0 4px; }
.add-pane .hint { margin: -8px 0 0; }
select {
  display: block; width: 100%; margin-top: 8px; padding: 10px 36px 10px 10px; border: 0; border-radius: 4px;
  color: var(--text); font: inherit; text-transform: none; font-weight: 400; outline: none;
  appearance: none; -webkit-appearance: none;
  background: var(--bg-rail) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23b5bac1' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 12px center;
}
select:focus { box-shadow: 0 0 0 2px var(--accent); }
.check { display: flex; align-items: center; gap: 10px; text-transform: none; font-size: 14px; font-weight: 500; color: var(--text); letter-spacing: 0; }
.check input { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--accent); }
.about { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border-soft); font-size: 13px; color: var(--muted); }
.about b { color: var(--text-strong); }
.about p { margin: 6px 0 0; }
.about a { color: var(--link); text-decoration: none; overflow-wrap: anywhere; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.hint a, .modal a { color: var(--link); }

.media-image-preview.natural {
  width: fit-content; min-width: min(120px, 100%); min-height: 80px;
  display: grid; place-items: center;
}
.media-image-preview.natural .image-preview-open { width: auto; height: auto; }
.media-image-preview.natural img { width: auto; height: auto; max-width: 100%; max-height: 320px; }
.media-image-preview .spinner, .media-video-preview .spinner { position: absolute; inset: 0; margin: auto; }
.media-video-preview {
  position: relative; display: block; margin-top: 4px; max-width: min(400px, 100%); border-radius: 8px;
  overflow: hidden; background: var(--bg-rail); min-height: 90px;
}
.video-preview-frame { position: absolute; inset: 0; display: grid; place-items: center; }
.video-preview-frame :is(video, img) { display: block; width: 100%; height: 100%; object-fit: contain; min-height: 0; }
.media-video-preview .play {
  position: absolute; inset: 0; margin: auto; width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.65); color: #fff; display: grid; place-items: center;
}
.media-video-preview .play svg { width: 26px; height: 26px; margin-left: 3px; }
.video-expand.btn {
  position: absolute; inset-block-start: 6px; inset-inline-end: 6px;
  padding: 6px; display: grid; place-items: center;
  background: rgba(0, 0, 0, .74); color: #fff; border-color: rgba(255, 255, 255, .35);
}
.video-expand svg { width: 18px; height: 18px; }
.msg audio { display: block; margin-top: 4px; width: min(360px, 100%); height: 40px; }
.msg .file { cursor: pointer; }
.msg .file .meta-col { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.msg .file .meta-col small { color: var(--muted); font-size: 12px; }
.msg .file .dl { margin-left: 6px; color: var(--icon-muted); }
.msg .file .dl svg { width: 22px; height: 22px; }
.upload-progress { height: 4px; border-radius: 2px; background: var(--bg-rail); overflow: hidden; margin-top: 6px; max-width: 400px; }
.upload-progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.lightbox {
  position: fixed; inset: 0; z-index: 80; display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 8px;
  background: #100f15; color: #f4eff8;
  padding: max(8px, var(--safe-top)) clamp(8px, 2vw, 20px) max(8px, var(--safe-bottom));
}
.lightbox-heading, .lightbox-footer, .lightbox-tools, .lightbox-playback { display: flex; align-items: center; gap: 8px; }
.lightbox-heading { justify-content: space-between; min-width: 0; }
.lightbox-heading > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lightbox .btn { padding: 5px 9px; min-height: 34px; background: #25212e; color: #f4eff8; border-color: #50495b; }
.lightbox .btn:hover:not(:disabled) { background: #393144; }
.lightbox .btn:focus-visible, .lightbox-stage:focus-visible { outline-color: #f4d4ef; }
.lightbox-stage {
  min-width: 0; min-height: 0; position: relative; overflow: auto; overscroll-behavior: contain;
  border: 1px solid #35303d; border-radius: 8px; background: #09080b;
  scrollbar-width: none; touch-action: none;
}
.lightbox-stage::-webkit-scrollbar { display: none; }
.lightbox-stage.can-pan { cursor: grab; }
.lightbox-stage.panning { cursor: grabbing; }
.lightbox-canvas { position: relative; overflow: hidden; min-width: 100%; min-height: 100%; }
.lightbox-canvas > :is(img, video) {
  position: absolute; inset: 50% auto auto 50%; max-width: none; max-height: none;
  object-fit: contain; user-select: none; -webkit-user-select: none;
}
.lightbox-footer { justify-content: center; flex-wrap: wrap; }
.lightbox-tools { flex-wrap: wrap; justify-content: center; }
.lightbox-tools .btn { min-width: 36px; }
.lightbox-zoom-level { min-width: 4.5ch; text-align: center; font-variant-numeric: tabular-nums; }
.lightbox-status { color: #d1c6d9; font-size: 13px; }
.lightbox-status:empty { display: none; }
.lightbox-playback { justify-self: stretch; }
.lightbox-playback input { flex: 1; min-width: 0; accent-color: #e3bae4; }
.lightbox .lightbox-close { padding: 0; width: 40px; height: 40px; flex: none; font-size: 24px; line-height: 1; }
@media (max-width: 600px) {
  .lightbox {
    gap: 0; padding: 0; background: #09080b;
  }
  .lightbox-heading {
    z-index: 1; gap: 10px; padding: calc(6px + var(--safe-top)) 12px 6px;
    background: #100f15; border-bottom: 1px solid #302936;
  }
  .lightbox-heading > span { font-size: 14px; }
  .lightbox-stage { border: 0; border-radius: 0; }
  .lightbox-footer, .lightbox-playback {
    background: #100f15; border-top: 1px solid #302936;
  }
  .lightbox-footer { gap: 6px; padding: 8px 10px calc(8px + var(--safe-bottom)); }
  .lightbox-tools { gap: 5px; }
  .lightbox .btn { min-height: 44px; font-size: 14px; border-radius: 10px; }
  .lightbox .lightbox-close { width: 44px; min-width: 44px; font-size: 24px; }
  .lightbox-tools .btn { min-width: 40px; }
  .lightbox-zoom-level { font-size: 13px; }
  .lightbox-playback { padding: 5px 10px; }
  .lightbox-status { text-align: center; }
}


.drop-overlay {
  position: absolute; inset: 0; z-index: 15; background: rgba(19, 26, 42, .85); display: grid; place-items: center;
  pointer-events: none;
}
.drop-overlay > div {
  border: 2px dashed var(--accent); border-radius: 16px; padding: 40px 56px; text-align: center;
  background: var(--accent); color: var(--on-accent); box-shadow: 0 8px 32px rgba(0,0,0,.4);
}
.drop-overlay b { display: block; font-size: 20px; }
.drop-overlay span { opacity: .85; }
.chat { position: relative; }

.gif-picker {
  position: absolute; right: 16px; bottom: calc(100% - 12px); z-index: 25;
  width: 420px; height: 460px; max-height: calc(60vh / var(--ui-zoom, 1)); display: flex; flex-direction: column;
  background: var(--bg-side); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.45); overflow: hidden;
}
.gif-head { display: flex; gap: 8px; align-items: center; padding: 12px; }
.gif-head input { margin: 0; background: var(--bg-rail); }
.gif-grid { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0 8px 8px; }
.gif-cols { display: flex; gap: 6px; align-items: flex-start; }
.gif-col { flex: 1; min-width: 0; }
.gif-grid button {
  display: block; width: 100%; margin: 0 0 6px; padding: 0; border: 0; border-radius: 6px; overflow: hidden;
  background: var(--bg-rail); position: relative;
}
.gif-grid button:hover, .gif-grid button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.gif-grid img { display: block; width: 100%; height: auto; }
.gif-foot { padding: 6px 12px; font-size: 11px; color: var(--muted); text-align: right; border-top: 1px solid var(--bg-rail); }
.gif-empty { padding: 24px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.gif-empty .btn { margin-top: 12px; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 65; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 520px; background: var(--bg-side); border-radius: 14px 14px 0 0;
  padding: 8px 8px calc(12px + var(--safe-bottom)); animation: sheet-up .18s ease-out;
}
.sheet::before { content: ""; display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 4px auto 10px; }
#sheet-body, #sheet-body * {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.sheet .preview { padding: 4px 12px 10px; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet button {
  display: flex; align-items: center; gap: 14px; width: 100%; border: 0; background: none; color: var(--text);
  padding: 14px 12px; border-radius: 8px; font-size: 16px; text-align: left;
}
.sheet button:active, .sheet button:hover { background: var(--bg-hover); }
.sheet button svg { width: 22px; height: 22px; color: var(--icon-muted); }
.sheet button.danger, .sheet button.danger svg { color: var(--red); }
@keyframes sheet-up { from { transform: translateY(100%); } }

.msg.reply-swiping { transform: translateX(var(--reply-drag, 0px)); }
.msg.reply-swiping::after {
  content: "\21A9"; position: absolute; top: 50%; left: -34px; transform: translateY(-50%);
  width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%;
  color: var(--muted); background: var(--bg-side); pointer-events: none;
}
.msg.reply-swipe-ready::after { color: var(--accent-text); background: var(--accent-soft); }
#messages .msg.touch-long-press, #messages .msg.touch-long-press * {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
@media (hover: none), (pointer: coarse) {
  #messages .msg, #messages .msg * {
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  }
}
@media (hover: none) {
  .msg:hover .msg-actions { display: none; }
  .msg:hover { background: none; }
  .msg.pressed { background: var(--bg-msg-hover); }
  .icon-btn { width: 40px; height: 40px; }
  .composer { gap: 4px; }
  .composer .attach, .composer .send { width: 40px; height: 40px; margin: 2px 0; }
  input { font-size: 16px; }
  .channel { min-height: 42px; }
  .sheet-backdrop .sheet { max-width: none; }
}

@media (max-width: 820px) {
  .gif-picker {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; height: min(calc(70vh / var(--ui-zoom, 1)), 560px); max-height: none;
    border-radius: 14px 14px 0 0; padding-bottom: var(--safe-bottom); z-index: 40;
  }
  .gif-picker::before { content: ""; display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 8px auto 0; flex: none; }
  .modal-backdrop { align-items: end; padding: 0; }
  .modal { max-width: none; border-radius: 14px 14px 0 0; max-height: calc(92vh / var(--ui-zoom, 1)); padding: 20px 16px calc(20px + var(--safe-bottom)); }
  .modal .field-row { flex-wrap: wrap; }
  .modal .field-row .btn { width: 100%; }
  .composer textarea, .composer-mention-mirror { font-size: 16px; }
  .security-banner { padding: 8px 12px; }
}

.emoji-grid button, .emoji-tabs button, .quick-reactions button {
  font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", "Twemoji Mozilla", var(--font);
}
.reaction .r-key { font-family: var(--font), "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji"; }
.composer .emoji-btn { margin: 6px 0; color: var(--icon-muted); }
.composer .emoji-btn svg { width: 22px; height: 22px; }
.composer .emoji-btn.active { color: #f0b232; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 8px; border-radius: 8px;
  border: 1px solid transparent; background: var(--bg-side); color: var(--text); font-size: 14px; line-height: 1;
}
.reaction:hover:not(:disabled) { border-color: var(--border-strong); }
.reaction.mine { background: var(--accent-soft); border-color: var(--accent); }
.reaction .r-count { font-size: 13px; font-weight: 600; color: var(--muted); }
.reaction.mine .r-count { color: var(--accent-text); }
.reaction:disabled { cursor: default; }
.reaction.add { color: var(--muted); padding: 0 6px; visibility: hidden; }
.reaction.add svg { width: 16px; height: 16px; }
.msg:hover .reaction.add, .reaction.add:focus-visible { visibility: visible; }
.emoji-picker { width: 380px; height: 420px; }
.emoji-tabs { display: flex; gap: 2px; padding: 0 8px 6px; overflow-x: auto; flex: none; scrollbar-width: none; }
.emoji-tabs button {
  flex: none; width: 34px; height: 30px; border: 0; border-radius: 6px; background: none; font-size: 18px; opacity: .55;
}
.emoji-tabs button.active, .emoji-tabs button:hover { opacity: 1; background: var(--bg-hover); }
.emoji-grid {
  flex: 1; overflow-y: auto; padding: 4px 8px 8px; display: grid; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 2px;
}
.emoji-grid button { height: 38px; border: 0; border-radius: 6px; background: none; font-size: 24px; padding: 0; line-height: 1; }
.emoji-grid button:hover, .emoji-grid button:focus-visible { background: var(--bg-hover); outline: none; }
.emoji-grid .gif-empty { grid-column: 1 / -1; }
.quick-reactions { display: flex; justify-content: space-between; gap: 4px; padding: 4px 8px 10px; }
.quick-reactions button {
  flex: 1; height: 46px; border: 0; border-radius: 23px; background: var(--bg-input); font-size: 24px; padding: 0;
  display: grid; place-items: center;
}
.quick-reactions .more { color: var(--muted); }
.quick-reactions .more svg { width: 22px; height: 22px; }
@media (hover: none) {
  .reaction.add { visibility: visible; }
  .composer .emoji-btn { width: 40px; height: 40px; margin: 2px 0; }
}
@media (max-width: 820px) {
  .emoji-picker { width: auto; height: min(calc(60vh / var(--ui-zoom, 1)), 460px); }
}

.msg .author { cursor: pointer; }
.msg .author:hover { text-decoration: underline; }
.member.invited .mname { font-style: italic; }
.member.banned { opacity: .6; }
.member.banned .mname { text-decoration: line-through; }
.banned-title { color: var(--red); }
.profile-head { display: flex; gap: 12px; align-items: center; min-width: 0; }
.profile-head .profile-avatar {
  display: grid; place-items: center; width: 64px; height: 64px;
  font-size: 26px; flex: none; border: 3px solid var(--bg-side);
}
.profile-who { min-width: 0; }
.modal .profile-name { margin: 0; text-align: left; line-height: 1.15; overflow-wrap: anywhere; }
.profile-id { margin-top: 4px; font-family: var(--mono); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; }
.profile-role {
  display: inline-flex; align-items: center; gap: 5px; min-width: 0; margin-top: 7px;
  padding: 3px 7px; border-radius: 7px; background: var(--accent-soft); color: var(--accent-text);
  font-size: 12px; font-weight: 600; overflow-wrap: anywhere;
}
.profile-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.profile-actions .btn { padding: 6px 12px; font-size: 13px; }
.power-form { margin-top: 4px; }
.mono { font-family: var(--mono); font-size: 12px; }

:root[data-theme="rose"] {
  --bg-rail: #1d1116;
  --bg-side: #2a1a21;
  --bg-chat: #34202a;
  --bg-input: #412a36;
  --bg-float: #150d12;
  --bg-hover: rgba(225, 120, 160, 0.14);
  --bg-active: rgba(225, 120, 160, 0.28);
  --bg-msg-hover: rgba(0, 0, 0, 0.16);
  --text: #eed9e0;
  --text-strong: #fcf0f5;
  --muted: #bd97a8;
  --faint: #8d6b7d;
  --accent: #e0559a;
  --on-accent: #200b17;
  --accent-hover: #c74484;
  --link: #ff8fc0;
  --panel: #211419;
  --bg-elevated: #2a1a21;
  --border-soft: #4a2e3d;
  --border-strong: #634050;
  --border-focus: #7a4f63;
  --icon-muted: #c2a3b2;
  --accent-soft: rgba(224, 85, 154, 0.16);
  --accent-text: #f5a8c6;
}

:root[data-theme="pitch"] {
  --bg-rail: #000000;
  --bg-side: #0b0b0b;
  --bg-chat: #000000;
  --bg-input: #141414;
  --bg-float: #000000;
  --bg-hover: rgba(255, 255, 255, 0.08);
  --bg-active: rgba(255, 255, 255, 0.16);
  --bg-msg-hover: rgba(255, 255, 255, 0.05);
  --text: #e8e8e8;
  --text-strong: #f5f5f5;
  --muted: #9a9a9a;
  --faint: #6a6a6a;
  --accent-soft: rgba(108, 94, 245, 0.25);
  --accent-text: #bcbcf0;
  --panel: #0d0d0d;
  --bg-elevated: #0b0b0b;
  --border-soft: #262626;
  --border-strong: #333333;
  --border-focus: #404040;
  --icon-muted: #a0a0a0;
}

:root[data-theme="mocha"] {
  --bg-rail: #11111b;
  --bg-side: #181825;
  --bg-chat: #1e1e2e;
  --bg-input: #313244;
  --bg-float: #11111b;
  --bg-hover: rgba(205, 214, 244, 0.1);
  --bg-active: rgba(205, 214, 244, 0.2);
  --bg-msg-hover: rgba(0, 0, 0, 0.18);
  --text: #cdd6f4;
  --text-strong: #e6e9f5;
  --muted: #a6adc8;
  --faint: #7f849c;
  --accent: #cba6f7;
  --on-accent: #21152f;
  --accent-hover: #b195dd;
  --green: #a6e3a1;
  --red: #f38ba8;
  --link: #89b4fa;
  --panel: #181825;
  --bg-elevated: #181825;
  --border-soft: #45475a;
  --border-strong: #585b70;
  --border-focus: #6c7086;
  --icon-muted: #a6adc8;
  --accent-soft: rgba(203, 166, 247, 0.14);
  --accent-text: #cba6f7;
}

:root[data-theme="slate"] {
  --bg-rail: #15181e;
  --bg-side: #1a1f27;
  --bg-chat: #21262e;
  --bg-input: #292f39;
  --bg-float: #15181e;
  --bg-hover: rgba(158, 179, 216, .12);
  --bg-active: rgba(158, 179, 216, .2);
  --text: #dbe2ed;
  --text-strong: #f2f5fa;
  --muted: #abb7c9;
  --faint: #93a0b4;
  --accent: #8ea8d8;
  --accent-hover: #a6bce3;
  --on-accent: #152039;
  --green: #86cf9f;
  --red: #f397a1;
  --link: #a8c5fb;
  --panel: #1a1f27;
  --bg-elevated: #252b35;
  --border-soft: #3b4452;
  --border-strong: #4b5768;
  --border-focus: #6a7c97;
  --icon-muted: #abb7c9;
  --accent-soft: rgba(142, 168, 216, .15);
  --accent-text: #b5ccf4;
}

:root[data-theme="ocean"] {
  --bg-rail: #0b1c27;
  --bg-side: #102633;
  --bg-chat: #142e3c;
  --bg-input: #1b3949;
  --bg-float: #0b1c27;
  --bg-hover: rgba(114, 209, 237, .1);
  --bg-active: rgba(114, 209, 237, .18);
  --text: #d4e8ef;
  --text-strong: #effaff;
  --muted: #a3c2ce;
  --faint: #8cafbd;
  --accent: #72d1ed;
  --accent-hover: #9fe2f4;
  --on-accent: #082733;
  --green: #85dfb2;
  --red: #f398a4;
  --link: #8cdaf1;
  --panel: #102633;
  --bg-elevated: #183343;
  --border-soft: #315363;
  --border-strong: #416779;
  --border-focus: #53869a;
  --icon-muted: #a3c2ce;
  --accent-soft: rgba(114, 209, 237, .14);
  --accent-text: #a4e8f6;
}

:root[data-theme="forest"] {
  --bg-rail: #14201b;
  --bg-side: #1a2b23;
  --bg-chat: #23382e;
  --bg-input: #2b4236;
  --bg-float: #14201b;
  --bg-hover: rgba(139, 209, 162, .12);
  --bg-active: rgba(139, 209, 162, .2);
  --text: #ddebe1;
  --text-strong: #f0faf2;
  --muted: #adc7b5;
  --faint: #9bb5a3;
  --accent: #8bd1a2;
  --accent-hover: #a8dfb9;
  --on-accent: #142c1e;
  --green: #8bd1a2;
  --red: #f3a2ab;
  --link: #a4e3c0;
  --panel: #1a2b23;
  --bg-elevated: #294034;
  --border-soft: #425e4e;
  --border-strong: #537261;
  --border-focus: #6e917a;
  --icon-muted: #adc7b5;
  --accent-soft: rgba(139, 209, 162, .14);
  --accent-text: #b0e7be;
}

:root[data-theme="daylight"] {
  color-scheme: light;
  --bg-rail: #e5eaf3;
  --bg-side: #f3f6fb;
  --bg-chat: #ffffff;
  --bg-input: #f6f8fc;
  --bg-float: #ffffff;
  --bg-hover: rgba(56, 91, 181, .08);
  --bg-active: rgba(56, 91, 181, .14);
  --bg-msg-hover: rgba(56, 91, 181, .04);
  --border: #d3dcec;
  --text: #29364b;
  --text-strong: #18243b;
  --muted: #4e5e77;
  --faint: #5b6a83;
  --accent: #385bb5;
  --accent-hover: #2d4893;
  --green: #177048;
  --red: #b32744;
  --link: #254d9e;
  --panel: #f3f6fb;
  --bg-elevated: #ffffff;
  --border-soft: #d2dbea;
  --border-strong: #acbad0;
  --border-focus: #768cb3;
  --icon-muted: #4e6080;
  --accent-soft: #e9effc;
  --accent-text: #2c4e9b;
  --badge-text: #fff;
  --danger-text: #a6263c;
}

.user-profile-button {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;
  border: 0; border-radius: 8px; padding: 3px; background: none; text-align: left;
}
.user-profile-button:hover { background: var(--bg-hover); }
.user-profile-button .avatar, .user-panel > .icon-btn { flex: none; }

.profile-banner {
  position: relative; display: grid; place-items: center; aspect-ratio: 3 / 1; overflow: hidden;
  border: 1px solid var(--border-soft); border-radius: var(--radius);
  background: linear-gradient(125deg, var(--accent-soft), var(--bg-side));
  color: var(--muted); font-size: 13px;
}
.profile-banner img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.profile-card {
  overflow: hidden; border: 1px solid var(--border-soft);
  border-radius: 14px; background: var(--bg-side);
}
.profile-card .profile-cover {
  width: 100%; height: clamp(120px, 24vw, 188px); aspect-ratio: auto;
  border: 0; border-bottom: 1px solid var(--border-soft);
  border-radius: 0; background: linear-gradient(122deg, var(--bg-input), var(--accent-soft) 63%, var(--bg-chat));
}
.profile-card-content { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 16px; }
.modal:has(.profile-dialog) { max-width: 820px; padding: 0; overflow: hidden; }
.profile-dialog {
  display: grid; grid-template-rows: minmax(0, 1fr) auto;
  max-height: calc(100vh / var(--ui-zoom, 1) - 32px);
  max-height: calc(100dvh / var(--ui-zoom, 1) - 32px);
}
.profile-scroll {
  min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-gutter: stable; padding: 20px;
}
.profile-scroll:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.profile-footer {
  display: flex; justify-content: flex-end; padding: 10px 20px;
  border-top: 1px solid var(--border-soft); background: var(--bg-chat);
}
@media (max-width: 820px) {
  .profile-dialog { max-height: calc(92vh / var(--ui-zoom, 1)); max-height: calc(92dvh / var(--ui-zoom, 1)); }
  .profile-scroll { padding: 12px; }
  .profile-footer { padding: 8px 12px calc(8px + var(--safe-bottom)); }
}
.profile-cover + .profile-card-content .profile-head > :is(.profile-avatar, .presence-avatar) { margin-top: -30px; position: relative; }
.profile-details {
  border-top: 1px solid var(--border-soft); padding-top: 12px;
}
.profile-moderation {
  margin-top: 12px; padding: 10px 12px; border: 1px solid var(--border-soft);
  border-radius: var(--radius); background: var(--bg-side);
}
.profile-moderation summary { color: var(--text-strong); font-weight: 600; cursor: pointer; }
.profile-moderation summary:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.profile-moderation .profile-actions { margin-top: 12px; }
.profile-details h3, .profile-editor h3 {
  color: var(--text-strong); margin: 0 0 6px; font-size: 14px;
}
.profile-bio { margin: 0; color: var(--text); font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.profile-editor { display: grid; gap: 16px; padding-top: 4px; }
.profile-bio-form label { margin-top: 0; }
.profile-bio-form textarea {
  display: block; resize: vertical; width: 100%; min-height: 96px; margin-top: 6px; padding: 9px 11px;
  background: var(--bg-side); border: 1px solid var(--border-soft); border-radius: var(--radius);
}
.profile-bio-form textarea:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.profile-edit-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.profile-edit-actions small { margin: 0 auto 0 0; }
.profile-status { margin: 6px 0 0; font-size: 13px; }
.profile-status:empty { display: none; }
.profile-pronouns { margin-bottom: 12px; }
.profile-pronouns ul {
  display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 5px 0 0; padding: 0;
}
.profile-pronouns li {
  min-width: 0; padding: 3px 8px; border-radius: 8px; background: var(--accent-soft);
  color: var(--text-strong); overflow-wrap: anywhere; font-size: 13px;
}
.pronoun-row {
  display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto;
  align-items: end; gap: 8px; margin: 8px 0;
}
.pronoun-row label { margin: 0; }
.pronoun-row input { margin-top: 4px; }
@media (max-width: 480px) {
  .pronoun-row { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
  .pronoun-row button { grid-column: 1 / -1; justify-self: end; }
}
.settings-tabs {
  display: flex; flex-wrap: wrap; gap: 4px; margin: 14px 0 12px; padding: 4px;
  border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--bg-side);
}
.settings-tabs button {
  flex: 1 0 auto; max-width: 100%; min-height: 36px; padding: 5px 9px;
  border: 1px solid transparent; border-radius: 7px; background: transparent;
  color: var(--muted); font-size: 13px; font-weight: 600;
}
.settings-tabs button:hover { background: var(--bg-hover); color: var(--text-strong); }
.settings-tabs button[aria-pressed="true"] {
  border-color: var(--border-soft); background: var(--accent-soft); color: var(--text-strong);
}
.settings-tabs button:focus-visible { outline-offset: -2px; }
.privacy-section { padding: 12px 0; }
.privacy-section + .privacy-section { border-top: 1px solid var(--border-soft); }
.privacy-section h3 { margin: 0 0 6px; font-size: 15px; }
.privacy-block-form { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; }
.privacy-block-form label { flex: 1 1 190px; min-width: 0; margin: 0; }
.privacy-user-list { margin: 10px 0 0; padding: 0; list-style: none; }
.privacy-user-list, .receipt-readers {
  max-height: min(calc(36vh / var(--ui-zoom, 1)), 280px);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  scrollbar-gutter: stable;
}
.privacy-user-list:focus-visible, .receipt-readers:focus-visible { outline-offset: -2px; }
.privacy-user-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  min-width: 0; padding: 7px 0; border-bottom: 1px solid var(--border-soft);
}
.privacy-user-list li > span { min-width: 0; overflow-wrap: anywhere; }
.privacy-user-list small { display: block; margin: 3px 0 0; }
.developer-diagnostics {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 7px 16px; margin: 0 0 12px;
}
.developer-diagnostics dt { color: var(--muted); }
.developer-diagnostics dd { margin: 0; overflow-wrap: anywhere; user-select: text; }
.developer-access { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border-soft); }
.developer-access h3 { margin: 0; font-size: 14px; }
.developer-access [role="status"]:empty { display: none; }
.developer-token {
  display: block; margin-top: 8px; padding: 10px; border-radius: 6px; background: var(--bg-side);
  overflow-wrap: anywhere; user-select: text; -webkit-user-select: text;
}

.room-details {
  display: grid; gap: 9px; margin-bottom: 14px; padding: 14px;
  border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--bg-side);
}
.room-details h3 { margin: 0; color: var(--text-strong); font-size: 14px; }
.room-edit-form label { margin: 0; }
.room-edit-form input, .room-edit-form textarea {
  display: block; width: 100%; margin-top: 5px; padding: 8px 10px; border: 1px solid var(--border-soft);
  border-radius: 7px; background: var(--bg-chat); text-transform: none;
}
.room-edit-form textarea {
  min-height: 88px; max-height: calc(50vh / var(--ui-zoom, 1));
  resize: vertical; overflow-x: hidden; overflow-wrap: anywhere;
}
.room-edit-form textarea:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.room-edit-form [readonly] { color: var(--muted); }
.room-edit-actions {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 6px; margin-top: 6px;
}
.room-edit-actions .btn { margin-left: auto; }
.room-edit-status { margin: 0; font-size: 12px; min-height: 0; }
.room-edit-status:empty { display: none; }
.room-edit-avatar {
  display: flex; gap: 12px; align-items: flex-start; margin-top: 3px; padding-top: 12px;
  border-top: 1px solid var(--border-soft);
}
.room-avatar-preview .avatar { width: 44px; height: 44px; font-size: 17px; }
.room-avatar-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.room-edit-actions .btn, .room-avatar-actions .btn { padding: 6px 9px; font-size: 13px; }
@media (max-width: 360px) {
  .profile-card-content { padding-inline: 12px; }
  .profile-head .profile-avatar { width: 52px; height: 52px; font-size: 21px; }
}

:root[data-theme="aubergine"] {
  --bg-rail: #1a1422;
  --bg-side: #241c2e;
  --bg-chat: #2b2235;
  --bg-input: #372b43;
  --bg-float: #1a1422;
  --bg-hover: rgba(204, 155, 234, .12);
  --bg-active: rgba(204, 155, 234, .22);
  --text: #e8dcef;
  --text-strong: #fbf1ff;
  --muted: #bfb0cc;
  --faint: #aa98b9;
  --accent: #cc9bea;
  --accent-hover: #ddbaef;
  --on-accent: #2b1638;
  --accent-soft: rgba(204, 155, 234, .16);
  --accent-text: #e2bafa;
  --green: #94d8ae;
  --red: #f5a1bc;
  --link: #d6bbfa;
  --panel: #241c2e;
  --bg-elevated: #30263b;
  --border-soft: #52435f;
  --border-strong: #665475;
  --border-focus: #8c70a0;
  --icon-muted: #c9b7d5;
}

:root[data-theme="ember"] {
  --bg-rail: #211813;
  --bg-side: #2b211a;
  --bg-chat: #352820;
  --bg-input: #403127;
  --bg-float: #211813;
  --bg-hover: rgba(237, 171, 118, .12);
  --bg-active: rgba(237, 171, 118, .22);
  --text: #f2e1d4;
  --text-strong: #fff5ed;
  --muted: #ccad97;
  --faint: #b39885;
  --accent: #edab76;
  --accent-hover: #f5c19a;
  --on-accent: #341d0e;
  --accent-soft: rgba(237, 171, 118, .16);
  --accent-text: #f7c49d;
  --green: #a3d19c;
  --red: #ffaaa2;
  --link: #ffd29e;
  --panel: #2b211a;
  --bg-elevated: #382b23;
  --border-soft: #624b3b;
  --border-strong: #785d48;
  --border-focus: #9f785a;
  --icon-muted: #d6b6a0;
}

:root[data-theme="paper"] {
  color-scheme: light;
  --bg-rail: #eee6d8;
  --bg-side: #f6f0e6;
  --bg-chat: #fffdf7;
  --bg-input: #faf5ea;
  --bg-float: #fffdf7;
  --bg-hover: rgba(128, 80, 30, .08);
  --bg-active: rgba(128, 80, 30, .14);
  --bg-msg-hover: rgba(128, 80, 30, .05);
  --border: #e0d5c4;
  --text: #3c3026;
  --text-strong: #332518;
  --muted: #685747;
  --faint: #746454;
  --accent: #80501e;
  --accent-hover: #694017;
  --accent-soft: #f1e4d4;
  --accent-text: #744517;
  --green: #33623d;
  --red: #a82c3c;
  --link: #75430d;
  --panel: #f6f0e6;
  --bg-elevated: #fffdf7;
  --border-soft: #d9cebd;
  --border-strong: #bcac95;
  --border-focus: #937d5f;
  --icon-muted: #695644;
  --badge-text: #fff;
  --danger-text: #a52b3e;
}

:root[data-theme="glacier"] {
  color-scheme: light;
  --bg-rail: #e1eeee;
  --bg-side: #edf6f6;
  --bg-chat: #f7fcfd;
  --bg-input: #eef7f8;
  --bg-float: #fcfefe;
  --bg-hover: rgba(23, 102, 109, .08);
  --bg-active: rgba(23, 102, 109, .15);
  --bg-msg-hover: rgba(23, 102, 109, .05);
  --border: #ccdfe1;
  --text: #203a40;
  --text-strong: #142f35;
  --muted: #426367;
  --faint: #506e73;
  --accent: #17666d;
  --accent-hover: #10545b;
  --accent-soft: #daeeee;
  --accent-text: #15595f;
  --green: #236448;
  --red: #a92f47;
  --link: #125d67;
  --panel: #edf6f6;
  --bg-elevated: #f7fcfd;
  --border-soft: #c6dddf;
  --border-strong: #9fbec1;
  --border-focus: #648f93;
  --icon-muted: #3e6266;
  --badge-text: #fff;
  --danger-text: #a32842;
}

:root[data-theme="graphite-mint"] {
  color-scheme: dark;
  --bg-rail: #131816;
  --bg-side: #1a221e;
  --bg-chat: #222b27;
  --bg-input: #29362f;
  --bg-float: #171e1a;
  --bg-hover: rgba(113, 220, 170, .11);
  --bg-active: rgba(113, 220, 170, .19);
  --bg-msg-hover: rgba(113, 220, 170, .07);
  --border: #3d5147;
  --text: #dce8e1;
  --text-strong: #effbf3;
  --muted: #a8beb2;
  --faint: #91a69b;
  --accent: #348263;
  --accent-hover: #286e53;
  --accent-text: #b1f5d3;
  --accent-soft: rgba(113, 220, 170, .16);
  --green: #58c78d;
  --red: #ef6b88;
  --link: #86e3ba;
  --panel: #1a221e;
  --bg-elevated: #222b27;
  --border-soft: #3d5147;
  --border-strong: #526b5d;
  --border-focus: #6d9983;
  --icon-muted: #a7beb1;
  --badge-text: #161018;
  --danger-text: #ff9caf;
}

:root[data-theme="afterglow"] {
  color-scheme: dark;
  --bg-rail: #19131b;
  --bg-side: #221923;
  --bg-chat: #2a202a;
  --bg-input: #352631;
  --bg-float: #1d151d;
  --bg-hover: rgba(255, 160, 117, .11);
  --bg-active: rgba(255, 160, 117, .19);
  --bg-msg-hover: rgba(255, 160, 117, .07);
  --border: #513b48;
  --text: #eedde5;
  --text-strong: #fff1f6;
  --muted: #c7abb9;
  --faint: #b199a7;
  --accent: #b4593f;
  --accent-hover: #994932;
  --accent-text: #ffd1ba;
  --accent-soft: rgba(255, 160, 117, .16);
  --green: #58c78d;
  --red: #ef6b88;
  --link: #ffba98;
  --panel: #221923;
  --bg-elevated: #2a202a;
  --border-soft: #513b48;
  --border-strong: #705362;
  --border-focus: #ad7a73;
  --icon-muted: #d6b4c1;
  --badge-text: #161018;
  --danger-text: #ffabb8;
}

:root[data-theme="blue-hour"] {
  color-scheme: dark;
  --bg-rail: #101826;
  --bg-side: #152137;
  --bg-chat: #1b2940;
  --bg-input: #253551;
  --bg-float: #101a2c;
  --bg-hover: rgba(144, 168, 255, .11);
  --bg-active: rgba(144, 168, 255, .19);
  --bg-msg-hover: rgba(144, 168, 255, .07);
  --border: #374a70;
  --text: #dde6ff;
  --text-strong: #f2f5ff;
  --muted: #aebcde;
  --faint: #98a9d0;
  --accent: #586fc8;
  --accent-hover: #475db1;
  --accent-text: #c3ceff;
  --accent-soft: rgba(144, 168, 255, .16);
  --green: #58c78d;
  --red: #ef6b88;
  --link: #adc6ff;
  --panel: #152137;
  --bg-elevated: #1b2940;
  --border-soft: #374a70;
  --border-strong: #51648b;
  --border-focus: #758cc8;
  --icon-muted: #b7c4e6;
  --badge-text: #161018;
  --danger-text: #ffa6bc;
}

:root[data-theme="porcelain"] {
  color-scheme: light;
  --bg-rail: #ebe7f3;
  --bg-side: #f3eff9;
  --bg-chat: #fcfaff;
  --bg-input: #f4effb;
  --bg-float: #ffffff;
  --bg-hover: rgba(102, 68, 160, .08);
  --bg-active: rgba(102, 68, 160, .15);
  --bg-msg-hover: rgba(102, 68, 160, .05);
  --border: #dcd2ea;
  --text: #342949;
  --text-strong: #251b39;
  --muted: #615477;
  --faint: #6b5d80;
  --accent: #6644a0;
  --accent-hover: #553688;
  --accent-text: #5b3b90;
  --accent-soft: rgba(102, 68, 160, .16);
  --green: #26764a;
  --red: #a62c49;
  --link: #5e40a0;
  --panel: #f3eff9;
  --bg-elevated: #fcfaff;
  --border-soft: #dcd2ea;
  --border-strong: #c4b6da;
  --border-focus: #947db4;
  --icon-muted: #645476;
  --badge-text: #fff;
  --danger-text: #a02551;
}

:root[data-theme="matcha"] {
  color-scheme: light;
  --bg-rail: #e3eadb;
  --bg-side: #eef2e7;
  --bg-chat: #fbfcf7;
  --bg-input: #eef3e8;
  --bg-float: #ffffff;
  --bg-hover: rgba(66, 109, 70, .08);
  --bg-active: rgba(66, 109, 70, .15);
  --bg-msg-hover: rgba(66, 109, 70, .05);
  --border: #d0ddcb;
  --text: #293c2c;
  --text-strong: #1c3021;
  --muted: #506553;
  --faint: #576b59;
  --accent: #426d46;
  --accent-hover: #335938;
  --accent-text: #375f3c;
  --accent-soft: rgba(66, 109, 70, .16);
  --green: #26764a;
  --red: #a62c49;
  --link: #2c644a;
  --panel: #eef2e7;
  --bg-elevated: #fbfcf7;
  --border-soft: #d0ddcb;
  --border-strong: #b0c6a8;
  --border-focus: #738e72;
  --icon-muted: #526951;
  --badge-text: #fff;
  --danger-text: #9e3045;
}

:root[data-theme="blush"] {
  color-scheme: dark;
  --bg-rail: #351023;
  --bg-side: #4a1534;
  --bg-chat: #42132e;
  --bg-input: #5b2043;
  --bg-float: #3b1129;
  --bg-hover: rgba(247, 128, 188, .13);
  --bg-active: rgba(247, 128, 188, .23);
  --bg-msg-hover: rgba(247, 128, 188, .08);
  --border: #68304e;
  --text: #f2d6e7;
  --text-strong: #fff0f8;
  --muted: #e8adc9;
  --faint: #d292b2;
  --accent: #f780bc;
  --accent-hover: #ffa0cf;
  --accent-text: #ffb9df;
  --accent-soft: rgba(247, 128, 188, .20);
  --on-accent: #381027;
  --green: #79c9a5;
  --red: #f08fa7;
  --link: #ffabd6;
  --panel: #53183b;
  --bg-elevated: #531b3d;
  --border-soft: #793b61;
  --border-strong: #995479;
  --border-focus: #d982af;
  --icon-muted: #ecaed0;
  --badge-text: #321923;
  --danger-text: #ffabc0;
}
:root[data-theme="blush"] .composer .send:not(:disabled) { color: var(--accent-text); }

.media-image-preview.media-placeholder { aspect-ratio: auto !important; min-height: 80px; display: grid; place-items: center; }
.media-unavailable { display: grid; justify-items: center; gap: 7px; width: 100%; padding: 12px; font-size: 13px; }
.media-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.media-actions .btn { padding: 5px 9px; font-size: 12px; }

.markdown-content p { margin: 0 0 0.55em; }
.markdown-content > :first-child { margin-top: 0; }
.markdown-content > :last-child { margin-bottom: 0; }
.markdown-content :is(h1, h2, h3, h4, h5, h6) {
  margin: 0.7em 0 0.25em; color: var(--text-strong); text-align: left;
}
.markdown-content :is(h1, h2) { font-size: 1.14em; }
.markdown-content :is(h3, h4, h5, h6) { font-size: 1em; }
.markdown-content :is(ul, ol) { margin: 0 0 0.55em; padding-inline-start: 1.4em; }
.markdown-content blockquote {
  margin: 0.45em 0; padding-inline-start: 0.75em;
  border-inline-start: 3px solid var(--border-strong); color: var(--muted);
}
.markdown-content blockquote > :last-child { margin-bottom: 0; }
.markdown-content :is(pre, table) { max-width: 100%; overflow: auto; }
.markdown-content table { display: block; border-collapse: collapse; margin: 0.4em 0; }
.markdown-content :is(th, td) { border: 1px solid var(--border-soft); padding: 4px 7px; }
.markdown-content hr { border: 0; border-top: 1px solid var(--border-soft); }
.markdown-content a { color: var(--link); }
.profile-bio code { font-family: var(--mono); background: var(--bg-chat); }
.profile-bio pre { background: var(--bg-chat); border-radius: 6px; padding: 8px; }
.markdown-plain { white-space: pre-wrap; }

.msg:focus-within .msg-actions { display: flex; }
.msg.has-touch-actions:focus-within { min-height: 36px; padding-inline-end: 46px; background: var(--bg-msg-hover); }
.msg.has-touch-actions:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.msg .msg-touch-actions { display: none; position: absolute; inset-inline-end: 5px; top: 0; width: 36px; height: 36px; }
.msg.has-touch-actions:focus-within .msg-touch-actions { display: grid; }

.android-notification-settings h3 { margin: 0; color: var(--text-strong); font-size: 14px; }
.android-notification-settings .btn { margin-top: 10px; }
.android-notification-actions { justify-content: flex-start; margin-top: 0; }
.android-notification-settings [role="status"]:empty { display: none; }

.user-presence {
  display: inline-flex; align-items: center; gap: 5px; flex: none; color: var(--muted);
  font-size: 12px; line-height: 1.3;
}
.user-presence::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.user-presence[hidden], .user-presence.offline:not(.with-label) { display: none; }
.user-presence.offline::before { content: none; }
.user-presence.online::before { background: var(--green); }
.user-presence.unavailable::before { background: #bf851e; }
.user-presence.unknown::before { background: transparent; border: 1px solid var(--muted); }
.presence-avatar { position: relative; display: inline-grid; flex: none; }
.presence-avatar > .user-presence {
  position: absolute; right: 0; bottom: 0;
  border-radius: 50%; border: 2px solid var(--bg-side);
}
.profile-meta .user-presence::before { content: none; }
.profile-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-top: 7px; }
.profile-meta .profile-role { margin-top: 0; }

.read-receipt {
  display: flex; align-items: center; width: fit-content; margin-top: 4px; margin-left: auto;
  padding: 2px 4px; border: 0; border-radius: 14px;
  background: transparent; color: var(--text); cursor: pointer;
}
.read-receipt:hover, .read-receipt:focus-visible { color: var(--text-strong); background: var(--bg-hover); }
.read-receipt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.msg.system .read-receipt { flex: none; align-self: center; margin-top: 0; }
.receipt-avatar-stack { display: flex; align-items: center; }
.receipt-avatar-stack .receipt-avatar { width: 23px; height: 23px; font-size: 10px; border: 2px solid var(--bg-chat); }
.receipt-avatar-stack .receipt-avatar + .receipt-avatar { margin-left: -4px; }
.receipt-overflow {
  margin-left: 4px; padding: 2px 5px; border-radius: 8px;
  background: var(--bg-hover); font-size: 11px; font-weight: 600;
}
@media (hover: none) { .read-receipt { min-height: 32px; } }
.receipt-readers { list-style: none; margin: 12px 0 0; padding: 0; }
.receipt-readers li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--border-soft); overflow-wrap: anywhere;
}
.receipt-reader { display: flex; align-items: center; gap: 9px; min-width: 0; }
.receipt-reader .receipt-avatar { width: 30px; height: 30px; font-size: 12px; }
.receipt-readers small { display: block; color: var(--muted); }
.receipt-readers time { color: var(--muted); font-size: 12px; text-align: right; }

.app.home-view > .members, .home-view .chat-icon { display: none; }
.app:is(.home-view, .space-view) .messages {
  background: radial-gradient(ellipse 75% 360px at 50% 0, var(--accent-soft), transparent 100%), var(--bg-chat);
}
[data-home-background] .app.home-view .messages {
  background: linear-gradient(180deg, transparent 10%, rgba(0, 0, 0, .22)),
    var(--home-cover-art) center / cover no-repeat, var(--bg-chat);
}
[data-home-background] .app.home-view .home-screen {
  padding-top: clamp(76px, 16vh, 154px);
}
.home-screen {
  display: grid; gap: clamp(14px, 2.2vw, 24px);
  width: min(100%, 960px); margin-inline: auto;
  padding: clamp(10px, 3vw, 36px) clamp(12px, 3vw, 36px) 40px;
}
.space-description {
  margin: 0; padding: 2px 2px 0; color: var(--text); font-size: 15px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.home-panel {
  min-width: 0; padding: clamp(12px, 2.2vw, 22px);
  border: 1px solid var(--border-soft); border-radius: 16px;
  background: var(--bg-elevated);
}
[data-home-background] .app.home-view .home-panel {
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
}
[data-home-background] .app.home-view .home-empty {
  background: color-mix(in srgb, var(--bg-chat) 55%, transparent);
}
.home-panel-header {
  display: flex; gap: 12px; align-items: center;
  margin-bottom: 16px;
}
.home-panel-header h3 {
  margin: 0; color: var(--text-strong);
  font-size: clamp(17px, 1.8vw, 21px); font-weight: 700; letter-spacing: -.025em;
}
.home-panel-icon, .home-channel-icon {
  display: grid; place-items: center; flex: none; width: 36px; height: 36px;
  border-radius: 10px; color: var(--accent-text); background: var(--accent-soft);
}
.home-panel-icon svg, .home-channel-icon svg { width: 18px; height: 18px; }
.home-rooms { display: grid; margin: 0; padding: 0; list-style: none; }
.home-room-item { min-width: 0; }
.home-room {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 56px;
  padding: 8px 10px; border: 1px solid transparent; border-radius: 10px;
  background: transparent; color: var(--text); text-align: start;
}
.home-room:is(:hover, :focus-visible) {
  background: var(--bg-hover); border-color: var(--border-focus);
}
.home-room:focus-visible { outline-offset: -2px; }
.home-room .avatar { width: 36px; height: 36px; font-size: 14px; }
.home-room .presence-avatar > .user-presence { border-color: var(--bg-chat); }
.home-room-copy { display: grid; gap: 2px; flex: 1; min-width: 0; }
.home-room-name, .home-room-detail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-room-name { color: var(--text-strong); font-size: 14px; font-weight: 650; }
.home-room-detail { color: var(--muted); font-size: 12px; }
.home-room-chevron {
  flex: none; width: 7px; height: 7px; margin-inline: 2px;
  border: solid var(--icon-muted); border-width: 1.5px 1.5px 0 0; transform: rotate(45deg);
}
.home-room:dir(rtl) .home-room-chevron { transform: rotate(-135deg); }
.home-panel .home-room-item + .home-room-item { border-top: 1px solid var(--border-soft); }
.home-recent .home-channel-icon { background: var(--bg-chat); color: var(--icon-muted); }
.home-empty {
  margin: 0; padding: 16px; border: 1px dashed var(--border-soft); border-radius: 10px;
  background: var(--bg-chat); color: var(--muted); font-size: 13px; overflow-wrap: anywhere;
}
@media (max-width: 820px) and (min-width: 560px) {
  .app.home-view.nav-open { grid-template-columns: 60px clamp(200px, 40vw, 236px) minmax(0, 1fr); }
  .home-view.nav-open > :is(.rail, .sidebar) {
    position: relative; inset: auto; width: auto; transform: none; box-shadow: none;
  }
  .home-view.nav-open > .rail { grid-column: 1; }
  .home-view.nav-open > .sidebar { grid-column: 2; }
  .home-view.nav-open > .chat { grid-column: 3; }
  .home-view.nav-open > .backdrop { display: none; }
}
