:root {
  --bg: #1e1e1e; --panel: #262f39; --panel2: #2f3a46; --line: #3a4652;
  --text: #e8eaed; --muted: #9aa4ae; --accent: #abc837; --accent-ink: #1e1e1e;
  --danger: #e5534b; --warn: #e3a33b;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
#app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1 { font-size: 1.3rem; margin: 0; }
h2 { font-size: 1rem; margin: 1.4rem 0 .5rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.err { color: var(--danger); min-height: 1.2em; margin: .4rem 0; }
.pad { padding: 1rem; }
.grow { flex: 1; min-width: 0; }

button { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; padding: .55rem .9rem; cursor: pointer; }
button:active { filter: brightness(1.2); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.big { width: 100%; padding: .9rem; font-size: 1.05rem; }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; }
button.icon { background: none; border: none; font-size: 1.4rem; padding: .2rem .6rem; }
input, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: .6rem .75rem; width: 100%; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row { display: flex; gap: .5rem; align-items: center; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: .6rem; margin-top: .8rem; }
.card { background: var(--panel); border-radius: 14px; padding: .8rem 1rem; margin-bottom: .5rem; }
.badge { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border-radius: 99px; margin-left: .4rem;
  background: var(--panel2); color: var(--muted); vertical-align: middle; }
.badge.on { background: var(--accent); color: var(--accent-ink); }
.badge.warn { background: var(--warn); color: #1e1e1e; }
code.secret { display: block; font-size: 1.1rem; padding: .6rem; background: var(--bg); border-radius: 8px; word-break: break-all; }

/* splash / login */
.splash, .center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem; gap: .6rem; }
.splash img { width: 96px; opacity: .8; }
.login { max-width: 420px; margin: 0 auto; width: 100%; }
.login .logo { width: 88px; border-radius: 20px; }
.login details { width: 100%; margin-top: 1rem; color: var(--muted); }
.login form input { margin: 0; }

/* shell */
main#content { flex: 1; min-height: 0; display: flex; flex-direction: column; }
section.tab { flex: 1; min-height: 0; display: flex; flex-direction: column; }
nav.tabbar { display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
nav.tabbar button { flex: 1; background: none; border: none; border-radius: 0; display: flex; flex-direction: column;
  align-items: center; gap: .1rem; padding: .45rem 0 .5rem; font-size: .75rem; color: var(--muted); }
nav.tabbar button .ico { font-size: 1.3rem; filter: grayscale(1); opacity: .7; }
nav.tabbar button.on { color: var(--accent); }
nav.tabbar button.on .ico { filter: none; opacity: 1; }
header.top { display: flex; align-items: center; gap: .5rem; padding: .7rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
  padding-top: max(.7rem, env(safe-area-inset-top)); }
header.top h1 { flex: 1; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
#toast { position: fixed; left: 50%; bottom: calc(5rem + var(--safe-b)); transform: translateX(-50%); max-width: 90vw;
  background: #000d; color: #fff; padding: .6rem 1rem; border-radius: 10px; z-index: 50; font-size: .9rem; }

/* modal */
.modal { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 40; padding: 1rem; }
.modal .card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: .7rem; padding: 1.2rem; }
.modal h2 { margin: 0; color: var(--text); text-transform: none; font-size: 1.15rem; letter-spacing: 0; }

/* chat: list */
.item { display: block; width: 100%; text-align: left; background: none; border: none; border-bottom: 1px solid var(--line);
  border-radius: 0; padding: .75rem 1rem; }
.item .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* chat: conversation */
.status { color: var(--muted); font-size: .9rem; }
.status.busy { color: var(--accent); }
.status.busy::before { content: ''; display: inline-block; width: .55rem; height: .55rem; border-radius: 50%;
  background: var(--accent); margin-right: .4rem; animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .25; } to { opacity: 1; } }
.msgs { padding: .8rem .7rem 1rem; display: flex; flex-direction: column; gap: .5rem; }
.msg { max-width: 100%; padding: .55rem .8rem; border-radius: 14px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; max-width: 88%; background: var(--accent); color: var(--accent-ink); white-space: pre-wrap; border-bottom-right-radius: 4px; }
.msg.bot { background: var(--panel); border-bottom-left-radius: 4px; }
.msg.live::after { content: '▍'; color: var(--accent); animation: pulse .6s infinite alternate; }
.msg.denied { background: #3a1f1f; border: 1px solid var(--danger); font-size: .9rem; }
.hint { color: var(--warn); font-size: .82rem; margin-top: .3rem; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: .45rem 0; }
.md pre { background: var(--bg); padding: .6rem; border-radius: 8px; overflow-x: auto; font-size: .82rem; }
.md code { font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: .88em; }
.md :not(pre) > code { background: var(--bg); padding: .05rem .3rem; border-radius: 4px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-size: .85rem; }
.md th, .md td { border: 1px solid var(--line); padding: .25rem .5rem; }
.md ul, .md ol { padding-left: 1.3rem; margin: .4rem 0; }
.md h1, .md h2, .md h3 { font-size: 1.05rem; color: var(--text); text-transform: none; letter-spacing: 0; margin: .7rem 0 .3rem; }
details.tool { background: var(--panel); border-left: 3px solid var(--line); border-radius: 8px; font-size: .85rem; }
details.tool summary { padding: .4rem .7rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
details.tool pre { margin: 0; padding: .5rem .7rem; white-space: pre-wrap; word-break: break-word; font-size: .78rem; max-height: 50vh; overflow-y: auto;
  border-top: 1px solid var(--line); font-family: ui-monospace, Menlo, monospace; }
details.tool .hint { padding: .3rem .7rem; }
details.tool.error { border-left-color: var(--warn); }
details.tool.denied { border-left-color: var(--danger); }
details.tool.denied summary { color: var(--danger); }
.note { align-self: center; color: var(--muted); font-size: .78rem; white-space: pre-wrap; text-align: center; }
.note.error { color: var(--danger); }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: .5rem; }
.composer textarea { resize: none; max-height: 160px; border-radius: 18px; }
.composer .send { border-radius: 50%; width: 2.6rem; height: 2.6rem; padding: 0; flex: none; }
.thumbs { display: flex; gap: .4rem; flex-wrap: wrap; }
.thumbs:not(:empty) { margin-bottom: .4rem; }
.thumb { position: relative; }
.thumb img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.thumb button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0; border-radius: 50%; font-size: .8rem; line-height: 1; }
input.code { text-align: center; font-size: 1.5rem; letter-spacing: .15em; text-transform: uppercase; font-family: ui-monospace, Menlo, monospace; }
.login .stack { width: 100%; }

/* downloads */
.chips { display: flex; gap: .4rem; overflow-x: auto; margin: .8rem 0 .2rem; padding-bottom: .2rem; }
.chip { flex: none; border-radius: 99px; padding: .3rem .8rem; font-size: .85rem; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin: .45rem 0 .3rem; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .6s; }
.dl .name, .recent .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl.small .name { font-weight: 400; margin-top: .6rem; }
.card.dl.bad { border-left: 3px solid var(--warn); }
.card.dl .row button { font-size: .85rem; margin-top: .5rem; }
.tiny { font-size: .72rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.right { text-align: right; flex: none; margin-left: .6rem; }
.msgs-list { margin: .4rem 0 0; padding-left: 1.1rem; color: var(--warn); overflow-wrap: anywhere; }
.recent { padding: .5rem 0; border-bottom: 1px solid var(--line); }

.update-banner { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(4.6rem + var(--safe-b)); z-index: 45;
  background: var(--accent); color: var(--accent-ink); border: none; border-radius: 99px; padding: .6rem 1.2rem; font-weight: 600; box-shadow: 0 4px 16px #0008; }
