:root {
  color-scheme: dark light;
  --bg:#0b0d12; --panel:#141821; --panel2:#1b2030; --line:#252b3a;
  --text:#eef0f6; --mute:#8c94a8; --acc:#6a8dff; --acc2:#8b6bff;
  --mine1:#3b5bdb; --mine2:#5b46d6; --theirs:#1d2333; --theirs-line:#262d40;
  --warn:#ffa45c; --danger:#ef5b60; --ok:#38d27c; --shadow:0 10px 34px rgba(0,0,0,.4);
  --wall: radial-gradient(1200px 500px at 10% -10%, rgba(106,141,255,.10), transparent 60%), radial-gradient(900px 500px at 110% 110%, rgba(139,107,255,.10), transparent 60%);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg:#eef1f7; --panel:#ffffff; --panel2:#f3f5fa; --line:#e1e5ee;
    --text:#171a22; --mute:#667086; --theirs:#ffffff; --theirs-line:#e3e7f0;
    --shadow:0 10px 34px rgba(30,45,90,.14);
    --wall: radial-gradient(1200px 500px at 10% -10%, rgba(106,141,255,.16), transparent 60%), radial-gradient(900px 500px at 110% 110%, rgba(139,107,255,.14), transparent 60%);
  }
}
* { box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html, body { height:100%; margin:0; background:var(--bg); color:var(--text);
  font:15px/1.45 system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",sans-serif; }
.hidden { display:none !important; }
button, select, input, textarea { font:inherit; color:inherit; }
button { cursor:pointer; }
a { color:inherit; }

/* ---------- gate ---------- */
.gate { min-height:100dvh; display:flex; align-items:center; justify-content:center; padding:20px; background:var(--wall), var(--bg); }
.card { width:100%; max-width:400px; background:var(--panel); border:1px solid var(--line); border-radius:22px; padding:30px 28px; box-shadow:var(--shadow); text-align:center; }
.logo { border-radius:16px; margin-bottom:6px; }
.card h1 { margin:6px 0 4px; font-size:30px; letter-spacing:-.8px; }
.card p { color:var(--mute); margin:0 0 20px; }
.card input { width:100%; padding:13px 15px; border-radius:12px; border:1px solid var(--line); background:var(--panel2); margin-bottom:12px; outline:none; }
.card input:focus { border-color:var(--acc); }
.btn { width:100%; border:0; color:#fff; padding:13px 16px; border-radius:12px; font-weight:650; background:linear-gradient(135deg,var(--acc),var(--acc2)); }
.btn:active { transform:scale(.99); }
.small { color:var(--mute); font-size:12px; margin-top:16px; text-align:left; }
#gate-err { color:var(--warn); font-size:13px; margin-top:10px; }

/* ---------- app shell ---------- */
.app { height:100dvh; max-width:860px; margin:0 auto; display:flex; flex-direction:column; background:var(--bg); position:relative; }
@media (min-width:900px) { .app { border-left:1px solid var(--line); border-right:1px solid var(--line); } }
header { display:flex; align-items:center; gap:6px; padding:10px 12px; background:var(--panel); border-bottom:1px solid var(--line); }
.roomav { width:40px; height:40px; border-radius:50%; background:linear-gradient(135deg,var(--acc),var(--acc2)); display:flex; align-items:center; justify-content:center; font-size:18px; flex:none; margin-right:4px; }
.hgrow { flex:1; min-width:0; }
.title { font-weight:700; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.sub { color:var(--mute); font-size:12px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.dot { display:inline-block; width:8px; height:8px; border-radius:50%; background:#666; margin-right:6px; }
.dot.on { background:var(--ok); box-shadow:0 0 0 3px rgba(56,210,124,.18); }
.ib { background:transparent; border:0; width:36px; height:36px; border-radius:50%; font-size:17px; display:flex; align-items:center; justify-content:center; flex:none; }
.ib:hover { background:var(--panel2); }
.ib.on { background:var(--panel2); }

.banner { display:flex; align-items:center; gap:8px; padding:9px 14px; background:rgba(56,210,124,.14); border-bottom:1px solid var(--line); font-size:13px; }
.banner span { flex:1; }
.chip { background:var(--panel2); border:1px solid var(--line); border-radius:999px; padding:6px 12px; font-size:13px; }
.chip.primary { background:var(--acc); border-color:var(--acc); color:#fff; }

/* ---------- message list ---------- */
#list { flex:1; overflow-y:auto; padding:14px 12px 8px; display:flex; flex-direction:column; gap:3px; background:var(--wall); overscroll-behavior:contain; }
.notice { align-self:center; text-align:center; color:var(--mute); font-size:12px; background:var(--panel); border:1px solid var(--line); padding:6px 12px; border-radius:999px; max-width:92%; margin:6px 0; }
.notice.err { color:var(--warn); }
.day, .unread { align-self:center; font-size:12px; color:var(--mute); background:var(--panel); border:1px solid var(--line); padding:3px 12px; border-radius:999px; margin:10px 0 6px; }
.unread { color:#fff; background:var(--acc); border-color:var(--acc); }

.row { display:flex; align-items:flex-end; gap:8px; margin-top:8px; max-width:100%; animation:pop .16s ease-out; }
.row.cont { margin-top:0; }
.row.mine { flex-direction:row-reverse; }
@keyframes pop { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }
.av { width:30px; height:30px; border-radius:50%; flex:none; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:13px; color:#fff; }
.row.cont .av { visibility:hidden; }
.row.mine .av { display:none; }
.bubble { max-width:min(78%,520px); padding:7px 11px 5px; border-radius:18px; background:var(--theirs); border:1px solid var(--theirs-line); overflow-wrap:anywhere; word-wrap:break-word; }
.row.theirs .bubble { border-bottom-left-radius:6px; }
.row.theirs.cont .bubble { border-top-left-radius:6px; }
.row.mine .bubble { background:linear-gradient(135deg,var(--mine1),var(--mine2)); border-color:transparent; color:#fff; border-bottom-right-radius:6px; }
.row.mine.cont .bubble { border-top-right-radius:6px; }
.who { font-size:12px; font-weight:650; margin-bottom:1px; }
.row.cont .who { display:none; }
.txt { white-space:pre-wrap; }
.txt a { text-decoration:underline; text-underline-offset:2px; word-break:break-all; }
.bubble img, .bubble video { max-width:100%; max-height:360px; border-radius:12px; display:block; margin:3px 0; }
.bubble iframe { width:100%; height:340px; border:0; border-radius:10px; background:#fff; margin:3px 0; }
.bubble pre { max-height:220px; overflow:auto; background:rgba(0,0,0,.22); padding:8px 10px; border-radius:10px; margin:3px 0; white-space:pre-wrap; font-size:13px; }
.bubble audio { width:260px; max-width:100%; margin:3px 0; }
.file { display:flex; align-items:center; gap:10px; margin:3px 0; padding:8px 10px; background:rgba(0,0,0,.18); border-radius:12px; }
.file .fi { font-size:20px; }
.file a { font-weight:650; text-decoration:none; word-break:break-all; }
.file .fs { opacity:.7; font-size:12px; margin-left:auto; white-space:nowrap; }
.meta { display:flex; gap:8px; align-items:center; justify-content:flex-end; font-size:11px; opacity:.72; margin-top:2px; }
.meta .burn { color:var(--warn); opacity:1; }
.row.mine .meta .burn { color:#ffd9b8; }
.meta button { background:none; border:0; padding:0; font-size:11px; opacity:.85; text-decoration:underline; }

/* voice note player */
.vp { display:flex; align-items:center; gap:10px; min-width:210px; padding:2px 0; }
.vbtn { width:36px; height:36px; border-radius:50%; border:0; flex:none; background:var(--acc); color:#fff; font-size:13px; }
.row.mine .vbtn { background:#fff; color:var(--mine2); }
.vmid { flex:1; min-width:0; }
.vbar { height:6px; border-radius:99px; background:rgba(127,127,127,.35); cursor:pointer; overflow:hidden; }
.vfill { height:100%; width:0; background:var(--acc); }
.row.mine .vfill { background:#fff; }
.vtime { font-size:11px; opacity:.75; margin-top:3px; }

.typing { height:18px; padding:0 16px; font-size:12px; color:var(--mute); }

/* ---------- composer ---------- */
footer { padding:6px 10px calc(8px + env(safe-area-inset-bottom)); background:var(--panel); border-top:1px solid var(--line); }
.compose { display:flex; gap:8px; align-items:flex-end; }
.field { flex:1; display:flex; align-items:flex-end; background:var(--panel2); border:1px solid var(--line); border-radius:24px; padding:2px 4px; }
.field:focus-within { border-color:var(--acc); }
.field textarea { flex:1; resize:none; max-height:120px; border:0; background:transparent; outline:none; padding:9px 4px; }
.field .ib { width:34px; height:36px; }
.fab { width:44px; height:44px; border-radius:50%; border:0; flex:none; font-size:18px; background:var(--panel2); border:1px solid var(--line); }
.fab.send { background:linear-gradient(135deg,var(--acc),var(--acc2)); color:#fff; border:0; }
.tools { display:flex; gap:10px; align-items:center; margin-top:6px; font-size:12px; color:var(--mute); flex-wrap:wrap; }
.tools select { background:var(--panel2); border:1px solid var(--line); border-radius:999px; padding:3px 8px; font-size:12px; margin-left:4px; }
.rec { display:flex; align-items:center; gap:10px; padding:4px 4px 8px; color:var(--danger); }
.rec .grow { flex:1; }
.recdot { animation:blink 1s infinite; }
@keyframes blink { 50% { opacity:.2; } }
.emojis { display:grid; grid-template-columns:repeat(8,1fr); gap:2px; padding:8px; margin-bottom:8px; background:var(--panel2); border:1px solid var(--line); border-radius:16px; }
.emojis button { background:none; border:0; font-size:22px; padding:4px; border-radius:10px; }
.emojis button:hover { background:var(--line); }

/* ---------- calls ---------- */
#call { position:fixed; inset:0; z-index:10; background:#07090d; display:flex; flex-direction:column; color:#fff; }
#grid { flex:1; display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,260px),1fr)); gap:8px; padding:8px; align-content:center; overflow:auto; }
.tile { position:relative; background:#161a22; border-radius:16px; overflow:hidden; min-height:180px; display:flex; align-items:center; justify-content:center; }
.tile video { width:100%; height:100%; object-fit:cover; max-height:70dvh; }
.tile .tname { position:absolute; left:8px; bottom:8px; background:rgba(0,0,0,.55); padding:2px 8px; border-radius:8px; font-size:12px; }
.tile .tav { display:none; width:84px; height:84px; border-radius:50%; background:linear-gradient(135deg,var(--acc),var(--acc2)); align-items:center; justify-content:center; font-size:36px; font-weight:700; }
.tile.audio .tav { display:flex; }
.tile.audio video { display:none; }
.ctl { display:flex; gap:16px; justify-content:center; padding:14px 14px calc(20px + env(safe-area-inset-bottom)); }
.cbtn { width:58px; height:58px; border-radius:50%; border:0; background:#2a3040; font-size:23px; }
.cbtn.off { background:#444; opacity:.55; }
.cbtn.red { background:var(--danger); }

#drop { position:fixed; inset:0; z-index:20; background:rgba(106,141,255,.2); border:3px dashed var(--acc); display:flex; align-items:center; justify-content:center; font-size:22px; pointer-events:none; }
#toast { position:fixed; left:50%; bottom:90px; transform:translate(-50%,20px); background:var(--panel); border:1px solid var(--line); padding:8px 16px; border-radius:999px; box-shadow:var(--shadow); opacity:0; transition:.2s; pointer-events:none; z-index:30; font-size:13px; }
#toast.show { opacity:1; transform:translate(-50%,0); }
