:root {
  --bg: #0d1117; --s1: #151b23; --s2: #1c232d; --hover: #252d39; --line: #262e3a;
  --text: #e8edf3; --muted: #8b95a5; --accent: #10b981; --accent-h: #059669; --accent-ink: #04140e;
  --mine: #10b981; --mine-ink: #04140e; --bubble: #1c232d; --bad: #f87171; --warn: #fbbf24;
  --mention: rgba(251, 191, 36, .14);
  --r: 18px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f5f7fa; --s1: #ffffff; --s2: #eef1f5; --hover: #e5e9ef; --line: #e1e6ec;
  --text: #0f172a; --muted: #64748b; --accent: #059669; --accent-h: #047857; --accent-ink: #ffffff;
  --mine: #059669; --mine-ink: #ffffff; --bubble: #ffffff; --bad: #dc2626; --warn: #b45309;
  --mention: rgba(245, 158, 11, .16);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f7fa; --s1: #ffffff; --s2: #eef1f5; --hover: #e5e9ef; --line: #e1e6ec;
    --text: #0f172a; --muted: #64748b; --accent: #059669; --accent-h: #047857; --accent-ink: #ffffff;
    --mine: #059669; --mine-ink: #ffffff; --bubble: #ffffff; --bad: #dc2626; --warn: #b45309;
    --mention: rgba(245, 158, 11, .16);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.noscript { padding: 24px; text-align: center; }

/* ---------- join screen */
.join { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.join-card { width: 100%; max-width: 380px; text-align: center; }
.join-logo { border-radius: 16px; box-shadow: 0 10px 30px rgba(16,185,129,.25); }
.join h1 { margin: 14px 0 4px; font-size: 28px; letter-spacing: -.02em; }
.join p { margin: 0 0 22px; }
.join form { text-align: left; background: var(--s1); border: 1px solid var(--line); border-radius: 20px; padding: 18px; margin-bottom: 14px; }
.lbl { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.in { width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--s2); border: 1.5px solid transparent;
  border-radius: 12px; padding: 12px 14px; outline: none; transition: border-color .15s; }
.in:focus { border-color: var(--accent); }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin: 6px 0 4px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; cursor: pointer; font-weight: 700;
  background: var(--accent); color: var(--accent-ink); border-radius: 12px; padding: 10px 16px; transition: background .15s, transform .1s; }
.btn:hover { background: var(--accent-h); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.big { width: 100%; padding: 13px; font-size: 16px; }
.btn.ghost { background: var(--s2); color: var(--text); }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { background: var(--bad); color: #fff; }

/* ---------- app layout */
.app { height: 100%; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; position: relative; }
.top { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) 16px 10px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); position: relative; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.brand img { border-radius: 9px; flex: none; }
.brand div { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand b { font-size: 16px; }
#status.off { color: var(--warn); }
.pill { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--s1); border-radius: 999px;
  padding: 6px 12px; cursor: pointer; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill:hover { background: var(--hover); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 10px; cursor: pointer; fill: currentColor; flex: none; }
.icon-btn:hover { background: var(--hover); }

.menu { position: absolute; right: 12px; top: calc(100% - 4px); background: var(--s1); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0,0,0,.3); padding: 6px; min-width: 210px; z-index: 20; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 9px; cursor: pointer; }
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--bad); }
.menu-who { padding: 8px 12px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.menu-who b { color: var(--text); }

.people { position: absolute; right: 12px; top: 64px; width: 260px; max-height: 60vh; overflow: auto; background: var(--s1); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: 0 16px 40px rgba(0,0,0,.3); z-index: 15; padding: 6px 6px 10px; }
.people-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 4px 10px; }
.people ul { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 10px; }
.people li button { margin-left: auto; padding: 4px 10px; font-size: 12px; }
.tag { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }

