:root {
  --paper: #f6f0e4;
  --paper-deep: #ebe2d1;
  --ink: #171512;
  --muted: #655d52;
  --rule: #cfc4b2;
  --rule-strong: #857763;
  --control-border: #857763;
  --accent: #8f2d25;
  --accent-hover: #74231c;
  --accent-ink: #fffaf2;
  --green: #1f5b45;
  --surface: #fffaf1;
  --surface-hover: rgba(255, 250, 241, 0.6);
  --prose-ink: #3b362e;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --max: 1180px;
  --radius: 6px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
img { max-width: 100%; display: block; }
button, input, select { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, .wordmark { font-family: var(--serif); font-weight: 600; letter-spacing: -0.02em; }
h1 { font-size: 48px; font-size: clamp(2.35rem, 5vw, 4.6rem); line-height: 1.02; margin: 0 0 1rem; max-width: 18ch; }
h2 { font-size: 32px; font-size: clamp(1.55rem, 2.6vw, 2.35rem); line-height: 1.1; margin: 0 0 0.7rem; }
h3 { font-size: 1.22rem; line-height: 1.2; margin: 0; }
p { margin: 0 0 0.85rem; }
.shell { width: min(var(--max), calc(100% - 40px)); margin: 0 auto; }
.small { color: var(--muted); font-size: 0.88rem; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.18em; font-size: 0.72rem; font-weight: 700; color: var(--accent); margin-bottom: 0.55rem; }
.lede { font-size: 1.12rem; color: var(--muted); max-width: 62ch; }
.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: absolute; left: 12px; top: -60px; background: var(--ink); color: var(--paper); padding: 10px 14px; z-index: 100; }
.skip-link:focus { top: 12px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.site-header { border-bottom: 1px solid var(--rule); background: var(--paper); position: sticky; top: 0; z-index: 40; }
.header-inner { min-height: 70px; display: flex; align-items: center; gap: 26px; }
.wordmark { display: inline-flex; align-items: center; gap: 10px; font-size: 1.05rem; text-decoration: none; white-space: nowrap; }
.wordmark-mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--ink); border-radius: 50%; font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.06em; }
.nav-list { display: flex; gap: 20px; list-style: none; margin: 0; padding: 0; }
.nav-list a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 2px; text-decoration: none; font-size: 0.9rem; color: var(--muted); }
.nav-list a:hover { color: var(--ink); }
.header-search { margin-left: auto; display: flex; gap: 6px; }
.header-search input { width: 220px; border: 1px solid var(--control-border); background: var(--surface); padding: 9px 11px; border-radius: var(--radius); }
.header-search button, .search-field button { border: 1px solid var(--ink); background: var(--ink); color: var(--paper); padding: 10px 16px; min-height: 44px; border-radius: var(--radius); }
.header-search button { padding: 9px 12px; }

.hero { padding: clamp(48px, 8vw, 100px) 0 60px; border-bottom: 1px solid var(--rule); }
.hero-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.7fr); gap: clamp(30px, 5vw, 80px); align-items: end; }
.hero-copy { font-size: 1.15rem; color: var(--muted); max-width: 66ch; }
.hero-note { border-left: 3px solid var(--accent); padding: 4px 0 4px 20px; }
.hero-note ol { margin: 0 0 1rem; padding-left: 1.2rem; color: var(--muted); }
.hero-note li { margin-bottom: 0.35rem; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; }
.hero-stats span { border: 1px solid var(--rule); padding: 8px 12px; background: var(--surface); font-size: 0.82rem; color: var(--muted); }
.hero-stats strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.search-form { margin: 28px 0 0; }
.search-field { display: flex; gap: 8px; max-width: 760px; }
.search-field input { flex: 1; min-width: 0; border: 2px solid var(--ink); background: var(--surface); padding: 15px 16px; border-radius: var(--radius); font-size: 1.05rem; }
.search-field button { padding: 15px 20px; }
.search-hint { font-size: 0.82rem; color: var(--muted); margin-top: 8px; }

.section { padding: clamp(42px, 6vw, 76px) 0; }
.section-tinted { background: var(--paper-deep); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.section-head { margin-bottom: 26px; }
.section-head h2 { max-width: 22ch; }
.section-link { margin-top: 24px; }
.section-link a { font-weight: 700; }

.genre-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; border-top: 1px solid var(--rule); border-left: 1px solid var(--rule); }
.genre-tile { display: flex; flex-direction: column; gap: 4px; min-height: 112px; padding: 20px; border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); text-decoration: none; background: transparent; }
.genre-tile strong { font-family: var(--serif); font-size: 1.25rem; }
.genre-tile span { color: var(--muted); font-size: 0.85rem; }
.genre-tile:hover { background: var(--surface); }

