:root {
  --bg: #f6f7f9;
  --bg-elev: #ffffff;
  --fg: #101114;
  --muted: #6b7280;
  --line: #e6e8ec;
  --accent: #2f6bff;
  --accent-soft: #eaf0ff;
  --bubble-user: #2f6bff;
  --bubble-user-fg: #ffffff;
  --bubble-ai: #ffffff;
  --shadow: 0 8px 24px rgba(16, 17, 20, .08);
  --radius: 18px;
  --maxw: 720px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
html.theme-dark {
  --bg: #0d0f13;
  --bg-elev: #161a21;
  --fg: #eef1f6;
  --muted: #9aa3b2;
  --line: #262c36;
  --accent: #5b8bff;
  --accent-soft: #1b2536;
  --bubble-user: #3b6fe0;
  --bubble-ai: #161a21;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Text", Segoe UI, Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background .35s ease, color .35s ease;
}

/* ── aurora ─────────────────────────────────────────── */
.aurora {
  position: fixed; inset: -20% -20% auto -20%; height: 70vh;
  background:
    radial-gradient(40% 55% at 25% 30%, rgba(47,107,255,.35), transparent 70%),
    radial-gradient(40% 55% at 75% 25%, rgba(168,85,247,.28), transparent 70%),
    radial-gradient(45% 60% at 50% 60%, rgba(16,185,129,.22), transparent 70%);
  filter: blur(40px); opacity: .7; z-index: 0; pointer-events: none;
  transition: opacity .6s ease;
}
body.has-chat .aurora { opacity: .25; }
.aurora.stop { display: none; }

/* ── topbar ─────────────────────────────────────────── */
.topbar {
  position: relative; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) 12px 8px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: -.2px; margin: 0 auto; }
.brand span { color: var(--accent); }
.topbar-right { display: flex; gap: 4px; }
.icon-btn {
  border: 0; background: transparent; color: var(--fg);
  width: 38px; height: 38px; border-radius: 12px; font-size: 20px;
  display: grid; place-items: center; cursor: pointer;
  transition: background .2s ease, transform .12s ease;
}
.icon-btn:active { transform: scale(.9); background: var(--accent-soft); }

/* ── scroll area ────────────────────────────────────── */
.scroll {
  position: relative; z-index: 1; flex: 1; overflow-y: auto;
  overscroll-behavior: contain; scroll-behavior: smooth;
}
.messages, .hero { max-width: var(--maxw); margin: 0 auto; padding: 0 14px; }
.messages { padding-bottom: 16px; }

.hero { text-align: center; padding: 14vh 20px 24px; transition: opacity .4s ease, transform .4s ease; }
.hero.hide { display: none; }
.hero-title { font-size: 30px; line-height: 1.15; margin: 0 0 10px; font-weight: 700; letter-spacing: -.5px; }
.hero-sub { color: var(--muted); margin: 0; font-size: 15px; }

