/* CodelyTeam
   Warm paper, a reading serif for the AI's voice, one clay accent. Flat surfaces, hairline borders, no gradients.
   Light is the default; dark is a warm charcoal, not blue-black. */

:root {
  color-scheme: light;
  --bg: #faf9f5;          /* paper */
  --side: #f3f1ea;        /* sidebar, a step darker than the page */
  --surface: #ffffff;     /* cards, composer */
  --raised: #f0eee6;      /* user bubbles, tiles */
  --sunk: #f6f4ed;        /* code, inputs */
  --line: #e8e5da;
  --line-2: #d8d4c5;
  --hover: rgba(31, 30, 29, .055);
  --active: rgba(31, 30, 29, .09);
  --text: #1f1e1d;
  --muted: #6c6a63;
  --faint: #9b988d;
  --accent: #c4623f;      /* clay */
  --accent-2: #a94f30;
  --accent-ink: #ffffff;
  --accent-soft: #f6e5dc;
  --coin: #8f6410; --coin-soft: #f6ebcf;
  --danger: #b1382c; --danger-soft: #f7e3df;
  --info: #3b6890; --info-soft: #e3edf4;
  --shadow: 0 1px 2px rgba(31, 30, 29, .04), 0 6px 20px rgba(31, 30, 29, .05);
  --shadow-up: 0 2px 4px rgba(31, 30, 29, .04), 0 10px 32px rgba(31, 30, 29, .08);
  --r: 14px; --r-sm: 10px; --r-lg: 20px;
  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --side-w: 288px;
  --read: 760px;          /* the width of a conversation */
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1f1e1c; --side: #1a1917; --surface: #292826; --raised: #33312e; --sunk: #232220;
  --line: #36342f; --line-2: #48453f;
  --hover: rgba(255, 255, 255, .05); --active: rgba(255, 255, 255, .09);
  --text: #ece9e0; --muted: #a29f94; --faint: #6f6c63;
  --accent: #d9774f; --accent-2: #e58a64; --accent-ink: #1f1e1c; --accent-soft: #3b2b23;
  --coin: #e6b449; --coin-soft: #38301a;
  --danger: #ee8173; --danger-soft: #3c2320; --info: #8fb4d3; --info-soft: #1f2c38;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  --shadow-up: 0 2px 4px rgba(0, 0, 0, .3), 0 10px 32px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.55; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; overflow-x: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-2); text-underline-offset: 3px; }
code, pre, .mono { font-family: var(--mono); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-soft); color: var(--text); }
.ico, .ic { display: inline-flex; flex: none; align-items: center; justify-content: center; }
.ic { width: 1em; height: 1em; }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 12px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: content-box; border: 3px solid transparent; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-sm);
  font-weight: 600; font-size: .94rem; text-decoration: none; color: var(--text); white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--raised); }
.btn:active { background: var(--active); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); background: transparent; border-color: var(--line-2); }
.btn.danger:hover { background: var(--danger-soft); border-color: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.icon { width: 40px; padding: 0; }
.btn.sm { min-height: 32px; padding: 0 12px; font-size: .86rem; border-radius: 8px; gap: 6px; }
.btn.sm.icon { width: 32px; }
.btn.lg { min-height: 50px; padding: 0 26px; font-size: 1.02rem; border-radius: 12px; }
.btn.block { width: 100%; }

/* ---------- avatar ---------- */
.avatar { --s: 40px; display: inline-block; width: var(--s); height: var(--s); flex: none; border-radius: 50%; overflow: hidden; vertical-align: middle; }
.avatar svg { display: block; width: 100%; height: 100%; }
.avatar .eyes { transform-box: fill-box; transform-origin: center; animation: eye-blink 6s infinite; }
@keyframes eye-blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); height: 100%; height: 100dvh; }
.sidebar { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding: 16px 12px; gap: 16px; overflow-y: auto; }
.scrim { display: none; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.topbar { display: flex; align-items: center; gap: 10px; height: 54px; padding: 0 20px; flex: none; }
.topbar .ttl { font-family: var(--serif); font-weight: 500; font-size: 1.1rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#menu-btn { display: none; }
.view { flex: 1; min-height: 0; overflow-y: auto; }
.loading { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 60px 20px; color: var(--muted); }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.spinner.sm { width: 13px; height: 13px; border-width: 2px; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.sb-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--serif); font-weight: 600; font-size: 1.3rem; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: url("/logo.png") center / cover no-repeat, var(--raised); border: 1px solid var(--line-2); }
.sb-close { display: none; }

.wallet-card { display: flex; align-items: center; gap: 8px; }
.coin-pill { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 14px 0 10px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--surface); color: var(--text); font-weight: 600; flex: 1; transition: background .15s; }
.coin-pill:hover { background: var(--raised); }
.coin-ico { display: inline-flex; color: var(--coin); }
.coin-amt { font-size: 1rem; font-variant-numeric: tabular-nums; }
.coin-dot { position: absolute; top: 2px; right: 4px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); border: 2px solid var(--side); }
.topbar-coins .coin-pill { flex: none; }

