:root {
  --bg: #f6f6f4; --panel: #ffffff; --text: #151515; --muted: #6b6b6b; --line: #e3e3df;
  --mine: #1f1f1f; --mine-text: #ffffff; --theirs: #ebebe7; --accent: #1f1f1f; --danger: #b3261e; --ok: #2e7d32;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111; --panel: #1a1a1a; --text: #f1f1ef; --muted: #9a9a96; --line: #2a2a2a;
    --mine: #f1f1ef; --mine-text: #111111; --theirs: #262626; --accent: #f1f1ef; --danger: #ef6b62; --ok: #66bb6a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 720px; margin: 0 auto; }
header {
  display: grid; grid-template-columns: 80px 1fr 80px; align-items: center;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; border-bottom: 1px solid var(--line); background: var(--panel);
}
header h2 { margin: 0; font-size: 17px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header > :last-child { justify-self: end; }
.hspace { width: 1px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: middle; }
.dot.on { background: var(--ok); } .dot.off { background: var(--muted); }
button { font: inherit; border: 0; cursor: pointer; }
button.link { background: none; color: var(--text); padding: 6px 4px; }
button.link.danger { color: var(--danger); }
button.primary { background: var(--accent); color: var(--bg); border-radius: 10px; padding: 12px 16px; font-weight: 600; }
button:disabled { opacity: .5; }
button.banner { display: block; width: calc(100% - 24px); margin: 12px; padding: 12px; border-radius: 10px; background: var(--theirs); color: var(--text); }
p.banner.warn { margin: 0; padding: 10px 14px; background: #fff3cd; color: #5c4400; font-size: 14px; }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list li { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:active { background: var(--theirs); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row.gap { justify-content: flex-start; gap: 16px; }
.preview { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.badge { background: var(--accent); color: var(--bg); border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .02em; }
.center { text-align: center; padding: 24px; }
.err { color: var(--danger); min-height: 1.2em; }
.warn { color: var(--danger); }
.card { background: var(--panel); margin: 12px; padding: 16px; border-radius: 14px; border: 1px solid var(--line); }
.card h1 { margin: 0 0 8px; font-size: 26px; }
.card h3 { margin: 0 0 8px; font-size: 17px; }
.card ol { padding-left: 20px; }
.card ol li { margin: 6px 0; }
.card input { width: 100%; font: inherit; padding: 12px; margin: 8px 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.card > button.primary { width: 100%; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: 10px 0; border-top: 1px solid var(--line); }
ul.plain li:first-child { border-top: 0; }
p.note { margin: 0; padding: 6px 14px; font-size: 12px; text-align: center; color: var(--muted); border-bottom: 1px solid var(--line); }
.msgs { flex: 1; overflow-y: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
.msg { display: flex; flex-direction: column; max-width: 80%; margin: 4px 0 10px; }
.msg.mine { margin-left: auto; align-items: flex-end; }
.msg.theirs { margin-right: auto; align-items: flex-start; }
.bubble { padding: 9px 13px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.mine .bubble { background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 6px; }
.theirs .bubble { background: var(--theirs); border-bottom-left-radius: 6px; }
.who { font-size: 12px; color: var(--muted); margin: 0 6px 2px; }
.meta { font-size: 11px; color: var(--muted); margin: 2px 6px 0; }
.composer {
  display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
  border-top: 1px solid var(--line); background: var(--panel);
}
.composer textarea {
  flex: 1; resize: none; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); max-height: 140px;
}
.composer .send { border-radius: 18px; padding: 10px 16px; }
