:root {
  /* Soft black + neon green. Dark only. */
  --bg: #0f1110;
  --bg-side: #0a0c0b;
  --surface: #161a18;
  --surface-2: #1d221f;
  --line: #262d29;
  --text: #e4ece6;
  --muted: #86948b;
  --accent: #39ff88;
  --accent-2: #b6ff3b;
  --accent-ink: #04140a;
  --accent-soft: rgba(57, 255, 136, .11);
  --glow: 0 0 0 1px rgba(57, 255, 136, .35), 0 0 18px rgba(57, 255, 136, .18);
  --gold: #f2d14e;
  --danger: #ff5f6d;
  --user-bubble: #1b2a21;
  --code-bg: #0b0d0c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15.5px/1.6 var(--sans); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 14px; }

/* brand */
.logo { width: 26px; height: 26px; border-radius: 8px; background: url(/favicon.svg) center/cover; display: inline-block; flex: none; }
.logo-xl { width: 44px; height: 44px; border-radius: 13px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 600; letter-spacing: .06em; font-size: 15px; }
.brand b { color: var(--accent); font-weight: 700; }
.brand-lg { font-size: 22px; justify-content: center; }
.brand-lg .logo { width: 36px; height: 36px; border-radius: 11px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 10px; cursor: pointer; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.07); }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; border: 0; background: transparent; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.link-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px 0; }
.link-btn:hover { color: var(--text); text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 32px 26px; box-shadow: var(--shadow); display: grid; gap: 14px; text-align: center; }
.login-card p { margin: 0; }
.field { display: grid; gap: 6px; text-align: left; font-size: 13px; color: var(--muted); }
.field input { padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 15px; }

