/* ===================== Theme variables ===================== */
:root,
:root[data-theme="dark"] {
  --bg-chat: #313338;
  --bg-sidebar: #2b2d31;
  --bg-rail: #1e1f22;
  --bg-userbar: #232428;
  --bg-composer: #383a40;
  --bg-modal: #313338;
  --bg-hover: #35373c;
  --bg-active: #404249;
  --bg-input: #1e1f22;
  --text-normal: #dbdee1;
  --text-muted: #949ba4;
  --text-bright: #fff;
  --text-secondary: #b5bac1;
  --blurple: #5865f2;
  --blurple-hover: #4752c4;
  --green: #23a55a;
  --yellow: #f0b232;
  --red: #f23f43;
  --scrollbar-thumb: #1a1b1e;
}
:root[data-theme="darker"] {
  --bg-chat: #2b2d31;
  --bg-sidebar: #232428;
  --bg-rail: #1a1b1e;
  --bg-userbar: #1a1b1e;
  --bg-composer: #2b2d31;
  --bg-modal: #2b2d31;
  --bg-hover: #2f3136;
  --bg-active: #393c43;
  --bg-input: #18191c;
  --text-normal: #dbdee1;
  --text-muted: #8b8e97;
  --text-bright: #fff;
  --text-secondary: #b5bac1;
  --blurple: #5865f2;
  --blurple-hover: #4752c4;
  --green: #23a55a;
  --yellow: #f0b232;
  --red: #f23f43;
  --scrollbar-thumb: #101113;
}
:root[data-theme="midnight"] {
  --bg-chat: #1a1d26;
  --bg-sidebar: #14161d;
  --bg-rail: #0f1015;
  --bg-userbar: #0f1015;
  --bg-composer: #1f2230;
  --bg-modal: #181a22;
  --bg-hover: #232636;
  --bg-active: #2b2f42;
  --bg-input: #10121a;
  --text-normal: #d7d9e3;
  --text-muted: #8388a0;
  --text-bright: #fff;
  --text-secondary: #b0b3c5;
  --blurple: #5865f2;
  --blurple-hover: #4752c4;
  --green: #23a55a;
  --yellow: #f0b232;
  --red: #f23f43;
  --scrollbar-thumb: #0a0b10;
}
:root[data-theme="light"] {
  --bg-chat: #ffffff;
  --bg-sidebar: #f2f3f5;
  --bg-rail: #e3e5e8;
  --bg-userbar: #ebedef;
  --bg-composer: #ebedef;
  --bg-modal: #ffffff;
  --bg-hover: #e3e5e8;
  --bg-active: #d8dade;
  --bg-input: #ebedef;
  --text-normal: #313338;
  --text-muted: #5c5e66;
  --text-bright: #060607;
  --text-secondary: #4e5058;
  --blurple: #5865f2;
  --blurple-hover: #4752c4;
  --green: #23a55a;
  --yellow: #f0b232;
  --red: #f23f43;
  --scrollbar-thumb: #c7c9cd;
}

/* ===================== Reset & base ===================== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: 'gg sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background: var(--bg-chat);
  color: var(--text-normal);
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; color: inherit; }
img { -webkit-user-drag: none; }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent; }

@media (max-width: 359px) {
  html, body { overflow-x: hidden; }
}

/* ===================== Login screen ===================== */
.login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-chat);
}
.login-box {
  background: var(--bg-sidebar);
  padding: 32px;
  border-radius: 8px;
  width: 340px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.login-box h1 { font-size: 22px; margin-bottom: 8px; color: var(--text-bright); }
.login-sub { font-size: 14px; color: var(--text-secondary); margin-bottom: 20px; }
.login-box form { display: flex; flex-direction: column; gap: 12px; }
.login-box input {
  background: var(--bg-input);
  border: 1px solid var(--bg-input);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-normal);
  outline: none;
}
.login-box input:focus { border-color: var(--blurple); }
.login-box button[type="submit"] {
  background: var(--blurple);
  color: #fff;
  padding: 10px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 14px;
}
.login-box button[type="submit"]:hover { background: var(--blurple-hover); }
.login-error { color: #fa777c; font-size: 13px; margin-top: 4px; }

/* ===================== App shell ===================== */
.app {
  display: grid;
  /* v9b: 4th column is auto — exactly one right panel (members /
     search results / DM profile) occupies it; fixed 240px made wider
     panels overflow past the viewport edge. */
  grid-template-columns: 72px 240px 1fr auto;
  height: 100%;
  min-height: 0;
}

/* Rail */
.rail {
  background: var(--bg-rail);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 12px;
  min-height: 0;
  overflow: hidden;
}
.rail-servers {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
  width: 100%;
  padding-bottom: 8px;
  scrollbar-width: none;
}
.rail-servers::-webkit-scrollbar { display: none; }

.rail-server-item { position: relative; display: flex; align-items: center; width: 100%; justify-content: center; }
.rail-pill {
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 8px;
  border-radius: 0 4px 4px 0;
  background: #fff;
  transition: height 0.15s ease, opacity 0.15s ease;
  opacity: 0;
}
.rail-server-item:hover .rail-pill { opacity: 1; height: 20px; }
.rail-server-item.active .rail-pill { opacity: 1; height: 40px; }

.rail-server-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  background: var(--blurple);
  overflow: hidden;
  cursor: pointer;
  transition: border-radius 0.15s ease, background 0.15s ease;
  flex-shrink: 0;
}
.rail-server-icon img { width: 100%; height: 100%; object-fit: cover; }
.rail-server-item:hover .rail-server-icon,
.rail-server-item.active .rail-server-icon { border-radius: 16px; }

.rail-server-icon[data-tooltip] { position: relative; }
.rail-server-item .rail-tooltip {
  position: fixed;
  background: #111214;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 5px;
  white-space: nowrap;
  z-index: 400;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.rail-server-item:hover .rail-tooltip { opacity: 1; }

.rail-add-server {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-sidebar);
  color: var(--green);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin: 4px 0 12px 0;
  transition: border-radius 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.rail-add-server:hover { border-radius: 16px; background: var(--green); color: #fff; }

/* Sidebar */
.sidebar {
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}
.sidebar-header {
  height: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-weight: 700;
  color: var(--text-bright);
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-header:hover { background: var(--bg-hover); }
#sidebar-header-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-header-chevron { font-size: 12px; color: var(--text-normal); transition: transform 0.15s ease; flex-shrink: 0; }
.sidebar-header.open .sidebar-header-chevron { transform: rotate(180deg); }

/* Server dropdown */
.server-dropdown {
  position: absolute;
  top: 52px;
  left: 8px;
  right: 8px;
  background: var(--bg-modal);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 60;
  padding: 6px;
}
.server-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
}
.server-dropdown-item:hover { background: var(--blurple); color: #fff; }
.server-dropdown-icon { font-size: 13px; opacity: 0.8; }
.server-dropdown-divider { height: 1px; background: rgba(127,127,127,0.24); margin: 6px 4px; }
.server-dropdown-danger { color: #fa777c; }
.server-dropdown-danger:hover { background: var(--red); color: #fff; }

.invite-panel {
  position: absolute;
  top: 52px;
  left: 8px;
  right: 8px;
  background: var(--bg-modal);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 60;
  padding: 14px;
}
.invite-panel-label { font-size: 12px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; margin-bottom: 8px; }
.invite-panel-row { display: flex; gap: 8px; }
.invite-code-display {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--bg-input);
  border-radius: 4px;
  padding: 8px 10px;
  color: var(--text-normal);
  font-size: 14px;
}
.invite-panel-close { position: absolute; top: 8px; right: 8px; color: var(--text-muted); font-size: 13px; padding: 4px; }
.invite-panel-close:hover { color: var(--text-bright); }

.channel-groups { flex: 1; overflow-y: auto; min-height: 0; padding: 8px; }
.channel-section { margin-bottom: 16px; }
.channel-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.add-channel-btn { font-size: 16px; color: var(--text-muted); line-height: 1; padding: 2px 4px; border-radius: 4px; }
.add-channel-btn:hover { color: var(--text-normal); background: rgba(127,127,127,0.15); }
.channel-list { display: flex; flex-direction: column; gap: 2px; }

.channel-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  position: relative;
}
.channel-item:hover { background: var(--bg-hover); color: var(--text-normal); }
.channel-item.active { background: var(--bg-active); color: var(--text-bright); }
.channel-item .channel-hash { opacity: 0.7; font-weight: 600; }
.channel-item .channel-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  flex-shrink: 0;
}
.voice-channel-users {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-left: 26px;
  margin-top: 2px;
}
.voice-channel-user {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 2px 0;
}
.voice-channel-user img { width: 18px; height: 18px; border-radius: 50%; }
.voice-channel-user .live-pill { margin-left: auto; }

/* LIVE pill */
.live-pill {
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.03em;
  padding: 2px 5px;
  border-radius: 4px;
  flex-shrink: 0;
}

/* Voice connected panel */
.voice-connected-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #232428;
  padding: 8px 10px;
  margin: 0 8px 8px 8px;
  border-radius: 8px;
}
.vcb-top { display: flex; align-items: center; justify-content: space-between; }
.vcb-info { display: flex; align-items: center; gap: 8px; min-width: 0; }
.vcb-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex-shrink: 0; }
.vcb-text { min-width: 0; }
.vcb-title { font-size: 12px; font-weight: 600; color: var(--green); }
.vcb-channel { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vcb-disconnect { color: var(--text-muted); font-size: 15px; padding: 4px; border-radius: 4px; }
.vcb-disconnect:hover { color: #fff; background: var(--red); }
.vcb-controls { display: flex; gap: 6px; }
.vcb-ctrl-btn {
  flex: 1;
  background: rgba(0,0,0,0.2);
  color: var(--text-muted);
  font-size: 15px;
  padding: 6px;
  border-radius: 4px;
}
.vcb-ctrl-btn:hover { background: rgba(0,0,0,0.35); color: #fff; }
.vcb-ctrl-btn.active { background: var(--blurple); color: #fff; }

/* User bar */
.user-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  background: var(--bg-userbar);
}
.user-bar-avatar-wrap { position: relative; flex-shrink: 0; cursor: pointer; }
.user-bar-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--blurple); display: block; }
.user-bar-info { flex: 1; min-width: 0; cursor: pointer; }
.user-bar-name { font-size: 13px; font-weight: 600; color: var(--text-bright); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-bar-status { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-bar-icon-btn { font-size: 15px; color: var(--text-muted); padding: 6px; border-radius: 4px; flex-shrink: 0; }
.user-bar-icon-btn:hover { color: var(--text-normal); background: rgba(127,127,127,0.15); }
.user-bar-icon-btn.active { color: var(--red); }

/* ===================== Main ===================== */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-chat); position: relative; }
.main-header {
  height: 48px;
  min-height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
  font-weight: 700;
  color: var(--text-bright);
}
.main-header-icon { color: var(--text-muted); font-size: 20px; font-weight: 600; }
.typing-indicator { margin-left: 12px; font-size: 12px; font-weight: 400; color: var(--text-muted); font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.header-toggle-btn {
  display: none;
  font-size: 18px;
  color: var(--text-secondary);
  padding: 4px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.header-toggle-btn:hover { color: var(--text-bright); background: rgba(127,127,127,0.15); }
.members-toggle-btn { margin-left: auto; }

/* SCROLL BUG FIX: chat-pane and message-list need min-height:0 at every flex level
   so the inner overflow-y:auto can actually engage instead of the parent stretching. */
.chat-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.message-list-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.message-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
}

/* Date divider */
.date-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 8px 0;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}
.date-divider::before, .date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(127,127,127,0.24);
}

/* Message groups (contract v4 §A): ~17px between different-author groups, avatar
   40px round left, header row = name (role-colored) + tag chip + timestamp. */
