:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1b1f27; --muted: #69707d;
  --line: #e2e5ea; --accent: #2f8f7d; --accent-text: #ffffff;
  --mine: #dff2ec; --theirs: #ffffff; --err: #b3261e; --code: #eef0f3;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181f; --panel: #1c222b; --text: #e6e9ee; --muted: #9aa3b0;
    --line: #2b333e; --accent: #5fb3a1; --accent-text: #0e1216;
    --mine: #1f3a34; --theirs: #222a34; --err: #ff8a80; --code: #2a323d;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.icon { padding: 8px 10px; min-width: 42px; }
button:disabled { opacity: .5; }
input, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%; }
.muted { color: var(--muted); } .small { font-size: 13px; } .err { color: var(--err); min-height: 1.2em; }
.center { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.center-text { text-align: center; padding: 12px; margin: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px;
  width: 100%; max-width: 380px; display: grid; gap: 14px; }
.card h1 { margin: 0; font-size: 22px; }
.card label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }

#v-chat { display: flex; flex-direction: column; height: 100dvh; max-width: 900px; margin: 0 auto;
  position: relative; }
#top { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line);
  background: var(--panel); padding-top: max(8px, env(safe-area-inset-top)); }
#top h2 { margin: 0; font-size: 17px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#typing { font-size: 13px; }
#rooms, .sheet { position: absolute; top: 58px; z-index: 5; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px; display: grid; gap: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.18);
  max-height: 70dvh; overflow: auto; }
#rooms { left: 12px; min-width: 220px; }
.sheet { right: 12px; min-width: 240px; max-width: calc(100% - 24px); }
#rooms button, .sheet button { text-align: left; border: 0; }
#rooms button.active { background: var(--mine); }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 0 7px;
  font-size: 12px; margin-left: 6px; }
.device { display: flex; justify-content: space-between; gap: 10px; align-items: center;
  border-bottom: 1px solid var(--line); padding: 6px 4px; font-size: 14px; }

#log { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 8px;
  overscroll-behavior: contain; }
.msg { max-width: 88%; padding: 8px 12px; border-radius: 14px; background: var(--theirs);
  border: 1px solid var(--line); overflow-wrap: anywhere; position: relative; }
.msg.mine { align-self: flex-end; background: var(--mine); border-color: transparent; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg .when { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg .react { position: absolute; bottom: -10px; left: -6px; font-size: 15px; }
.msg.deleted { display: none; }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin-bottom: 0; }
.msg h3, .msg h4 { margin: 6px 0 4px; font-size: 16px; }
.msg ul, .msg ol { margin: 4px 0 6px; padding-left: 22px; }
.msg code { background: var(--code); border-radius: 5px; padding: 1px 4px; font-size: 14px; }
.msg pre { background: var(--code); border-radius: 8px; padding: 8px; overflow-x: auto; margin: 4px 0; }
.msg pre code { background: none; padding: 0; }
.msg table { border-collapse: collapse; font-size: 14px; display: block; overflow-x: auto; margin: 4px 0; }
.msg td, .msg th { border: 1px solid var(--line); padding: 3px 6px; }
.msg a { color: var(--accent); }
.msg img { max-width: 100%; border-radius: 8px; display: block; }
.msg audio { width: 240px; max-width: 100%; }
.btns { display: grid; gap: 6px; margin-top: 8px; }
.btns .row { display: flex; gap: 6px; flex-wrap: wrap; }
.btns button { flex: 1; padding: 8px 10px; font-size: 14px; }
.pressed { font-size: 13px; color: var(--muted); margin-top: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); }

#composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
#composer textarea { resize: none; max-height: 40dvh; }
#b-mic.rec { background: var(--err); color: #fff; border-color: var(--err); }
