:root {
  --bg: #ffffff;
  --bg-elev: #f5f5f7;
  --bg-sidebar: #fbfbfd;
  --text: #1d1d1f;
  --text-dim: #6e6e73;
  --sep: rgba(0,0,0,0.10);
  --accent: #0071e3;
  --accent-press: #0060c0;
  --bubble-user: #0071e3;
  --bubble-user-text: #ffffff;
  --bubble-ai: #f0f0f2;
  --code-bg: #1d1d1f;
  --code-text: #f5f5f7;
  --danger: #ff3b30;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 8px 30px rgba(0,0,0,0.06);
  --header-blur: rgba(255,255,255,0.72);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --bg-sidebar: #0d0d0f;
    --text: #f5f5f7;
    --text-dim: #98989d;
    --sep: rgba(255,255,255,0.12);
    --accent: #0a84ff;
    --accent-press: #409cff;
    --bubble-user: #0a84ff;
    --bubble-user-text: #ffffff;
    --bubble-ai: #1c1c1e;
    --code-bg: #000000;
    --code-text: #f5f5f7;
    --header-blur: rgba(20,20,22,0.72);
    --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 8px 30px rgba(0,0,0,0.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  font-size: 17px; line-height: 1.47;
}
body { overflow: hidden; }
#app { height: 100dvh; }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
[hidden] { display: none !important; }

/* ---------------- Login ---------------- */
.login {
  height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  background: var(--bg);
}
.login-card {
  width: 100%; max-width: 340px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  animation: rise .5s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.brand-logo {
  width: 84px; height: 84px; border-radius: 22px;
  background: var(--accent);
  display: grid; place-items: center; box-shadow: var(--shadow);
}
.brand-logo svg { width: 52px; height: 52px; }
.login h1 { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; margin: 2px 0 0; }
.login p { margin: 0; color: var(--text-dim); font-size: 15px; }
.code-input {
  width: 100%; text-align: center; padding: 15px 16px; border-radius: 14px;
  background: var(--bg-elev); border: 1px solid var(--sep); outline: none;
  font-size: 20px; letter-spacing: 0.12em; transition: border-color .2s;
}
.code-input:focus { border-color: var(--accent); }
.btn-primary {
  width: 100%; padding: 14px 16px; border-radius: 14px; font-weight: 600;
  background: var(--accent); color: #fff; transition: background .15s, transform .05s;
}
.btn-primary:active { background: var(--accent-press); transform: scale(.99); }
.btn-primary:disabled { opacity: .5; }
.err { color: var(--danger); font-size: 14px; min-height: 18px; }

/* ---------------- Main layout ---------------- */
#main { height: 100dvh; display: flex; }
#sidebar {
  width: 288px; flex-shrink: 0; background: var(--bg-sidebar);
  border-right: 1px solid var(--sep); display: flex; flex-direction: column;
  padding-top: var(--safe-top); padding-left: var(--safe-left);
}
.side-head {
  padding: 14px 14px 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.side-title { font-weight: 700; font-size: 20px; letter-spacing: -.02em; }
.new-chat {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 12px;
  background: var(--bg-elev); font-size: 15px; font-weight: 500; transition: background .15s;
}
.new-chat:active { background: var(--sep); }
.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px calc(12px + var(--safe-bottom)); }
.chat-item {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px;
  cursor: pointer; color: var(--text); position: relative;
}
.chat-item:hover { background: var(--bg-elev); }
.chat-item.active { background: var(--bg-elev); }
.chat-item .title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.chat-item .del {
  opacity: 0; color: var(--text-dim); padding: 2px 6px; border-radius: 8px; font-size: 13px; transition: opacity .15s;
}
.chat-item:hover .del, .chat-item.active .del { opacity: .7; }
.chat-item .del:active { color: var(--danger); }

/* ---------------- Chat pane ---------------- */
#chatPane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + var(--safe-top)) calc(14px + var(--safe-right)) 8px calc(14px + var(--safe-left));
  background: var(--header-blur); backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--sep);
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  color: var(--text); transition: background .15s;
}
.icon-btn:active { background: var(--bg-elev); }
.icon-btn svg { width: 22px; height: 22px; }
#menuBtn { display: none; }
.pill-select {
  appearance: none; -webkit-appearance: none; padding: 7px 30px 7px 13px; border-radius: 11px;
  background: var(--bg-elev); border: 1px solid var(--sep); font-size: 14px; font-weight: 500;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='3'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
}
.spacer { flex: 1; }

