/* 優伶拾酒 AI — one stylesheet.
   Same liquid-glass language as uling19.com: three materials (pane > card > control),
   one accent, spring motion. Sections: tokens, base, background, controls, login,
   sidebar, main, messages, composer, menus and dialogs, small screens, motion. */

/* ---------- tokens ---------- */
:root {
  color-scheme: dark;
  --font: Inter, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  --base: #070d1c;
  --ink: #f1f6ff;
  --ink-2: #c3d0e6;
  --ink-3: #a2b2cc;
  --accent: #86dcf2;
  --accent-ink: #082331;
  --danger: #ff9a9a;
  --warn: #f6c56b;
  --ok: #7fe0b0;

  --pane: rgb(9 14 30 / .44);
  --pane-filter: blur(28px) saturate(1.5);
  --pane-edge: rgb(255 255 255 / .13);
  --pane-shadow: 0 30px 80px rgb(0 4 18 / .46), 0 2px 8px rgb(0 4 18 / .28);
  --pane-rim: inset 0 1px 0 rgb(255 255 255 / .12);

  --card: linear-gradient(180deg, rgb(255 255 255 / .085), rgb(255 255 255 / .032) 56%, rgb(255 255 255 / .018));
  --card-edge: rgb(255 255 255 / .13);
  --card-edge-hi: rgb(186 236 250 / .62);
  --card-rim: inset 0 1px 0 rgb(255 255 255 / .10);
  --card-shadow: 0 14px 32px rgb(0 3 14 / .26), 0 2px 6px rgb(0 3 14 / .22);

  --tile: rgb(255 255 255 / .05);
  --tile-hi: rgb(255 255 255 / .09);
  --line: rgb(255 255 255 / .10);
  --field: rgb(2 8 22 / .38);
  --field-edge: rgb(255 255 255 / .20);
  --ctl: rgb(255 255 255 / .07);
  --ctl-hi: rgb(255 255 255 / .12);
  --ctl-rim: inset 0 1px 0 rgb(255 255 255 / .26), inset 0 -1px 0 rgb(0 0 0 / .22),
    inset 0 12px 20px -14px rgb(255 255 255 / .20), inset 0 -10px 16px -12px rgb(126 204 255 / .12);
  --lens: rgb(255 255 255 / .16);
  --lens-rim: inset 0 1px 0 rgb(255 255 255 / .44), inset 0 -7px 10px -8px rgb(255 255 255 / .16), 0 2px 8px rgb(0 5 20 / .28);
  --bubble-user: linear-gradient(180deg, rgb(134 220 242 / .26), rgb(134 220 242 / .14));
  --bubble-user-edge: rgb(134 220 242 / .38);
  --code: rgb(2 7 20 / .56);
  --scrim: rgb(2 6 18 / .56);
  --ring: 0 0 0 3px rgb(134 220 242 / .30);

  --orb-a: rgb(134 220 242 / .20);
  --orb-b: rgb(120 110 255 / .22);
  --orb-c: rgb(42 96 190 / .30);

  --r-pane: 26px;
  --r-card: 18px;
  --r-ctl: 12px;
  --gap: 16px;
  --sb: 8px;
  --sidebar-w: 312px;
  --col: 860px;

  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --spring-soft: cubic-bezier(.3, 1.22, .5, 1);
}
@supports (transition-timing-function: linear(0, 1)) {
  :root {
    --spring: linear(0, 0.051, 0.179, 0.353, 0.542, 0.725, 0.886, 1.015, 1.109, 1.167, 1.193, 1.194, 1.176, 1.146, 1.11, 1.073, 1.038, 1.009, 0.987, 0.972, 0.964, 0.961, 0.963, 0.968, 0.975, 0.982, 0.989, 0.995, 1, 1.004, 1.006, 1.007, 1.008, 1.007, 1.006, 1.004, 1);
    --spring-soft: linear(0, 0.018, 0.065, 0.132, 0.214, 0.303, 0.394, 0.485, 0.572, 0.653, 0.727, 0.792, 0.85, 0.899, 0.94, 0.973, 0.999, 1.019, 1.034, 1.044, 1.051, 1.054, 1.054, 1.053, 1.05, 1.046, 1.041, 1.036, 1.032, 1.027, 1.022, 1.018, 1.014, 1.01, 1.007, 1.005, 1);
  }
}
html[data-theme="light"] {
  color-scheme: light;
  --base: #e7eef8;
  --ink: #12233d;
  --ink-2: #33475f;
  --ink-3: #455a75;
  --accent: #0d6f8c;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --warn: #8a5a00;
  --ok: #0f7a4d;

  --pane: rgb(244 248 255 / .52);
  --pane-filter: blur(28px) saturate(1.7);
  --pane-edge: rgb(255 255 255 / .78);
  --pane-shadow: 0 28px 72px rgb(40 66 116 / .18), 0 2px 8px rgb(40 66 116 / .08);
  --pane-rim: inset 0 1px 0 rgb(255 255 255 / .9);

  --card: linear-gradient(180deg, rgb(255 255 255 / .62), rgb(255 255 255 / .34) 56%, rgb(255 255 255 / .26));
  --card-edge: rgb(118 148 200 / .24);
  --card-edge-hi: rgb(13 111 140 / .46);
  --card-rim: inset 0 1px 0 rgb(255 255 255 / .9);
  --card-shadow: 0 14px 30px rgb(40 66 116 / .13), 0 2px 6px rgb(40 66 116 / .09);

  --tile: rgb(255 255 255 / .42);
  --tile-hi: rgb(255 255 255 / .68);
  --line: rgb(70 100 150 / .20);
  --field: rgb(255 255 255 / .66);
  --field-edge: rgb(60 90 140 / .42);
  --ctl: rgb(255 255 255 / .56);
  --ctl-hi: rgb(255 255 255 / .82);
  --ctl-rim: inset 0 1px 0 rgb(255 255 255 / .98), inset 0 -1px 0 rgb(60 90 140 / .10),
    inset 0 12px 20px -14px rgb(255 255 255 / .75), inset 0 -10px 16px -12px rgb(96 150 230 / .10);
  --lens: rgb(255 255 255 / .92);
  --lens-rim: inset 0 1px 0 rgb(255 255 255 / 1), inset 0 -7px 10px -8px rgb(120 160 230 / .14), 0 2px 8px rgb(46 72 120 / .16);
  --bubble-user: linear-gradient(180deg, rgb(13 111 140 / .16), rgb(13 111 140 / .09));
  --bubble-user-edge: rgb(13 111 140 / .30);
  --code: rgb(18 35 61 / .07);
  --scrim: rgb(30 50 90 / .30);
  --ring: 0 0 0 3px rgb(13 111 140 / .22);

  --orb-a: rgb(120 200 235 / .50);
  --orb-b: rgb(170 160 255 / .38);
  --orb-c: rgb(255 255 255 / .70);
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font: 14px/1.55 var(--font);
  color: var(--ink);
  background: var(--base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
}
h1, h2, h3, p { margin: 0; }
p, .hero-tile span, .small-note, .model-status, .title-row p { text-wrap: pretty; }
body { word-break: auto-phrase; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
::selection { background: color-mix(in srgb, var(--accent) 34%, transparent); }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* one scrollbar look everywhere: thin, no track, no arrow buttons (Firefox uses the first rule) */
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--ink-3) 42%, transparent) transparent; }
}
::-webkit-scrollbar { width: var(--sb); height: var(--sb); }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--ink-3) 36%, transparent); border-radius: 99px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: color-mix(in srgb, var(--ink-3) 60%, transparent); }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-button { display: none; width: 0; height: 0; }

/* ---------- background ---------- */
.shell-bg {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: clip;
  isolation: isolate;
  background:
    radial-gradient(90% 70% at 100% 0%, var(--orb-c), transparent 62%),
    var(--base);
}
.bg-orb {
  position: absolute;
  inset: -22%;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(34% 32% at 22% 24%, var(--orb-a), transparent 72%),
    radial-gradient(38% 36% at 78% 74%, var(--orb-b), transparent 72%),
    radial-gradient(26% 24% at 62% 18%, var(--orb-a), transparent 74%);
  animation: ai-drift 28s ease-in-out infinite alternate;
  will-change: transform;
}
@keyframes ai-drift {
  from { transform: translate3d(-3%, -2%, 0) scale(1); }
  to   { transform: translate3d(4%, 3%, 0) scale(1.06); }
}

/* ---------- controls ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  background: var(--ctl);
  box-shadow: var(--ctl-rim);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform .36s var(--spring), background-color .2s var(--ease), border-color .2s var(--ease), opacity .2s;
}
.btn:hover { background: var(--ctl-hi); }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .42), 0 8px 20px color-mix(in srgb, var(--accent) 24%, transparent);
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, white); }
.btn-danger-soft { color: var(--danger); }
.btn-danger-soft:hover { background: color-mix(in srgb, var(--danger) 16%, transparent); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--tile-hi); }

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--ctl);
  box-shadow: var(--ctl-rim);
  color: var(--ink-2);
  transition: transform .36s var(--spring), background-color .2s var(--ease), color .2s;
}
.icon-btn:hover { background: var(--ctl-hi); color: var(--ink); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .42), 0 8px 20px color-mix(in srgb, var(--accent) 26%, transparent);
}
.icon-btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, white); color: var(--accent-ink); }
.icon-btn:disabled { opacity: .5; cursor: not-allowed; }

.input, .search-input, .ui-modal-input, .ui-modal textarea {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--field-edge);
  border-radius: var(--r-ctl);
  background: var(--field);
  color: var(--ink);
  outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease), background-color .2s;
}
.input::placeholder, .search-input::placeholder, .chat-input::placeholder, .ui-modal-input::placeholder, .ui-modal textarea::placeholder { color: var(--ink-3); opacity: .8; }
.input:focus, .search-input:focus, .ui-modal-input:focus, .ui-modal textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
  box-shadow: var(--ring);
}
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
.field { display: grid; gap: 6px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-3); letter-spacing: .02em; }
.row { display: flex; gap: 10px; }
.row > .btn { flex: 1; }
.small-note, .model-status { font-size: 12.5px; line-height: 1.6; color: var(--ink-3); }
.error-box { font-size: 13px; color: var(--danger); }
.error-box:empty { display: none; }

/* theme switch: a small segmented control, the active chip is a lens */
.theme-group, .compact-theme {
  flex: none;
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--tile);
}
.theme-chip {
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color .25s var(--ease), color .2s, box-shadow .25s var(--ease), transform .36s var(--spring);
}
.theme-chip:hover { color: var(--ink); }
.theme-chip:active { transform: scale(.94); }
.theme-chip.active { background: var(--lens); box-shadow: var(--lens-rim); color: var(--ink); }

