:root {
  --bg: #f7f7f5; --panel: #ffffff; --text: #1d1d1b; --muted: #6b6b66; --line: #e3e2dc;
  --accent: #2f6f5e; --accent-text: #ffffff; --user: #e8f0ec; --code: #f0efea; --err: #b3261e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161716; --panel: #1f201f; --text: #e8e7e2; --muted: #9a9a93; --line: #31322f;
    --accent: #5fae97; --accent-text: #0e1a16; --user: #23302b; --code: #2a2b29; --err: #f2b8b5;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}
button, select, input, textarea { font: inherit; color: inherit; }
button {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 600;
}
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 500; }
button.stop { background: var(--err); color: var(--panel); }
select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; max-width: 46vw; }

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 2;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; user-select: none; }

main { flex: 1; overflow-y: auto; padding: 20px 16px 8px; }
.empty { max-width: 720px; margin: 12vh auto 0; text-align: center; color: var(--muted); }
.empty h1 { color: var(--text); font-size: 22px; margin: 0 0 6px; }

.msg { max-width: 760px; margin: 0 auto 14px; display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { padding: 10px 14px; border-radius: 12px; max-width: 100%; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); max-width: 85%; white-space: pre-wrap; }
.msg.ai .bubble { background: var(--panel); border: 1px solid var(--line); width: 100%; }
.msg.ai .bubble p { margin: 0 0 .7em; }
.msg.ai .bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: var(--code); padding: 10px 12px; border-radius: 8px; overflow-x: auto; margin: .6em 0; }
.bubble code { background: var(--code); padding: 1px 5px; border-radius: 4px; font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; }
.bubble pre code { background: none; padding: 0; }
.bubble ul, .bubble ol { margin: .3em 0 .7em; padding-left: 1.4em; }
.bubble h3, .bubble h4 { margin: .6em 0 .3em; font-size: 1em; }
details.thinking { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
details.thinking div { white-space: pre-wrap; border-left: 2px solid var(--line); padding-left: 10px; margin-top: 4px; }
.meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.err { color: var(--err); }
.cursor::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.composer {
  display: flex; gap: 8px; align-items: flex-end;
  max-width: 792px; width: 100%; margin: 0 auto; padding: 8px 16px 0;
}
.composer textarea {
  flex: 1; resize: none; max-height: 40vh; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); outline-color: var(--accent);
}
.status { max-width: 792px; width: 100%; margin: 0 auto; padding: 4px 16px calc(10px + env(safe-area-inset-bottom)); color: var(--muted); font-size: 12px; min-height: 1.6em; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); padding: 22px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
dialog p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
dialog input[type=password] { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); margin-bottom: 10px; }
dialog button { width: 100%; margin-top: 12px; }

@media (max-width: 560px) {
  .bar { padding: 8px 12px; }
  .controls { width: 100%; }
  select { flex: 1; max-width: none; }
  .msg.user .bubble { max-width: 92%; }
}
