/* kefeiyan.com — shared by index.html (agent page) and classic.html.
   Theme tokens live in :root; two breakpoints (520px for phones, 900px for the two-column
   layout with the sticky hero); no decorative animation.

   Three border colours, deliberately not one, because they answer to different rules:
   --rule draws dividers (decorative, exempt from any contrast floor); --ctrl draws the edge that
   makes a control look like a control (3:1, WCAG 1.4.11); --frame draws the edge of a picture
   (no floor either, but a hairline that reads on one ground vanishes on the other, so it cannot
   just inherit --rule). The dark theme is at the end of the file. */

:root {
  color-scheme: light dark;
  --bg: #fdfdf8;
  --surface: #fbfaf2;          /* a panel sitting on --bg: the chat input */
  --ink: #1a1a1a;
  --muted: #6b6a63;
  --rule: #e6e3d6;             /* dividers only: decorative, exempt from contrast rules */
  --ctrl: #938e87;             /* oklch(0.65 0.012 80): 3.19 on --bg, 3.11 on --surface */
  --frame: #e6e3d6;            /* a picture's edge; same as --rule on this ground, not on the dark one */
  --scroll-track: #f2f0e6;
  --scroll-thumb: #bfbaa6;
  --scroll-thumb-hover: #a29c88;
  --accent: oklch(0.52 0.09 62);
  --accent-line: oklch(0.88 0.04 62);   /* the user bubble's edge */
  --accent-bg: oklch(0.94 0.025 62);
  --serif: "Charter", "Iowan Old Style", "Source Serif Pro", "Source Serif 4", Georgia, Cambria, "Times New Roman", Times, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
/* One column below 900px: the hero above the content, the photo above the name. The two-column
   layout with the sticky hero is at the end of this file, under the 900px query. */
main {
  max-width: 776px;
  margin: 0 auto;
  padding: 56px 28px 80px;
}

/* ---- Hero (identical markup on both pages, the mode switch aside) ---- */
.hero .photo {
  display: block;
  width: 112px;
  height: auto;          /* the ratio comes from the tag's width/height, written by the build */
  border-radius: 16px;
  margin: 0 0 18px;
}
.hero h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 34px;
  letter-spacing: -0.01em;
  margin: 0 0 10px;
  line-height: 1.1;
}
.hero .tagline {
  margin: 0 0 6px;
  font-style: italic;
  font-size: 17px;
  line-height: 1.45;
}
.hero .current {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-family: var(--sans);
  line-height: 1.5;
}

/* ---- Contact links: a wrapped row in one column, a list in the sidebar ---- */
.contact {
  margin-top: 18px;
  font-family: var(--sans);
  font-size: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  align-items: baseline;
}
.contact a { color: var(--ink); }
.contact a:hover { color: var(--accent); }
.switch {
  margin: 14px 0 0;
  font-family: var(--sans);
  font-size: 14px;
}

/* ---- Small labels: one style on both pages (layer labels, source tags, chat header, skip, thinking) ---- */
.layer-label, .src-tag, .chat-header, .turn .skip, .think-block .think-head {
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-style: normal;
}

hr.rule {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 36px 0 28px;
}

/* ---- About / Research interests ---- */
section.about p,
section.research p {
  margin: 0;
  font-size: 18px;
  line-height: 1.65;
}

/* ---- Chat (de-boxed) ---- */
section.chat {
  margin-top: 36px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 16px 0 4px;
  background: var(--bg);
}

/* ---- Chat input ---- */
.chat-input {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border: 1px solid var(--ctrl);
  border-radius: 10px;
  padding: 8px 10px 8px 14px;
  background: var(--surface);
  margin-bottom: 14px;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
/* The glow is --accent-bg softened, expressed as such rather than copied out by hand: a second
   literal of the same colour drifts the first time --accent-bg moves. The focus indicator that
   has to carry the contrast is the border-color below (--accent, 5.53:1); this is supplementary. */
.chat-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent-bg) 60%, transparent);
}
.chat-input textarea {
  flex: 1;
  min-height: 22px;
  max-height: 140px;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink);
  padding: 6px 0;
  overflow-y: auto;
}
.chat-input textarea::placeholder { color: var(--muted); font-style: italic; }
.chat-input button {
  flex: 0 0 auto;
  border: 1px solid var(--ctrl);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 140ms ease;
  margin-bottom: 2px;
}
.chat-input button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.chat-input button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.chat-input .kbd {
  font-family: var(--mono);
  font-size: 11px;
  margin-left: 6px;
  opacity: 0.6;
}

