:root {
  --bg: #EFEFEF; --panel: #E4E4E4; --surface: #FFFFFF; --ink: #1A1A1A;
  --muted: #666666; --line: #D4D4D4; --accent: #1A1A1A; --accent-ink: #FFFFFF;
  --bubble: #E4E4E4; --kw: rgba(0,0,0,.09); --danger: #1A1A1A; --sel: rgba(0,0,0,.07);
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, sans-serif;
  --display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141414; --panel: #0D0D0D; --surface: #1F1F1F; --ink: #EAEAEA;
    --muted: #9A9A9A; --line: #2F2F2F; --accent: #EAEAEA; --accent-ink: #111111;
    --bubble: #2A2A2A; --kw: rgba(255,255,255,.14); --danger: #EAEAEA; --sel: rgba(255,255,255,.09);
  }
}
:root[data-theme="dark"] {
  --bg: #141414; --panel: #0D0D0D; --surface: #1F1F1F; --ink: #EAEAEA;
  --muted: #9A9A9A; --line: #2F2F2F; --accent: #EAEAEA; --accent-ink: #111111;
  --bubble: #2A2A2A; --kw: rgba(255,255,255,.14); --danger: #EAEAEA; --sel: rgba(255,255,255,.09);
}
*, *::before, *::after { box-sizing: inherit; }
html { height: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); }
body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--body); }
button, textarea, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
: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; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 7px 14px; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:disabled { opacity: .45; cursor: default; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: .88rem; }

/* ---------- Public chat ---------- */
.pub { display: flex; flex-direction: column; height: 100%; }
.pub-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 20px; }
.brand { display: flex; align-items: center; gap: 10px; font: 700 1.2rem/1 var(--display); letter-spacing: -.01em; }