.sb-title-row { display: flex; align-items: center; justify-content: space-between; padding: 0 8px; }
.sb-title { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .86rem; font-weight: 600; }
.counter { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ai-list { display: flex; flex-direction: column; gap: 2px; min-height: 60px; }
.ai-item { display: flex; align-items: center; gap: 12px; padding: 7px 8px; border-radius: var(--r-sm); color: var(--text); text-decoration: none; font-weight: 500; }
.ai-item .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-item .ico { color: var(--faint); }
.ai-item:hover { background: var(--hover); }
.ai-item.active { background: var(--active); font-weight: 600; }
.ai-item.active .ico { color: var(--accent); }
.list-empty { display: flex; align-items: center; gap: 10px; padding: 14px; color: var(--muted); border: 1px dashed var(--line-2); border-radius: var(--r-sm); font-size: .94rem; }
.sb-links { display: flex; flex-direction: column; gap: 2px; margin-top: auto; }
.side-link { display: flex; align-items: center; gap: 12px; padding: 9px 8px; border-radius: var(--r-sm); background: none; border: 0; color: var(--text); text-decoration: none; font-weight: 500; width: 100%; text-align: left; }
.side-link:hover { background: var(--hover); }
.side-link .ico { color: var(--muted); }
.side-link .tag { margin-left: auto; font-size: .72rem; font-weight: 600; color: var(--accent-2); background: var(--accent-soft); border-radius: 999px; padding: 2px 8px; }
.limit-note { display: flex; gap: 8px; align-items: center; font-size: .86rem; color: var(--muted); padding: 10px; border: 1px dashed var(--line-2); border-radius: var(--r-sm); }
.sb-foot { display: flex; align-items: center; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.user-dot { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 600; flex: none; }
.user-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- pages ---------- */
.page { max-width: 1040px; margin: 0 auto; padding: 36px 28px 64px; }
.page-head h1 { margin: 0 0 6px; font-family: var(--serif); font-weight: 500; font-size: clamp(2rem, 3.4vw, 2.7rem); line-height: 1.1; letter-spacing: -.02em; }
.page-head p { margin: 0 0 26px; color: var(--muted); font-size: 1.04rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 28px; }
.stat { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center; text-align: left; padding: 14px 16px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); }
.stat .ico { grid-row: span 2; width: 40px; height: 40px; border-radius: 10px; background: var(--raised); color: var(--muted); }
.stat b { font-family: var(--serif); font-weight: 500; font-size: 1.5rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span:not(.ico) { color: var(--muted); font-size: .86rem; }
button.stat { cursor: pointer; transition: border-color .15s; }
button.stat:hover { border-color: var(--line-2); background: var(--raised); }
button.stat .ico { background: var(--coin-soft); color: var(--coin); }
.ai-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.ai-card { display: flex; flex-direction: column; gap: 6px; padding: 20px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); color: var(--text); text-decoration: none; transition: border-color .15s, box-shadow .15s; }
.ai-card:hover { border-color: var(--line-2); box-shadow: var(--shadow); }
.ai-card .nm { font-family: var(--serif); font-size: 1.3rem; font-weight: 500; margin-top: 8px; }
.ai-card .sub { color: var(--muted); font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.8em; }
.ai-card .open { display: inline-flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--accent-2); font-weight: 600; font-size: .9rem; }
.ai-card.new { align-items: center; justify-content: center; border-style: dashed; border-color: var(--line-2); background: transparent; min-height: 200px; }
.ai-card.new:hover { background: var(--hover); box-shadow: none; }
.plus-ring { width: 56px; height: 56px; border-radius: 50%; border: 1.5px solid var(--line-2); color: var(--muted); display: grid; place-items: center; }

.empty { max-width: 520px; margin: 64px auto; text-align: center; padding: 20px; }
.empty h2 { font-family: var(--serif); font-weight: 500; font-size: 2rem; line-height: 1.15; letter-spacing: -.02em; margin: 16px 0 8px; }
.empty p { color: var(--muted); margin: 0 0 22px; font-size: 1.05rem; }
.big-ico { color: var(--faint); }
.float { display: inline-block; }
.perks { list-style: none; padding: 0; margin: 0 0 26px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.perks li { display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-weight: 500; font-size: .9rem; }
.perks .ico { color: var(--accent); }

/* ---------- editor ---------- */
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; }
.steps { display: flex; flex-direction: column; gap: 16px; }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px; }
.step h3 { margin: 0 0 14px; display: flex; align-items: center; gap: 12px; font-family: var(--serif); font-weight: 500; font-size: 1.2rem; }
.step-num { width: 30px; height: 30px; border-radius: 50%; background: var(--raised); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.avatar-opt { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px 8px; border-radius: var(--r); border: 1.5px solid var(--line); background: var(--bg); transition: border-color .15s, background .15s; }
.avatar-opt:hover { border-color: var(--line-2); background: var(--raised); }
.avatar-opt[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.avatar-opt .ao-label { font-size: .8rem; font-weight: 500; color: var(--muted); }
.avatar-opt[aria-checked="true"] .ao-label { color: var(--accent-2); }
.avatar-opt.bounce .avatar { animation: pop .35s; }
@keyframes pop { 40% { transform: scale(1.12); } }
.field input, .field textarea, .auth-card input {
  width: 100%; padding: 11px 14px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { min-height: 150px; resize: vertical; line-height: 1.5; }
.field input:focus, .field textarea:focus, .auth-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
::placeholder { color: var(--faint); }
.hint { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; color: var(--muted); font-size: .84rem; }
.preview { position: sticky; top: 20px; }
.preview-label { margin: 0 0 8px; font-size: .86rem; font-weight: 600; color: var(--muted); }
.preview-card { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 30px 20px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); text-align: center; }
.preview-card .nm { font-family: var(--serif); font-size: 1.45rem; font-weight: 500; word-break: break-word; }
.preview-card .on, .status { display: inline-flex; align-items: center; gap: 7px; font-size: .86rem; color: var(--muted); }
.online { width: 8px; height: 8px; border-radius: 50%; background: #5a9a62; box-shadow: 0 0 0 3px rgba(90, 154, 98, .18); }
.form-error { color: var(--danger); font-weight: 500; min-height: 1.4em; margin: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- dialogs & toasts ---------- */
dialog { border: 1px solid var(--line-2); background: var(--surface); color: var(--text); border-radius: var(--r-lg); padding: 0; box-shadow: var(--shadow-up); }
dialog::backdrop { background: rgba(31, 30, 29, .45); backdrop-filter: blur(3px); }
dialog.modal { width: min(440px, calc(100vw - 32px)); padding: 26px; animation: settle .2s; }
.modal h3 { margin: 12px 0 8px; font-family: var(--serif); font-weight: 500; font-size: 1.4rem; }
.modal p { color: var(--muted); margin: 0 0 18px; }
.modal .actions { justify-content: flex-end; margin-top: 16px; }
.modal-ico { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-2); }
.modal-ico.danger { background: var(--danger-soft); color: var(--danger); }
dialog.lightbox { background: transparent; border: 0; box-shadow: none; max-width: 94vw; max-height: 94vh; }
.lightbox img { max-width: 94vw; max-height: 90vh; border-radius: var(--r); display: block; }
.toasts { position: fixed; z-index: 99; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 24px)); pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--r-sm); background: var(--text); color: var(--bg); font-weight: 500; box-shadow: var(--shadow-up); animation: settle .2s; }
.toast .ico { color: var(--accent-2); }
.toast.err { background: var(--danger); color: #fff; } .toast.err .ico { color: #fff; }
@keyframes settle { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* wallet + storage dialogs */
.wallet-top { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.wallet-coin { width: 60px; height: 60px; border-radius: 50%; background: var(--coin-soft); color: var(--coin); display: grid; place-items: center; }
.wallet-bal { font-family: var(--serif); font-size: 2.6rem; font-weight: 500; line-height: 1; font-variant-numeric: tabular-nums; }
.wallet-lbl { color: var(--muted); }
.wallet-note, .note { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: var(--r-sm); background: var(--raised); color: var(--muted); font-size: .92rem; margin: 0 0 14px; }
.wallet-note b { color: var(--text); }
.wallet h4 { margin: 20px 0 8px; font-size: .88rem; font-weight: 600; color: var(--muted); }
.ledger { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
.ledger li { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: .92rem; }
.ledger .lg-ico { color: var(--muted); } .ledger .lg-time { color: var(--faint); font-size: .8rem; }
.ledger .lg-amt { font-weight: 600; font-family: var(--mono); font-size: .88rem; min-width: 48px; text-align: right; }
.lg-amt.pos { color: #4b8a53; } .lg-amt.neg { color: var(--danger); }
.ledger-empty { display: block !important; color: var(--muted); text-align: center; padding: 18px 0 !important; }
.meter { height: 8px; border-radius: 999px; background: var(--raised); overflow: hidden; margin: 6px 0; }
.meter-bar { height: 100%; min-width: 4px; background: var(--accent); border-radius: 999px; }
.meter-row { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: .86rem; margin-bottom: 14px; }
dialog.storage { width: min(480px, calc(100vw - 32px)); }

/* ---------- chat ---------- */
.chat { position: relative; display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px 12px; border-bottom: 1px solid var(--line); flex: none; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; }
.who .avatar { --s: 40px !important; }
.who .nm { font-family: var(--serif); font-weight: 500; font-size: 1.2rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .status { gap: 8px; }
.cost-tag { display: inline-flex; align-items: center; gap: 5px; margin-left: 6px; padding: 0 8px; border-radius: 999px; background: var(--coin-soft); color: var(--coin); font-size: .76rem; font-weight: 600; }
.head-actions { display: flex; gap: 6px; flex: none; }
.head-actions .btn { min-height: 34px; padding: 0 12px; font-size: .88rem; background: transparent; border-color: transparent; color: var(--muted); }
.head-actions .btn:hover { background: var(--hover); color: var(--text); }
.head-actions .btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 28px 20px 12px; display: flex; flex-direction: column; gap: 26px; scroll-behavior: smooth; }
.msg { display: flex; gap: 14px; max-width: var(--read); width: 100%; margin: 0 auto; animation: settle .25s both; }
.msg.user { justify-content: flex-end; }
.msg-avatar { align-self: flex-start; margin-top: 2px; }
.msg-avatar .avatar { --s: 30px !important; }
.bubble { position: relative; min-width: 0; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--raised); color: var(--text); padding: 10px 16px; border-radius: 18px; white-space: pre-wrap; max-width: min(100%, 560px); }
.msg.model .bubble { flex: 1 1 auto; padding: 0; background: none; border: 0; font-family: var(--serif); font-size: 1.1rem; line-height: 1.65; }
.bubble .time { display: block; margin-top: 6px; text-align: right; font-family: var(--font); font-size: .72rem; color: var(--faint); }
.msg.model .bubble .time { text-align: left; opacity: 0; transition: opacity .15s; }
.msg.model:hover .bubble .time { opacity: 1; }
.msg.typing .bubble { display: flex; gap: 5px; padding: 10px 0; flex: none; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); animation: dot 1.1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { transform: none; opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }
.msg-error .bubble { padding: 12px 14px; border-radius: var(--r); background: var(--danger-soft); font-family: var(--font); font-size: .96rem; }
.msg-error .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--danger); font-weight: 500; }
.chat-empty { margin: auto; text-align: center; max-width: 480px; padding: 20px; }
.chat-empty h3 { font-family: var(--serif); font-weight: 500; font-size: 2rem; line-height: 1.15; letter-spacing: -.02em; margin: 16px 0 8px; }
.chat-empty p { color: var(--muted); margin: 0 0 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip-btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); font-weight: 500; font-size: .88rem; transition: background .15s; }
.chip-btn:hover { background: var(--raised); }

/* composer */
.composer { flex: none; padding: 8px 20px 18px; }
.composer > * { max-width: var(--read); margin-left: auto; margin-right: auto; }
.input-row { display: flex; align-items: flex-end; gap: 6px; padding: 8px; border: 1px solid var(--line-2); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; }
.input-row:focus-within { border-color: var(--accent); box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft); }
.input-row textarea { flex: 1; min-width: 0; resize: none; border: 0; background: transparent; padding: 9px 6px; max-height: 180px; outline: none; line-height: 1.5; }
.input-row .btn.icon { border-radius: 14px; border-color: transparent; background: transparent; color: var(--muted); }
.input-row .btn.icon:hover { background: var(--hover); color: var(--text); }
.send { border-radius: 14px; min-height: 40px; padding: 0 14px; gap: 10px; }
.input-row .send { background: var(--accent); color: var(--accent-ink); }
.input-row .send:hover { background: var(--accent-2); }
.send-cost { display: inline-flex; align-items: center; gap: 3px; font-size: .78rem; font-weight: 600; opacity: .85; }
.coin-banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-bottom: 8px; border-radius: var(--r-sm); background: var(--coin-soft); color: var(--coin); font-weight: 500; font-size: .92rem; }
.coin-banner span { flex: 1; }
.tray { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.chip { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 12px 12px; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line-2); overflow: hidden; }
.chip-ico { width: 38px; height: 38px; border-radius: 10px; background: var(--raised); display: grid; place-items: center; color: var(--muted); flex: none; }
.chip-main { flex: 1; min-width: 0; }
.chip-top { display: flex; gap: 10px; align-items: baseline; }
.chip .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .sz { color: var(--muted); font-size: .78rem; font-family: var(--mono); flex: none; }
.chip-status { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.chip.ok .chip-status { color: #4b8a53; } .chip.busy .chip-status { color: var(--info); } .chip.bad .chip-status { color: var(--danger); } .chip.dev .chip-status { color: var(--coin); }
.chip > button { width: 28px; height: 28px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; }
.chip > button:hover { background: var(--danger-soft); color: var(--danger); }
.prog { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); transition: width .15s; }
.chip.busy .prog { background: var(--info); }
.drop-hint { position: absolute; inset: 10px; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; border: 2px dashed var(--accent); border-radius: var(--r-lg); background: var(--bg); opacity: .96; color: var(--accent-2); font-size: 1.1rem; pointer-events: none; }
.drop-hint span { color: var(--muted); font-size: .92rem; }
.model-row { display: flex; align-items: center; gap: 6px; padding: 8px 8px 0; color: var(--faint); }
.model-sel { border: 0; background: transparent; color: var(--muted); border-radius: 8px; padding: 4px 6px; font-size: .84rem; font-weight: 500; max-width: 100%; cursor: pointer; }
.model-sel:hover { background: var(--hover); color: var(--text); }

/* attachments in messages */
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.att-slot { position: relative; max-width: 100%; }
.att-img { display: block; max-width: min(320px, 100%); max-height: 260px; border-radius: 12px; cursor: zoom-in; }
.att-media { display: block; max-width: min(380px, 100%); border-radius: 12px; background: #000; }
.att-audio { max-width: 100%; }
.att-chip { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--surface); color: var(--text); border: 1px solid var(--line); min-width: 220px; max-width: 100%; white-space: normal; }
.att-chip.gone { opacity: .7; }
.att-ico { width: 38px; height: 38px; border-radius: 10px; background: var(--raised); color: var(--muted); display: grid; place-items: center; flex: none; }
.att-meta { flex: 1; min-width: 0; }
.att-name { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-sub { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: .76rem; color: var(--muted); font-family: var(--mono); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 999px; font-family: var(--font); font-weight: 600; font-size: .68rem; }
.badge.dev { background: var(--accent-soft); color: var(--accent-2); }
.badge.cloud { background: var(--info-soft); color: var(--info); }
.badge.off { background: var(--raised); color: var(--faint); }
.badge.floating { position: absolute; left: 8px; top: 8px; background: rgba(31, 30, 29, .7); color: #fff; backdrop-filter: blur(4px); }

/* markdown: the AI's voice is serif, code is not */
.md { font-family: var(--serif); }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: .7em 0; } .md ul, .md ol { padding-left: 1.5em; } .md li { margin: .3em 0; } .md li::marker { color: var(--faint); }
.md h1, .md h2, .md h3, .md h4 { margin: 1.3em 0 .4em; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
.md h1 { font-size: 1.5rem; } .md h2 { font-size: 1.3rem; } .md h3 { font-size: 1.12rem; }
.md strong { font-weight: 600; }
.md code { font-family: var(--mono); background: var(--raised); padding: .1em .4em; border-radius: 6px; font-size: .8em; }
.md pre code { background: none; padding: 0; font-size: inherit; }
.md blockquote { margin: .9em 0; padding: 0 16px; border-left: 3px solid var(--line-2); color: var(--muted); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; font-family: var(--font); font-size: .94rem; } .md th, .md td { border: 1px solid var(--line-2); padding: 6px 12px; text-align: left; } .md th { background: var(--raised); font-weight: 600; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }
.codebox { margin: 1em 0; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; background: var(--sunk); font-family: var(--font); }
.codebox .bar { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 4px 14px; border-bottom: 1px solid var(--line); font-size: .78rem; color: var(--muted); }
.codebox .copy { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--muted); font-weight: 500; padding: 4px 8px; border-radius: 6px; font-size: .78rem; }
.codebox .copy:hover { background: var(--hover); color: var(--text); }
.codebox pre { margin: 0; padding: 12px 14px; overflow-x: auto; font-size: .84rem; line-height: 1.6; }

/* files and ZIP from the AI */
.ai-out { display: flex; flex-direction: column; gap: 10px; font-family: var(--font); }
.ai-out > .md { font-family: var(--serif); }
.file-card { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); overflow: hidden; font-size: 1rem; line-height: 1.5; }
.file-card.partial { border-color: var(--danger); }
.fc-head { display: flex; align-items: center; gap: 12px; padding: 10px 12px; flex-wrap: wrap; }
.fc-ico { width: 38px; height: 38px; border-radius: 10px; background: var(--raised); color: var(--muted); display: grid; place-items: center; flex: none; }
.fc-meta { flex: 1; min-width: 140px; }
.fc-name { font-weight: 600; font-family: var(--mono); font-size: .86rem; word-break: break-all; }
.fc-sub { color: var(--muted); font-size: .78rem; }
.fc-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.fc-warn { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--danger-soft); color: var(--danger); font-size: .88rem; font-weight: 500; }
.fc-warn .btn { margin-left: auto; color: var(--text); }
.fc-body { border-top: 1px solid var(--line); background: var(--sunk); max-height: 360px; overflow: auto; }
.fc-code { margin: 0; padding: 12px 14px; font-size: .82rem; line-height: 1.55; white-space: pre; }
.zip-bar { display: flex; align-items: center; gap: 14px; padding: 14px; border: 1px solid var(--line-2); border-radius: var(--r); background: var(--raised); flex-wrap: wrap; font-family: var(--font); font-size: 1rem; line-height: 1.5; margin: .6em 0; }
.zb-ico { width: 48px; height: 48px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.zb-meta { flex: 1; min-width: 180px; }
.zb-name { font-weight: 600; font-family: var(--mono); font-size: .92rem; word-break: break-all; }
.zb-sub { color: var(--muted); font-size: .84rem; }
.zb-tree summary { cursor: pointer; font-size: .84rem; font-weight: 500; color: var(--accent-2); margin-top: 4px; }
.zb-tree pre { margin: 6px 0 0; font-size: .78rem; max-height: 160px; overflow: auto; color: var(--muted); }

/* live view: what the AI is doing while it writes */
.lv-steps { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.lv-step { display: flex; align-items: center; gap: 8px; font-family: var(--font); font-size: .86rem; color: var(--muted); }
.lv-step.now { color: var(--text); }
.lv-step.done .ico { color: var(--accent); }
.lv-file { border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); margin: 10px 0; overflow: hidden; font-family: var(--font); font-size: 1rem; line-height: 1.5; }
.lv-file.writing { border-color: var(--accent); }
.lv-fhead { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: .88rem; }
.lv-fhead .fc-ico { width: 28px; height: 28px; border-radius: 8px; }
.lv-fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-weight: 600; }
.lv-fmeta { color: var(--faint); font-size: .78rem; font-family: var(--mono); }
.lv-fstate { display: inline-flex; color: var(--accent); }
.lv-code { margin: 0; padding: 10px 12px; max-height: 260px; overflow: auto; background: var(--sunk); font-family: var(--mono); font-size: .8rem; line-height: 1.55; white-space: pre; }
.lv-file.writing .lv-code::after { content: "▍"; color: var(--accent); animation: caret 1s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }
.pv { border: 1px solid var(--line); border-radius: var(--r-sm); margin-top: 12px; overflow: hidden; background: var(--surface); font-family: var(--font); font-size: 1rem; line-height: 1.5; }
.pv-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 12px; font-size: .9rem; }
.pv-head .ico { color: var(--accent); }
.pv-name { flex: 1; min-width: 0; color: var(--faint); font-family: var(--mono); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-body { border-top: 1px solid var(--line); }
.pv-frame { display: block; width: 100%; height: 380px; border: 0; background: #fff; }

/* memory panel */
.mem-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(31, 30, 29, .45); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 16px; }
.mem-panel { width: min(520px, 100%); max-height: 86vh; overflow: auto; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-lg); padding: 20px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow-up); animation: settle .2s; }
.mem-head { display: flex; align-items: center; gap: 10px; } .mem-head h3 { flex: 1; margin: 0; font-family: var(--serif); font-weight: 500; font-size: 1.3rem; } .mem-head .ico { color: var(--accent); }
.mem-sub { margin: 0; color: var(--muted); font-size: .92rem; }
.mem-switch { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.mem-switch input { accent-color: var(--accent); width: 16px; height: 16px; }
.mem-add, .mem-row { display: flex; gap: 8px; align-items: center; }
.mem-add input, .mem-row input { flex: 1; min-width: 0; border: 1px solid var(--line-2); background: var(--surface); color: var(--text); border-radius: var(--r-sm); padding: 9px 12px; }
.mem-add input:focus, .mem-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.mem-list { display: flex; flex-direction: column; gap: 8px; }
.mem-foot { display: flex; justify-content: flex-end; }

/* ---------- sign in ---------- */
.theme-float { position: fixed; top: 14px; right: 14px; z-index: 10; }
.auth { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); min-height: 100dvh; }
.auth-art { background: var(--side); border-right: 1px solid var(--line); padding: 44px 52px; display: flex; flex-direction: column; justify-content: space-between; gap: 32px; }
.auth-art h1 { font-family: var(--serif); font-weight: 500; font-size: clamp(2.4rem, 4.4vw, 3.8rem); line-height: 1.04; letter-spacing: -.025em; margin: 0 0 16px; }
.auth-art h1 em { font-style: italic; color: var(--accent-2); }
.auth-art p { color: var(--muted); font-size: 1.12rem; max-width: 460px; }
.auth-feats { list-style: none; margin: 24px 0 0; padding: 0; display: grid; gap: 12px; }
.auth-feats li { display: flex; align-items: center; gap: 12px; font-weight: 500; }
.auth-feats .ico { width: 34px; height: 34px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); color: var(--accent); }
.auth-avatars { display: flex; flex-wrap: wrap; gap: 10px; }
.auth-avatars .avatar { border: 2px solid var(--side); }
.auth-form-wrap { display: grid; place-items: center; padding: 30px 20px; }
.auth-card { width: min(400px, 100%); }
.auth-card h2 { font-family: var(--serif); font-weight: 500; font-size: 2rem; margin: 0 0 4px; letter-spacing: -.02em; }
.auth-card .sub { color: var(--muted); margin: 0 0 22px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--raised); margin-bottom: 18px; }
.tabs button { border: 0; background: transparent; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(31, 30, 29, .1); }
.divider { display: flex; align-items: center; gap: 12px; color: var(--faint); margin: 16px 0; font-size: .86rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.auth-card .field { margin-bottom: 14px; } .auth-card label { display: block; font-weight: 500; font-size: .88rem; margin-bottom: 6px; color: var(--muted); }
.auth-msg { min-height: 1.4em; font-weight: 500; margin: 0 0 10px; } .auth-msg.err { color: var(--danger); } .auth-msg.ok { color: #4b8a53; }
.input-ico { position: relative; } .input-ico .ico { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; } .input-ico input { padding-left: 42px; }

/* ---------- small screens ---------- */
@media (max-width: 920px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(86vw, 320px); transform: translateX(-102%); transition: transform .25s; box-shadow: var(--shadow-up); }
  .sidebar.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(31, 30, 29, .45); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .scrim.show { opacity: 1; pointer-events: auto; }
  #menu-btn, .sb-close { display: inline-flex; }
  .topbar { padding: 0 12px; }
  .editor-grid { grid-template-columns: 1fr; } .preview { position: static; order: -1; }
  .auth { grid-template-columns: 1fr; } .auth-art { display: none; }
  .page { padding: 24px 16px 52px; }
}
@media (max-width: 640px) {
  .chat-head { padding: 8px 12px 10px; } .head-actions .lbl { display: none; } .head-actions .btn { width: 38px; padding: 0; }
  .messages { padding: 20px 14px 8px; gap: 22px; } .composer { padding: 6px 10px 12px; } .cost-tag { display: none; }
  .msg { gap: 10px; } .msg-avatar .avatar { --s: 26px !important; }
  .msg.model .bubble { font-size: 1.05rem; }
  .toasts { bottom: 96px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---------- chat header: one Settings button with a menu ---------- */
.head-actions { position: relative; }
.head-menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; min-width: 230px; padding: 6px; display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r); box-shadow: var(--shadow-up); animation: settle .15s both; }
.head-menu[hidden] { display: none; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 11px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text); font: inherit; font-size: .92rem; text-align: left; text-decoration: none; cursor: pointer; }
.menu-item[hidden] { display: none; }
.menu-item .ico { display: inline-flex; color: var(--muted); }
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); outline: none; }
.menu-item.danger, .menu-item.danger .ico { color: var(--danger); }
.menu-item.danger:hover, .menu-item.danger:focus-visible { background: var(--danger-soft); }
.menu-sep { height: 1px; margin: 4px 2px; background: var(--line); }