.message-group { display: flex; gap: 16px; padding: 2px 8px; margin-top: 17px; border-radius: 4px; position: relative; }
.message-group:first-child { margin-top: 4px; }
.msg-avatar { width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; object-fit: cover; }
.message-group-body { flex: 1; min-width: 0; }
.message-group-header { display: flex; align-items: baseline; gap: 8px; }
.message-author { font-weight: 500; font-size: 15px; cursor: pointer; }
.message-timestamp { font-size: 11px; color: var(--text-muted); }

/* Full-row hover background (contract v4 §A: "#2e3035-ish overlay"), applied to the
   whole group OR a single grouped item so hovering anywhere on a message highlights
   its entire row, not just the group's first line. */
.message-group:hover,
.message-item:hover {
  background: rgba(46,48,53,0.6);
}

.message-item { position: relative; display: flex; flex-direction: column; gap: 2px; padding: 1px 8px 1px 0; margin-top: 2px; border-radius: 4px; }
.message-group-body > .message-item:first-child { margin-top: 0; }
.message-line { font-size: 15px; line-height: 1.375; color: var(--text-normal); white-space: pre-wrap; word-break: break-word; }
.message-line.hidden { display: none; }
.edited-tag { font-size: 10px; color: var(--text-muted); margin-left: 4px; }

/* Grouped (continued) message row shows time-on-hover to the left. The negative
   margin + matching padding lets the hover background span the FULL row width
   (contract v4 §A "full-row hover"), reaching left under where the avatar column
   would be, matching the ungrouped group's hover box. */
.message-item.grouped { margin-left: -56px; padding-left: 56px; position: relative; }
.message-item.grouped .continued-time {
  position: absolute;
  left: 0;
  top: 3px;
  width: 44px;
  text-align: right;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0;
}
.message-item.grouped:hover .continued-time { opacity: 1; }

.message-actions {
  position: absolute;
  top: -18px;
  right: 8px;
  display: none;
  background: var(--bg-sidebar);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 6px;
  overflow: visible;
  z-index: 5;
}
/* only the individually hovered message shows its action bar — a group-level
   :hover here lights up every bar in the group at once */
.message-item:hover .message-actions {
  display: flex;
}
.message-action-btn { padding: 6px 8px; font-size: 15px; color: var(--text-secondary); line-height: 1; }
.message-action-btn:hover { background: var(--bg-hover); color: var(--text-bright); }

/* Reaction chips */
.reaction-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.reaction-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(88,101,242,0.08);
  border: 1px solid rgba(127,127,127,0.2);
  border-radius: 8px;
  padding: 2px 7px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}
.reaction-chip:hover { border-color: var(--blurple); }
.reaction-chip.own {
  background: rgba(88,101,242,0.24);
  border-color: var(--blurple);
  color: #c9cdfb;
}
.reaction-chip .reaction-count { font-size: 12px; font-weight: 600; }
.reaction-chip-emoji-img { width: 16px; height: 16px; object-fit: contain; display: block; }

/* @Username mention pill (contract v5 §A, pin-messages.png). */
.mention-pill {
  background: rgba(88,101,242,.3);
  color: #c9cdfb;
  border-radius: 3px;
  padding: 0 2px;
  font-weight: 500;
}

/* Custom :name: inline emoji + stickers (contract v4 §A/§E) */
.inline-emoji { width: 24px; height: 24px; object-fit: contain; vertical-align: -6px; margin: 0 1px; }
.jumbo-emoji-line { font-size: 48px; line-height: 1; }
.inline-emoji.jumbo-emoji { width: 48px; height: 48px; vertical-align: -10px; margin: 2px; }

.sticker-el { margin-top: 4px; }
.sticker-img { width: 160px; height: 160px; object-fit: contain; display: block; }

/* Server-tag chip (contract v4 §G, server-badge.png): small rounded chip next to a
   member's name wherever they appear (messages + member list). */
.server-tag-chip {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  background: rgba(127,127,127,0.16);
  border-radius: 4px;
  padding: 1px 5px;
  line-height: 1.5;
}
.member-name-row { display: flex; align-items: center; gap: 5px; min-width: 0; }
.member-name-row .member-name { display: inline; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Role icon badge (contract v5 §F, roles.png): 16px rounded img right after the name,
   before the server-tag chip. Used in both the member list and message author rows. */
.role-icon-badge { width: 16px; height: 16px; border-radius: 4px; object-fit: cover; flex-shrink: 0; display: inline-block; align-self: center; }

/* Emoji picker popup */
.emoji-picker {
  position: fixed;
  z-index: 250;
  background: var(--bg-modal);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  padding: 8px;
}
.emoji-picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  width: 176px;
}
.emoji-picker-grid button {
  font-size: 20px;
  padding: 6px;
  border-radius: 4px;
  text-align: center;
}
.emoji-picker-grid button:hover { background: var(--bg-hover); }

/* Reply quote */
.reply-quote {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 2px;
  cursor: pointer;
  padding-left: 4px;
  border-left: 2px solid #4e5058;
}
.reply-quote:hover { color: var(--text-normal); }
.reply-quote-name { font-weight: 600; color: var(--text-secondary); }
.reply-quote:hover .reply-quote-name { color: var(--text-bright); }

/* Forwarded */
.forwarded-tag {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 2px;
}

.flash-highlight { animation: flash-bg 1.4s ease; }
@keyframes flash-bg {
  0% { background: rgba(88,101,242,0.35); }
  100% { background: transparent; }
}

/* Mark Unread "NEW" divider (contract v5 §D, Discord-style thin red line + chip). */
.mark-unread-divider {
  display: flex;
  align-items: center;
  height: 0;
  border-top: 1px solid var(--red);
  margin: 8px 8px 8px 0;
  position: relative;
}
.mark-unread-chip {
  position: absolute;
  right: 0;
  top: -8px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 1px 6px;
  border-radius: 0 0 0 4px;
}

/* Attachments — media size cap (contract v4 §A, the "too big" complaint fix):
   max-height 350px, max-width min(550px, 100%), width auto so portrait media keeps
   its natural aspect ratio (~200-260px wide for a tall image, per the reference
   screenshots) instead of being stretched to fill the cap; object-fit: contain and
   no explicit width means the browser never upscales beyond the image's natural
   size — a small source image simply renders at its native size, capped only if it
   exceeds 350x550. */
.attachment-image {
  max-height: 350px;
  max-width: min(550px, 100%);
  width: auto;
  height: auto;
  border-radius: 8px;
  margin-top: 4px;
  cursor: pointer;
  display: block;
  object-fit: contain;
}
.attachment-video {
  max-height: 350px;
  max-width: min(550px, 100%);
  width: auto;
  height: auto;
  border-radius: 8px;
  margin-top: 4px;
  display: block;
  object-fit: contain;
}

/* Attachment hover actions (contract v5 §B, video-message.png): a download button
   pinned to the top-right corner of image/video media, visible only on hover. */
.attachment-media-wrap { position: relative; display: inline-block; max-width: 100%; }
.attachment-hover-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
}
.attachment-media-wrap:hover .attachment-hover-actions {
  opacity: 1;
  pointer-events: auto;
}
.attachment-hover-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2b2d31;
  border: 1px solid #1e1f22;
  border-radius: 8px;
  color: var(--text-normal);
  font-size: 15px;
  text-decoration: none;
}
.attachment-hover-btn:hover { background: #35373c; }
.attachment-file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-sidebar);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 4px;
  max-width: 340px;
  text-decoration: none;
  color: var(--text-normal);
}
.attachment-file-card:hover { background: var(--bg-hover); }
.attachment-file-icon { font-size: 22px; }
.attachment-file-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Reply bar / attachment preview above composer */
.reply-bar, .attachment-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-sidebar);
  padding: 8px 14px;
  margin: 0 16px;
  border-radius: 8px 8px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}
.reply-bar-cancel, .attachment-preview-cancel {
  font-size: 14px;
  color: var(--text-muted);
  padding: 4px;
}
.reply-bar-cancel:hover, .attachment-preview-cancel:hover { color: var(--text-bright); }
#reply-bar-name { font-weight: 600; color: var(--text-bright); }
.attachment-preview-inner { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.attachment-preview-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Composer */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-composer);
  margin: 0 16px 16px 16px;
  border-radius: 8px;
  padding: 10px 12px;
}
.reply-bar:not(.hidden) + .attachment-preview:not(.hidden) { border-radius: 0; }
.attach-btn { font-size: 20px; padding: 4px; color: var(--text-secondary); }
.attach-btn:hover { color: var(--text-bright); }
.composer-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text-normal);
  font-size: 15px;
  line-height: 1.375;
  max-height: 200px;
  padding: 6px 0;
}
.composer-input::placeholder { color: #6d6f78; }
.send-btn { font-size: 18px; color: var(--text-secondary); padding: 4px 6px; }
.send-btn:hover { color: var(--blurple); }

/* ===================== Voice pane (no-video tile view) ===================== */
.voice-pane { flex: 1; display: flex; flex-direction: column; background: var(--bg-chat); padding: 20px; min-height: 0; }
.voice-tiles {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  align-content: start;
  overflow-y: auto;
}
.voice-tile {
  background: var(--bg-sidebar);
  border-radius: 12px;
  aspect-ratio: 16 / 10;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.voice-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.voice-tile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
}
.voice-tile-name {
  position: absolute;
  bottom: 8px;
  left: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: rgba(0,0,0,0.5);
  padding: 2px 8px;
  border-radius: 4px;
}
.voice-tile .live-pill {
  position: absolute;
  top: 8px;
  right: 8px;
}
.voice-tile-muted-icon {
  position: absolute;
  bottom: 8px;
  right: 10px;
  background: rgba(0,0,0,0.5);
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.voice-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px 0 4px 0;
}
.voice-ctrl-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-composer);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.voice-ctrl-btn:hover { background: var(--bg-active); }
.voice-ctrl-btn.active { background: var(--blurple); }
.voice-disconnect { background: var(--red); }
.voice-disconnect:hover { background: #a12828; }

/* ===================== Stream stage ===================== */
.stream-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #000;
  min-height: 0;
  position: relative;
}
.stage-main { flex: 1; display: flex; min-height: 0; padding: 16px 16px 0 16px; }
.stage-video-wrap {
  flex: 1;
  background: #18191c;
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.stage-video-slot { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.stage-video-slot video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.stage-title-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,0.55);
  padding: 6px 10px;
  border-radius: 6px;
  z-index: 3;
}
.stage-title-text { font-size: 14px; font-weight: 600; color: #fff; }
.stage-fullscreen-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 16px;
  padding: 6px 8px;
  border-radius: 6px;
  z-index: 3;
}
.stage-fullscreen-btn:hover { background: rgba(0,0,0,0.8); }

.stage-thumb-strip {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  overflow-x: auto;
}
.stage-thumb {
  width: 140px;
  height: 88px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px solid transparent;
}
.stage-thumb.focused { border-color: var(--blurple); }
.stage-thumb video { width: 100%; height: 100%; object-fit: cover; }
.stage-thumb .voice-tile-name { font-size: 11px; padding: 1px 6px; }
.stage-thumb .live-pill { position: absolute; top: 4px; right: 4px; font-size: 8px; }

/* ===================== Voice-activity "speaking" ring ===================== */
/* Applied to the sid-bearing container element in each voice UI location
   (sidebar occupant row, voice tile, stage thumbnail). Ring goes on the avatar
   image/fallback child so it hugs the circular avatar rather than the tile box. */
