/* ==========================================================================
   Basalt — design tokens
   Stone-grey surfaces; one ember accent that only ever means "the model is live".
   ========================================================================== */

@font-face { font-family: "Plex Sans"; src: url(../vendor/fonts/plex-sans-400.woff2) format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url(../vendor/fonts/plex-sans-400-italic.woff2) format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url(../vendor/fonts/plex-sans-500.woff2) format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url(../vendor/fonts/plex-sans-600.woff2) format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url(../vendor/fonts/plex-mono-400.woff2) format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url(../vendor/fonts/plex-mono-500.woff2) format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }

:root {
  color-scheme: dark;
  --bg: #1b1e22;
  --bg-side: #16191c;
  --surface: #23272c;
  --surface-2: #2a2f35;
  --surface-3: #333940;
  --line: #2f343a;
  --line-strong: #424951;
  --text: #e8e6e1;
  --text-2: #a9afb6;
  --text-3: #7b828a;
  --stone: #8d96a0;
  --ember: #ff7f3a;
  --ember-2: #e5512b;
  --ember-soft: rgba(255, 127, 58, 0.13);
  --ember-line: rgba(255, 127, 58, 0.45);
  --focus: #8ab4f8;
  --danger: #ff7a7a;
  --danger-bg: #c43d3d;
  --danger-soft: rgba(255, 122, 122, 0.1);
  --bubble: #2b3137;
  --code-bg: #15181b;
  --selection: rgba(138, 180, 248, 0.28);
  --scrim: rgba(9, 11, 13, 0.62);
  --shadow-pop: 0 18px 40px -12px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--line);
  --shadow-dock: 0 -14px 28px -18px rgba(0, 0, 0, 0.7);

  --font: "Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Plex Mono", ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;

  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 11px;
  --r-lg: 18px;

  --side-w: 272px;
  --top-h: 56px;
  --col: 47rem;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  /* syntax */
  --hl-keyword: #c3a6e6;
  --hl-string: #a6d39d;
  --hl-number: #e6c27a;
  --hl-comment: #6e767e;
  --hl-title: #8fc0ef;
  --hl-builtin: #e2a77d;
  --hl-attr: #95cdd6;
  --hl-meta: #8b939b;
}

/* Light ("pumice") — applied for an explicit choice or when following a light system theme. */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f6; --bg-side: #eaecee; --surface: #ffffff; --surface-2: #eff1f3; --surface-3: #e4e7ea;
  --line: #dde1e5; --line-strong: #c7cdd3; --text: #1b1f23; --text-2: #525a63; --text-3: #7c848d;
  --stone: #6f7882; --ember: #e8622a; --ember-2: #c8451d; --ember-soft: rgba(232, 98, 42, 0.1);
  --ember-line: rgba(232, 98, 42, 0.45); --focus: #2f6fe0; --danger: #c93838; --danger-bg: #c93838;
  --danger-soft: rgba(201, 56, 56, 0.08); --bubble: #e6e9ec; --code-bg: #f7f8f9;
  --selection: rgba(47, 111, 224, 0.18); --scrim: rgba(27, 31, 35, 0.35);
  --shadow-pop: 0 18px 40px -14px rgba(27, 31, 35, 0.28), 0 0 0 1px var(--line);
  --shadow-dock: 0 -14px 28px -20px rgba(27, 31, 35, 0.25);
  --hl-keyword: #7a45b8; --hl-string: #3c7636; --hl-number: #93660f; --hl-comment: #8a929a;
  --hl-title: #2862ad; --hl-builtin: #a24f1c; --hl-attr: #1c7480; --hl-meta: #6f7882;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f5f6; --bg-side: #eaecee; --surface: #ffffff; --surface-2: #eff1f3; --surface-3: #e4e7ea;
    --line: #dde1e5; --line-strong: #c7cdd3; --text: #1b1f23; --text-2: #525a63; --text-3: #7c848d;
    --stone: #6f7882; --ember: #e8622a; --ember-2: #c8451d; --ember-soft: rgba(232, 98, 42, 0.1);
    --ember-line: rgba(232, 98, 42, 0.45); --focus: #2f6fe0; --danger: #c93838; --danger-bg: #c93838;
    --danger-soft: rgba(201, 56, 56, 0.08); --bubble: #e6e9ec; --code-bg: #f7f8f9;
    --selection: rgba(47, 111, 224, 0.18); --scrim: rgba(27, 31, 35, 0.35);
    --shadow-pop: 0 18px 40px -14px rgba(27, 31, 35, 0.28), 0 0 0 1px var(--line);
    --shadow-dock: 0 -14px 28px -20px rgba(27, 31, 35, 0.25);
    --hl-keyword: #7a45b8; --hl-string: #3c7636; --hl-number: #93660f; --hl-comment: #8a929a;
    --hl-title: #2862ad; --hl-builtin: #a24f1c; --hl-attr: #1c7480; --hl-meta: #6f7882;
  }
}

