@font-face { font-family: "Archivo"; src: url("fonts/archivo.woff2") format("woff2"); font-weight: 100 900; font-stretch: 62% 125%; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }

/* Cool grey paper, dark ink, and Keep's amber used only to mark where a search hit. */
:root {
  color-scheme: light;
  --bg: #e9edf1;
  --panel: #f8fafb;
  --raised: #ffffff;
  --ink: #17202a;
  --muted: #5a6573;
  --line: #d3d9e0;
  --amber: #f5b400;
  --amber-soft: #ffe7a3;
  --focus: #0b63c5;
  --danger: #b0332a;
  --text: "Atkinson Hyperlegible", system-ui, sans-serif;
  --display: "Archivo", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12171d;
    --panel: #1a2129;
    --raised: #212a34;
    --ink: #e6ebf0;
    --muted: #9aa6b4;
    --line: #2e3945;
    --amber: #f5b400;
    --amber-soft: #5a4300;
    --focus: #6aa8ff;
    --danger: #ff8a80;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12171d; --panel: #1a2129; --raised: #212a34; --ink: #e6ebf0; --muted: #9aa6b4;
  --line: #2e3945; --amber: #f5b400; --amber-soft: #5a4300; --focus: #6aa8ff; --danger: #ff8a80;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 17px/1.5 var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
mark { background: var(--amber-soft); color: inherit; border-bottom: 2px solid var(--amber); padding: 0 1px; }
[hidden] { display: none !important; }

/* ── Top bar ── */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); }
.top-inner { max-width: 1400px; margin: 0 auto; padding: 14px 20px; display: grid; grid-template-columns: auto 1fr auto; gap: 12px 20px; align-items: center; }
.brand { font: 800 26px/1 var(--display); font-stretch: 118%; letter-spacing: -0.01em; margin: 0; }
.brand span { color: var(--muted); font-weight: 500; font-stretch: 100%; font-size: 15px; letter-spacing: 0; margin-left: 8px; }
.query { display: flex; gap: 8px; }
.query input, .query textarea { flex: 1; min-width: 0; padding: 12px 16px; border: 2px solid var(--line); border-radius: 12px; background: var(--raised); font-size: 18px; resize: none; }
.query input:focus, .query textarea:focus { border-color: var(--ink); outline: none; }
.btn { padding: 10px 18px; border: 2px solid var(--ink); border-radius: 12px; background: var(--ink); color: var(--bg); font-weight: 700; cursor: pointer; }
.btn.quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.modes { display: inline-flex; border: 2px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; background: var(--panel); }
.modes button { border: 0; background: none; padding: 7px 14px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 700; }
.modes button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.top-actions { display: flex; gap: 10px; align-items: center; }

/* ── Layout ── */
.layout { max-width: 1400px; margin: 0 auto; padding: 18px 20px 60px; display: grid; grid-template-columns: 230px minmax(0, 1fr) minmax(0, 1.05fr); gap: 24px; align-items: start; }
.layout.no-note { grid-template-columns: 230px minmax(0, 1fr); }

/* ── Filters ── */
.filters { position: sticky; top: 92px; max-height: calc(100vh - 110px); overflow: auto; font-size: 15px; padding-right: 4px; }
.filters h2 { font: 700 13px/1.2 var(--text); color: var(--muted); margin: 18px 0 8px; }
.filters h2:first-child { margin-top: 4px; }
.facet { list-style: none; margin: 0; padding: 0; }
.facet button { width: 100%; display: flex; justify-content: space-between; gap: 8px; text-align: left; border: 0; background: none; padding: 4px 8px; border-radius: 8px; cursor: pointer; }
.facet button:hover { background: var(--panel); }
.facet button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.facet .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.facet button[aria-pressed="true"] .n { color: inherit; opacity: 0.75; }
.facet.more li:nth-child(n+13) { display: none; }
.facet.more.open li { display: list-item; }
.linkish { border: 0; background: none; color: var(--muted); text-decoration: underline; padding: 4px 8px; cursor: pointer; font-size: 14px; }
.dates { display: grid; gap: 6px; }
.dates label { display: grid; grid-template-columns: 40px 1fr; align-items: center; gap: 6px; color: var(--muted); }
.dates input, .filters select { width: 100%; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); }
.check { display: flex; gap: 8px; align-items: center; color: var(--muted); margin-top: 6px; }

/* ── Timeline: notes per year, the signature of the archive ── */
.timeline { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; align-items: end; height: 92px; margin: 0 0 6px; }
.timeline button { position: relative; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; border: 0; padding: 0; background: none; cursor: pointer; }
.timeline .bar { display: block; background: var(--line); border-radius: 4px 4px 0 0; min-height: 3px; }
.timeline button:hover .bar { background: var(--muted); }
.timeline button[aria-pressed="true"] .bar { background: var(--amber); }
.timeline-years { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 16px; font-variant-numeric: tabular-nums; }