/* ---- LLM thinking stream ---- */
.think-block {
  border-left: 2px solid var(--rule);
  padding: 6px 0 6px 14px;
  margin: 0;
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--muted);
  font-style: italic;
}
.think-block .think-head {
  opacity: 0.8;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  cursor: pointer;
  user-select: none;
}
.think-block .think-head .chev {
  display: inline-block;
  transition: transform 180ms ease;
}
.think-block.collapsed .think-head .chev { transform: rotate(-90deg); }
.think-block.collapsed .think-body { display: none; }
.think-block .think-body { display: block; }
.think-block .think-step {
  display: block;
  opacity: 0;
  animation: thinkfade 280ms ease forwards;
}
/* Rendered all at once, in front of a generated answer: there is nothing to stagger, and fading
   it in would only delay a block that is collapsed anyway. */
.think-block .think-step.shown { opacity: 1; animation: none; }
.think-block .think-step + .think-step { margin-top: 2px; }
.think-block .think-step .tcaret {
  display: inline-block;
  width: 5px;
  height: 0.95em;
  background: var(--muted);
  margin-left: 2px;
  vertical-align: -1px;
  opacity: 0.6;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes thinkfade {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 0.85; transform: translateY(0); }
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
/* The conversation scrolls inside its own box rather than stretching the page. Without this a
   long session pushes the input, the suggested questions and the footer far below the fold. */
.conversation {
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: relative;            /* so a turn's offsetTop is measured against this box */
  max-height: min(52vh, 520px);
  overflow-y: auto;
  overscroll-behavior: contain;  /* reaching the end does not start scrolling the page */
  padding: 4px 14px 4px 2px;     /* room for the scrollbar without the text touching it */
  margin-right: -14px;
}
.conversation:empty { display: none; }

/* macOS hides overlay scrollbars until you scroll, so the box looks like it does not scroll at
   all. Styling ::-webkit-scrollbar makes Chrome and Safari draw a real, always-visible one.
   Firefox has no ::-webkit-scrollbar, so it gets the standard properties instead — declaring
   both would let the standard ones win in Chrome and bring the disappearing bar back. */
.conversation::-webkit-scrollbar { width: 10px; }
/* The thumb is not --rule: that hairline colour against --bg is invisible at 4px wide, which
   reads as "the box does not scroll". A tinted track shows the channel; the thumb is dark
   enough to find without being a piece of furniture. */
.conversation::-webkit-scrollbar-track { background: var(--scroll-track); border-radius: 5px; }
.conversation::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 5px;
  border: 2px solid var(--scroll-track);
}
.conversation::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); }
@supports not selector(::-webkit-scrollbar) {
  .conversation { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) var(--scroll-track); }
}

/* A hairline at whichever edge has more conversation past it, so it is clear there is more to
   read even before the scrollbar appears. chat.js toggles the classes. */
.conversation.more-above { border-top: 1px solid var(--rule); }
.conversation.more-below { border-bottom: 1px solid var(--rule); }

.turn { display: flex; flex-direction: column; gap: 10px; position: relative; scroll-margin-top: 16px; }
/* No pointer cursor: the body of a turn is not a control any more. It used to carry the skip
   handler, which fired on the mouseup at the end of a drag-select — so trying to copy an answer
   stopped it instead. Stopping and skipping live on the button at the top right. */
.turn.animating { padding-top: 18px; }
/* Said outright rather than left to the default, so a rule added elsewhere cannot quietly take
   the conversation out of the selection. */