/* never shown: legacy guest quota, unused badges and toasts, duplicate copy button */
.toast-stack, .sending-badge, .msg-bubble-copy, #taskArtifactsBar { display: none !important; }

/* ---------- login ---------- */
.login-wrap {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
}
.login-card {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  width: min(1000px, 100%);
  border: 1px solid var(--pane-edge);
  border-radius: var(--r-pane);
  background: var(--pane);
  -webkit-backdrop-filter: var(--pane-filter);
  backdrop-filter: var(--pane-filter);
  box-shadow: var(--pane-shadow), var(--pane-rim);
  overflow: hidden;
  animation: ai-rise .7s var(--spring-soft) both;
}
.hero {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 24px;
  padding: 40px;
  border-right: 1px solid var(--line);
}
.hero h1 { font-size: 30px; line-height: 1.2; letter-spacing: -.01em; }
.hero p { margin-top: 12px; color: var(--ink-2); line-height: 1.7; }
.hero-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero-tile {
  display: grid;
  gap: 4px;
  align-content: start;
  padding: 14px;
  border: 1px solid var(--card-edge);
  border-radius: var(--r-card);
  background: var(--card);
  box-shadow: var(--card-rim);
}
.hero-tile strong { font-size: 13.5px; }
.hero-tile span { font-size: 12.5px; line-height: 1.6; color: var(--ink-3); }
.login-panel { position: relative; display: grid; align-content: center; gap: 16px; padding: 40px; }
.login-top { display: block; }
.theme-group-login { position: absolute; top: 20px; right: 40px; }
.title-row h2 { font-size: 22px; line-height: 1.25; }
.title-row p { margin-top: 8px; font-size: 13px; line-height: 1.65; color: var(--ink-3); }
.login-panel .input { height: 44px; }
.login-panel .btn { height: 44px; }

