:root {
  --bg: #0b0e14;
  --bg-elev: #121722;
  --bg-elev2: #1a2130;
  --line: #232b3a;
  --text: #e6ebf2;
  --muted: #8a93a6;
  --accent: #6d8bff;
  --accent2: #46e0b8;
  --user: #2a3a6b;
  --danger: #ff6b6b;
  --warn: #ffcc66;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 11px; }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.err { color: var(--danger); }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #0006; padding: 1px 5px; border-radius: 6px; font-size: .9em; }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--bg-elev2); color: var(--text);
  padding: 11px 14px; border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #4d6fe0); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.icon-btn { background: transparent; border: none; color: var(--text); font-size: 20px; width: 42px; height: 42px;
  border-radius: 50%; cursor: pointer; display: grid; place-items: center; }
.icon-btn:active { background: var(--bg-elev2); }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(120% 100% at 50% 0%, #16203a, var(--bg)); padding: 24px; z-index: 50; }
.login-card { width: 100%; max-width: 360px; background: var(--bg-elev); border: 1px solid var(--line); border-radius: 20px; padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.login-card input { padding: 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; }
.brand.small { font-size: 17px; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--accent2), var(--accent)); color: #04121a; display: grid; place-items: center; font-weight: 900; }

/* app shell */
.app { height: 100dvh; display: flex; overflow: hidden; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100dvh; }

/* topbar */
.topbar { display: flex; align-items: center; gap: 4px; padding: calc(6px + var(--safe-t)) 6px 6px; background: var(--bg-elev); border-bottom: 1px solid var(--line); }
.topbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.1; }
.title-text { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* messages */
.messages { flex: 1; overflow-y: auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 12px; -webkit-overflow-scrolling: touch; }
.msg { max-width: 88%; display: flex; flex-direction: column; gap: 6px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; }
.bubble { padding: 10px 13px; border-radius: 16px; font-size: 15px; line-height: 1.5; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user .bubble { background: linear-gradient(135deg, #33509e, #2a3a6b); border-bottom-right-radius: 5px; color: #eaf0ff; }
.msg.assistant .bubble { background: var(--bg-elev); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.assistant .bubble.err { border-color: var(--danger); }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 20px; }
.bubble h1,.bubble h2,.bubble h3 { margin: 10px 0 6px; font-size: 1.05em; }
.bubble pre { background: #05070c; border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow-x: auto; font-size: 13px; }
.bubble pre code { background: none; padding: 0; }
.bubble a { color: var(--accent); }
.msg-meta { font-size: 10px; color: var(--muted); padding: 0 4px; }

/* tool card */
.tool { background: var(--bg-elev2); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; font-size: 13px; }
.tool-head { display: flex; align-items: center; gap: 8px; padding: 8px 11px; cursor: pointer; }
.tool-ico { width: 20px; text-align: center; }
.tool-name { font-weight: 700; }
.tool-sub { color: var(--muted); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, monospace; font-size: 12px; }
.tool-status { font-size: 11px; }
.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tool-body { display: none; border-top: 1px solid var(--line); padding: 8px 11px; }
.tool.open .tool-body { display: block; }
.tool-body pre { margin: 6px 0 0; background: #05070c; border-radius: 8px; padding: 8px; overflow-x: auto; max-height: 320px; overflow-y: auto; font-size: 12px; white-space: pre-wrap; word-break: break-word; }
.tool-body .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }

/* thinking + typing indicator */
.thinking { font-size: 12px; color: var(--muted); font-style: italic; padding: 0 4px; }
.typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2){ animation-delay: .2s } .typing i:nth-child(3){ animation-delay: .4s }
@keyframes blink { 0%,60%,100%{opacity:.25} 30%{opacity:1} }

/* empty state */
.empty { margin: auto; text-align: center; color: var(--muted); padding: 30px; max-width: 320px; }
.empty h3 { color: var(--text); margin: 8px 0; }
.empty .chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.chip { background: var(--bg-elev2); border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; font-size: 13px; cursor: pointer; color: var(--text); }
.chip:active { border-color: var(--accent); }

/* quick strip */
.quick-strip { display: flex; gap: 7px; overflow-x: auto; padding: 6px 10px; background: var(--bg); border-top: 1px solid var(--line); scrollbar-width: none; }
.quick-strip::-webkit-scrollbar { display: none; }
.quick-strip .chip { white-space: nowrap; flex: 0 0 auto; font-size: 12.5px; }

/* composer */
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(8px + var(--safe-b)); background: var(--bg-elev); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; max-height: 40vh; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  border-radius: 20px; padding: 11px 14px; font-size: 16px; line-height: 1.35; font-family: inherit; }
.composer textarea:focus { outline: none; border-color: var(--accent); }
.send-btn { width: 44px; height: 44px; flex: 0 0 auto; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #4d6fe0); color: #fff; font-size: 18px; display: grid; place-items: center; }
.send-btn:disabled { opacity: .4; }
.send-btn.stop { background: var(--danger); }

/* drawer */
.drawer { position: fixed; z-index: 30; top: 0; left: 0; height: 100dvh; width: 82%; max-width: 330px;
  background: var(--bg-elev); border-right: 1px solid var(--line); transform: translateX(-105%); transition: transform .25s ease;
  display: flex; flex-direction: column; padding-top: var(--safe-t); }
.drawer.open { transform: translateX(0); }
.drawer-head { padding: 14px 14px 8px; display: flex; flex-direction: column; gap: 12px; border-bottom: 1px solid var(--line); }
.chat-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.chat-item { padding: 10px 11px; border-radius: 11px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.chat-item:active { background: var(--bg-elev2); }
.chat-item.active { background: var(--bg-elev2); border: 1px solid var(--line); }
.chat-item .ci-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.chat-item .ci-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .ci-preview { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .ci-del { color: var(--muted); font-size: 15px; padding: 2px 6px; }
.drawer-foot { border-top: 1px solid var(--line); padding: 12px 14px calc(12px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; }
.switch-row { padding: 2px 0; }
.scrim { position: fixed; inset: 0; background: #0009; z-index: 20; opacity: 0; pointer-events: none; transition: opacity .25s; }
.scrim.show { opacity: 1; pointer-events: auto; }

/* modal / skills sheet */
.modal { position: fixed; inset: 0; z-index: 60; background: #0008; display: flex; align-items: flex-end; }
.sheet { background: var(--bg-elev); width: 100%; max-height: 88dvh; border-radius: 20px 20px 0 0; border: 1px solid var(--line);
  display: flex; flex-direction: column; padding-bottom: var(--safe-b); animation: rise .25s ease; }
@keyframes rise { from { transform: translateY(30px); opacity: .6; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-intro { padding: 0 16px; }
.search { margin: 8px 16px; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px; }
.skill-groups { overflow-y: auto; padding: 0 12px 16px; }
.skill-group { margin-top: 12px; }
.skill-group h3 { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 6px 4px; }
.skill-group .g-blurb { color: var(--muted); font-size: 12px; font-weight: 400; }
.skill { background: var(--bg-elev2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; margin: 6px 0; cursor: pointer; }
.skill:active { border-color: var(--accent); }
.skill .s-name { font-weight: 700; font-size: 14px; color: var(--accent2); }
.skill .s-desc { color: var(--muted); font-size: 12.5px; margin-top: 2px; line-height: 1.4; }

/* toasts */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(72px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 70; pointer-events: none; }
.toast { background: var(--bg-elev2); border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: 999px; font-size: 13px; box-shadow: 0 6px 24px #0007; animation: pop .2s ease; max-width: 90%; }
.toast.ok { border-color: var(--accent2); }
.toast.err { border-color: var(--danger); }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }

@media (min-width: 820px) {
  .drawer { position: static; transform: none; width: 320px; }
  .scrim { display: none; }
  #menuBtn { display: none; }
}