/* ==========================================================================
   Base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--selection); }

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; }

a { color: inherit; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-xs); }

.sprite { display: none; }

.icon { width: 20px; height: 20px; flex: none; display: block; }
.icon--sm { width: 16px; height: 16px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

.mark { width: 24px; height: 24px; fill: var(--ember); color: var(--stone); flex: none; }

.kbd {
  font-family: var(--font);
  font-size: 11px;
  line-height: 18px;
  padding: 0 6px;
  border-radius: 5px;
  border: 1px solid var(--line);
  color: var(--text-3);
  white-space: nowrap;
}
.kbd:empty { display: none; }

/* ==========================================================================
   Buttons & form controls
   ========================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--r-md);
  font-size: 14px; font-weight: 500; line-height: 1;
  transition: background-color 0.15s, color 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn--block { width: 100%; }
.btn--sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: var(--r-sm); }
.btn--primary { background: var(--text); color: var(--bg); }
.btn--primary:hover:not(:disabled) { opacity: 0.88; }
.btn--quiet { color: var(--text-2); }
.btn--quiet:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn--danger { background: var(--danger-bg); color: #fff; }
.btn--danger:hover:not(:disabled) { opacity: 0.9; }
.btn:disabled { opacity: 0.5; }

.btn.is-busy { position: relative; }
.btn.is-busy .btn__label { opacity: 0; }
.btn.is-busy::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}

.icon-btn {
  position: relative;
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: var(--r-sm);
  color: var(--text-2);
  transition: background-color 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.link-btn { color: var(--text-2); font-size: 12px; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.link-btn:hover { color: var(--text); }

.field { display: grid; gap: 7px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field input[type="text"], .field input[type="password"], .field select, .field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  padding: 0 13px;
  height: 44px;
  font-size: 15px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field textarea { height: auto; padding: 11px 13px; line-height: 1.55; resize: vertical; min-height: 120px; font-size: 14px; }
.field select {
  appearance: none; padding-right: 36px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 19px) 19px, calc(100% - 14px) 19px;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible {
  outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent);
}
.field__wrap { position: relative; }
.field__wrap input { padding-right: 46px; }
.field__reveal {
  position: absolute; right: 4px; top: 4px; width: 36px; height: 36px; border-radius: var(--r-sm);
  display: grid; place-items: center; color: var(--text-3);
}
.field__reveal:hover { color: var(--text); background: var(--surface-2); }
.field__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field__row--hint { font-size: 12px; color: var(--text-3); }
.field__help { margin: 0; font-size: 12.5px; color: var(--text-3); line-height: 1.5; }
.field output { font-size: 13px; color: var(--text); font-variant-numeric: tabular-nums; }
.field input[type="range"] { width: 100%; accent-color: var(--text-2); margin: 4px 0; }

.form { display: grid; gap: 18px; }
.form__error {
  margin: -4px 0 0; padding: 10px 12px; border-radius: var(--r-sm);
  background: var(--danger-soft); color: var(--danger); font-size: 13.5px; line-height: 1.45;
}

/* ==========================================================================
   Sign-in page
   ========================================================================== */

.auth-page { min-height: 100%; display: flex; }

.auth {
  width: min(400px, 100% - 48px);
  margin: auto;
  padding: max(48px, env(safe-area-inset-top)) 0 max(48px, env(safe-area-inset-bottom));
}

.auth__brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 15px; font-weight: 600; letter-spacing: -0.005em;
  margin-bottom: 56px;
}
.auth__brand .mark { width: 28px; height: 28px; }

.auth__step h1 { margin: 0 0 8px; font-size: 30px; font-weight: 500; letter-spacing: -0.02em; line-height: 1.15; }
.auth__lede { margin: 0 0 32px; color: var(--text-2); font-size: 15px; line-height: 1.55; max-width: 34ch; }
.auth__step { animation: rise 0.35s var(--ease); }