/* ---------- workspace shell ---------- */
.app-shell {
  height: 100%;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: var(--gap);
  padding: 18px;
}
.sidebar, .main-panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--pane-edge);
  border-radius: var(--r-pane);
  background: var(--pane);
  -webkit-backdrop-filter: var(--pane-filter);
  backdrop-filter: var(--pane-filter);
  box-shadow: var(--pane-shadow), var(--pane-rim);
}
.mobile-toggle, .scrim { display: none; }

/* ---------- sidebar ---------- */
.sidebar { display: flex; flex-direction: column; overflow-x: hidden; overflow-y: auto; }
.sidebar-head { flex: none; display: flex; flex-direction: column; gap: 10px; padding: 16px 16px 10px; }
.brand { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 34px; }
.brand h2 { font-size: 17px; letter-spacing: .01em; white-space: nowrap; }
.toolbar { display: flex; gap: 8px; }
.toolbar .btn-primary { flex: 1; }

.profile-card { display: grid; gap: 10px; }
.profile-top { min-width: 0; }
.profile-identity { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 2px; }
.profile-identity > div:last-child { min-width: 0; }
.profile-avatar, .profile-avatar-fallback {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--pane-edge);
  object-fit: cover;
}
.profile-avatar-fallback { display: grid; place-items: center; background: var(--tile-hi); font-size: 12px; font-weight: 700; color: var(--ink-2); }
.profile-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-meta { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-type-badge {
  align-items: center;
  height: 18px;
  margin-top: 4px;
  padding: 0 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .04em;
}

/* API note, balance, model settings: the same quiet tile */
.profile-link-strip, .quota-wrap {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--tile);
}
.profile-link-strip .label { display: grid; gap: 3px; min-width: 0; }
.kicker { font-size: 11px; font-weight: 700; letter-spacing: .08em; color: var(--ink-3); }
.profile-link-strip .title { font-size: 13px; font-weight: 600; }
.profile-link-strip .desc { font-size: 12px; color: var(--ink-3); }
.quota-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.quota-head .btn { height: 24px; padding: 0 9px; border-radius: 8px; font-size: 11.5px; }
.quota-value { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 4px; font-size: 12.5px; line-height: 1.5; color: var(--ink-2); }
.quota-part { max-width: 100%; overflow-wrap: anywhere; }
.quota-part:first-child { color: var(--ink); font-weight: 600; }

