/* Restored reader. Two layers:
   1. Plain page: styles for a built chapter (spec 8.1) with no script. A
      single readable column; notes and footnotes at the foot.
   2. html.rd: added by reader.js. The book lies open: pages, page turn,
      settings, notes in a panel. Text stays real HTML throughout. */

@font-face { font-family: 'EB Garamond'; src: url(fonts/eb-garamond-latin-400-normal.woff2) format('woff2'); font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'EB Garamond'; src: url(fonts/eb-garamond-latin-ext-400-normal.woff2) format('woff2'); font-display: swap; unicode-range: U+0100-02AF, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'EB Garamond'; font-style: italic; src: url(fonts/eb-garamond-latin-400-italic.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Literata'; src: url(fonts/literata-latin-400-normal.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Literata'; font-style: italic; src: url(fonts/literata-latin-400-italic.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Atkinson Hyperlegible'; src: url(fonts/atkinson-hyperlegible-latin-400-normal.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Atkinson Hyperlegible'; font-style: italic; src: url(fonts/atkinson-hyperlegible-latin-400-italic.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'IM Fell English'; src: url(fonts/im-fell-english-latin-400-normal.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'IM Fell English'; font-style: italic; src: url(fonts/im-fell-english-latin-400-italic.woff2) format('woff2'); font-display: swap; }
/* Phemister Draft v0.996: roman, italic, bold and bold italic, 159 characters
   each, with small capitals and fi fl ligatures; SIL Open Font License 1.1.
   The bold is mechanical. The site's own pages use these files too. */
@font-face { font-family: 'Phemister Draft'; src: url(fonts/phemister-draft-400-normal.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Phemister Draft'; font-style: italic; src: url(fonts/phemister-draft-400-italic.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Phemister Draft'; font-weight: 700; src: url(fonts/phemister-draft-700-normal.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Phemister Draft'; font-weight: 700; font-style: italic; src: url(fonts/phemister-draft-700-italic.woff2) format('woff2'); font-display: swap; }

/* Plain page: the chapter takes its colours and type from the site around it
   where the site names them (Quoin's tokens), and falls back to the reader's. */
.rd-main, .rd-nav, .rd-library {
  --rd-ink: var(--ink, #1f1b16);
  --rd-soft: var(--muted, #6b6255);
  --rd-accent: var(--accent, #2e4372);
  --rd-line: var(--rule, #d6cdb8);
  --rd-face: var(--font-body, 'EB Garamond', 'Iowan Old Style', Georgia, serif);
  --rd-display: var(--font-heading, 'IM Fell English', 'EB Garamond', Georgia, serif);
  --rd-ui: var(--font-ui, system-ui, -apple-system, 'Segoe UI', sans-serif);
  --rd-fs: 1.1875rem;
  --rd-lh: 1.55;
  --rd-th: 600px;
}

/* The open book: the reader's own paper, ink and faces. Every property is
   prefixed so nothing here can change a site's own tokens. */
html.rd {
  color-scheme: light dark;
  --rd-desk: light-dark(#e7e1d1, #12110f);
  --rd-page: light-dark(#f5f2e9, #211e1a);
  --rd-edge: light-dark(#d9d1bd, #3a352e);
  --rd-bar: light-dark(rgba(245, 242, 233, 0.94), rgba(24, 22, 19, 0.94));
  --rd-fs: 19px;
  --rd-th: 600px;
}
html.rd, html.rd .rd-main, html.rd .rd-nav {
  --rd-ink: light-dark(#1f1b16, #e7e0d1);
  --rd-soft: light-dark(#6b6255, #a59c8c);
  --rd-accent: light-dark(#2e4372, #9fb3e0);
  --rd-line: light-dark(#d6cdb8, #38332c);
  --rd-face: 'EB Garamond', 'Iowan Old Style', Georgia, serif;
  --rd-display: 'IM Fell English', 'EB Garamond', Georgia, serif;
  --rd-ui: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --rd-lh: 1.5;
}
html.rd[data-paper='cream'] { color-scheme: light; }
html.rd[data-paper='white'] { color-scheme: light; --rd-desk: #e9e9e7; --rd-page: #fff; --rd-edge: #dcdcd8; --rd-bar: rgba(255, 255, 255, 0.95); }
html.rd[data-paper='white'], html.rd[data-paper='white'] .rd-main { --rd-line: #dedcd6; }
html.rd[data-paper='dark'] { color-scheme: dark; }
html.rd[data-face='literata'], html.rd[data-face='literata'] .rd-main { --rd-face: 'Literata', Georgia, serif; --rd-lh: 1.55; }
html.rd[data-face='atkinson'], html.rd[data-face='atkinson'] .rd-main { --rd-face: 'Atkinson Hyperlegible', system-ui, sans-serif; --rd-lh: 1.6; }
html.rd[data-face='phemister'], html.rd[data-face='phemister'] .rd-main { --rd-face: 'Phemister Draft', 'Literata', Georgia, serif; --rd-lh: 1.5; }

.rd-main, .rd-main *, .rd-shell, .rd-shell * { box-sizing: border-box; }

/* ---- the chapter, in either layer ------------------------------------------ */
.chapter { font-family: var(--rd-face); font-size: var(--rd-fs); line-height: var(--rd-lh); font-variant-numeric: oldstyle-nums; text-align: justify; hyphens: auto; -webkit-hyphens: auto; }
.chapter p { margin: 0; text-indent: 1.4em; text-wrap: pretty; orphans: 2; widows: 2; }
.chapter p.first, .chapter blockquote > p:first-child, .chapter figure + p, .chapter blockquote + p, .chapter li p, .chapter .signature p, .chapter .center p, .chapter .verse p, .chapter .epigraph p { text-indent: 0; }
.chapter .head { text-align: center; padding: 2.2em 0 1.4em; break-inside: avoid; }
.chapter .head .num { font-variant-caps: all-small-caps; letter-spacing: 0.12em; color: var(--rd-soft); text-indent: 0; }
.chapter .head .num::before { content: 'Chapter '; }
.chapter .head .num:not(:empty) { margin: 0; }
.chapter h1 { font: 400 1.75em/1.12 var(--rd-display); margin: 0.3em 0 0; text-wrap: balance; hyphens: none; }
.chapter h2, .chapter h3 { font: inherit; font-variant-caps: all-small-caps; letter-spacing: 0.06em; text-align: center; margin: 1.6em 0 0.5em; break-after: avoid; hyphens: none; text-wrap: balance; }
/* The drop capital belongs to the open book; the plain page does without it. */
html.rd .chapter p.rd-opening::first-letter { font-family: var(--rd-display); font-size: 3.1em; line-height: 0.82; float: left; padding: 0.06em 0.08em 0 0; }
@supports (initial-letter: 3) or (-webkit-initial-letter: 3) {
  html.rd .chapter p.rd-opening::first-letter { float: none; font-size: inherit; line-height: inherit; padding: 0; margin-right: 0.08em; initial-letter: 3; -webkit-initial-letter: 3; }
}
.chapter .sc { font-variant-caps: all-small-caps; letter-spacing: 0.04em; }
.chapter em { font-style: italic; }
.chapter blockquote { margin: 0.8em 1.5em; }
.chapter .center { text-align: center; margin: 1.6em 0 0; }
.chapter .center p { text-align: center; letter-spacing: 0.1em; }
.chapter .signature { margin-top: 1.2em; }
.chapter .signature p:first-child { text-align: right; }
.chapter .signature p { font-size: 0.9em; text-align: left; }
.chapter .verse p { text-align: left; padding-left: 2em; text-indent: -2em; hyphens: none; }
.chapter hr.orn { border: 0; margin: 1em 0; text-align: center; color: var(--rd-soft); }
.chapter hr.orn::after { content: attr(data-glyph); }
.chapter table { border-collapse: collapse; margin: 1em auto; font-variant-numeric: lining-nums tabular-nums; text-align: left; hyphens: none; }
.chapter table caption { font-variant-caps: all-small-caps; letter-spacing: 0.04em; padding-bottom: 0.4em; }
.chapter thead { border-top: 1px solid var(--rd-ink); border-bottom: 1px solid var(--rd-ink); }
.chapter tbody { border-bottom: 1px solid var(--rd-ink); }
.chapter th, .chapter td { padding: 0.15em 0.7em; font-weight: 400; }

/* Where each printed page began is kept in the markup (the scan link and
   leaf addresses need it) but not shown: it interrupts the reading. */
.chapter .pg { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; user-select: none; -webkit-user-select: none; }

/* Editorial marks: quiet. A dotted rule and a dagger; the text keeps its colour. */
.chapter .ed[aria-describedby] { border-bottom: 1px dotted var(--rd-accent); }
.chapter .ed[aria-describedby]::after { content: '\2020'; color: var(--rd-accent); font-size: 0.7em; vertical-align: 0.45em; margin-left: 1px; font-style: normal; }
.chapter .ed.supplied::before { content: '['; }
.chapter .ed.supplied::after { content: ']\2020'; font-size: inherit; vertical-align: baseline; color: inherit; }
.chapter .fnref { font: 500 0.65em/1 var(--rd-ui); vertical-align: 0.5em; color: var(--rd-accent); text-decoration: none; padding: 0 0.15em; }

.chapter figure { margin: 1.2em 0; text-align: center; break-inside: avoid; }
.chapter figure img { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.chapter figcaption { font-variant-caps: all-small-caps; letter-spacing: 0.05em; font-size: 0.85em; line-height: 1.3; margin-top: 0.5em; text-wrap: balance; hyphens: none; }
.chapter figcaption .credit { font-variant-caps: normal; font-style: italic; letter-spacing: 0; }

.chapter .footnotes, .chapter .ednotes { margin-top: 2.5em; padding-top: 0.8em; border-top: 1px solid var(--rd-line); font-size: 0.85em; text-align: left; hyphens: none; }
.chapter .ednotes h2 { margin: 0 0 0.3em; text-align: left; }
.chapter .footnotes p, .chapter .ednotes p { text-indent: 0; }
.chapter a { color: var(--rd-accent); }

/* ---- layer 1: the plain page ------------------------------------------------ */
html:not(.rd) .rd-main { max-width: 34em; margin: 0 auto; padding: 0 1rem 3rem; color: var(--rd-ink); }
.rd-nav { max-width: 40em; margin: 0 auto 1rem; padding: 1rem 1rem 0; display: flex; justify-content: space-between; gap: 1rem; font: 14px/1.4 var(--rd-ui); }
.rd-nav a { color: var(--rd-soft); }
.rd-nav a:empty { visibility: hidden; }

/* ---- layer 2: the open book ------------------------------------------------ */
html.rd, html.rd body { height: 100%; }
html.rd body { margin: 0; overflow: hidden; background: var(--rd-desk); }
/* The site's own header, footer and the rest stay in the page but out of sight. */
html.rd body > :not(.rd-shell) { display: none !important; }
.rd-shell { height: 100vh; height: 100dvh; display: flex; flex-direction: column; background: var(--rd-desk); color: var(--rd-ink); font: 15px/1.4 var(--rd-ui); }
.rd-shell .rd-main { color: var(--rd-ink); }
.rd-shell button { font: inherit; color: inherit; background: none; border: 0; border-radius: 0; margin: 0; padding: 0; cursor: pointer; box-shadow: none; text-transform: none; letter-spacing: 0; min-height: 0; }
.rd-shell button:focus-visible, .rd-shell a:focus-visible { outline: 2px solid var(--rd-accent); outline-offset: 2px; border-radius: 4px; }
.rd-bar { display: flex; align-items: center; gap: 6px; padding: 0 max(8px, env(safe-area-inset-left)); height: 52px; background: var(--rd-bar); border-bottom: 1px solid var(--rd-line); flex: none; z-index: 5; }
.rd-bar .home { font-family: var(--rd-display); font-size: 19px; color: var(--rd-ink); text-decoration: none; padding: 10px 8px; }
.rd-where { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--rd-soft); font-size: 14px; }
.rd-where a { font: italic 16px var(--rd-face); color: var(--rd-ink); text-decoration: none; }
.rd-shell .rd-tb { min-width: 44px; height: 44px; border-radius: 8px; display: grid; place-items: center; font-size: 14px; padding: 0 8px; }
.rd-shell .rd-tb:hover, .rd-shell .rd-tb[aria-pressed='true'] { background: var(--rd-line); }
.rd-tb .big { font-family: var(--rd-face); font-size: 20px; }
.rd-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.rd-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.rd-turn { z-index: 3; }
.rd-vp { position: absolute; overflow: hidden; z-index: 2; touch-action: pan-y pinch-zoom; }
html.rd .rd-main { column-fill: auto; transition: opacity 0.1s; will-change: transform; }
html.rd .rd-main.out { opacity: 0; }
html.rd .rd-main.rag .chapter { text-align: left; hyphens: manual; -webkit-hyphens: manual; }
html.rd .chapter .head { padding-top: calc(var(--rd-th) * 0.2); }
html.rd .chapter .ed[aria-describedby], html.rd .chapter .fnref { cursor: pointer; }
html.rd .chapter .ednotes, html.rd .chapter .footnotes { display: none; }
/* A plate takes a page to itself; the caption stays with it. */
html.rd:not(.rd-scroll) .chapter figure { margin: 0; height: var(--rd-th); display: flex; flex-direction: column; align-items: center; justify-content: center; break-before: column; break-after: column; }
html.rd:not(.rd-scroll) .chapter figure img { max-height: calc(var(--rd-th) - 4.5em); width: auto; min-height: 0; object-fit: contain; flex: 0 1 auto; }
/* A paragraph the reader has split across a plate: the first part ends flush, the second starts without an indent. */
html.rd .chapter p.rd-cont { text-indent: 0; }
html.rd .rd-main:not(.rag) .chapter p.rd-cut { text-align-last: justify; }
html.rd .chapter figure img { filter: sepia(0.18); box-shadow: 0 0 0 1px var(--rd-line); }
.rd-end { display: block; }
.rd-shell .rd-edge { position: absolute; top: 0; bottom: 0; width: 44px; z-index: 4; display: grid; place-items: center; color: var(--rd-soft); font-size: 26px; opacity: 0; transition: opacity 0.2s; }
.rd-stage:hover .rd-edge, .rd-edge:focus-visible { opacity: 0.8; }
.rd-edge[disabled] { visibility: hidden; }
.rd-edge.prev { left: 0; }
.rd-edge.next { right: 0; }
.rd-foot { flex: none; height: 46px; display: flex; align-items: center; gap: 10px; padding: 0 12px; border-top: 1px solid var(--rd-line); background: var(--rd-bar); font-size: 13px; color: var(--rd-soft); z-index: 5; font-variant-numeric: tabular-nums; }
.rd-count { white-space: nowrap; }
.rd-prog { flex: 1; height: 3px; background: var(--rd-line); border-radius: 2px; overflow: hidden; }
.rd-prog i { display: block; height: 100%; width: 0; background: var(--rd-ink); transition: width 0.3s; }
.rd-shell .rd-orig { white-space: nowrap; color: var(--rd-accent); padding: 10px 4px; }
.rd-bar, .rd-foot { transition: opacity 0.35s; }
.rd-shell.rd-calm .rd-bar, .rd-shell.rd-calm .rd-foot { opacity: 0; pointer-events: none; }
.rd-shell.rd-calm .rd-edge { opacity: 0 !important; }

/* scroll instead of pages */
html.rd-scroll .rd-stage { overflow-y: auto; }
html.rd-scroll .rd-stage canvas, html.rd-scroll .rd-edge { display: none; }
html.rd-scroll .rd-vp { position: static; overflow: visible; padding: 28px max(5vw, 20px) 60px; }
html.rd-scroll .rd-main { width: min(640px, 100%); margin: 0 auto; background: var(--rd-page); padding: clamp(24px, 5vw, 56px); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
html.rd-scroll .chapter .head { padding-top: 2.2em; }
html.rd-scroll .rd-prog, html.rd-scroll .rd-count { visibility: hidden; }
.rd-chapnav { display: none; }
html.rd-scroll .rd-chapnav { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3em; font: 14px/1.4 var(--rd-ui); }
html.rd-scroll .rd-chapnav a { color: var(--rd-accent); }

/* panels */
.rd-sheet { position: fixed; left: 50%; bottom: 58px; transform: translate(-50%, 20px); width: min(460px, calc(100% - 24px)); max-height: calc(100% - 130px); overflow: auto; background: var(--rd-page); color: var(--rd-ink); border: 1px solid var(--rd-line); border-radius: 12px; padding: 18px 20px 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25); z-index: 9; opacity: 0; visibility: hidden; transition: 0.2s; }
.rd-sheet.open { opacity: 1; transform: translate(-50%, 0); visibility: visible; }
.rd-sheet h2 { margin: 0 0 6px; font: 500 13px/1.3 var(--rd-ui); color: var(--rd-accent); }
.rd-sheet p { margin: 0 0 10px; font: 17px/1.45 var(--rd-face); }
.rd-sheet .big { font: 400 48px/1 var(--rd-display); margin: 2px 0 6px; }
.rd-row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.rd-shell .rd-btn { min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--rd-line) !important; display: inline-flex; align-items: center; text-decoration: none; color: var(--rd-ink); font-size: 14px; }
.rd-shell .rd-btn.primary { background: var(--rd-ink) !important; color: var(--rd-page) !important; border-color: var(--rd-ink) !important; }
.rd-opts { display: grid; gap: 14px; margin-bottom: 14px; }
.rd-opt > span { display: block; font: 500 13px var(--rd-ui); color: var(--rd-soft); margin-bottom: 6px; }
.rd-seg { display: flex; border: 1px solid var(--rd-line); border-radius: 9px; overflow: hidden; }
.rd-shell .rd-seg button { flex: 1; min-height: 44px; padding: 0 4px; font-size: 14px; border-left: 1px solid var(--rd-line); }
.rd-shell .rd-seg button:first-child { border-left: 0; }
.rd-shell .rd-seg button[aria-pressed='true'] { background: var(--rd-ink); color: var(--rd-page); }
.rd-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
@media (max-width: 600px) { .rd-where .ch { display: none; } }
@media (prefers-reduced-motion: reduce) { html.rd .rd-main, .rd-sheet, .rd-prog i, .rd-bar, .rd-foot { transition: none; } }

/* ---- the reading list (library.js) ------------------------------------------- */
.rd-library { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.9em; }
.rd-library a { color: inherit; }
.rd-library small { display: block; font: 13px/1.4 var(--rd-ui); color: var(--rd-soft); }
.rd-library progress { display: block; width: 100%; max-width: 16em; height: 3px; margin-top: 0.35em; accent-color: var(--rd-ink); }
.rd-library button { font: 13px/1.4 var(--rd-ui); color: var(--rd-soft); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }
