:root {
  --bg: #f6f5f2; --surface: #ffffff; --text: #1d1d1f; --muted: #6b6b70; --line: #e3e1dc;
  --accent: #1f6f5c; --accent-text: #ffffff; --pm: #1f6f5c; --pm-text: #ffffff; --claude: #ffffff;
  --on: #2e9d58; --busy: #d99a1e; --off: #a0a0a6; --error: #b3261e;
  --code-bg: rgba(0, 0, 0, .06); --pick: #e7f2ee;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416; --surface: #1e1e21; --text: #ececee; --muted: #9a9aa1; --line: #2e2e33;
    --accent: #4cb393; --accent-text: #0d1f1a; --pm: #2c6e5d; --pm-text: #f2fbf8; --claude: #232327;
    --error: #f2b8b5; --code-bg: rgba(255, 255, 255, .08); --pick: #1d3a32; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang HK", "Microsoft JhengHei", sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; border: 0; border-radius: 10px; padding: 10px 16px; background: var(--accent); color: var(--accent-text); cursor: pointer; font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); padding: 6px 12px; font-weight: 500; }
input, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.muted { color: var(--muted); margin: 0 0 16px; }
.error { color: var(--error); min-height: 1.5em; margin: 8px 0 0; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; display: grid; gap: 8px; }
.card h1 { font-size: 20px; margin: 0; }
.card label { font-size: 13px; color: var(--muted); }
.card button { margin-top: 8px; }

.chat { height: 100%; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--bg); }
.title { display: grid; gap: 2px; min-width: 0; }
.presence { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; min-width: 0; }
.presence span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.presence i { width: 8px; height: 8px; border-radius: 50%; background: var(--off); flex: none; }
.presence.on i { background: var(--on); }
.presence.busy i { background: var(--busy); }

.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.day { align-self: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.msg { max-width: min(85%, 640px); display: grid; gap: 2px; }
.msg .body { padding: 10px 14px; border-radius: 14px; overflow-wrap: anywhere; min-width: 0; }
.msg .meta { font-size: 11px; color: var(--muted); padding: 0 6px; }
.msg.pm { align-self: flex-end; }
.msg.pm .body { background: var(--pm); color: var(--pm-text); border-bottom-right-radius: 4px; }
.msg.pm .meta { text-align: right; }
.msg.claude { align-self: flex-start; }
.msg.claude .body { background: var(--claude); border: 1px solid var(--line); border-bottom-left-radius: 4px; }

.composer { display: flex; gap: 8px; align-items: flex-end; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.composer textarea { resize: none; max-height: 200px; }
.notice { margin: 0; padding: 0 16px 8px; font-size: 12px; color: var(--muted); min-height: 0; }
.notice:empty { display: none; }

/* formatted message text (public/format.js) */
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body p, .body ul, .body ol, .body pre, .body blockquote, .body .table-wrap { margin: 0 0 8px; }
.body h3, .body h4, .body h5, .body h6 { margin: 12px 0 4px; line-height: 1.3; }
.body h3 { font-size: 1.15em; } .body h4 { font-size: 1.05em; } .body h5, .body h6 { font-size: 1em; }
.body ul, .body ol { padding-left: 1.4em; }
.body li + li { margin-top: 2px; }
.body li > ul, .body li > ol { margin: 2px 0 0; }
.body li.task { list-style: none; margin-left: -1.1em; }
.body code { font: .9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.body pre { background: var(--code-bg); padding: 8px 10px; border-radius: 8px; overflow-x: auto; }
.body pre code { background: none; padding: 0; white-space: pre; }
.body blockquote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--muted); }
.msg.pm .body blockquote { color: inherit; opacity: .85; border-color: rgba(255, 255, 255, .4); }
.body hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.body a { color: var(--accent); }
.msg.pm .body a { color: inherit; }
.body .table-wrap { overflow-x: auto; }
.body table { border-collapse: collapse; font-size: .93em; }
.body th, .body td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.body th { background: var(--code-bg); }
.reply-to { font-size: 12px; opacity: .8; margin-bottom: 4px; }

/* a question with radio choices */
.choices { margin-top: 10px; }
.choices fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; min-width: 0; }
.choices legend { font-size: 12px; color: var(--muted); padding: 0; margin-bottom: 6px; }
.choices label { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.choices label:has(input:checked) { border-color: var(--accent); background: var(--pick); }
.choices input[type=radio], .choices input[type=checkbox] { width: auto; margin: 3px 0 0; accent-color: var(--accent); flex: none; }
.choices textarea { resize: vertical; min-height: 38px; }
.choice-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.choice-row button { padding: 8px 14px; }
.choice-status { font-size: 12px; color: var(--muted); }
.choices.answered label { cursor: default; }
.choices.answered label:not(.picked) { opacity: .55; }

/* a round: several questions in one form, one send button */
.choices.round { display: grid; gap: 14px; }
.choices.round fieldset + fieldset { border-top: 1px solid var(--line); padding-top: 12px; }
.choices.round .choice-row { margin-top: -4px; }
.q-text { font-weight: 600; overflow-wrap: anywhere; }
.q-text p { margin: 0; }
.choices.round fieldset.open legend::after { content: " · not answered"; }
