:root { color-scheme: light dark; --bg:#fafafa; --panel:#fff; --fg:#242424; --muted:#616161; --line:#e0e0e0;
  --accent:#c5001f; --me:#ebf3fc; --code:#f3f3f3; }
@media (prefers-color-scheme: dark) { :root { --bg:#1f1f1f; --panel:#292929; --fg:#f0f0f0; --muted:#adadad;
  --line:#3d3d3d; --accent:#ff4d5e; --me:#2b3a4a; --code:#333; } }
body.dark { --bg:#1f1f1f; --panel:#292929; --fg:#f0f0f0; --muted:#adadad; --line:#3d3d3d; --accent:#ff4d5e; --me:#2b3a4a; --code:#333; }
body.light { --bg:#fafafa; --panel:#fff; --fg:#242424; --muted:#616161; --line:#e0e0e0; --accent:#c5001f; --me:#ebf3fc; --code:#f3f3f3; }
* { box-sizing:border-box; }
html, body { height:100%; }
body { margin:0; background:var(--bg); color:var(--fg); font:14px/1.5 "Segoe UI",-apple-system,system-ui,sans-serif;
  display:flex; flex-direction:column; }
header { display:flex; align-items:center; justify-content:space-between; padding:10px 16px; border-bottom:1px solid var(--line); background:var(--panel); }
.brand { display:flex; gap:10px; align-items:center; }
.brand span#who { display:block; color:var(--muted); font-size:12px; }
.logo { background:var(--accent); color:#fff; font-weight:700; border-radius:6px; width:32px; height:32px;
  display:flex; align-items:center; justify-content:center; font-size:14px; }
button { font:inherit; cursor:pointer; }
#new { background:none; border:1px solid var(--line); color:var(--fg); border-radius:6px; padding:5px 12px; }
main { flex:1; overflow-y:auto; padding:16px; display:flex; flex-direction:column; gap:14px; }
.intro { max-width:640px; margin:24px auto; text-align:center; }
.intro h1 { font-size:20px; margin:0 0 6px; }
.intro p { color:var(--muted); margin:0 0 16px; }
.examples { display:flex; flex-direction:column; gap:8px; }
.examples button { background:var(--panel); border:1px solid var(--line); color:var(--fg); border-radius:8px; padding:8px 12px; text-align:left; }
.msg { max-width:860px; width:100%; margin:0 auto; }
.msg.user .bubble { background:var(--me); margin-left:auto; max-width:80%; width:fit-content; }
.bubble { background:var(--panel); border:1px solid var(--line); border-radius:10px; padding:10px 14px; overflow-wrap:anywhere; }
.bubble p:first-child { margin-top:0; } .bubble p:last-child { margin-bottom:0; }
.bubble pre { background:var(--code); padding:8px; border-radius:6px; overflow-x:auto; }
.bubble code { background:var(--code); padding:1px 4px; border-radius:4px; }
.bubble pre code { padding:0; }
.bubble table { border-collapse:collapse; } .bubble td, .bubble th { border:1px solid var(--line); padding:3px 6px; }
.status { color:var(--muted); font-size:12px; margin-top:6px; }
.sources { margin-top:8px; font-size:12px; color:var(--muted); }
.sources summary { cursor:pointer; }
.sources li { margin:2px 0; }
form { display:flex; gap:8px; padding:12px 16px; border-top:1px solid var(--line); background:var(--panel); }
textarea { flex:1; resize:none; font:inherit; color:var(--fg); background:var(--bg); border:1px solid var(--line); border-radius:8px; padding:8px 10px; max-height:160px; }
#send { background:var(--accent); color:#fff; border:0; border-radius:8px; padding:0 18px; font-weight:600; }
#send:disabled { opacity:.5; cursor:default; }
[hidden] { display:none !important; }
#signin { font-size:12px; color:var(--muted); text-align:center; padding:4px 16px; }
#signin.err { color:var(--accent); }
#signin button { margin-left:8px; background:none; border:1px solid var(--line); color:var(--fg); border-radius:6px; padding:2px 10px; }
#fatal { position:fixed; inset:0; background:var(--bg); display:flex; align-items:center; justify-content:center; padding:24px; text-align:center; }
#fatal a { color:var(--accent); font-weight:600; }
/* Voice: mic (dictation) and voice mode */
button.icon { background:var(--panel); color:var(--fg); border:1px solid var(--line); border-radius:8px; width:40px;
  display:flex; align-items:center; justify-content:center; padding:0; }
button.icon:hover { border-color:var(--accent); }
button.icon:disabled { opacity:.5; cursor:default; }
form.recording > textarea { display:none; }
#recbar { flex:1; display:flex; align-items:center; gap:10px; background:var(--bg); border:1px solid var(--accent);
  border-radius:8px; padding:0 12px; min-height:38px; }
#recbar[hidden] { display:none; }
#recbar .dot { width:10px; height:10px; border-radius:50%; background:var(--accent); animation:pulse 1s infinite; }
#rectime { font-variant-numeric:tabular-nums; color:var(--muted); margin-left:auto; }
#mic { touch-action:none; user-select:none; -webkit-user-select:none; -webkit-touch-callout:none; }
#mic.rec { background:var(--accent); color:#fff; border-color:var(--accent); transform:scale(1.08); }
@keyframes pulse { 50% { opacity:.4; } }
/* Voice mode: a dock where the question box was; the chat above stays readable */
.vdock { display:flex; align-items:center; gap:14px; padding:12px 16px; border-top:1px solid var(--line); background:var(--panel); }
.vdock[hidden] { display:none; }
#orb { position:relative; width:56px; height:56px; flex:none; border-radius:50%; border:0; cursor:pointer;
  background:radial-gradient(circle at 35% 35%, #ff8a96, var(--accent)); }
#vlevel { --lvl:0; position:absolute; inset:-6px; border-radius:50%; border:3px solid var(--accent);
  opacity:calc(.15 + var(--lvl) * .85); transform:scale(calc(1 + var(--lvl) * .25)); transition:transform .06s, opacity .06s; }
.vdock.heard #orb { background:radial-gradient(circle at 35% 35%, #ffb3bb, #e11d48); }
.vdock.thinking #orb { animation:breathe 1.4s ease-in-out infinite; }
.vdock.speaking #orb { background:radial-gradient(circle at 35% 35%, #9cc7ff, #2563eb); }
.vdock.speaking #vlevel { border-color:#2563eb; }
@keyframes breathe { 50% { transform:scale(.88); opacity:.7; } }
.vtext { flex:1; min-width:0; }
.vlabel { font-size:12px; color:var(--muted); }
#vstatus { font-size:16px; font-weight:600; }
#vend { background:#c42b1c; color:#fff; border:0; border-radius:999px; padding:10px 26px; font-size:15px; font-weight:600; }
body.in-voice main { font-size:15px; }
/* Sources: visible list, each opens the cited passage */
.sources { margin-top:10px; display:flex; flex-direction:column; gap:4px; align-items:flex-start; }
.shead { font-size:12px; font-weight:600; color:var(--muted); text-transform:uppercase; letter-spacing:.04em; }
.src { background:none; border:0; padding:2px 0; color:var(--accent); text-align:left; font-size:13px; cursor:pointer; text-decoration:underline; }
.modal { position:fixed; inset:0; z-index:20; background:rgba(0,0,0,.45); display:flex; align-items:center; justify-content:center; padding:16px; }
.modal[hidden] { display:none; }
.mcard { background:var(--panel); color:var(--fg); border-radius:12px; max-width:720px; width:100%; max-height:85vh; overflow:auto; padding:16px 18px; }
.mhead { display:flex; justify-content:space-between; gap:12px; align-items:flex-start; margin-bottom:10px; }
#pmeta { color:var(--muted); font-size:13px; }
#pclose { background:none; border:1px solid var(--line); color:var(--fg); border-radius:50%; width:32px; height:32px; flex:none; }
#ptext { white-space:pre-wrap; font-size:14px; line-height:1.55; }
.mnote { margin-top:12px; font-size:12px; color:var(--muted); }
.vsens { display:flex; flex-direction:column; font-size:11px; color:var(--muted); gap:2px; }
.vsens select { font:inherit; font-size:13px; color:var(--fg); background:var(--bg); border:1px solid var(--line); border-radius:6px; padding:3px 6px; }
@media (max-width:520px) { .vsens { display:none; } }
/* History drawer */
.hbtns { display:flex; gap:8px; }
#historyBtn, #openBrowser { background:none; border:1px solid var(--line); color:var(--fg); border-radius:6px; padding:5px 12px; }
.drawer { position:fixed; inset:0; z-index:15; background:rgba(0,0,0,.3); display:flex; }
.drawer[hidden] { display:none; }
.dpanel { width:min(340px, 88vw); height:100%; background:var(--panel); border-right:1px solid var(--line); display:flex;
  flex-direction:column; padding:12px; gap:8px; box-sizing:border-box; }
.dhead { display:flex; justify-content:space-between; align-items:center; }
#hclose { background:none; border:1px solid var(--line); color:var(--fg); border-radius:50%; width:30px; height:30px; }
#hsearch { font:inherit; color:var(--fg); background:var(--bg); border:1px solid var(--line); border-radius:8px; padding:7px 10px; }
#hlist { flex:1; overflow-y:auto; display:flex; flex-direction:column; gap:2px; }
.hgroup { font-size:11px; font-weight:600; color:var(--muted); text-transform:uppercase; letter-spacing:.04em; margin:10px 4px 4px; }
.hrow { display:flex; align-items:center; border-radius:6px; }
.hrow:hover, .hrow.current { background:var(--bg); }
.hopen { flex:1; min-width:0; background:none; border:0; color:var(--fg); text-align:left; padding:7px 6px; overflow:hidden;
  text-overflow:ellipsis; white-space:nowrap; font-size:13px; }
.hdel { background:none; border:0; color:var(--muted); padding:4px 6px; visibility:hidden; }
.hrow:hover .hdel, .hrow.current .hdel { visibility:visible; }
.hnote { font-size:12px; color:var(--muted); padding:4px; }
.hnote.err { color:var(--accent); }
#openBrowser[hidden] { display:none; }
#signin button { margin-left:6px; }
@media (max-width:520px) { #openBrowser { display:none; } }
