/* reader/themes.css — the shared theme/type token system for hosted-book reading pages.
   One pool of 8 verified-contrast themes (WCAG ratios computed at build; see the
   reading-templates spec §C) + 5 type presets on self-hosted OFL fonts. Every reading
   template (classic/scroll/serial/folio) consumes THESE tokens — never its own hexes.
   Fonts: /reader/fonts/*.woff2 (latin + latin-ext), licenses in fonts/OFL-LICENSES.txt.
   CSP is connect-src 'self' — nothing here may reference an external host. */

/* ============================ SELF-HOSTED FONTS (SIL OFL) ============================ */
@font-face {
  font-family: 'Literata';
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url(/reader/fonts/literata-italic-200-900-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Literata';
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url(/reader/fonts/literata-italic-200-900-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Literata';
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url(/reader/fonts/literata-roman-200-900-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Literata';
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url(/reader/fonts/literata-roman-200-900-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Vollkorn';
  font-style: italic;
  font-weight: 400 900;
  font-display: swap;
  src: url(/reader/fonts/vollkorn-italic-400-900-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Vollkorn';
  font-style: italic;
  font-weight: 400 900;
  font-display: swap;
  src: url(/reader/fonts/vollkorn-italic-400-900-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Vollkorn';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url(/reader/fonts/vollkorn-roman-400-900-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Vollkorn';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url(/reader/fonts/vollkorn-roman-400-900-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Source Sans 3';
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url(/reader/fonts/sourcesans3-italic-200-900-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Source Sans 3';
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url(/reader/fonts/sourcesans3-italic-200-900-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Source Sans 3';
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url(/reader/fonts/sourcesans3-roman-200-900-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Source Sans 3';
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url(/reader/fonts/sourcesans3-roman-200-900-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url(/reader/fonts/sourceserif4-italic-200-900-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url(/reader/fonts/sourceserif4-italic-200-900-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url(/reader/fonts/sourceserif4-roman-200-900-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url(/reader/fonts/sourceserif4-roman-200-900-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Atkinson Hyperlegible Next';
  font-style: italic;
  font-weight: 200 800;
  font-display: swap;
  src: url(/reader/fonts/atkinson-italic-200-800-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Atkinson Hyperlegible Next';
  font-style: italic;
  font-weight: 200 800;
  font-display: swap;
  src: url(/reader/fonts/atkinson-italic-200-800-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Atkinson Hyperlegible Next';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url(/reader/fonts/atkinson-roman-200-800-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Atkinson Hyperlegible Next';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url(/reader/fonts/atkinson-roman-200-800-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ============================ THEME TOKEN POOL (8, verified contrast) ============================
   --bg --ink --muted --accent --hl on :root[data-reader-theme]. Ratios vs bg:
   paper 15.5/5.5/5.4 · sepia 10.7/4.8/6.1 · dusk 9.2/4.5/6.2 · ink 12.1/5.2/7.8 ·
   oled 12.3/6.1/8.5 (never #FFF ink — halation) · hc-light 21/11.2/9.9 ·
   hc-dark 21/13.6/11.8 · comfort 14.5/6.4/6.7. Accents all warm amber family. */
:root {
  /* paper is the no-attribute default (auto-mapping below may re-map it) */
  --bg: #FAF6EE; --ink: #221D15; --muted: #6E6250; --accent: #8A5A2B;
  --hl: color-mix(in srgb, var(--accent) 16%, transparent);
  /* derived, single-source — templates use these instead of inventing hexes */
  --rd-rule: color-mix(in srgb, var(--ink) 14%, transparent);
  --rd-dim: color-mix(in srgb, var(--ink) 38%, transparent);
  --rd-surface: color-mix(in srgb, var(--ink) 4%, var(--bg));
}
:root[data-reader-theme='paper']    { --bg: #FAF6EE; --ink: #221D15; --muted: #6E6250; --accent: #8A5A2B; }
:root[data-reader-theme='sepia']    { --bg: #F4E8D2; --ink: #3B2F1F; --muted: #75634A; --accent: #7A4A21; }
:root[data-reader-theme='dusk']     { --bg: #2A2B2E; --ink: #CDD0D4; --muted: #8E9298; --accent: #D0A46A; }
:root[data-reader-theme='ink']      { --bg: #16171A; --ink: #D8D4CB; --muted: #8F8A80; --accent: #D9A05B; }
:root[data-reader-theme='oled']     { --bg: #000000; --ink: #C6C6C6; --muted: #8A8A8A; --accent: #CF9B57; }
:root[data-reader-theme='hc-light'] { --bg: #FFFFFF; --ink: #000000; --muted: #3B3B3B; --accent: #6B3400;
  --hl: color-mix(in srgb, var(--accent) 28%, transparent); }
:root[data-reader-theme='hc-dark']  { --bg: #000000; --ink: #FFFFFF; --muted: #D0D0D0; --accent: #FFB347;
  --hl: color-mix(in srgb, var(--accent) 28%, transparent); }
:root[data-reader-theme='comfort']  { --bg: #FBF3DF; --ink: #25211B; --muted: #5F574A; --accent: #7A4A21; }

/* Auto-mapping — applies ONLY while the reader has no stored choice (the boot script
   sets data-reader-theme from localStorage; an explicit choice always wins). */
@media (prefers-color-scheme: dark) {
  :root:not([data-reader-theme]) { --bg: #16171A; --ink: #D8D4CB; --muted: #8F8A80; --accent: #D9A05B; }
}
@media (prefers-contrast: more) {
  /* a HINT toward the HC theme of the current polarity (semantics are muddled cross-OS —
     treat as suggestion, still user-overridable via the swatches) */
  :root:not([data-reader-theme]) { --bg: #FFFFFF; --ink: #000000; --muted: #3B3B3B; --accent: #6B3400;
    --hl: color-mix(in srgb, var(--accent) 28%, transparent); }
}
@media (prefers-contrast: more) and (prefers-color-scheme: dark) {
  :root:not([data-reader-theme]) { --bg: #000000; --ink: #FFFFFF; --muted: #D0D0D0; --accent: #FFB347; }
}
@media (forced-colors: active) {
  /* Windows HC etc: let the system palette through instead of fighting it */
  :root, :root[data-reader-theme] {
    --bg: Canvas; --ink: CanvasText; --muted: GrayText; --accent: LinkText; --hl: Highlight;
    --rd-rule: GrayText; --rd-dim: GrayText; --rd-surface: Canvas;
  }
}

/* ============================ TYPE PRESETS (5) ============================
   [data-reader-font] sets the DEFAULTS; the controls component overrides size /
   leading / measure / justification with inline :root vars (inline style wins).
   Five VISIBLY DISTINCT faces — one per category a lay reader can actually tell
   apart (remake research §2): modern book serif / dark old-style / crisp
   transitional / humanist sans / hyperlegible. Deltas between presets are
   deliberate: size, leading, and paragraph FEEL (justified-indent vs ragged-gap)
   all shift together so switching fonts is a visible event, not a subtlety. */
:root {
  --rd-font-book: 'Literata', 'Iowan Old Style', Georgia, serif;
  --rd-font-literary: 'Vollkorn', 'Palatino Linotype', Palatino, Georgia, serif;
  --rd-font-modern: 'Source Serif 4', 'Iowan Old Style', Georgia, serif;
  --rd-font-sans: 'Source Sans 3', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --rd-font-comfort: 'Atkinson Hyperlegible Next', 'Atkinson Hyperlegible', Lexend, 'Trebuchet MS', Verdana, sans-serif;
  --rd-sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  /* book preset = the no-attribute default */
  --rd-serif: var(--rd-font-book);
  --rd-size: 19px; --rd-leading: 1.55; --rd-measure: 39rem;
  --rd-align: justify; --rd-hyphens: auto; --rd-indent: 1.5em; --rd-pgap: 0em;
  --rd-tracking: 0em; --rd-wordsp: normal;
}
:root[data-reader-font='book'] {
  --rd-serif: var(--rd-font-book);
  --rd-size: 19px; --rd-leading: 1.55; --rd-measure: 39rem;
  --rd-align: justify; --rd-hyphens: auto; --rd-indent: 1.5em; --rd-pgap: 0em;
  --rd-tracking: 0em; --rd-wordsp: normal;
}
/* Vollkorn — dark, wide old-style; set dense and justified like a printed page */
:root[data-reader-font='literary'] {
  --rd-serif: var(--rd-font-literary);
  --rd-size: 18px; --rd-leading: 1.48; --rd-measure: 37rem;
  --rd-align: justify; --rd-hyphens: auto; --rd-indent: 1.5em; --rd-pgap: 0em;
  --rd-tracking: 0em; --rd-wordsp: normal;
}
/* Source Serif 4 — crisp transitional; set airy and ragged like an essay */
:root[data-reader-font='modern'] {
  --rd-serif: var(--rd-font-modern);
  --rd-size: 18px; --rd-leading: 1.65; --rd-measure: 39rem;
  --rd-align: left; --rd-hyphens: manual; --rd-indent: 0em; --rd-pgap: 1lh;
  --rd-tracking: 0em; --rd-wordsp: normal;
}
/* Source Sans 3 — humanist sans (warm, open apertures; Inter stays chrome-only) */
:root[data-reader-font='sans'] {
  --rd-serif: var(--rd-font-sans);
  --rd-size: 18px; --rd-leading: 1.6; --rd-measure: 39rem;
  --rd-align: left; --rd-hyphens: manual; --rd-indent: 0em; --rd-pgap: 1lh;
  --rd-tracking: 0em; --rd-wordsp: normal;
}
:root[data-reader-font='comfort'] {
  --rd-serif: var(--rd-font-comfort);
  --rd-size: 20px; --rd-leading: 1.7; --rd-measure: 34rem;
  --rd-align: left; --rd-hyphens: manual; --rd-indent: 0em; --rd-pgap: 1lh;
  --rd-tracking: 0.01em; --rd-wordsp: 0.05em;
}
/* justify toggle (controls) — auto-binds hyphenation: never justify unhyphenated */
:root[data-reader-justify='1'] { --rd-align: justify; --rd-hyphens: auto; }
:root[data-reader-justify='0'] { --rd-align: left; --rd-hyphens: manual; }
/* Comfort is ALWAYS ragged, hyphens off — wins over the justify toggle (last rule) */
:root[data-reader-font='comfort'],
:root[data-reader-font='comfort'][data-reader-justify='1'] { --rd-align: left; --rd-hyphens: manual; }

/* ============================ SHARED PROSE FLOOR ============================ */
body.rd-body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--rd-sans); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  font-synthesis: none;
}
/* The page itself must never scroll horizontally — wide content (tables, code)
   scrolls inside its own container. Guards a WebKit overflow-x:auto scrollWidth
   quirk. NOT applied to the Folio, whose reading experience IS a horizontal track. */
body.rd-body:not(.rd-tpl-folio) { overflow-x: clip; }
html:has(> body.rd-body:not(.rd-tpl-folio)) { overflow-x: clip; }
.rd-prose {
  font-family: var(--rd-serif);
  font-size: var(--rd-size);
  line-height: var(--rd-leading);
  letter-spacing: var(--rd-tracking);
  word-spacing: var(--rd-wordsp);
  /* long unbreakable strings (raw URLs in notes) must never widen the layout
     viewport on phones — the browser zooms out and drags every fixed bar along */
  overflow-wrap: break-word;
  color: var(--ink);
  text-align: var(--rd-align);
  -webkit-hyphens: var(--rd-hyphens);
  hyphens: var(--rd-hyphens);           /* requires lang= on the container — SSR sets it */
  hyphenate-limit-chars: 6 3 3;
  hanging-punctuation: first last;      /* free Safari enhancement */
  font-variant-ligatures: common-ligatures;
}
:root[data-reader-font='book'] .rd-prose,
:root:not([data-reader-font]) .rd-prose { font-variant-numeric: oldstyle-nums; }
.rd-prose p {
  margin: 0 0 var(--rd-pgap);
  text-indent: var(--rd-indent);
  text-wrap: pretty;                    /* per-paragraph, never one giant container */
}
.rd-prose p:first-of-type,
.rd-prose h1 + p, .rd-prose h2 + p, .rd-prose h3 + p,
.rd-prose hr + p, .rd-prose blockquote + p { text-indent: 0; }
.rd-prose h1, .rd-prose h2, .rd-prose h3, .rd-prose h4 {
  font-family: var(--rd-serif); font-weight: 600; line-height: 1.2;
  letter-spacing: -0.01em; margin: 2em 0 0.6em; text-align: left; text-indent: 0;
  text-wrap: balance; hyphens: manual; -webkit-hyphens: manual;
}
.rd-prose h1 { font-size: 1.7em; } .rd-prose h2 { font-size: 1.4em; }
.rd-prose h3 { font-size: 1.18em; } .rd-prose h4 { font-size: 1.04em; }
.rd-prose em { font-style: italic; }
.rd-prose strong { font-weight: 700; }
.rd-prose a { color: var(--accent); }
.rd-prose img { max-width: 100%; height: auto; }
.rd-prose hr { border: none; text-align: center; margin: 2.2em 0; }
.rd-prose hr::before { content: '✷'; color: var(--muted); font-size: 1rem; letter-spacing: 0.5em; }
.rd-prose blockquote {
  margin: 1.8em 0; padding: 0.2em 0 0.2em 1.4em;
  border-left: 3px solid var(--accent); font-style: italic;
}
.rd-prose ul, .rd-prose ol { margin: 1.1em 0; padding-left: 1.4em; text-align: left; }
.rd-prose li { margin: 0.35em 0; }
/* Imported tables can be wider than the column (esp. on phones) — make each table
   its own horizontally-scrollable block so it never widens the page. */
.rd-prose table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 0.92em; -webkit-overflow-scrolling: touch; }
.rd-prose th, .rd-prose td { border: 1px solid var(--rd-rule); padding: 0.5em 0.7em; text-align: left; }
::selection { background: color-mix(in srgb, var(--accent) 24%, transparent); }
/* read-along highlight (theme-aware, ink unchanged): the speaking BLOCK gets a
   faint wash; the spoken SENTENCE (.rd-s.on, wrapped lazily by readalong.js)
   carries the full --hl tint. Blocks that could not be sentence-wrapped fall
   back to the block wash alone. */
.rd-prose .speaking { background: color-mix(in srgb, var(--accent) 7%, transparent); border-radius: 4px; }
.rd-prose .rd-s.on {
  background: var(--hl); border-radius: 3px;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ============================ SHARED CONTROLS COMPONENT (controls.js) ============================ */
.rdc { display: grid; gap: 0.7rem; font-family: var(--rd-sans); font-size: 0.85rem; color: var(--ink); }
.rdc-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.rdc-label { flex: none; width: 5rem; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); white-space: nowrap; }
.rdc-group { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.rdc-btn {
  font-family: inherit; font-size: 0.82rem; color: var(--ink); cursor: pointer;
  background: var(--rd-surface); border: 1px solid var(--rd-rule); border-radius: 8px;
  padding: 0.32rem 0.6rem; transition: border-color 0.15s;
}
.rdc-btn:hover { border-color: var(--accent); }
.rdc-btn.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.rdc-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rdc-size-val { min-width: 3.2em; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
/* preset buttons and menu entries preview their own face (picker convention:
   Kindle / Apple Books / Kobo all set the font's NAME in the font itself) */
.rdc-font-book { font-family: var(--rd-font-book); }
.rdc-font-literary { font-family: var(--rd-font-literary); }
.rdc-font-modern { font-family: var(--rd-font-modern); }
.rdc-font-sans { font-family: var(--rd-font-sans); }
.rdc-font-comfort { font-family: var(--rd-font-comfort); }

/* ============================ CONTROLS v2 — ICON-CYCLE CLUSTER ============================
   One compact set every template docks in its chrome, identical on all four:
   A− A+ · Aa(font-cycle) · theme-cycle · spacing-cycle · justify. SSR'd by
   reader-page.js, wired by controls.js strip(). No pill, no dots, no More panel,
   no font menu, no swatch grid — everything the reader needs is on screen. Each
   button carries a persistent title=; controls.js flashes a floating rdc-tip
   naming the new mode on every cycle. The buttons reuse each template's
   .rd-iconbtn sizing; only the font "Aa" preview, the justify-on state, the
   viewport guard and the tip are styled here. */
/* the font button renders "Aa" IN the current face (a live preview) */
.rdc-fontbtn { font-family: var(--rd-serif); font-size: 1.04rem; line-height: 1; letter-spacing: -0.01em; }
/* the justify toggle reads active (accent) when text is justified */
.rd-iconbtn.on { color: var(--accent); }
/* The fixed topbars must never widen past the viewport and shove the Listen
   control off-screen (that stranded phone audio). The right cluster is protected
   at full width and never wraps; the book title on the left is the only element
   allowed to yield (it truncates). The footnote popover + serial numeral — the
   overflow sources that used to stretch the bar — are viewport-contained. */
.rd-body .rd-topbar { max-width: 100vw; box-sizing: border-box; }
.rd-body .rd-topbar-left { flex: 0 1 auto; min-width: 0; }
.rd-body .rd-topbar-right { flex: 0 0 auto; display: flex; align-items: center; flex-wrap: nowrap; }
/* the six-icon cluster fits a 360px phone: tighten the icon buttons on narrow
   screens so A− A+ · Aa · theme · spacing · justify · (zen) · Listen all fit on
   one row without wrapping or overflowing the bar. */
@media (max-width: 559px) {
  .rd-body .rd-topbar-right .rd-iconbtn { min-width: 30px; padding-left: 0.14rem; padding-right: 0.14rem; }
}
/* the floating cycle tip — a small label near the button naming the new mode for
   ~1.2s. controls.js clamps it inside the viewport (UX-IT: floating elements
   never leave it) and flips it above the button when below won't fit. */
.rdc-tip {
  position: fixed; z-index: 80; pointer-events: none;
  max-width: calc(100vw - 12px);
  background: var(--ink); color: var(--bg);
  font-family: var(--rd-sans); font-size: 0.74rem; line-height: 1; font-weight: 600;
  letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0.36rem 0.55rem; border-radius: 7px;
  box-shadow: 0 8px 22px -10px color-mix(in srgb, var(--rd-dim) 90%, transparent);
}
.rdc-tip[hidden] { display: none; }

/* ============================ SHARED AUDIO PLAYER (player.js) ============================
   One bar, every template: ARC-styled — paper surface, thin rule, serif chapter
   title. Docks above the bottom safe-area; the sheet (chapters/speed/sleep)
   rises above it. Templates may reposition via their own css but the pieces
   and tokens are single-sourced here. */
/* A small, unintrusive FLOATING popup player — a rounded pill centred near the
   bottom, not a full-width docked bar. Expands upward into the sheet on More. */
.rd-player {
  position: fixed; z-index: 135;
  left: 50%; transform: translateX(-50%);
  bottom: calc(0.9rem + env(safe-area-inset-bottom));
  width: max-content; max-width: calc(100vw - 1.6rem);
}
.rd-player[hidden] { display: none; }
.rd-player audio { display: none; }
/* the floating pill doesn't reserve full-width space; keep a little bottom room
   so the last line of prose isn't hidden behind it */
:root[data-rd-player-open] body.rd-body { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }

/* the shell wraps every VISIBLE part; display:contents in-page so each template's
   .rd-player / .rdp-* rules key off the parts directly, a real flex column in PiP */
.rdp-shell { display: contents; }

/* whole-book scrubber — an elegant thin rule you can grab to jump to ANY point in
   the book; thickens on hover, shows a chapter·% tooltip, drag or click to seek.
   A styled div (not a native range) so the tooltip + book-wide seek are ours.
   Kept as .rdp-scrub so every template's layout rule (order/width) still applies. */
.rdp-scrub {
  position: relative; display: block; width: 100%; height: 16px;
  margin: 0 0.15rem 0.1rem; cursor: pointer; touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.rdp-scrub::before {                          /* the rail */
  content: ''; position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%);
  height: 3px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 14%, transparent);
  transition: height 0.12s ease;
}
.rdp-fill {                                   /* progress */
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  height: 3px; width: 0%; border-radius: 999px; background: var(--accent);
  transition: height 0.12s ease; pointer-events: none;
}
.rdp-scrub:hover::before, .rdp-scrub:focus-visible::before,
.rdp-scrub:hover .rdp-fill, .rdp-scrub:focus-visible .rdp-fill { height: 5px; }
.rdp-knob {
  position: absolute; top: 50%; left: 0; width: 13px; height: 13px; margin-left: -6.5px;
  transform: translateY(-50%); border-radius: 50%; background: var(--accent);
  border: 2px solid var(--bg); box-shadow: 0 1px 4px color-mix(in srgb, var(--rd-dim) 60%, transparent);
  opacity: 0; transition: opacity 0.12s ease; pointer-events: none;
}
.rdp-scrub:hover .rdp-knob, .rdp-scrub:focus-within .rdp-knob { opacity: 1; }
.rdp-scrub:focus-visible { outline: none; }
.rdp-scrub:focus-visible::before { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }
/* the hover tooltip: chapter name · book % — clamped within the track (player.js),
   so it can never leave the viewport (UX-IT: floating UI stays visible) */
.rdp-tip {
  position: absolute; bottom: 100%; left: 0; margin-bottom: 7px; transform: translateX(-50%);
  padding: 0.22rem 0.5rem; border-radius: 8px; white-space: nowrap; pointer-events: none; z-index: 3;
  font: 600 0.72rem/1.2 var(--rd-sans); color: var(--bg); background: color-mix(in srgb, var(--ink) 92%, transparent);
  box-shadow: 0 6px 20px -8px color-mix(in srgb, var(--rd-dim) 80%, transparent);
  max-width: 16rem; overflow: hidden; text-overflow: ellipsis;
}
.rdp-tip[hidden] { display: none; }
/* passive top-edge hairline — the scrubber replaces it, so it stays hidden by
   default; templates that hide the scrubber (Scroll) fall back to their own meter */
.rdp-line { display: none; }
.rdp-line > span { display: block; height: 100%; width: 0%; background: var(--accent); }

.rdp-bar {
  position: relative;
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.35rem 0.55rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(20px) saturate(1.3); -webkit-backdrop-filter: blur(20px) saturate(1.3);
  border: 1px solid var(--rd-rule); border-radius: 999px;
  box-shadow: 0 8px 30px -10px color-mix(in srgb, var(--rd-dim) 70%, transparent),
              0 1px 0 color-mix(in srgb, var(--bg) 60%, transparent) inset;
}
/* the info column (chapter · time-left) sits to the left, compact + optional on narrow */
/* LAYOUT-LOCK: the info column is a FIXED width so a changing chapter title or
   time-left string can never resize the bar (which would re-centre the floating
   pill and make the controls jump under the cursor). Title + time truncate inside. */
.rd-player .rdp-info { flex: 0 0 11rem; width: 11rem; max-width: 11rem; }
@media (max-width: 460px) { .rd-player .rdp-info { display: none; } }
.rdp-info {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 0;
  background: transparent; border: none; padding: 0.15rem 0.3rem; cursor: pointer; text-align: left;
  color: var(--ink); font-family: inherit; border-radius: 8px; overflow: hidden;
}
.rdp-info:hover { background: var(--rd-surface); }
.rdp-info:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rdp-ch {
  font-family: var(--rd-serif); font-style: italic; font-weight: 600; font-size: 0.98rem;
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rdp-left { max-width: 100%; font-size: 0.7rem; letter-spacing: 0.06em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.rdp-ctls { display: flex; align-items: center; gap: 0.15rem; flex: none; }
/* LAYOUT-LOCK: every control is a FIXED size (width, not min-width) so its content
   — the speed label 1×→1.75×, a skip flash, the play/pause glyph — can never grow
   the button and shift its neighbours. */
.rdp-btn {
  display: inline-grid; place-items: center; width: 40px; min-width: 40px; height: 40px; padding: 0;
  border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--ink);
  cursor: pointer;
}
.rdp-btn:hover { background: var(--rd-surface); }
.rdp-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rdp-play { color: var(--bg); background: var(--accent); border-radius: 50%; }
.rdp-play:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.rdp-jump { color: var(--accent); }
.rdp-exit { color: var(--muted); min-width: 34px; }
.rdp-pin { min-width: 34px; }
.rdp-pin:hover, .rdp-pin.on { color: var(--accent); }
/* LP-sleeve cover — hidden by default; surfaces (and grows) in the popped-out
   window. A square cardboard jacket faced with the cover art (or the title),
   the grooved record peeking out of the open right edge; the record spins
   while playing, parked when paused. */
.rdp-vinyl {
  display: none; flex: none; position: relative; width: 56px; height: 46px;
  border: 0; padding: 0; background: transparent; cursor: pointer;
}
.rdp-vrec {                                  /* the record, tucked in the sleeve */
  position: absolute; top: 7%; bottom: 7%; right: 0; aspect-ratio: 1;
  border-radius: 50%;
  background:
    conic-gradient(rgba(255,255,255,0.1) 0deg, rgba(255,255,255,0) 55deg, rgba(255,255,255,0) 165deg, rgba(255,255,255,0.07) 205deg, rgba(255,255,255,0) 260deg),
    repeating-radial-gradient(circle at 50% 50%, #1c1c1c 0 1.4px, #0f0f0f 1.5px 3px),
    #141414;
  box-shadow: 0 0 0 1px color-mix(in srgb, #000 55%, transparent);
  animation: rdp-spin 3.4s linear infinite; animation-play-state: paused;
}
.rd-player[data-rd-playing] .rdp-vrec,
.rdp-shell[data-rd-playing] .rdp-vrec { animation-play-state: running; }   /* shell flag = the one that rides into PiP */
.rdp-vlabel {                                /* the jacket face */
  position: absolute; inset: 0 auto 0 0; aspect-ratio: 1; border-radius: 2px;
  overflow: hidden; box-sizing: border-box;
  background-size: cover; background-position: center; background-color: var(--accent);
  color: var(--bg); display: grid; place-items: center; text-align: center;
  font: 700 0.42rem/1.05 var(--rd-sans); padding: 2px;
  box-shadow: 3px 0 6px -2px color-mix(in srgb, #000 60%, transparent),
              0 0 0 1px color-mix(in srgb, #000 45%, transparent) inset;
}
.rdp-vinyl.has-art .rdp-vlabel { background-color: #ddd; }
.rdp-vlabel::after {                         /* cardboard spine + opening edge */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,0.26) 0, rgba(0,0,0,0) 7%, rgba(0,0,0,0) 93%, rgba(0,0,0,0.16) 100%);
}
@keyframes rdp-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .rd-player[data-rd-playing] .rdp-vrec,
  .rdp-shell[data-rd-playing] .rdp-vrec { animation: none; }
}
/* compact speed stepper — shows the current rate as text (1×, 1.5×, 3×).
   LAYOUT-LOCK: fixed width sized for the widest label ("1.75×"), so stepping the
   speed never resizes the button. */
.rdp-speed {
  width: 3.2rem; min-width: 3.2rem; height: 40px; padding: 0; border-radius: 999px;
  font-family: var(--rd-sans); font-weight: 700; font-size: 0.82rem; color: var(--ink);
  font-variant-numeric: tabular-nums; text-align: center;
}
.rdp-speed:hover { background: var(--rd-surface); }
/* incremental skip: a small "+20s" tag flashes as fast taps widen the jump */
.rdp-skip { position: relative; }
.rdp-skiptag {
  position: absolute; top: -0.55rem; left: 50%; transform: translateX(-50%);
  font: 700 0.62rem/1 var(--rd-sans); color: var(--bg); background: var(--accent);
  padding: 0.1rem 0.3rem; border-radius: 999px; white-space: nowrap; pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.rdp-skiptag[hidden] { display: none; }
.rdp-skip.rdp-chain { color: var(--accent); }
/* Document Picture-in-Picture window: ONLY the player, edge to edge, themed —
   no reader chrome. Contents grow responsively with the window (bigger → the
   LP-sleeve cover appears and enlarges). NOTE: the browser draws its own small
   origin title bar above this; that strip is platform-mandated and not removable
   by the page. The persistent <audio> stays in the page, so playback never stops. */
body.rdp-pip-body {
  margin: 0; width: 100vw; height: 100vh; overflow: hidden;
  background: var(--bg); color: var(--ink); font-family: var(--rd-sans);
  display: flex; align-items: center; justify-content: center;
}
body.rdp-pip-body .rdp-shell {
  display: flex; flex-direction: column; justify-content: center; gap: 0.55rem; position: relative;
  width: 100%; height: 100%; padding: 0.7rem 0.95rem; box-sizing: border-box;
}
body.rdp-pip-body .rdp-bar {
  border: 0; box-shadow: none; background: transparent; padding: 0; gap: 0.4rem;
  backdrop-filter: none; -webkit-backdrop-filter: none; flex-wrap: wrap;
}
body.rdp-pip-body .rdp-scrub { display: block; order: -1; margin: 0; }
body.rdp-pip-body .rdp-line { display: none; }
/* LAYOUT-LOCK: fixed-width info in the pop-out too, so a changing title/time never
   reflows the wrapped control row (which made the buttons jump under the cursor). */
body.rdp-pip-body .rdp-info { display: flex; flex: 0 0 11rem; width: 11rem; max-width: 11rem; }
/* the track sits at the top of the pop-out → flip its tooltip below it */
body.rdp-pip-body .rdp-tip { bottom: auto; top: 100%; margin-top: 7px; margin-bottom: 0; }
/* "the bigger the window, the more we can fit" — the LP cover appears, then grows */
@media (min-width: 470px) { body.rdp-pip-body .rdp-vinyl { display: block; } }
@media (min-width: 640px) {
  body.rdp-pip-body .rdp-vinyl { width: 80px; height: 66px; }
  body.rdp-pip-body .rdp-vlabel { font-size: 0.5rem; }
}
@media (min-width: 820px) {
  body.rdp-pip-body .rdp-shell { gap: 0.8rem; padding: 1rem 1.3rem; }
  body.rdp-pip-body .rdp-vinyl { width: 126px; height: 104px; }
  body.rdp-pip-body .rdp-ch { font-size: 1.15rem; }
}
/* very small pop-out: drop the text column so the controls always fit (never clip) */
@media (max-width: 384px) { body.rdp-pip-body .rdp-info { display: none; } }
/* the expanded sheet (Contents / speed / sleep) inside the pop-out: an IN-FLOW
   panel under the bar. The page's anchoring — bottom:100% here, the templates'
   position:fixed overrides — is meaningless in the tiny PiP viewport and landed
   the sheet off-window: the Contents were unreachable from the pop-out. In flow
   it takes the leftover height and scrolls; the scrub + bar never shrink. */
body.rdp-pip-body .rdp-bar { flex: none; }
body.rdp-pip-body .rdp-sheet {
  position: static; inset: auto; order: 1; margin: 0;
  width: auto; max-width: none; flex: 1 1 auto; min-height: 0; max-height: none;
  overflow-y: auto; border-radius: 12px;
}
/* grown pop-out: the Contents panel is ALWAYS on, alongside the LP cover — the
   same progressive @media reveal the vinyl uses (the bigger the window, the more
   it fits). The ▲ toggle disappears with it: its target is permanently open.
   (Headless PiP ignores resizeTo — verified via @media rule inspection.) */
@media (min-width: 820px) and (min-height: 320px) {
  body.rdp-pip-body .rdp-shell {
    display: grid; column-gap: 1.1rem; align-items: stretch;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 34%);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: 'scrub scrub' 'bar toc';
  }
  body.rdp-pip-body .rdp-scrub { grid-area: scrub; }
  body.rdp-pip-body .rdp-bar { grid-area: bar; align-self: center; }
  body.rdp-pip-body .rdp-sheet, body.rdp-pip-body .rdp-sheet[hidden] {
    display: block; grid-area: toc;
  }
  body.rdp-pip-body .rdp-more { display: none; }
}

/* expanded sheet — chapters / speed / sleep */
.rdp-sheet {
  position: absolute; bottom: 100%; right: 10px; margin-bottom: 8px;
  width: min(400px, calc(100vw - 20px)); max-height: min(60vh, 460px); overflow-y: auto;
  background: var(--bg); border: 1px solid var(--rd-rule); border-radius: 14px;
  padding: 0.9rem 1rem 1rem;
  box-shadow: 0 18px 48px -18px color-mix(in srgb, var(--rd-dim) 85%, transparent);
  /* razor-thin scrollbar (standing rule) */
  scrollbar-gutter: stable; scrollbar-width: thin; scrollbar-color: transparent transparent;
}
.rdp-sheet:hover, .rdp-sheet:focus-within { scrollbar-color: color-mix(in srgb, var(--rd-dim) 60%, transparent) transparent; }
.rdp-sheet::-webkit-scrollbar { width: 12px; background: transparent; }
.rdp-sheet::-webkit-scrollbar-track { background: transparent; border: 0; }
.rdp-sheet::-webkit-scrollbar-button { width: 0; height: 0; display: none; }
.rdp-sheet::-webkit-scrollbar-thumb {
  background-color: transparent; background-clip: padding-box;
  border: 3px solid transparent; border-radius: 999px; min-height: 40px;
}
.rdp-sheet:hover::-webkit-scrollbar-thumb { background-color: color-mix(in srgb, var(--rd-dim) 60%, transparent); }
.rdp-sheet[hidden] { display: none; }
/* narrow phones: the pill-anchored sheet (wider than the pill) ran past the left
   viewport edge — same bug class as the PiP off-window sheet: anchoring that
   ignores the real viewport. Pin it to the viewport instead, and make its width
   values border-box (content-box padding pushed the Scroll's calc(100vw - 24px)
   past 100vw). Templates with their own placement (Scroll in-column, Serial top
   strip, Folio bottom sheet) load after this sheet and keep their overrides. */
@media (max-width: 480px) {
  .rdp-sheet {
    position: fixed; left: 10px; right: 10px; width: auto; box-sizing: border-box;
    bottom: calc(70px + env(safe-area-inset-bottom)); margin-bottom: 0;
  }
}
.rdp-sec { margin: 0 0 0.9rem; }
.rdp-sec:last-child { margin-bottom: 0; }
.rdp-label {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted);
  margin: 0 0 0.45rem;
}
.rdp-chapters { display: grid; gap: 2px; }
.rdp-chapter {
  display: flex; align-items: baseline; gap: 0.55rem; width: 100%; text-align: left;
  padding: 0.4rem 0.55rem; border: none; border-radius: 9px; background: transparent;
  color: var(--ink); cursor: pointer; font-family: inherit; font-size: 0.88rem; line-height: 1.3;
}
.rdp-chapter:hover { background: var(--rd-surface); }
.rdp-chapter.on { background: var(--rd-surface); box-shadow: inset 2px 0 0 var(--accent); }
.rdp-chapter-num { flex: none; width: 1.4em; font-size: 0.72rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.rdp-chapter.on .rdp-chapter-num { color: var(--accent); }
.rdp-chapter-title { flex: 1; min-width: 0; font-family: var(--rd-serif); }
.rdp-chapter-dur { flex: none; font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.rdp-row { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.rdp-pill {
  font-family: inherit; font-size: 0.8rem; color: var(--ink); cursor: pointer;
  background: var(--rd-surface); border: 1px solid var(--rd-rule); border-radius: 999px;
  padding: 0.3rem 0.7rem; font-variant-numeric: tabular-nums; transition: border-color 0.15s;
}
.rdp-pill:hover { border-color: var(--accent); }
.rdp-pill.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.rdp-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rdp-note { margin-top: 0.5rem; font-size: 0.74rem; color: var(--muted); }
@media (hover: none) {
  .rdp-sheet { scrollbar-width: auto; scrollbar-color: auto; scrollbar-gutter: auto; }
  .rdp-sheet::-webkit-scrollbar { width: 0; height: 0; }
}

/* URLs and other unbroken runs inside links may exceed any measure — break anywhere.
   Scoped to the whole reading body: footnote/endnote anchors live outside .rd-prose. */
.rd-body a { overflow-wrap: anywhere; word-break: break-word; -webkit-hyphens: none; hyphens: none; } /* WebKit: hyphens:auto suppresses overflow-wrap break points — URLs must not hyphenate anyway */

/* ============================ FOOTNOTES + ENDNOTES (notes.js) ============================
   The SSR baseline: sup.fn markers in the prose + a linked .rd-notes endnotes
   block at each chapter's end (works without JS; SEO-visible). notes.js
   upgrades markers to popovers: hover bubble on desktop prose, bottom sheet on
   phones, print-style page-bottom band on the Folio (folio.css restyles it). */
sup.fn { line-height: 0; }
sup.fn a {
  position: relative; z-index: 2;                    /* own hit area, above surrounding inline runs */
  color: var(--accent); text-decoration: none; font-weight: 600;
  font-size: 0.72em; font-variant-numeric: lining-nums tabular-nums;
  padding: 0.45em 0.4em; margin: -0.45em -0.2em;     /* comfortable tap target, zero layout shift */
  border-radius: 5px;
}
sup.fn a:hover, sup.fn a[aria-expanded='true'] { background: color-mix(in srgb, var(--accent) 14%, transparent); }
sup.fn a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.rd-notes {
  margin: 2.8em 0 0; padding-top: 1.2em;
  border-top: 1px solid var(--rd-rule);
  font-size: 0.85em; line-height: 1.5;
  /* endnote text (esp. imported footnotes with raw URLs/long tokens) must never
     widen the column — a bare-URL run would otherwise blow out the whole layout
     viewport and drag every fixed bar + full-bleed band off-screen with it. */
  max-width: var(--rd-measure); overflow-wrap: anywhere; word-break: break-word;
}
.rd-note, .rd-note-def, .rd-note-src { overflow-wrap: anywhere; word-break: break-word; -webkit-hyphens: none; hyphens: none; }
.rd-notes-head {
  font-family: var(--rd-sans); font-size: 0.66rem; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
  margin: 0 0 0.8em; text-align: left;
}
.rd-notes-list { margin: 0; padding-left: 1.7em; text-align: left; }
.rd-note { margin: 0 0 0.7em; }
.rd-note::marker { color: var(--muted); font-variant-numeric: lining-nums tabular-nums; }
.rd-note-src { color: var(--muted); }
.rd-note-def + .rd-note-src { display: block; margin-top: 0.15em; font-size: 0.94em; }
.rd-note-back { margin-left: 0.45em; text-decoration: none; color: var(--muted); }
.rd-note-back:hover, .rd-note-back:focus-visible { color: var(--accent); }
.rd-note:target { animation: rd-note-flash 1.8s ease-out 1; }
@keyframes rd-note-flash {
  0%, 45% { background: color-mix(in srgb, var(--accent) 16%, transparent); }
  100% { background: transparent; }
}
/* anchor jumps (marker ⇄ endnote) land clear of the fixed top bar */
.rd-note, sup.fn a { scroll-margin-top: calc(var(--rdt-topbar, 56px) + 20px); }

/* external links: visibly styled + a quiet new-tab tell */
.rd-prose a[target='_blank'], .rd-note a[target='_blank'] {
  text-decoration: underline; text-underline-offset: 2px;
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
}
.rd-prose a[target='_blank']::after, .rd-note a[target='_blank']::after {
  content: '\2197'; font-size: 0.68em; vertical-align: super;
  margin-left: 0.12em; opacity: 0.55;
}

/* the footnote popover (created by notes.js, one per page) */
.rd-fnpop {
  position: fixed; z-index: 75;
  /* both axes capped to the viewport (UX-IT: floating elements never leave it);
     long notes scroll internally. notes.js clamps top/left/bottom/right and
     flips above the marker when below won't fit, re-clamping on resize/scroll. */
  width: min(26rem, calc(100vw - 24px));
  max-height: min(19rem, calc(100vh - 24px)); overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border: 1px solid var(--rd-rule); border-radius: 12px;
  padding: 0.75rem 0.95rem;
  font-family: var(--rd-serif); font-size: 0.86rem; line-height: 1.55; color: var(--ink);
  box-shadow: 0 18px 48px -18px color-mix(in srgb, var(--rd-dim) 85%, transparent);
}
.rd-fnpop[hidden] { display: none; }
.rd-fnpop:focus { outline: none; }
.rd-fnpop-n { color: var(--accent); font-weight: 600; font-variant-numeric: lining-nums; }
.rd-fnpop-src { color: var(--muted); font-size: 0.93em; }
.rd-fnpop-def + .rd-fnpop-src { margin-top: 0.45em; }
/* phone prose: a bottom sheet — bubbles clip on small screens */
.rd-fnpop[data-rd-mode='sheet'] {
  left: 50%; top: auto; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  width: min(40rem, calc(100vw - 16px));
  border-radius: 14px;
  box-shadow: 0 -12px 40px -12px color-mix(in srgb, var(--rd-dim) 85%, transparent);
}

/* ============================ ABOUT-THIS-BOOK INFO PANEL (reader-core.js) ============================
   The topbar (i) opens a centred modal: title/subtitle/author, the untitled
   "editions" links row (commercial versions), the colophon, and the author's
   note. Always in the viewport — centred, capped height, scrolls internally. */
.rd-info { position: fixed; inset: 0; z-index: 160; display: grid; place-items: center; padding: 1rem; }
.rd-info[hidden] { display: none; }
.rd-info-scrim { position: absolute; inset: 0; background: color-mix(in srgb, var(--ink) 44%, transparent); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.rd-info-card {
  position: relative; z-index: 1; box-sizing: border-box; width: min(30rem, 100%); max-height: min(84vh, 640px); overflow-y: auto;
  background: var(--bg); color: var(--ink); border: 1px solid var(--rd-rule); border-radius: 16px;
  padding: 1.5rem 1.6rem 1.7rem;
  box-shadow: 0 24px 64px -22px color-mix(in srgb, var(--rd-dim) 90%, transparent);
  /* razor-thin scrollbar (standing rule) */
  scrollbar-gutter: stable; scrollbar-width: thin; scrollbar-color: transparent transparent;
}
.rd-info-card:hover, .rd-info-card:focus-within { scrollbar-color: color-mix(in srgb, var(--rd-dim) 60%, transparent) transparent; }
.rd-info-card::-webkit-scrollbar { width: 12px; background: transparent; }
.rd-info-card::-webkit-scrollbar-thumb { background-color: transparent; background-clip: padding-box; border: 3px solid transparent; border-radius: 999px; min-height: 40px; }
.rd-info-card:hover::-webkit-scrollbar-thumb { background-color: color-mix(in srgb, var(--rd-dim) 60%, transparent); }
.rd-info-x {
  position: absolute; top: 0.7rem; right: 0.8rem; width: 34px; height: 34px; display: grid; place-items: center;
  border: none; background: transparent; color: var(--muted); font-size: 1.5rem; line-height: 1; border-radius: 8px; cursor: pointer;
}
.rd-info-x:hover { background: var(--rd-surface); color: var(--ink); }
.rd-info-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rd-info-h { font-family: var(--rd-serif); font-weight: 600; font-size: 1.4rem; line-height: 1.2; margin: 0 2rem 0.15rem 0; text-wrap: balance; }
.rd-info-sub { font-family: var(--rd-serif); font-style: italic; color: var(--muted); margin: 0 0 0.35rem; font-size: 1.02rem; text-wrap: balance; }
.rd-info-by { color: var(--ink); margin: 0 0 0.2rem; font-size: 0.95rem; }
.rd-info-block { margin-top: 1.15rem; padding-top: 1.1rem; border-top: 1px solid var(--rd-rule); }
.rd-info-eds { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.rd-ed {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-family: var(--rd-sans); font-size: 0.86rem; font-weight: 600; text-decoration: none;
  color: var(--accent); background: var(--rd-surface); border: 1px solid var(--rd-rule);
  border-radius: 999px; padding: 0.42rem 0.85rem; transition: border-color 0.15s, background 0.15s;
}
.rd-ed:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--bg)); }
.rd-ed:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rd-info-meta { margin: 0; display: grid; gap: 0.45rem; }
.rd-info-row { display: grid; grid-template-columns: 8.5rem 1fr; gap: 0.6rem; align-items: baseline; }
.rd-info-row dt { font-family: var(--rd-sans); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0; }
.rd-info-row dd { margin: 0; font-size: 0.92rem; color: var(--ink); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.rd-info-about { margin: 1.15rem 0 0; padding-top: 1.1rem; border-top: 1px solid var(--rd-rule); font-style: italic; color: var(--muted); line-height: 1.55; font-size: 0.95rem; }
/* Abuse/takedown route — reachable from every hosted book page (R-01). Quiet by design. */
.rd-info-report { margin: 1.1rem 0 0; padding-top: 0.9rem; border-top: 1px solid var(--rd-rule); font-family: var(--rd-sans); font-size: 0.76rem; }
.rd-info-report a { color: var(--muted); text-decoration: none; border-bottom: 1px solid transparent; }
.rd-info-report a:hover { color: var(--ink); border-bottom-color: var(--rd-rule); }
@media (max-width: 460px) { .rd-info-row { grid-template-columns: 1fr; gap: 0.05rem; } }