.otp { display: flex; align-items: center; gap: 8px; border: 0; margin: 0; padding: 0; min-width: 0; }
.otp__gap { width: 6px; flex: none; }
.otp__cell {
  flex: 1 1 0; min-width: 0; height: 58px;
  text-align: center; font-family: var(--mono); font-size: 24px; font-weight: 500;
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  caret-color: var(--text-2);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.otp__cell:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.otp__cell.is-filled { border-color: var(--text-3); }
.otp.is-error .otp__cell { border-color: var(--danger); }
.otp.is-error { animation: shake 0.36s; }

/* ==========================================================================
   App shell
   ========================================================================== */

.app-page { overflow: hidden; }

.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  transition: grid-template-columns 0.25s var(--ease);
}
.app.is-side-closed { grid-template-columns: 0 minmax(0, 1fr); }
.app.is-side-closed .sidebar { visibility: hidden; }

/* ---------- Sidebar ---------- */

.sidebar {
  min-width: 0;
  display: flex; flex-direction: column;
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
}

.sidebar__head {
  height: var(--top-h); flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px 0 16px;
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.brand__name { font-size: 15px; font-weight: 600; letter-spacing: -0.005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.new-chat {
  margin: 4px 12px 10px;
  height: 38px; padding: 0 10px 0 12px;
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  font-size: 14px; font-weight: 500;
  transition: background-color 0.15s;
}
.new-chat:hover { background: var(--surface-2); }
.new-chat span { flex: 1; text-align: left; }

.search {
  margin: 0 12px 6px;
  height: 36px; padding: 0 8px 0 10px;
  display: flex; align-items: center; gap: 8px;
  border-radius: var(--r-md);
  color: var(--text-3);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  border: 1px solid transparent;
  transition: border-color 0.15s;
}
.search:focus-within { border-color: var(--line-strong); }
.search .icon { width: 16px; height: 16px; }
.search input { flex: 1; min-width: 0; background: none; border: 0; height: 100%; font-size: 13.5px; color: var(--text); }
.search input::placeholder { color: var(--text-3); }
.search input::-webkit-search-cancel-button { display: none; }
.search input:focus-visible { outline: none; }
.search:focus-within .kbd { display: none; }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px 16px; overscroll-behavior: contain; }

.conv-group__label { padding: 16px 8px 6px; font-size: 12px; font-weight: 500; color: var(--text-3); }

.conv {
  position: relative;
  display: flex; align-items: center;
  height: 34px; border-radius: var(--r-sm);
  color: var(--text-2);
  transition: background-color 0.12s, color 0.12s;
}
.conv:hover { background: var(--surface-2); color: var(--text); }
.conv.is-active { background: var(--surface-3); color: var(--text); }
.conv__link {
  flex: 1; min-width: 0; height: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 0 4px 0 10px;
  text-decoration: none; font-size: 13.5px;
}
.conv__title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv__live { width: 7px; height: 7px; border-radius: 50%; background: var(--ember); flex: none; box-shadow: 0 0 8px var(--ember); animation: pulse 1.6s ease-in-out infinite; }
.conv__more {
  flex: none; width: 28px; height: 28px; margin-right: 3px; border-radius: var(--r-xs);
  display: grid; place-items: center; color: var(--text-3);
  opacity: 0; transition: opacity 0.12s;
}
.conv:hover .conv__more, .conv.is-active .conv__more, .conv__more[aria-expanded="true"], .conv__more:focus-visible { opacity: 1; }
.conv__more:hover { color: var(--text); background: var(--surface-3); }
.conv__rename {
  flex: 1; min-width: 0; height: 30px; margin: 0 4px;
  background: var(--bg); border: 1px solid var(--focus); border-radius: var(--r-xs);
  padding: 0 8px; font-size: 13.5px;
}
.conv__rename:focus-visible { outline: none; }

.conv-empty { padding: 24px 12px; color: var(--text-3); font-size: 13px; line-height: 1.5; }

.sidebar__foot {
  flex: none;
  border-top: 1px solid var(--line);
  padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  display: grid; gap: 2px;
}

.backend {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px; border-radius: var(--r-sm);
  text-align: left; min-width: 0;
}
.backend:hover { background: var(--surface-2); }
.backend__dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  border: 1.5px solid var(--text-3);
  transition: background-color 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.backend.is-online .backend__dot { background: var(--stone); border-color: var(--stone); }
.backend.is-warm .backend__dot { background: var(--ember); border-color: var(--ember); box-shadow: 0 0 10px -1px var(--ember); }
.backend.is-busy .backend__dot { animation: pulse 1.4s ease-in-out infinite; }
.backend__text { display: grid; min-width: 0; }
.backend__label { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.backend__detail { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.backend__detail:empty { display: none; }

.account { position: relative; }
.account__btn {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 6px 6px; border-radius: var(--r-sm);
  color: var(--text-2);
}
.account__btn:hover, .account__btn[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }
.account__name { flex: 1; min-width: 0; text-align: left; font-size: 13.5px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar {
  width: 28px; height: 28px; border-radius: var(--r-sm); flex: none;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--text);
  font-size: 13px; font-weight: 600; text-transform: uppercase;
}

/* ---------- Menus & popovers ---------- */

.menu, .popover {
  position: absolute; z-index: 40;
  background: var(--surface);
  border-radius: 13px;
  box-shadow: var(--shadow-pop);
  padding: 6px;
  animation: pop 0.14s var(--ease);
}
.account .menu { left: 0; right: 0; bottom: calc(100% + 6px); }
.menu__item {
  width: 100%; height: 36px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px; border-radius: var(--r-sm);
  font-size: 13.5px; color: var(--text);
}
.menu__item:hover, .menu__item:focus-visible { background: var(--surface-2); outline: none; }
.menu__item--danger { color: var(--danger); }
.menu__sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu__group { padding: 4px 4px 6px; display: grid; gap: 8px; }
.menu__heading { font-size: 12px; color: var(--text-3); padding: 2px 6px 0; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 3px; background: var(--bg); border-radius: 10px; }
.segmented button {
  height: 30px; border-radius: 7px; font-size: 12.5px; color: var(--text-2);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked="true"] { background: var(--surface-3); color: var(--text); }

.menu--floating { position: fixed; min-width: 184px; }

/* ---------- Main column ---------- */

.main {
  position: relative;
  min-width: 0; height: 100dvh;
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

.topbar {
  flex: none; height: var(--top-h);
  display: flex; align-items: center; gap: 6px;
  padding: 0 12px;
  position: relative; z-index: 20;
}
.topbar__show { display: none; }
.app.is-side-closed .topbar__show { display: inline-grid; }
.topbar__title {
  flex: 1; min-width: 0; margin: 0;
  font-size: 14px; font-weight: 400; color: var(--text-2);
  text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 12px;
}
.topbar__actions { display: flex; gap: 2px; }

.picker { position: relative; min-width: 0; }
.picker__btn {
  display: flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 10px 0 12px; border-radius: var(--r-md);
  min-width: 0; max-width: min(360px, 52vw);
  transition: background-color 0.15s;
}
.picker__btn:hover, .picker__btn[aria-expanded="true"] { background: var(--surface-2); }
.picker__name { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker__btn > .icon--sm { color: var(--text-3); }
.picker__caps { display: flex; gap: 4px; color: var(--text-3); }
.picker__caps .icon { width: 15px; height: 15px; }
.picker__caps:empty { display: none; }

.picker__pop { top: calc(100% + 6px); left: 0; width: min(380px, calc(100vw - 24px)); }
.picker__list { max-height: min(420px, 60vh); overflow-y: auto; display: grid; gap: 2px; }
.picker__foot { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; display: flex; }

.model {
  display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; align-items: center; column-gap: 10px;
  padding: 9px 10px; border-radius: 10px; text-align: left; width: 100%;
}
.model:hover, .model:focus-visible { background: var(--surface-2); outline: none; }
.model__check { color: var(--text); opacity: 0; grid-row: 1 / span 2; }
.model[aria-selected="true"] .model__check { opacity: 1; }
.model__name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model__meta { grid-column: 2; display: flex; gap: 12px; font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; margin-top: 2px; }
.model__caps { grid-row: 1 / span 2; grid-column: 3; display: flex; align-items: center; gap: 6px; color: var(--text-3); }
.model__caps .icon { width: 16px; height: 16px; }
.model__hot { width: 7px; height: 7px; border-radius: 50%; background: var(--ember); box-shadow: 0 0 8px var(--ember); }
.picker__empty { padding: 16px 12px; font-size: 13px; color: var(--text-2); line-height: 1.5; }

/* ---------- Thread ---------- */

.thread {
  position: relative;
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;
}
.thread:focus-visible { outline: none; }
.thread__inner { width: min(var(--col), 100% - 40px); margin: 0 auto; padding: 16px 0 40px; }
.thread__inner:empty { padding: 0; }

.thread__loading { position: absolute; inset: 0; display: grid; place-content: center; grid-auto-flow: column; gap: 6px; }
.thread__loading span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: blink 1.2s infinite both; }
.thread__loading span:nth-child(2) { animation-delay: 0.15s; }
.thread__loading span:nth-child(3) { animation-delay: 0.3s; }

.welcome {
  position: absolute; inset: 0;
  width: min(var(--col), 100% - 40px); margin: 0 auto;
  display: flex; flex-direction: column; justify-content: center;
  padding-bottom: 8vh;
}
.welcome__mark { width: 40px; height: 40px; margin-bottom: 26px; filter: drop-shadow(0 0 14px var(--ember-soft)); }
.welcome__title { margin: 0; font-size: clamp(26px, 3.4vw, 34px); font-weight: 500; letter-spacing: -0.022em; line-height: 1.15; }
.welcome__sub { margin: 12px 0 0; font-size: 15.5px; color: var(--text-2); max-width: 48ch; line-height: 1.55; }

/* ---------- Messages ---------- */

.msg { position: relative; margin-top: 28px; }
.msg:first-child { margin-top: 12px; }

.msg--user { display: flex; flex-direction: column; align-items: flex-end; }
.msg__bubble {
  max-width: min(85%, 38rem);
  background: var(--bubble);
  border-radius: var(--r-lg) var(--r-lg) 6px var(--r-lg);
  padding: 10px 15px;
  font-size: 15px; line-height: 1.6;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg__images { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-bottom: 6px; max-width: 85%; }
.msg__images button { display: block; border-radius: 12px; }
.msg__images img {
  display: block; width: 132px; height: 132px; object-fit: cover;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  cursor: zoom-in;
}

.msg__edit { width: min(100%, 40rem); display: grid; gap: 8px; }
.msg__edit textarea {
  width: 100%; min-height: 80px; max-height: 50vh; resize: vertical;
  background: var(--surface); border: 1px solid var(--focus); border-radius: var(--r-lg);
  padding: 11px 15px; font-size: 15px; line-height: 1.6;
}
.msg__edit textarea:focus-visible { outline: none; }
.msg__edit-actions { display: flex; justify-content: flex-end; gap: 6px; }

.msg--assistant { display: grid; grid-template-columns: 26px minmax(0, 1fr); column-gap: 16px; }
.msg__gutter { padding-top: 3px; }
.msg__gutter .mark { width: 22px; height: 22px; fill: var(--stone); color: var(--line-strong); transition: fill 0.4s; }
.msg.is-live .msg__gutter .mark { fill: var(--ember); animation: glow 2.2s ease-in-out infinite; }
.msg__body { min-width: 0; }

.msg__actions {
  display: flex; align-items: center; gap: 2px; margin-top: 6px;
  min-height: 30px;
  opacity: 0; transition: opacity 0.15s;
}
.msg:hover .msg__actions, .msg:focus-within .msg__actions, .msg.is-last .msg__actions { opacity: 1; }
.msg.is-live .msg__actions { visibility: hidden; }
.msg:not(.is-last) .msg__actions [data-action="regenerate"] { display: none; }
.msg__actions .icon-btn { width: 30px; height: 30px; }
.msg__actions .icon-btn .icon { width: 16px; height: 16px; }
.msg__stats { margin-left: 8px; font-size: 12px; color: var(--text-3); display: flex; gap: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }

.msg__notice {
  display: flex; align-items: flex-start; gap: 10px;
  margin-top: 12px; padding: 10px 12px; border-radius: var(--r-md);
  font-size: 13.5px; line-height: 1.5;
}
.msg__notice .icon { width: 18px; height: 18px; margin-top: 1px; }
.msg__notice--error { background: var(--danger-soft); color: var(--danger); }
.msg__notice--stopped { color: var(--text-3); padding: 0; margin-top: 8px; font-size: 13px; }

.pending { display: flex; align-items: center; gap: 5px; padding: 6px 0 4px; min-height: 28px; }
.pending__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ember); animation: blink 1.2s infinite both; }
.pending__dot:nth-child(2) { animation-delay: 0.15s; }
.pending__dot:nth-child(3) { animation-delay: 0.3s; }
.pending__label { margin-left: 8px; font-size: 13px; color: var(--text-3); }

/* Thinking */
.thought { margin: 0 0 12px; }
.thought__toggle {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 8px 0 6px; margin-left: -6px; border-radius: var(--r-sm);
  font-size: 13.5px; color: var(--text-2);
}
.thought__toggle:hover { background: var(--surface-2); color: var(--text); }
.thought__toggle .icon { width: 14px; height: 14px; transition: transform 0.2s var(--ease); }
.thought.is-open .thought__toggle .icon { transform: rotate(90deg); }
.thought.is-live .thought__label {
  background: linear-gradient(90deg, var(--text-3) 0%, var(--ember) 45%, var(--text-3) 90%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 2.4s linear infinite;
}
.thought__text {
  margin: 6px 0 2px;
  border-left: 2px solid var(--line-strong);
  padding: 2px 0 2px 14px;
  font-size: 13.5px; line-height: 1.6; color: var(--text-3);
  white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 360px; overflow-y: auto;
}

/* ---------- Markdown ---------- */

.md { font-size: 15.5px; line-height: 1.68; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md .table-wrap, .md .code, .md hr { margin: 0 0 0.9em; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.5em 0 0.55em; line-height: 1.3; letter-spacing: -0.01em; font-weight: 600; }
.md h1 { font-size: 1.4em; }
.md h2 { font-size: 1.22em; }
.md h3 { font-size: 1.06em; }
.md h4 { font-size: 1em; color: var(--text-2); }
.md ul, .md ol { padding-left: 1.5em; }
.md li { margin: 0.25em 0; }
.md li > ul, .md li > ol { margin: 0.25em 0; }
.md li::marker { color: var(--text-3); }
.md strong { font-weight: 600; }
.md a { color: var(--text); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.md a:hover { text-decoration-color: var(--text-2); }
.md blockquote { border-left: 3px solid var(--line-strong); padding: 0.1em 0 0.1em 1em; color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.6em 0; }
.md :not(pre) > code {
  font-family: var(--mono); font-size: 0.86em;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 5px; padding: 0.08em 0.36em;
}
.md .table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); }
.md table { border-collapse: collapse; width: 100%; font-size: 0.92em; }
.md th, .md td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.md th { font-weight: 600; background: var(--surface); }
.md tr:last-child td { border-bottom: 0; }
.md td { font-variant-numeric: tabular-nums; }
.md table { overflow-wrap: normal; }
.md th code, .md td code { white-space: nowrap; }

.code { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--code-bg); overflow: hidden; }
.code__head {
  display: flex; align-items: center; justify-content: space-between;
  height: 36px; padding: 0 6px 0 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px; color: var(--text-3);
}
.code__copy {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 8px; border-radius: var(--r-xs);
  font-size: 12.5px; color: var(--text-3);
}
.code__copy:hover { background: var(--surface-2); color: var(--text); }
.code__copy .icon { width: 14px; height: 14px; }
.code pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.code code { font-family: var(--mono); font-size: 13.5px; line-height: 1.6; tab-size: 4; white-space: pre; }

.hljs-keyword, .hljs-selector-tag, .hljs-doctag, .hljs-section { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-template-tag { color: var(--hl-string); }
.hljs-number, .hljs-literal, .hljs-symbol, .hljs-bullet { color: var(--hl-number); }
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-title, .hljs-title.function_, .hljs-title.class_, .hljs-tag, .hljs-selector-id, .hljs-selector-class { color: var(--hl-title); }
.hljs-built_in, .hljs-variable.language_, .hljs-params { color: var(--hl-builtin); }
.hljs-attr, .hljs-attribute, .hljs-type, .hljs-name, .hljs-property { color: var(--hl-attr); }
.hljs-meta, .hljs-meta .hljs-keyword { color: var(--hl-meta); }
.hljs-deletion { color: var(--danger); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }

/* ---------- Jump to latest ---------- */

.jump {
  position: absolute; left: 50%; bottom: calc(var(--dock-h, 120px) + 12px); z-index: 15;
  transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 14px 0 10px; border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow-pop);
  font-size: 13px; color: var(--text-2);
  animation: fade 0.16s;
}
.jump:hover { color: var(--text); }

/* ---------- Composer ---------- */

.dock {
  flex: none;
  padding: 0 20px max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 22px);
  margin-top: -22px;
  position: relative; z-index: 10;
}

.composer {
  position: relative;
  width: min(var(--col), 100%); margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  padding: 12px 10px 10px 16px;
  box-shadow: var(--shadow-dock);
  transition: border-color 0.2s, box-shadow 0.3s;
}
.composer:focus-within { border-color: color-mix(in srgb, var(--text-3) 80%, var(--line-strong)); }

/* The one bold move: a molten seam runs along the composer while the model writes. */
.composer::before {
  content: ""; position: absolute; left: 18px; right: 18px; top: -1px; height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--ember-2) 20%, var(--ember) 50%, var(--ember-2) 80%, transparent);
  background-size: 200% 100%;
  opacity: 0; transition: opacity 0.3s;
  pointer-events: none;
}
.composer.is-live { border-color: var(--ember-line); box-shadow: var(--shadow-dock), 0 0 32px -12px var(--ember); }
.composer.is-live::before { opacity: 1; animation: flow 2.2s linear infinite; }