#messages { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.messages-inner { max-width: 760px; margin: 0 auto; padding: 22px 18px 8px; }
.empty {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: var(--text-dim); text-align: center; padding: 40px;
}
.empty .brand-logo { width: 64px; height: 64px; border-radius: 18px; }
.empty .brand-logo svg { width: 40px; height: 40px; }
.empty h2 { color: var(--text); font-weight: 600; letter-spacing: -.02em; margin: 4px 0 0; }

.msg { display: flex; margin: 14px 0; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 86%; padding: 11px 15px; border-radius: 20px; overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--bubble-user); color: var(--bubble-user-text); border-bottom-right-radius: 7px; }
.msg.ai .bubble { background: transparent; color: var(--text); max-width: 100%; padding-left: 0; padding-right: 0; }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1,.bubble h2,.bubble h3 { letter-spacing: -.01em; line-height: 1.3; margin: 14px 0 8px; }
.bubble h1 { font-size: 22px; } .bubble h2 { font-size: 20px; } .bubble h3 { font-size: 18px; }
.bubble ul,.bubble ol { margin: 6px 0 10px; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble a { color: var(--accent); text-decoration: none; }
.bubble a:hover { text-decoration: underline; }
.bubble code.inline {
  background: var(--bg-elev); padding: 1px 6px; border-radius: 6px; font-size: .9em;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
.msg.user .bubble code.inline { background: rgba(255,255,255,.22); }
.bubble blockquote { border-left: 3px solid var(--sep); margin: 8px 0; padding: 2px 0 2px 12px; color: var(--text-dim); }

.codeblock { margin: 12px 0; border-radius: 14px; overflow: hidden; background: var(--code-bg); box-shadow: var(--shadow); }
.codeblock .cb-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: rgba(255,255,255,0.06); color: #c7c7cc; font-size: 12.5px;
}
.codeblock .cb-name { flex: 1; font-family: "SF Mono", ui-monospace, Menlo, monospace; }
.codeblock .cb-btn { color: #c7c7cc; padding: 3px 9px; border-radius: 8px; font-size: 12.5px; background: rgba(255,255,255,.08); }
.codeblock .cb-btn:active { background: rgba(255,255,255,.18); }
.codeblock pre { margin: 0; padding: 13px 14px; overflow-x: auto; }
.codeblock code {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 13.5px; line-height: 1.55;
  color: var(--code-text); white-space: pre;
}

.thinking {
  margin: 4px 0 10px; border-radius: 12px; background: var(--bg-elev); border: 1px solid var(--sep); overflow: hidden;
}
.thinking summary {
  list-style: none; cursor: pointer; padding: 8px 13px; font-size: 13.5px; color: var(--text-dim);
  display: flex; align-items: center; gap: 7px; user-select: none;
}
.thinking summary::-webkit-details-marker { display: none; }
.thinking[open] summary { border-bottom: 1px solid var(--sep); }
.thinking .think-body {
  padding: 10px 13px; font-size: 14px; color: var(--text-dim); white-space: pre-wrap;
  max-height: 320px; overflow-y: auto;
}
.think-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100%{opacity:.35;} 50%{opacity:1;} }

.att-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 2px; }
.att-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border-radius: 12px;
  background: var(--bg-elev); border: 1px solid var(--sep); font-size: 13.5px; max-width: 220px;
}
.msg.user .att-chip { background: rgba(255,255,255,.18); border-color: transparent; color: #fff; }
.att-chip img { width: 30px; height: 30px; border-radius: 7px; object-fit: cover; }
.att-chip .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-chip a { color: inherit; text-decoration: none; }

.typing { display: inline-flex; gap: 4px; padding: 6px 2px; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); animation: bounce 1.2s infinite; }
.typing span:nth-child(2){ animation-delay: .15s; } .typing span:nth-child(3){ animation-delay: .3s; }
@keyframes bounce { 0%,60%,100%{ transform: translateY(0); opacity:.4;} 30%{ transform: translateY(-5px); opacity:1;} }

