:root {
  --paper: #faf8f4;
  --paper-2: #f2eee6;
  --ink: #211f1c;
  --ink-soft: #5c574e;
  --ink-faint: #8b8579;
  --rule: #e0dad0;
  --accent: #8a6420;
  --accent-soft: #f0e7d6;
  --shadow: 0 1px 2px rgba(30, 25, 15, .06), 0 8px 24px rgba(30, 25, 15, .06);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --measure: 34rem;
  --reader-size: 1.075rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --paper: #15161a;
    --paper-2: #1c1e23;
    --ink: #e6e2d9;
    --ink-soft: #a8a294;
    --ink-faint: #776f60;
    --rule: #2b2e35;
    --accent: #d9ab5e;
    --accent-soft: #2a2620;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme=dark] {
  --paper: #15161a;
  --paper-2: #1c1e23;
  --ink: #e6e2d9;
  --ink-soft: #a8a294;
  --ink-faint: #776f60;
  --rule: #2b2e35;
  --accent: #d9ab5e;
  --accent-soft: #2a2620;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  overflow-wrap: break-word;
}
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }

/* ---------- chrome ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem max(.8rem, env(safe-area-inset-left)) .55rem max(.8rem, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.brand .mark { width: 1.15rem; height: 1.15rem; flex: none; color: var(--accent); }
.brand span { font-size: .95rem; }
.spacer { flex: 1 1 auto; }

.iconbtn {
  display: inline-grid; place-items: center;
  width: 2.1rem; height: 2.1rem; flex: none;
  border: 1px solid var(--rule); border-radius: .55rem;
  background: var(--paper-2); cursor: pointer;
}
.iconbtn:hover { border-color: var(--ink-faint); }
.iconbtn svg { width: 1.05rem; height: 1.05rem; }

.searchwrap { position: relative; flex: 1 1 auto; max-width: 30rem; }
.searchwrap svg { position: absolute; left: .6rem; top: 50%; translate: 0 -50%; width: 1rem; height: 1rem; color: var(--ink-faint); pointer-events: none; }
#q {
  width: 100%; padding: .45rem .7rem .45rem 2.05rem;
  border: 1px solid var(--rule); border-radius: .55rem;
  background: var(--paper-2); outline: none;
}
#q:focus { border-color: var(--accent); }

/* ---------- layout ---------- */
main { padding: 1.4rem max(.9rem, env(safe-area-inset-left)) 5rem max(.9rem, env(safe-area-inset-right)); }
.wrap { max-width: 62rem; margin: 0 auto; }
.reader-wrap { max-width: var(--measure); margin: 0 auto; }
h1, h2, h3 { line-height: 1.22; letter-spacing: -.015em; margin: 0; }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.tiny { font-size: .8rem; }

.hero { margin-bottom: 1.5rem; }
.hero h1 { font-family: var(--serif); font-size: clamp(1.6rem, 4.5vw, 2.3rem); }
.hero p { margin: .5rem 0 0; color: var(--ink-soft); max-width: 42rem; }
.statline { display: flex; flex-wrap: wrap; gap: .35rem 1.1rem; margin-top: .8rem; font-size: .85rem; color: var(--ink-faint); }
.statline b { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- library ---------- */
.toolrow { display: flex; gap: .5rem; align-items: center; margin: 0 0 1rem; flex-wrap: wrap; }
#filter {
  flex: 1 1 14rem; min-width: 0; padding: .45rem .7rem;
  border: 1px solid var(--rule); border-radius: .55rem; background: var(--paper-2); outline: none;
}
#filter:focus { border-color: var(--accent); }
select {
  padding: .45rem .6rem; border: 1px solid var(--rule); border-radius: .55rem;
  background: var(--paper-2); cursor: pointer; outline: none;
}
.grid { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr)); }
.card {
  display: flex; flex-direction: column; gap: .4rem;
  padding: .85rem .95rem; border: 1px solid var(--rule); border-radius: .7rem;
  background: var(--paper-2); transition: border-color .15s, transform .15s;
  /* the grid runs to hundreds of cards; skip the off-screen ones */
  content-visibility: auto;
  contain-intrinsic-size: auto 7rem;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card .t { font-family: var(--serif); font-size: 1.02rem; line-height: 1.3; }
.card .meta { display: flex; gap: .5rem; align-items: center; font-size: .78rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.pill { padding: .05rem .4rem; border: 1px solid var(--rule); border-radius: 999px; font-size: .7rem; letter-spacing: .02em; text-transform: uppercase; }
.pill.scan { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--rule)); }
.bar { height: 3px; border-radius: 2px; background: var(--rule); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }

