:root {
  --bg: #0a0a0a;
  --fg: #ececec;
  --dim: #8a8a8a;
  --line: #1e1e1e;
  --bubble: #171717;
  --accent: #e8e8e8;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
#bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
#title { font-weight: 600; letter-spacing: .2px; }
#menu { background: none; border: 0; color: var(--dim); font-size: 20px; padding: 4px 8px; cursor: pointer; }
#menu-sheet {
  position: fixed; right: 12px; top: 52px; z-index: 20;
  background: #141414; border: 1px solid var(--line); border-radius: 12px;
  padding: 6px; display: flex; flex-direction: column; min-width: 180px;
}
#menu-sheet button {
  background: none; border: 0; color: var(--fg); text-align: left;
  padding: 10px 12px; border-radius: 8px; font-size: 15px; cursor: pointer;
}
#menu-sheet button:hover { background: #1f1f1f; }
#thread {
  flex: 1; overflow-y: auto; padding: 20px 16px 8px;
  display: flex; flex-direction: column; gap: 18px;
  max-width: 760px; width: 100%; margin: 0 auto;
}
.msg { display: flex; flex-direction: column; gap: 4px; max-width: 100%; }
.msg.user { align-items: flex-end; }
.msg.user .body {
  background: var(--bubble); padding: 10px 14px; border-radius: 18px;
  max-width: 85%; white-space: pre-wrap; word-wrap: break-word;
}
.msg.assistant .body { white-space: pre-wrap; word-wrap: break-word; }
.msg.assistant .body p { margin: 0 0 10px; }
.msg.assistant .body p:last-child { margin-bottom: 0; }
.msg.assistant .body code {
  background: #1a1a1a; padding: 1px 5px; border-radius: 5px; font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.msg.assistant .body pre {
  background: #141414; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; overflow-x: auto; margin: 10px 0;
}
.msg.assistant .body pre code { background: none; padding: 0; }
.msg.assistant .body ul, .msg.assistant .body ol { margin: 8px 0; padding-left: 22px; }
.msg.assistant .body a { color: #7aa2f7; }
.cursor::after { content: "▍"; color: var(--dim); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
#composer {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; gap: 8px; align-items: flex-end;
  max-width: 760px; width: 100%; margin: 0 auto;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
#input {
  flex: 1; resize: none; max-height: 40vh;
  background: #141414; color: var(--fg);
  border: 1px solid var(--line); border-radius: 22px;
  padding: 12px 16px; font: inherit; outline: none;
}
#input:focus { border-color: #333; }
#send {
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: var(--accent); color: #0a0a0a; font-size: 18px; font-weight: 700;
  cursor: pointer; flex: 0 0 auto;
}
#send:disabled { opacity: .35; cursor: default; }
body.login { display: grid; place-items: center; }
#login-form { display: flex; flex-direction: column; gap: 12px; width: min(340px, 86vw); }
#login-form h1 { font-size: 22px; margin: 0 0 8px; font-weight: 600; }
#login-form input {
  background: #141414; border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 15px; color: var(--fg); font: inherit; outline: none;
}
#login-form button {
  background: var(--accent); color: #0a0a0a; border: 0; border-radius: 12px;
  padding: 13px; font: inherit; font-weight: 600; cursor: pointer;
}
#err { color: #f7768e; font-size: 14px; min-height: 18px; margin: 0; }