/* ---------------- Composer ---------------- */
#composer {
  border-top: 1px solid var(--sep); background: var(--header-blur);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  padding: 8px calc(12px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(12px + var(--safe-left));
}
.composer-wrap { max-width: 760px; margin: 0 auto; }
#attachRow { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 2px 6px; }
#attachRow:empty { display: none; }
.pending-att {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 9px; border-radius: 11px;
  background: var(--bg-elev); border: 1px solid var(--sep); font-size: 13px; max-width: 200px;
}
.pending-att img { width: 26px; height: 26px; border-radius: 6px; object-fit: cover; }
.pending-att .x { color: var(--text-dim); font-weight: 700; padding: 0 2px; }
.pending-att.uploading { opacity: .6; }
.composer-inner {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--bg-elev); border: 1px solid var(--sep); border-radius: 22px; padding: 5px 6px 5px 8px;
}
#input {
  flex: 1; resize: none; border: none; outline: none; background: transparent;
  max-height: 180px; padding: 8px 4px; line-height: 1.4;
}
.send-btn {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; flex-shrink: 0; transition: background .15s, opacity .15s;
}
.send-btn:disabled { opacity: .35; }
.send-btn svg { width: 20px; height: 20px; }
.tool-btn { width: 36px; height: 36px; border-radius: 50%; color: var(--text-dim); display: grid; place-items: center; flex-shrink: 0; }
.tool-btn:active { background: var(--sep); }
.tool-btn svg { width: 22px; height: 22px; }

/* ---------------- Mobile ---------------- */
#scrim { display: none; }
@media (max-width: 760px) {
  #menuBtn { display: grid; }
  #sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 50; width: 82%; max-width: 320px;
    transform: translateX(-102%); transition: transform .28s cubic-bezier(.2,.8,.2,1); box-shadow: var(--shadow);
  }
  #main.side-open #sidebar { transform: none; }
  #scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .28s; }
  #main.side-open #scrim { opacity: 1; pointer-events: auto; }
  .bubble { max-width: 90%; }
  .messages-inner { padding: 16px 14px 8px; }
}

/* ---------------- Agent status / activity ---------------- */
.agent-status { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 14px; margin: 2px 0 8px; }
.activity { margin: 2px 0 10px; border-radius: 12px; background: var(--bg-elev); border: 1px solid var(--sep); overflow: hidden; }
.activity summary { list-style: none; cursor: pointer; padding: 8px 13px; font-size: 13.5px; color: var(--text-dim); user-select: none; }
.activity summary::-webkit-details-marker { display: none; }
.activity[open] summary { border-bottom: 1px solid var(--sep); }
.activity-log { padding: 8px 12px; max-height: 260px; overflow-y: auto; }
.act-line { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 12.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 2px 0; }

/* ---------------- Artifacts (image / html) ---------------- */
.artifact { margin: 12px 0; border-radius: 14px; overflow: hidden; background: var(--bg-elev); border: 1px solid var(--sep); box-shadow: var(--shadow); }
.art-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg-sidebar); color: var(--text-dim); font-size: 12.5px; border-bottom: 1px solid var(--sep); }
.art-name { flex: 1; font-weight: 500; }
.art-head .cb-btn { color: var(--text); background: var(--bg-elev); border: 1px solid var(--sep); padding: 3px 10px; border-radius: 8px; font-size: 12.5px; }
.art-head .cb-btn:active { background: var(--sep); }
.art-body { display: flex; justify-content: center; align-items: center; padding: 14px; background:
  repeating-conic-gradient(var(--bg) 0% 25%, transparent 0% 50%) 50% / 20px 20px; }