.model-settings-wrap { display: grid; gap: 10px; }
.model-settings-wrap.is-collapsible { padding: 0; gap: 0; overflow: hidden; }
.model-settings-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  transition: background-color .2s var(--ease);
}
.model-settings-toggle:hover { background: var(--tile-hi); }
.model-settings-toggle > span:first-child { flex: none; }
.mst-cur { flex: 1; min-width: 0; text-align: right; font: 500 12px/1.4 var(--mono); color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mst-arrow { flex: none; color: var(--ink-3); transition: transform .45s var(--spring-soft); }
.model-settings-wrap.collapsed .mst-arrow { transform: rotate(-90deg); }
.model-settings-body { display: grid; gap: 10px; padding: 4px 12px 12px; }
.model-settings-wrap.collapsed .model-settings-body { display: none; }
.model-picker-row { display: flex; gap: 6px; min-width: 0; }
.model-picker-row .input { flex: 1; min-width: 0; height: 36px; padding: 0 10px; font: 500 12.5px/1 var(--mono); }
.model-dropdown-btn, .model-refresh-btn {
  flex: none;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  background: var(--ctl);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  transition: background-color .2s var(--ease), transform .36s var(--spring);
}
.model-dropdown-btn { width: 36px; padding: 0; }
.model-dropdown-btn:hover, .model-refresh-btn:hover { background: var(--ctl-hi); color: var(--ink); }
.model-dropdown-btn:active, .model-refresh-btn:active { transform: scale(.94); }

.search-box { flex: none; padding: 0 16px 10px; }
.conv-list { flex: 1 1 auto; min-height: 150px; overflow-y: auto; padding: 0 16px 12px; scrollbar-gutter: auto; }
.conv-item {
  position: relative;
  display: grid;
  margin-bottom: 4px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  transition: background-color .2s var(--ease), border-color .2s var(--ease), transform .36s var(--spring);
}
.conv-item:hover { background: var(--tile); }
.conv-item:active { transform: scale(.985); }
.conv-item.active { background: var(--tile-hi); border-color: var(--card-edge); box-shadow: var(--card-rim); }
.conv-item.archived { opacity: .62; }
.conv-main { display: grid; gap: 2px; min-width: 0; }
.conv-title { padding-right: 26px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; font-size: 11px; color: var(--ink-3); }
.status-chip { flex: none; padding: 1px 7px; border-radius: 999px; background: var(--tile-hi); font-size: 10.5px; font-weight: 600; }
.status-chip.active { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.conv-delete-inline {
  position: absolute;
  top: 7px;
  right: 7px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
  font-size: 16px;
  line-height: 1;
  opacity: 0;
  transition: opacity .2s, background-color .2s, color .2s;
}
.conv-item:hover .conv-delete-inline, .conv-item.active .conv-delete-inline, .conv-delete-inline:focus-visible { opacity: 1; }
.conv-delete-inline:hover { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

/* ---------- main ---------- */
.main-panel { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: clip; }
.main-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}
.main-head > div:first-child { min-width: 0; }
.head-title { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-sub { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-actions { flex: none; display: flex; gap: 8px; }
.head-actions .btn { height: 34px; padding: 0 12px; font-size: 13px; }

/* ---------- messages ---------- */
.chat-view {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable both-edges;
  padding: 30px max(20px, calc((100% - var(--col)) / 2 - var(--sb))) 26px;
  scroll-behavior: smooth;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 40px, #000 calc(100% - 22px), transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0, #000 40px, #000 calc(100% - 22px), transparent 100%);
}
.msg { display: flex; flex-direction: column; gap: 6px; min-width: 0; max-width: 100%; }
.msg.user { align-items: flex-end; }
.msg.assistant, .msg.system { align-items: flex-start; }
.msg:last-child { animation: ai-msg .55s var(--spring-soft) both; }
.msg-meta { display: flex; align-items: center; gap: 8px; min-height: 24px; font-size: 12px; font-weight: 600; color: var(--ink-3); }
.msg.user .msg-meta { flex-direction: row-reverse; }
.msg-meta-tools { display: flex; gap: 2px; opacity: 0; transition: opacity .2s var(--ease); }
.msg:hover .msg-meta-tools, .msg:focus-within .msg-meta-tools { opacity: 1; }
.msg-meta > span:first-child { color: var(--ink-2); }
.msg-inline-action { height: 24px; padding: 0 8px; border-radius: 8px; font-size: 12px; font-weight: 500; color: var(--ink-3); }
.msg-inline-action:hover { color: var(--ink); }
.msg-bubble {
  position: relative;
  min-width: 0;
  max-width: min(100%, 760px);
  padding: 12px 16px;
  border: 1px solid var(--card-edge);
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--card-rim), var(--card-shadow);
  line-height: 1.7;
  overflow-wrap: anywhere;
}
.msg.assistant .msg-bubble { border-top-left-radius: 8px; }
.msg.user .msg-bubble { max-width: min(86%, 620px); border-top-right-radius: 8px; border-color: var(--bubble-user-edge); background: var(--bubble-user); }
.msg.system .msg-bubble { border-style: dashed; box-shadow: none; color: var(--ink-2); font-size: 13px; }
.msg-bubble > p + p, .msg-bubble > p + .md-content { margin-top: 8px; }
.msg-image { display: block; max-width: min(720px, 100%); height: auto; border: 1px solid var(--line); border-radius: 14px; }

.md-content { min-width: 0; }
.md-content > :first-child { margin-top: 0; }
.md-content > :last-child { margin-bottom: 0; }
.md-content p, .md-content ul, .md-content ol, .md-content blockquote, .md-content pre, .md-content table { margin: 0 0 10px; }
.md-content h1, .md-content h2, .md-content h3, .md-content h4 { margin: 16px 0 8px; line-height: 1.35; }
.md-content h1 { font-size: 20px; }
.md-content h2 { font-size: 17.5px; }
.md-content h3 { font-size: 15.5px; }
.md-content h4 { font-size: 14px; }
.md-content ul, .md-content ol { padding-left: 22px; }
.md-content li + li { margin-top: 3px; }
.md-content blockquote { padding: 2px 12px; border-left: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); color: var(--ink-2); }
.md-content blockquote > :last-child { margin-bottom: 0; }
.md-content hr { height: 1px; margin: 14px 0; border: 0; background: var(--line); }
.md-content img { max-width: 100%; height: auto; border-radius: 12px; }
.md-content code { padding: 1px 5px; border: 1px solid var(--line); border-radius: 6px; background: var(--code); font: 500 .9em/1.5 var(--mono); }
.md-content pre { max-width: 100%; padding: 12px 56px 12px 14px; overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--code); }
.md-content pre code { padding: 0; border: 0; background: none; font-size: 12.5px; line-height: 1.6; white-space: pre; overflow-wrap: normal; }
.md-content table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 13px; }
.md-content th, .md-content td { padding: 6px 10px; border: 1px solid var(--line); text-align: left; }
.md-content th { background: var(--tile); font-weight: 600; }
.md-content .katex-display { margin: 10px 0; padding: 4px 52px 4px 0; overflow-x: auto; overflow-y: hidden; }
.mini-code-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--pane);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--ink-2);
  font: 600 11.5px/1 var(--font);
  opacity: 0;
  transition: opacity .2s var(--ease);
}
pre:hover > .mini-code-copy-btn, .katex-display:hover > .mini-code-copy-btn, .mini-code-copy-btn:focus-visible { opacity: 1; }

