:root {
  color-scheme: dark;
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #262b36; --fg: #e6e9ef; --dim: #8b93a3;
  --accent: #6c8cff; --accent-fg: #0b1020; --mine: #243056; --ok: #3ecf8e; --bad: #ff6b6b;
  --safe-t: env(safe-area-inset-top); --safe-b: env(safe-area-inset-bottom);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden; }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
#root { height: 100dvh; }
.boot { display: grid; place-items: center; height: 100%; color: var(--dim); }
button, input, textarea { font: inherit; color: inherit; }
input, textarea { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 100%; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--dim); } .sub { color: var(--dim); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pad { padding: 12px 16px; } .row { display: flex; gap: 8px; align-items: center; } .row.end { justify-content: flex-end; } .row.pad { padding: 12px; }
.empty { color: var(--dim); text-align: center; padding: 32px 16px; }
.error { color: var(--bad); min-height: 1.4em; }

.btn { background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 600; cursor: pointer; }
.btn:disabled { opacity: .6; }
.btn.ghost { background: var(--panel2); color: var(--fg); border: 1px solid var(--line); }
.btn.danger, .chip.danger { color: var(--bad); }
.btn.big { width: 100%; padding: 14px; margin-top: 10px; } .btn.block { display: block; width: 100%; margin-top: 8px; }
.chip { background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.icon { background: none; border: 0; font-size: 22px; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; color: var(--fg); }
.icon:hover { background: var(--panel2); } .icon.sm { width: 30px; height: 30px; font-size: 16px; color: var(--dim); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--dim); margin-left: 8px; vertical-align: middle; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }

/* signed out */
.auth { max-width: 380px; margin: 0 auto; padding: calc(var(--safe-t) + 12vh) 20px 20px; }
.logo { font-size: 32px; letter-spacing: -.02em; margin: 0 0 18px; } .logo span, .brand span { color: var(--accent); }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; } .auth input { margin-top: 10px; }

/* app shell */
.app { display: grid; grid-template-columns: 300px 1fr; height: 100dvh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding-top: var(--safe-t); }
.pane { display: flex; flex-direction: column; min-height: 0; padding-top: var(--safe-t); }
.bar { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--line); min-height: 56px; }
.brand { font-weight: 700; font-size: 20px; padding-left: 6px; } .title { min-width: 0; } .title strong { display: block; }
.back { display: none; }
.groups { flex: 1; overflow-y: auto; padding: 6px 8px; }
.ghead { display: flex; align-items: center; gap: 6px; padding: 10px 6px 4px; }
.chan { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 10px; padding: 8px 12px; color: var(--dim); cursor: pointer; }
.chan:hover { background: var(--panel2); } .chan.on { background: var(--panel2); color: var(--fg); } .chan.unread { color: var(--fg); font-weight: 700; }

