:root {
  --bg: #FAF9F5;
  --side: #F3F1EA;
  --surface: #FFFFFF;
  --user: #F0EEE6;
  --text: #1F1E1D;
  --muted: #73726C;
  --faint: #A3A199;
  --line: #E6E3D8;
  --accent: #C96442;
  --accent-soft: #F6E4DC;
  --code-bg: #F5F3EC;
  --shadow: 0 1px 2px rgba(31, 30, 29, .04), 0 4px 18px rgba(31, 30, 29, .06);
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Source Serif 4', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #262624; --side: #1F1E1D; --surface: #30302E; --user: #3A3936;
    --text: #F2F0E8; --muted: #A6A39A; --faint: #75736C; --line: #3D3C38;
    --accent: #D97757; --accent-soft: #4A3229; --code-bg: #1F1E1D;
    --shadow: 0 1px 2px rgba(0,0,0,.2), 0 6px 22px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #262624; --side: #1F1E1D; --surface: #30302E; --user: #3A3936;
  --text: #F2F0E8; --muted: #A6A39A; --faint: #75736C; --line: #3D3C38;
  --accent: #D97757; --accent-soft: #4A3229; --code-bg: #1F1E1D;
  --shadow: 0 1px 2px rgba(0,0,0,.2), 0 6px 22px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.app { display: grid; grid-template-columns: 260px minmax(0, 1fr) 0; height: 100dvh; overflow: hidden; transition: grid-template-columns .35s ease; }
.app.with-panel { grid-template-columns: 260px minmax(0, 1fr) minmax(0, 1.1fr); }

/* Mark: a warm gradient orb. Still at rest; it turns slowly and breathes while "thinking". */
.ava { position: relative; display: inline-block; width: 26px; height: 26px; flex: none; border-radius: 50%; overflow: hidden; isolation: isolate;
  box-shadow: 0 1px 2px rgba(31, 30, 29, .18), 0 4px 12px rgba(201, 100, 66, .18); }
.ava::before { content: ''; position: absolute; inset: -20%;
  background: conic-gradient(from 200deg, #B5543A, #D9825E, #F2C3A0, #E59A72, #C96442, #9E4A30, #B5543A); filter: blur(2px); }
.ava::after { content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 32% 26%, rgba(255, 255, 255, .7), rgba(255, 255, 255, 0) 45%);
  box-shadow: inset 0 -3px 6px rgba(80, 30, 15, .22), inset 0 0 0 .5px rgba(255, 255, 255, .25); }
.ava.big { width: 44px; height: 44px; }
.ava.small { width: 18px; height: 18px; }
.ava.busy { animation: breathe 1.6s ease-in-out infinite; }
.ava.busy::before { animation: turn 2.4s linear infinite; }
@keyframes breathe { 50% { transform: scale(.86); } }
@keyframes turn { to { transform: rotate(360deg); } }

/* Sidebar */
.sidebar { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 12px; gap: 14px; min-width: 0; }
.side-top { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.brand { font: 600 19px/1 var(--serif); letter-spacing: -.01em; }
.new-chat { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--accent); font-weight: 500; text-align: left; }
.new-chat svg { background: var(--accent); color: #fff; border-radius: 50%; padding: 3px; width: 22px; height: 22px; stroke-width: 2.2; }
.new-chat:hover, .recent:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.recents { flex: 1; overflow: auto; }
.recents-label { font-size: 12px; color: var(--muted); padding: 6px 10px; }
.recent { font-size: 13.5px; padding: 7px 10px; border-radius: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 10px 8px 2px; border-top: 1px solid var(--line); font-size: 13.5px; }
.side-user small { display: block; color: var(--muted); font-size: 12px; }
.avatar { width: 32px; height: 32px; flex: none; }
.avatar svg { width: 100%; height: 100%; display: block; stroke: none; }

/* Main */
.main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; gap: 12px; }
.model { display: flex; align-items: center; gap: 4px; padding: 6px 10px; border-radius: 8px; font-weight: 500; font-size: 14.5px; white-space: nowrap; }
.model:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.model-sub { color: var(--muted); font-weight: 400; }

.thread { flex: 1; overflow-y: auto; padding: 8px 24px 24px; scroll-behavior: smooth; }
.thread > * { max-width: 720px; margin-left: auto; margin-right: auto; }
.welcome { display: grid; place-items: center; min-height: 38vh; align-content: end; padding-bottom: 28px; }
.welcome h1 { display: flex; align-items: center; gap: 14px; font: 400 clamp(28px, 4.4vw, 40px)/1.15 var(--serif); letter-spacing: -.02em; margin: 0; text-align: center; }

.app.chatting .welcome { display: none; }
.app:not(.chatting) .thread { flex: 0 0 auto; }
.app:not(.chatting) .main { justify-content: center; }
.app:not(.chatting) .topbar { position: absolute; top: 0; left: 0; right: 0; }

/* Messages */
.msg-user { display: flex; justify-content: flex-end; margin: 22px auto 8px; }
.msg-user .bubble { background: var(--user); padding: 10px 16px; border-radius: 18px; max-width: 80%; font-size: 15px; animation: rise .25s ease; }
.msg-ai { margin: 6px auto 26px; font: 17px/1.62 var(--serif); }
.msg-ai p { margin: 0 0 14px; }
.msg-ai strong { font-weight: 600; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.think { font: 13.5px/1.5 var(--sans); color: var(--muted); margin-bottom: 14px; }
.think-head { display: inline-flex; align-items: center; gap: 8px; padding: 4px 8px 4px 0; border-radius: 8px; }
.think-head > svg { width: 14px; height: 14px; transition: transform .2s; }
.tok { font: 12px var(--mono); color: var(--faint); }
.tok:empty { display: none; }
.status { display: flex; align-items: center; gap: 8px; font: 13.5px var(--sans); color: var(--muted); margin: 2px 0 12px; }
.status .think-label { font: inherit; }
.think.open .think-head > svg { transform: rotate(90deg); }
.think-label.live { background: linear-gradient(90deg, var(--muted) 0%, var(--text) 50%, var(--muted) 100%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.6s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.think-body { display: none; border-left: 2px solid var(--line); margin: 6px 0 4px 6px; padding: 2px 0 2px 14px; }
.think.open .think-body { display: block; }
.think-body p { margin: 0 0 6px; animation: rise .3s ease; }

.msg-foot { display: flex; gap: 14px; align-items: center; color: var(--faint); font: 12px var(--mono); margin-top: -2px; }
.msg-foot .acts { display: flex; gap: 2px; }
.msg-foot .acts span { padding: 5px; border-radius: 6px; display: grid; }
.msg-foot svg { width: 15px; height: 15px; }

.cursor { display: inline-block; width: 9px; height: 17px; background: var(--accent); border-radius: 2px; vertical-align: -2px; margin-left: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Artifact card inside a message */
.art-card { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 0 0 10px; font: 14px/1.35 var(--sans); box-shadow: var(--shadow); transition: border-color .15s, transform .15s; animation: rise .3s ease; }
.art-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.art-card.active { border-color: var(--accent); }
.art-icon { width: 44px; height: 44px; border-radius: 10px; flex: none; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.art-icon svg { width: 21px; height: 21px; }
.art-meta { min-width: 0; flex: 1; }
.art-meta strong { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.art-meta small { color: var(--muted); font-size: 12.5px; }
.art-open { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.art-card.writing .art-meta small::after { content: ' · writing…'; }
.art-card.writing .art-icon { animation: pulse 1s infinite; }

/* Inline widgets: charts and cards drawn inside the reply */
.wg { font: 14px/1.45 var(--sans); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px 14px; margin: 4px 0 16px; box-shadow: var(--shadow); animation: rise .35s ease; overflow: hidden; }
.wg-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.wg-title { font-weight: 500; }
.wg-note { color: var(--muted); font-size: 12.5px; margin-top: 12px; }
.wg-callout { text-align: right; flex: none; }
.wg-callout b { display: block; font: 600 26px/1 var(--serif); color: var(--accent); }
.wg-callout span { font-size: 12px; color: var(--muted); }
.vbars { display: grid; gap: 8px; align-items: end; height: 160px; margin-top: 16px; }
.vbar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; min-width: 0; }
.vbar i { width: 100%; max-width: 40px; border-radius: 6px 6px 2px 2px; background: color-mix(in srgb, var(--accent) 55%, var(--surface)); transform-origin: bottom; animation: growy .9s cubic-bezier(.2, .8, .2, 1) backwards; }
@keyframes growy { from { transform: scaleY(0); } }
.vbar.accent i { background: var(--accent); }
.vbar.muted i { background: color-mix(in srgb, var(--faint) 45%, var(--surface)); }
.vbar b { font: 500 12px var(--mono); }
.vbar span { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.tile { background: var(--bg); border: 1px solid var(--line); border-radius: 11px; padding: 12px 13px; animation: rise .4s ease backwards; }
.tile b { display: block; font: 600 23px/1.1 var(--serif); color: var(--accent); margin-bottom: 4px; letter-spacing: -.01em; }
.tile span { font-size: 12.5px; color: var(--muted); }
.hbars { margin-top: 16px; position: relative; display: grid; gap: 14px; padding-bottom: 22px; }
.hbar-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.hbar-label b { font: 500 13px var(--mono); color: var(--accent); }
.hbar-track { height: 12px; background: var(--code-bg); border-radius: 99px; overflow: hidden; }
.hbar-track i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transform-origin: left; animation: growx 1s cubic-bezier(.2, .8, .2, 1) backwards; }
@keyframes growx { from { transform: scaleX(0); } }
.hbar-ref { position: absolute; top: -4px; bottom: 0; border-left: 1.5px dashed var(--faint); }
.hbar-ref span { position: absolute; bottom: 0; right: 6px; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.tlw { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); margin-top: 16px; position: relative; }
.tlw::before { content: ''; position: absolute; left: 0; right: 0; top: 27px; height: 1.5px; background: var(--line); }
.tlw div { position: relative; padding-right: 6px; animation: rise .4s ease backwards; }
.tlw b { font: 600 12.5px var(--mono); color: var(--accent); }
.tlw i { display: block; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); margin: 6px 0 10px; box-shadow: 0 0 0 4px var(--surface); position: relative; }
.tlw div:last-child i { background: var(--surface); border: 2px solid var(--accent); }
.tlw strong { display: block; font-weight: 500; font-size: 13px; line-height: 1.3; }
.tlw span { font-size: 12px; color: var(--muted); }
.cmp { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.cmp > div { border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 14px; }
.cmp-org { display: flex; justify-content: space-between; font-weight: 500; }
.cmp-org span { color: var(--muted); font: 12px var(--mono); }
.cmp p { margin: 6px 0 12px; color: var(--muted); font-size: 13px; }
.cmp-stats { display: flex; gap: 14px; flex-wrap: wrap; }
.cmp-stats b { display: block; font: 600 20px/1.1 var(--serif); color: var(--accent); }
.cmp-stats span { font-size: 11.5px; color: var(--muted); }
.wg .contact { margin: 12px 0 0; }
.wg { container-type: inline-size; }
@container (max-width: 600px) {
  .tlw { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .tlw::before { left: 4px; right: auto; top: 6px; bottom: 6px; width: 1.5px; height: auto; }
  .tlw div { display: grid; grid-template-columns: 9px 46px 1fr; gap: 0 10px; align-items: baseline; padding: 4px 0; }
  .tlw i { grid-column: 1; grid-row: 1; margin: 0; }
  .tlw b { grid-column: 2; grid-row: 1; }
  .tlw strong { grid-column: 3; }
  .tlw span { grid-column: 3; }
}
@container (max-width: 440px) {
  .tiles, .cmp { grid-template-columns: minmax(0, 1fr); }
  .vbars { gap: 4px; }
  .vbar span { font-size: 10px; }
  .wg-head { flex-direction: column; gap: 6px; }
  .wg-callout { text-align: left; display: flex; align-items: baseline; gap: 8px; }
}

/* Composer */
.composer-wrap { padding: 0 24px 14px; }
.composer-wrap > * { max-width: 720px; margin-left: auto; margin-right: auto; }
.composer { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 14px 14px 10px 18px; transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.composer.nudge { animation: nudge .5s ease; }
@keyframes nudge { 30% { box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); } }
/* The suggested question sits behind the textarea as ghost text; typed characters cover it exactly. */
.input-wrap { display: grid; }
.input-wrap > * { grid-area: 1 / 1; font: 16px/1.5 var(--sans); padding: 0; margin: 0; min-height: 24px; white-space: pre-wrap; overflow-wrap: break-word; }
.ghost { color: var(--faint); pointer-events: none; }
.ghost .t { color: transparent; }
.ghost kbd { font: 500 11px/1 var(--sans); color: var(--muted); border: 1px solid var(--line); background: var(--bg); border-radius: 5px; padding: 3px 6px; margin-left: 8px; vertical-align: 2px; }
.composer textarea { width: 100%; border: 0; outline: 0; resize: none; overflow: hidden; background: transparent; color: var(--text); caret-color: var(--accent); }
.composer textarea::placeholder { color: var(--faint); }
.composer-row { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.composer-tools { display: flex; gap: 6px; color: var(--muted); }
.tool { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 9px; padding: 5px 7px; font-size: 12.5px; }
.tool svg { width: 15px; height: 15px; }
.tool.pill { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); background: var(--accent-soft); }
.send { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; transition: opacity .15s, transform .15s; }
.send svg { stroke-width: 2.2; }
.send:disabled { opacity: .35; cursor: default; }
.send:not(:disabled):hover { transform: translateY(-1px); }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 7px 13px; border-radius: 10px; font-size: 13.5px; color: var(--muted); transition: color .15s, border-color .15s; }
.chip:hover { color: var(--text); border-color: var(--faint); }
.app.chatting .chips { display: none; }
.fineprint { text-align: center; color: var(--faint); font-size: 12px; margin: 10px auto 0; }

/* Artifact panel */
.panel { background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.panel[hidden] { display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--line); }
.panel-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.panel-title strong { display: block; font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-title small { color: var(--muted); font-size: 12px; }
.panel-title > div { min-width: 0; }
.panel-icon { color: var(--accent); display: grid; }
.panel-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.tabs { display: flex; background: var(--code-bg); border-radius: 9px; padding: 3px; }
.tab { padding: 4px 10px; border-radius: 7px; font-size: 12.5px; color: var(--muted); }
.tab.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.icon-btn { padding: 6px; border-radius: 8px; display: grid; color: var(--muted); }
.icon-btn:hover { background: var(--code-bg); color: var(--text); }
.panel-body { flex: 1; overflow-y: auto; }
.new-top { display: none; margin-left: auto; }

/* Artifact preview content */
.doc { padding: 34px clamp(20px, 4vw, 44px) 48px; animation: rise .35s ease; }
.doc-eyebrow { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.doc-eyebrow span + span::before { content: '·'; margin-right: 8px; }
.doc h2 { font: 500 clamp(24px, 2.6vw, 30px)/1.18 var(--serif); letter-spacing: -.015em; margin: 10px 0 12px; }
.doc-lede { font: 17px/1.55 var(--serif); color: var(--muted); margin: 0 0 26px; max-width: 60ch; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 28px; }
.stat { border: 1px solid var(--line); border-radius: 12px; padding: 14px 14px 12px; background: var(--bg); animation: rise .4s ease backwards; }
.stat b { display: block; font: 600 26px/1.1 var(--serif); color: var(--accent); letter-spacing: -.02em; margin-bottom: 6px; }
.stat span { font-size: 13px; color: var(--muted); line-height: 1.4; }
.doc h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 500; margin: 0 0 10px; }
.doc ul { margin: 0 0 26px; padding: 0; list-style: none; }
.doc li { position: relative; padding: 0 0 9px 22px; }
.doc li::before { content: ''; position: absolute; left: 4px; top: .6em; width: 7px; height: 7px; border-radius: 2px; background: var(--accent); transform: rotate(45deg); }
.best { border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 12px 12px 0; padding: 14px 18px; margin-bottom: 26px; font: 16px/1.55 var(--serif); }
.best small { display: block; font: 600 11.5px var(--sans); text-transform: uppercase; letter-spacing: .07em; color: var(--accent); margin-bottom: 4px; }
.stack { display: flex; flex-wrap: wrap; gap: 6px; }
.stack span { font: 12px var(--mono); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; color: var(--muted); }

.tl { list-style: none; margin: 0 0 26px; padding: 0; }
.doc .tl li { display: grid; grid-template-columns: 56px 1fr; gap: 14px; padding: 0 0 18px; position: relative; }
.doc .tl li::before { left: 61px; top: 7px; width: 9px; height: 9px; border-radius: 50%; transform: none; }
.doc .tl li::after { content: ''; position: absolute; left: 65px; top: 20px; bottom: 0; width: 1px; background: var(--line); }
.doc .tl li:last-child::after { display: none; }
.tl b { font: 600 14px var(--mono); color: var(--accent); }
.tl div { padding-left: 20px; }
.tl strong { display: block; font-weight: 500; }
.tl span { color: var(--muted); font-size: 13.5px; }

.contact { display: grid; gap: 10px; margin-bottom: 10px; }
.contact a { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); text-decoration: none; background: var(--bg); transition: border-color .15s; }
.contact a:hover { border-color: var(--accent); }
.contact a svg { color: var(--accent); }
.contact a span { color: var(--muted); font-size: 13px; margin-left: auto; }
.contact a.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.contact a.primary svg, .contact a.primary span { color: #fff; }

.code { margin: 0; padding: 22px 24px; font: 12.5px/1.65 var(--mono); background: var(--code-bg); min-height: 100%; white-space: pre-wrap; word-break: break-word; }
.code .k { color: #B0573A; } .code .s { color: #4D7C4A; } .code .n { color: #6A55A8; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .code .k { color: #E89A7C; } :root:not([data-theme="light"]) .code .s { color: #A6C99A; } :root:not([data-theme="light"]) .code .n { color: #B6A4E6; } }

/* Narrow screens */
@media (max-width: 1100px) {
  .app.with-panel { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
  .app.with-panel .sidebar { display: none; }
}
@media (max-width: 860px) {
  .app, .app.with-panel { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .new-top { display: grid; }
  .panel { position: fixed; inset: 0; z-index: 10; animation: slideup .3s ease; }
  @keyframes slideup { from { transform: translateY(24px); opacity: 0; } }
  .thread { padding: 8px 16px 16px; }
  .composer-wrap { padding: 0 16px calc(12px + env(safe-area-inset-bottom)); }
  .model-sub { display: none; }
  .tool:not(.pill) { display: none; }
  .msg-ai { font-size: 16.5px; }
  .welcome { min-height: 30vh; }
  .welcome h1 { flex-direction: column; gap: 12px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