/* ---------- message buttons: copy, reply, edit ---------- */
.msg-actions { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
@media (hover: none) { .msg-actions { opacity: .8; } }
.msg-actions .act { width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.msg-actions .act:hover, .msg-actions .act:focus-visible { background: var(--hover); color: var(--text); outline: none; }
.msg-actions .act.ok { color: #4b8a53; }
.ubox { display: flex; flex-direction: column; align-items: flex-end; min-width: 0; max-width: min(100%, 560px); }
.ubox .msg-actions { justify-content: flex-end; margin-top: 4px; }
.msg.user.editing .ubox { width: 100%; max-width: 100%; align-items: stretch; }

/* the quoted message above a reply, and the bar above the box while you write one */
.reply-quote { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 8px; padding: 6px 10px; border-left: 3px solid var(--accent); border-radius: 6px; background: var(--active); color: var(--muted); font-family: var(--font); font-size: .82rem; line-height: 1.4; white-space: normal; }
.reply-quote .ico { flex: none; margin-top: 2px; }
.reply-quote b { display: block; color: var(--text); font-size: .78rem; font-weight: 600; }
.reply-quote span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.reply-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; padding: 8px 8px 8px 12px; border: 1px solid var(--line-2); border-left: 3px solid var(--accent); border-radius: var(--r-sm); background: var(--surface); color: var(--accent); }
.reply-bar[hidden] { display: none; }
.reply-bar .rb-main { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: .84rem; }
.reply-bar .rb-main b { color: var(--text); font-weight: 600; }
.reply-bar .rb-main span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-bar > button { width: 28px; height: 28px; display: grid; place-items: center; flex: none; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.reply-bar > button:hover { background: var(--hover); color: var(--text); }

/* inline editor for a message or an answer */
.edit-box { display: flex; flex-direction: column; gap: 8px; width: 100%; font-family: var(--font); font-size: .96rem; line-height: 1.5; }
.edit-area { width: 100%; min-height: 96px; max-height: 55vh; resize: vertical; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--surface); color: var(--text); font: inherit; }
.edit-area.mono { font-family: var(--mono); font-size: .86rem; line-height: 1.55; min-height: 180px; }
.edit-area:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.edit-note { color: var(--muted); font-size: .8rem; }
.edit-actions { display: flex; justify-content: flex-end; gap: 8px; }
@media (max-width: 640px) { .head-menu { min-width: min(260px, calc(100vw - 24px)); } }
