:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1b1c1e;
  --muted: #5d6066;
  --line: #e2dfd7;
  --accent: #b5462a;
  --accent-ink: #ffffff;
  --accent-soft: #f6e4dc;
  --focus: #1f5fbf;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px rgb(0 0 0 / 0.05);
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Charter, Georgia, "Songti SC", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121314;
    --surface: #1a1b1d;
    --surface-2: #232427;
    --text: #ecebe7;
    --muted: #a3a49f;
    --line: #2e2f33;
    --accent: #f08a68;
    --accent-ink: #1a0d08;
    --accent-soft: #3a2219;
    --focus: #8ab4ff;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { animation: none !important; transition: none !important; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.6 var(--sans);
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration-color: color-mix(in srgb, var(--accent) 60%, transparent); text-underline-offset: 3px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.wrap { width: min(760px, 100% - 40px); margin-inline: auto; }
.muted { color: var(--muted); }
.small { font-size: 0.94rem; }
.tiny { font-size: 0.8rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 12px; top: -48px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip:focus { top: 12px; }

/* ---------- Hero ---------- */
.hero { padding: clamp(56px, 12vw, 112px) 0 28px; }
.eyebrow { margin: 0 0 14px; font: 500 0.78rem/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
h1 { margin: 0; font: 600 clamp(2.6rem, 8vw, 4.2rem)/1.02 var(--serif); letter-spacing: -0.02em; }
.tagline { margin: 16px 0 22px; font-size: clamp(1.05rem, 2.6vw, 1.25rem); color: var(--muted); max-width: 36ch; }
.tagline .arrow { color: var(--accent); }
.links { display: flex; flex-wrap: wrap; gap: 6px 20px; font-size: 0.95rem; }
.links a { text-decoration: none; border-bottom: 1px solid var(--line); padding-bottom: 2px; }
.links a:hover { border-color: var(--accent); }

/* ---------- Chat ---------- */
#ask { scroll-margin-top: 24px; }
.chat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  padding: clamp(18px, 4vw, 28px);
}
.chat-head h2 { margin: 0 0 4px; font: 600 1.35rem/1.25 var(--serif); }
.chat-head p { margin: 0; }

.log {
  margin: 20px 0 14px;
  max-height: min(52vh, 460px);
  min-height: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 4px;
  overscroll-behavior: contain;
}
.msg { max-width: 88%; padding: 10px 14px; border-radius: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.msg p { margin: 0; }
.msg p + p { margin-top: 0.6em; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.error { background: color-mix(in srgb, var(--accent) 12%, var(--surface-2)); }

.sources { margin: 10px 0 0; padding: 8px 0 0; border-top: 1px solid var(--line); list-style: none; font-size: 0.8rem; color: var(--muted); }
.sources li { display: flex; gap: 6px; }
.sources b { font: 600 0.72rem/1.6 var(--mono); color: var(--accent); }

.cite {
  position: relative;
  display: inline-block;
  vertical-align: super;
  margin: 0 1px;
  padding: 0 4px;
  min-width: 1.4em;
  font: 600 0.66rem/1.5 var(--mono);
  color: var(--accent);
  background: var(--accent-soft);
  border: 0;
  border-radius: 6px;
  cursor: help;
}
.cite .tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  width: max-content;
  max-width: min(260px, 70vw);
  padding: 6px 9px;
  font: 500 0.75rem/1.35 var(--sans);
  color: var(--bg);
  background: var(--text);
  border-radius: 8px;
  text-align: left;
  white-space: normal;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.12s ease;
  pointer-events: none;
  z-index: 5;
}
.cite:hover .tip, .cite:focus-visible .tip, .cite[aria-expanded="true"] .tip { visibility: visible; opacity: 1; }

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out both; }
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  font: 500 0.86rem/1.2 var(--sans);
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip:disabled { opacity: 0.5; cursor: default; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px 6px 6px 14px;
}
.composer:focus-within { border-color: var(--focus); }
.composer textarea {
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  line-height: 1.5;
  padding: 7px 0;
  max-height: 160px;
}
.composer textarea::placeholder { color: var(--muted); }
.send {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
.send:disabled { opacity: 0.45; cursor: default; }
.help { margin: 8px 2px 0; }

/* ---------- Sections ---------- */
section { padding-block: 28px; }
.section-title { margin: 32px 0 18px; font: 600 1.6rem/1.2 var(--serif); }

.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.card-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card h3 { margin: 0; font: 600 1.1rem/1.3 var(--mono); }
.card p { margin: 10px 0 0; font-size: 0.94rem; }
.card .stack { margin-top: auto; padding-top: 14px; font: 0.76rem/1.4 var(--mono); color: var(--muted); }
.card-link { margin-top: 8px; font-size: 0.84rem; }
.tag { flex: none; font: 600 0.68rem/1 var(--mono); letter-spacing: 0.04em; text-transform: uppercase; padding: 5px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); }
.tag-wip { background: color-mix(in srgb, #c9a227 22%, transparent); color: color-mix(in srgb, #8a6a00 100%, var(--text)); }
.tag-muted { background: var(--surface-2); color: var(--muted); }
@media (prefers-color-scheme: dark) { .tag-wip { color: #e8c766; } }

.timeline { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.timeline li { position: relative; display: grid; grid-template-columns: 150px 1fr; gap: 4px 20px; padding: 0 0 22px 22px; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--bg); border: 2px solid var(--accent); }
.when { font: 0.8rem/1.9 var(--mono); color: var(--muted); }
.timeline h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.timeline p { margin: 2px 0 0; font-size: 0.94rem; color: var(--muted); }
@media (max-width: 560px) { .timeline li { grid-template-columns: 1fr; } }

.footer { padding: 40px 0 56px; margin-top: 24px; border-top: 1px solid var(--line); font-size: 0.9rem; color: var(--muted); }
.footer p { margin: 0 0 6px; }
.footer strong { color: var(--text); font-weight: 600; }