@media (prefers-color-scheme: dark) { .art-body { background: #0d0d0f; } }
.artifact-img { max-width: 100%; max-height: 60vh; border-radius: 8px; }
.artifact-frame { width: 100%; height: 440px; border: 0; background: #fff; display: block; }
.art-code { margin: 0; padding: 12px 14px; overflow-x: auto; background: var(--code-bg); }
.art-code code { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 13px; color: var(--code-text); white-space: pre; }

/* ---------------- Math ---------------- */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 2px; }
.katex { font-size: 1.02em; }

/* ---------------- Fullscreen / standalone hardening ---------------- */
html { height: 100%; }
@supports (-webkit-touch-callout: none) {
  #app, .login, #main { min-height: -webkit-fill-available; }
}

/* ============================================================
   Phase-1 refresh: compact UI, tables, animations, polish
   ============================================================ */

/* Slightly smaller, tighter overall */
html, body { font-size: 15.5px; line-height: 1.45; }
.messages-inner { max-width: 720px; padding: 18px 16px 8px; }
.msg { margin: 11px 0; }
.bubble { font-size: 15px; padding: 10px 14px; border-radius: 18px; }
.msg.ai .bubble { font-size: 15px; }
.side-title { font-size: 18px; }
.chat-item .title { font-size: 14px; }
.pill-select { font-size: 13px; padding: 6px 26px 6px 11px; }
.icon-btn { width: 36px; height: 36px; }
.icon-btn svg { width: 20px; height: 20px; }

/* Composer: sit lower, tighter, seamless (blur only, no heavy bar) */
#composer { padding: 6px calc(10px + var(--safe-right)) calc(max(6px, var(--safe-bottom))) calc(10px + var(--safe-left)); border-top: none; background: linear-gradient(to top, var(--bg) 62%, transparent); backdrop-filter: none; -webkit-backdrop-filter: none; }
.composer-inner { border-radius: 24px; box-shadow: var(--shadow); }
#topbar { border-bottom: none; background: linear-gradient(to bottom, var(--bg) 60%, transparent); backdrop-filter: none; -webkit-backdrop-filter: none; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 12px 0; border: 1px solid var(--sep); border-radius: 12px; }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: 14px; }
.table-wrap th, .table-wrap td { padding: 8px 12px; border-bottom: 1px solid var(--sep); text-align: left; white-space: nowrap; }
.table-wrap th { background: var(--bg-elev); font-weight: 600; }
.table-wrap tr:last-child td { border-bottom: none; }

/* Math display sizing */
.katex-display { margin: 10px 0; }

/* ---- Animations ---- */
@keyframes msgIn { from { opacity: 0; transform: translateY(10px) scale(.99); } to { opacity: 1; transform: none; } }
.msg { animation: msgIn .32s cubic-bezier(.22,.8,.24,1) both; }
@keyframes artIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.artifact, .codeblock, .table-wrap { animation: artIn .35s cubic-bezier(.22,.8,.24,1) both; }
.send-btn { transition: transform .18s cubic-bezier(.2,.9,.3,1.4), background .15s, opacity .15s; }
.send-btn:not(:disabled):active { transform: scale(.88); }
.send-btn:not(:disabled):hover { transform: translateY(-1px); }
.new-chat, .chat-item, .pill-select, .tool-btn { transition: background .18s, transform .12s, box-shadow .18s; }
.new-chat:active, .tool-btn:active { transform: scale(.94); }
.chat-item { transform-origin: left center; }
.chat-item:active { transform: scale(.985); }
.brand-logo { transition: transform .4s cubic-bezier(.2,.8,.2,1); }
.brand-logo:hover { transform: rotate(-4deg) scale(1.04); }
@keyframes popIn { 0% { opacity: 0; transform: scale(.8); } 60% { transform: scale(1.05); } 100% { opacity: 1; transform: scale(1); } }
.artifact-img { animation: popIn .5s cubic-bezier(.22,.8,.24,1) both; }
.agent-status { animation: msgIn .25s ease both; }

/* Buttons feel a touch more premium */
.btn-primary { box-shadow: 0 6px 18px rgba(0,113,227,.28); }
.send-btn { box-shadow: 0 4px 14px rgba(0,113,227,.35); }

/* Reduce top/side padding a bit on mobile */
@media (max-width: 760px) {
  .messages-inner { padding: 14px 12px 8px; }
  .bubble { font-size: 15px; }
}

/* ============================================================
   Claude-like theme (warm paper + coral) + projects UI
   ============================================================ */
:root {
  --bg: #faf9f6; --bg-elev: #efece3; --bg-sidebar: #f4f1ea; --text: #2b2a27; --text-dim: #74726a;
  --sep: rgba(0,0,0,.08); --accent: #c96442; --accent-press: #b5563a;
  --bubble-user: #eae7db; --bubble-user-text: #2b2a27; --bubble-ai: #efece3;
  --code-bg: #2b2a26; --code-text: #f5f3ee; --danger: #c0392b;
  --header-blur: rgba(250,249,246,.82);
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 10px 34px rgba(60,50,40,.10);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #262624; --bg-elev: #333230; --bg-sidebar: #1f1e1d; --text: #f2f1ea; --text-dim: #aeaba1;
    --sep: rgba(255,255,255,.10); --accent: #d97757; --accent-press: #e28b6c;
    --bubble-user: #3b3a37; --bubble-user-text: #f2f1ea; --bubble-ai: #333230;
    --code-bg: #1a1a18; --code-text: #f2f1ea; --danger: #e5705f;
    --header-blur: rgba(38,38,36,.82);
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 10px 34px rgba(0,0,0,.5);
  }
}
.side-title { font-family: ui-serif, Georgia, "Times New Roman", serif; font-weight: 600; }
.empty h2 { font-family: ui-serif, Georgia, "Times New Roman", serif; font-weight: 500; font-size: 25px; }
.msg.user .bubble code.inline { background: rgba(0,0,0,.06); }
@media (prefers-color-scheme: dark) { .msg.user .bubble code.inline { background: rgba(255,255,255,.12); } }
.msg.user .att-chip { background: rgba(0,0,0,.05); color: var(--text); }
@media (prefers-color-scheme: dark) { .msg.user .att-chip { background: rgba(255,255,255,.10); } }

/* Sidebar sections */
.side-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 2px 8px calc(12px + var(--safe-bottom)); }
.chat-list { flex: none; overflow: visible; padding: 0 0 6px; }
.side-sec-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 4px; font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-dim); }
.sec-add { width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; color: var(--text-dim); transition: background .15s; }
.sec-add:active { background: var(--sep); }
.side-empty { padding: 2px 12px 8px; color: var(--text-dim); font-size: 13px; }
.chat-item.project { gap: 9px; }
.chat-item .pi-ic { flex-shrink: 0; color: var(--accent); }
.chat-item.project .title { font-weight: 600; }

