:root {
  --bg: #f4f4f8; --surface: #ffffff; --surface-2: #f7f7fb; --ink: #15172b; --ink-2: #44475e; --muted: #6c6f86; --line: #e2e3ee;
  --accent: #4f46e5; --accent-ink: #fff; --accent-soft: #ecebfd; --crit: #d33f49; --crit-soft: #fdecee; --good: #0d8a5f;
  --openai: #10a37f; --anthropic: #d97757; --gemini: #4285f4; --openrouter: #8b5cf6;
  --r: 14px; --shadow: 0 1px 2px rgba(20,22,50,.04), 0 8px 28px -14px rgba(20,22,50,.18);
  --f-display: "Bricolage Grotesque", "Inter", system-ui, sans-serif; --f-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e0f1a; --surface: #161829; --surface-2: #1c1e33; --ink: #ecedf7; --ink-2: #c3c5d8; --muted: #8e91a8; --line: #2a2c44;
    --accent: #8b85ff; --accent-ink: #0e0f1a; --accent-soft: #24234a; --crit: #ff7a82; --crit-soft: #3a1d24; --good: #3ccf98;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -16px rgba(0,0,0,.6); color-scheme: dark; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.55 var(--f-body); }
h1, h2, h3 { font-family: var(--f-display); margin: 0; text-wrap: balance; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.note { color: var(--muted); font-size: 13px; margin: 0; }

/* header */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top, 0px); }
.top-in { max-width: 1500px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px max(18px, env(safe-area-inset-right, 0px)) 10px max(18px, env(safe-area-inset-left, 0px)); }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand b { display: block; font: 700 21px/1 var(--f-display); letter-spacing: -.01em; }
.brand small { color: var(--muted); font-size: 12px; }
.dots { display: inline-flex; }
.dots i { width: 16px; height: 16px; border-radius: 50%; margin-left: -5px; border: 2px solid var(--bg); animation: bob 2.4s ease-in-out infinite; }
.dots i:nth-child(1) { background: var(--openai); margin-left: 0; } .dots i:nth-child(2) { background: var(--anthropic); animation-delay: .2s; } .dots i:nth-child(3) { background: var(--gemini); animation-delay: .4s; }
@keyframes bob { 0%, 60%, 100% { transform: none; } 30% { transform: translateY(-4px); } }
.top-actions { display: flex; gap: 6px; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; padding-inline: 20px; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary[disabled] { opacity: .55; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface); border-color: var(--line); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

.wrap { max-width: 1500px; margin: 0 auto; padding: 22px max(18px, env(safe-area-inset-right, 0px)) calc(48px + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px)); display: grid; gap: 18px; }

/* composer */
.composer { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px 14px 12px; display: grid; gap: 10px; }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
textarea#prompt { width: 100%; border: 0; resize: vertical; min-height: 70px; max-height: 50vh; background: transparent; outline: none; font-size: 16px; line-height: 1.5; padding: 4px 6px; }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { --c: var(--muted); display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px 5px 9px; cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--ink-2); transition: background .15s, border-color .15s; }
.chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c); opacity: .35; transition: opacity .15s; }
.chip[aria-pressed="true"] { border-color: color-mix(in srgb, var(--c) 55%, var(--line)); background: color-mix(in srgb, var(--c) 10%, var(--surface)); color: var(--ink); }
.chip[aria-pressed="true"]::before { opacity: 1; }
.chip[disabled] { opacity: .45; cursor: not-allowed; }
.ask-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.hint { font-size: 12px; color: var(--muted); }
.notice { font-size: 13.5px; color: var(--crit); background: var(--crit-soft); border-radius: 10px; padding: 8px 12px; }

