:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #1d1d1f; --muted: #6e6e73; --line: #e2e0da;
  --accent: #2f5bd3; --accent-ink: #ffffff; --me: #e7edfb; --tool: #8a8a8f;
  --working: #b26b00; --asking: #c62f2f; --idle: #2e7d4f; --off: #8a8a8f;
  --term-bg: #15161a; --term-ink: #d8d8dc;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101113; --panel: #1a1b1f; --ink: #ececf0; --muted: #9a9aa2; --line: #2b2c31;
    --accent: #6d8cff; --accent-ink: #0d0e12; --me: #1f2a44; --tool: #85858d;
    --working: #f0a43a; --asking: #ff6b6b; --idle: #5cc98a; --off: #7a7a82;
  }
}
:root[data-theme="dark"] {
  --bg: #101113; --panel: #1a1b1f; --ink: #ececf0; --muted: #9a9aa2; --line: #2b2c31;
  --accent: #6d8cff; --accent-ink: #0d0e12; --me: #1f2a44; --tool: #85858d;
  --working: #f0a43a; --asking: #ff6b6b; --idle: #5cc98a; --off: #7a7a82;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; min-height: 100vh;
  overflow-x: hidden; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
.pad { padding: 12px 16px; }
#bar { position: sticky; top: 0; z-index: 5; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
#bar .row { display: flex; align-items: center; gap: 10px; }
#bar h1 { font-size: 17px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon { font-size: 30px; line-height: 1; color: var(--accent); text-decoration: none; padding: 0 6px 4px 0; }
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 10px;
  padding: 10px 16px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.wide { display: block; width: 100%; margin: 12px 0; }
.btn:disabled { opacity: .5; }
.lead { font-size: 18px; margin: 24px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.chip { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 3px 8px;
  border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.chip.working { color: var(--working); } .chip.asking { color: var(--asking); } .chip.idle { color: var(--idle); }
.chip.exited, .chip.stopped { color: var(--off); }
.card { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
  margin: 0 0 10px; color: inherit; text-decoration: none; }
.card .row { display: flex; align-items: center; gap: 8px; }
.card strong { font-size: 17px; }
.card .right { margin-left: auto; font-size: 13px; }
.card p { margin: 6px 0 0; }
.snippet { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.signout { display: block; margin: 18px auto 8px; background: none; border: 0; color: var(--muted); font: inherit; text-decoration: underline; }
.tabs { display: flex; gap: 6px; margin-top: 10px; }
.tabs button { flex: 1; padding: 7px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  color: var(--ink); font: inherit; font-weight: 600; }
.tabs button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
#chat { padding-bottom: 190px; }
.msg { margin: 10px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { background: var(--me); border-radius: 14px 14px 4px 14px; padding: 8px 12px; margin-left: 12%; }
.msg.assistant { background: var(--panel); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; padding: 8px 12px; margin-right: 6%; }
.msg.tool { color: var(--tool); font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; margin: 4px 0; padding-left: 10px;
  border-left: 2px solid var(--line); }
.msg.note { color: var(--muted); font-size: 13px; text-align: center; }
.msg time { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
#screenbox { padding: 8px 16px 190px; }
.zoom { display: flex; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.zoom button { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 4px 12px; font: inherit; }
#screen { margin: 0; background: var(--term-bg); color: var(--term-ink); border-radius: 10px; padding: 10px; overflow-x: auto;
  font: 11px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; max-width: 100%; }
#screen.nowrap { white-space: pre; overflow-wrap: normal; }
#compose { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--panel); border-top: 1px solid var(--line);
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); }
.keys { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.keys button { flex: 0 0 auto; min-width: 42px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink); font: 14px ui-monospace, SFMono-Regular, Menlo, monospace; }
.keys button.danger { color: var(--asking); }
.keys button.armed { background: var(--asking); color: #fff; }
#form { display: flex; gap: 8px; align-items: flex-end; }
#text { flex: 1; min-width: 0; resize: none; max-height: 40vh; border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px;
  background: var(--bg); color: var(--ink); font: 16px/1.35 inherit; font-family: inherit; }
#sendmsg { margin: 4px 0 0; min-height: 1em; }