/* layout */
.app { display: grid; grid-template-columns: 272px 1fr; height: 100%; height: 100dvh; }
.sidebar { background: var(--bg-side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding: 14px 10px 10px; gap: 10px; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 4px; }
.btn-new { justify-content: flex-start; background: transparent; border-color: var(--line); font-weight: 500; }
.btn-new svg { color: var(--accent); }
.search { display: flex; align-items: center; gap: 8px; padding: 0 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.search input { border: 0; background: transparent; outline: none; padding: 8px 0; width: 100%; color: var(--text); font-size: 14px; }
.conv-list { flex: 1; overflow-y: auto; min-height: 0; margin: 0 -4px; padding: 0 4px; }
.conv-group { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 10px 4px; }
.conv { position: relative; display: flex; align-items: center; gap: 6px; border-radius: 9px; }
.conv a { flex: 1; min-width: 0; padding: 7px 10px; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conv:hover, .conv.active { background: var(--surface-2); }
.conv.active a { font-weight: 600; }
.conv .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; margin-left: 10px; flex: none; }
.conv .dot + a { padding-left: 2px; }
.conv-menu { display: none; gap: 2px; padding-right: 4px; }
.conv:hover .conv-menu, .conv.active .conv-menu { display: flex; }
.conv-menu button { width: 26px; height: 26px; }
.conv-menu svg { width: 15px; height: 15px; }
.side-foot { display: flex; justify-content: space-between; align-items: center; padding: 8px 8px 2px; border-top: 1px solid var(--line); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 18px; min-height: 56px; }
.conv-title { flex: 1; min-width: 0; margin: 0; font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-pick select { appearance: none; border: 1px solid var(--line); background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2386948b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") right 8px center/14px no-repeat; padding: 6px 30px 6px 12px; border-radius: 9px; font-size: 13.5px; cursor: pointer; max-width: 46vw; }

.scroller { flex: 1; overflow-y: auto; min-height: 0; scroll-behavior: auto; }
.thread { max-width: 780px; margin: 0 auto; padding: 8px 20px 40px; }
.empty { min-height: 58%; display: grid; place-items: end center; padding: 0 16px 18px; }
.hello { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.hello h2 { font-family: var(--serif); font-weight: 400; font-size: clamp(26px, 4.2vw, 38px); margin: 0; letter-spacing: -.01em; }

/* messages */
.msg { margin: 22px 0; }
.msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.bubble { background: var(--user-bubble); padding: 10px 16px; border-radius: 18px 18px 4px 18px; max-width: min(85%, 640px); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; margin-top: 4px; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions, .msg-asst.last .msg-actions { opacity: 1; }
.msg-actions .icon-btn { width: 30px; height: 30px; }
.msg-actions svg { width: 16px; height: 16px; }
.msg-actions .meta { font-size: 12px; color: var(--muted); align-self: center; margin-left: 6px; }
.edit-box { width: min(100%, 640px); display: grid; gap: 8px; }
.edit-box textarea { width: 100%; min-height: 90px; border: 1px solid var(--accent); border-radius: 14px; padding: 10px 14px; background: var(--surface); resize: vertical; }
.edit-box .row { display: flex; justify-content: flex-end; gap: 8px; }

.msg-asst { display: grid; grid-template-columns: 30px 1fr; gap: 14px; }
.msg-asst > .logo { width: 28px; height: 28px; margin-top: 2px; }
.msg-asst.streaming > .logo { animation: breathe 1.6s ease-in-out infinite; }
.asst-body { min-width: 0; }

.md { 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, .md pre { margin: 0 0 14px; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); font-weight: 600; line-height: 1.3; margin: 22px 0 10px; }
.md h1 { font-size: 1.5em; } .md h2 { font-size: 1.3em; } .md h3 { font-size: 1.12em; }
.md ul, .md ol { padding-left: 1.4em; }
.md li { margin: 3px 0; }
.md blockquote { border-left: 3px solid var(--line); padding: 2px 14px; color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.md img { max-width: 100%; border-radius: 8px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; }
.md pre { position: relative; background: var(--code-bg); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.md pre code { display: block; border: 0; padding: 14px 16px; overflow-x: auto; background: transparent !important; font-size: 13.5px; line-height: 1.55; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--line); font: 12px var(--mono); color: var(--muted); }
.code-head button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font: 12px var(--sans); padding: 3px 8px; border-radius: 6px; }
.code-head button:hover { background: var(--surface-2); color: var(--text); }
.cite { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin: 0 1px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font: 600 11px/1 var(--sans); text-decoration: none; vertical-align: 2px; }
.cite:hover { background: var(--accent); color: var(--accent-ink); }
.caret::after { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-left: 4px; vertical-align: middle; animation: pulse 1s ease-in-out infinite; }

/* thinking + tool steps */
.steps { display: grid; gap: 6px; margin-bottom: 12px; }
.step { border: 1px solid var(--line); border-radius: 11px; background: var(--surface); font-size: 13.5px; overflow: hidden; }
.step > summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 7px 12px; cursor: pointer; color: var(--muted); user-select: none; }
.step > summary::-webkit-details-marker { display: none; }
.step > summary .label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step > summary .label b { color: var(--text); font-weight: 500; }
.step > summary .chev { transition: transform .15s; width: 14px; height: 14px; }
.step[open] > summary .chev { transform: rotate(90deg); }
.step .step-body { padding: 4px 14px 12px 38px; color: var(--muted); max-height: 340px; overflow-y: auto; }
.step.thinking .step-body { white-space: pre-wrap; font-size: 13px; line-height: 1.55; }
.step.running > summary .label { background: linear-gradient(90deg, var(--muted) 30%, var(--text) 50%, var(--muted) 70%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.6s linear infinite; }
.step.failed > summary { color: var(--danger); }
.results { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.results a { color: var(--text); text-decoration: none; display: flex; gap: 8px; align-items: baseline; }
.results a:hover .t { text-decoration: underline; }
.results .n { font: 600 11px var(--sans); color: var(--accent); min-width: 16px; }
.results .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .d { color: var(--muted); font-size: 12px; flex: none; }
.spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }

.sources { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
.sources summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.sources ol { margin: 8px 0 0; padding-left: 1.6em; font-size: 13.5px; display: grid; gap: 3px; }
.sources a { color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.sources a:hover { text-decoration: underline; }
.sources .d { color: var(--muted); font-size: 12px; margin-left: 6px; }
.notice { margin-top: 10px; font-size: 13.5px; color: var(--muted); }
.notice.err { color: var(--danger); background: color-mix(in srgb, var(--danger) 9%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); padding: 8px 12px; border-radius: 10px; }

/* composer */
.composer-wrap { padding: 0 20px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.composer { max-width: 780px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 12px 12px 10px 16px; transition: border-color .15s; }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.composer textarea { width: 100%; border: 0; outline: none; resize: none; background: transparent; max-height: 40vh; line-height: 1.5; padding: 2px 0 6px; font-size: 15.5px; }
.composer-bar { display: flex; align-items: center; gap: 6px; }
.spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.pill svg { width: 15px; height: 15px; }
.pill-static { cursor: default; color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle input:checked + .pill { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.toggle input:focus-visible + .pill { outline: 2px solid var(--accent); outline-offset: 2px; }
.send { width: 36px; height: 36px; border-radius: 11px; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; cursor: pointer; }
.send:disabled { opacity: .35; cursor: default; }
.send .i-stop { display: none; fill: currentColor; stroke: none; }
.send.stop .i-send { display: none; }
.send.stop .i-stop { display: block; }
.send.stop { background: var(--text); color: var(--bg); }
.disclaimer { text-align: center; margin: 7px 0 0; }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); z-index: 50; max-width: calc(100vw - 32px); }

.only-mobile { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 19; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-grid; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 20; transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .app.side-open .sidebar { transform: none; }
  .topbar { padding: 8px 12px; }
  .thread { padding: 4px 16px 32px; }
  .composer-wrap { padding-left: 12px; padding-right: 12px; }
  .msg-asst { grid-template-columns: 1fr; gap: 6px; }
  .msg-asst > .logo { width: 24px; height: 24px; }
  .msg-actions { opacity: 1; }
  .conv-menu { display: flex; }
}


/* neon touches */
::selection { background: rgba(57, 255, 136, .28); }
.brand b { text-shadow: 0 0 12px rgba(57, 255, 136, .55); }
.btn-primary { box-shadow: 0 0 22px rgba(57, 255, 136, .25); }
.send:not(:disabled):not(.stop) { box-shadow: 0 0 16px rgba(57, 255, 136, .35); }
.composer:focus-within { box-shadow: var(--shadow), 0 0 0 1px rgba(57, 255, 136, .28), 0 0 26px rgba(57, 255, 136, .08); }
.hello h2 { background: linear-gradient(90deg, var(--text), var(--accent) 120%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo-xl { box-shadow: 0 0 30px rgba(57, 255, 136, .3); }
.conv.active { box-shadow: inset 2px 0 0 var(--accent); }
.bubble { border: 1px solid rgba(57, 255, 136, .14); }
.md a { color: var(--accent); }
.md strong { color: #f3fff6; }
.md h1, .md h2, .md h3 { color: #f3fff6; }
.md code { color: var(--accent-2); }
.md pre code { color: var(--text); }
body { background: radial-gradient(1200px 600px at 70% -10%, rgba(57, 255, 136, .05), transparent 60%), var(--bg); background-attachment: fixed; }
.scroller::-webkit-scrollbar, .conv-list::-webkit-scrollbar { width: 9px; }
.scroller::-webkit-scrollbar-thumb, .conv-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 9px; border: 2px solid transparent; background-clip: padding-box; }

@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(.88); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
