:root {
  color-scheme: dark;
  --bg: #141518;
  --sidebar: #1b1c21;
  --surface: #202227;
  --raised: #282a32;
  --border: #343740;
  --ink: #f1f0f7;
  --muted: #a3a5b2;
  --accent: #c2b4ff;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 15px; }
[hidden] { display: none !important; }
button, input, textarea, select { color: inherit; font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .46; }
button, select { border: 1px solid var(--border); background: var(--raised); border-radius: 9px; }
button:not(:disabled):hover, select:hover { background: #373942; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
input, textarea { min-width: 0; }
h1 { margin: 0; font-weight: 650; letter-spacing: -.04em; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.025em; }
.mark { display: grid; place-items: center; height: 30px; width: 30px; border-radius: 10px; background: var(--accent); color: #2b2142; font-size: 19px; }
.text-button { display: inline-block; color: var(--muted); border-color: transparent; background: transparent; padding: 7px 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.error { color: #ffb1be; overflow-wrap: anywhere; }
.error:empty { display: none; }

#entry { display: grid; min-height: 100dvh; place-items: center; padding: 22px; background: radial-gradient(ellipse at 50% 15%, #242131 0, var(--bg) 64%); }
.auth-card { width: min(100%, 390px); border: 1px solid var(--border); border-radius: 22px; background: var(--sidebar); padding: 30px; }
.auth-card h1 { margin: 25px 0 18px; font-size: 27px; }
.auth-card label { display: grid; gap: 8px; margin-bottom: 14px; color: var(--muted); font-size: 14px; }
.auth-card input { height: 44px; width: 100%; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); color: var(--ink); padding: 9px 12px; font-size: 16px; }
.primary { width: 100%; margin: 5px 0 8px; padding: 11px 10px; background: var(--accent); color: #201833; font-weight: 650; border-color: transparent; }
.primary:not(:disabled):hover, .round:not(:disabled):hover { background: #dcceff; }
#auth-mode { margin-left: -8px; }

#app { display: grid; grid-template-columns: 252px minmax(0, 1fr); height: 100dvh; }
#sidebar { display: flex; flex-direction: column; padding: 17px 13px 12px; background: var(--sidebar); border-right: 1px solid var(--border); min-height: 0; }
#sidebar .brand { padding: 3px 6px 21px; }
#new-chat { height: 42px; text-align: left; padding: 0 10px; font-weight: 600; }
#new-chat span { display: inline-block; margin-right: 6px; color: var(--accent); }
.history-title { color: var(--muted); font-size: 12px; padding: 24px 9px 8px; }
#chats { display: flex; flex-direction: column; gap: 3px; flex: 1; min-height: 0; overflow-y: auto; }
.chat-link { flex: 0 0 auto; border-color: transparent; background: transparent; text-align: left; padding: 9px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chat-link[aria-current] { border-color: var(--border); background: var(--raised); }
.account { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 13px; border-top: 1px solid var(--border); padding: 10px 2px 0 7px; font-size: 13px; }
.account span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.account button { flex-shrink: 0; }
#workspace { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
header { display: flex; align-items: center; gap: 12px; height: 62px; padding: 0 clamp(12px, 3vw, 30px); border-bottom: 1px solid #2b2c34; }
.current-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.model-control { flex: 0 0 auto; }
.model-control select { padding: 8px 7px 8px 10px; font-size: 14px; }
.icon { display: none; min-width: 36px; height: 36px; background: transparent; }
#thread { overflow-y: auto; overscroll-behavior: contain; padding: 0 clamp(13px, 3vw, 30px); }
#intro { height: 100%; display: grid; align-content: center; justify-items: center; gap: 16px; padding: 10px 0 0; }
#intro .large { width: 47px; height: 47px; font-size: 27px; border-radius: 15px; }
#intro h1 { font-size: clamp(26px, 4vw, 38px); }
#messages { max-width: 760px; width: 100%; margin: 0 auto; padding: 26px 0 14px; }
.message { margin-bottom: 25px; overflow-wrap: anywhere; line-height: 1.65; min-width: 0; }
.message.user { display: flex; justify-content: flex-end; }
.bubble { max-width: min(86%, 610px); white-space: pre-wrap; background: #2b2b37; border: 1px solid #3c3b4b; border-radius: 17px 17px 5px 17px; padding: 10px 14px; }
.answer-from { color: var(--muted); font-size: 12px; font-weight: 650; margin-bottom: 7px; }
.assistant p { margin: 0 0 9px; white-space: pre-wrap; }
.assistant h2, .assistant h3, .assistant h4, .assistant h5 { margin: 15px 0 6px; line-height: 1.3; }
.assistant a { color: var(--accent); }
.assistant code { background: var(--surface); border-radius: 4px; padding: 1px 4px; }
.assistant pre { border: 1px solid var(--border); background: var(--surface); padding: 12px; border-radius: 9px; overflow-x: auto; }
.assistant pre code { display: block; padding: 0; }
.thinking { color: var(--muted); }
.retry { background: transparent; padding: 6px 10px; }
.compose-area { width: min(100%, 820px); margin: 0 auto; padding: 6px clamp(12px, 3vw, 30px) max(16px, env(safe-area-inset-bottom)); }
.compose-area .error { margin: 0 0 7px; font-size: 14px; }
#composer { display: grid; gap: 8px; border: 1px solid var(--border); background: var(--surface); border-radius: 19px; padding: 10px; }
.compose-row { display: flex; align-items: end; gap: 5px; min-width: 0; }
.attach { height: 40px; width: 36px; flex: 0 0 auto; border-color: transparent; background: transparent; font-size: 23px; color: var(--muted); }
.attachments, .message-images { display: flex; flex-wrap: wrap; gap: 7px; }
.attachment { position: relative; width: 63px; height: 63px; }
.attachment img { width: 100%; height: 100%; object-fit: cover; border-radius: 9px; }
.attachment button { position: absolute; top: 2px; right: 2px; border-radius: 50%; width: 22px; height: 22px; padding: 0; line-height: 17px; }
.message-images img { display: block; max-width: min(225px, 58vw); max-height: 225px; border-radius: 9px; }
.message-images + div { margin-top: 8px; }
.remote-image { display: block; max-width: 100%; max-height: 420px; border-radius: 10px; margin: 9px 0; }
#composer:focus-within { border-color: #7f789a; }
#content { flex: 1; resize: none; border: 0; outline: 0; padding: 8px; background: transparent; min-height: 40px; max-height: 150px; line-height: 1.45; font-size: 16px; }
#content::placeholder { color: var(--muted); }
.actions { display: flex; gap: 6px; }
.round { display: grid; place-items: center; border-radius: 50%; width: 40px; height: 40px; background: var(--accent); color: #231a38; border: 0; font-size: 23px; }
#stop { font-size: 13px; background: var(--raised); color: var(--ink); border: 1px solid var(--border); }
.scrim { display: none; }

@media (max-width: 700px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  #sidebar { display: none; position: fixed; inset: 0 auto 0 0; width: min(83vw, 290px); z-index: 2; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  #sidebar.open { display: flex; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 1; border: 0; border-radius: 0; background: #080710a0 !important; }
  .icon { display: inline-block; }
  header { height: 56px; gap: 8px; }
  .model-control select { font-size: 13px; }
}