.bubble-user, .answer, .src-tag, .sources {
  -webkit-user-select: text;
  user-select: text;
}
.turn .skip {
  position: absolute;
  top: 0;
  right: 0;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  opacity: 0.8;
}
.turn .skip:hover { color: var(--accent); opacity: 1; }
.bubble-user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--accent-bg);
  color: var(--ink);
  border: 1px solid var(--accent-line);
  padding: 8px 14px;
  border-radius: 14px 14px 4px 14px;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  animation: rise 320ms cubic-bezier(.2,.7,.2,1) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.answer {
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.65;
  color: var(--ink);
}
.answer .caret {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  background: var(--ink);
  margin-left: 1px;
  vertical-align: -2px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.thinking { display: inline-flex; gap: 5px; align-items: center; padding: 4px 0; }
.thinking span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  opacity: 0.4;
  animation: pulse 1.1s ease-in-out infinite;
}
.thinking span:nth-child(2) { animation-delay: 0.18s; }
.thinking span:nth-child(3) { animation-delay: 0.36s; }
@keyframes pulse {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50%      { opacity: 0.9;  transform: translateY(-2px); }
}

.chat-foot {
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px dashed var(--rule);
}
.chips {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
/* Two groups: what Kefei wrote, and what only works with a model loaded. The label is what makes
   the difference legible; without it the second group reads as more of the same. */
.chip-group { display: flex; flex-direction: column; gap: 6px; }
.chip-label {
  margin: 0;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.chip {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.3;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ctrl);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip:active { transform: translateY(1px); }
.chip.asked { color: var(--muted); border-style: dashed; }
/* A question that will actually be generated, marked so it is not mistaken for a stored answer. */
.chip-ai { border-color: var(--accent-line); background: var(--accent-bg); }
.chip-ai:hover { border-color: var(--accent); }
/* Four chips show at first; the rest stay in the DOM with the hidden attribute. Stated here so
   the attribute keeps winning if .chip ever gains an explicit display. */
.chip[hidden] { display: none; }
/* .chips is display:flex, which would otherwise beat the hidden attribute on the panel itself. */
.chips[hidden] { display: none; }
.chips-toggle { align-self: flex-start; padding-left: 0; }
.chips-toggle::after {
  content: " \25be";
  display: inline-block;
  margin-left: 2px;
  transform: rotate(-90deg);
  transition: transform 180ms ease;
}
.chips-toggle[aria-expanded="true"]::after { transform: none; }
.chips-toggle[aria-expanded="true"] { margin-bottom: 8px; }
.chips-more {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 6px 4px;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.chips-more:hover { text-decoration-thickness: 2px; }

/* ---- What a model's Markdown renders as. Weight rather than colour: an answer is body text,
   and a coloured run inside it would read as a link that does not go anywhere. ---- */
.answer strong { font-weight: 600; }
.answer em { font-style: italic; }
.answer code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0 4px;
}

/* ---- Copy the question, or the answer, under each finished turn ---- */
.turn-foot { display: flex; justify-content: flex-end; gap: 4px; margin-top: -4px; }
.copy-btn {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 7px;
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease;
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent-line); }
.copy-btn:focus-visible { color: var(--accent); border-color: var(--accent); }

/* ---- Local AI, at the foot of the page ---- */
/* In normal flow, not fixed and not inside the opening card: the card is display:none once a
   choice has been made, which is exactly when someone wants to read this. */
.localai-note {
  margin: 34px 0 0;
  padding: 20px 0 0;
  border-top: 1px solid var(--rule);
}
.localai-title {
  display: inline;
  margin: 0;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
/* Collapsed by default. The summary is the whole control, with the same chevron the process note
   uses, so the two read as the same kind of thing. */
.localai-details > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  list-style: none;
  border-radius: 4px;
}
.localai-details > summary::-webkit-details-marker { display: none; }
.localai-details > summary::before {
  content: "\25be";
  font-family: var(--sans);
  font-size: 11px;
  color: var(--muted);
  transform: rotate(-90deg);
  transition: transform 180ms ease;
}
.localai-details[open] > summary::before { transform: none; }
.localai-details > summary:hover .localai-title { color: var(--accent); }
.localai-details > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.localai-details[open] > summary { margin-bottom: 12px; }
/* Closed, the section is a single line, and the footer's usual 64px above it reads as a hole.
   Only on this page: classic.html has no such section and keeps its spacing. */
.localai-note + footer { margin-top: 32px; }
.localai-state {
  margin: 0 0 14px;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  max-width: 62ch;
}
.localai-grid { margin: 0; display: grid; gap: 12px; }
.localai-row { display: grid; gap: 2px; }
.localai-row dt {
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
}
.localai-row dd {
  margin: 0;
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--muted);
  max-width: 68ch;
}
.localai-acts { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.localai-acts button {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ctrl);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  transition: border-color 140ms ease, color 140ms ease;
}
.localai-acts button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.localai-acts button:disabled { color: var(--muted); border-style: dashed; cursor: default; }

