:root {
  --bg: #0f1420; --bg2: #141b2b; --panel: #182136; --border: #26304a;
  --text: #e8edf6; --muted: #97a3bd; --accent: #5b8cff; --accent-2: #2ee6a6;
  --user: #22314f; --tool: #2a2140;
}
@media (prefers-color-scheme: light) {
  :root { --bg:#f6f8fc; --bg2:#eef2f8; --panel:#fff; --border:#e2e8f2; --text:#141b2b; --muted:#5b6577; --accent:#2f6bd6; --user:#e6eefc; --tool:#efe9fb; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  display: flex; flex-direction: column; min-height: 100dvh;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: env(safe-area-inset-top) 0 0;
}
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.title { font-weight: 700; }
.bar-actions { display: flex; gap: 8px; }
.ghost { background: none; border: 1px solid var(--border); color: var(--muted); border-radius: 8px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.ghost:hover { color: var(--text); border-color: var(--accent); }

/* Login overlay */
.login { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: var(--bg); }
.login[hidden] { display: none; } /* the [hidden] attr alone is overridden by .login's display:flex */
.login-card { width: 100%; max-width: 360px; text-align: center; background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 28px 24px; }
.login-emoji { font-size: 40px; }
.login-card h1 { font-size: 22px; margin: 10px 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.login-card input { width: 100%; border: 1px solid var(--border); background: var(--bg2); color: var(--text); border-radius: 12px; padding: 12px 14px; font-size: 16px; outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-error { color: #ff6b78; font-size: 13px; margin-top: 10px; }
.login-btn { width: 100%; margin-top: 14px; border: none; background: var(--accent); color: #fff; border-radius: 12px; padding: 12px; font-size: 15px; font-weight: 700; cursor: pointer; }
.login-btn:disabled { opacity: .5; }

.messages { flex: 1; overflow-y: auto; padding: 20px 0 12px; }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }

.msg { max-width: 760px; margin: 0 auto 16px; padding: 0 16px; }
.msg .role { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.msg.user .bubble { background: var(--user); }
.bubble { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; }

/* Rendered Markdown (applied once a response finishes streaming) */
.bubble.md { white-space: normal; }
.bubble.md > :first-child { margin-top: 0; }
.bubble.md > :last-child { margin-bottom: 0; }
.bubble.md p { margin: 8px 0; }
.bubble.md .md-h { font-weight: 700; margin: 14px 0 6px; line-height: 1.3; }
.bubble.md .md-h1 { font-size: 20px; } .bubble.md .md-h2 { font-size: 18px; }
.bubble.md .md-h3 { font-size: 16px; } .bubble.md .md-h4 { font-size: 15px; }
.bubble.md ul, .bubble.md ol { margin: 8px 0; padding-left: 22px; }
.bubble.md li { margin: 4px 0; }
.bubble.md code { font-family: ui-monospace, Menlo, monospace; background: var(--bg2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.bubble.md pre.code { background: var(--bg2); border: 1px solid var(--border); padding: 12px; border-radius: 10px; overflow-x: auto; margin: 10px 0; }
.bubble.md pre.code code { background: none; border: none; padding: 0; }
.bubble.md a { color: var(--accent); }
.bubble.md hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.bubble.md .md-table-wrap { overflow-x: auto; margin: 10px 0; }
.bubble.md table { border-collapse: collapse; font-size: 14px; }
.bubble.md th, .bubble.md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.bubble.md th { background: var(--bg2); font-weight: 700; }
.bubble .cursor { display: inline-block; width: 7px; height: 16px; background: var(--accent); border-radius: 1px; vertical-align: -3px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.tool-chip { font-size: 12px; font-weight: 600; color: var(--accent-2); background: var(--tool); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; }
.meta { font-size: 12px; color: var(--muted); margin-top: 8px; }
.err { color: #ff6b78; }

.empty { max-width: 620px; margin: 8vh auto; text-align: center; color: var(--muted); padding: 0 20px; }
.empty .emoji { font-size: 48px; }
.empty h1 { color: var(--text); font-size: 24px; margin: 12px 0 6px; }
.empty code { background: var(--panel); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; }
.suggestions { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.chip { text-align: left; background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 12px; padding: 12px 14px; font-size: 14px; cursor: pointer; }
.chip:hover { border-color: var(--accent); }

.composer {
  display: flex; align-items: flex-end; gap: 10px; max-width: 760px; width: 100%;
  margin: 0 auto; padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--bg);
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--border); background: var(--bg2); color: var(--text);
  border-radius: 16px; padding: 12px 14px; font-size: 16px; font-family: inherit; max-height: 160px; outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.send {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 18px; cursor: pointer;
}
.send:disabled { opacity: .4; cursor: default; }
