:root {
  /* black theme with a yellow accent (the colours of Brain); one theme only */
  --bg: #000000; --surface: #0b0b0c; --surface-2: #151516; --surface-3: #1d1d20; --line: #2a2a2e;
  --fg: #ededed; --muted: #9b9ba1; --accent: #f5c518;
  --accent-soft: color-mix(in oklch, #f5c518 11%, #121214); --accent-fg: #0a0800;
  --add: #5fcf8a; --del: #f08a82; --del-bg: #2b1514; --mod: #f0a35e; --mod-bg: #2b1d0e;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --side: 288px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 15px/1.55 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); font-size: 13px; }
.pad { padding: 16px; }
.err { color: var(--del); font-size: 13px; }

body:not([data-ready]) #shell { visibility: hidden; } /* the shell is public: stay blank until the server has confirmed the session, so a logged-out visitor never sees it */
#shell { display: flex; height: 100vh; height: 100dvh; }

/* ---------- sidebar */
#side { width: var(--side); flex: none; display: flex; flex-direction: column; gap: 6px; background: var(--surface); border-right: 1px solid var(--line); padding: calc(10px + env(safe-area-inset-top, 0px)) 10px 10px; min-height: 0; }
.brand { display: flex; align-items: center; gap: 8px; padding: 6px 8px 8px; font-size: 17px; font-weight: 650; }
.brand svg { color: var(--accent); width: 24px; height: 24px; }
#side a { color: var(--fg); text-decoration: none; }
.newchat, #side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; font-weight: 550; }
.newchat { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); color: var(--accent) !important; }
.newchat:hover, #side nav a:hover { background: var(--surface-3); }
.newchat:hover { background: color-mix(in oklch, #f5c518 16%, #121214); }
#side nav a.on { background: var(--surface-3); }
.search input { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); color: var(--fg); font: inherit; font-size: 14px; padding: 8px 12px; }
.clist { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin: 4px -4px 0; padding: 0 4px calc(8px + env(safe-area-inset-bottom, 0px)); }
.grp h3 { margin: 12px 8px 4px; font-size: 11px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.citem { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px 10px; border-radius: 9px; font-size: 14px; }
.citem:hover { background: var(--surface-3); }
.citem.on { background: var(--accent-soft); }
.citem .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.citem .st svg { width: 13px; height: 13px; color: var(--accent); fill: var(--accent); stroke: none; }
.citem .run { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.citem small { flex-basis: 100%; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes pulse { 50% { opacity: .25; } }
#scrim { display: none; }

/* ---------- main */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 8px; flex: none; min-height: calc(48px + env(safe-area-inset-top, 0px)); padding: env(safe-area-inset-top, 0px) 12px 0; border-bottom: 1px solid var(--line); background: var(--surface); }
.ttl { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; line-height: 1.25; }
.title { background: none; border: 0; padding: 4px 6px; margin: 0 -6px; text-align: left; font-size: 16px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: 8px; }
.title:not(.static):not(:disabled):hover { background: var(--surface-3); }
.title:disabled { cursor: default; }
.ttl .sub { font-size: 12px; color: var(--muted); text-decoration: none; padding: 0 0; }
.ttl .sub:hover { color: var(--accent); }
.icon { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: none; border: 0; color: var(--muted); text-decoration: none; flex: none; }
.icon:hover { background: var(--surface-3); color: var(--fg); }
.icon.sm { width: 32px; height: 32px; }
.icon.sm svg { width: 17px; height: 17px; }
.menubtn { display: none; color: var(--fg); }
.badge { font-size: 11px; font-weight: 650; letter-spacing: .04em; padding: 3px 9px; border-radius: 999px; color: var(--muted); background: var(--surface-3); }
.badge.api { background: var(--mod-bg); color: var(--mod); }
.badge.bedrock { background: var(--surface-3); color: var(--muted); }
.scroller { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.dock { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0px)); }

.btn { display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 7px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-size: 14px; font-weight: 550; text-decoration: none; color: var(--fg); }
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary.danger { background: var(--del); border-color: var(--del); }
.btn svg { width: 17px; height: 17px; }

/* ---------- chat log */
.log { max-width: 780px; margin: 0 auto; padding: 18px 16px 24px; display: flex; flex-direction: column; gap: 22px; min-height: 100%; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 40px 0; }
.empty svg { width: 48px; height: 48px; color: var(--accent); stroke-width: 2.3; }
.empty h1 { margin: 12px 0 4px; font-size: 26px; font-weight: 600; color: var(--fg); }
.empty p { margin: 0; }
.msg { position: relative; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.bubble { max-width: min(88%, 640px); background: var(--surface-3); border: 1px solid var(--line); border-radius: 18px 18px 6px 18px; padding: 10px 14px; overflow-wrap: anywhere; }
.bubble .txt { white-space: pre-wrap; }
.bubble textarea.edit { width: min(78vw, 600px); max-width: 100%; border: 0; background: transparent; color: var(--fg); font: inherit; resize: vertical; outline: none; min-height: 60px; }
.edit-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.att { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); color: var(--fg); text-decoration: none; font-size: 13px; max-width: 100%; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att small { color: var(--muted); }
.att.expired { color: var(--muted); border-style: dashed; }
.att.img { padding: 0; border: 0; background: none; }
.att.img img { display: block; max-width: min(100%, 300px); max-height: 240px; border-radius: 12px; border: 1px solid var(--line); }
.acts { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; margin-top: 2px; }
.msg:hover .acts, .msg:focus-within .acts, .msg.last .acts { opacity: 1; }
@media (hover: none) { .acts { opacity: 1; } }
.msg.assistant:not(.lastassistant) [data-act="redo"] { display: none; }
.msg.user.editing .acts { display: none; }
.assistant .tools { display: flex; flex-wrap: wrap; gap: 6px; }
.assistant .tools:not(:empty) { margin-bottom: 8px; }
.tool { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool svg { width: 13px; height: 13px; }
.assistant .err { margin-top: 8px; padding: 8px 12px; background: var(--del-bg); border-radius: 10px; }
.assistant.stopped .err { background: var(--surface-2); color: var(--muted); }
.assistant .meta { margin-top: 6px; font-size: 12px; color: var(--muted); }
.assistant .meta:empty { display: none; }
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- rendered markdown */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .85em; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.2em 0 .5em; line-height: 1.3; }
.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.28em; } .md h3 { font-size: 1.1em; } .md h4 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 .85em; padding-left: 1.5em; }
.md li { margin: .2em 0; }
.md li > p { margin: 0 0 .4em; }
.md blockquote { margin: 0 0 .85em; padding: 2px 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md code { font: .88em var(--mono); background: var(--surface-3); border-radius: 5px; padding: .12em .38em; }
.md pre code { background: none; padding: 0; border-radius: 0; font-size: 13px; }
.codeblock { margin: 0 0 .9em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.codehead { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 4px 12px; font: 12px var(--mono); color: var(--muted); background: var(--surface-3); }
.codehead .copy { display: inline-grid; place-items: center; width: 30px; height: 30px; border: 0; background: none; color: var(--muted); border-radius: 8px; }
.codehead .copy:hover { color: var(--fg); background: var(--surface-2); }
.codehead svg { width: 16px; height: 16px; }
.codeblock pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.codeblock pre code.hljs { background: none; padding: 0; }
.tbl { overflow-x: auto; margin: 0 0 .9em; border: 1px solid var(--line); border-radius: 10px; }
.tbl table { border-collapse: collapse; width: 100%; font-size: 14px; }
.tbl th, .tbl td { padding: 7px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { background: var(--surface-3); font-weight: 650; white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.md .chk { color: var(--muted); }
.md .chk.on { color: var(--accent); }
.md li:has(> .chk), .md li:has(> p > .chk) { list-style: none; margin-left: -1.2em; }
.md-img { max-width: 100%; border-radius: 10px; }
.math.block { display: block; margin: .6em 0 1em; overflow-x: auto; overflow-y: hidden; text-align: center; padding: 2px 0; }
.math-err { color: var(--mod); font-family: var(--mono); }
.mathml-out { margin: .6em 0 1em; overflow-x: auto; text-align: center; }
.mathml-out math { font-size: 1.15em; }
.md math { font-size: 1.05em; }
.svgblock { margin: .4em 0 .6em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.svgblock img { width: 100%; max-width: 560px; max-height: 520px; height: auto; } /* an SVG with only a viewBox fills the width: not wider than 560px, or a small drawing becomes huge */
.svgblock.broken { color: var(--mod); font-size: 13px; }
details.svgsrc { margin: 0 0 .9em; }
details.svgsrc > summary { cursor: pointer; font-size: 12.5px; color: var(--muted); padding: 2px 0; }
details.svgsrc .codeblock { margin-top: 6px; }
.diagram { margin: .4em 0 1em; overflow-x: auto; text-align: center; }
.diagram svg { max-width: 100%; height: auto; stroke-width: initial; fill: initial; }
.sketch, .htmlprev { margin: .4em 0 .6em; }
.sketch-wrap { position: relative; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.sketch-frame { display: block; width: 100%; height: 300px; border: 0; background: var(--surface-2); }
.sketch-frame.html { background: #fff; }
.sketch-pp { position: absolute; right: 8px; top: 8px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 80%, transparent); color: var(--fg); }
.sketch-pp svg { width: 16px; height: 16px; }
.sketch-err { margin-top: 6px; font-size: 13px; color: var(--del); }

/* ---------- composer */
.composer { max-width: 780px; margin: 0 auto; width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 20px; padding: 8px 10px 8px 12px; display: flex; flex-direction: column; gap: 4px; }
.composer:focus-within { border-color: var(--accent); }
.composer.drop { border-color: var(--accent); background: var(--accent-soft); }
.composer textarea { width: 100%; border: 0; background: transparent; color: var(--fg); font: inherit; font-size: 16px; resize: none; outline: none; padding: 6px 2px; max-height: 240px; }
.crow { display: flex; align-items: center; gap: 4px; }
.crow .spacer { flex: 1; }
.model { border: 1px solid var(--line); border-radius: 999px; background: var(--surface-3); color: var(--fg); font: inherit; font-size: 13px; padding: 6px 10px; max-width: 120px; }
.send { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; flex: none; }
.send:disabled { background: var(--surface-3); color: var(--muted); cursor: default; }
.send svg { width: 20px; height: 20px; stroke-width: 2.2; }
.send.stop { background: var(--fg); color: var(--bg); }
.icon-btn.mic { width: 40px; height: 40px; border: 0; background: none; color: var(--muted); border-radius: 50%; display: inline-grid; place-items: center; flex: none; }
.icon-btn.mic:hover { background: var(--surface-3); color: var(--fg); }
.icon-btn.mic.rec { background: var(--accent-soft); color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 2px; }
.chip.file { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-3); border: 1px solid var(--line); border-radius: 10px; padding: 4px 6px 4px 8px; font-size: 13px; max-width: 100%; }
.chip.file img { width: 26px; height: 26px; object-fit: cover; border-radius: 6px; }
.chip.file svg { width: 15px; height: 15px; }
.chip.file .nm { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.file small { color: var(--muted); }
.chip.file .x { border: 0; background: none; color: var(--muted); padding: 2px; display: grid; }
.chip.file .x svg { width: 13px; height: 13px; }

/* ---------- pages (projects, settings) */
.page { max-width: 780px; margin: 0 auto; padding: 18px 16px 40px; display: flex; flex-direction: column; gap: 22px; }
.page .lead { margin: 0; color: var(--muted); }
.page h2 { margin: 0 0 8px; font-size: 13px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.page h2 small, .page h2 select { text-transform: none; letter-spacing: 0; font-weight: 400; }
.page h2 select { margin-left: auto; }
.page section textarea, .page select, .dlg input, .dlg textarea, .dlg select { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); color: var(--fg); font: inherit; font-size: 15px; padding: 10px 12px; }
.page h2 select { width: auto; padding: 4px 8px; font-size: 13px; }
.page section textarea:focus, .dlg input:focus, .dlg textarea:focus { outline: none; border-color: var(--accent); }
.page section textarea { resize: vertical; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.card { display: flex; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--fg); text-decoration: none; }
.card:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.card > svg { color: var(--accent); margin-top: 2px; }
.card b { display: block; }
.card small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; overflow-wrap: anywhere; }
.card small.count { margin-top: 6px; }
.phead h1 { margin: 0; font-size: 24px; cursor: pointer; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.frow, .plink { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); margin-bottom: 6px; color: var(--fg); text-decoration: none; }
.frow .nm, .plink .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frow small, .plink small { color: var(--muted); font-size: 12px; white-space: nowrap; }
.frow > svg, .plink > svg { color: var(--muted); }
.plink:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.card-plain { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.card-plain p { margin: 0 0 8px; }
.card-plain p:last-child { margin-bottom: 0; }
.card-plain code, .page code { font: .88em var(--mono); background: var(--surface-3); padding: .1em .35em; border-radius: 5px; overflow-wrap: anywhere; }
.facts { margin: 8px 0 0; padding-left: 18px; }
.facts .warn { color: var(--mod); }
.copyline { display: flex; align-items: center; gap: 6px; margin: 6px 0; }
.copyline code { flex: 1; min-width: 0; padding: 8px 10px; }

/* ---------- dialog, menu, toast, banner */
.dlg { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--fg); padding: 0; width: min(440px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(0, 0, 0, .65); }
.dlg form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { margin: 0; font-size: 17px; }
.dlg p { margin: 0; color: var(--muted); font-size: 14px; }
.dlg label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.dlg textarea { min-height: 200px; font-family: var(--mono); font-size: 13px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.menu { position: fixed; z-index: 60; min-width: 220px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; box-shadow: 0 10px 30px rgba(0, 0, 0, .6); }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: none; border-radius: 8px; text-align: left; font-size: 14px; }
.menu button:hover { background: var(--surface-3); }
.menu button.danger { color: var(--del); }
.menu svg { width: 17px; height: 17px; color: var(--muted); }
.menu button.danger svg { color: var(--del); }
#toast { position: fixed; z-index: 70; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--surface-3); border: 1px solid var(--line); border-radius: 12px; padding: 9px 16px; font-size: 14px; max-width: calc(100vw - 32px); transition: opacity .15s, transform .15s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--del-bg); color: var(--del); border-color: transparent; }
.update-banner { position: fixed; z-index: 80; top: env(safe-area-inset-top, 0px); left: 0; right: 0; border: 0; padding: 10px 16px; background: var(--accent); color: var(--accent-fg); font-size: 15px; cursor: pointer; }

/* ---------- phone: the sidebar becomes a drawer */
@media (max-width: 820px) {
  #side { position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(86vw, 330px); transform: translateX(-102%); transition: transform .2s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .7); }
  body.nav-open #side { transform: none; }
  body.nav-open #scrim { display: block; position: fixed; z-index: 30; inset: 0; background: rgba(0, 0, 0, .6); }
  .menubtn { display: inline-grid; }
  .log { padding-top: 14px; }
  .bubble { max-width: 94%; }
  .model { max-width: 96px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
