:root {
  --bg: #0b0e13;
  --bg-2: #11151d;
  --panel: #151a23;
  --panel-2: #1b212c;
  --line: #28313f;
  --line-2: #344052;
  --text: #e7ecf3;
  --muted: #8b97a8;
  --muted-2: #6b7688;
  --accent: #5b8cff;
  --accent-d: #3f6fe0;
  --green: #38d39f;
  --red: #ff6b6b;
  --me: #3a63d8;
  --them: #232c3a;
  --shadow: 0 14px 50px rgba(0,0,0,.45);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14.5px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
body { height: 100vh; height: 100dvh; overflow: hidden; }
.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* buttons */
.primary {
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  padding: 11px 16px; font-size: 14.5px; font-weight: 600; transition: filter .15s, opacity .15s;
}
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: .45; cursor: not-allowed; }
.ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--line-2);
  border-radius: 10px; padding: 10px 14px; font-size: 14px; font-weight: 500;
}
.ghost:hover { color: var(--text); border-color: var(--accent); }
.icon {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  width: 36px; height: 36px; border-radius: 9px; font-size: 17px; line-height: 1;
}
.icon:hover { background: var(--panel-2); color: var(--text); }

input, textarea, select {
  width: 100%; padding: 11px 13px; background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; font-size: 14.5px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; }
label { display: block; font-size: 12.5px; color: var(--muted); margin: 12px 0 6px; }

/* ============ AUTH ============ */
.auth {
  height: 100vh; height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; background: radial-gradient(900px 500px at 50% -5%, #18202f, var(--bg));
}
.auth-card {
  width: min(420px, 92vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 26px; box-shadow: var(--shadow);
}
.brand { font-size: 24px; display: flex; align-items: center; gap: 10px; }
.brand .logo {
  width: 30px; height: 30px; display: inline-block; flex: 0 0 30px;
  background: url("/icon.svg") center/contain no-repeat;
}
.tagline { color: var(--muted); margin: 6px 0 20px; font-size: 13.5px; }
.tabs { display: flex; gap: 6px; background: var(--bg-2); padding: 5px; border-radius: 11px; margin-bottom: 18px; }
.tab {
  flex: 1; background: transparent; border: none; color: var(--muted);
  padding: 9px; border-radius: 8px; font-size: 14px; font-weight: 600;
}
.tab.active { background: var(--panel-2); color: var(--text); }
.auth-form .primary { width: 100%; margin-top: 18px; }
.auth-error { color: var(--red); font-size: 13px; min-height: 18px; margin: 10px 0 0; }
.cryptoline { color: var(--muted-2); font-size: 11.5px; letter-spacing: .3px; }

/* ============ APP LAYOUT ============ */
.app { height: 100vh; height: 100dvh; display: grid; grid-template-columns: 340px 1fr; }
.sidebar { background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.main { display: flex; flex-direction: column; min-height: 0; }

/* me bar */
.me-bar { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px; border-bottom: 1px solid var(--line); }
.me-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-name { font-weight: 600; }
.me-handle { color: var(--muted); font-size: 12px; }
.me-actions { display: flex; gap: 2px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 38px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 15px; background: linear-gradient(135deg, var(--accent), #8a5bff);
}
.avatar.lg { width: 42px; height: 42px; flex-basis: 42px; }

/* search */
.search-row { display: flex; gap: 8px; padding: 12px 14px; }
.search-results { max-height: 240px; overflow-y: auto; border-bottom: 1px solid var(--line); }
.search-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; gap: 10px; }
.search-item .si-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.search-item .si-id > div { min-width: 0; }
.search-item:hover { background: var(--panel); }
.search-item .si-name { font-weight: 600; }
.search-item .si-handle { color: var(--muted); font-size: 12px; }
.search-item .primary { padding: 6px 12px; font-size: 13px; }

/* conversation list */
.conv-list { flex: 1; overflow-y: auto; min-height: 0; }
.conv {
  display: flex; align-items: center; gap: 11px; padding: 11px 14px; border-bottom: 1px solid rgba(40,49,63,.5);
}
.conv:hover { background: var(--panel); }
.conv.active { background: var(--panel-2); }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.conv-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { color: var(--muted-2); font-size: 11px; flex: 0 0 auto; }
.conv-preview { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 1px 7px; margin-left: 6px;
}
.presence { position: relative; }
.presence .pdot {
  position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px;
  border-radius: 50%; border: 2px solid var(--bg-2); background: var(--muted-2);
}
.presence .pdot.on { background: var(--green); }

.conn-status { padding: 9px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); margin-right: 4px; }
.dot.on { background: var(--green); box-shadow: 0 0 7px var(--green); }
.dot.off { background: var(--red); }

/* empty state */
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; }
.empty-logo { font-size: 46px; opacity: .6; margin-bottom: 8px; }
.empty h2 { margin: 0 0 6px; color: var(--text); font-weight: 600; }

/* conversation */
.conversation { display: flex; flex-direction: column; min-height: 0; flex: 1; position: relative; }
.conv-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.backBtn { display: none; }
.conv-id { display: flex; align-items: center; gap: 11px; min-width: 0; }
.conv-id > div { min-width: 0; }
.conv-title, .conv-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-title { font-weight: 600; }
.conv-sub { color: var(--muted); font-size: 12.5px; }
.conv-tools { display: flex; align-items: center; gap: 8px; }
.disappear { width: auto; padding: 7px 10px; font-size: 12.5px; color: var(--muted); }

.safety-drawer { background: var(--panel-2); border-bottom: 1px solid var(--line); padding: 14px 18px; font-size: 12.5px; color: var(--muted); }
.safety-drawer pre {
  font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--green);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 11px;
  white-space: pre-wrap; word-break: break-word; letter-spacing: 1px; margin: 8px 0;
}
.verify-row { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; margin-top: 8px; }
.verify-row input { width: auto; }