/* ── Results ── */
.status { color: var(--muted); font-size: 15px; margin: 2px 0 12px; min-height: 1.5em; }
.status.error { color: var(--danger); }
.results { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card { display: block; width: 100%; text-align: left; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); padding: 12px 16px; cursor: pointer; }
.card:hover { border-color: var(--muted); }
.card[aria-current="true"] { border-color: var(--ink); box-shadow: inset 4px 0 0 var(--amber); }
.card h3 { margin: 0 0 4px; font-size: 17px; line-height: 1.3; }
.card h3.untitled { color: var(--muted); font-weight: 400; }
.card p { margin: 0; color: var(--ink); font-size: 15px; white-space: pre-line; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.label-chip { border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; background: none; font-size: inherit; color: inherit; }
button.label-chip { cursor: pointer; }
button.label-chip:hover { border-color: var(--muted); color: var(--ink); }
.more-btn { margin-top: 14px; }

/* ── Ask ── */
.answer { background: var(--raised); border: 1px solid var(--line); border-left: 5px solid var(--amber); border-radius: 12px; padding: 16px 20px; margin-bottom: 18px; }
.answer p { margin: 0 0 0.7em; white-space: pre-line; }
.answer p:last-child { margin-bottom: 0; }
.cite { border: 0; background: var(--amber-soft); border-radius: 6px; padding: 0 6px; font-size: 13px; font-weight: 700; cursor: pointer; vertical-align: 1px; }
.sources-head { font: 700 14px/1.2 var(--text); color: var(--muted); margin: 0 0 8px; }
.hint { color: var(--muted); font-size: 15px; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.examples button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 14px; }

/* ── Note pane ── */
.note { position: sticky; top: 92px; max-height: calc(100vh - 110px); overflow: auto; background: var(--raised); border: 1px solid var(--line); border-radius: 14px; padding: 20px 24px 24px; }
.note-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.note h2 { font: 800 24px/1.2 var(--display); font-stretch: 105%; margin: 0 0 6px; overflow-wrap: anywhere; }
.note h2.untitled { color: var(--muted); font-weight: 500; }
.note .body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 16px 0 0; line-height: 1.6; }
.note .links, .note .similar { margin-top: 22px; }
.note h3 { font: 700 14px/1.2 var(--text); color: var(--muted); margin: 0 0 8px; }
.note .links ul { margin: 0; padding-left: 1.1em; }
.note .links a { color: var(--focus); overflow-wrap: anywhere; }
.note img { display: block; max-width: 100%; height: auto; border-radius: 10px; margin-top: 14px; border: 1px solid var(--line); }
.close { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; width: 38px; height: 38px; font-size: 20px; line-height: 1; cursor: pointer; flex: none; }
.similar .results { gap: 8px; }
.similar .card { padding: 10px 14px; }
.similar .card p { -webkit-line-clamp: 2; }

/* ── Login ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: grid; gap: 14px; }
.login h1 { font: 800 32px/1 var(--display); font-stretch: 118%; margin: 0 0 4px; }
.login input { padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; background: var(--raised); }
.login .err { color: var(--danger); margin: 0; }

/* ── Small screens: one column, note opens over the list ── */
@media (max-width: 1100px) {
  .layout, .layout.no-note { grid-template-columns: 200px minmax(0, 1fr); }
  .note { position: fixed; inset: 0; top: 0; max-height: none; border-radius: 0; z-index: 10; padding: 16px; }
}
@media (max-width: 760px) {
  body { font-size: 16px; }
  .top-inner { grid-template-columns: 1fr auto; padding: 10px 16px; }
  .top-actions { display: contents; }
  .top-actions form { grid-column: 2; grid-row: 1; }
  .query { grid-column: 1 / -1; grid-row: 2; min-width: 0; }
  .modes { grid-column: 1 / -1; grid-row: 3; justify-self: start; }
  .top-actions .btn.quiet { padding: 6px 10px; }
  .brand span { display: block; margin: 4px 0 0; font-size: 13px; }
  .layout, .layout.no-note { grid-template-columns: 1fr; padding: 12px 16px 40px; }
  .filters { position: static; max-height: none; }
  .filters[data-collapsed="true"] .filter-body { display: none; }
  .timeline { height: 64px; }
}
@media (min-width: 761px) { .filter-toggle { display: none; } }
@media (prefers-reduced-motion: no-preference) {
  .card, .facet button, .timeline .bar { transition: background-color 120ms, border-color 120ms; }
}

/* Suggested labels: dashed so they never pass for real Keep labels */
.label-chip.suggested { border-style: dashed; font-style: italic; }
.facet .plus { opacity: 0.8; font-style: italic; }
.facet button.unlabeled > span:first-child { font-style: italic; }
.check.switch { margin: 0 0 8px; }
.facet.more li:nth-child(n+14) { display: none; }
.facet.more.open li { display: list-item; }

/* Ask about one note */
.note-ask { display: flex; gap: 8px; margin-top: 16px; }
.note-ask input { flex: 1; min-width: 0; padding: 9px 12px; border: 2px solid var(--line); border-radius: 10px; background: var(--panel); }
.note-ask input:focus { border-color: var(--ink); outline: none; }
.note-ask .btn { padding: 8px 14px; }
.note-answer .answer { margin: 12px 0 0; }
.note-answer .hint, .note-answer .status { margin: 10px 0 0; }

/* Conversations */
.turn { margin-bottom: 14px; }
.turn-q { font-weight: 700; margin: 0 0 6px; }
.turn-q::before { content: "You asked: "; color: var(--muted); font-weight: 400; }
.followup { margin: 0 0 18px; align-items: center; flex-wrap: wrap; }
.note-convo { margin-top: 16px; }
.note-convo .note-answer .turn:first-child { margin-top: 0; }
.note-convo .note-ask { margin-top: 10px; }