.voice-channel-user.speaking img,
.voice-channel-user.speaking .avatar-fallback {
  box-shadow: 0 0 0 2px #23a559;
}
.voice-tile.speaking img,
.voice-tile.speaking .avatar-fallback {
  box-shadow: 0 0 0 2px #23a559;
}
.stage-thumb.speaking {
  border-color: #23a559;
}
.stage-thumb.speaking img,
.stage-thumb.speaking .avatar-fallback {
  box-shadow: 0 0 0 2px #23a559;
}

.stage-control-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 0 20px 0;
}

/* ===================== Members sidebar ===================== */
/* SCROLL BUG FIX: members-sidebar scrolls independently of the message list; it is a
   grid column (not a flex child of .main) so it only needs its own min-height:0 to
   respect the grid row height instead of growing past it. */
.members-sidebar {
  width: 240px; /* v9b: the grid column is auto now; size the panel itself */
  background: var(--bg-sidebar);
  padding: 16px 8px;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.members-group { margin-bottom: 12px; }
.members-header { font-size: 11px; font-weight: 700; color: var(--text-muted); padding: 0 8px 8px 8px; letter-spacing: 0.02em; }
.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.member-item:hover { background: var(--bg-hover); }
.member-item.offline { opacity: 0.5; }
.member-avatar-wrap { position: relative; flex-shrink: 0; }
.member-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.status-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 3px solid var(--bg-sidebar);
}
.status-dot.online { background: var(--green); }
.status-dot.idle { background: var(--yellow); }
.status-dot.dnd { background: var(--red); }
.status-dot.offline, .status-dot.invisible { background: #80848e; }
.member-text-col { min-width: 0; flex: 1; }
.member-name { font-size: 14px; color: var(--text-normal); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.member-custom-status { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }

/* ===================== Modals ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  /* must sit above the settings/server-settings overlays (z 300) — the
     Upload a Sound modal opens from inside server settings */
  z-index: 500;
}
.modal {
  background: var(--bg-modal);
  border-radius: 8px;
  width: 440px;
  max-width: 92vw;
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-bright);
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
}
.modal-close { font-size: 16px; color: var(--text-muted); padding: 4px; }
.modal-close:hover { color: var(--text-bright); }
.modal-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 4px; }
.modal-label { font-size: 12px; font-weight: 700; color: var(--text-secondary); margin-top: 12px; margin-bottom: 6px; text-transform: uppercase; }
.modal-input {
  background: var(--bg-input);
  border: 1px solid var(--bg-input);
  border-radius: 4px;
  padding: 10px;
  font-size: 14px;
  color: var(--text-normal);
  outline: none;
  width: 100%;
  resize: vertical;
}
.modal-input:focus { border-color: var(--blurple); }
.modal-input-color {
  width: 100%;
  height: 40px;
  background: var(--bg-input);
  border: 1px solid var(--bg-input);
  border-radius: 4px;
  padding: 4px;
  cursor: pointer;
}
.modal-range { width: 100%; accent-color: var(--blurple); }
.modal-footer { padding: 12px 20px 20px 20px; display: flex; justify-content: flex-end; }
.modal-primary-btn {
  background: var(--blurple);
  color: #fff;
  padding: 10px 18px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 14px;
}
.modal-primary-btn:hover { background: var(--blurple-hover); }
.modal-secondary-btn {
  background: #4e5058;
  color: #fff;
  padding: 8px 14px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 13px;
}
.modal-secondary-btn:hover { background: #6d6f78; }

.profile-avatar-row { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.profile-avatar-preview { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: var(--blurple); }

.forward-channel-list { display: flex; flex-direction: column; gap: 2px; }
.forward-channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 15px;
  color: var(--text-normal);
}
.forward-channel-item:hover { background: var(--bg-hover); }
.forward-channel-item.sent { opacity: 0.5; pointer-events: none; }

/* Screen share modal pills */
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.pill-btn {
  background: var(--bg-input);
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
}
.pill-btn:hover { background: var(--bg-hover); color: var(--text-bright); }
.pill-btn.active { background: var(--blurple); color: #fff; }
.go-live-btn { width: 100%; text-align: center; font-size: 15px; padding: 12px; }

/* ===================== Profile popout ===================== */
.profile-popout {
  position: fixed;
  width: 300px;
  background: var(--bg-modal);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 220;
  overflow: hidden;
}
.popout-banner { height: 60px; background: var(--blurple); }
.popout-body { padding: 0 16px 16px 16px; position: relative; }
.popout-avatar-row { margin-top: -32px; margin-bottom: 8px; }
.popout-avatar-wrap { position: relative; width: 72px; }
.popout-avatar {
  width: 72px; height: 72px; border-radius: 50%; object-fit: cover;
  border: 5px solid var(--bg-modal); background: var(--blurple); display: block;
}
.popout-avatar-wrap .status-dot { width: 18px; height: 18px; border: 4px solid var(--bg-modal); bottom: 0; right: 0; }
.popout-display-name { font-size: 17px; font-weight: 700; color: var(--text-bright); }
.popout-username { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }
.popout-divider { height: 1px; background: rgba(127,127,127,0.24); margin: 10px 0; }
.popout-status-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--bg-input);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-normal);
  outline: none;
  margin-bottom: 8px;
}
.popout-status-input:focus { border-color: var(--blurple); }
.popout-status-rows { display: flex; flex-direction: column; gap: 2px; }
.popout-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
}
.popout-status-row:hover { background: var(--bg-hover); }
.popout-status-row.selected { background: rgba(88,101,242,0.16); color: #c9cdfb; }
.popout-status-row .status-dot { position: static; border: none; width: 10px; height: 10px; }
.popout-full-btn { width: 100%; margin-top: 8px; text-align: center; }

/* ===================== Settings overlay ===================== */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  background: var(--bg-chat);
}
.settings-nav {
  width: 240px;
  background: var(--bg-sidebar);
  display: flex;
  justify-content: flex-end;
}
.settings-nav-inner { width: 220px; padding: 60px 6px 20px 6px; }
.settings-nav-header { font-size: 12px; font-weight: 700; color: var(--text-muted); padding: 0 10px 6px 10px; letter-spacing: 0.02em; }
.settings-nav-item {
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 15px;
  color: var(--text-secondary);
  cursor: pointer;
  margin-bottom: 2px;
}
.settings-nav-item:hover { background: var(--bg-hover); color: var(--text-normal); }
.settings-nav-item.active { background: var(--bg-active); color: var(--text-bright); }
.settings-nav-divider { height: 1px; background: rgba(127,127,127,0.24); margin: 8px 10px; }
.settings-nav-logout { color: #fa777c; }
.settings-nav-logout:hover { background: rgba(242,63,67,0.12); color: #fa777c; }

.settings-content { flex: 1; overflow-y: auto; padding: 60px 40px; position: relative; max-width: 740px; }
.settings-close-btn {
  position: fixed;
  top: 24px;
  right: 32px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  color: var(--text-muted);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.settings-close-btn:hover { color: var(--text-bright); border-color: var(--text-bright); }

.settings-section { display: none; }
.settings-section.active { display: block; }
.settings-title { font-size: 20px; color: var(--text-bright); margin-bottom: 20px; }

.settings-profile-layout { display: flex; gap: 32px; flex-wrap: wrap; }
.settings-profile-form { flex: 1; min-width: 260px; }
.settings-save-btn { margin-top: 20px; }
.settings-preview-col { width: 260px; flex-shrink: 0; }

.preview-card {
  background: var(--bg-sidebar);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.preview-card-banner { height: 60px; background: var(--blurple); }
.preview-card-body { padding: 0 16px 16px 16px; position: relative; }
.preview-card-avatar-wrap { position: relative; width: 64px; margin-top: -28px; margin-bottom: 8px; }
.preview-card-avatar {
  width: 64px; height: 64px; border-radius: 50%; object-fit: cover;
  border: 4px solid var(--bg-sidebar); background: var(--blurple); display: block;
}
.preview-card-avatar-wrap .status-dot { width: 16px; height: 16px; border: 3px solid var(--bg-sidebar); }
.preview-card-name { font-size: 16px; font-weight: 700; color: var(--text-bright); }
.preview-card-username { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.preview-card-divider { height: 1px; background: rgba(127,127,127,0.24); margin: 8px 0; }
.preview-card-status { font-size: 13px; color: var(--text-normal); margin-bottom: 6px; }
.preview-card-bio { font-size: 12px; color: var(--text-secondary); white-space: pre-wrap; word-break: break-word; }

.theme-card-row { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; }
.theme-card { width: 120px; cursor: pointer; text-align: center; }
.theme-card-swatch {
  height: 70px;
  border-radius: 8px;
  border: 2px solid transparent;
  margin-bottom: 6px;
}
.theme-card.selected .theme-card-swatch { border-color: var(--blurple); }
.theme-card-label { font-size: 13px; color: var(--text-secondary); }
.theme-swatch-dark { background: linear-gradient(135deg, #313338 50%, #1e1f22 50%); }
.theme-swatch-darker { background: linear-gradient(135deg, #2b2d31 50%, #1a1b1e 50%); }
.theme-swatch-midnight { background: linear-gradient(135deg, #1a1d26 50%, #0f1015 50%); }
.theme-swatch-light { background: linear-gradient(135deg, #ffffff 50%, #e3e5e8 50%); border: 1px solid rgba(127,127,127,0.3); }

/* ===================== Lightbox ===================== */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: zoom-out;
}
.lightbox-img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}

/* Avatar color fallback */
.avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
}

/* ===================== Add a Server modal ===================== */
.add-server-modal { width: 440px; }
.add-server-sub { font-size: 14px; color: var(--text-secondary); margin-bottom: 16px; line-height: 1.4; }
.add-server-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-hover);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  margin-bottom: 8px;
}
.add-server-row:hover { background: var(--bg-active); }
.add-server-row-icon { font-size: 22px; }
.add-server-row-label { flex: 1; font-weight: 600; font-size: 15px; color: var(--text-bright); }
.add-server-row-chevron { color: var(--text-muted); font-size: 18px; }
.add-server-invite-footer { margin-top: 16px; text-align: center; }
.add-server-invite-title { font-weight: 700; font-size: 16px; color: var(--text-bright); margin-bottom: 10px; }
.add-server-join-btn { width: 100%; margin-top: 8px; text-align: center; }

.add-server-icon-picker { display: flex; flex-direction: column; align-items: center; margin: 8px 0 20px 0; cursor: pointer; position: relative; }
.add-server-icon-circle {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: 2px dashed var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--text-muted);
  overflow: hidden;
  background: var(--bg-hover);
}
.add-server-icon-circle img { width: 100%; height: 100%; object-fit: cover; }
.add-server-icon-plus {
  position: absolute;
  bottom: 4px;
  right: calc(50% - 45px);
  background: var(--blurple);
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  border: 3px solid var(--bg-modal);
}
.add-server-footer { display: flex; justify-content: space-between; gap: 8px; }
.add-server-footer .modal-primary-btn { margin-left: auto; }

/* ===================== Server settings ===================== */
.banner-swatch-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 4px; }
.banner-swatch {
  aspect-ratio: 16 / 10;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
}
.banner-swatch.selected { border-color: #fff; }
.danger-btn { background: var(--red); }
.danger-btn:hover { background: #a12828; }
.server-delete-confirm { margin-top: 16px; }
.server-delete-confirm p { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }

.server-settings-members-list { display: flex; flex-direction: column; gap: 2px; }
.server-settings-member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 4px;
}
.server-settings-member-row:hover { background: var(--bg-hover); }
.server-settings-member-name { flex: 1; font-size: 14px; color: var(--text-normal); }
.server-owner-crown { font-size: 14px; }

/* ===================== Audio attachment card ===================== */
.attachment-audio-card {
  background: var(--bg-sidebar);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 4px;
  max-width: 432px;
  width: 100%;
}
.audio-card-file-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.audio-card-icon { font-size: 18px; color: var(--blurple); flex-shrink: 0; }
.audio-card-meta { min-width: 0; flex: 1; }
.audio-card-name { display: block; font-size: 13px; color: #6d95f5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audio-card-size { display: block; font-size: 11px; color: var(--text-muted); }
.audio-card-controls { display: flex; align-items: center; gap: 8px; }
.audio-card-playbtn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-active);
  color: var(--text-bright);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.audio-card-playbtn:hover { background: var(--blurple); }
.audio-card-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; white-space: nowrap; min-width: 78px; text-align: center; }
.audio-card-seek {
  flex: 1;
  min-width: 40px;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-active);
  accent-color: var(--blurple);
  cursor: pointer;
}
.audio-card-volume-icon { font-size: 13px; color: var(--text-muted); flex-shrink: 0; }
.audio-card-volume {
  width: 60px;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-active);
  accent-color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
}

/* ===================== YouTube / GitHub embed card ===================== */
.embed-card {
  display: flex;
  gap: 0;
  max-width: min(432px, 100%);
  margin-top: 6px;
  background: var(--bg-sidebar);
  border-radius: 4px;
  overflow: hidden;
}
.embed-card-accent { width: 4px; background: var(--red); flex-shrink: 0; }
.embed-card-body { padding: 10px 12px; min-width: 0; flex: 1; }
.embed-card-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.embed-card-author { font-size: 13px; color: var(--text-normal); margin-bottom: 2px; }
.embed-card-title { font-size: 15px; font-weight: 700; color: #6d95f5; margin-bottom: 8px; display: block; text-decoration: none; }
.embed-card-title:hover { text-decoration: underline; }
.embed-card-thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 4px;
  overflow: hidden;
  background: #000;
  cursor: pointer;
}
.embed-card-thumb-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.embed-card-thumb-wrap iframe { width: 100%; height: 100%; border: none; display: block; }
.embed-card-play-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 56px;
  height: 40px;
  background: rgba(0,0,0,0.7);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
}
.embed-card-thumb-wrap:hover .embed-card-play-btn { background: var(--red); }

/* GitHub embed card (contract v4 §F, match github-message.png): gray accent bar
   instead of red, description text, stars/forks row. */
.embed-card-accent-github { background: #6d6f78; }
.embed-card-description { font-size: 13px; color: var(--text-normal); line-height: 1.35; margin-bottom: 8px; }
.embed-card-og-image-link { display: block; margin-bottom: 8px; }
.embed-card-og-image { display: block; max-width: 400px; width: 100%; border-radius: 4px; }
.embed-card-github-stats { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }

/* Linkified message links */
.message-link { color: #6d95f5; text-decoration: none; word-break: break-all; }
.message-link:hover { text-decoration: underline; }

/* Media max-width safety (contract §6). .embed-card is NOT in this list: a
   later same-specificity max-width:100% would silently override its 432px cap. */
.attachment-image, .attachment-video, .attachment-audio-card, .attachment-file-card {
  max-width: 100%;
}

/* ===================== Inline edit textarea (contract v4 §B) ===================== */
.edit-message-textarea {
  width: 100%;
  min-height: 22px;
  resize: none;
  font-size: 15px;
  line-height: 1.375;
  font-family: inherit;
  color: var(--text-normal);
  background: var(--bg-input);
  border: 1px solid var(--blurple);
  border-radius: 4px;
  padding: 6px 8px;
  margin-top: 2px;
}
.edit-message-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ===================== Message context menu (contract v4 §B, message-settings.png) === */
.message-context-menu {
  position: fixed;
  z-index: 260;
  width: 220px;
  background: var(--bg-modal);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  padding: 6px;
}
.context-menu-quick-react {
  display: flex;
  gap: 4px;
  padding: 4px 4px 8px 4px;
}
.context-menu-quick-react-btn {
  flex: 1;
  font-size: 18px;
  padding: 6px 0;
  border-radius: 6px;
  background: var(--bg-sidebar);
  text-align: center;
}
.context-menu-quick-react-btn:hover { background: var(--bg-hover); }
.context-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--text-normal);
  cursor: pointer;
}
.context-menu-item:hover { background: var(--blurple); color: #fff; }
.context-menu-item.hidden { display: none; }
.context-menu-icon { font-size: 13px; color: var(--text-muted); }
.context-menu-item:hover .context-menu-icon { color: #fff; }
.context-menu-danger { color: var(--red); }
.context-menu-danger:hover { background: var(--red); color: #fff; }
.context-menu-divider { height: 1px; background: rgba(127,127,127,0.2); margin: 6px 4px; }

/* ===================== Pinned messages popover (contract v4 §C, pin-messages.png) ==== */
/* search-wrap now owns the margin-left:auto push; pinned button follows it */
.pinned-toggle-btn { display: flex; }
.pinned-popover {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  max-width: 90vw;
  background: var(--bg-sidebar);
  border-left: 1px solid rgba(0,0,0,0.3);
  box-shadow: -4px 0 16px rgba(0,0,0,0.3);
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.pinned-popover-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-bright);
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
}
.pinned-popover-icon { font-size: 16px; }
.pinned-popover-close { margin-left: auto; color: var(--text-muted); font-size: 14px; padding: 4px; }
.pinned-popover-close:hover { color: var(--text-bright); }
.pinned-popover-list { flex: 1; overflow-y: auto; padding: 8px; }
.pinned-popover-empty { color: var(--text-muted); font-size: 13px; padding: 16px 8px; text-align: center; }

.pinned-entry {
  padding: 10px 8px;
  border-radius: 6px;
  cursor: pointer;
  border-bottom: 1px solid rgba(127,127,127,0.14);
}
.pinned-entry:hover { background: var(--bg-hover); }
.pinned-entry-header { display: flex; align-items: center; gap: 5px; margin-bottom: 4px; }
.pinned-entry-name { font-size: 13px; font-weight: 600; color: var(--text-bright); }
.pinned-entry-time { font-size: 11px; color: var(--text-muted); margin-left: 3px; }
.pinned-entry-content { font-size: 13px; color: var(--text-normal); line-height: 1.35; word-break: break-word; }
.pinned-entry-thumb { margin-top: 6px; }
.pinned-entry-thumb img { max-width: 100%; max-height: 200px; border-radius: 6px; display: block; }
/* Video thumb in the pinned panel is a dark placeholder with a centered ▶ glyph
   (contract v5 §G, pin-messages.png) rather than a playable element. */
.pinned-entry-video-thumb {
  width: 100%;
  max-width: 260px;
  height: 160px;
  background: #000;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pinned-entry-play-glyph {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

/* ===================== Jump to present bar (contract v4 §D, jump-to-present.png) ===== */
.jump-to-present-bar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(30,31,34,0.95);
  border-radius: 20px;
  padding: 8px 8px 8px 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  font-size: 13px;
  color: var(--text-normal);
  white-space: nowrap;
}
.jump-to-present-btn {
  background: var(--blurple);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 16px;
}
.jump-to-present-btn:hover { background: var(--blurple-hover); }

/* ===================== Composer picker button ===================== */
.composer-picker-btn { font-size: 20px; color: var(--text-muted); padding: 4px; flex-shrink: 0; }
.composer-picker-btn:hover { color: var(--text-normal); }

/* ===================== Composer picker panel (contract v4 §E/§F, tenor.png) ========== */
.composer-picker {
  position: absolute;
  right: 16px;
  bottom: 76px;
  width: 420px;
  max-width: 90vw;
  height: 480px;
  max-height: 70vh;
  background: var(--bg-modal);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.composer-picker-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 10px 0 10px;
  flex-shrink: 0;
}
.composer-picker-tab {
  flex: 1;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-sidebar);
  border-radius: 6px 6px 0 0;
}
.composer-picker-tab.active { color: var(--text-bright); background: var(--bg-active); }
.composer-picker-tab:hover { color: var(--text-normal); }

.composer-picker-panel { display: none; flex: 1; min-height: 0; flex-direction: column; padding: 10px; }
.composer-picker-panel.active { display: flex; }

.composer-picker-search-row { flex-shrink: 0; margin-bottom: 8px; }
.composer-picker-search {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid rgba(127,127,127,0.25);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-normal);
}
.composer-picker-search:focus { border-color: var(--blurple); }

.gif-results-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
/* v8b: JS masonry (two flex column stacks). The old CSS multicol version
   repainted lazily during scroll — tiles visibly deformed until the layout
   settled — and a height-constrained multicol overflows sideways anyway. */
.gif-masonry {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.gif-masonry-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.gif-result-tile {
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: var(--bg-sidebar);
  /* aspect-ratio is set inline per tile from the Tenor dims */
}
.gif-result-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gif-result-tile:hover { outline: 2px solid var(--blurple); }

.sticker-results-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
  align-content: start;
}
.sticker-result-tile {
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  cursor: pointer;
  background: var(--bg-sidebar);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}
.sticker-result-tile img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.sticker-result-tile:hover { background: var(--bg-hover); }

.emoji-results-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 2px;
  align-content: start;
}
.emoji-result-btn { font-size: 20px; padding: 5px; border-radius: 4px; text-align: center; }
.emoji-result-btn:hover { background: var(--bg-hover); }
.custom-emoji-result-btn { display: flex; align-items: center; justify-content: center; }
.custom-emoji-result-btn img { width: 22px; height: 22px; object-fit: contain; }
.emoji-grid-divider {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 6px 4px 2px 4px;
}
.picker-loading, .picker-empty {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 24px 8px;
}

/* ===================== Server Tag (contract v4 §G, server-badge.png) ===================== */
.server-tag-section { margin-top: 24px; padding-top: 16px; border-top: 1px solid rgba(127,127,127,0.24); }
.server-tag-input-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.server-tag-input { width: 120px; text-transform: uppercase; }
.server-tag-chip-preview {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  background: rgba(127,127,127,0.16);
  border-radius: 4px;
  padding: 2px 6px;
  line-height: 1.5;
}

/* Choose Badge / Choose Color grids (contract v5 §E, server-badge.png). */
.server-tag-badge-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; margin: 4px 0 14px; max-width: 420px; }
.server-tag-badge-swatch {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  border-radius: 6px;
  background: var(--bg-input);
  border: 2px solid transparent;
  cursor: pointer;
}
.server-tag-badge-swatch.selected { border-color: var(--blurple); }
.server-tag-color-grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 8px; margin: 4px 0 14px; max-width: 420px; }
.server-tag-color-swatch {
  aspect-ratio: 1;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
}
.server-tag-color-swatch.selected { border-color: #fff; }

/* ===================== Roles tab (contract v4 §G, roles.png) ===================== */
.roles-layout { display: flex; gap: 0; min-height: 420px; margin: -4px -8px; }
.roles-list-col { width: 220px; flex-shrink: 0; padding: 4px 8px; border-right: 1px solid rgba(127,127,127,0.16); }
.roles-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 4px 6px 8px 6px;
  letter-spacing: 0.02em;
}
.roles-list { display: flex; flex-direction: column; gap: 2px; }
.role-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--text-normal);
  cursor: pointer;
}
.role-list-item:hover { background: var(--bg-hover); }
.role-list-item.active { background: var(--bg-active); color: var(--text-bright); }
.role-list-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.roles-edit-col { flex: 1; padding: 4px 20px; min-width: 0; }
.roles-edit-empty { color: var(--text-muted); font-size: 14px; padding: 20px 8px; }
.role-color-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 8px; margin-top: 4px; max-width: 420px; }
.role-color-swatch {
  aspect-ratio: 1;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
}
.role-color-swatch.selected { border-color: #fff; }

/* Native color picker beside the swatch grid (contract v5 §F, roles.png). */
.role-color-row { display: flex; align-items: center; gap: 10px; }
.role-color-row .role-color-grid { flex: 1; }
.role-color-custom-input { width: 44px; height: 32px; flex-shrink: 0; padding: 2px; }

/* Role icon upload control (contract v5 §F, roles.png). */
.role-icon-row { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.role-icon-preview {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.role-icon-preview-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.role-icon-preview-placeholder { font-size: 20px; color: var(--text-muted); }

.roles-manage-members { margin-top: 8px; }
.role-members-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; max-height: 220px; overflow-y: auto; }
.role-member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 4px;
}
.role-member-row:hover { background: var(--bg-hover); }
.role-member-name { flex: 1; font-size: 13px; color: var(--text-normal); }
.role-member-remove { color: var(--text-muted); font-size: 12px; padding: 4px; border-radius: 4px; }
.role-member-remove:hover { color: #fff; background: var(--red); }
.role-add-member-row { display: flex; gap: 8px; }
.role-add-member-row .modal-input { flex: 1; }
.role-delete-btn { margin-top: 24px; }

/* ===================== Expression tabs: Emoji / Stickers / Soundboard (contract v4 §E) ===================== */
.expression-upload-error { color: #fa777c; font-size: 13px; margin-top: 10px; }
.expression-table { margin-top: 20px; border-radius: 8px; overflow: hidden; background: var(--bg-sidebar); }
.expression-table-header {
  display: grid;
  grid-template-columns: 60px 1fr 200px;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(0,0,0,0.15);
}
.expression-table-row {
  display: grid;
  grid-template-columns: 60px 1fr 200px;
  align-items: center;
  padding: 8px 14px;
  position: relative;
}
.expression-table-row:hover { background: var(--bg-hover); }
.expression-table-img { width: 32px; height: 32px; object-fit: contain; display: block; }
.expression-table-uploader { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.expression-delete-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  padding: 6px;
  border-radius: 4px;
  opacity: 0;
}
.expression-table-row:hover .expression-delete-btn { opacity: 1; }
.expression-delete-btn:hover { color: #fff; background: var(--red); }

.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, 160px); gap: 12px; margin-top: 20px; }
.sticker-settings-tile {
  width: 160px;
  background: var(--bg-sidebar);
  border-radius: 8px;
  padding: 10px;
  position: relative;
  text-align: center;
}
.sticker-settings-tile:hover { background: var(--bg-hover); }
.sticker-settings-img { width: 100%; height: 100px; object-fit: contain; display: block; margin-bottom: 6px; }
.sticker-settings-name { font-size: 13px; font-weight: 600; color: var(--text-normal); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sticker-settings-uploader { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.sticker-settings-delete { top: 6px; right: 6px; transform: none; background: rgba(0,0,0,0.4); }
.sticker-settings-tile:hover .sticker-settings-delete { opacity: 1; }

.sound-list { margin-top: 20px; display: flex; flex-direction: column; gap: 2px; }
.sound-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 6px;
  background: var(--bg-sidebar);
  position: relative;
}
.sound-row + .sound-row { margin-top: 2px; }
.sound-row:hover { background: var(--bg-hover); }
.sound-row-play-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-active);
  color: var(--text-bright);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sound-row-play-btn:hover { background: var(--blurple); }
.sound-row-name { flex: 1; font-size: 14px; color: var(--text-normal); }
.sound-row-uploader { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); margin-right: 30px; }

/* Upload a Sound modal (soundboard-upload-...png) */
.sound-upload-modal { width: 420px; }
.sound-upload-file-row { display: flex; align-items: center; gap: 8px; }
.sound-upload-filename {
  flex: 1;
  background: var(--bg-input);
  border-radius: 4px;
  padding: 10px;
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sound-upload-footer { display: flex; justify-content: space-between; gap: 8px; }
.sound-upload-footer .modal-primary-btn { margin-left: auto; }

/* Trim editor inside the Upload a Sound modal */
.sound-trim-section { margin-top: 12px; }
.sound-trim-canvas {
  display: block;
  width: 100%;
  height: 64px;
  background: var(--bg-input);
  border-radius: 4px;
}
.sound-trim-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}
.sound-trim-label { font-size: 12px; color: var(--text-muted); }

/* ===================== Soundboard popover (voice) ===================== */
.soundboard-popover {
  position: fixed;
  width: 280px;
  max-height: 340px;
  background: var(--bg-modal);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 220;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.soundboard-popover-header {
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-bright);
  border-bottom: 1px solid rgba(127,127,127,0.16);
  flex-shrink: 0;
}
.soundboard-popover-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 10px;
  overflow-y: auto;
}
.soundboard-tile {
  background: var(--bg-hover);
  border-radius: 6px;
  padding: 14px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-normal);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.soundboard-tile:hover { background: var(--blurple); color: #fff; }

/* ===================== Voice & Video settings (contract v4 §H) ===================== */
.voice-settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; }
.mic-test-row { display: flex; align-items: center; gap: 14px; margin-top: 20px; }
.mic-test-row .modal-primary-btn { flex-shrink: 0; }
.mic-test-row .modal-primary-btn.active { background: var(--red); }
.mic-test-meter {
  flex: 1;
  height: 16px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.mic-test-meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #23a559 0%, #23a559 60%, #f0b232 80%, #da373c 100%);
  transition: width 0.05s linear;
}