/* Project banner in chat */
.proj-banner { display: flex; align-items: center; gap: 8px; background: var(--bg-elev); border: 1px solid var(--sep); border-radius: 12px; padding: 8px 12px; font-size: 13.5px; color: var(--text-dim); margin-bottom: 14px; }
.proj-banner svg { color: var(--accent); flex-shrink: 0; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(20,15,10,.5); display: flex; align-items: center; justify-content: center; padding: 20px; padding-bottom: calc(20px + var(--safe-bottom)); }
.modal-card { width: 100%; max-width: 384px; background: var(--bg); border: 1px solid var(--sep); border-radius: 22px; padding: 22px; box-shadow: var(--shadow); animation: rise .28s cubic-bezier(.2,.8,.2,1); }
.modal-card h3 { margin: 0 0 4px; font-size: 20px; font-weight: 700; }
.modal-sub { margin: 0 0 16px; color: var(--text-dim); font-size: 13.5px; line-height: 1.4; }
.modal-input { width: 100%; padding: 12px 14px; border-radius: 12px; background: var(--bg-elev); border: 1px solid var(--sep); outline: none; margin-bottom: 10px; font-size: 15px; color: var(--text); }
.modal-input:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-btn { flex: 1; padding: 12px; border-radius: 13px; font-weight: 600; background: var(--accent); color: #fff; transition: background .15s, transform .05s; }
.modal-btn:active { transform: scale(.98); }
.modal-btn.ghost { background: var(--bg-elev); color: var(--text); border: 1px solid var(--sep); }

/* ============================================================
   File cards (downloadable) + "creating file" progress + reveal
   ============================================================ */
.filecard { margin: 12px 0; border-radius: 16px; overflow: hidden; background: var(--bg-elev); border: 1px solid var(--sep); box-shadow: var(--shadow); }
.fc-head { display: flex; align-items: center; gap: 11px; padding: 11px 13px; }
.fc-ic { flex-shrink: 0; width: 40px; height: 40px; border-radius: 11px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .02em; }
.fc-info { flex: 1; min-width: 0; }
.fc-name { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fc-sub { font-size: 12.5px; color: var(--text-dim); }
.fc-sub b { color: var(--accent); }
.filecard .cb-btn { color: var(--text); background: transparent; border: 1px solid var(--sep); padding: 7px 13px; border-radius: 10px; font-size: 13px; font-weight: 600; }
.filecard .cb-btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.filecard .cb-btn:active { transform: scale(.96); }
.filecard pre { margin: 0; padding: 12px 14px; overflow-x: auto; background: var(--code-bg); max-height: 340px; }
.filecard code { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 13px; color: var(--code-text); white-space: pre; }
.filecard.generating pre { display: none; }

/* creating-file progress */
.fc-spin { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--sep); border-top-color: var(--accent); animation: spin360 .8s linear infinite; flex-shrink: 0; }
@keyframes spin360 { to { transform: rotate(360deg); } }
.gen-bar { height: 4px; background: var(--sep); overflow: hidden; position: relative; }
.gen-bar span { position: absolute; left: 0; top: 0; bottom: 0; width: 38%; border-radius: 4px; background: linear-gradient(90deg, transparent, var(--accent), transparent); animation: genslide 1.15s ease-in-out infinite; }
@keyframes genslide { 0% { left: -40%; } 100% { left: 100%; } }
.filecard.generating .fc-ic { animation: fcpulse 1.2s ease-in-out infinite; }
@keyframes fcpulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .7; transform: scale(.94); } }

