:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #6b6f76;
  --border: #e3e1dd;
  --accent: #c8643b;
  --ok: #2f8f5b;
  --warn: #b7860b;
  --err: #c0392b;
  --code: #f0eeea;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2025;
    --text: #e8e6e3;
    --muted: #8f949c;
    --border: #2c3036;
    --accent: #e8875b;
    --ok: #4cc38a;
    --warn: #e0b341;
    --err: #ef6b5b;
    --code: #262a30;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 14px; cursor: pointer; min-height: 44px;
}
button.ghost { background: transparent; color: var(--muted); }
button.danger { background: var(--err); }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%;
}

/* Login */
#login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px; width: min(360px, 100%); display: grid; gap: 14px; }
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.error { color: var(--err); margin: 0; min-height: 1em; font-size: 14px; }

/* App */
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
header {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border); background: var(--bg); position: sticky; top: 0;
}
header select { flex: 1; min-width: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--err); flex: none; }
.dot.on { background: var(--ok); }
.state { padding: 6px 16px; font-size: 13px; color: var(--muted); }
.state .busy { color: var(--warn); }
.state .idle { color: var(--ok); }

#feed { flex: 1; overflow-y: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.ev { border-radius: 12px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); overflow-wrap: anywhere; }
.ev .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; margin-bottom: 4px; }
.ev .body { white-space: pre-wrap; }
.ev.prompt { border-left: 3px solid var(--accent); }
.ev.answer { border-left: 3px solid var(--ok); }
.ev.answer.bad { border-left-color: var(--err); }
.ev.remote { border-style: dashed; }
.ev.tool { padding: 6px 12px; background: transparent; font-size: 13px; }
.ev.tool .body { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.tool.err .body { color: var(--err); }
.ev.wait { border-left: 3px solid var(--warn); }
.ev.system { background: transparent; border: 0; text-align: center; font-size: 12px; color: var(--muted); padding: 2px; }
.more { align-self: center; }

#compose {
  display: flex; gap: 8px; padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--bg);
}
#compose textarea { resize: none; max-height: 40vh; min-height: 44px; }
#compose button { flex: none; width: 48px; padding: 0; }