/* ===================== Responsive (contract §6) ===================== */
@media (max-width: 1000px) {
  .app { grid-template-columns: 72px 240px 1fr auto; }
  .members-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 240px;
    max-width: 80vw;
    z-index: 150;
    box-shadow: -4px 0 16px rgba(0,0,0,0.4);
    transform: translateX(100%);
    transition: transform 0.18s ease;
  }
  .members-sidebar.open { transform: translateX(0); }
  .members-toggle-btn { display: flex; }
}

@media (max-width: 700px) {
  .app { grid-template-columns: 72px 1fr auto; }
  #channel-sidebar {
    position: fixed;
    top: 0;
    left: 72px;
    bottom: 0;
    width: 240px;
    max-width: 80vw;
    z-index: 150;
    box-shadow: 4px 0 16px rgba(0,0,0,0.4);
    transform: translateX(-100%);
    transition: transform 0.18s ease;
  }
  #channel-sidebar.open { transform: translateX(0); }
  #channel-drawer-btn { display: flex; }
  .drawer-scrim {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 140;
  }
  .modal, .settings-overlay .settings-nav, .settings-overlay .settings-content {
    max-width: 95vw;
  }
  .settings-overlay { flex-direction: column; overflow-y: auto; }
  .settings-nav { width: 100%; justify-content: flex-start; }
  .settings-nav-inner { width: 100%; padding: 16px; }
  .settings-content { padding: 50px 16px 24px 16px; max-width: 100%; }
  .roles-layout { flex-direction: column; }
  .roles-list-col { width: 100%; border-right: none; border-bottom: 1px solid rgba(127,127,127,0.16); padding-bottom: 12px; margin-bottom: 12px; }
  .voice-settings-grid { grid-template-columns: 1fr; }
}