/* ---------- composer ---------- */
.composer { padding: 6px max(calc(20px + var(--sb)), calc((100% - var(--col)) / 2)) 20px; }
.composer-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 22px; margin-bottom: 8px; }
.composer-hint { min-width: 0; font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-hint.status-error { color: var(--danger); }
.composer-meta { flex: none; display: flex; align-items: center; gap: 8px; max-width: 60%; }
.file-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  height: 26px;
  padding: 0 4px 0 10px;
  border: 1px solid var(--card-edge);
  border-radius: 999px;
  background: var(--tile-hi);
  font-size: 12px;
}
.file-pill span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-pill button { flex: none; display: grid; place-items: center; width: 20px; height: 20px; border: 0; border-radius: 50%; background: transparent; color: var(--ink-3); font-size: 15px; line-height: 1; }
.file-pill button:hover { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.compose-box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--card-edge);
  border-radius: 26px;
  background: var(--card);
  box-shadow: var(--card-rim), var(--card-shadow);
  transition: border-color .25s var(--ease), box-shadow .25s var(--ease);
}
.compose-box:focus-within { border-color: var(--card-edge-hi); }
.chat-input {
  flex: 1;
  min-width: 0;
  height: 42px;
  min-height: 42px;
  max-height: 38vh;
  padding: 10px 4px;
  border: 0;
  background: transparent;
  outline: none;
  resize: none;
  line-height: 22px;
  overflow-y: auto;
  field-sizing: content;
}
@supports (field-sizing: content) { .chat-input { height: auto; } }