.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 7px; min-height: 0; }
.msg { max-width: 70%; width: fit-content; padding: 8px 12px; border-radius: 14px; overflow-wrap: anywhere; position: relative; }
.msg.me { align-self: flex-end; background: var(--me); color: #fff; border-bottom-right-radius: 4px; }
.msg.them { align-self: flex-start; background: var(--them); border-bottom-left-radius: 4px; }
.msg .text { white-space: pre-wrap; }
.msg .sender { font-size: 11px; color: var(--accent); font-weight: 600; margin-bottom: 2px; }
/* emoji-only messages render large (Discord-style) */
.msg.emoji-jumbo, .msg.emoji-big { background: transparent !important; padding: 2px 4px; }
.msg.emoji-jumbo .text { font-size: 3.4em; line-height: 1.15; }
.msg.emoji-big .text { font-size: 2em; line-height: 1.2; }
.msg.emoji-jumbo .meta, .msg.emoji-big .meta { opacity: .55; }
/* @mentions */
.mention { color: var(--accent); font-weight: 600; background: rgba(91,140,255,.14); border-radius: 5px; padding: 0 3px; }
.msg.me .mention { color: #dce8ff; background: rgba(255,255,255,.18); }
.mention.me-mention { background: rgba(255,193,7,.22); color: #ffcf4d; }
.msg .meta { font-size: 10.5px; opacity: .65; margin-top: 3px; display: flex; gap: 5px; justify-content: flex-end; align-items: center; }
.msg .ticks { font-size: 11px; opacity: 1; }
.msg .ticks.read { color: #2f9bff; font-weight: 700; }
/* the read tick reads through the meta row's dimming — keep it crisp */
.msg .meta:has(.ticks.read) { opacity: .85; }
.msg.disappearing { box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); }
.sysmsg { align-self: center; color: var(--muted-2); font-size: 12px; padding: 3px 0; }

.typing { padding: 0 18px 6px; color: var(--muted); font-size: 12.5px; font-style: italic; }
.composer { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); }
.composer input { flex: 1; }

/* ============ MODALS ============ */
.modal-layer { position: fixed; inset: 0; background: rgba(5,8,12,.66); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { width: min(460px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 8px; }
.modal p { color: var(--muted); font-size: 13.5px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.code-box {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; letter-spacing: 1.5px;
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 10px; padding: 14px;
  color: var(--green); white-space: pre-wrap; word-break: break-all; line-height: 1.8; margin: 14px 0 10px;
}
#enterAppBtn { width: 100%; margin-top: 14px; }
.muted-note { color: var(--muted-2); font-weight: 400; font-size: 11.5px; }
.group-members { display: flex; flex-direction: column; gap: 6px; max-height: 230px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; margin-top: 6px; padding: 6px; }
.gm-item .primary, .gm-item .ghost { padding: 5px 11px; font-size: 12.5px; }
.gm-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; }
.gm-item:hover { background: var(--panel-2); }
.gm-item input { width: auto; }
.gm-item .si-handle { color: var(--muted); font-size: 12px; }

/* Clickable person card (group member picker): pfp + name + @username */
.gm-card {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 8px 10px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 11px; cursor: pointer; color: var(--text); font: inherit;
}
.gm-card:hover { border-color: var(--accent); background: var(--panel-2); }
.gm-card.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--bg-2)); }
.gm-card .avatar.sm { flex: 0 0 auto; }
.gm-card-main { flex: 1; min-width: 0; }
.gm-card-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gm-card .si-handle { color: var(--muted); font-size: 12px; }
.gm-card-pick { flex: 0 0 auto; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--panel-2); color: var(--accent); font-weight: 700; font-size: 14px; }
.gm-card.selected .gm-card-pick { background: var(--accent); color: #fff; }
.gm-empty { padding: 14px 12px; color: var(--muted); font-size: 13px; text-align: center; }

/* ============ MOBILE / RESPONSIVE ============ */
@media (max-width: 760px) {
  /* One column: show the conversation LIST first; a tapped chat takes over. */
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: none; }
  .main { display: none; }                       /* hidden until a chat is opened */
  .app.show-chat .sidebar { display: none; }
  .app.show-chat .main { display: flex; }

  /* Back button returns to the list (hidden on desktop). */
  .backBtn { display: inline-flex; align-items: center; justify-content: center; font-size: 24px; margin-right: 2px; }

  .conv-header { padding: 11px 12px; }
  .conv-tools { gap: 4px; }
  .disappear { max-width: 132px; }

  .messages { padding: 14px 12px; }
  .msg { max-width: 85%; }
  .composer { padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }

  /* 16px inputs stop iOS Safari from auto-zooming on focus. */
  input, textarea, select { font-size: 16px; }

  .modal { padding: 18px; border-radius: 14px; }
  .code-box { font-size: 13px; letter-spacing: 1px; line-height: 1.7; }
  .me-bar, .search-row { padding-left: 12px; padding-right: 12px; }
}

/* Extra room on very small phones */
@media (max-width: 380px) {
  .msg { max-width: 90%; }
  .avatar { width: 34px; height: 34px; flex-basis: 34px; font-size: 13px; }
  .me-name { font-size: 14px; }
}