/* (Base .header-toggle-btn rule is display:none; the max-width breakpoints above
   switch the relevant button to display:flex, so no min-width override is needed.) */

/* ===================== Message search (v7) ===================== */
.search-wrap { position: relative; margin-left: auto; }
.message-search-input {
  width: 150px;
  background: var(--bg-input);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 13px;
  color: var(--text-normal);
  transition: width 0.15s ease;
}
.message-search-input:focus { width: 240px; border-color: var(--blurple); }
.search-clear-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 12px;
  padding: 2px 4px;
}
.search-clear-btn:hover { color: var(--text-bright); }
.search-suggest {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 320px;
  background: var(--bg-modal);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  padding: 8px;
  z-index: 210;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.search-suggest.hidden { display: none; }
.search-suggest-title { font-size: 11px; font-weight: 700; color: var(--text-muted); padding: 4px 6px; text-transform: uppercase; }
.search-suggest-row {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 6px 8px;
  border-radius: 4px;
  color: var(--text-normal);
}
.search-suggest-row:hover { background: var(--bg-hover); }
.search-suggest-icon { width: 20px; text-align: center; flex-shrink: 0; font-size: 14px; }
.search-suggest-avatar { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.search-suggest-text { display: flex; flex-direction: column; min-width: 0; }
.search-suggest-title-line { font-size: 13px; color: var(--text-bright); }
.search-suggest-sub { font-size: 11.5px; color: var(--text-muted); }
.search-header-actions { display: flex; align-items: center; gap: 6px; }
.search-header-btn {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-normal);
  background: var(--bg-input);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 5px;
  padding: 4px 9px;
}
.search-header-btn:hover { color: var(--text-bright); border-color: var(--blurple); }
.search-group-header {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-bright);
  padding: 6px 2px 0;
}
.search-mark {
  background: rgba(193, 155, 88, 0.45);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
.members-sidebar.search-hidden { display: none; }
.search-results-panel {
  width: 340px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.search-results-panel.hidden { display: none; }
.search-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-bright);
  border-bottom: 1px solid rgba(0,0,0,0.25);
  flex-shrink: 0;
}
.search-results-close { color: var(--text-muted); font-size: 14px; padding: 2px 6px; }
.search-results-close:hover { color: var(--text-bright); }
.search-results-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.search-result-card {
  position: relative;
  background: var(--bg-secondary, rgba(0,0,0,0.18));
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}
.search-result-card:hover { border-color: var(--blurple); }
.search-result-jump {
  position: absolute;
  top: 8px;
  right: 8px;
  display: none;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-normal);
  background: var(--bg-input);
  border-radius: 4px;
  padding: 2px 8px;
}
.search-result-card:hover .search-result-jump { display: block; }
.search-result-jump:hover { color: var(--text-bright); }
.search-result-head { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.search-result-avatar { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.search-result-author { font-size: 13px; font-weight: 600; color: var(--text-bright); }
.search-result-time { font-size: 11px; color: var(--text-muted); }
.search-result-content { font-size: 13px; color: var(--text-normal); line-height: 1.35; word-break: break-word; }
.search-result-media {
  display: block;
  max-width: 100%;
  max-height: 160px;
  width: auto;
  border-radius: 4px;
  margin-top: 6px;
}
.search-result-video {
  width: 120px;
  height: 70px;
  margin-top: 6px;
  background: #000;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
}
.search-result-sticker { width: 80px; height: 80px; object-fit: contain; margin-top: 6px; }
.search-result-file { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.search-empty { padding: 16px; font-size: 13px; color: var(--text-muted); }

/* Filters modal (message-search-4/5.png) */
.search-filters-modal { width: 460px; }
.search-filters-body { max-height: 60vh; overflow-y: auto; }
.search-filter-sub { font-size: 12px; color: var(--text-muted); margin: 2px 0 6px; }
.sf-user-box {
  position: relative;
  background: var(--bg-input);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 12px;
}
.sf-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.sf-chips:not(:empty) { margin-bottom: 6px; }
.sf-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-sidebar);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  color: var(--text-bright);
}
.sf-chip-x { color: var(--text-muted); font-size: 10px; }
.sf-chip-x:hover { color: #fa777c; }
.sf-user-input {
  width: 100%;
  background: transparent;
  border: none;
  font-size: 13px;
  color: var(--text-normal);
}
.sf-user-suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  background: var(--bg-modal);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  padding: 6px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sf-user-suggest.hidden { display: none; }
.sf-has-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.sf-has-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-normal);
  cursor: pointer;
}
.sf-has-row:hover { background: var(--bg-hover); }
.sf-date-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.sf-date, .sf-select {
  background: var(--bg-input);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 5px;
  color: var(--text-normal);
  padding: 5px 8px;
  font-size: 13px;
}
.search-filters-footer { display: flex; align-items: center; gap: 8px; }
.sf-clear-btn { color: var(--blurple); font-size: 13px; font-weight: 600; }
.sf-footer-spacer { flex: 1; }
.search-results-more {
  margin: 8px 10px 12px;
  padding: 7px 0;
  border-radius: 4px;
  background: var(--blurple);
  color: #fff;
  font-size: 13px;
  flex-shrink: 0;
}
@media (max-width: 1000px) {
  .search-results-panel {
    position: absolute;
    right: 0;
    top: 48px;
    bottom: 0;
    z-index: 150;
    box-shadow: -4px 0 12px rgba(0,0,0,0.35);
  }
  .message-search-input { width: 110px; }
  .message-search-input:focus { width: 160px; }
}

