/*
  📖 The reader (web/novel-read.js): the book set as real pages on paper (--paper, --paper-ink, --book-font), the cover
  in the book's colour (--cover-<key>, the words on it --cover-ink), a running head and the page number, two pages side
  by side from 900 px (.nr-two), one on a phone. The page size comes from the script as --nr-pw / --nr-ph / --nr-fs
  (6 × 9, fitting the window): the hidden page it measures with (.nr-measure) is styled exactly like the ones shown, so
  nothing here may make a page's lines differ by where it is (edit mode's highlight is background, shadow and outline
  only). Tokens only: no colour of its own. Motion only at ✨ Full (html[data-fx="full"]), never under reduced motion.
*/

.nr-reader { --nr-pw: 280px; --nr-ph: 420px; --nr-fs: 15px; display: flex; flex-direction: column; gap: .75rem; min-width: 0; max-width: 100%; }
.nr-reader.nr-plain { gap: 1rem; }
/* (100svh in px: the window's height without a phone's bars, read once per layout) */
.nr-vh { position: fixed; top: 0; left: 0; width: 1px; height: 100vh; height: 100svh; visibility: hidden; pointer-events: none; }

/* ---------- the head: ← Book, the title, ☰ Chapters, A− A+, ✏️ Edit, ✍️ Write ---------- */
.nr-top { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .6rem; min-width: 0; }
.nr-h { flex: 1 1 10rem; min-width: 0; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nr-tools { display: flex; flex: 1 1 auto; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .3rem; min-width: 0; max-width: 100%; }
.nr-chap-field { display: flex; flex: 1 1 6.5rem; min-width: 5.5rem; max-width: 15rem; }
.nr-chap-field select, .nr-chap-field .bsel-btn { width: 100%; min-width: 0; padding: .35rem .6rem; font-size: .85rem; }
.nr-size { display: inline-flex; gap: .25rem; }
.nr-tools .btn.small { min-height: 2.1rem; padding-left: .55rem; padding-right: .55rem; }
.nr-edit-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); color: var(--accent-text); }
@media (max-width: 420px) { .nr-wide { display: none; } }
/* (one line always, so turning ✏️ Edit on or off never changes the pages' size) */
.nr-note { margin: 0; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nr-editing .nr-note { color: var(--accent-text); }

/* ---------- the stage and the pages ---------- */
.nr-stage { position: relative; display: flex; justify-content: center; min-width: 0; padding: .25rem 0 .5rem; touch-action: pan-y pinch-zoom; outline: none; }
.nr-stage:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 4px; border-radius: var(--radius); }
.nr-spread { display: flex; justify-content: center; max-width: 100%; perspective: 1600px; }
.nr-measure { position: absolute; top: 0; left: 0; width: var(--nr-pw); height: var(--nr-ph); visibility: hidden; pointer-events: none; contain: strict; z-index: -1; }
.nr-measure .nr-page { box-shadow: none; }

.nr-page {
  position: relative; box-sizing: border-box; flex: none; display: flex; flex-direction: column; overflow: hidden;
  width: var(--nr-pw); height: var(--nr-ph);
  padding: calc(var(--nr-pw) * .07) calc(var(--nr-pw) * .1) calc(var(--nr-pw) * .05);
  background: var(--paper); color: var(--paper-ink); border: 1px solid var(--paper-edge); border-radius: 3px 6px 6px 3px;
  box-shadow: var(--paper-shadow);
  font-family: var(--book-font); font-size: var(--nr-fs); line-height: 1.5;
  font-kerning: normal; font-variant-ligatures: common-ligatures; text-rendering: optimizeLegibility;
}
/* Side by side: the inner margins a little wider (the same text width either side), the spine shaded. */
.nr-two .nr-page.nr-left { padding-left: calc(var(--nr-pw) * .085); padding-right: calc(var(--nr-pw) * .115); border-radius: 6px 0 0 6px; border-right-color: transparent; box-shadow: var(--paper-shadow), inset -18px 0 22px -18px color-mix(in srgb, var(--paper-ink) 28%, transparent); }
.nr-two .nr-page.nr-right:not(.nr-cover) { padding-left: calc(var(--nr-pw) * .115); padding-right: calc(var(--nr-pw) * .085); border-radius: 0 6px 6px 0; border-left-color: transparent; box-shadow: var(--paper-shadow), inset 18px 0 22px -18px color-mix(in srgb, var(--paper-ink) 28%, transparent); }