/* ---------- model menu, dialogs ---------- */
.model-menu {
  position: fixed;
  z-index: 10000;
  max-height: 270px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--pane-edge);
  border-radius: 16px;
  background: color-mix(in srgb, var(--base) 82%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(1.5);
  backdrop-filter: blur(24px) saturate(1.5);
  box-shadow: var(--pane-shadow);
  animation: ai-pop .32s var(--spring-soft) both;
}
.model-menu-head { display: flex; justify-content: space-between; gap: 8px; padding: 4px 8px 6px; font-size: 11px; color: var(--ink-3); }
.model-menu-glabel { padding: 8px 8px 2px; font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.model-menu-item {
  display: block;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font: 500 12.5px/1.4 var(--mono);
  text-align: left;
  overflow-wrap: anywhere;
}
.model-menu-item:hover { background: var(--tile-hi); }
.model-menu-item.is-active { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.model-menu-empty { padding: 10px 8px; font-size: 12px; color: var(--ink-3); }

.ui-modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity .18s var(--ease);
}
.ui-modal-scrim.show { opacity: 1; }
.ui-modal {
  display: grid;
  gap: 14px;
  width: min(460px, 100%);
  padding: 22px;
  border: 1px solid var(--pane-edge);
  border-radius: 22px;
  background: color-mix(in srgb, var(--base) 78%, transparent);
  -webkit-backdrop-filter: var(--pane-filter);
  backdrop-filter: var(--pane-filter);
  box-shadow: var(--pane-shadow), var(--pane-rim);
  transform: scale(.94) translateY(8px);
  transition: transform .42s var(--spring-soft);
}
.ui-modal-scrim.show .ui-modal { transform: none; }
.ui-modal h3 { font-size: 17px; }
.ui-modal-body { color: var(--ink-2); line-height: 1.7; white-space: pre-wrap; }
.ui-modal textarea { height: auto; min-height: 120px; max-height: 50vh; padding: 10px 12px; line-height: 1.6; resize: vertical; }
.ui-modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.ui-modal-btn {
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  background: var(--ctl);
  box-shadow: var(--ctl-rim);
  font-size: 13.5px;
  font-weight: 600;
  transition: transform .36s var(--spring), background-color .2s var(--ease);
}
.ui-modal-btn:hover { background: var(--ctl-hi); }
.ui-modal-btn:active { transform: scale(.96); }
.ui-modal-btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.ui-modal-btn.danger { background: color-mix(in srgb, var(--danger) 22%, transparent); border-color: color-mix(in srgb, var(--danger) 46%, transparent); color: var(--danger); }

/* ---------- touch: actions are always visible and easier to hit ---------- */
@media (hover: none) {
  .msg-meta-tools, .conv-delete-inline, .mini-code-copy-btn { opacity: 1; }
  .msg-inline-action { height: 30px; padding: 0 10px; }
  .quota-head .btn { height: 32px; padding: 0 12px; }
  .msg-meta { min-height: 30px; }
  .conv-delete-inline { width: 32px; height: 32px; top: 6px; right: 4px; }
}

/* ---------- small screens: the sidebar becomes a drawer ---------- */
@media (max-width: 980px) {
  .shell-bg { height: var(--mobile-app-height, 100dvh); }
  .app-shell { display: flex; padding: 0; gap: 0; }
  .main-panel { flex: 1; border: 0; border-radius: 0; box-shadow: none; }
  .mobile-toggle {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    left: 12px;
    z-index: 130;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--ctl);
    box-shadow: var(--ctl-rim);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    color: var(--ink);
    transition: transform .36s var(--spring);
  }
  .mobile-toggle:active { transform: scale(.92); }
  body:not(.app-active) .mobile-toggle { display: none; }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 120;
    width: min(320px, 86vw);
    padding-top: calc(50px + env(safe-area-inset-top));
    border-radius: 0 var(--r-pane) var(--r-pane) 0;
    border-left: 0;
    background: var(--base);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform .5s var(--spring-soft), visibility 0s linear .5s;
  }
  .sidebar.open { transform: none; visibility: visible; transition: transform .5s var(--spring-soft), visibility 0s; }
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 110;
    background: var(--scrim);
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s var(--ease);
  }
  .scrim.open { opacity: 1; pointer-events: auto; }
  .main-head { flex-wrap: wrap; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px 62px; }
  .main-head > div:first-child { flex: 1 1 100%; min-height: 40px; display: grid; align-content: center; }
  .head-title { font-size: 16px; }
  .head-actions { flex: 1 1 100%; margin-left: -50px; gap: 8px; }
  .head-actions .btn { flex: 1; height: 40px; padding: 0 8px; }
  .head-actions .btn-danger-soft { flex: 0 0 auto; margin-left: 12px; padding: 0 14px; }
  .mobile-toggle { width: 44px; height: 44px; }
  .theme-chip { height: 32px; }
  .chat-view { gap: 14px; padding: 22px 10px 18px; scrollbar-gutter: auto; scrollbar-width: none; }
  .chat-view::-webkit-scrollbar { display: none; }
  .msg-bubble { padding: 10px 14px; }
  .msg.user .msg-bubble { max-width: 88%; }
  .msg-bubble { max-width: 100%; }
  .md-content pre code { line-height: 1.55; }
  .composer { padding: 6px 10px calc(10px + env(safe-area-inset-bottom)); }
  .composer-top { margin-bottom: 6px; }
  /* 16px stops iOS from zooming the page when a field takes focus */
  .input, .search-input, .chat-input, .ui-modal-input, .ui-modal textarea, .model-picker-row .input { font-size: 16px; }
  .login-wrap { place-items: start center; padding: 16px; }
  .login-card { grid-template-columns: 1fr; margin: auto 0; }
  .hero { display: none; }
  .login-panel { padding: 26px 20px; }
  .theme-group-login { top: 20px; right: 20px; }
  .title-row h2 { min-height: 34px; padding-right: 150px; display: flex; align-items: center; white-space: nowrap; }
  .title-row p { margin-top: 12px; }
}
@media (max-width: 420px) {
  .row { flex-direction: column; }
  .row > .btn { flex: none; width: 100%; }
}
@media (max-width: 350px) {
  /* too narrow for the heading and the switch side by side: the switch gets its own line */
  .theme-group-login { position: static; margin-top: 14px; }
  .title-row h2 { padding-right: 0; }
}