/* ===================== TOTP login + multi-account (v6) ===================== */
.totp-setup { margin: 12px 0 4px; text-align: left; }
.totp-qr {
  display: block;
  margin: 10px auto;
  width: 180px;
  height: 180px;
  border-radius: 6px;
  background: #fff; /* quiet zone contrast for camera scanning */
  image-rendering: pixelated;
}
.totp-manual-label { margin-top: 10px; margin-bottom: 6px; font-size: 12px; }
.totp-secret {
  display: block;
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid rgba(127,127,127,0.25);
  border-radius: 4px;
  font-family: monospace;
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--text-bright);
  word-break: break-all;
  user-select: all;
}
#login-invite-code { margin-bottom: 8px; }
#login-code { margin-top: 10px; text-align: center; letter-spacing: 4px; font-size: 18px; }
.login-accounts { margin-top: 18px; text-align: left; }
.login-accounts-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 6px;
}
.account-switcher-list { display: flex; flex-direction: column; gap: 4px; max-width: 420px; }
#login-accounts-list { display: flex; flex-direction: column; gap: 4px; }
.account-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg-sidebar);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-normal);
}
.account-row:hover { background: var(--bg-hover); }
.account-row.current { cursor: default; opacity: 0.8; }
.account-row-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-row-current { font-size: 11px; color: var(--text-muted); }
.account-row-forget {
  color: var(--text-muted); font-size: 12px; padding: 2px 6px; border-radius: 4px;
}
.account-row-forget:hover { color: #fa777c; }
.settings-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; max-width: 460px; }

/* ================= Contract v8: stream settings ================= */

/* §E (stream-settings-5.png): full-width top overlay bar on the stage video. */
.stage-title-bar { right: 12px; justify-content: space-between; }
.stage-title-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.stage-title-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.stage-channel-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255,255,255,0.08);
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
.stage-title-avatar { display: flex; align-items: center; }
.stage-title-avatar img, .stage-title-avatar .avatar-fallback {
  width: 20px; height: 20px; border-radius: 50%;
}
.stage-watchers { display: flex; align-items: center; }
.stage-watchers img, .stage-watchers .avatar-fallback {
  width: 18px; height: 18px; border-radius: 50%;
  margin-left: -6px;
  border: 1px solid rgba(0,0,0,0.6);
}
.stage-watchers img:first-child, .stage-watchers .avatar-fallback:first-child { margin-left: 0; }
.stage-watchers-more { font-size: 11px; color: var(--text-muted); margin-left: 3px; }
.stage-quality-badge {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: rgba(0,0,0,0.6);
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}

/* §A (stream-settings-3.png): hover Watch Stream overlay on LIVE tiles. */
.watch-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(0,0,0,0.45);
  opacity: 0;
  transition: opacity 0.12s ease;
  z-index: 2;
}
.voice-tile:hover .watch-overlay, .stage-thumb:hover .watch-overlay { opacity: 1; }
.watch-stream-pill {
  background: var(--bg-modal);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.watch-stream-pill:hover { background: var(--blurple); }
.watch-popout-btn {
  background: var(--bg-modal);
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  font-size: 15px;
  cursor: pointer;
}
.watch-popout-btn:hover { background: var(--blurple); }
.stage-thumb .watch-stream-pill { padding: 4px 8px; font-size: 11px; }
.stage-thumb .watch-popout-btn { width: 24px; height: 24px; font-size: 12px; }

/* §B/§C/§D: stream + voice options menus (reuse .context-menu-item rows). */
.stream-menu { width: 250px; z-index: 320; }
.ctx-checkbox {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1.5px solid var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: transparent;
  flex-shrink: 0;
}
.ctx-checkbox.checked {
  background: var(--blurple);
  border-color: var(--blurple);
  color: #fff;
}
.context-menu-item:hover .ctx-checkbox { border-color: #fff; }
.context-menu-item:hover .ctx-checkbox.checked { background: var(--blurple); }
.ctx-disabled { opacity: 0.45; cursor: not-allowed; }
.ctx-desc {
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 10px 6px 10px;
  line-height: 1.35;
}
.ctx-slider-row { padding: 4px 10px 8px 10px; }
.ctx-slider-label { font-size: 13px; color: var(--text-normal); margin-bottom: 6px; }
.ctx-slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--blurple);
  cursor: pointer;
}

/* §F: real toast (showToast). */
.app-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--bg-modal);
  color: var(--text-normal);
  padding: 10px 18px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  font-size: 14px;
  z-index: 400;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.app-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* §D: new-message preview card over the voice view. */
.voice-msg-preview {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 10px;
  max-width: 420px;
  background: var(--bg-modal);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  cursor: pointer;
  z-index: 350;
}
.voice-msg-preview.visible { display: flex; }
.voice-msg-preview img, .voice-msg-preview .avatar-fallback {
  width: 28px; height: 28px; border-radius: 50%;
  flex-shrink: 0;
}
.voice-msg-preview-body { min-width: 0; }
.voice-msg-preview-head {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.voice-msg-preview-text {
  font-size: 13px;
  color: var(--text-normal);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* v8b: Go Live audio-source hint */
.modal-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.4;
  min-height: 16px;
}

/* v8b: animated GIFs in chat + picker on their own compositor layer —
   scrolling then moves a finished texture instead of re-rastering the
   animation in tiles (the mid-raster state showed as seams/deformation). */
.attachment-image.attachment-gif,
.gif-result-tile img {
  transform: translateZ(0);
  will-change: transform;
}

/* ================= Contract v9: Direct Messages ================= */

/* Rail home button (dm-1.png) */
.rail-home {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-sidebar);
  color: var(--text-normal);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-radius 0.15s ease, background 0.15s ease;
}
.rail-home:hover, .rail-home.active {
  border-radius: 16px;
  background: var(--blurple);
  color: #fff;
}
.rail-home-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 3px solid var(--bg-rail);
}
.rail-divider {
  width: 32px;
  height: 2px;
  border-radius: 1px;
  background: rgba(127,127,127,0.3);
  margin: 8px 0;
  flex-shrink: 0;
}

/* DM sidebar content */
.dm-home {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.dm-search-wrap { padding: 10px 10px 8px 10px; }
.dm-search-input {
  width: 100%;
  background: var(--bg-rail);
  border: none;
  border-radius: 4px;
  color: var(--text-normal);
  font-size: 13px;
  padding: 6px 8px;
}
.dm-nav { padding: 0 8px; }
.dm-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
}
.dm-nav-item:hover, .dm-nav-item.active { background: var(--bg-hover); color: var(--text-normal); }
.dm-nav-icon { width: 20px; text-align: center; }
.dm-nav-decor { opacity: 0.55; cursor: default; }
.dm-nav-decor:hover { background: none; color: var(--text-muted); }
.dm-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 4px 16px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}
.dm-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 8px 8px; }
.dm-row, .friend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
}
.dm-row:hover, .dm-row.active, .friend-row:hover { background: var(--bg-hover); color: var(--text-normal); }
.dm-row.unread { color: var(--text-normal); font-weight: 600; }
.dm-row-avatar { position: relative; flex-shrink: 0; display: flex; }
.dm-row-avatar img, .dm-row-avatar .avatar-fallback { width: 32px; height: 32px; border-radius: 50%; }
.dm-group-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--blurple);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}
.dm-presence-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #747f8d;
  border: 3px solid var(--bg-sidebar);
}
.dm-presence-dot.online { background: var(--green); }
.dm-row-body { min-width: 0; flex: 1; }
.dm-row-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-row-sub { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-unread-dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; flex-shrink: 0; }

/* Friends pane */
.friends-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.friends-toolbar { padding: 14px 16px 8px 16px; }
.friends-filter {
  width: 100%;
  max-width: 420px;
  background: var(--bg-rail);
  border: none;
  border-radius: 4px;
  color: var(--text-normal);
  font-size: 14px;
  padding: 8px 10px;
}
.friends-count {
  padding: 6px 16px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}
.friends-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 12px 8px; }
.friend-row { border-top: 1px solid rgba(127,127,127,0.12); border-radius: 0; padding: 10px 8px; }
.friend-row:hover { border-radius: 8px; }
.friend-msg-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--bg-rail);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  flex-shrink: 0;
}
.friend-row:hover .friend-msg-btn { color: var(--text-normal); }
.friend-msg-btn:hover { background: var(--blurple); color: #fff; }

/* DM right panel: profile + note / group members (dm-1.png) */
.dm-profile-sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.members-sidebar.dm-hidden { display: none; }
.dm-profile-banner { height: 100px; background: var(--blurple); flex-shrink: 0; }
.dm-profile-avatar { margin: -40px 0 0 16px; }
.dm-profile-avatar img, .dm-profile-avatar .avatar-fallback {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 6px solid var(--bg-sidebar);
}
.dm-profile-name { font-size: 20px; font-weight: 700; color: var(--text-normal); padding: 8px 16px 0 16px; }
.dm-profile-sub { font-size: 13px; color: var(--text-muted); padding: 2px 16px 10px 16px; }
.dm-profile-card {
  margin: 0 12px 12px 12px;
  background: var(--bg-rail);
  border-radius: 8px;
  padding: 12px;
}
.dm-profile-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: 10px 0 4px 0;
}
.dm-profile-label:first-child { margin-top: 0; }
.dm-profile-bio { font-size: 13px; color: var(--text-normal); white-space: pre-wrap; }
.dm-profile-note {
  width: 100%;
  min-height: 54px;
  background: transparent;
  border: none;
  resize: vertical;
  color: var(--text-normal);
  font-size: 13px;
  font-family: inherit;
}
.dm-profile-note:focus { outline: none; background: rgba(0,0,0,0.2); border-radius: 4px; }
.dm-profile-members-header { padding: 14px 16px 6px 16px; }

/* Group DM creation modal */
.dm-group-user-list {
  max-height: 260px;
  overflow-y: auto;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dm-group-user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-normal);
  font-size: 14px;
}
.dm-group-user-row:hover { background: var(--bg-hover); }
.dm-group-user-row img, .dm-group-user-row .avatar-fallback { width: 24px; height: 24px; border-radius: 50%; }
.dm-group-user-row input[type="checkbox"] { accent-color: var(--blurple); width: 16px; height: 16px; }

/* v9b: DM header buttons — .header-toggle-btn is display:none on desktop (it
   is the mobile drawer-button base class); these must render like the pinned
   button does. First one carries the right-alignment. */
.dm-header-btn { display: flex; }
#dm-call-btn { margin-left: auto; }

/* ===================== v10: permissions / categories / moderation / mentions ===================== */