.book-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.book-card { display: grid; grid-template-columns: 4px 1fr; gap: 16px; background: var(--surface); border: 1px solid var(--rule); padding: 18px; min-height: 170px; }
.book-card-rule { background: var(--accent); }
.book-card h3 a { text-decoration: none; }
.book-card h3 a:hover { text-decoration: underline; }
.card-eyebrow { font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.card-author { color: var(--muted); font-size: 0.9rem; }
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; }
.badge { display: inline-flex; align-items: center; border: 1px solid var(--rule); padding: 3px 8px; font-size: 0.72rem; letter-spacing: 0.04em; color: var(--muted); background: var(--paper); }
.badge-free { border-color: var(--green); color: var(--green); }
.badge-paid { border-color: var(--accent); color: var(--accent); }
.badge-rating { border-color: var(--ink); color: var(--ink); }
.badge-genre { background: transparent; }
.card-rating { margin-left: auto; font-size: 0.82rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.two-col { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr); gap: clamp(28px, 5vw, 70px); align-items: start; }
.paid-card { display: grid; gap: 18px; background: var(--surface); color: var(--ink); padding: clamp(22px, 3vw, 34px); border: 1px solid var(--rule-strong); border-top: 4px solid var(--accent); border-radius: var(--radius); }
.paid-card h2 { color: var(--ink); }
.paid-card p { color: var(--muted); }
.paid-card .eyebrow { color: var(--accent); }
.paid-card .disclosure { font-size: 0.78rem; color: var(--muted); }
.paid-card .text-link { color: var(--accent); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: var(--radius); text-decoration: none; font-weight: 700; font-size: 0.9rem; border: 1px solid transparent; width: fit-content; }
.button-primary { background: var(--accent); color: var(--accent-ink); }
.button-primary:hover { background: var(--accent-hover); color: var(--accent-ink); }
.button-secondary { background: transparent; border-color: var(--ink); color: var(--ink); }
.button-secondary:hover { background: var(--ink); color: var(--paper); }
.button-paid { background: transparent; border-color: var(--accent); color: var(--accent); }
.button-paid:hover { background: var(--accent); color: var(--accent-ink); }
.text-link { display: inline-flex; align-items: center; min-height: 44px; font-size: 0.9rem; margin-right: 12px; }
.link-button { border: 0; background: transparent; color: var(--muted); text-decoration: underline; padding: 12px 0; }

.faq-list { border-top: 1px solid var(--rule); }
.faq-list details { border-bottom: 1px solid var(--rule); padding: 16px 0; }
.faq-list summary { cursor: pointer; font-weight: 700; }
.faq-list p { margin: 10px 0 0; color: var(--muted); max-width: 75ch; }