@media (min-width: 900px) {
  .localai-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 28px; }
}

/* ---- Section heading ---- */
h2.section {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 27px;
  margin: 64px 0 24px;
  line-height: 1.2;
  letter-spacing: -0.005em;
}
h3.section {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 20px;
  margin: 40px 0 14px;
  letter-spacing: -0.005em;
}
/* A heading right after a rule does not need its own 64px of air on top of the rule's. */
hr.rule + section > h2.section:first-child { margin-top: 28px; }

/* ---- Project layers ---- */
.layer { margin-bottom: 36px; }
.layer:last-child { margin-bottom: 0; }
.layer-label { margin: 0 0 18px; }

.project { margin: 0 0 22px; }
.project:last-child { margin-bottom: 0; }
.project .name { font-weight: 600; font-size: 18px; }
.project .pt { font-style: italic; color: var(--muted); margin-left: 6px; }
.project .desc,
.pub .desc { margin: 6px 0 6px; }
.project .meta,
.pub .meta {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  margin: 4px 0 0;
  line-height: 1.5;
}
/* The separators are --muted at half strength: --rule vanishes at 13px on this background. They
   composite to about 2:1 and stay that way on purpose — a middle dot between two meta items is
   decorative under 1.4.3 (delete it and nothing is lost), not text anyone has to read. */
.project .meta .sep,
.pub .pub-links .sep { color: var(--muted); opacity: 0.5; }
.project .repo {
  margin: 4px 0 0;
  font-family: var(--sans);
  font-size: 14px;
}

/* ---- Headline + folded description (native <details>, no JS), on projects and publications ---- */
.project .headline,
.pub .headline {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 400;
  color: var(--ink);
  margin: 4px 0 6px;
}
details.more summary {
  display: inline-block;
  list-style: none;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
details.more summary::-webkit-details-marker { display: none; }
details.more summary:hover { text-decoration-thickness: 2px; }
details.more summary .close { display: none; }
details.more[open] summary .open { display: none; }
details.more[open] summary .close { display: inline; }
details.more .desc { margin: 8px 0 6px; }

/* ---- Publications: thumbnail left, text right; one block on phones (see the 520px query) ---- */
.pub {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  column-gap: 24px;
  align-items: start;
  margin: 0 0 36px;
}
.pub:last-child { margin-bottom: 0; }
.pub-body { min-width: 0; }
.pub-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 19px;
  line-height: 1.3;
  letter-spacing: -0.005em;
  margin: 0 0 6px;
}
.pub .authors { margin: 0 0 4px; font-size: 16px; line-height: 1.5; }
.pub .authors .me { font-weight: 600; }
.pub .authors .eqnote { font-family: var(--sans); font-size: 12.5px; color: var(--muted); }
.pub .venue {
  margin: 0 0 6px;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.5;
}
.pub .pub-links { margin: 0 0 10px; font-family: var(--sans); font-size: 14px; }
.pub .pub-links .sep { margin: 0 4px; }
.thumb { margin: 0; }
.thumb a { display: block; }
/* --frame, not --ctrl, even though the image is wrapped in a link: what identifies that link is
   the picture, not its edge, so this is a frame rather than a control boundary. */
.thumb img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--frame);
  border-radius: 6px;
}
.thumb figcaption {
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
  margin-top: 6px;
}

/* visually hidden, still read by assistive technology */
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Timeline (Experience / Education) ---- */
.timeline {
  display: grid;
  grid-template-columns: 110px 1fr;
  column-gap: 18px;
  row-gap: 8px;
}
.timeline .yrs {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  padding-top: 1px;
  white-space: nowrap;
}
.timeline .row {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.5;
}
.timeline .row .org { font-weight: 500; }
.timeline .row .where {
  color: var(--muted);
  font-style: italic;
  font-size: 15px;
}

/* ---- Links ---- */
a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
a:hover { text-decoration-thickness: 2px; }
a .ext { font-size: 0.78em; margin-left: 2px; }  /* no opacity: 0.7 put this 10.9px glyph at 3.02:1. Size keeps it subordinate. */