/* ---------- reader ---------- */
.bookhead { margin-bottom: 1.6rem; padding-bottom: 1.1rem; border-bottom: 1px solid var(--rule); }
.bookhead h1 { font-family: var(--serif); font-size: clamp(1.35rem, 4vw, 1.9rem); }
.crumbs { display: flex; align-items: center; gap: .4rem; margin-bottom: .7rem; font-size: .85rem; color: var(--ink-faint); }
.crumbs a:hover { color: var(--accent); }

/* No content-visibility here: the reader only holds a few pages at a time, and
   skipping the subtree stops `loading=lazy` images inside from ever loading. */
.page { padding: .3rem 0 1.6rem; }
.pagenum {
  display: flex; align-items: center; gap: .7rem;
  margin: 2rem 0 1rem; color: var(--ink-faint);
  font-size: .72rem; letter-spacing: .09em; text-transform: uppercase;
}
.pagenum::before, .pagenum::after { content: ""; height: 1px; background: var(--rule); flex: 1; }
.page p {
  font-family: var(--serif); font-size: var(--reader-size); line-height: 1.62;
  margin: 0 0 1.05em; hyphens: auto;
}
.page p:last-child { margin-bottom: 0; }
/* title pages, headings and verse keep their original line breaks */
.page p.verse { white-space: pre-line; line-height: 1.5; }
.page img {
  display: block; width: 100%; height: auto; margin: 1.2rem 0;
  border: 1px solid var(--rule); border-radius: .4rem; background: #fff;
}
.blank { color: var(--ink-faint); font-style: italic; font-size: .9rem; }

.sentinel { height: 1px; }
.loading { padding: 2rem 0; text-align: center; color: var(--ink-faint); font-size: .88rem; }

/* page jump + settings */
.readerbar {
  position: fixed; left: 50%; translate: -50% 0;
  bottom: max(.8rem, env(safe-area-inset-bottom));
  z-index: 15; display: flex; align-items: center; gap: .35rem;
  padding: .35rem .4rem; border: 1px solid var(--rule); border-radius: 999px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(12px); box-shadow: var(--shadow);
}
.readerbar button { border: 0; background: none; cursor: pointer; padding: .3rem .55rem; border-radius: 999px; color: var(--ink-soft); }
.readerbar button:hover { background: var(--accent-soft); color: var(--ink); }
.readerbar .pos { font-size: .8rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; padding: 0 .3rem; white-space: nowrap; }
#jump { width: 3.6rem; padding: .25rem .4rem; text-align: center; border: 1px solid var(--rule); border-radius: .45rem; background: var(--paper-2); outline: none; }
#jump:focus { border-color: var(--accent); }

/* ---------- search ---------- */
.result { padding: .9rem 0; border-bottom: 1px solid var(--rule); }
.result h3 { font-family: var(--serif); font-size: 1.02rem; }
.result .where { font-size: .8rem; color: var(--ink-faint); margin-top: .1rem; }
.result .snip { margin-top: .45rem; font-family: var(--serif); font-size: .95rem; color: var(--ink-soft); line-height: 1.55; }
mark { background: color-mix(in srgb, var(--accent) 26%, transparent); color: inherit; border-radius: .15rem; padding: 0 .1em; }
.empty { padding: 3rem 0; text-align: center; color: var(--ink-faint); }
.morebtn {
  display: block; margin: 1.2rem auto 0; padding: .5rem 1.1rem;
  border: 1px solid var(--rule); border-radius: .5rem;
  background: var(--paper-2); cursor: pointer;
}
.morebtn:hover { border-color: var(--accent); }
.readerbar button:disabled { cursor: default; }

.sheet {
  position: fixed; inset: auto 0 0 0; z-index: 30;
  background: var(--paper); border-top: 1px solid var(--rule);
  padding: 1rem max(1rem, env(safe-area-inset-left)) max(1.2rem, env(safe-area-inset-bottom));
  box-shadow: var(--shadow); display: none;
}
.sheet.open { display: block; }
.sheet .row { display: flex; align-items: center; gap: .6rem; justify-content: space-between; max-width: 30rem; margin: 0 auto .8rem; }
.sheet .row:last-child { margin-bottom: 0; }
.seg { display: flex; gap: .25rem; }
.seg button { padding: .35rem .7rem; border: 1px solid var(--rule); border-radius: .45rem; background: var(--paper-2); cursor: pointer; }
.seg button[aria-pressed=true] { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.backdrop { position: fixed; inset: 0; z-index: 29; background: rgba(0,0,0,.35); display: none; }
.backdrop.open { display: block; }

@media (max-width: 32rem) {
  .brand span { display: none; }
  main { padding-top: 1rem; }
}

.card .by { font-size: .82rem; color: var(--ink-soft); margin-top: -.15rem; }
.card .subj { font-size: .72rem; color: var(--ink-faint); letter-spacing: .02em; }