.question { display: flex; gap: 12px; align-items: baseline; padding: 0 4px; }
.q-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); flex: none; }
.question p { margin: 0; font-weight: 500; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* answer cards */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: 14px; align-items: start; }
.card { --c: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); display: grid; grid-template-rows: auto 1fr auto; min-width: 0; overflow: hidden; animation: rise .4s cubic-bezier(.2,.8,.2,1) both; }
.card:nth-child(2) { animation-delay: 60ms; } .card:nth-child(3) { animation-delay: 120ms; } .card:nth-child(4) { animation-delay: 180ms; } .card:nth-child(n+5) { animation-delay: 240ms; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.card.wide { grid-column: 1 / -1; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 10px; border-bottom: 1px solid var(--line); position: relative; }
.card-head::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: var(--c); }
.avatar { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--c); font: 700 13px var(--f-display); flex: none; }
.who { min-width: 0; flex: 1; }
.who b { display: block; font: 600 15.5px/1.2 var(--f-display); }
.who small { display: block; color: var(--muted); font: 400 11.5px var(--f-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--c); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; transform: scale(.7); } }
.status.done { color: var(--good); } .status.err { color: var(--crit); }
.answer { padding: 12px 16px 6px; min-height: 120px; max-height: 70vh; overflow: auto; overflow-wrap: anywhere; font-size: 14.5px; }
.card.wide .answer { max-height: none; }
.answer > :first-child { margin-top: 0; }
.answer h1, .answer h2, .answer h3, .answer h4 { font-family: var(--f-body); font-weight: 600; margin: 1em 0 .4em; line-height: 1.3; }
.answer h1 { font-size: 1.2em; } .answer h2 { font-size: 1.12em; } .answer h3, .answer h4 { font-size: 1.02em; }
.answer p, .answer ul, .answer ol { margin: .55em 0; }
.answer ul, .answer ol { padding-left: 1.3em; }
.answer code { font-family: var(--f-mono); font-size: .88em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }
.answer pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; overflow: auto; }
.answer pre code { border: 0; padding: 0; background: none; }
.answer table { border-collapse: collapse; display: block; overflow: auto; font-size: .92em; }
.answer th, .answer td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; }
.answer blockquote { margin: .6em 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--ink-2); }
.answer a { color: var(--accent); }
.answer .err-box { color: var(--crit); background: var(--crit-soft); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.skeleton { display: grid; gap: 9px; padding-top: 4px; }
.skeleton i { display: block; height: 11px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), color-mix(in srgb, var(--c) 14%, var(--surface-2)), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; }
.skeleton i:nth-child(2) { width: 88%; } .skeleton i:nth-child(3) { width: 72%; } .skeleton i:nth-child(4) { width: 80%; }
@keyframes shimmer { to { background-position: -200% 0; } }
.caret::after { content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 2px; vertical-align: -2px; background: var(--c); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px 10px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.stats { display: flex; gap: 12px; font: 400 11.5px var(--f-mono); color: var(--muted); flex-wrap: wrap; }
.card-actions { display: flex; gap: 4px; }

/* empty state */
.empty { text-align: center; padding: 40px 16px; color: var(--ink-2); display: grid; justify-items: center; gap: 10px; }
.empty h2 { font-size: 24px; }
.empty p { max-width: 520px; margin: 0; color: var(--muted); }
.empty-art { display: flex; gap: 10px; margin-bottom: 6px; }
.empty-art i { width: 54px; height: 70px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); position: relative; animation: bob 3s ease-in-out infinite; }
.empty-art i::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; border-radius: 12px 12px 0 0; }
.empty-art i:nth-child(1)::before { background: var(--openai); } .empty-art i:nth-child(2) { animation-delay: .25s; } .empty-art i:nth-child(2)::before { background: var(--anthropic); }
.empty-art i:nth-child(3) { animation-delay: .5s; } .empty-art i:nth-child(3)::before { background: var(--gemini); } .empty-art i:nth-child(4) { animation-delay: .75s; } .empty-art i:nth-child(4)::before { background: var(--openrouter); }

/* history drawer */
.scrim { position: fixed; inset: 0; z-index: 30; background: rgba(10,12,30,.4); }
.drawer { position: fixed; z-index: 31; top: 0; bottom: 0; right: 0; width: min(420px, 100vw); background: var(--surface); border-left: 1px solid var(--line); box-shadow: -20px 0 50px -24px rgba(0,0,0,.4);
  transform: translateX(105%); visibility: hidden; transition: transform .3s cubic-bezier(.2,.8,.2,1), visibility 0s linear .3s; overflow-y: auto; display: grid; gap: 10px; align-content: start;
  padding: calc(16px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) 16px; }
.drawer.open { transform: none; visibility: visible; transition: transform .3s cubic-bezier(.2,.8,.2,1), visibility 0s; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.drawer-head h2 { font-size: 20px; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.history button { width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 12px; cursor: pointer; display: grid; gap: 2px; }
.history button:hover { background: var(--surface-2); }
.history b { font-weight: 500; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.history small { color: var(--muted); font-size: 12px; }

/* settings */
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); background: var(--surface); color: var(--ink); box-shadow: 0 30px 70px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10,12,30,.45); }
.dlg { display: grid; gap: 12px; padding: 18px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg h2 { font-size: 21px; } .dlg h3 { font-size: 16px; margin-top: 4px; }
.field { display: grid; gap: 4px; font-size: 13.5px; }
.field input, .models input, .models select { border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 7px 9px; min-width: 0; }
.models { display: grid; gap: 8px; }
.mrow { display: grid; grid-template-columns: 22px 1fr 1.1fr 1.6fr 30px; gap: 8px; align-items: center; }
.mrow.off { opacity: .55; }
.mrow .x { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; padding: 4px; border-radius: 6px; }
.mrow .x:hover { color: var(--crit); background: var(--crit-soft); }
.mhead { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
@media (max-width: 600px) { .mrow { grid-template-columns: 22px 1fr 1fr 30px; } .mrow .mid { grid-column: 2 / 4; } .mhead { display: none; } .hint { display: none; } }
.dlg-foot { display: flex; gap: 8px; flex-wrap: wrap; }

.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom, 0px)); z-index: 60; transform: translate(-50%, 16px); opacity: 0; pointer-events: none; background: var(--ink); color: var(--surface);
  padding: 9px 16px; border-radius: 10px; font-size: 14px; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (max-width: 480px) { .brand small { display: none; } .top-actions .btn { padding-inline: 10px; } }
