:root {
  --bg: #f6f5f2; --surface: #ffffff; --ink: #1d1d20; --sub: #6b6a70; --line: #e4e2dc;
  --accent: #1f5eff; --accent-ink: #ffffff; --warn: #b4431f; --ok: #1d7a46; --chip: #efeee9;
  --radius: 14px; color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151517; --surface: #1f1f23; --ink: #ecebe7; --sub: #9a99a0; --line: #2e2e33;
    --accent: #6b93ff; --accent-ink: #0d0d10; --warn: #ff8a66; --ok: #5fd08e; --chip: #2a2a2f; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; -webkit-text-size-adjust: 100%; }
#app { min-height: 100dvh; display: flex; flex-direction: column; max-width: 640px; margin: 0 auto; }
main { flex: 1; padding: 12px 16px 96px; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
textarea, input { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; resize: none; }

.bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.back { font-size: 28px; line-height: 1; padding: 0 8px 0 0; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--sub); }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--sub); }
.pill.connected i { background: var(--ok); }
.pill.owner_offline i, .pill.revoked i { background: var(--warn); }
.banner { margin: 0; padding: 10px 16px; background: var(--chip); color: var(--warn); font-size: 14px; }

.list { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card.permission { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.meta { font-size: 13px; color: var(--sub); }
.meta b { color: var(--ink); font-weight: 600; }
.question { margin: 0; font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.command { margin: 0; padding: 8px 10px; border-radius: 8px; background: var(--chip); font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.options { display: flex; flex-wrap: wrap; gap: 8px; }
.option { padding: 10px 14px; border-radius: 999px; background: var(--chip); font-weight: 600; min-height: 44px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; }
.primary { background: var(--accent); color: var(--accent-ink); padding: 10px 18px; border-radius: 10px; font-weight: 600; min-height: 44px; }
.quiet { background: var(--chip); padding: 10px 16px; border-radius: 10px; min-height: 44px; }
.wide { width: 100%; margin-top: 12px; }
.error { color: var(--warn); font-size: 14px; margin: 0; }
.sub { color: var(--sub); font-size: 14px; }
.empty { padding: 48px 8px; text-align: center; }
.empty p { margin: 4px 0; }

.rows { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--line); min-height: 52px; }
.row:last-child { border-bottom: 0; }
.row .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .state { color: var(--sub); font-size: 13px; flex: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }

.room h2 { font-size: 17px; margin: 4px 0 12px; overflow-wrap: anywhere; }
.messages { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.msg { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; max-width: 88%; }
.msg.mine { align-self: flex-end; background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.msg .from { font-size: 12px; color: var(--sub); margin-bottom: 2px; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.event { font-size: 13px; color: var(--sub); text-align: center; }
.composer { position: sticky; bottom: 0; display: flex; gap: 8px; align-items: flex-end; padding: 8px 0 calc(env(safe-area-inset-bottom) + 8px); background: var(--bg); }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: center; background: var(--bg); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tab { flex: 1; max-width: 213px; padding: 12px 4px 14px; font-size: 14px; color: var(--sub); display: inline-flex; justify-content: center; align-items: center; gap: 6px; min-height: 52px; }
.tab.on { color: var(--ink); font-weight: 600; }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 12px; min-width: 20px; padding: 1px 6px; font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 14px; }

.pair { padding: calc(env(safe-area-inset-top) + 40px) 20px 40px; }
.pair h1 { font-size: 24px; margin: 0 0 16px; }
.pair label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--sub); }
.code { font: 700 40px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .06em; padding: 18px 0; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 8px 0 12px; }

.scrim { position: fixed; inset: 0; z-index: 5; background: color-mix(in srgb, #000 45%, transparent); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; background: var(--surface); border-radius: 18px 18px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 16px); display: flex; flex-direction: column; gap: 12px; max-height: 85dvh; overflow-y: auto; }
.sheet h2 { margin: 0; font-size: 19px; }
.sheet .command { max-height: 40dvh; overflow-y: auto; }
.sheet .actions { justify-content: stretch; }
.sheet .actions button { flex: 1; }
.note { margin: 0; font-size: 14px; color: var(--sub); }
.pair code, .note code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