/* ---------- motion ---------- */
@keyframes ai-rise { from { opacity: 0; transform: translateY(16px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes ai-msg  { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes ai-pop  { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* API workbench and task controls */
.compact-select{max-width:140px;min-height:34px;padding:6px 28px 6px 9px;border:1px solid var(--line,#34425a);border-radius:7px;background:var(--base);color:var(--ink);font:inherit}
.compact-select-label{font-size:12px;color:var(--ink-3)}
.workbench{color:var(--ink);position:absolute;z-index:30;inset:72px 18px 18px;background:var(--base);border:1px solid var(--line,#34425a);border-radius:8px;padding:18px;overflow:auto;box-shadow:0 18px 50px rgba(0,0,0,.35)}
.workbench-head,.workbench-actions{display:flex;align-items:center;justify-content:space-between;gap:10px}.workbench-head h2{font-size:18px;margin:0}
.workbench-controls{display:grid;grid-template-columns:repeat(4,minmax(130px,1fr));gap:10px;margin:16px 0}
.workbench-controls label,.multipart-fields label,.workbench-advanced label{display:grid;gap:5px;font-size:12px;color:var(--ink-3)}
.workbench-label{display:block;margin:10px 0 5px;font-size:12px;color:var(--ink-3)}
.workbench-json{width:100%;min-height:150px;font-family:ui-monospace,monospace;resize:vertical}
.multipart-fields,.gif-options{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;margin:12px 0}
.workbench-advanced{margin:12px 0;padding:10px 0;border-top:1px solid var(--line,#34425a)}.workbench-advanced summary{cursor:pointer;font-weight:600;margin-bottom:10px}
.workbench-advanced[open]{display:grid;gap:10px}.workbench-actions{justify-content:flex-start;flex-wrap:wrap;margin:12px 0}
.workbench-preview{min-height:120px;max-height:38vh;overflow:auto;padding:10px;border:1px solid var(--line,#34425a);border-radius:6px;background:var(--field)}
.workbench-preview pre{white-space:pre-wrap;overflow-wrap:anywhere;margin:0;font:12px/1.55 ui-monospace,monospace}.workbench-preview img{display:block;max-width:100%;max-height:34vh;object-fit:contain}.workbench-preview video,.workbench-preview audio{max-width:100%}
@media(max-width:760px){.workbench{inset:54px 8px 8px;padding:12px}.workbench-controls{grid-template-columns:repeat(2,minmax(0,1fr))}.composer-meta{flex-wrap:wrap}.compact-select{max-width:120px}.multipart-fields,.gif-options{grid-template-columns:1fr}}