.msgs { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.day { align-self: center; color: var(--dim); font-size: 12px; margin: 10px 0 4px; }
.bubble { max-width: min(78%, 520px); align-self: flex-start; background: var(--panel2); border-radius: 16px 16px 16px 4px; padding: 7px 11px; word-break: break-word; }
.bubble.mine { align-self: flex-end; background: var(--mine); border-radius: 16px 16px 4px 16px; }
.bubble.bare { background: none; padding: 0; }
.bubble.flash { animation: flash 1.6s; } @keyframes flash { 0%, 60% { outline: 2px solid var(--accent); } 100% { outline: 2px solid transparent; } }
.who { font-size: 12px; color: var(--accent); font-weight: 600; } .text { white-space: pre-wrap; }
.meta { font-size: 11px; color: var(--dim); text-align: right; margin-top: 2px; }
.quote { border-left: 3px solid var(--accent); padding: 1px 8px; margin-bottom: 4px; color: var(--dim); font-size: 13px; }
.photo { display: block; max-width: 100%; max-height: 360px; border-radius: 12px; margin: 2px 0; background: #000; }
.sticker { display: block; width: 150px; height: 150px; object-fit: contain; }
.gone { color: var(--dim); font-style: italic; padding: 4px 0; } .file { color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.jump { align-self: center; position: sticky; top: 0; z-index: 2; }

.replybar { display: flex; align-items: center; padding: 6px 14px; background: var(--panel); border-top: 1px solid var(--line); font-size: 14px; color: var(--dim); }
.composer { display: flex; align-items: flex-end; gap: 4px; padding: 8px 8px calc(8px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { resize: none; max-height: 140px; border-radius: 20px; }
.composer .chip { align-self: center; font-size: 12px; padding: 4px 9px; }
.send { background: var(--accent); color: var(--accent-fg); border: 0; width: 42px; height: 42px; border-radius: 50%; font-size: 18px; cursor: pointer; flex: none; }
.stickers { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; background: var(--panel); border-top: 1px solid var(--line); max-height: 220px; overflow-y: auto; }
.stickers[hidden] { display: none; } .tile { width: 64px; height: 64px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; padding: 4px; font-size: 24px; }
.tile img { width: 100%; height: 100%; object-fit: contain; } .hint { flex-basis: 100%; margin: 0; font-size: 12px; }

/* overlays */
.searchlayer { position: fixed; inset: 0; background: var(--bg); z-index: 20; display: flex; flex-direction: column; padding-top: var(--safe-t); }
.searchlayer .results, .settings-body { flex: 1; overflow-y: auto; }
.hit { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; cursor: pointer; }
mark { background: #6c8cff44; color: var(--fg); border-radius: 3px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; margin: 12px; } .card h3 { margin: 0 0 8px; }
.secret { display: block; background: var(--panel2); padding: 10px; border-radius: 10px; word-break: break-all; margin: 8px 0; user-select: all; }
.modal { background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 18px; padding: 18px; width: min(92vw, 420px); }
.modal::backdrop { background: #000a; } .modal h3 { margin: 0 0 10px; } .modal input { margin: 8px 0; } .modes label { display: block; padding: 6px 0; }
.once img, .once video { max-width: 100%; max-height: 70vh; border-radius: 12px; display: block; margin: 0 auto; }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translate(-50%, 20px); background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; opacity: 0; transition: .25s; z-index: 100; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* camera */
.cam { position: fixed; inset: 0; background: #000; z-index: 50; }
.cam-live, .cam-review { position: absolute; inset: 0; display: flex; flex-direction: column; } .cam-live[hidden] { display: none; }
.cam-view { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.cam-src { position: absolute; width: 2px; height: 2px; opacity: 0; pointer-events: none; }
.cam-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .08s; } .cam-flash.on { opacity: 1; }
.cam-top { position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 8px; padding: calc(10px + var(--safe-t)) 12px 10px; z-index: 2; }
.cam-btn { background: #0008; color: #fff; border: 0; border-radius: 999px; padding: 9px 14px; font-size: 15px; cursor: pointer; } .cam-btn.on { background: #ffd54a; color: #000; }
.cam-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 12px calc(18px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; align-items: center; z-index: 2; background: linear-gradient(transparent, #000a); }
.cam-bottom input { background: #0009; color: #fff; } .cam-bottom .row { width: 100%; }
.filters { display: flex; gap: 8px; overflow-x: auto; max-width: 100%; padding: 2px; } .filters .chip { background: #0008; color: #fff; border-color: #fff3; }
.shutter-wrap { position: relative; width: 84px; height: 84px; display: grid; place-items: center; }
.shutter { width: 66px; height: 66px; border-radius: 50%; border: 4px solid #fff; background: #fff4; cursor: pointer; touch-action: none; transition: transform .15s, background .15s; } .shutter.rec { background: #ff3b30; transform: scale(.85); }
.ring { position: absolute; inset: 0; border-radius: 50%; --p: 0; background: conic-gradient(#ff3b30 calc(var(--p) * 360deg), transparent 0); -webkit-mask: radial-gradient(circle, transparent 38px, #000 39px); mask: radial-gradient(circle, transparent 38px, #000 39px); pointer-events: none; }
.cam-msg { position: absolute; inset: 40% 24px auto; text-align: center; color: #fff; z-index: 3; }
.cam-review > img, .cam-review > video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }

@media (max-width: 799px) {
  .app { grid-template-columns: 1fr; } .side, .pane { grid-column: 1; grid-row: 1; }
  .app[data-view="list"] .pane, .app[data-view="chat"] .side { display: none; } .back { display: block; }
}
