@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/vendor/bricolage-grotesque.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  --mist: #edf0f3;
  --surface: #ffffff;
  --sunken: #e3e7ec;
  --ink: #161a22;
  --muted: #5e6675;
  --line: #d3d9e0;
  --accent: #2d3fe0;
  --on-accent: #ffffff;
  --bubble: #dfe4fb;
  --heat-a: #f59e0b;
  --heat-b: #dc4a12;
  --danger: #b3261e;
  --code-bg: #171b24;
  --code-ink: #e7eaf0;
  --display: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sidebar-w: 17rem;
  --column: 46rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --mist: #12151b;
    --surface: #1b1f27;
    --sunken: #0d0f14;
    --ink: #e7eaf0;
    --muted: #9aa3b2;
    --line: #2c323d;
    --accent: #8fa0ff;
    --on-accent: #0d1030;
    --bubble: #262d4d;
    --danger: #ff8a80;
    --code-bg: #0b0d12;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--mist);
  color: var(--ink);
  font: 1rem/1.6 var(--body);
  -webkit-text-size-adjust: 100%;
}
button, select, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 1.25rem; height: 1.25rem; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* ── layout ── */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100dvh; }
.app.sidebar-closed { grid-template-columns: 0 minmax(0, 1fr); }
.app.sidebar-closed .sidebar { visibility: hidden; }

.sidebar {
  display: flex; flex-direction: column; gap: .5rem;
  min-width: 0; padding: .75rem;
  background: var(--sunken);
  border-right: 1px solid var(--line);
  overflow: hidden;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: .125rem .25rem .5rem; }
.wordmark {
  display: inline-flex; align-items: center; gap: .45rem;
  font: 650 1.2rem/1 var(--display); letter-spacing: -.02em;
  color: var(--ink); text-decoration: none;
}
.wordmark .mark { width: 1.3rem; height: 1.3rem; color: var(--accent); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 2.25rem; height: 2.25rem; padding: 0;
  background: none; border: 0; border-radius: .5rem; color: var(--muted);
}
.icon-btn:hover { background: color-mix(in srgb, var(--ink) 9%, transparent); color: var(--ink); }

.new-chat, .sidebar-foot {
  display: flex; align-items: center; gap: .6rem;
  width: 100%; padding: .55rem .65rem;
  background: none; border: 0; border-radius: .6rem; text-align: left;
}
.new-chat { font-weight: 600; }
.new-chat svg { color: var(--accent); }
.new-chat:hover, .sidebar-foot:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.sidebar-foot { color: var(--muted); font-size: .9rem; }