.page-head { padding: clamp(40px, 6vw, 72px) 0 26px; border-bottom: 1px solid var(--rule); margin-bottom: 32px; }
.page-head h1 { font-size: clamp(2.1rem, 4vw, 3.6rem); }
.search-page { padding: clamp(40px, 6vw, 72px) 0 60px; }
.search-form-compact { margin: 0; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin: 20px 0 10px; padding: 14px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.filter-field { display: grid; gap: 4px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.filter-field select { min-width: 150px; min-height: 44px; padding: 8px 10px; border: 1px solid var(--rule-strong); background: var(--surface); border-radius: var(--radius); }
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; border: 1px solid var(--rule-strong); background: var(--surface); padding: 9px 12px; border-radius: var(--radius); color: var(--muted); }
.toggle span { width: 28px; height: 16px; border-radius: 999px; background: var(--rule-strong); position: relative; }
.toggle span::after { content: ""; position: absolute; width: 12px; height: 12px; top: 2px; left: 2px; border-radius: 50%; background: var(--surface); transition: transform 120ms ease; }
.toggle.active { color: var(--ink); border-color: var(--ink); }
.toggle.active span { background: var(--green); }
.toggle.active span::after { transform: translateX(12px); }
.search-meta { display: flex; justify-content: space-between; gap: 12px; min-height: 30px; margin: 12px 0; }
.search-status { color: var(--muted); }
.result-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.result { border-bottom: 1px solid var(--rule); }
.result-link { display: block; padding: 20px 0; text-decoration: none; }
.result-link:hover { background: var(--surface-hover); }
.result h2 { font-size: 1.35rem; margin: 0 0 3px; }
.result-author { color: var(--muted); margin: 0; }
.result-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 28px; }
.pagination button { border: 1px solid var(--rule-strong); background: var(--surface); min-height: 44px; padding: 8px 12px; border-radius: var(--radius); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.page-label { font-size: 0.85rem; color: var(--muted); }

.breadcrumbs { display: flex; flex-wrap: wrap; gap: 8px; font-size: 0.8rem; color: var(--muted); padding: 24px 0 0; }
.breadcrumbs a { text-decoration: none; padding: 6px 0; }
.book-detail { padding: 26px 0 70px; }
.book-header { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(240px, 0.5fr); gap: 30px; align-items: end; padding-bottom: 28px; border-bottom: 1px solid var(--rule); }
.book-header h1 { font-size: clamp(2.4rem, 5vw, 4.3rem); max-width: 20ch; }
.book-author { font-size: 1.15rem; color: var(--muted); }
.book-aside { border-left: 2px solid var(--rule); padding-left: 18px; }
.book-section { padding: 30px 0; border-bottom: 1px solid var(--rule); }
.book-section h2 { font-size: 1.65rem; }
.source-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; border-top: 1px solid var(--rule); }
.source-option { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 0; border-bottom: 1px solid var(--rule); }
.source-option p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.source-note { color: var(--muted); font-size: 0.78rem; font-style: italic; }
.related-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 28px; border-top: 1px solid var(--rule); }
.related-list li { border-bottom: 1px solid var(--rule); }
.related-list a { display: grid; padding: 12px 0; text-decoration: none; }
.related-list small { color: var(--muted); }
.prose { max-width: 72ch; font-size: 1.03rem; }
.prose h2 { margin-top: 2rem; }
.prose p { color: var(--prose-ink); }
.disclosure .text-link { display: inline; min-height: 0; margin-right: 0; }
.table-scroll { overflow-x: auto; margin: 1.5rem 0; }
.table-scroll table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table-scroll caption { text-align: left; color: var(--muted); font-size: 0.82rem; padding-bottom: 8px; }
.table-scroll th, .table-scroll td { border-bottom: 1px solid var(--rule); padding: 10px 12px; text-align: left; vertical-align: top; }
.table-scroll th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.table-scroll tr:last-child td { border-bottom: 0; }
.fact-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; border: 1px solid var(--rule); margin: 0 0 36px; }
.fact-grid > div { padding: 16px; border-right: 1px solid var(--rule); display: grid; gap: 4px; }
.fact-grid > div:last-child { border-right: 0; }
.fact-grid span { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.fact-grid strong, .fact-grid a { font-size: 0.95rem; }
.link-list, .guide-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.link-list a, .guide-list a { display: grid; gap: 3px; padding: 14px 0; border-bottom: 1px solid var(--rule); text-decoration: none; }
.link-list span, .guide-list span { color: var(--muted); font-size: 0.88rem; }
.notice { border: 1px solid var(--accent); padding: 14px; background: var(--surface); }
.empty-state { padding: 34px 0; border-bottom: 1px solid var(--rule); }
.empty-state h2 { font-size: 1.5rem; }
.empty-state p { color: var(--muted); }
.empty-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }

.site-footer { border-top: 1px solid var(--rule); padding: 46px 0 24px; background: var(--paper-deep); }
.footer-grid { display: grid; grid-template-columns: 1.4fr 0.6fr 0.9fr; gap: 30px; }
.footer-grid strong { font-family: var(--serif); font-size: 1.05rem; }
.footer-grid p, .footer-grid li { color: var(--muted); font-size: 0.86rem; }
.footer-grid ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.footer-note { border-top: 1px solid var(--rule); margin-top: 28px; padding-top: 16px; color: var(--muted); font-size: 0.78rem; }

@media (max-width: 980px) {
  .header-inner { flex-wrap: wrap; padding: 12px 0; gap: 14px; }
  .header-search { width: 100%; margin-left: 0; }
  .header-search input { flex: 1; width: auto; }
  .hero-grid, .two-col, .book-header { grid-template-columns: 1fr; }
  .genre-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .footer-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .shell { width: min(var(--max), calc(100% - 28px)); }
  .nav-list { gap: 12px; flex-wrap: wrap; }
  .nav-list a { font-size: 0.82rem; }
  .search-field { flex-direction: column; }
  .search-field button { width: 100%; }
  .genre-grid, .book-grid, .fact-grid, .related-list, .footer-grid { grid-template-columns: 1fr; }
  .fact-grid > div { border-right: 0; border-bottom: 1px solid var(--rule); }
  .fact-grid > div:last-child { border-bottom: 0; }
  .source-option { align-items: flex-start; flex-direction: column; }
  .source-option .button { width: 100%; }
  h1 { max-width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}