/* Category sections in the channel sidebar */
.category-section { margin-bottom: 4px; }
.category-header {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 8px 2px 10px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.4px;
  color: var(--text-muted, #949ba4); cursor: pointer; user-select: none;
  text-transform: uppercase;
}
.category-header:hover { color: #dbdee1; }
.category-arrow { font-size: 9px; transition: transform 0.12s ease; }
.category-section.collapsed .category-arrow { transform: rotate(-90deg); }
.category-section.collapsed .category-children .channel-item:not(.active):not(.has-unread) { display: none; }
.category-section.collapsed .category-children .voice-channel-users { display: none; }

/* Red mention badge on channel rows + DM rows */
.channel-mention-badge {
  margin-left: auto; min-width: 16px; height: 16px; border-radius: 8px;
  background: #f23f43; color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 5px; flex: none;
}

/* Message highlighted when I'm mentioned */
.message-item.mentioned {
  background: rgba(250, 168, 26, 0.08);
  box-shadow: inset 2px 0 0 #faa61a;
}
.message-item.mentioned:hover { background: rgba(250, 168, 26, 0.12); }
.mention-pill.mention-self { background: rgba(88, 101, 242, 0.5); color: #fff; }

/* Composer autocomplete (@members, /commands) */
.composer-autocomplete {
  position: absolute; left: 16px; right: 16px; bottom: 76px;
  background: #2b2d31; border: 1px solid #1e1f22; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  max-height: 300px; overflow-y: auto; z-index: 250; padding: 6px;
}
.autocomplete-header {
  font-size: 11px; font-weight: 700; color: #949ba4; letter-spacing: 0.4px;
  padding: 4px 8px; text-transform: uppercase;
}
.autocomplete-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: 4px; cursor: pointer;
  color: #dbdee1; font-size: 14px;
}
.autocomplete-item.selected, .autocomplete-item:hover { background: #35373c; }
.autocomplete-item .autocomplete-usage { color: #949ba4; font-size: 12px; margin-left: auto; }
.autocomplete-item .autocomplete-desc { color: #949ba4; font-size: 12px; }

/* Role permissions grid */
.role-perms-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin-bottom: 8px; }
.role-perm-row {
  display: flex; align-items: flex-start; gap: 8px; padding: 6px 8px;
  border-radius: 4px; cursor: pointer; background: #2b2d31;
}
.role-perm-row:hover { background: #35373c; }
.role-perm-check {
  width: 18px; height: 18px; border-radius: 4px; border: 2px solid #80848e;
  flex: none; margin-top: 1px; display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: transparent;
}
.role-perm-row.checked .role-perm-check { background: #5865f2; border-color: #5865f2; color: #fff; }
.role-perm-name { font-size: 13px; font-weight: 600; color: #dbdee1; }
.role-perm-desc { font-size: 11px; color: #949ba4; margin-top: 1px; }

/* Audit log + bans lists */
.audit-log-list, .bans-list { display: flex; flex-direction: column; gap: 4px; max-width: 640px; }
.audit-row, .ban-row {
  display: flex; align-items: center; gap: 10px;
  background: #2b2d31; border-radius: 6px; padding: 8px 12px; font-size: 13px; color: #dbdee1;
}
.audit-action { font-weight: 700; color: #f0b132; }
.audit-action.audit-danger { color: #f23f43; }
.audit-time, .ban-time { color: #80848e; font-size: 11px; margin-left: auto; flex: none; }
.audit-reason { color: #949ba4; font-style: italic; }
.ban-revoke-btn {
  margin-left: auto; background: #4e5058; color: #fff; border: none; border-radius: 4px;
  padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.ban-revoke-btn:hover { background: #f23f43; }
.settings-empty-hint { color: #949ba4; font-size: 13px; padding: 8px 0; }

/* Member context menu reuses .message-context-menu; nickname on member rows */
.member-nickname-note { color: #80848e; font-size: 11px; }

/* ===================== v11: shop & profile addons ===================== */

.shop-pane {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-primary, #313338);
}
.shop-pane.hidden { display: none; }
.shop-toolbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; border-bottom: 1px solid #26272b; flex: none; flex-wrap: wrap;
}
.shop-title { font-weight: 700; font-size: 16px; color: #f2f3f5; }
.shop-tabs { display: flex; gap: 6px; }
.shop-tab {
  background: none; border: none; color: #b5bac1; font-size: 13px; font-weight: 600;
  padding: 5px 10px; border-radius: 4px; cursor: pointer;
}
.shop-tab:hover { background: #35373c; color: #dbdee1; }
.shop-tab.active { background: #404249; color: #fff; }
.shop-upload-btn { margin-left: auto; width: auto; padding: 7px 14px; font-size: 13px; }
.shop-grid {
  flex: 1; overflow-y: auto; padding: 18px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px;
  align-content: start;
}
.shop-card {
  background: #2b2d31; border-radius: 8px; padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.shop-card-name { font-weight: 700; font-size: 14px; color: #f2f3f5; }
.shop-card-by { font-size: 11px; color: #949ba4; }
.shop-card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.shop-card-btn {
  border: none; border-radius: 4px; padding: 5px 10px; font-size: 12px; font-weight: 600;
  cursor: pointer; background: #4e5058; color: #fff;
}
.shop-card-btn:hover { background: #6d6f78; }
.shop-card-btn.primary { background: #5865f2; }
.shop-card-btn.primary:hover { background: #4752c4; }
.shop-card-btn.danger:hover { background: #f23f43; }
.shop-empty-hint { color: #949ba4; font-size: 13px; grid-column: 1 / -1; }

/* Aspect frames — the same frame renders shop previews, editor and worn addons */
.addon-frame { position: relative; overflow: hidden; background: #1e1f22; border-radius: 6px; width: 100%; }
.addon-frame.avatar_decoration { aspect-ratio: 1 / 1; border-radius: 50%; }
.addon-frame.profile_effect { aspect-ratio: 2 / 3; }
.addon-frame.nameplate { aspect-ratio: 5 / 1; }
.addon-frame > img, .addon-frame > video {
  position: absolute; display: block; max-width: none;
}
/* In-context previews (shop cards + editor stage) */
.addon-preview {
  display: flex; justify-content: center; align-items: center;
  background: #1e1f22; border-radius: 8px; padding: 14px; min-height: 110px;
}
.addon-preview.nameplate { display: block; }
.addon-preview-avatar { position: relative; display: inline-block; line-height: 0; }
.addon-preview-row { pointer-events: none; }
.addon-preview-row .member-name { color: #dbdee1; }
.addon-preview-card {
  position: relative; overflow: hidden; width: 150px; aspect-ratio: 2 / 3;
  background: #232428; border-radius: 8px;
}
.addon-preview-banner { height: 34%; }
.addon-preview-card-body {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  margin-top: -22px;
}
.addon-preview-card-body img, .addon-preview-card-body .avatar-fallback {
  border: 3px solid #232428; border-radius: 50%;
}
.addon-preview-card-name { font-size: 13px; font-weight: 600; color: #f2f3f5; }

/* Editor stage */
.addon-editor-stage {
  width: 100%; max-width: 340px; margin: 6px auto 0;
  cursor: grab; user-select: none; border: 2px dashed #5865f2; border-radius: 6px;
}
.addon-editor-stage:active { cursor: grabbing; }
.addon-editor-stage .addon-preview { min-height: 150px; }
.addon-editor-stage .addon-preview-card { width: 190px; }
.addon-editor-stage .addon-preview img, .addon-editor-stage .addon-preview video {
  -webkit-user-drag: none;
}
.addon-file-name { font-size: 12px; color: #949ba4; margin-left: 8px; }
.addon-public-row {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  font-size: 13px; color: #dbdee1; cursor: pointer;
}

/* Worn: avatar decoration overlay */
.avatar-decor-wrap { position: relative; display: inline-block; flex-shrink: 0; line-height: 0; }
.avatar-decoration-overlay {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 132%; height: 132%; pointer-events: none; z-index: 2;
}
.avatar-decoration-overlay .addon-frame { background: none; border-radius: 50%; width: 100%; height: 100%; }

/* Worn: nameplate behind member rows */
.member-item { position: relative; overflow: hidden; }
.member-nameplate-bg {
  position: absolute; inset: 0; pointer-events: none; z-index: 0; opacity: 0.55;
  -webkit-mask-image: linear-gradient(to left, rgba(0,0,0,1), rgba(0,0,0,0) 85%);
  mask-image: linear-gradient(to left, rgba(0,0,0,1), rgba(0,0,0,0) 85%);
}
.member-nameplate-bg { overflow: hidden; }
.member-nameplate-bg img, .member-nameplate-bg video {
  position: absolute; display: block; max-width: none;
}
.member-item > *:not(.member-nameplate-bg) { position: relative; z-index: 1; }

/* Worn: profile popout effect + nameplate banner */
.profile-popout { overflow: hidden; }
.popout-effect-overlay {
  position: absolute; inset: 0; pointer-events: none; z-index: 5;
}
.popout-effect-overlay { overflow: hidden; }
.popout-effect-overlay img, .popout-effect-overlay video {
  position: absolute; display: block; max-width: none; opacity: 0.9;
}
.popout-banner { position: relative; overflow: hidden; }
.popout-banner .popout-nameplate-media {
  position: absolute; display: block; max-width: none;
}

/* ===================== Contract v12 ===================== */

/* ----- §A: channel permissions editor ----- */
.channel-perms-modal { width: 720px; max-width: 94vw; }
.channel-perms-body { display: flex; gap: 16px; min-height: 340px; }
.perms-targets-col { width: 220px; flex-shrink: 0; display: flex; flex-direction: column; gap: 8px; }
.perms-target-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.perms-target-item {
  padding: 6px 10px; border-radius: 4px; cursor: pointer; font-size: 14px;
  color: var(--text-muted, #b5bac1); display: flex; align-items: center; gap: 6px;
}
.perms-target-item:hover { background: rgba(78,80,88,0.3); }
.perms-target-item.active { background: rgba(78,80,88,0.6); color: #fff; }
.perms-target-item .perms-target-kind { font-size: 11px; opacity: 0.6; margin-left: auto; }
.perms-grid-col { flex: 1; min-width: 0; }
.perm-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 4px; border-bottom: 1px solid rgba(78,80,88,0.35);
}
.perm-row-name { font-size: 14px; color: #dbdee1; }
.perm-row-desc { font-size: 11.5px; color: #949ba4; margin-top: 2px; }
.perm-tristate { display: flex; border-radius: 4px; overflow: hidden; border: 1px solid rgba(78,80,88,0.6); flex-shrink: 0; }
.perm-tristate button {
  width: 34px; height: 26px; background: #2b2d31; color: #949ba4; border: none;
  cursor: pointer; font-size: 13px; font-weight: 700;
}
.perm-tristate button:not(:last-child) { border-right: 1px solid rgba(78,80,88,0.6); }
.perm-tristate button.sel-deny { background: #da373c; color: #fff; }
.perm-tristate button.sel-neutral { background: #4e5058; color: #fff; }
.perm-tristate button.sel-allow { background: #248046; color: #fff; }

/* channel row gear (visible on hover for managers) */
.channel-gear {
  margin-left: auto; opacity: 0; font-size: 12px; padding: 0 2px;
  cursor: pointer; flex-shrink: 0;
}
.channel-item:hover .channel-gear { opacity: 0.7; }
.channel-gear:hover { opacity: 1 !important; }

/* ----- §B/§C: integrations ----- */
.integrations-block { margin-top: 18px; max-width: 640px; }
.bots-list, .webhooks-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.bot-row, .webhook-row {
  background: #2b2d31; border-radius: 8px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.bot-row-head, .webhook-row-head { display: flex; align-items: center; gap: 8px; }
.bot-row-name, .webhook-row-name { font-weight: 600; color: #f2f3f5; }
.bot-row-head .danger-link, .webhook-row-head .danger-link {
  margin-left: auto; color: #da373c; cursor: pointer; font-size: 12.5px; background: none; border: none;
}
.bot-token-row, .webhook-url-row { display: flex; align-items: center; gap: 6px; }
.bot-token-row code, .webhook-url-row code {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: #1e1f22; padding: 4px 8px; border-radius: 4px; font-size: 12px; color: #b5bac1;
}
.bot-copy-btn {
  background: #4e5058; border: none; color: #fff; border-radius: 4px;
  padding: 4px 10px; cursor: pointer; font-size: 12px; flex-shrink: 0;
}
.bot-events-row { display: flex; gap: 14px; font-size: 13px; color: #b5bac1; align-items: center; flex-wrap: wrap; }
.bot-events-row label { display: flex; gap: 5px; align-items: center; cursor: pointer; }
.bot-events-row input[type="text"] { flex: 1; min-width: 160px; }
.bot-create-row, .webhook-create-row { display: flex; gap: 8px; margin-top: 10px; }
.bot-create-row input { flex: 1; }
.webhook-create-row select { width: 180px; flex-shrink: 0; }
.webhook-create-row input { flex: 1; }

/* BOT / APP chips */
.bot-badge {
  background: #5865f2; color: #fff; font-size: 10px; font-weight: 700;
  border-radius: 3px; padding: 1px 4px; margin-left: 4px; vertical-align: middle;
  flex-shrink: 0; letter-spacing: 0.3px;
}
.bot-badge.app { background: #248046; }

/* ----- §D: discovery ----- */
.discover-pane { flex: 1; overflow-y: auto; padding: 0 0 32px; }
.discover-hero {
  background: linear-gradient(135deg, #3b428f 0%, #5865f2 55%, #7c87f5 100%);
  padding: 44px 24px 36px; display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.discover-hero-title { font-size: 22px; font-weight: 800; color: #fff; }
.discover-search { width: min(560px, 90%); }
.discover-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px; padding: 20px 24px;
}
.discover-card {
  background: #2b2d31; border-radius: 10px; padding: 14px; display: flex;
  flex-direction: column; gap: 8px;
}
.discover-card-head { display: flex; align-items: center; gap: 10px; }
.discover-card-icon {
  width: 44px; height: 44px; border-radius: 12px; background: #5865f2; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  font-size: 18px; overflow: hidden; flex-shrink: 0;
}
.discover-card-icon img { width: 100%; height: 100%; object-fit: cover; }
.discover-card-name { font-weight: 700; color: #f2f3f5; }
.discover-card-desc { font-size: 13px; color: #b5bac1; min-height: 34px; }
.discover-card-meta { font-size: 12px; color: #949ba4; }
.discover-card-join {
  align-self: flex-start; background: #248046; color: #fff; border: none;
  border-radius: 4px; padding: 6px 14px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.discover-card-join[disabled] { background: #4e5058; cursor: default; }
.discover-empty { color: #949ba4; padding: 24px; text-align: center; grid-column: 1 / -1; }

/* ----- §E: stage channels ----- */
.stage-checkbox-row {
  display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: #b5bac1;
  margin-top: 10px; cursor: pointer; line-height: 1.4;
}
.stage-checkbox-row input { margin-top: 2px; }
.stage-audience {
  border-top: 1px solid rgba(78,80,88,0.5); padding: 10px 18px 4px; max-height: 30%;
  overflow-y: auto;
}
.stage-audience-header { font-size: 11px; font-weight: 700; letter-spacing: 0.4px; color: #949ba4; margin-bottom: 6px; }
.stage-audience-row {
  display: flex; align-items: center; gap: 8px; padding: 4px 2px; font-size: 14px; color: #dbdee1;
}
.stage-audience-row .stage-hand { font-size: 14px; }
.stage-mod-btn {
  margin-left: auto; background: #4e5058; color: #fff; border: none; border-radius: 4px;
  padding: 3px 9px; cursor: pointer; font-size: 12px;
}
.stage-mod-btn:hover { background: #5865f2; }
.stage-role-pill {
  font-size: 10px; font-weight: 700; border-radius: 3px; padding: 1px 5px;
  background: #4e5058; color: #dbdee1; flex-shrink: 0;
}
.voice-tile .stage-mod-btn { position: absolute; bottom: 8px; right: 8px; z-index: 3; opacity: 0; }
.voice-tile:hover .stage-mod-btn { opacity: 1; }

/* ======================== CONTRACT v13 ======================== */

/* Threads (§A) */
.thread-chip {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 4px; padding: 4px 10px;
  background: var(--bg-sidebar); border: 1px solid var(--bg-active);
  border-radius: 6px; cursor: pointer; font-size: 13px; max-width: 480px;
}
.thread-chip:hover { background: var(--bg-hover); border-color: var(--blurple); }
.thread-chip-icon { font-size: 13px; }
.thread-chip-name {
  color: var(--blurple); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px;
}
.thread-chip-count { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.thread-chip.archived .thread-chip-name { color: var(--text-muted); }

.threads-popover { right: 96px; }
.threads-popover-new {
  margin-left: auto; background: none; border: none; color: var(--text-secondary);
  cursor: pointer; font-size: 12px; padding: 2px 6px; border-radius: 4px;
}
.threads-popover-new:hover { color: var(--text-bright); background: var(--bg-hover); }
.thread-list-row {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.thread-list-row:hover { background: var(--bg-hover); }
.thread-list-main { flex: 1; min-width: 0; }
.thread-list-name {
  font-weight: 600; color: var(--text-normal);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-list-row.archived .thread-list-name { color: var(--text-muted); }
.thread-list-sub { font-size: 12px; color: var(--text-muted); }

/* Friends (§B) */
.friends-tabs {
  display: flex; gap: 8px; align-items: center;
  padding: 12px 16px 0; flex-wrap: wrap;
}
.friends-tab {
  background: none; border: none; color: var(--text-secondary);
  padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 15px;
  display: inline-flex; align-items: center; gap: 6px;
}
.friends-tab:hover { background: var(--bg-hover); color: var(--text-normal); }
.friends-tab.active { background: var(--bg-active); color: var(--text-bright); }
.friends-tab-add { background: var(--green); color: #fff; font-weight: 600; }
.friends-tab-add.active { background: none; color: var(--green); }
.friends-pending-badge {
  background: var(--red); color: #fff; border-radius: 8px;
  font-size: 11px; font-weight: 700; padding: 1px 6px; min-width: 16px; text-align: center;
}
.friends-add-box { padding: 16px; }
.friends-add-row { display: flex; gap: 8px; }
.friends-add-row .modal-input { flex: 1; }
.friends-add-status { margin-top: 8px; font-size: 13px; min-height: 18px; }
.friends-add-status.ok { color: var(--green); }
.friends-add-status.err { color: var(--red); }
.friends-empty { padding: 24px 16px; color: var(--text-muted); font-size: 14px; }
.friends-section-head { margin-top: 10px; }
.friend-btn-danger:hover { color: var(--red); }

/* Per-server profile modal (§C) */
.sp-bio { resize: vertical; font-family: inherit; }
.sp-banner-row, .sp-avatar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.sp-banner-row input[type="color"] {
  width: 44px; height: 30px; padding: 2px; border: none;
  background: var(--bg-input); border-radius: 4px; cursor: pointer;
}
.sp-avatar-preview {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover;
  border: 2px solid var(--bg-active);
}
.sp-inline-hint { margin: 0; font-size: 12px; color: var(--text-muted); }
.dm-profile-friend-btn {
  display: block; width: 100%; margin-top: 8px; padding: 7px 10px;
  background: var(--blurple); color: #fff; border: none; border-radius: 4px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.dm-profile-friend-btn:hover { background: var(--blurple-hover); }
.dm-profile-friend-btn.danger { background: var(--bg-active); color: var(--red); }
.dm-profile-friend-btn.danger:hover { background: var(--red); color: #fff; }
/* v13 fix: .header-toggle-btn base is display:none (mobile drawer class) —
   like .pinned-toggle-btn, these must opt in to render on desktop. */
.threads-toggle-btn, #thread-back-btn { display: flex; }

/* ======================== CONTRACT v14 — background effects ======================== */

/* Host/canvas layering: isolate makes negative z-index paint above the host's
   own background but below all its content. */
.fx-host { position: relative; isolation: isolate; overflow: hidden; }
.fx-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; }

/* Tier-1 CSS presets (aurora sweep, scanlines) */
[data-fx="aurora"] {
  background: linear-gradient(120deg, var(--fx-color, #00e5e5), #16171b, var(--fx-color, #00e5e5)) !important;
  background-size: 300% 300% !important;
  animation: fx-aurora-shift var(--fx-speed, 8s) ease infinite;
}
@keyframes fx-aurora-shift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
[data-fx="scanlines"]::after {
  content: "";
  position: absolute; inset: 0; z-index: -1;
  background: repeating-linear-gradient(
    0deg,
    color-mix(in srgb, var(--fx-color, #00e5e5) 14%, transparent) 0px,
    transparent 1px, transparent 3px
  );
  pointer-events: none;
}

/* VC speaking-indicator upgrade: rings pulse in the user's effect color while
   the analyser marks them speaking. */
.voice-tile.speaking[data-vc-effect="pulse-ring"] {
  animation: fx-pulse-ring 1.2s ease-out infinite;
}
@keyframes fx-pulse-ring {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--fx-color, #00e5e5) 60%, transparent); }
  100% { box-shadow: 0 0 0 14px transparent; }
}

/* Channel ambiance (mod-set, CSS-only — cheap for every client) */
#chat-pane[data-ambiance] { background-color: transparent; }
#chat-pane[data-ambiance="gradient-pulse"] {
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--amb-a, #8b0000) 26%, transparent), transparent 60%),
    radial-gradient(circle at bottom right, color-mix(in srgb, var(--amb-b, #00e5e5) 22%, transparent), transparent 60%);
  animation: fx-ambiance-breathe 12s ease-in-out infinite;
}
@keyframes fx-ambiance-breathe {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.12); }
}
#chat-pane[data-ambiance="scanlines"] {
  background: repeating-linear-gradient(
    0deg,
    color-mix(in srgb, var(--amb-b, #00e5e5) 5%, transparent) 0px,
    transparent 1px, transparent 4px
  );
}
#chat-pane[data-ambiance="starfield"] {
  background-image:
    radial-gradient(1px 1px at 12% 24%, color-mix(in srgb, var(--amb-b, #00e5e5) 80%, transparent), transparent 55%),
    radial-gradient(1px 1px at 34% 68%, color-mix(in srgb, var(--amb-a, #8b0000) 85%, transparent), transparent 55%),
    radial-gradient(1.5px 1.5px at 56% 12%, color-mix(in srgb, var(--amb-b, #00e5e5) 70%, transparent), transparent 55%),
    radial-gradient(1px 1px at 71% 47%, color-mix(in srgb, var(--amb-b, #00e5e5) 85%, transparent), transparent 55%),
    radial-gradient(1.5px 1.5px at 88% 81%, color-mix(in srgb, var(--amb-a, #8b0000) 75%, transparent), transparent 55%),
    radial-gradient(1px 1px at 23% 89%, color-mix(in srgb, var(--amb-b, #00e5e5) 65%, transparent), transparent 55%),
    radial-gradient(1px 1px at 92% 15%, color-mix(in srgb, var(--amb-b, #00e5e5) 75%, transparent), transparent 55%);
  background-size: 260px 260px;
  animation: fx-star-drift 90s linear infinite;
}
@keyframes fx-star-drift {
  from { background-position: 0 0; }
  to   { background-position: -260px 260px; }
}

/* Settings picker bits */
.fx-controls-row { display: flex; gap: 16px; align-items: flex-end; }
.fx-intensity-col { flex: 1; }
.ambiance-btn { display: flex; }

/* Guide §5: reduced motion freezes every effect */
@media (prefers-reduced-motion: reduce) {
  [data-fx], [data-fx]::after, [data-ambiance], .voice-tile.speaking[data-vc-effect] {
    animation: none !important;
  }
}