.composer__input {
  display: block; width: 100%;
  background: none; border: 0; resize: none;
  font-size: 15.5px; line-height: 1.55;
  max-height: 40vh; min-height: 26px;
  padding: 2px 4px 2px 0;
  overflow-y: auto;
}
.composer__input:focus-visible { outline: none; }
.composer__input::placeholder { color: var(--text-3); }

.composer__bar { display: flex; align-items: center; gap: 4px; margin-top: 8px; margin-left: -6px; }
.composer__spacer { flex: 1; }
.composer__hint { font-size: 12px; color: var(--text-3); margin-right: 8px; white-space: nowrap; }

.chip-btn {
  position: relative;
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center; color: var(--text-2);
}
.chip-btn:hover { background: var(--surface-2); color: var(--text); }

.toggle {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 11px 0 9px; border-radius: 999px;
  border: 1px solid var(--line-strong);
  font-size: 13px; color: var(--text-3);
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.toggle:hover { color: var(--text); }
.toggle[aria-pressed="true"] { background: var(--surface-3); border-color: var(--surface-3); color: var(--text); }

.send {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: grid; place-items: center;
  background: var(--text); color: var(--bg);
  transition: opacity 0.15s, background-color 0.2s, transform 0.1s;
}
.send:active:not(:disabled) { transform: scale(0.95); }
.send:disabled { opacity: 0.25; }
.send .icon { width: 19px; height: 19px; grid-area: 1 / 1; }
.send .icon--stop { display: none; }
.composer.is-live .send { background: var(--ember); color: #1a0d05; opacity: 1; }
.composer.is-live .send .icon--send { display: none; }
.composer.is-live .send .icon--stop { display: block; }

.composer__files { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.file {
  position: relative; width: 64px; height: 64px;
  border-radius: 12px; overflow: hidden; border: 1px solid var(--line);
  background: var(--surface-2);
}
.file img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file.is-processing img { opacity: 0.4; }
.file__remove {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(10, 12, 14, 0.72); color: #fff;
}
.file__remove .icon { width: 13px; height: 13px; }

.composer__drop {
  position: absolute; inset: -1px; border-radius: 20px;
  border: 1.5px dashed var(--text-3);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  display: none; place-items: center;
  font-size: 14px; color: var(--text-2);
  pointer-events: none;
}
.composer.is-dragging .composer__drop { display: grid; }

/* ---------- Settings drawer ---------- */

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: min(400px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 48px -24px rgba(0, 0, 0, 0.45);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  animation: slide-in 0.24s var(--ease);
}
.drawer__head { height: var(--top-h); flex: none; display: flex; align-items: center; justify-content: space-between; padding: 0 12px 0 22px; border-bottom: 1px solid var(--line); }
.drawer__head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.drawer__body { flex: 1; overflow-y: auto; padding: 20px 22px; display: grid; gap: 26px; align-content: start; }
.drawer__scope { margin: 0; font-size: 13px; color: var(--text-3); line-height: 1.5; }
.drawer__foot { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px max(12px, env(safe-area-inset-bottom)) 22px; border-top: 1px solid var(--line); }
.drawer__saved { font-size: 12.5px; color: var(--text-3); }

/* ---------- Dialogs ---------- */

.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0; border: 0; border-radius: 16px;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-pop);
}
.dialog[open] { animation: pop 0.16s var(--ease); }
.dialog::backdrop { background: var(--scrim); }
.dialog__form { padding: 22px 22px 18px; }
.dialog__title { margin: 0 0 8px; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.dialog__body { margin: 0 0 22px; font-size: 14px; color: var(--text-2); line-height: 1.55; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; }

.shortcuts { display: grid; grid-template-columns: 1fr auto; gap: 10px 24px; margin: 14px 0 24px; font-size: 14px; }
.shortcuts dt { color: var(--text-2); }
.shortcuts dd { margin: 0; display: flex; gap: 4px; justify-content: flex-end; }

.lightbox { padding: 0; border: 0; background: transparent; max-width: 94vw; max-height: 94vh; overflow: visible; }
.lightbox::backdrop { background: rgba(5, 6, 7, 0.86); }
.lightbox img { display: block; max-width: 94vw; max-height: 94vh; border-radius: 10px; cursor: zoom-out; }

/* ---------- Toasts ---------- */

.toasts {
  position: fixed; z-index: 100; top: calc(var(--top-h) + 8px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  display: grid; gap: 8px; justify-items: center;
  width: min(480px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px; border-radius: var(--r-md);
  background: var(--surface-3); color: var(--text);
  box-shadow: var(--shadow-pop);
  font-size: 13.5px; line-height: 1.45;
  animation: drop 0.2s var(--ease);
}
.toast .icon { width: 18px; height: 18px; margin-top: 1px; }
.toast--error .icon { color: var(--danger); }
.toast.is-leaving { opacity: 0; transform: translateY(-6px); transition: opacity 0.2s, transform 0.2s; }

/* ---------- Tooltips ---------- */

@media (hover: hover) and (pointer: fine) {
  [data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute; top: calc(100% + 6px); left: 50%;
    transform: translateX(-50%);
    padding: 5px 8px; border-radius: 6px;
    background: var(--text); color: var(--bg);
    font-size: 12px; font-weight: 500; white-space: nowrap;
    pointer-events: none; z-index: 60;
    animation: fade 0.12s 0.45s both;
  }
  .composer [data-tip]:hover::after { top: auto; bottom: calc(100% + 6px); }
  .topbar__actions [data-tip]:hover::after { left: auto; right: 0; transform: none; }
}

.scrim { position: fixed; inset: 0; z-index: 30; background: var(--scrim); animation: fade 0.2s; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 900px) {
  .app, .app.is-side-closed { grid-template-columns: minmax(0, 1fr); }
  .app.is-side-closed .sidebar { visibility: visible; }
  .sidebar {
    position: fixed; z-index: 35; top: 0; bottom: 0; left: 0;
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform 0.26s var(--ease), visibility 0s 0.26s;
    visibility: hidden;
  }
  .app.is-side-open .sidebar { transform: none; visibility: visible; transition: transform 0.26s var(--ease); box-shadow: 24px 0 48px -24px rgba(0, 0, 0, 0.5); }
  .app .topbar__show { display: inline-grid; }
  .topbar { padding: 0 8px; }
  .topbar__title { display: none; }
  .picker { flex: 1; display: flex; justify-content: center; }
  .picker__caps { display: none; }
  .picker__btn { max-width: 100%; }
  .picker__pop { left: 50%; translate: -50% 0; }
  .kbd, .composer__hint { display: none; }
  .dock { padding: 0 10px max(10px, env(safe-area-inset-bottom)); }
  .thread__inner, .welcome { width: calc(100% - 32px); }
  .msg--assistant { grid-template-columns: minmax(0, 1fr); }
  .msg__gutter { display: none; }
  .msg__actions { opacity: 1; }
  .msg__bubble { max-width: 90%; }
  .composer__input, .field input, .field textarea, .field select, .search input, .conv__rename, .msg__edit textarea { font-size: 16px; }
  .md { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ==========================================================================
   Motion
   ========================================================================== */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes drop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }
@keyframes flow { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes glow { 0%, 100% { filter: drop-shadow(0 0 0 transparent); } 50% { filter: drop-shadow(0 0 6px var(--ember)); } }
