:root {
  color-scheme: light dark;
  --bg: #f6f3ee; --surface: #ffffff; --soft: #efebe4; --line: #e0dacf;
  --fg: #26232b; --muted: #77707f; --accent: #7a55b0; --accent-fg: #ffffff; --accent-soft: #ece4f6;
  --user: #e9e2f3; --danger: #b3261e;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  --sidebar: 280px; --panel: min(46vw, 640px); --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17151a; --surface: #201d25; --soft: #29252f; --line: #36313d;
    --fg: #ece8f1; --muted: #9b94a5; --accent: #b79be0; --accent-fg: #1b1524; --accent-soft: #332a43;
    --user: #34293f; --danger: #f2b8b5; --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 20px rgb(0 0 0 / 25%);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
a { color: var(--accent); }

.btn { display: inline-block; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 10px 22px; text-decoration: none; color: var(--fg); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
.icon { border: 0; background: transparent; width: 38px; height: 38px; border-radius: 10px; display: inline-grid; place-items: center; color: var(--muted); text-decoration: none; font-size: 18px; }
.icon:hover { background: var(--soft); color: var(--fg); }
.link { border: 0; background: none; color: var(--muted); text-decoration: underline; padding: 0; font-size: .9rem; }
.fine { color: var(--muted); font-size: .8rem; margin: 6px 0 0; text-align: center; }
.pill { font-size: .75rem; padding: 2px 10px; border-radius: 999px; background: var(--soft); color: var(--muted); }

/* ---- login ---- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { text-align: center; max-width: 360px; width: 100%; background: var(--surface); border-radius: 20px; padding: 36px 24px; box-shadow: var(--shadow); }
.login-card img { image-rendering: pixelated; }
.login-card h1 { margin: 10px 0 2px; font-size: 1.5rem; }
.login-card p { color: var(--muted); margin: 0 0 22px; }

/* ---- layout ---- */
.app { height: 100dvh; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.app.has-panel { grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--panel); }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 14px 12px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; padding: 4px 6px 8px; }
.brand img { image-rendering: pixelated; border-radius: 8px; }
.search input { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 12px; }
.label { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 14px 8px 2px; font-weight: 600; }
.list { display: flex; flex-direction: column; gap: 2px; }
.item { display: flex; align-items: center; gap: 10px; text-align: left; width: 100%; border: 0; background: transparent; border-radius: 10px; padding: 8px 10px; color: var(--fg); }
.item:hover { background: var(--soft); }
.item.active { background: var(--accent-soft); }
.item small { margin-left: auto; color: var(--muted); font-size: .72rem; }
.item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.item span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--muted); font-size: .85rem; padding: 4px 10px; }
.results { display: flex; flex-direction: column; gap: 2px; }
.result { text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 10px; color: var(--fg); }
.result:hover { background: var(--soft); }
.result b { display: block; font-size: .75rem; color: var(--muted); font-weight: 600; }
.result span { font-size: .88rem; display: block; overflow-wrap: anywhere; }
.result mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 2px; }
.side-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; padding: 10px 6px 2px; color: var(--muted); font-size: .9rem; }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.top { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.top h1 { font-size: 1.05rem; margin: 0; font-weight: 650; }
.top #menu { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 18px 16px 8px; scroll-behavior: smooth; overscroll-behavior: contain; }
.messages > * { max-width: 48rem; margin-left: auto; margin-right: auto; }
.day { text-align: center; color: var(--muted); font-size: .75rem; margin: 16px 0 8px; }
.more { display: block; margin: 0 auto 12px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; color: var(--muted); font-size: .85rem; }

.msg { display: flex; gap: 10px; margin: 14px auto; align-items: flex-start; }
.msg.me { flex-direction: row-reverse; }
.avatar { width: 36px; height: 36px; flex: none; border-radius: 10px; background: var(--soft); image-rendering: pixelated; object-fit: cover; }
.col { min-width: 0; max-width: calc(100% - 50px); display: flex; flex-direction: column; gap: 6px; }
.msg.me .col { align-items: flex-end; }
.who { font-size: .75rem; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.badge { font-size: .65rem; padding: 0 7px; border-radius: 999px; background: var(--soft); color: var(--muted); }
.bubble { overflow-wrap: anywhere; }
.msg.me .bubble { background: var(--user); padding: 9px 14px; border-radius: var(--radius) var(--radius) 4px var(--radius); }
.msg.bot .bubble { padding: 2px 2px; }
.bubble p { margin: 0 0 .7em; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 .7em; padding-left: 1.4em; }
.bubble h3, .bubble h4, .bubble h5 { margin: .9em 0 .3em; font-size: 1rem; }
.bubble blockquote { margin: 0 0 .7em; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.bubble hr { border: 0; border-top: 1px solid var(--line); }
.bubble code { background: var(--soft); border-radius: 5px; padding: 1px 5px; font: .88em ui-monospace, Menlo, Consolas, monospace; }
.bubble pre { position: relative; background: var(--soft); border-radius: 10px; padding: 12px; overflow-x: auto; margin: 0 0 .7em; }
.bubble pre code { background: none; padding: 0; }
.copy { position: absolute; top: 6px; right: 6px; border: 0; background: var(--surface); color: var(--muted); border-radius: 6px; font-size: .72rem; padding: 2px 8px; opacity: 0; }
.bubble pre:hover .copy, .copy:focus-visible { opacity: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: .74rem; color: var(--muted); background: var(--soft); border-radius: 999px; padding: 2px 10px; }
.card { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 360px; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); }
.card:hover { border-color: var(--accent); }
.card .kind { font-size: .72rem; color: var(--muted); display: block; }
.actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.msg:hover .actions, .msg:focus-within .actions { opacity: 1; }
.actions button { border: 0; background: transparent; color: var(--muted); font-size: .75rem; padding: 2px 6px; border-radius: 6px; }
.actions button:hover { background: var(--soft); color: var(--fg); }
.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
.thinking .bubble { color: var(--muted); }
.shimmer { display: inline-block; background: linear-gradient(90deg, var(--muted) 20%, var(--fg) 50%, var(--muted) 80%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shim 1.4s linear infinite; }
@keyframes shim { to { background-position: -200% 0; } }
.error { color: var(--danger); }

.composer { padding: 6px 16px calc(12px + env(safe-area-inset-bottom)); }
.composer .box { max-width: 48rem; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 8px 8px 8px 16px; box-shadow: var(--shadow); }
.composer textarea { flex: 1; border: 0; background: transparent; resize: none; outline: none; max-height: 11rem; padding: 6px 0; line-height: 1.45; }
.send { width: 38px; height: 38px; flex: none; border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-fg); font-size: 20px; line-height: 1; }
.send:disabled { opacity: .4; cursor: default; }

/* ---- artifact panel ---- */
.panel { background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.panel header { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.panel h2 { flex: 1; margin: 0; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel iframe { flex: 1; width: 100%; border: 0; background: var(--bg); }

.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 40%); z-index: 20; }

/* ---- phone and narrow windows ---- */
@media (max-width: 1100px) {
  .app.has-panel { grid-template-columns: var(--sidebar) minmax(0, 1fr); }
  .panel { position: fixed; inset: 0 0 0 auto; width: min(100%, 560px); z-index: 30; box-shadow: var(--shadow); }
}
@media (max-width: 760px) {
  .app, .app.has-panel { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 25; transform: translateX(-102%); transition: transform .2s; padding-top: calc(14px + env(safe-area-inset-top)); }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .top #menu { display: inline-grid; }
  .panel { width: 100%; }
  .messages { padding-inline: 12px; }
  .composer { padding-inline: 12px; }
  .composer #composer-note { display: none; }
  .actions { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---- header tools, composer extras ---- */
.top .tools { margin-left: auto; display: flex; gap: 2px; }
.box .icon { width: 34px; height: 34px; flex: none; }
.box .icon.on { color: var(--accent); background: var(--accent-soft); }
.related { max-width: 48rem; margin: 0 auto 6px; display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.related button { flex: none; max-width: 16rem; border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 3px 12px; font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.related button:hover { border-color: var(--accent); color: var(--fg); }
.quick button { color: var(--fg); background: var(--soft); border-color: transparent; }
.quick button:hover { background: var(--accent-soft); }
.related b { color: var(--accent); font-weight: 600; margin-right: 6px; }
.thumbs { max-width: 48rem; margin: 0 auto 6px; display: flex; gap: 8px; flex-wrap: wrap; }
.thumb { position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border: 0; border-radius: 50%; background: rgb(0 0 0 / 60%); color: #fff; font-size: 12px; line-height: 1; }
.composer.drag .box { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- media in messages ---- */
.media { display: flex; flex-wrap: wrap; gap: 8px; }
.media img, .media video { max-width: min(100%, 420px); max-height: 320px; border-radius: 12px; display: block; background: var(--soft); cursor: zoom-in; }
.media video { cursor: default; }
.msg.me .media { justify-content: flex-end; }

/* ---- dialogs ---- */
.dlg { border: 0; border-radius: 18px; padding: 0; background: var(--surface); color: var(--fg); width: min(92vw, 560px); max-height: 86dvh; box-shadow: var(--shadow); }
.dlg::backdrop { background: rgb(0 0 0 / 50%); }
.dlg > header { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--line); }
.dlg h2 { margin: 0; font-size: 1.05rem; }
.dlg h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 0 8px; }
.dlg-body { padding: 16px 20px 22px; overflow-y: auto; max-height: calc(86dvh - 60px); }
.dlg.wide { width: auto; max-width: 96vw; background: transparent; box-shadow: none; overflow: visible; }
.dlg.wide img { max-width: 94vw; max-height: 88dvh; border-radius: 12px; display: block; }
.dlg.wide .close { position: absolute; top: -8px; right: -8px; background: var(--surface); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row select { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 10px; }
.keys { list-style: none; padding: 0; margin: 0; color: var(--muted); font-size: .9rem; display: grid; gap: 6px; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 6px; font: .8em ui-monospace, Menlo, Consolas, monospace; background: var(--bg); }

/* ---- her mind ---- */
.bar { display: grid; grid-template-columns: 7.5rem 1fr 3rem; gap: 10px; align-items: center; margin: 7px 0; font-size: .9rem; }
.bar .track { height: 8px; border-radius: 99px; background: var(--soft); position: relative; }
.bar .fill { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--accent); }
.bar .base { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--fg); opacity: .5; border-radius: 2px; }
.bar small { color: var(--muted); text-align: right; }
.bar .ends { grid-column: 2; display: flex; justify-content: space-between; color: var(--muted); font-size: .7rem; margin-top: -2px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { background: var(--accent-soft); border-radius: 99px; padding: 2px 12px; font-size: .85rem; }
.log { margin: 0; padding-left: 18px; color: var(--muted); font-size: .88rem; }
.notes { font-size: .92rem; }

/* ---- usage ---- */
.big { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.stats { display: flex; gap: 28px; flex-wrap: wrap; margin-bottom: 14px; }
.stats small { display: block; color: var(--muted); }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 8px; }
.chart div { flex: 1; min-width: 3px; background: var(--accent); border-radius: 3px 3px 0 0; opacity: .85; }
.chart div:hover { opacity: 1; }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: .72rem; margin-top: 4px; }

/* ---- themes (the settings can override the device) ---- */
:root[data-theme="light"] { color-scheme: light; --bg: #f6f3ee; --surface: #ffffff; --soft: #efebe4; --line: #e0dacf; --fg: #26232b; --muted: #77707f; --accent: #7a55b0; --accent-fg: #ffffff; --accent-soft: #ece4f6; --user: #e9e2f3; --danger: #b3261e; }
:root[data-theme="dark"] { color-scheme: dark; --bg: #17151a; --surface: #201d25; --soft: #29252f; --line: #36313d; --fg: #ece8f1; --muted: #9b94a5; --accent: #b79be0; --accent-fg: #1b1524; --accent-soft: #332a43; --user: #34293f; --danger: #f2b8b5; }
:root[data-size="s"] body { font-size: 14.5px; }
:root[data-size="l"] body { font-size: 18px; }