.scroll { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.thread { width: 100%; max-width: 740px; margin: 0 auto; padding: 24px 20px 32px; display: flex; flex-direction: column; gap: 26px; }
.empty { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 40px 20px 8px; gap: 14px; }
.empty h1 { font: 700 clamp(2rem, 5vw, 3rem)/1.05 var(--display); letter-spacing: -.02em; margin: 0; max-width: 16ch; }
.empty p { margin: 0; color: var(--muted); max-width: 46ch; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; max-width: 560px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-size: .92rem; }
.chip:hover { border-color: var(--accent); }

.msg-user { align-self: flex-end; max-width: 82%; background: var(--bubble); padding: 10px 16px; border-radius: 20px 20px 6px 20px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-bot { display: grid; grid-template-columns: 30px 1fr; gap: 14px; align-items: start; }
.bot-text { font-size: 1.06rem; overflow-wrap: anywhere; padding-top: 2px; }
.bot-text .kw { background: var(--kw); border-radius: 4px; box-shadow: 0 0 0 2px var(--kw); }
.why { margin-top: 8px; font-size: .86rem; color: var(--muted); }
.why summary { cursor: pointer; width: fit-content; list-style: none; padding: 2px 0; }
.why summary::-webkit-details-marker { display: none; }
.why summary::before { content: "+ "; }
.why[open] summary::before { content: "\2212  "; }
.why dl { margin: 6px 0 0; padding: 10px 12px; border-left: 2px solid var(--line); display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; }
.why dd { margin: 0; color: var(--ink); }

.composer-wrap { padding: 8px 20px 16px; }
.composer { max-width: 740px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 10px 10px 10px 18px; display: flex; align-items: flex-end; gap: 10px; box-shadow: 0 6px 24px -12px rgba(0,0,0,.2); }
.composer:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; border: 0; outline: 0; resize: none; background: transparent; max-height: 200px; padding: 8px 0; line-height: 1.45; }
.composer textarea::placeholder { color: var(--muted); }
.send { flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.send:disabled { opacity: .35; cursor: default; }
.hint { max-width: 740px; margin: 8px auto 0; font-size: .8rem; color: var(--muted); text-align: center; }

/* Thinking state */
.mark { flex: none; display: block; }
.mark.thinking circle { transform-box: fill-box; transform-origin: center; animation: breathe 1.8s ease-in-out infinite; }
.mark.thinking .wave { stroke-dasharray: 5 3; animation: flow .9s linear infinite; }
@keyframes breathe { 0%, 100% { transform: scale(.9); opacity: .85; } 50% { transform: scale(1); opacity: 1; } }
@keyframes flow { to { stroke-dashoffset: -16; } }
.status { padding-top: 4px; font-size: .98rem; }
.shimmer {
  display: inline-block;
  background: linear-gradient(90deg, var(--muted) 0%, var(--muted) 40%, var(--ink) 50%, var(--muted) 60%, var(--muted) 100%);
  background-size: 250% 100%;
  -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
  animation: shimmer 1.8s linear infinite;
  transition: opacity .18s, transform .18s;
}
.shimmer.swap { opacity: 0; transform: translateY(-3px); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -150% 0; } }
.caret { display: inline-block; width: 1px; height: 1.15em; margin-left: 2px; vertical-align: -.2em; background: var(--ink); animation: caret 1s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }
.send.stop { background: var(--ink); color: var(--bg); }

.msg-bot.err .bot-text { color: var(--muted); font-style: italic; }

@media (max-width: 820px) {
  .msg-user { max-width: 90%; }
}
@media (prefers-reduced-motion: reduce) {
  .mark.thinking circle, .mark.thinking .wave, .shimmer, .caret { animation: none; }
  .shimmer { background: none; color: var(--muted); -webkit-text-fill-color: currentColor; }
}

/* Topic picker */
.pub-top { justify-content: flex-start; }
.topic-picker { position: relative; }
.topic-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px 6px 14px; font-size: .92rem; font-weight: 700; }
.topic-btn:hover { border-color: var(--accent); }
.topic-btn svg { color: var(--muted); }
.topic-menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; min-width: 280px; max-width: min(360px, calc(100vw - 32px)); list-style: none; margin: 0; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 32px -12px rgba(0,0,0,.3); }
.topic-opt { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 9px; cursor: pointer; }
.topic-opt:hover, .topic-opt:focus { background: var(--bg); outline: none; }
.topic-opt:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.topic-opt-text { flex: 1; min-width: 0; }
.topic-opt b { display: block; font-size: .95rem; }
.topic-opt-text span { display: block; color: var(--muted); font-size: .85rem; line-height: 1.35; }
.topic-opt .check { flex: none; color: var(--accent); visibility: hidden; }
.topic-opt[aria-selected="true"] .check { visibility: visible; }

.pills { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 4px; background: var(--panel); border-radius: 999px; max-width: 100%; }
.pill { border: 0; background: transparent; border-radius: 999px; padding: 7px 14px; font-size: .92rem; color: var(--muted); }
.pill:hover { color: var(--ink); }
.pill[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
#topicDesc { min-height: 1.5em; }

.topic-divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; }
.topic-divider::before, .topic-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

@media (max-width: 520px) {
  .pills { border-radius: 16px; }
}

.empty .intro { max-width: 54ch; color: var(--muted); }
.empty #topicDesc { font-size: .92rem; }

.empty .picker-head { margin: 14px 0 -4px; font: 700 .8rem/1.2 var(--body); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

/* Sliding focus highlight: one shape behind the options that moves to the selected one */
.pills.has-indicator { position: relative; }
.pills.has-indicator .pill { position: relative; z-index: 1; transition: color .3s ease; }
.pills.has-indicator .pill[aria-checked="true"] { background: transparent; box-shadow: none; }
.pill-indicator { position: absolute; top: 0; left: 0; z-index: 0; border-radius: 999px; background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); pointer-events: none; transition: transform .45s cubic-bezier(.3, .7, .2, 1), width .45s cubic-bezier(.3, .7, .2, 1), height .45s cubic-bezier(.3, .7, .2, 1); }
@media (prefers-reduced-motion: reduce) {
  .pill-indicator, .pills.has-indicator .pill { transition: none; }
}