/* ── bubbles ────────────────────────────────────────── */
.msg { margin: 14px 0; display: flex; animation: rise .35s ease both; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 88%; border-radius: var(--radius); padding: 12px 15px;
  background: var(--bubble-ai); box-shadow: var(--shadow); overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--bubble-user); color: var(--bubble-user-fg);
  border-bottom-right-radius: 6px;
}
.msg.ai .bubble { border-bottom-left-radius: 6px; }
.bubble p { margin: .5em 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h2 { font-size: 18px; margin: .7em 0 .3em; }
.bubble h3 { font-size: 16px; margin: .6em 0 .3em; }
.bubble ul, .bubble ol { margin: .4em 0; padding-left: 1.3em; }
.bubble code {
  background: var(--accent-soft); padding: 1px 6px; border-radius: 6px;
  font: .9em ui-monospace, SFMono-Regular, Menlo, monospace;
}
.cursor::after {
  content: "▌"; margin-left: 1px; color: var(--accent);
  animation: blink 1s steps(1) infinite;
}
.skeleton { height: 14px; border-radius: 7px; margin: 8px 0;
  background: linear-gradient(90deg, var(--line) 25%, var(--accent-soft) 37%, var(--line) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
.skeleton.short { width: 55%; }

/* ── sources ────────────────────────────────────────── */
.sources { margin-top: 10px; display: grid; gap: 8px; }
.source-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px;
  background: var(--bg-elev); font-size: 13px; cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
}
.source-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.source-card .st { font-weight: 600; margin-bottom: 2px; }
.source-card .sm { color: var(--muted); font-size: 12px; }
.badge {
  display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); margin-right: 6px;
}
.usage-line { margin-top: 8px; font-size: 12px; color: var(--muted); }

/* ── composer ───────────────────────────────────────── */
.composer {
  position: relative; z-index: 5; padding: 8px 12px calc(10px + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
}
.pills { display: flex; gap: 6px; overflow-x: auto; max-width: var(--maxw);
  margin: 0 auto 8px; scrollbar-width: none; }
.pills::-webkit-scrollbar { display: none; }
.pill {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--bg-elev);
  color: var(--fg); border-radius: 999px; padding: 6px 13px; font-size: 13px;
  cursor: pointer; transition: all .18s ease;
}
.pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.science-note { max-width: var(--maxw); margin: 0 auto 6px; font-size: 12px; color: var(--muted); }
.input-row {
  display: flex; align-items: flex-end; gap: 8px; max-width: var(--maxw); margin: 0 auto;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 22px;
  padding: 6px 6px 6px 14px; box-shadow: var(--shadow);
}
#q {
  flex: 1; border: 0; background: transparent; color: var(--fg); resize: none;
  font: inherit; max-height: 140px; padding: 8px 0; outline: none;
}
.send-btn {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  cursor: pointer; transition: transform .12s ease, opacity .2s ease;
}
.send-btn:active { transform: scale(.9); }
.send-btn:disabled { opacity: .45; }

/* ── drawers & modal ────────────────────────────────── */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; animation: fade .2s ease; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 92vw);
  background: var(--bg-elev); z-index: 30; transform: translateX(105%);
  transition: transform .3s cubic-bezier(.2,.8,.2,1); display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + var(--safe-t)) 14px 12px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 17px; }
.drawer-body { padding: 14px; overflow-y: auto; }
.prompt-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.prompt-list li { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  display: flex; align-items: center; gap: 8px; }
.prompt-list .pname { flex: 1; font-weight: 600; }
.prompt-list .ptrunc { color: var(--muted); font-size: 12px; }
.prompt-form { display: grid; gap: 8px; }
.prompt-form input, .prompt-form textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  background: var(--bg); color: var(--fg); font: inherit; resize: vertical;
}
.primary-btn { background: var(--accent); color: #fff; border: 0; border-radius: 12px;
  padding: 11px 14px; font: inherit; font-weight: 600; cursor: pointer; }
.primary-btn:disabled { opacity: .5; }
.mini-btn { border: 1px solid var(--line); background: transparent; color: var(--fg);
  border-radius: 9px; padding: 5px 9px; font-size: 12px; cursor: pointer; }
.mini-btn.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  background: rgba(0,0,0,.45); padding: 18px; animation: fade .2s ease; }
.modal-card { background: var(--bg-elev); border-radius: 20px; padding: 22px;
  width: min(420px, 100%); box-shadow: var(--shadow); display: grid; gap: 12px; }
.modal-card h2 { margin: 0; }
.muted { color: var(--muted); font-size: 14px; margin: 0; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.check input { margin-top: 3px; width: 18px; height: 18px; }
.choice-btn { border: 1px solid var(--line); background: var(--bg); color: var(--fg);
  border-radius: 14px; padding: 14px; font: inherit; font-weight: 600; cursor: pointer;
  transition: all .18s ease; }
.choice-btn:active { transform: scale(.98); background: var(--accent-soft); }
.toast { position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; z-index: 50; box-shadow: var(--shadow); animation: rise .25s ease; }

/* ── animations ─────────────────────────────────────── */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@media (prefers-reduced-motion: no-preference) {
  .aurora { animation: drift 22s ease-in-out infinite alternate; }
  @keyframes drift {
    from { transform: translate3d(-4%, -2%, 0) scale(1.05); }
    to { transform: translate3d(4%, 3%, 0) scale(1.15); }
  }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
