:root {
  --paper: #f5f1e9;
  --paper-deep: #e9e1d4;
  --ink: #1d2722;
  --ink-soft: #39433d;
  --muted: #69736d;
  --line: #d6cec0;
  --line-strong: #a99f90;
  --card: #fcfaf6;
  --accent: #c54d31;
  --accent-soft: #f0d8cd;
  --green: #55745d;
  --shadow: 0 22px 60px rgba(55, 48, 38, 0.11);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --sans: 'Manrope', 'Segoe UI', sans-serif;
  --serif: 'Newsreader', Georgia, serif;
  --mono: 'DM Mono', Consolas, monospace;
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; background: var(--paper); color: var(--ink); color-scheme: light; }
body {
  min-width: 320px;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 85% 2%, rgba(197, 77, 49, 0.09), transparent 30rem),
    radial-gradient(circle at 8% 52%, rgba(85, 116, 93, 0.06), transparent 25rem),
    var(--paper);
  font-family: var(--sans);
  text-rendering: optimizeLegibility;
}
body.drawer-open { overflow: hidden; }
::selection { background: var(--ink); color: var(--paper); }
button, input, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
a { color: inherit; }
button { color: inherit; }
*[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: fixed;
  z-index: 20;
  top: 12px;
  left: 12px;
  transform: translateY(-180%);
  padding: 10px 13px;
  background: var(--ink);
  color: var(--paper);
  font: 11px var(--mono);
  text-decoration: none;
}
.skip-link:focus-visible { transform: translateY(0); }

.site-shell { width: min(1540px, 100%); margin: 0 auto; padding: 0 48px 36px; }
.topbar {
  position: sticky;
  z-index: 4;
  top: 0;
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 90%, transparent);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(16px);
}
.brand { display: inline-flex; gap: 12px; align-items: center; min-width: 0; text-decoration: none; }
.brand-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  font: 500 11px var(--mono);
  letter-spacing: -0.08em;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 13px; letter-spacing: 0.02em; }
.brand small { margin-top: 3px; color: var(--muted); font: 10px var(--mono); text-transform: uppercase; letter-spacing: 0.08em; }
.sync-pill { display: flex; gap: 8px; align-items: center; color: var(--muted); font: 11px var(--mono); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.sync-pill[data-state="ready"] .status-dot { background: var(--green); box-shadow: 0 0 0 4px rgba(85, 116, 93, 0.12); }
.sync-pill[data-state="error"] .status-dot { background: var(--accent); }

.intro { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 48px; padding: 86px 0 68px; }
.intro::after {
  position: absolute;
  right: 3%;
  bottom: 17px;
  color: rgba(197, 77, 49, 0.08);
  content: '01';
  font: 500 170px/0.8 var(--serif);
  letter-spacing: -0.12em;
  pointer-events: none;
}
.eyebrow, .field-label, .search-label, .sync-label { margin: 0; color: var(--accent); font: 500 10px var(--mono); letter-spacing: 0.14em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 {
  max-width: 790px;
  margin-bottom: 22px;
  font: 500 clamp(50px, 7vw, 100px)/0.91 var(--serif);
  letter-spacing: -0.06em;
  text-wrap: balance;
}
.intro-text { max-width: 570px; margin-bottom: 0; color: var(--muted); font-size: 15px; line-height: 1.75; text-wrap: pretty; }
.intro-aside { align-self: end; padding: 16px 0 5px 26px; border-left: 1px solid var(--line); }
.intro-copy, .intro-aside { opacity: 0; transform: translateY(12px); animation: intro-reveal 520ms var(--ease-out) both; }
.intro-aside { animation-delay: 80ms; }
.intro-aside strong { display: block; margin: 9px 0 13px; font: 500 21px var(--serif); }
.intro-aside a { color: var(--ink); font-size: 12px; text-underline-offset: 4px; }
.intro-aside a:hover { color: var(--accent); }

.stat-strip { display: grid; grid-template-columns: repeat(3, 1fr) 2fr; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--line); }
.stat-block { min-height: 96px; padding: 19px 24px 16px 0; border-right: 1px solid var(--line); }
.stat-block + .stat-block { padding-left: 24px; }
.stat-block:last-child { border-right: 0; padding-right: 0; }
.stat-value { display: block; font: 500 30px var(--serif); font-variant-numeric: tabular-nums; }
.stat-label { display: block; margin-top: 6px; color: var(--muted); font: 10px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }
.stat-note { display: flex; flex-direction: column; justify-content: center; align-items: flex-end; }
.stat-note strong { font: 500 17px var(--serif); }

.workspace { display: grid; grid-template-columns: 238px minmax(0, 1fr); gap: 54px; padding-top: 54px; }
.sidebar { min-width: 0; }
.sidebar-section { padding: 0 0 27px; margin-bottom: 25px; border-bottom: 1px solid var(--line); }
.search-section { padding-bottom: 23px; }
.search-box { position: relative; display: flex; align-items: center; margin-top: 12px; border-bottom: 1px solid var(--ink); }
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 2px 0 var(--accent); }
.search-icon { position: absolute; left: 0; color: var(--accent); font: 500 16px var(--mono); }
#search-input { width: 100%; min-width: 0; padding: 9px 31px 10px 21px; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 13px; }
#search-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
#search-input::placeholder { color: #9a948a; }
.icon-button { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; font: 16px/1 var(--mono); transition: transform 120ms var(--ease-out), background-color 160ms ease, color 160ms ease; }
.icon-button:hover { background: var(--paper-deep); color: var(--ink); }
.search-box .icon-button { position: absolute; right: 0; }
.search-hint { margin: 10px 0 0 21px; color: var(--muted); font-size: 10px; }
kbd { padding: 2px 5px; border: 1px solid var(--line); border-bottom-color: var(--line-strong); border-radius: 3px; font: 10px var(--mono); }
.field-label { color: var(--muted); letter-spacing: 0.08em; }
select {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 9px 23px 9px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  outline: 0;
  background-color: var(--paper);
  color: var(--ink);
  font-size: 12px;
  cursor: pointer;
}
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.section-count, .results-count { color: var(--muted); font: 10px var(--mono); font-variant-numeric: tabular-nums; }
.topic-list { display: grid; gap: 2px; margin-top: 12px; }
.topic-button { display: flex; align-items: baseline; justify-content: space-between; width: 100%; padding: 7px 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; text-align: left; font-size: 11px; transition: transform 120ms var(--ease-out), color 160ms ease; }
.topic-button:hover, .topic-button.is-active { color: var(--accent); }
.topic-button.is-active { padding-left: 9px; border-left: 2px solid var(--accent); }
.topic-button span:last-child { font: 10px var(--mono); font-variant-numeric: tabular-nums; }