/* Reveal artifacts/files only when the answer is finalised */
@keyframes fileReveal { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
.md.final .filecard, .md.final .artifact, .md.final .codeblock, .md.final .table-wrap { animation: fileReveal .4s cubic-bezier(.22,.8,.24,1) both; }
.md.final .filecard { animation-duration: .45s; }

/* Slightly refined message entrance + streaming cursor */
.msg { animation: msgIn .3s cubic-bezier(.22,.8,.24,1) both; }
.md:not(.final) > p:last-child::after, .md:not(.final) > :last-child::after { }

/* ============================================================
   Choice menu (ask) + animated empty-state cloud
   ============================================================ */
.askmenu { margin: 12px 0; border: 1px solid var(--sep); border-radius: 16px; overflow: hidden; background: var(--bg-elev); box-shadow: var(--shadow); animation: fileReveal .4s cubic-bezier(.22,.8,.24,1) both; }
.ask-q { padding: 13px 15px; font-weight: 600; font-size: 15px; border-bottom: 1px solid var(--sep); }
.ask-opts { display: flex; flex-direction: column; }
.ask-opt { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 15px; text-align: left; background: transparent; border: none; border-bottom: 1px solid var(--sep); color: var(--text); font-size: 14.5px; font-weight: 500; cursor: pointer; transition: background .15s, padding-left .15s; }
.ask-opt > span { flex: 1; }
.ask-opt:last-child { border-bottom: none; }
.ask-opt svg { color: var(--text-dim); flex-shrink: 0; opacity: .55; transition: transform .15s, opacity .15s, color .15s; }
.ask-opt:hover { background: var(--bg-sidebar); padding-left: 19px; }
.ask-opt:hover svg { color: var(--accent); opacity: 1; transform: translateX(2px); }
.ask-opt:active { background: var(--sep); }
.ask-opt.chosen { background: var(--accent); color: #fff; }
.ask-opt.chosen svg { color: #fff; opacity: 1; }
.askmenu.answered .ask-opt:not(.chosen) { opacity: .45; }
.askmenu.answered .ask-opt { cursor: default; }

/* Animated cloud in the empty chat (Claude-like gentle motion) */
.empty .brand-logo { animation: cloudFloat 4.5s ease-in-out infinite; box-shadow: 0 12px 34px rgba(201,100,66,.34); }
@keyframes cloudFloat { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-9px) scale(1.035); } }
.empty .brand-logo svg { animation: cloudBreathe 4.5s ease-in-out infinite; }
@keyframes cloudBreathe { 0%, 100% { opacity: .96; } 50% { opacity: 1; } }
@media (prefers-color-scheme: dark) { .empty .brand-logo { box-shadow: 0 12px 34px rgba(217,119,87,.4); } }

/* ============================================================
   Blue accent + no-bg animated cloud + ask-from-input + viewers
   ============================================================ */
:root {
  --bg: #f7f8fa; --bg-elev: #ecedf1; --bg-sidebar: #f0f1f5; --text: #1e2024; --text-dim: #696d76;
  --sep: rgba(0,0,0,.08); --accent: #2f6fe6; --accent-press: #245fce;
  --bubble-user: #e6ebf7; --bubble-user-text: #1e2024; --bubble-ai: #ecedf1;
  --code-bg: #1b1e27; --code-text: #eef0f5; --header-blur: rgba(247,248,250,.82);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1d23; --bg-elev: #262931; --bg-sidebar: #16171c; --text: #eef0f5; --text-dim: #a6aab4;
    --sep: rgba(255,255,255,.10); --accent: #5b8cf5; --accent-press: #7aa2ff;
    --bubble-user: #2c313d; --bubble-user-text: #eef0f5; --bubble-ai: #262931;
    --code-bg: #15161c; --code-text: #eef0f5; --header-blur: rgba(27,29,35,.82);
  }
}
/* Empty-chat cloud: no background, blue, gentle drift */
.empty-logo { width: 104px; height: 80px; color: var(--accent); margin: 0 auto 6px; filter: drop-shadow(0 14px 18px rgba(47,111,230,.26)); animation: cloudDrift 6.5s ease-in-out infinite; }
@media (prefers-color-scheme: dark) { .empty-logo { filter: drop-shadow(0 14px 18px rgba(91,140,245,.3)); } }
.empty-logo svg { width: 100%; height: 100%; fill: currentColor; }
@keyframes cloudDrift { 0%,100% { transform: translate(-7px,0) } 25% { transform: translate(0,-9px) } 50% { transform: translate(7px,0) } 75% { transform: translate(0,-3px) } }