/* ---- Footer ---- */
footer {
  margin-top: 64px;
  padding-top: 22px;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.6;
}
footer .note { margin: 0; max-width: 56ch; }
footer .copy { margin: 14px 0 0; font-size: 12.5px; }  /* no opacity: 0.8 put it at 3.52:1 */

@media (max-width: 520px) {
  main { padding: 48px 20px 72px; }
  body { font-size: 17px; }
  .hero h1 { font-size: 30px; }
  .timeline { grid-template-columns: 104px 1fr; column-gap: 12px; }
  .pub { display: block; }
  .pub .thumb { max-width: 220px; margin: 0 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .bubble-user, .think-block .think-step { animation: none; opacity: 1; }
  .copy-btn, .icon-btn, .chips-toggle::after, .localai-details > summary::before { transition: none; }
  .answer .caret, .think-block .think-step .tcaret, .thinking span { animation: none; }
  .think-block .think-head .chev { transition: none; }
}

::selection { background: var(--accent-bg); }


/* ---- Source label on a turn (Written by Kefei / From site notes / Local AI) ---- */
.src-tag { margin: 0; }   /* no opacity: at 0.85 this 11.5px label composited to 3.88:1 */
.turn-static { gap: 6px; }

/* ---- Opening choice card: no box of its own, the two options carry the borders ---- */
.startcard { padding: 4px 0 0; }
.startcard-title {
  margin: 0 0 12px;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
}
.startcard-opts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.opt {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--ctrl);
  border-radius: 8px;
  background: var(--bg);
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
  transition: border-color 140ms ease, color 140ms ease;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { opacity: 0.5; cursor: not-allowed; }
/* `display: block` above outranks the UA sheet's [hidden] rule, so restate it. */
.opt[hidden] { display: none; }
.opt-h {
  display: block;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
}
.opt:hover:not(:disabled) .opt-h { color: var(--accent); }
.opt-d {
  display: block;
  margin-top: 3px;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}
.startcard-note {
  margin: 10px 0 0;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}
.startcard-note:empty { display: none; }
/* A pointer to the permanent section at the foot of the page, which is where the explanation
   lives now. It used to be duplicated here inside a <details>, and the two copies drifted. */
p.startcard-more {
  margin: 10px 0 0;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
}
p.startcard-more a { color: var(--muted); }
p.startcard-more a:hover { color: var(--accent); }
.startcard.done { display: none; }

/* ---- Download the conversation: an icon, so it sits in the header without crowding the status.
   24px is the WCAG 2.2 minimum target; the glyph inside is smaller, the hit area is not. It uses
   currentColor, so the dark theme needs nothing extra. ---- */
.chat-header-right { display: inline-flex; align-items: center; gap: 8px; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent-line); }
.icon-btn:focus-visible { color: var(--accent); border-color: var(--accent); outline: none; }
.icon-btn[hidden] { display: none; }

/* ---- Mode status in the chat header ---- */
#mode-status { text-transform: none; letter-spacing: 0.02em; }
#mode-status .act {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

@media (max-width: 520px) {
  .conversation { max-height: 58vh; }
}

/* ---- Two columns from 900px: the hero is a sticky left column, the content a 720px measure.
   `main` has exactly two children (header.hero and div.content), so the hero's grid area is the
   full page height and it can stick all the way down; align-self: start is what lets it move
   (a stretched item has nowhere to go). ---- */
@media (min-width: 900px) {
  main {
    max-width: 1092px;
    padding: 72px 32px 96px;
    display: grid;
    grid-template-columns: 260px minmax(0, 720px);
    column-gap: 48px;
    align-items: start;
  }
  .hero { position: sticky; top: 72px; align-self: start; }
  .hero .photo { width: 160px; height: auto; border-radius: 20px; margin-bottom: 22px; }
  .hero h1 { font-size: 32px; }
  .contact { flex-direction: column; align-items: flex-start; gap: 6px; }
  .content > hr.rule:first-child { display: none; }
  section.chat { margin-top: 0; }
  .conversation { max-height: min(64vh, 720px); }   /* the hero no longer sits above the chat */
}

/* ---- Where an answer came from (built from the matched notes, never from model output) ---- */
.sources {
  margin: 2px 0 0;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
}
.sources a { color: var(--accent); }