/* ---------- messages */
.feed { flex: 1; overflow-y: auto; padding: 14px 16px 8px; overscroll-behavior: contain; scroll-behavior: auto; }
.older { display: block; margin: 0 auto 12px; border: 1px solid var(--line); background: var(--s1); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 13px; }
.day { text-align: center; margin: 14px 0 10px; font-size: 12px; font-weight: 600; color: var(--muted); }
.sys { text-align: center; font-size: 12.5px; color: var(--muted); margin: 8px 0; }
.row { display: flex; gap: 10px; align-items: flex-end; margin-top: 10px; }
.row.cont { margin-top: 3px; }
.row.mine { flex-direction: row-reverse; }
.av { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; flex: none; user-select: none; }
.row.cont .av { visibility: hidden; height: 0; }
.row.mine .av { display: none; }
.col { display: flex; flex-direction: column; align-items: flex-start; max-width: min(78%, 560px); min-width: 0; }
.row.mine .col { align-items: flex-end; }
.who { font-size: 12.5px; font-weight: 700; margin: 0 0 3px 12px; }
.who-btn { border: 0; background: none; padding: 0; cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 700; text-align: left; }
.who-btn:hover { text-decoration: underline; }
.bub { position: relative; background: var(--bubble); border: 1px solid var(--line); padding: 8px 12px; border-radius: var(--r);
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.row:not(.mine) .bub { border-bottom-left-radius: 6px; }
.row.mine .bub { background: var(--mine); color: var(--mine-ink); border-color: transparent; border-bottom-right-radius: 6px; }
.row.ment .bub { background: var(--mention); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.bub a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.bub .at { font-weight: 700; }
.meta { font-size: 11px; color: var(--muted); margin: 3px 10px 0; display: flex; gap: 8px; align-items: center; opacity: 0; transition: opacity .15s; }
.row:hover .meta, .row.last .meta, .row:focus-within .meta { opacity: 1; }
.meta button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; font-size: 11px; text-decoration: underline; }
.meta button:hover { color: var(--bad); }
.row.pending .bub { opacity: .6; }
.row.failed .bub { outline: 2px solid var(--bad); }
.empty { text-align: center; color: var(--muted); margin: 60px 0; }

.jump { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(86px + var(--safe-b)); border: 0; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 13px; padding: 8px 14px; border-radius: 999px; box-shadow: 0 8px 20px rgba(0,0,0,.25); cursor: pointer; z-index: 4; }

/* ---------- composer */
.composer { padding: 6px 12px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--bg); }
.typing { font-size: 12px; color: var(--muted); height: 16px; padding-left: 8px; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#send-form { display: flex; gap: 8px; align-items: flex-end; }
#text { flex: 1; resize: none; font: inherit; font-size: 16px; color: var(--text); background: var(--s1); border: 1.5px solid var(--line); border-radius: 22px;
  padding: 10px 16px; max-height: 160px; outline: none; line-height: 1.4; }
#text:focus { border-color: var(--accent); }
.send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); fill: var(--accent-ink); display: grid; place-items: center; cursor: pointer; flex: none;
  transition: background .15s, transform .1s; }
.send:hover { background: var(--accent-h); }
.send:active { transform: scale(.94); }
.send:disabled { opacity: .4; cursor: default; }
.count { text-align: right; color: var(--muted); height: 0; overflow: visible; padding-right: 60px; }
.count.near { color: var(--warn); height: auto; }

/* ---------- dialogs */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.sheet { width: 100%; max-width: 380px; background: var(--s1); border: 1px solid var(--line); border-radius: 20px; padding: 20px; box-shadow: 0 24px 60px rgba(0,0,0,.35); }
.sheet h2 { margin: 0 0 6px; font-size: 19px; }
.sheet p { margin: 0 0 14px; color: var(--muted); }
.sheet .acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.sheet .opts { display: grid; gap: 8px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(100px + var(--safe-b)); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; z-index: 60; max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.toast.bad { background: var(--bad); color: #fff; }

@media (min-width: 700px) {
  .feed { padding: 18px 22px 10px; }
  .composer { padding-left: 18px; padding-right: 18px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