.nr-run { flex: none; height: 1.5em; line-height: 1.5em; margin-bottom: .7em; font-size: .7em; letter-spacing: .12em; text-transform: uppercase; text-align: center; color: var(--paper-ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nr-body { flex: 1 1 auto; min-height: 0; overflow: hidden; overflow: clip; overflow-clip-margin: .25em; }
.nr-foot { flex: none; height: 1.5em; line-height: 1.5em; margin-top: .5em; font-size: .75em; text-align: center; color: var(--paper-ink-2); font-variant-numeric: oldstyle-nums; }

/* A chapter opens a little way down its page. */
.nr-chap { padding: clamp(1.25em, calc(var(--nr-ph) * .1), 5em) 0 1.25em; text-align: center; }
.nr-chap-n { margin: 0 0 .35em; font-size: .75em; letter-spacing: .2em; text-transform: uppercase; color: var(--paper-ink-2); }
.nr-chap-t { margin: 0; font-family: inherit; font-size: 1.5em; font-weight: 600; line-height: 1.25; color: inherit; overflow-wrap: break-word; }

/* Paragraphs: justified, hyphenated, a first-line indent (none after an opening or a break, nor where one goes on). */
.nr-p { margin: 0; text-align: justify; text-indent: 1.5em; hyphens: auto; -webkit-hyphens: auto; overflow-wrap: break-word; }
.nr-p.nr-flush { text-indent: 0; }
.nr-p.nr-split { text-align-last: justify; }
/* (a small phone's short lines, under ~30 characters: a ragged right edge reads better than wide gaps) */
.nr-ragged .nr-p, .nr-ragged .nr-p.nr-split { text-align: left; text-align-last: auto; }
.nr-chap + .nr-p::first-line { font-variant-caps: small-caps; letter-spacing: .04em; }
.nr-break { margin: 0; padding: .55em 0; text-align: center; letter-spacing: .45em; color: var(--paper-ink-2); }

/* The cover: the title page in the book's colour. */
.nr-cover { --nr-cover: var(--cover-violet); background: var(--nr-cover); color: var(--cover-ink); border-color: color-mix(in srgb, var(--nr-cover) 75%, var(--paper-ink)); border-radius: 3px 8px 8px 3px; padding: calc(var(--nr-pw) * .08); box-shadow: var(--paper-shadow), inset 7px 0 10px -6px color-mix(in srgb, var(--paper-ink) 45%, transparent); }
.nr-cover-violet { --nr-cover: var(--cover-violet); }
.nr-cover-midnight { --nr-cover: var(--cover-midnight); }
.nr-cover-forest { --nr-cover: var(--cover-forest); }
.nr-cover-wine { --nr-cover: var(--cover-wine); }
.nr-cover-ocean { --nr-cover: var(--cover-ocean); }
.nr-cover-amber { --nr-cover: var(--cover-amber); }
.nr-cover-rose { --nr-cover: var(--cover-rose); }
.nr-cover-slate { --nr-cover: var(--cover-slate); }
.nr-cover-in { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .7em; padding: 1.4em .9em; text-align: center; border: 1px solid color-mix(in srgb, var(--cover-ink) 40%, transparent); border-radius: 2px; overflow: hidden; }
.nr-cover-emoji { font-size: 2.6em; line-height: 1; }
.nr-cover-title { margin: 0; font-family: inherit; font-size: 1.9em; font-weight: 700; line-height: 1.15; color: inherit; overflow-wrap: anywhere; }
.nr-cover-sub { margin: 0; font-style: italic; opacity: .9; overflow-wrap: anywhere; }
.nr-cover-rule { width: 3em; height: 1px; background: currentColor; opacity: .6; }
.nr-cover-by { margin: 0; font-size: .95em; letter-spacing: .06em; overflow-wrap: anywhere; }
/* 🖼️ A cover image fills the title page (rounded like the cover, the spine still shaded over it; the colour shows
   while it loads). The title and author stay in the page for screen readers, visually hidden. */
.nr-has-cover { padding: 0; }
.nr-cover-img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.nr-has-cover::after { content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; box-shadow: inset 7px 0 10px -6px color-mix(in srgb, var(--paper-ink) 45%, transparent), inset 0 0 0 1px color-mix(in srgb, var(--cover-ink) 12%, transparent); }
.nr-has-cover .nr-cover-in { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* 🖼️ A chapter's art at the top of its opening page: a box of a fixed share of the page's height (novel-read.js
   ART.page), so the text under it is set the same whether the image has arrived or not (the measured page has the
   empty box). Decorative: the heading under it says what the chapter is. */
.nr-chap.nr-with-art { padding-top: 0; }
.nr-art { height: calc(var(--nr-ph) * .3); margin: 0 0 1.1em; border-radius: 6px; overflow: hidden; background: color-mix(in srgb, var(--paper-edge) 60%, var(--paper)); box-shadow: 0 1px 3px color-mix(in srgb, var(--paper-ink) 16%, transparent); }
.nr-art-img { display: block; width: 100%; height: 100%; object-fit: cover; }

/* ---------- ✏️ edit mode: a paragraph lights up under the mouse or the keyboard (both pieces of one cut in two) ---------- */
.nr-editing .nr-body [data-act="nr-para"] { cursor: pointer; border-radius: 3px; transition: background-color .15s ease, box-shadow .15s ease; }
.nr-editing .nr-body [data-act="nr-para"]:hover,
.nr-editing .nr-body [data-act="nr-para"].nr-hot { background: var(--highlight); box-shadow: 0 0 0 .15em var(--highlight); }
.nr-editing .nr-body [data-act="nr-para"]:focus-visible { background: var(--highlight); outline: 2px solid var(--accent); outline-offset: -1px; }
.nr-editing .nr-body [data-act="nr-para"]:focus:not(:focus-visible) { outline: none; }

/* ---------- under the pages: ←, the slider and "Page 12 of 240", → ---------- */
.nr-nav { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .6rem; width: 100%; max-width: 36rem; margin: 0 auto; }
.nr-turn { min-width: 2.75rem; font-size: 1.1rem; }
.nr-where { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.nr-slider { width: 100%; margin: 0; accent-color: var(--accent); }
.nr-label { text-align: center; font-size: .85rem; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- the ✏️ edit box ---------- */
.nr-form textarea { font-family: var(--book-font); font-size: 1.05rem; font-weight: 400; line-height: 1.6; min-height: 12rem; }
.nr-form-where { margin: -.4rem 0 0; }
.nr-form-hint { margin: -.35rem 0 0; }

/* ---------- turning (✨ Full only; core.js moves() adds the class only then too) ---------- */
@keyframes nr-turn-next { from { opacity: .2; transform: translateX(1.5rem) rotateY(-5deg); } to { opacity: 1; transform: none; } }
@keyframes nr-turn-prev { from { opacity: .2; transform: translateX(-1.5rem) rotateY(5deg); } to { opacity: 1; transform: none; } }
html[data-fx="full"] .nr-spread.nr-turn-next { animation: nr-turn-next .32s cubic-bezier(.2, .7, .3, 1) both; transform-origin: left center; }
html[data-fx="full"] .nr-spread.nr-turn-prev { animation: nr-turn-prev .32s cubic-bezier(.2, .7, .3, 1) both; transform-origin: right center; }
html[data-fx="subtle"] .nr-spread, html[data-fx="off"] .nr-spread { animation: none; }
html[data-fx="off"] .nr-editing .nr-body [data-act="nr-para"] { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .nr-spread { animation: none !important; }
  .nr-editing .nr-body [data-act="nr-para"] { transition: none; }
}