/* ============ THEMES (data-theme on <html>) — 10 total ============ */
/* midnight = default (:root). The rest override the surface palette. */
html[data-theme="abyss"]    { --bg: #000000; --bg-2: #0a0a0c; --panel: #0e0e12; --panel-2: #16161c; --line: #20202a; --line-2: #2c2c38; }
html[data-theme="slate"]    { --bg: #0f141a; --bg-2: #151b22; --panel: #1a212a; --panel-2: #222c38; --line: #2c3744; --line-2: #3a4757; }
html[data-theme="royal"]    { --bg: #0e0a18; --bg-2: #140e22; --panel: #1a1230; --panel-2: #241844; --line: #322052; --line-2: #43306a; }
html[data-theme="forest"]   { --bg: #0a1410; --bg-2: #0f1c16; --panel: #13241c; --panel-2: #1b3328; --line: #244234; --line-2: #305442; }
html[data-theme="ocean"]    { --bg: #07131c; --bg-2: #0b1c28; --panel: #0f2433; --panel-2: #163345; --line: #1f4357; --line-2: #2b566d; }
html[data-theme="crimson"]  { --bg: #160a0c; --bg-2: #201013; --panel: #2a161a; --panel-2: #381e23; --line: #4a2830; --line-2: #5e333d; }
html[data-theme="sand"]     { --bg: #14110b; --bg-2: #1d1810; --panel: #251f15; --panel-2: #33291c; --line: #443827; --line-2: #564832; }
html[data-theme="grape"]    { --bg: #120a16; --bg-2: #1a0f20; --panel: #22142b; --panel-2: #301c3d; --line: #422a52; --line-2: #543668; }
html[data-theme="mono"]     { --bg: #0c0c0d; --bg-2: #141416; --panel: #1a1a1d; --panel-2: #232327; --line: #2e2e33; --line-2: #3c3c43; }

/* ============ ACCENTS (data-accent on <html>) — 10 total ============ */
/* blue = default (:root). */
html[data-accent="green"]   { --accent: #2bb673; --accent-d: #1f8f59; --me: #1f9d63; }
html[data-accent="purple"]  { --accent: #8a5bff; --accent-d: #6f3fe0; --me: #7a4be0; }
html[data-accent="pink"]    { --accent: #ff5b9c; --accent-d: #e03f80; --me: #e0497f; }
html[data-accent="orange"]  { --accent: #f59e3f; --accent-d: #e0851f; --me: #d98233; }
html[data-accent="red"]     { --accent: #ff5a5a; --accent-d: #e03f3f; --me: #d84747; }
html[data-accent="teal"]    { --accent: #18c2c2; --accent-d: #0f9b9b; --me: #149e9e; }
html[data-accent="gold"]    { --accent: #e7b831; --accent-d: #c99a1c; --me: #c79f2f; }
html[data-accent="indigo"]  { --accent: #6d6cff; --accent-d: #524fe0; --me: #5b59e0; }
html[data-accent="rose"]    { --accent: #ff7a9a; --accent-d: #e85d80; --me: #e06384; }

/* ============ TEXT SIZE (data-font) ============ */
/* Drives a variable that message bubbles + composer consume directly, so the
   change is actually visible (root font-size alone wouldn't affect px rules). */
html            { --msg-size: 15px; }
html[data-font="small"]  { --msg-size: 13px; }
html[data-font="normal"] { --msg-size: 15px; }
html[data-font="large"]  { --msg-size: 17.5px; }
html[data-font="xlarge"] { --msg-size: 20px; }
.msg .text { font-size: var(--msg-size); }
#msgInput { font-size: var(--msg-size); }
.msg .sender { font-size: calc(var(--msg-size) - 3px); }

/* ============ BUBBLE STYLE (data-bubble) ============ */
html[data-bubble="sharp"] .msg { border-radius: 5px; }
html[data-bubble="pill"]  .msg { border-radius: 18px; }

/* ============ WALLPAPER (data-wallpaper) ============ */
html[data-wallpaper="dots"] .messages { background-image: radial-gradient(rgba(255,255,255,.045) 1px, transparent 1px); background-size: 18px 18px; }
html[data-wallpaper="grid"] .messages { background-image: linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px); background-size: 24px 24px; }
html[data-wallpaper="glow"] .messages { background-image: radial-gradient(600px 300px at 50% 0%, rgba(91,140,255,.08), transparent); }

/* ============ COMPACT + NO-AVATARS ============ */
html.compact .messages { gap: 3px; }
html.compact .msg { padding: 5px 10px; }
html.compact .conv { padding: 7px 14px; }
html.no-avatars .conv .avatar { display: none; }

/* ============ PRIVACY BLUR ============ */
body.privacy-blur .app { filter: blur(16px); transition: filter .15s; }

/* ============ SETTINGS PANEL ============ */
.modal-lg { width: min(560px, 94vw); padding: 0; max-height: 88vh; display: flex; flex-direction: column; }
.settings-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.settings-head h2 { margin: 0; }
.settings-body { overflow-y: auto; padding: 8px 22px 16px; flex: 1; }
.settings-section { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent); font-weight: 700; margin: 18px 0 8px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px solid rgba(128,140,160,.08); }
.set-row-col { flex-direction: column; align-items: stretch; gap: 6px; }
.set-label { font-size: 14px; }
.set-help { font-size: 11.5px; color: var(--muted); margin-top: 2px; max-width: 360px; }
.set-control { flex: 0 0 auto; }
.set-control select { width: auto; min-width: 130px; padding: 7px 10px; font-size: 13px; }
.set-row-col .set-control { width: 100%; }
.set-row-col .set-control input { width: 100%; }
.set-control .danger { color: var(--red); border-color: rgba(255,107,107,.4); }
.settings-foot { display: flex; align-items: center; justify-content: space-between; padding: 14px 22px; border-top: 1px solid var(--line); }

/* toggle switch */
.switch { position: relative; display: inline-block; width: 44px; height: 25px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background: var(--line-2); border-radius: 999px; transition: .18s; }
.slider::before { content: ""; position: absolute; height: 19px; width: 19px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .18s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(19px); }

/* ============ LOCK SCREEN ============ */
.lock-screen { position: fixed; inset: 0; z-index: 100; background: rgba(6,9,14,.86); backdrop-filter: blur(22px); display: flex; align-items: center; justify-content: center; }
.lock-card { text-align: center; color: var(--text); }
.lock-logo { font-size: 54px; margin-bottom: 8px; }
.lock-card h2 { margin: 0 0 6px; }
.lock-card p { color: var(--muted); margin: 0 0 18px; }

@media (max-width: 760px) {
  .modal-lg { max-height: 92vh; }
  .settings-head, .settings-body, .settings-foot { padding-left: 16px; padding-right: 16px; }
}

/* ============ PROFILE CARD ============ */
.conv-id { cursor: pointer; border-radius: 10px; }
.conv-id:hover { background: rgba(128,140,160,.08); }
#meAvatar { cursor: pointer; }
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.profile-name { font-size: 19px; font-weight: 700; }
.profile-handle { color: var(--muted); font-size: 13px; }
.profile-presence { color: var(--accent-2, var(--accent)); font-size: 13px; margin-bottom: 14px; }
.profile-bio-label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent); font-weight: 700; margin-bottom: 5px; }
.profile-bio { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-height: 44px; white-space: pre-wrap; word-break: break-word; color: var(--text); }

/* ============ GROUP INFO ============ */
.gi-row { display: flex; align-items: center; gap: 11px; padding: 9px 0; border-bottom: 1px solid rgba(128,140,160,.08); cursor: pointer; }
.gi-row:hover { background: rgba(128,140,160,.05); }
.gi-main { flex: 1; min-width: 0; }
.owner-tag { font-size: 10.5px; font-weight: 700; color: var(--accent); border: 1px solid var(--accent); border-radius: 999px; padding: 1px 7px; margin-left: 4px; }
.ghost.danger { color: var(--red); border-color: rgba(255,107,107,.4); }
.ghost.danger:hover { background: rgba(255,107,107,.1); border-color: var(--red); }

/* profile save button + multiline bio in settings */
.set-row-col textarea { width: 100%; resize: vertical; min-height: 46px; }
#saveProfileBtn { width: 100%; }

/* ============ EMOJI PICKER ============ */
.emoji-btn { font-size: 19px; flex: 0 0 auto; }
.emoji-panel {
  position: absolute; left: 14px; bottom: 72px;
  width: 352px; max-width: calc(100% - 28px);
  background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden; z-index: 40;
}
.emoji-search-row { padding: 10px 10px 6px; }
.emoji-search-row input { padding: 9px 12px; border-radius: 10px; font-size: 14px; }
.emoji-tabs {
  display: flex; gap: 2px; padding: 4px 8px; overflow-x: auto;
  border-bottom: 1px solid var(--line); scrollbar-width: none;
}
.emoji-tabs::-webkit-scrollbar { display: none; }
.emoji-tab {
  flex: 0 0 auto; background: transparent; border: none; cursor: pointer;
  font-size: 18px; line-height: 1; padding: 7px 9px; border-radius: 9px;
  opacity: .6; transition: opacity .12s, background .12s;
}
.emoji-tab:hover { opacity: 1; background: var(--panel-2); }
.emoji-tab.active { opacity: 1; background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--accent); }
.emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 1px;
  padding: 8px; max-height: 240px; overflow-y: auto; overflow-x: hidden;
}
.emoji-cell {
  background: transparent; border: none; cursor: pointer;
  font-size: 23px; line-height: 1; padding: 5px 0; border-radius: 8px;
  transition: background .1s, transform .08s;
}
.emoji-cell:hover { background: var(--panel-2); transform: scale(1.18); }
.emoji-cell:active { transform: scale(.95); }
.emoji-empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 18px; font-size: 13px; }

/* ============ SIDEBAR LIST TABS ============ */
.list-tabs { display: flex; gap: 4px; padding: 4px 10px 8px; }
.list-tab {
  flex: 1; background: transparent; border: 1px solid var(--line);
  color: var(--muted); padding: 7px; border-radius: 9px; font-size: 13px;
  font-weight: 600; cursor: pointer; transition: all .12s;
}
.list-tab:hover { color: var(--text); }
.list-tab.active { background: var(--panel-2); color: var(--text); border-color: var(--accent); }
.list-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 26px 18px; line-height: 1.5; }
.contact-row .contact-open { flex: 0 0 auto; opacity: .7; }
.contact-row .contact-open:hover { opacity: 1; }

/* ============ PROFILE CONTACT STATE ============ */
.profile-contact-row { margin: 12px 0 2px; }
.contact-pill {
  display: inline-block; font-size: 12px; padding: 4px 11px; border-radius: 999px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--muted);
}
.contact-pill.on { color: var(--green); border-color: rgba(56,211,159,.4); }

/* ============ DEVICES (settings) ============ */
.devices-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.device-row {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 11px;
}
.device-ico { font-size: 20px; flex: 0 0 auto; }
.device-main { flex: 1; min-width: 0; }
.device-label { font-weight: 600; font-size: 14px; }
.device-here {
  font-size: 10.5px; font-weight: 700; color: var(--green);
  border: 1px solid rgba(56,211,159,.45); border-radius: 999px; padding: 1px 7px; margin-left: 5px;
}
.device-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.device-remove { flex: 0 0 auto; padding: 6px 12px; font-size: 12.5px; }
.set-current { color: var(--muted); font-size: 13px; margin-right: 10px; }

/* Composer character counter (shows -N when over the 2,000 char limit) */
.char-count {
  align-self: center; flex: 0 0 auto; min-width: 34px; text-align: right;
  font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); user-select: none;
}
.char-count.over { color: var(--red); font-weight: 700; }

/* ============ MOBILE: emoji panel fills width ============ */
@media (max-width: 760px) {
  .emoji-panel { left: 6px; right: 6px; bottom: 64px; max-width: none; }
  .emoji-grid { grid-template-columns: repeat(7, 1fr); }
}

/* ============ CONVERSATION ACTIONS MENU (dropdown) ============ */
.menu-wrap { position: relative; }
.dropdown {
  position: absolute; right: 0; top: 42px; z-index: 45; min-width: 190px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column;
}
.dd-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: transparent; border: none; color: var(--text); cursor: pointer;
  padding: 9px 11px; border-radius: 8px; font-size: 14px;
}
.dd-item:hover { background: var(--panel-2); }
.dd-item.danger { color: var(--red); }
.dd-item.danger:hover { background: rgba(255,107,107,.1); }
.dd-ico { width: 18px; text-align: center; }

/* conv-list flags (pinned / muted) */
.conv-flag { margin-right: 4px; font-size: 11px; opacity: .85; }
.archived-bar {
  width: 100%; text-align: left; background: transparent; border: none; cursor: pointer;
  color: var(--muted); font-size: 13px; font-weight: 600; padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}
.archived-bar:hover { background: var(--panel); color: var(--text); }

/* ============ TOAST ============ */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line-2);
  padding: 10px 18px; border-radius: 999px; font-size: 13.5px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 120;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ GROUP INFO ACTIONS / INVITE ============ */
.gi-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.gi-actions .ghost { padding: 8px 11px; font-size: 13px; }
.gi-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent); font-weight: 700; margin: 6px 0 4px; }
.gi-inline { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.gi-inline label { margin: 0; flex: 0 0 auto; }
.gi-inline input, .gi-inline select { flex: 1; }
.gi-inline-note { color: var(--muted); font-size: 12.5px; padding: 6px 0; }
.gi-add-list { display: flex; flex-direction: column; gap: 4px; padding: 6px 0; }
.gi-add-item { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 8px; cursor: pointer; }
.gi-add-item:hover { background: var(--panel-2); }
.gi-add-item input { width: auto; }
.gi-invite { background: var(--bg-2); border: 1px solid var(--line); border-radius: 11px; padding: 12px; margin-bottom: 10px; }
.gi-invite-link { display: flex; gap: 8px; margin-top: 8px; }
.gi-invite-link input { font-size: 12.5px; }
#giInvResult { margin-top: 8px; }

/* ============ MENTION AUTOCOMPLETE + RENDER ============ */
.mention-box {
  position: absolute; left: 14px; right: 14px; bottom: 68px; max-width: 320px; z-index: 38;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px;
  box-shadow: var(--shadow); padding: 5px; display: flex; flex-direction: column;
}
.mention-item {
  display: flex; align-items: center; gap: 8px; background: transparent; border: none;
  color: var(--text); cursor: pointer; padding: 8px 9px; border-radius: 8px; font-size: 13.5px; text-align: left;
}
.mention-item:hover { background: var(--panel-2); }
.avatar.sm { width: 24px; height: 24px; flex-basis: 24px; font-size: 11px; }

/* ============ LOADING SPLASH ============ */
.splash {
  position: fixed; inset: 0; z-index: 200; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  background: radial-gradient(900px 500px at 50% -5%, #18202f, var(--bg));
  transition: opacity .42s ease;
}
.splash.hide { opacity: 0; pointer-events: none; }
.splash-logo { font-size: 56px; line-height: 1; filter: drop-shadow(0 6px 24px rgba(91,140,255,.35)); animation: splash-pop .5s ease both; }
.splash-name { font-size: 26px; font-weight: 700; letter-spacing: .5px; }
.splash-sub { color: var(--muted); font-size: 13px; }
.splash-spinner {
  width: 30px; height: 30px; margin-top: 4px; border-radius: 50%;
  border: 3px solid var(--line-2); border-top-color: var(--accent);
  animation: splash-spin .8s linear infinite;
}
@keyframes splash-spin { to { transform: rotate(360deg); } }
@keyframes splash-pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ============ SYSTEM LOG TIMESTAMP ============ */
.sysmsg {
  display: inline-flex; align-items: center; gap: 6px; max-width: 80%;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px; margin: 2px auto; text-align: center;
}
.sysmsg .log-time { color: var(--muted-2); font-size: 10.5px; opacity: .85; flex: 0 0 auto; }

/* ============ BLOCKED COMPOSER BAR ============ */
.block-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-top: 1px solid var(--line); background: var(--bg-2);
  color: var(--muted); font-size: 13.5px;
}
.block-bar .ghost { flex: 0 0 auto; }

/* ============ EMOJI PICKER: bigger scroll area ============ */
.emoji-grid { max-height: min(46vh, 300px); }

/* ============ MESSAGE REACTIONS ============ */
.reactions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.msg.me .reactions { justify-content: flex-end; }
.rx {
  display: inline-flex; align-items: center; gap: 4px; font-size: 15px; font-weight: 600;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 3px 10px; line-height: 1.5; cursor: pointer;
  transition: transform .08s, background .12s, border-color .12s;
}
.rx .rx-count { font-size: 12.5px; opacity: .9; }
.rx:hover { transform: scale(1.06); }
.rx.mine { background: rgba(91,140,255,.18); border-color: var(--accent); }
.msg.me .rx { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.2); color: #fff; }
.msg.me .rx.mine { background: rgba(255,255,255,.32); }

/* system log rows get centered reactions under the pill */
.sysrow { align-self: center; display: flex; flex-direction: column; align-items: center; gap: 4px; max-width: 86%; cursor: pointer; }
/* group-icon-change log: the new photo shown above the text */
.log-photo {
  width: 64px; height: 64px; border-radius: 50%; object-fit: cover; cursor: zoom-in;
  border: 2px solid var(--line-2); box-shadow: 0 4px 14px rgba(0,0,0,.35);
}

/* ============ REPLY QUOTE / FORWARD / EDITED / PIN / DELETED ============ */
.reply-quote {
  border-left: 3px solid var(--accent); background: rgba(0,0,0,.16);
  border-radius: 6px; padding: 3px 8px; margin-bottom: 4px; font-size: 12.5px;
  display: flex; flex-direction: column; max-width: 100%;
}
.msg.me .reply-quote { border-left-color: #fff; background: rgba(255,255,255,.14); }
.reply-quote .rq-name { font-weight: 700; font-size: 11.5px; opacity: .9; }
.reply-quote .rq-body { opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fwd-tag { font-size: 11px; opacity: .7; font-style: italic; margin-bottom: 3px; }
.edited { font-size: 10px; opacity: .7; font-style: italic; }
.pin-flag { position: absolute; top: -7px; right: -4px; font-size: 11px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.msg.deleted { opacity: .7; font-style: italic; }
.msg.deleted .text { color: var(--muted); }
.msg.flash { animation: msg-flash 1.1s ease; }
@keyframes msg-flash { 0%, 100% { box-shadow: none; } 25% { box-shadow: 0 0 0 3px var(--accent); } }

/* ============ PINNED BAR (below header) ============ */
.pinned-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  background: var(--panel-2); border-bottom: 1px solid var(--line); cursor: pointer;
}
.pinned-bar:hover { background: var(--panel); }
.pinned-text { flex: 1; min-width: 0; font-size: 12.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinned-text b { color: var(--text); font-weight: 600; }
.pinned-bar .icon { font-size: 12px; width: auto; padding: 0 6px; flex: 0 0 auto; }

/* ============ REPLY / EDIT COMPOSER BAR ============ */
.reply-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  border-top: 1px solid var(--line); background: var(--bg-2);
}
.reply-bar-main { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 9px; }
.reply-bar-label { font-size: 11.5px; font-weight: 700; color: var(--accent); }
.reply-bar-text { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============ MESSAGE ACTION MENU (popover) ============ */
.msg-menu {
  position: fixed; z-index: 220; min-width: 180px; /* above the photo viewer (200) */
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px;
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; gap: 4px;
}
.mm-reactions { display: flex; gap: 3px; padding: 3px; border-bottom: 1px solid var(--line); margin-bottom: 3px; }
.mm-rx {
  flex: 1; background: transparent; border: none; cursor: pointer; font-size: 24px;
  padding: 6px 0; border-radius: 10px; transition: background .1s, transform .08s;
}
.mm-rx:hover { background: var(--panel-2); transform: scale(1.2); }
.mm-actions { display: flex; flex-direction: column; }
.mm-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: transparent; border: none; color: var(--text); cursor: pointer;
  padding: 9px 11px; border-radius: 9px; font-size: 14px;
}
.mm-item:hover { background: var(--panel-2); }
.mm-item.danger { color: var(--red); }
.mm-item.danger:hover { background: rgba(255,107,107,.1); }
.mm-ico { width: 18px; text-align: center; }

/* ============ FORWARD MODAL LIST ============ */
.forward-list { display: flex; flex-direction: column; gap: 2px; max-height: 50vh; overflow-y: auto; margin-top: 6px; }
.fwd-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: transparent; border: none; color: var(--text); cursor: pointer;
  padding: 9px 10px; border-radius: 10px; font-size: 14px;
}
.fwd-item:hover { background: var(--panel-2); }
.fwd-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============ NETWORK / RECONNECTING BANNER ============ */
.net-banner {
  position: fixed; top: env(safe-area-inset-top, 0px); left: 0; right: 0; z-index: 150;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(90deg, #b9821f, #d39a2f); color: #fff;
  font-size: 13px; font-weight: 600; padding: 7px 12px;
  box-shadow: 0 4px 18px rgba(0,0,0,.35); animation: net-slide .25s ease;
}
@keyframes net-slide { from { transform: translateY(-100%); } to { transform: translateY(0); } }
.net-spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.45); border-top-color: #fff;
  animation: splash-spin .7s linear infinite;
}

/* ============ SAFE-AREA / PWA (added-to-home-screen) ============ */
/* When launched from the home screen with a translucent status bar, pad the top
   bars by the safe-area inset so the notch/status bar never overlaps content.
   env() is 0 on desktop, so these are no-ops there. */
.me-bar { padding-top: calc(14px + env(safe-area-inset-top, 0px)); }
.conv-header { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
.auth { padding-top: calc(22px + env(safe-area-inset-top, 0px)); padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px)); }
.composer { padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
.sidebar { padding-bottom: env(safe-area-inset-bottom, 0px); }
/* iOS Safari/standalone: dvh can still be flaky, so fall back to fill-available. */
/* Only fall back to fill-available where dynamic viewport units AREN'T supported.
   On modern iOS, 100dvh is correct; forcing min-height:fill-available there made
   the app taller than the screen and pushed the latest (right-side) messages out
   of view. */
@supports (-webkit-touch-callout: none) and (not (height: 100dvh)) {
  html, body, .app, .auth { height: -webkit-fill-available; }
}

/* ============ AVATAR IMAGES (photos) ============ */
/* The image clips itself to a circle (border-radius), so we DON'T put
   overflow:hidden on .avatar — that would clip the presence dot at its edge. */
.avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.avatar.xl { width: 96px; height: 96px; flex-basis: 96px; font-size: 34px; }

/* ============ MESSAGE ROWS w/ GROUPED AVATARS ============ */
.msg-row { display: flex; align-items: flex-end; gap: 8px; max-width: 78%; }
.msg-row.me { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.them { align-self: flex-start; }
.msg-row .msg { max-width: 100%; }
.msg-av {
  width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%; overflow: hidden;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  font-size: 12px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), #8a5bff); align-self: flex-end; margin-bottom: 2px;
}
.msg-av .avatar-img { width: 100%; height: 100%; object-fit: cover; }
.msg-av.spacer { background: none; visibility: hidden; }
.msg .sender { cursor: pointer; width: fit-content; max-width: 100%; }
.msg .sender:hover { text-decoration: underline; }

/* forwarded-from chip */
.fwd-tag { display: flex; align-items: center; gap: 5px; }
.fwd-av { width: 16px; height: 16px; border-radius: 50%; object-fit: cover; }
.fwd-av-i { display: inline-flex; align-items: center; justify-content: center; font-size: 8px; font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--accent), #8a5bff); }
.fwd-from { font-weight: 700; font-style: normal; cursor: pointer; }
.fwd-from:hover { text-decoration: underline; }

/* ============ PROFILE MODAL (redesigned) ============ */
.profile-modal { padding: 0; overflow: hidden; position: relative; }
.profile-x { position: absolute; top: 12px; right: 12px; z-index: 3; color: #fff; }
.profile-cover {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 30px 22px 22px; gap: 4px;
  background: radial-gradient(120% 120% at 50% -20%, color-mix(in srgb, var(--accent) 45%, transparent), transparent 70%), var(--panel-2);
  border-bottom: 1px solid var(--line);
}
.profile-cover .avatar.xl { box-shadow: 0 8px 30px rgba(0,0,0,.35); cursor: pointer; transition: transform .12s; }
.profile-cover .avatar.xl:hover { transform: scale(1.04); }
.profile-cover .avatar.xl.has-photo { cursor: zoom-in; }
.profile-name { font-size: 21px; font-weight: 700; margin-top: 10px; }
.profile-handle { color: var(--muted); font-size: 14px; }
.profile-presence { color: var(--accent); font-size: 13px; margin-top: 4px; }
.profile-info { padding: 16px 22px; display: flex; flex-direction: column; gap: 14px; }
.profile-field .pf-label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent); font-weight: 700; margin-bottom: 4px; }
.profile-since { font-size: 14px; color: var(--text); }
.profile-modal .modal-actions { padding: 0 22px 20px; }

/* ============ SETTINGS / GROUP AVATAR HEADER ============ */
.settings-avatar-wrap, .gi-photo-row { display: flex; align-items: center; gap: 16px; padding: 6px 0 16px; }
.gi-photo-row { padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.settings-avatar {
  position: relative; width: 84px; height: 84px; flex: 0 0 84px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; cursor: pointer; overflow: hidden;
  font-size: 30px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), #8a5bff);
  border: 2px dashed rgba(255,255,255,.35);
}
.settings-avatar.has-photo { border: 2px solid var(--line-2); }
.settings-avatar .avatar-img { width: 100%; height: 100%; object-fit: cover; }
.sa-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.42); opacity: 0; transition: opacity .15s;
}
.settings-avatar:hover .sa-overlay, .settings-avatar:focus .sa-overlay { opacity: 1; }
/* When there's no photo, the + is always visible (it's the "add" affordance). */
.settings-avatar:not(.has-photo) .sa-overlay { opacity: 1; background: rgba(0,0,0,.25); }
.sa-plus { font-size: 30px; color: #fff; line-height: 1; }
.settings-avatar-meta { flex: 1; min-width: 0; }
.sa-name { font-size: 17px; font-weight: 700; }
.sa-handle { color: var(--muted); font-size: 13px; }
.sa-hint { color: var(--muted-2); font-size: 12px; margin-top: 4px; }
.link-btn { background: none; border: none; color: var(--red); cursor: pointer; font-size: 12.5px; padding: 4px 0; }
.link-btn:hover { text-decoration: underline; }

/* ============ PHOTO VIEWER (full-screen) ============ */
.photo-viewer {
  position: fixed; inset: 0; z-index: 200; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  background: rgba(0,0,0,.92); padding: 40px 16px;
}
.photo-close { position: absolute; top: calc(14px + env(safe-area-inset-top,0px)); right: 16px; color: #fff; font-size: 20px; }
.photo-viewer-img { max-width: min(92vw, 560px); max-height: 72vh; border-radius: 16px; object-fit: contain; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.photo-history { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; max-width: 92vw; }
.ph-hint { width: 100%; text-align: center; color: rgba(255,255,255,.6); font-size: 12px; margin-bottom: 2px; }
.ph-thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; cursor: pointer; opacity: .55; border: 2px solid transparent; transition: opacity .12s, border-color .12s; }
.ph-thumb:hover { opacity: .85; }
.ph-thumb.active { opacity: 1; border-color: var(--accent); }

/* ============ MOBILE: wider message rows (avatars take a column) ============ */
@media (max-width: 760px) {
  .msg-row { max-width: 90%; }
  .msg-av { width: 26px; height: 26px; flex-basis: 26px; }
  .settings-avatar { width: 72px; height: 72px; flex-basis: 72px; }
  .avatar.xl { width: 84px; height: 84px; flex-basis: 84px; }
}

/* ============ MOBILE LAYOUT ROBUSTNESS (own messages cut off) ============ */
/* Prevent any horizontal overflow — with body overflow:hidden, an overflow
   would CLIP the right-aligned (own) messages off-screen. Let flex children
   shrink properly instead. */
.main { min-width: 0; }
.messages { overflow-x: hidden; }
.msg-row { min-width: 0; }
.msg-row .msg { min-width: 0; flex: 0 1 auto; }
.msg .text { overflow-wrap: anywhere; word-break: break-word; }
@media (max-width: 760px) {
  .app { width: 100%; max-width: 100vw; overflow-x: hidden; }
  .conversation { min-width: 0; }
  /* keep the last messages clear of the safe-area home indicator */
  .messages { padding-bottom: 6px; }
}

/* ============ GROUP BIO + OWNER PERMISSIONS PANEL ============ */
.gi-bio-block { margin: 4px 0 10px; }
.gi-bio { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.gi-bio-empty { color: var(--muted-2); }
.gi-inline-col { flex-direction: column; align-items: stretch; }
.gi-inline-col textarea { width: 100%; resize: vertical; }
.gi-perms { display: flex; flex-direction: column; gap: 4px; padding: 4px 0; }
.gi-perm-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 2px; border-bottom: 1px solid rgba(128,140,160,.08); font-size: 13.5px; }
.gi-perm-row span:first-child { flex: 1; }
.settings-avatar.locked { cursor: default; border-style: solid; opacity: .9; }

/* ============ DELETED ACCOUNT (padlock avatar) ============ */
.deleted-av { width: 58%; height: 58%; color: #aeb8c7; opacity: .92; }
.avatar .deleted-av, .msg-av .deleted-av { display: block; }
/* deleted avatars get a flat muted background instead of the gradient */
.profile-cover .avatar.xl.deleted,
.avatar:has(.deleted-av), .msg-av:has(.deleted-av) { background: var(--panel-2); }
.profile-cover .avatar.xl.deleted { box-shadow: none; }

/* ============ SYNC GATE + DEVICE PASSWORD MODALS ============ */
.sync-gate-head { text-align: center; margin-bottom: 6px; }
.sync-gate-logo { font-size: 40px; line-height: 1; margin-bottom: 6px; }
.sync-gate-head h2 { margin: 0 0 6px; }
#devicePwModal label, #syncGateModal label { margin-top: 12px; }
#devicePwCurrentRow.hidden { display: none; }

/* ============================================================
   LANDING PAGE
   ============================================================ */
/* When the landing is showing, the HTML element is the scroll container (the
   app normally locks the body). Making <html> the scroller keeps `position:
   sticky` working for the nav AND lets in-page #anchor links scroll. */
html.landing-mode { height: auto; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; }
html.landing-mode body { height: auto; min-height: 100%; overflow: visible; }
/* Anchor targets clear the sticky nav (so the heading isn't hidden under it). */
.landing [id] { scroll-margin-top: 78px; }
.landing {
  position: relative; min-height: 100vh; min-height: 100dvh;
  background: var(--bg); color: var(--text);
}
.lp-glow {
  position: absolute; top: -20vh; left: 50%; transform: translateX(-50%);
  width: 120vw; height: 80vh; pointer-events: none; z-index: 0;
  background:
    radial-gradient(50% 50% at 30% 30%, rgba(91,140,255,.20), transparent 70%),
    radial-gradient(45% 45% at 75% 20%, rgba(138,91,255,.16), transparent 70%);
}
/* Keep all real content above the glow. (Scoped so it doesn't override the
   glow's own positioning the way a blanket `.landing > *` rule did.) */
.lp-nav, .lp-hero, .lp-section, .lp-final, .lp-footer { position: relative; z-index: 1; }

/* nav */
.lp-nav-wrap {
  position: sticky; top: 0; z-index: 6;
  background: rgba(11,14,19,.96); border-bottom: 1px solid var(--line);
}
.lp-nav {
  display: flex; align-items: center; gap: 18px;
  max-width: 1080px; margin: 0 auto; padding: 16px 22px;
}
.lp-brand { font-size: 20px; display: flex; align-items: center; gap: 9px; }
.lp-logo {
  width: 26px; height: 26px; display: inline-block; flex: 0 0 26px;
  background: url("/icon.svg") center/contain no-repeat;
}
.lp-nav-links { display: flex; gap: 22px; margin-left: auto; }
.lp-nav-links a { color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 500; transition: color .15s; }
.lp-nav-links a:hover { color: var(--text); }
.lp-nav-cta { padding: 9px 16px; }

/* hero */
.lp-hero { max-width: 860px; margin: 0 auto; padding: 60px 22px 40px; text-align: center; }
.lp-badge {
  display: inline-block; font-size: 12.5px; color: var(--accent); font-weight: 600;
  background: rgba(91,140,255,.12); border: 1px solid rgba(91,140,255,.3);
  padding: 6px 14px; border-radius: 999px; margin-bottom: 22px;
}
.lp-title { font-size: clamp(34px, 6vw, 60px); line-height: 1.05; margin: 0 0 18px; font-weight: 800; letter-spacing: -1px; }
.lp-grad { background: linear-gradient(120deg, var(--accent), #8a5bff 60%, #ff5b9c); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.lp-sub { font-size: clamp(15px, 2.2vw, 18px); color: var(--muted); max-width: 620px; margin: 0 auto 28px; line-height: 1.6; }
.lp-cta-row { display: flex; gap: 14px; justify-content: center; align-items: center; flex-wrap: wrap; }
.lp-center { margin-top: 28px; }
.lp-cta-big { font-size: 16px; padding: 14px 28px; border-radius: 14px; box-shadow: 0 10px 40px rgba(91,140,255,.35); }
.lp-cta-ghost { text-decoration: none; }
.lp-cryptoline { color: var(--muted-2); font-size: 11.5px; letter-spacing: .4px; margin-top: 22px; }

/* hero preview */
.lp-preview {
  max-width: 420px; margin: 46px auto 0; text-align: left;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 18px;
  box-shadow: var(--shadow); overflow: hidden;
}
.lp-pre-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.lp-pre-av { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--accent), #8a5bff); }
.lp-pre-name { font-weight: 600; }
.lp-pre-status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.lp-pre-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 6px var(--green); }
.lp-pre-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.lp-bubble { max-width: 78%; padding: 9px 13px; border-radius: 15px; font-size: 14px; animation: lp-pop .4s ease both; }
.lp-bubble.them { align-self: flex-start; background: var(--them); border-bottom-left-radius: 5px; }
.lp-bubble.me { align-self: flex-end; background: var(--me); color: #fff; border-bottom-right-radius: 5px; }
.lp-bubble.lp-emoji { font-size: 26px; background: transparent; padding: 2px 6px; }
.lp-bubble:nth-child(2) { animation-delay: .1s; }
.lp-bubble:nth-child(3) { animation-delay: .2s; }
.lp-bubble:nth-child(4) { animation-delay: .3s; }
.lp-bubble:nth-child(5) { animation-delay: .4s; }
@keyframes lp-pop { from { opacity: 0; transform: translateY(8px) scale(.96); } to { opacity: 1; transform: none; } }

/* sections */
.lp-section { max-width: 1080px; margin: 0 auto; padding: 64px 22px; }
.lp-section-alt { background: var(--bg-2); }
/* Center the inner content of full-bleed alt sections without re-constraining
   every child individually (which mis-aligned the headings). */
.lp-section.lp-section-alt { max-width: none; }
.lp-section.lp-section-alt > * { max-width: 1080px; margin-left: auto; margin-right: auto; }
.lp-h2 {
  font-size: clamp(24px, 4vw, 34px); font-weight: 700; text-align: center;
  margin: 0 auto 14px; letter-spacing: 0; color: var(--text);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.lp-lead { text-align: center; color: var(--muted); max-width: 600px; margin: 0 auto 36px; font-size: 15px; line-height: 1.6; }
/* sections whose h2 isn't followed by a lead still get spacing below the title */
.lp-sec-grid, .lp-steps, .lp-faq { margin-top: 24px; }

.lp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.lp-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px 22px 22px 24px; position: relative; transition: border-color .15s, background .15s; }
.lp-card::before { content: ""; position: absolute; left: 0; top: 16px; bottom: 16px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); opacity: .55; }
.lp-card:hover { border-color: var(--line-2); background: var(--panel-2); }
.lp-card h3 { margin: 0 0 7px; font-size: 16px; font-weight: 600; }
.lp-card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }

.lp-sec-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 22px; }
.lp-sec h3 { margin: 0 0 8px; font-size: 18px; }
.lp-sec p { margin: 0; color: var(--muted); font-size: 14.5px; line-height: 1.65; }
.lp-sec em { color: var(--text); font-style: normal; font-weight: 600; }

.lp-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
.lp-step { text-align: center; }
.lp-step-n { width: 46px; height: 46px; margin: 0 auto 14px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px; color: #fff; background: linear-gradient(135deg, var(--accent), #8a5bff); box-shadow: 0 8px 24px rgba(91,140,255,.4); }
.lp-step h3 { margin: 0 0 8px; font-size: 17px; }
.lp-step p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }

.lp-faq { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.lp-q { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px 18px; }
.lp-q summary { cursor: pointer; padding: 14px 0; font-weight: 600; font-size: 15.5px; list-style: none; display: flex; justify-content: space-between; align-items: center; }
.lp-q summary::-webkit-details-marker { display: none; }
.lp-q summary::after { content: "+"; color: var(--accent); font-size: 22px; font-weight: 400; }
.lp-q[open] summary::after { content: "−"; }
.lp-q p { margin: 0 0 16px; color: var(--muted); font-size: 14.5px; line-height: 1.6; }

.lp-final { text-align: center; padding: 80px 22px; background: radial-gradient(60% 100% at 50% 0%, rgba(91,140,255,.16), transparent 70%); }
.lp-final-sub { color: var(--muted); font-size: 16px; margin: 0 0 28px; }

.lp-footer { text-align: center; padding: 40px 22px 56px; border-top: 1px solid var(--line); color: var(--muted); }
.lp-footer .lp-brand { justify-content: center; margin-bottom: 8px; }
.lp-footer p { margin: 4px 0; font-size: 13px; }

@media (max-width: 860px) {
  .lp-nav-links { display: none; }
  .lp-grid, .lp-sec-grid, .lp-steps { grid-template-columns: 1fr; }
  .lp-hero { padding-top: 40px; }
}

/* ============ BLOCKED USERS (settings) ============ */
.blocked-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.blocked-row { display: flex; align-items: center; gap: 11px; padding: 9px 11px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 11px; }
.blocked-main { flex: 1; min-width: 0; }
.blocked-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.blocked-row .blocked-unblock { flex: 0 0 auto; padding: 6px 13px; font-size: 13px; }

/* ============ FAILED (blocked) MESSAGE ============ */
.msg.failed { border: 1px solid var(--red); }
.msg.me.failed { background: color-mix(in srgb, var(--red) 28%, var(--me)); }
.msg.failed .msg-fail { color: #ffd9d9; font-size: 11.5px; margin-top: 4px; font-weight: 600; }
.msg.them.failed { background: color-mix(in srgb, var(--red) 18%, var(--them)); }