/* Ask menu rises from the input area, always has a free-text option */
.askmenu { animation: askUp .44s cubic-bezier(.2,.92,.32,1.2) both; transform-origin: bottom center; }
@keyframes askUp { from { opacity: 0; transform: translateY(64px) scale(.94); } to { opacity: 1; transform: none; } }
.ask-opt.write { color: var(--accent); font-weight: 600; }
.ask-opt.write svg { color: var(--accent); opacity: 1; }

/* File icons (pictures, not just text) */
.fc-ic { background: transparent !important; padding: 0; width: 44px; height: 44px; }
.fc-ic svg { width: 100%; height: 100%; }
.filecard.site .fc-sub b { color: var(--accent); }

/* Fullscreen viewer (preview / code / run) */
.viewer { position: fixed; inset: 0; z-index: 130; background: var(--bg); display: flex; flex-direction: column; animation: viewerIn .28s cubic-bezier(.2,.8,.2,1); }
@keyframes viewerIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: calc(9px + var(--safe-top)) calc(12px + var(--safe-right)) 9px calc(12px + var(--safe-left)); background: var(--header-blur); backdrop-filter: saturate(180%) blur(18px); -webkit-backdrop-filter: saturate(180%) blur(18px); border-bottom: 1px solid var(--sep); }
.viewer-title { flex: 1; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-tab { padding: 6px 12px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--text-dim); background: var(--bg-elev); }
.viewer-tab.active { background: var(--accent); color: #fff; }
.viewer-x { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: var(--text); }
.viewer-x:active { background: var(--bg-elev); }
.viewer-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; display: block; }
.viewer-body pre { margin: 0; padding: 16px calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)); background: var(--code-bg); min-height: 100%; }
.viewer-body pre code { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 13px; color: var(--code-text); white-space: pre; }
.run-console { font-family: "SF Mono", ui-monospace, Menlo, monospace; font-size: 13px; padding: 14px calc(14px + var(--safe-right)) calc(14px + var(--safe-bottom)); white-space: pre-wrap; word-break: break-word; background: var(--code-bg); min-height: 100%; color: var(--code-text); }
.run-line.error { color: #ff8a80; } .run-line.info { color: #9aa0aa; } .run-line.warn { color: #ffd27a; }
.run-spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--sep); border-top-color: var(--accent); border-radius: 50%; animation: spin360 .8s linear infinite; vertical-align: -2px; margin-right: 6px; }

/* File card actions row + icon head */
.filecard .fc-head { padding: 12px 13px 8px; }
.filecard.generating .fc-head { padding-bottom: 10px; }
.fc-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 13px 13px; }
.fc-actions .cb-btn { color: var(--text); background: transparent; border: 1px solid var(--sep); padding: 8px 14px; border-radius: 10px; font-size: 13px; font-weight: 600; transition: transform .06s, background .15s; }
.fc-actions .cb-btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.fc-actions .cb-btn:active { transform: scale(.96); }

.login-note { margin-top: 6px; color: var(--text-dim); font-size: 12px; line-height: 1.4; max-width: 300px; }

.link-btn { background: none; color: var(--text-dim); font-size: 14px; font-weight: 500; padding: 8px; }
.link-btn:active { color: var(--text); }
#loginArea:empty + .link-btn { margin-top: 2px; }

/* Move the message composer lower (closer to the bottom edge) */
#composer { padding-top: 4px; padding-bottom: max(2px, var(--safe-bottom)); }