.chat-list { flex: 1; min-height: 0; overflow-y: auto; margin: .25rem -.25rem 0; padding: 0 .25rem; }
.chat-list-empty { padding: .5rem .65rem; color: var(--muted); font-size: .9rem; }
.chat-item { position: relative; display: flex; align-items: center; border-radius: .6rem; }
.chat-item:hover, .chat-item:focus-within { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.chat-item.active { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.chat-link {
  flex: 1; min-width: 0; padding: .45rem .65rem;
  background: none; border: 0; border-radius: .6rem; text-align: left;
  font-size: .925rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-rename {
  flex: 1; min-width: 0; margin: .2rem; padding: .25rem .45rem;
  background: var(--surface); border: 1px solid var(--accent); border-radius: .4rem; font-size: .925rem;
}
.chat-actions { display: none; padding-right: .2rem; }
.chat-item:hover .chat-actions, .chat-item:focus-within .chat-actions { display: flex; }
.chat-actions button {
  display: inline-grid; place-items: center; height: 1.8rem; min-width: 1.8rem; padding: 0 .3rem;
  background: none; border: 0; border-radius: .4rem; color: var(--muted); font-size: .8rem;
}
.chat-actions button:hover { background: color-mix(in srgb, var(--ink) 10%, transparent); color: var(--ink); }
.chat-actions button.confirm { color: var(--danger); font-weight: 600; }
.chat-actions svg { width: 1rem; height: 1rem; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: .5rem; min-height: 3.25rem; padding: .5rem .75rem; }
.app:not(.sidebar-closed) #expand { display: none; }
.chat-title { margin: 0; font-size: .95rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.scroller { flex: 1; min-height: 0; overflow-y: auto; padding: 0 1rem; scrollbar-gutter: stable both-edges; }
.thread { max-width: var(--column); margin: 0 auto; padding: .5rem 0 2rem; }

/* ── empty state: greeting and composer sit together in the middle ── */
.greeting { max-width: var(--column); margin: 0 auto; }
.greeting h2 {
  margin: 0 0 .5rem;
  font: 560 clamp(2rem, 1.2rem + 3.2vw, 3.1rem)/1.05 var(--display);
  letter-spacing: -.035em;
}
.greeting p { margin: 0; max-width: 34rem; color: var(--muted); }
.app.empty .scroller { flex: 0 0 auto; display: flex; align-items: flex-end; min-height: 34dvh; padding-bottom: 1.5rem; }
.app.empty .greeting { width: 100%; }
.app.empty .thread { display: none; }
.app:not(.empty) .greeting { display: none; }
.app.empty .composer { margin-bottom: auto; }

/* ── messages ── */
.msg { margin: 1.5rem 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  max-width: 85%; padding: .6rem .95rem;
  background: var(--bubble); border-radius: 1.1rem 1.1rem .3rem 1.1rem;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.assistant .body { overflow-wrap: anywhere; }
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body p, .body ul, .body ol, .body blockquote, .body table { margin: 0 0 .9rem; }
.body h1, .body h2, .body h3, .body h4 { margin: 1.4rem 0 .5rem; line-height: 1.25; letter-spacing: -.01em; }
.body h1 { font-size: 1.45rem; } .body h2 { font-size: 1.25rem; } .body h3 { font-size: 1.1rem; } .body h4 { font-size: 1rem; }
.body ul, .body ol { padding-left: 1.4rem; }
.body li + li { margin-top: .25rem; }
.body a { color: var(--accent); text-underline-offset: .15em; }
.body blockquote { padding-left: .9rem; border-left: 3px solid var(--line); color: var(--muted); }
.body hr { border: 0; border-top: 1px solid var(--line); margin: 1.4rem 0; }
.body :not(pre) > code {
  padding: .1em .35em; border-radius: .3rem;
  background: color-mix(in srgb, var(--ink) 9%, transparent); font: .9em var(--mono);
}
.body table { display: block; width: max-content; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: .95rem; }
.body th, .body td { padding: .4rem .7rem; border-bottom: 1px solid var(--line); text-align: left; }
.body th { font-weight: 600; }
.body img { max-width: 100%; }

.code { margin: 0 0 .9rem; border-radius: .7rem; background: var(--code-bg); color: var(--code-ink); overflow: hidden; }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: .3rem .4rem .3rem .9rem; font-size: .8rem; color: #a7b0c0; }
.code-head button { padding: .2rem .55rem; background: none; border: 0; border-radius: .35rem; color: inherit; font-size: .8rem; }
.code-head button:hover { background: rgb(255 255 255 / .12); color: #fff; }
.code pre { margin: 0; padding: .2rem .9rem .9rem; overflow-x: auto; font: .875rem/1.55 var(--mono); tab-size: 2; }

.thinking { margin: 0 0 .75rem; color: var(--muted); font-size: .925rem; }
.thinking summary { width: max-content; padding: .15rem 0; cursor: pointer; font-weight: 500; }
.thinking summary:hover { color: var(--ink); }
.thinking .thought { margin-top: .35rem; padding-left: .9rem; border-left: 2px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }

.msg-actions { display: flex; gap: .15rem; margin-top: .5rem; margin-left: -.4rem; }
.msg-actions button {
  display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .5rem;
  background: none; border: 0; border-radius: .45rem; color: var(--muted); font-size: .825rem;
}
.msg-actions button:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--ink); }
.msg-actions svg { width: 1rem; height: 1rem; }
.msg-note { margin-top: .6rem; color: var(--muted); font-size: .875rem; }
.msg-note.error { color: var(--danger); }
.cursor { display: inline-block; width: .55rem; height: 1.05em; margin-left: .1rem; vertical-align: text-bottom; background: var(--accent); border-radius: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ── composer ── */
.composer { width: 100%; max-width: calc(var(--column) + 2rem); margin: 0 auto; padding: 0 1rem max(1rem, env(safe-area-inset-bottom)); }
.composer-box {
  padding: .75rem .75rem .6rem 1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 1.25rem;
  box-shadow: 0 1px 2px rgb(22 26 34 / .05), 0 10px 28px -14px rgb(22 26 34 / .28);
}
.composer-box:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
#input {
  display: block; width: 100%; max-height: 14rem; padding: .15rem 0 .5rem;
  background: none; border: 0; outline: 0; resize: none; line-height: 1.5;
}
#input::placeholder { color: var(--muted); }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.model-picker {
  min-width: 0; max-width: 100%; padding: .35rem 1.7rem .35rem .65rem;
  background: color-mix(in srgb, var(--ink) 6%, transparent)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%237a8394' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E")
    no-repeat right .5rem center / .75rem;
  border: 0; border-radius: .6rem; appearance: none; font-size: .9rem; text-overflow: ellipsis;
}
.model-picker:hover { background-color: color-mix(in srgb, var(--ink) 11%, transparent); }
.send {
  display: inline-grid; place-items: center; width: 2.4rem; height: 2.4rem; padding: 0;
  background: var(--accent); color: var(--on-accent); border: 0; border-radius: .8rem;
}
.send:disabled { opacity: .4; cursor: default; }
.send .i-stop, .app.busy .send .i-send { display: none; }
.app.busy .send .i-stop { display: block; }

.notice { min-height: 1.3rem; margin: .4rem .5rem 0; color: var(--muted); font-size: .8rem; }
.notice.error { color: var(--danger); }

/* The one loud thing: a heat bar while a cold GPU comes up. */
.warming { display: flex; align-items: center; gap: .7rem; margin: 0 .5rem .6rem; font-size: .875rem; color: var(--muted); }
.warming[hidden] { display: none; }
.heat {
  flex: none; width: 5.5rem; height: .4rem; border-radius: 1rem;
  background: linear-gradient(90deg, var(--heat-a), var(--heat-b), var(--heat-a)) 0 0 / 200% 100%;
  animation: heat 1.6s linear infinite;
}
@keyframes heat { to { background-position: -200% 0; } }

/* ── settings dialog ── */
.settings {
  width: min(27rem, calc(100vw - 2rem)); padding: 1.5rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 1rem;
}
.settings::backdrop { background: rgb(10 12 18 / .5); }
.settings h2 { margin: 0 0 .4rem; font: 600 1.3rem/1.2 var(--display); letter-spacing: -.02em; }
.settings p { margin: 0 0 1rem; color: var(--muted); font-size: .925rem; }
.settings label { display: block; margin-bottom: .3rem; font-size: .875rem; font-weight: 600; }
.settings input {
  width: 100%; padding: .55rem .7rem;
  background: var(--mist); border: 1px solid var(--line); border-radius: .55rem; font-family: var(--mono); font-size: .9rem;
}
.signin-error { color: var(--danger) !important; }
.signin-error:empty { display: none; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }
.btn { padding: .5rem .95rem; border: 0; border-radius: .6rem; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.quiet { background: none; color: var(--muted); }
.btn.quiet:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--ink); }

.backdrop { display: none; }

/* ── phone: the sidebar becomes a drawer ── */
@media (max-width: 768px) {
  .app, .app.sidebar-closed { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(var(--sidebar-w), 86vw);
    visibility: visible !important; transition: translate .2s ease;
  }
  .app.sidebar-closed .sidebar { translate: -105% 0; }
  .app:not(.sidebar-closed) .backdrop { display: block; position: fixed; inset: 0; z-index: 10; background: rgb(10 12 18 / .45); }
  .app:not(.sidebar-closed) #expand { display: inline-grid; }
  .chat-actions { display: flex; }
  .msg.user .bubble { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  .heat, .cursor { animation: none; }
  .sidebar { transition: none; }
}
