/* Chapter-only reading controls; manuscript markup stays untouched. */
.chapter-page {
  --reader-paper: #f2f0ed;
  --reader-ink: #161314;
  --reader-muted: #666666;
  --reader-line: #c7c7c7;
  --reader-accent: #ff4545;
  --reader-text-size: 21px;
  --reader-toolbar-top: 96px;
}
.chapter-page[data-reader-size="small"] { --reader-text-size: 18px; }
.chapter-page[data-reader-size="large"] { --reader-text-size: 24px; }
.chapter-page[data-reader-theme="dark"] {
  --reader-paper: #161314;
  --reader-ink: #f2f0ed;
  --reader-muted: #bdbdbd;
  --reader-line: #474747;
}
.chapter-page .reader-tools[hidden] { display: none !important; }
.chapter-page .reader-tools {
  position: sticky;
  top: var(--reader-toolbar-top);
  z-index: 45;
  max-width: 1050px;
  margin: 0 auto 24px;
  background: var(--reader-paper);
  color: var(--reader-ink);
  border: 1px solid var(--reader-line);
  box-shadow: 0 5px 24px #16131410;
  font: 500 13px/1.3 var(--sans, 'DM Sans', sans-serif);
}
.chapter-page .reader-tools-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
}
.chapter-page .reader-tools-exit {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  font-weight: 700;
  white-space: nowrap;
  color: var(--reader-ink);
}
.chapter-page .reader-tool-field { display: flex; align-items: center; gap: 9px; }
.chapter-page .reader-tool-field > span { color: var(--reader-muted); white-space: nowrap; }
.chapter-page .reader-tool-field select {
  min-height: 42px;
  padding: 7px 28px 7px 9px;
  border: 1px solid var(--reader-line);
  border-radius: 0;
  background: var(--reader-paper);
  color: var(--reader-ink);
  font: inherit;
  cursor: pointer;
  max-width: 100%;
}
.chapter-page .reader-focus-button {
  min-height: 42px;
  padding: 8px 15px;
  border: 1px solid var(--reader-line);
  border-radius: 0;
  background: transparent;
  color: var(--reader-ink);
  font: 700 13px/1.3 var(--sans, 'DM Sans', sans-serif);
  cursor: pointer;
  white-space: nowrap;
}
.chapter-page .reader-focus-button[aria-pressed="true"] { background: var(--reader-accent); color: #161314; border-color: var(--reader-accent); }
.chapter-page .reader-tools a:hover { text-decoration: underline; text-underline-offset: 4px; }
.chapter-page .reader-tools button:hover { border-color: var(--reader-ink); }
.chapter-page .reader-tools :is(a, button, select):focus-visible { outline: 3px solid #b71c2c; outline-offset: 3px; }
.chapter-page .reader-progress-label { min-width: 3.5ch; font-variant-numeric: tabular-nums; color: var(--reader-muted); text-align: right; }
.chapter-page .reader-progress { height: 3px; overflow: hidden; background: var(--reader-line); }
.chapter-page .reader-progress > span { display: block; width: 100%; height: 100%; background: #b71c2c; transform: scaleX(0); transform-origin: left center; }
.chapter-page[data-reader-theme="dark"] .reader-progress > span { background: var(--reader-accent); }
.chapter-page .reading-surface { background: var(--reader-paper); color: var(--reader-ink); }
.chapter-page .chapter-prose .chapter-text { font-size: var(--reader-text-size); line-height: 1.85; color: var(--reader-ink); }
.chapter-page .chapter-prose .chapter-text > p { color: inherit; }
.chapter-page .chapter-prose .chapter-text :is(h2, h3, h4) { color: var(--reader-ink); scroll-margin-top: 200px; }
.chapter-page .chapter-prose .chapter-text h2 { font-size: 1.75em; }
.chapter-page .chapter-prose .chapter-text h3 { font-size: 1.4em; }
.chapter-page .chapter-text hr { border-color: var(--reader-line); }
.chapter-page[data-reader-theme="dark"] .chapter-text code { background: #343434; color: #efefef; }
.chapter-page[data-reader-theme="dark"] :is(.chapter-aside, .chapter-end, .chapter-pagination span) { color: var(--reader-muted); border-color: var(--reader-line); }
.chapter-page[data-reader-theme="dark"] :is(.chapter-picker summary, .chapter-picker a, .chapter-picker a span, .chapter-pagination strong, .chapter-aside .text-link) { color: #ff4545; border-color: var(--reader-line); }
.chapter-page[data-reader-theme="dark"] .chapter-pagination { border-color: var(--reader-line); }
.chapter-page[data-reader-theme="dark"] :is(.reader-support, .paperback-order) { background: #2a2a2a; color: var(--reader-ink); border-color: var(--reader-line); }
.chapter-page[data-reader-theme="dark"] :is(.reader-support .text-link, .paperback-order .order-policy, .paperback-order .paperback-price) { color: #ff4545; }
.chapter-page[data-reader-theme="dark"] .paperback-order .te-commerce-actions .te-button.te-secondary { color: #ff4545 !important; border-color: #959595; }
.chapter-page.is-reading-focus { --reader-toolbar-top: 12px; }
.chapter-page.is-reading-focus :is(.site-header, .footer, .chapter-aside, .chapter-prose > .paperback-order, .chapter-prose > .reader-support) { display: none !important; }
.chapter-page.is-reading-focus .reading-layout { grid-template-columns: minmax(0, 710px); }
.chapter-page.is-reading-focus .chapter-heading { padding-top: 38px; }
.chapter-page.is-reading-focus .chapter-prose .chapter-text :is(h2, h3, h4) { scroll-margin-top: 115px; }
@media (max-width: 760px) {
  .chapter-page { --reader-toolbar-top: 82px; }
  .chapter-page .reader-tools { width: calc(100% - 24px); }
  .chapter-page .reader-tools-controls { display: grid; grid-template-columns: 1fr auto auto; gap: 5px 12px; padding: 8px 12px; }
  .chapter-page .reader-tools-exit { grid-column: 1; grid-row: 1; }
  .chapter-page .reader-tool-field { grid-row: 2; gap: 6px; }
  .chapter-page .reader-tool-field[for="reader-text-size"] { grid-column: 1 / 3; }
  .chapter-page .reader-tool-field[for="reader-paper"] { grid-column: 3; }
  .chapter-page .reader-focus-button { grid-column: 2 / 4; grid-row: 1; justify-self: end; }
  .chapter-page .reader-progress-label { display: none; }
  .chapter-page .reader-tool-field select { min-width: 0; padding-right: 20px; }
  .chapter-page .chapter-prose .chapter-text { line-height: 1.8; }
  .chapter-page .chapter-prose .chapter-text :is(h2, h3, h4) { scroll-margin-top: 225px; }
  .chapter-page.is-reading-focus .chapter-prose .chapter-text :is(h2, h3, h4) { scroll-margin-top: 150px; }
}
@media (prefers-reduced-motion: reduce) {
  .chapter-page .reader-tools, .chapter-page .reader-tools * { transition: none !important; animation: none !important; scroll-behavior: auto; }
}
@media print {
  .chapter-page .reader-tools { display: none !important; }
  .chapter-page .reading-surface, .chapter-page .chapter-prose .chapter-text { color: #000 !important; background: #fff !important; }
  .chapter-page .chapter-prose .chapter-text { font-size: 12pt; }
}