.results-panel { min-width: 0; }
.results-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 25px; }
h2 { margin: 7px 0 0; font: 500 clamp(38px, 4vw, 48px)/0.98 var(--serif); letter-spacing: -0.045em; text-wrap: balance; }
.active-filters { display: flex; flex-wrap: wrap; gap: 7px; margin: -8px 0 22px; }
.filter-chip { display: inline-flex; gap: 8px; align-items: center; padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 10px; }
.filter-chip button { padding: 0; border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; }
.results-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.bookmark-card {
  min-height: 282px;
  display: flex;
  flex-direction: column;
  padding: 21px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--card);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  cursor: pointer;
  text-align: left;
  content-visibility: auto;
  contain-intrinsic-size: 282px;
  transition: transform 180ms var(--ease-out);
}
.bookmark-card:nth-child(4n) { background: #f8f3ea; }
.card-top { display: flex; justify-content: space-between; gap: 8px; min-width: 0; }
.card-topic { overflow: hidden; color: var(--accent); font: 10px var(--mono); letter-spacing: 0.06em; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.card-year { flex: 0 0 auto; color: var(--muted); font: 10px var(--mono); font-variant-numeric: tabular-nums; }
.card-author { margin: 25px 0 12px; overflow: hidden; color: var(--muted); font: 11px var(--mono); text-overflow: ellipsis; white-space: nowrap; }
.card-title { display: -webkit-box; overflow: hidden; margin: 0 0 10px; font: 500 25px/1.03 var(--serif); letter-spacing: -0.027em; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.card-excerpt { display: -webkit-box; overflow: hidden; margin: 0; color: var(--ink-soft); font-size: 12px; line-height: 1.58; -webkit-box-orient: vertical; -webkit-line-clamp: 4; }
.card-bottom { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; margin-top: auto; padding-top: 21px; color: var(--muted); font: 10px var(--mono); }
.card-link { min-width: 0; overflow: hidden; color: var(--accent); text-overflow: ellipsis; white-space: nowrap; }
.load-more { display: block; margin: 31px auto 0; padding: 12px 18px; border: 1px solid var(--ink); background: transparent; color: var(--ink); cursor: pointer; font: 10px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; transition: transform 120ms var(--ease-out), background-color 160ms ease, color 160ms ease; }
.load-more:hover { background: var(--ink); color: var(--paper); }
.empty-state, .error-state { padding: 86px 20px; text-align: center; }
.empty-mark { display: block; margin-bottom: 12px; color: var(--accent); font: 34px var(--serif); }
.empty-state h3, .error-state h3 { margin-bottom: 8px; font: 500 29px var(--serif); text-wrap: balance; }
.empty-state p, .error-state p { max-width: 390px; margin-right: auto; margin-left: auto; color: var(--muted); font-size: 12px; line-height: 1.6; }

.footer { display: flex; justify-content: space-between; gap: 20px; margin-top: 82px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font: 10px var(--mono); letter-spacing: 0.06em; text-transform: uppercase; }
.footer a { text-underline-offset: 3px; }
.footer a:hover { color: var(--accent); }

.drawer-backdrop { position: fixed; inset: 0; z-index: 5; background: rgba(29, 39, 34, 0.42); opacity: 0; pointer-events: none; backdrop-filter: blur(3px); transition: opacity 220ms var(--ease-out); }
.drawer-backdrop.is-open { opacity: 1; pointer-events: auto; }
.detail-drawer {
  position: fixed;
  z-index: 6;
  top: 0;
  right: 0;
  width: min(590px, 100%);
  height: 100vh;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 31px 38px 54px;
  background: var(--card);
  box-shadow: -24px 0 70px rgba(30, 27, 20, 0.2);
  opacity: 0;
  transform: translateX(100%);
  transition: transform 280ms var(--ease-drawer), opacity 220ms var(--ease-out);
}
.detail-drawer.is-open { opacity: 1; transform: translateX(0); }
.drawer-header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.drawer-title { margin: 43px 0 12px; font: 500 47px/0.98 var(--serif); letter-spacing: -0.05em; text-wrap: balance; }
.drawer-author { margin-bottom: 29px; color: var(--muted); font: 11px var(--mono); }
.drawer-text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink-soft); font-size: 14px; line-height: 1.78; }
.drawer-meta { display: flex; flex-wrap: wrap; gap: 9px 17px; margin: 31px 0; padding: 17px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); font: 10px var(--mono); }
.drawer-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.drawer-actions a { padding: 10px 13px; border: 1px solid var(--ink); color: var(--ink); text-decoration: none; font: 10px var(--mono); transition: transform 120ms var(--ease-out), background-color 160ms ease, color 160ms ease; }
.drawer-actions a:hover { background: var(--ink); color: var(--paper); }
.drawer-links { display: grid; gap: 8px; margin-top: 29px; }
.drawer-links a { overflow-wrap: anywhere; color: var(--accent); font-size: 12px; line-height: 1.4; }
.quote-card { margin-top: 31px; padding: 18px; border-left: 2px solid var(--accent); background: var(--paper); }
.quote-label { margin-bottom: 8px; color: var(--accent); font: 10px var(--mono); text-transform: uppercase; }
.quote-card p { margin-bottom: 8px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.quote-card small { color: var(--ink); font: 10px var(--mono); }
.noscript-message { max-width: 600px; margin: 24px auto; padding: 14px 18px; border: 1px solid var(--accent); background: var(--card); color: var(--ink); font-size: 13px; }

:where(a, button, input, select):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
select:focus-visible { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 3px; }

.results-grid.is-entering { animation: results-reveal 220ms var(--ease-out) both; }
.bookmark-card:active { transform: translateY(-1px) scale(0.99); }
.load-more:active, .icon-button:active, .topic-button:active, .filter-chip button:active, .drawer-actions a:active { transform: scale(0.97); }

@media (hover: hover) and (pointer: fine) {
  .bookmark-card:hover { transform: translateY(-4px); border-color: var(--line-strong); background: #fffdfa; box-shadow: var(--shadow); }
}

@keyframes intro-reveal {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes results-reveal {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1100px) {
  .site-shell { padding-right: 30px; padding-left: 30px; }
  .results-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace { gap: 35px; }
}

@media (max-width: 760px) {
  .site-shell { padding: 0 18px 24px; }
  .topbar { min-height: 72px; }
  .sync-pill { font-size: 9px; }
  .intro { display: block; padding: 57px 0 44px; }
  .intro::after { right: 0; bottom: 20px; font-size: 110px; }
  h1 { max-width: 620px; font-size: clamp(52px, 15vw, 84px); }
  .intro-aside { margin-top: 38px; padding: 15px 0 0; border-top: 1px solid var(--line); border-left: 0; }
  .stat-strip { grid-template-columns: repeat(2, 1fr); }
  .stat-block, .stat-block + .stat-block { padding: 16px 12px 15px 0; }
  .stat-block:nth-child(2n) { padding-left: 12px; border-right: 0; }
  .stat-note { align-items: flex-start; grid-column: span 2; border-top: 1px solid var(--line); }
  .workspace { display: block; padding-top: 35px; }
  .sidebar { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 17px; margin-bottom: 41px; }
  .search-section, .topic-section { grid-column: span 2; }
  .sidebar-section { margin-bottom: 18px; padding-bottom: 18px; }
  .results-grid { grid-template-columns: 1fr; }
  .results-toolbar { align-items: start; }
  h2 { font-size: 36px; }
  .footer { display: grid; gap: 8px; margin-top: 54px; }
  .detail-drawer { padding: 25px 20px 42px; }
  .drawer-title { font-size: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
  .intro-copy, .intro-aside, .results-grid.is-entering { opacity: 1; transform: none; animation: none; }
  .drawer-backdrop { transition: opacity 160ms ease; }
  .detail-drawer { transform: none; transition: opacity 160ms ease; }
  .detail-drawer.is-open { transform: none; }
}
