:root {
  --bg: #f6f2ea; --paper: #fffcf7; --ink: #0d1b33; --muted: #5c6578; --line: #e4ddd0;
  --accent: #8a5210; --accent-bg: #f3e4c9; --mark: #f7dd9a; --focus: #c4841d;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs: 1.16rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1726; --paper: #152033; --ink: #e8e4dc; --muted: #9aa3b5; --line: #26324a;
    --accent: #e0a44a; --accent-bg: #2a2a22; --mark: #6b4e14; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1726; --paper: #152033; --ink: #e8e4dc; --muted: #9aa3b5; --line: #26324a;
  --accent: #e0a44a; --accent-bg: #2a2a22; --mark: #6b4e14; color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); line-height: 1.6; min-height: 100vh; display: flex; flex-direction: column; }
main { flex: 1; outline: none; }
a { color: var(--accent); }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 1rem; }
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: var(--bg); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: .5rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.site-header { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { display: flex; align-items: center; gap: .5rem; text-decoration: none; color: var(--ink); font-size: 1.15rem; letter-spacing: .01em; }
.brand b { color: var(--accent); }
nav { display: flex; align-items: center; gap: .25rem; }
nav a { text-decoration: none; color: var(--muted); padding: .45rem .7rem; border-radius: 8px; font-weight: 500; }
nav a:hover, nav a[aria-current="page"] { color: var(--ink); background: var(--accent-bg); }
.icon-btn { background: none; border: 1px solid transparent; color: var(--muted); padding: .4rem; border-radius: 8px; cursor: pointer; display: inline-flex; }
.icon-btn:hover { color: var(--ink); background: var(--accent-bg); }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; } :root[data-theme="dark"] .i-moon { display: inline; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .i-sun { display: none; } :root:not([data-theme="light"]) .i-moon { display: inline; } }

.loading { color: var(--muted); padding: 3rem 0; text-align: center; }
.error { background: #fde8e6; color: #7a1c12; border-radius: 10px; padding: 1rem; margin: 1.5rem 0; }

/* Home */
.hero { padding: 2.25rem 0 1rem; }
.hero h1 { font-family: var(--serif); font-weight: 600; font-size: clamp(1.8rem, 4vw, 2.6rem); margin: 0 0 .35rem; }
.hero p { color: var(--muted); margin: 0; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 1.25rem 1.35rem; }
.votd { margin: 1.25rem 0; }
.votd .label { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; color: var(--accent); font-weight: 700; }
.votd blockquote { font-family: var(--serif); font-size: clamp(1.2rem, 2.6vw, 1.5rem); line-height: 1.5; margin: .5rem 0 .75rem; }
.votd .ref { font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: .35rem; font: inherit; font-weight: 600; font-size: .95rem; padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }
.books h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 1.75rem 0 .6rem; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .4rem; }
.book-grid button { font: inherit; text-align: left; padding: .5rem .7rem; background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: 9px; cursor: pointer; }
.book-grid button:hover, .book-grid button[aria-expanded="true"] { border-color: var(--accent); background: var(--accent-bg); }
.chapter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: .35rem; margin: .6rem 0 1rem; grid-column: 1 / -1; padding: .75rem; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; }
.chapter-grid a { text-align: center; padding: .4rem 0; border-radius: 7px; text-decoration: none; color: var(--ink); background: var(--bg); }
.chapter-grid a:hover { background: var(--accent-bg); color: var(--accent); }

/* Reader */
.toolbar { position: sticky; top: 56px; z-index: 4; background: var(--bg); padding: .65rem 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.toolbar label { font-size: .78rem; color: var(--muted); display: flex; flex-direction: column; gap: .15rem; }
select, input[type="search"] { font: inherit; font-size: .95rem; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 9px; padding: .45rem .6rem; min-height: 40px; }
select:hover, input[type="search"]:hover { border-color: var(--accent); }
.toolbar .grow { flex: 1; }
.toolbar .nav-btns { display: flex; gap: .35rem; align-self: flex-end; }
.chapter-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin: 1.5rem 0 .75rem; }
.chapter-head h1 { font-family: var(--serif); font-weight: 600; font-size: clamp(1.6rem, 4vw, 2.2rem); margin: 0; }
.chapter-head .tr { color: var(--muted); font-size: .9rem; }
.text { font-family: var(--serif); font-size: var(--fs); line-height: 1.85; max-width: 42em; }
.text p { margin: 0; }
.v { scroll-margin-top: 140px; border-radius: 4px; }
.v sup, .compare sup { font-family: var(--sans); font-size: .62em; font-weight: 700; color: var(--accent); margin: 0 .2em 0 .1em; vertical-align: .55em; user-select: none; }
.v.target, .cell.target { background: var(--mark); box-shadow: 0 0 0 3px var(--mark); }
em.added { font-style: italic; opacity: .85; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 0 2rem; font-family: var(--serif); font-size: var(--fs); line-height: 1.7; }
.compare .colhead { font-family: var(--sans); font-weight: 700; font-size: .8rem; letter-spacing: .06em; color: var(--muted); padding-bottom: .4rem; border-bottom: 1px solid var(--line); }
.compare .cell { padding: .45rem 0; border-bottom: 1px dashed var(--line); }
.compare .cell .tag { display: none; }
@media (max-width: 680px) {
  .compare { grid-template-columns: 1fr; }
  .compare .colhead { display: none; }
  .compare .cell.second { border-bottom: 1px solid var(--line); padding-bottom: .8rem; margin-bottom: .2rem; }
  .compare .cell.first { border-bottom: 0; padding-bottom: .1rem; }
  .compare .cell .tag { display: inline; font-family: var(--sans); font-size: .7rem; font-weight: 700; color: var(--muted); margin-right: .35rem; }
  .toolbar { position: static; padding: .5rem 0; gap: .4rem; }
  .toolbar label { font-size: .72rem; }
  .toolbar label.tr-pick, .toolbar label.cmp-pick { flex: 1 1 40%; }
  .toolbar label.book-pick { flex: 1 1 55%; } .toolbar label.ch-pick { flex: 1 1 25%; }
  .toolbar select { width: 100%; }
  .toolbar .grow { display: none; }
  .toolbar .nav-btns { display: none; }
  .chapter-head { margin-top: 1rem; }
}
.pager { display: flex; justify-content: space-between; gap: .5rem; margin: 2rem 0 3rem; max-width: 42em; }

/* Search */
.search-form { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1.5rem 0 1rem; }
.search-form input { flex: 1 1 260px; }
.meta { color: var(--muted); font-size: .92rem; }
.results { list-style: none; padding: 0; margin: 1rem 0; }
.results li { padding: .8rem 0; border-bottom: 1px solid var(--line); }
.results a.ref { font-weight: 700; text-decoration: none; }
.results .vt { font-family: var(--serif); font-size: 1.05rem; margin-top: .15rem; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 .1em; }

.site-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; padding: 1.25rem 0 1.75rem; margin-top: 2rem; }
.site-footer p { margin: .3rem 0; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
@media print { .site-header, .toolbar, .pager, .site-footer { display: none; } }
