/* Reading preferences are independent of the catalogue's light/dark theme. */
body.is-reading[data-reader-theme="light"] {
  color-scheme: light;
  --bg: #faf9f5; --paper: #fffdf5; --surface: #fffdf8; --ink: #20283e;
  --muted: #494951; --line: #dedbe5; --blue: #583c8a; --blue-hover: #503982;
  --tint: #ece6fa; --soft: #f0edf5; --series-ink: #496b56;
}
body.is-reading[data-reader-theme="dark"] {
  color-scheme: dark;
  --bg: #172035; --paper: #17222c; --surface: #1e2942; --ink: #fff6e4;
  --muted: #d0d4df; --line: #3c4761; --blue: #d7c8ff; --blue-hover: #ded2ff;
  --tint: #34324f; --soft: #28324b; --series-ink: #c7dfcc;
}
body.is-reading[data-reader-theme="black"] {
  color-scheme: dark;
  --bg: #000; --paper: #000; --surface: #141414; --ink: #eeeae2;
  --muted: #d0d0c8; --line: #353535; --blue: #d2bfff; --blue-hover: #e4d8ff;
  --tint: #292331; --soft: #202020; --series-ink: #d4cfbf;
}
body.is-reading[data-reader-theme="book"] {
  color-scheme: light;
  --bg: #f5ecd8; --paper: #f5ecd8; --surface: #fcf4e3; --ink: #342a20;
  --muted: #493f31; --line: #d5c7ad; --blue: #4d356e; --blue-hover: #402b60;
  --tint: #e8dfed; --soft: #ebe0ca; --series-ink: #594a32;
}
/* Retain the approved series colours for the existing reading themes. */
body.is-reading[data-reader-theme="light"][data-series="space"] { --paper: #f5fafb; --series-ink: #2d6572; }
body.is-reading[data-reader-theme="light"][data-series="forest"] { --paper: #fcf9f1; --series-ink: #7b6a49; }
body.is-reading[data-reader-theme="dark"][data-series="space"] { --paper: #14232d; --series-ink: #a7d6df; }
body.is-reading[data-reader-theme="dark"][data-series="forest"] { --paper: #1a2528; --series-ink: #e0cfaa; }
body.is-reading.no-ornaments[data-reader-theme="light"],
body.is-reading.no-ornaments[data-reader-theme="dark"] { --paper: var(--bg); --series-ink: var(--muted); }
body.is-reading .reader-scroll { background: var(--paper); }
body.is-reading .story-end { color: var(--muted); }
body.is-reading .reader-header-name small { display: flex; min-width: 0; column-gap: .3em; white-space: nowrap; }
.reader-header-author { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-header-name #progress-value { flex: none; white-space: nowrap; }
body.is-reading .reader-scroll::selection { background: var(--tint); color: var(--ink); }

.finish-panel { flex-wrap: wrap; }
.finish-panel .finish-actions { width: 100%; justify-content: center; }

.reader-lighting-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr)); gap: 8px; }
.reader-lighting-option { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; text-align: left; font-size: var(--type-control, 1rem); }
.reader-lighting-option:hover { background: var(--soft); }
.reader-lighting-option[aria-pressed="true"] { border-color: var(--blue); background: var(--tint); }
.reader-lighting-sample { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 6px; font: 19px Georgia, serif; box-shadow: inset 0 0 0 1px var(--line); }
.reader-lighting-sample[data-lighting="light"] { background: #fffdf5; color: #20283e; }
.reader-lighting-sample[data-lighting="dark"] { background: #17222c; color: #fff6e4; }
.reader-lighting-sample[data-lighting="black"] { background: #000; color: #eeeae2; }
.reader-lighting-sample[data-lighting="book"] { background: #f5ecd8; color: #342a20; }
.reader-mode-note { margin: 4px 0 0; color: var(--muted); font-size: var(--type-meta, .875rem); line-height: 1.5; }

/* The original DOM flows into columns; text and block IDs are never duplicated. */
.reader-scroll.reader-paged { position: relative; overflow: hidden; scrollbar-gutter: auto; --reader-safe-left: env(safe-area-inset-left, 0px); --reader-safe-right: env(safe-area-inset-right, 0px); padding: 16px var(--reader-page-gutter); touch-action: pan-y pinch-zoom; }
.reader-paged .reader { width: var(--reader-page-width); max-width: none; height: var(--reader-page-height); padding: 0; margin: 0; column-width: var(--reader-page-width); column-gap: var(--reader-page-gap); column-fill: auto; }
.reader-paged .story-content.has-verse { display: block; }
.reader-paged .story-text { orphans: 2; widows: 2; }
.reader-paged .reader-start { margin-top: 0; break-inside: avoid; }
.reader-paged .story-figure { margin: 12px 0 24px; break-inside: avoid; }
.reader-paged .story-picture { aspect-ratio: auto; }
.reader-paged .figure-button img { height: auto; max-height: calc(var(--reader-page-height) - 48px); aspect-ratio: auto; object-fit: contain; background: transparent; }
.reader-paged #finish-container { break-before: column; }
.reader-paged .finish-panel, .reader-paged .reader-next, .reader-paged .reader-ending, .reader-paged .reader-links { break-inside: avoid; }
.reader-paged .finish-panel { margin-top: 0; }
.reader-page-extent { position: absolute; top: 0; width: 1px; height: 1px; pointer-events: none; }
.reader-page-controls:not([hidden]) { display: flex; flex: none; justify-content: space-between; align-items: center; gap: 16px; max-width: 784px; width: 100%; align-self: center; padding: 8px max(20px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px)); background: var(--paper); border-top: 1px solid var(--line); font-family: var(--ui); }
.reader-page-controls button { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 10px; color: var(--blue); border-radius: 10px; }
.reader-page-controls button:hover:not([aria-disabled="true"]) { background: var(--soft); }
.reader-page-controls button[aria-disabled="true"] { opacity: .4; cursor: default; }
.reader-page-controls .reader-page-count { text-align: center; color: var(--muted); font-size: var(--type-meta, .875rem); font-variant-numeric: tabular-nums; line-height: 1.4; }

@media (max-width: 359px) {
  .reader-lighting-option { gap: 7px; padding-inline: 8px; }
  .reader-lighting-sample { width: 26px; height: 30px; }
}