/* ---- Dark theme: follows the system, no toggle (classic.html loads no script and keeps it).
   Only the tokens are redefined; every component already draws from them. Warm on both grounds —
   neutrals near hue 80, the accent 62-68 — so the two themes read as one identity. Deliberately
   not #000 and not #fff: the halation the optics literature actually predicts is worst at the
   extremes, and #eae8e3 on #191713 is already 14.62:1.

   prefers-color-scheme, not light-dark(): that function was 83% supported when this shipped, and
   an unsupporting browser drops the whole declaration, leaving the custom property with no value
   at all. Revisit once it is Baseline widely available. ---- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191713;
    --surface: #23201c;
    --ink: #eae8e3;              /* 14.62 on --bg */
    --muted: #a29e98;            /* 6.72 */
    --rule: #39352f;             /* dividers; 1.47 — decorative, and meant to be barely there */
    --ctrl: #736e65;             /* oklch(0.54 0.015 80): 3.53 on --bg, 3.20 on --surface.
                                    The harder side flips here: --surface is LIGHTER than --bg on
                                    this ground, so it is the one that sets the floor (L 0.5246). */
    --frame: #524c43;            /* 2.11 on the page, but ~9.7:1 against the screenshots it edges —
                                    that is the job: a dark line between a bright picture and a dark
                                    page. --rule would vanish (1.47) and --ctrl is a control's weight.
                                    The hero portrait deliberately gets NO frame: measured, it is a
                                    *lighter* object than this ground (edge 2.42:1), so it already
                                    draws its own boundary, and a line between them lands at 1.15:1
                                    against the photo's own edge — invisible, and solving nothing. */
    --scroll-track: #262420;
    --scroll-thumb: #716d66;
    --scroll-thumb-hover: #8a857c;
    --accent: oklch(0.78 0.085 68);       /* 8.82 */
    --accent-line: oklch(0.42 0.05 62);
    --accent-bg: oklch(0.30 0.035 62);    /* --ink on it: 11.22 */
  }

  /* The two publication thumbnails are light-background screenshots; on this ground they are the
     brightest thing on the page (edge 14.14:1 and 12.09:1 — a bigger step than the body text
     makes). 0.92 is derived, not picked: 234/255 puts their white at 15.01:1, level with --ink's
     14.62:1, so the picture never out-shines the page's own brightest text. It is Apple's
     "slightly", and it costs a 4.5:1 label inside the screenshot only 0.2 of a ratio point.

     Not grayscale() and not a heavier dim: firefair-statewide.jpg is a choropleth by
     social-vulnerability quintile, where hue IS the datum. The visible work of making these read
     as mounted figures rather than holes is done by --frame above; this only caps the peak. */
  .thumb img { filter: brightness(0.92); }
}

/* A filter is an effect, and forced-colors / prefers-contrast: more are requests to strip effects.
   Without this the dim lands on exactly the readers who asked for more contrast, not less. */
@media (forced-colors: active), (prefers-contrast: more) {
  .thumb img { filter: none; }
}

/* ---- Print. The profile is the page someone prints, and a printed dark theme is either a black
   rectangle or invisible ink. Chrome happens to force prefers-color-scheme: light when printing,
   but that is undocumented behaviour this file should not depend on, so the light tokens are
   restated here and the scroll box is unclipped. ---- */
@media print {
  :root {
    --bg: #fff;
    --surface: #fff;
    --ink: #1a1a1a;
    --muted: #4a4944;          /* darker than screen --muted: paper has no backlight */
    --rule: #bbb;
    --ctrl: #999;
    --frame: #bbb;
    --accent: #5c3a1a;
    --accent-line: #bbb;
    --accent-bg: #fff;
  }
  .thumb img { filter: none; }
  /* The conversation is a max-height scroll box on screen; on paper that clips the transcript. */
  .conversation { max-height: none; overflow: visible; }
  /* Controls do not print: nothing on paper can be typed into or clicked. */
  .chat-input, .chips, .chat-foot, .startcard, .turn .skip, .switch,
  .localai-acts, .localai-state, .turn-foot, .icon-btn, .chips-toggle { display: none; }
  .localai-grid { grid-template-columns: 1fr; }
  a { text-decoration: underline; }
  main { max-width: none; padding: 0; }
}

/* A notes answer is a lead line plus one or two summaries; keep the line breaks the router made. */
.answer { white-space: pre-line; }
