:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #1b1c1f; --muted: #6d7078; --line: #e3e1dc;
  --mine: #1f3a5f; --mine-ink: #f4f6fa; --theirs: #ffffff; --accent: #b4532a;
  --ok: #2f8f5b; --warn: #c9932b; --off: #9a9da4;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14161a; --panel: #1d2026; --ink: #eceae6; --muted: #9a9da4; --line: #2b2f36; --mine: #2d4f7c; --theirs: #23272e; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; }

#pair { display: grid; place-items: center; min-height: 100%; padding: 24px 16px; }
#pair form { width: 100%; max-width: 380px; display: grid; gap: 14px; }
#pair h1 { margin: 0; font-size: 24px; }
#pair p { margin: 0; color: var(--muted); }
#pair label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
#pair input { font-size: 18px; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
#pair button { padding: 14px; border: 0; border-radius: 10px; background: var(--mine); color: var(--mine-ink); font-weight: 600; }
#pair-error { color: var(--accent) !important; min-height: 1.4em; }

#chat { display: flex; flex-direction: column; height: 100dvh; }
header { display: flex; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.who { display: grid; flex: 1; min-width: 0; }
.who small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#account { color: var(--muted); font-size: 13px; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--off); flex: none; }
.conn.on { background: var(--ok); } .conn.half { background: var(--warn); }
.ghost { border: 1px solid var(--line); background: none; border-radius: 8px; padding: 4px 10px; font-size: 13px; }

#thread { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; -webkit-overflow-scrolling: touch; }
.msg { max-width: 82%; padding: 9px 12px; border-radius: 16px; position: relative; display: grid; gap: 4px; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; background: var(--mine); color: var(--mine-ink); border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; background: var(--theirs); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.kind-notify { border-left: 3px solid var(--accent); }
.msg .meta { display: flex; gap: 8px; font-size: 11px; opacity: .7; justify-content: flex-end; }
.msg.theirs .meta { justify-content: flex-start; }
.play { justify-self: start; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg); }
.play svg { width: 18px; height: 18px; fill: currentColor; }
.play.playing { background: var(--accent); color: #fff; border-color: var(--accent); }

footer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px); background: var(--panel); border-top: 1px solid var(--line); }
#input { flex: 1; resize: none; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 20px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); max-height: 140px; }
footer button { flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0; background: none; display: grid; place-items: center; }
footer button svg { width: 24px; height: 24px; fill: currentColor; }
#btn-send { background: var(--mine); color: var(--mine-ink); }
#btn-rec.recording { background: var(--accent); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 30%, transparent); } }
@media (prefers-reduced-motion: reduce) { #btn-rec.recording { animation: none; } }
