:root {
  --bg: #313338; --side: #2b2d31; --deep: #1e1f22; --hover: #2e3035; --text: #dbdee1; --muted: #949ba4;
  --accent: #5865f2; --ok: #23a55a; --warn: #f0b232; --bad: #f23f43; --line: #3f4147; --chip: #2b2d31;
  --mine: #3b3d44;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { overscroll-behavior: none; }
button { font: inherit; color: inherit; background: var(--hover); border: 0; border-radius: 6px; padding: 8px 12px; cursor: pointer; }
button.primary { background: var(--accent); color: #fff; font-weight: 600; padding: 12px 20px; }
button.danger { background: #4a2326; color: #ffb3b5; }
button.icon { background: none; padding: 6px 10px; font-size: 20px; line-height: 1; }
[hidden] { display: none !important; }
a { color: #00a8fc; }
.muted { color: var(--muted); font-size: 14px; }
.err { color: var(--bad); min-height: 1.2em; }

.gate { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; height: 100%; padding: 24px; text-align: center; }
.gate h1 { margin: 0; }
.gate input { font: inherit; padding: 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--deep); color: var(--text); width: min(320px, 90vw); }

.app { display: flex; height: 100dvh; }
.side { width: 280px; background: var(--side); display: flex; flex-direction: column; flex-shrink: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 8px 12px 16px; border-bottom: 1px solid var(--deep); padding-top: max(12px, env(safe-area-inset-top)); }
.brand { font-weight: 700; font-size: 17px; }
.channels { overflow-y: auto; flex: 1; padding: 8px 8px 24px; }
.cat { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 16px 8px 4px; cursor: pointer; user-select: none; }
.cat::before { content: "▾ "; }
.cat.collapsed::before { content: "▸ "; }
.chan { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 6px; color: var(--muted); cursor: pointer; text-decoration: none; }
.chan:hover { background: var(--hover); }
.chan.active { background: #404249; color: #fff; }
.chan.unread { color: #fff; font-weight: 600; }
.chan .hash { opacity: .7; }
.chan .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--bad); color: #fff; border-radius: 9px; font-size: 12px; padding: 0 6px; font-weight: 700; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot.on { background: var(--ok); }
.dot.asleep { background: #80848e; }
.dot.none { border: 1px solid #80848e; }
.dot.waiting { background: var(--warn); }
.box-banner { background: #4a2326; color: #ffb3b5; padding: 8px 12px; font-size: 14px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.chan-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--deep); min-height: 50px; padding-top: max(10px, env(safe-area-inset-top)); }
.chan-title { font-weight: 700; }
.chan-status { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }
.pending { background: #49391a; color: #ffd98a; padding: 8px 14px; font-size: 14px; }
.log { flex: 1; overflow-y: auto; padding: 8px 0 12px; overflow-anchor: auto; }
.jump { position: absolute; bottom: 84px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 6px 14px; border-radius: 16px; font-size: 14px; cursor: pointer; }
.day { text-align: center; color: var(--muted); font-size: 12px; margin: 16px 0 4px; }
.newline { border-top: 1px solid var(--bad); margin: 6px 16px; position: relative; }
.newline::after { content: "new"; position: absolute; right: 0; top: -9px; background: var(--bad); color: #fff; font-size: 10px; padding: 0 4px; border-radius: 3px; font-weight: 700; }
.msg { padding: 2px 16px 2px 16px; position: relative; }
.msg:hover { background: #2e3035; }
.msg.sel { background: #393c43; }
.msg.head { margin-top: 12px; }
.who { font-weight: 600; margin-right: 6px; }
.who.keel { color: #8ea1ff; }
.who.ari { color: #f7c8ff; }
.time { color: var(--muted); font-size: 12px; }
.tag { font-size: 10px; background: var(--chip); color: var(--muted); border-radius: 3px; padding: 0 4px; margin-left: 4px; vertical-align: 1px; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.38; }
.body code { background: var(--deep); padding: 1px 4px; border-radius: 4px; font-size: 90%; }
.body pre { background: var(--deep); padding: 8px; border-radius: 6px; overflow-x: auto; white-space: pre; margin: 4px 0; }
.body pre code { background: none; padding: 0; }
.body blockquote { margin: 2px 0; padding-left: 10px; border-left: 4px solid #4e5058; }
.body h1, .body h2, .body h3 { margin: 6px 0 2px; line-height: 1.2; }
.body h1 { font-size: 1.4em; } .body h2 { font-size: 1.2em; } .body h3 { font-size: 1.05em; }
.mention { background: rgba(88,101,242,.3); color: #c9cdfb; border-radius: 3px; padding: 0 2px; }
.edited { color: var(--muted); font-size: 11px; }
.quote { color: var(--muted); font-size: 13px; margin: 2px 0 0 0; padding-left: 8px; border-left: 2px solid #4e5058; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.files img { max-width: min(360px, 80vw); max-height: 320px; border-radius: 6px; display: block; cursor: zoom-in; }
.file { background: var(--side); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; text-decoration: none; color: var(--text); }
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.react { background: var(--chip); border: 1px solid transparent; border-radius: 8px; padding: 1px 7px; font-size: 14px; }
.react.mine { border-color: var(--accent); background: rgba(88,101,242,.15); }
.react .n { color: var(--muted); font-size: 12px; margin-left: 2px; }
.flash { animation: flash 1.5s; }
@keyframes flash { from { background: #5865f244; } to { background: transparent; } }

.composer { padding: 8px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.compose-row { display: flex; align-items: flex-end; gap: 4px; background: #383a40; border-radius: 10px; padding: 4px; }
.compose-row textarea { flex: 1; resize: none; border: 0; background: none; color: var(--text); font: inherit; font-size: 16px; padding: 8px 4px; max-height: 40vh; outline: none; }
.attach { cursor: pointer; color: var(--muted); }
.send { color: var(--accent); }
.reply-bar, .attach-list { display: flex; align-items: center; gap: 8px; background: var(--side); border-radius: 8px 8px 0 0; padding: 6px 10px; font-size: 13px; color: var(--muted); }
.reply-bar span { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.attach-list { flex-wrap: wrap; }
.attach-list .chip { background: var(--hover); border-radius: 6px; padding: 2px 8px; }

.sheet { position: fixed; inset: 0; background: #000a; display: flex; justify-content: center; align-items: flex-end; z-index: 10; }
.sheet-body { background: var(--side); width: min(520px, 100vw); max-height: 90dvh; overflow-y: auto; border-radius: 14px 14px 0 0; padding: 12px 18px 24px; }
.sheet-body header { display: flex; justify-content: space-between; align-items: center; }
.sheet-body section { border-top: 1px solid var(--line); padding: 8px 0 12px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.sheet-body h3 { margin: 6px 0 0; font-size: 15px; }
.row { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.devices { list-style: none; padding: 0; margin: 0; width: 100%; }
.devices li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.devices li span { flex: 1; }

.actions { position: fixed; left: 0; right: 0; bottom: 0; background: var(--side); border-radius: 14px 14px 0 0; padding: 12px 12px max(12px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 6px; z-index: 9; box-shadow: 0 -4px 24px #0008; }
.actions > button { text-align: left; padding: 12px; }
.quick { display: flex; justify-content: space-between; gap: 4px; }
.quick button { font-size: 22px; padding: 8px; flex: 1; background: var(--hover); }

.lightbox { position: fixed; inset: 0; background: #000e; z-index: 20; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100vw; max-height: 100dvh; }

@media (max-width: 760px) {
  .side { width: 100%; }
  .app.in-chan .side { display: none; }
  .app:not(.in-chan) .main { display: none; }
  .back { display: inline-block; }
}
@media (min-width: 761px) {
  .actions { left: auto; right: 16px; bottom: 90px; width: 340px; border-radius: 12px; }
}
