:root {
  --desk: #e5e1d9;
  --paper: #faf6eb;
  --ink: #302b24;
  --muted: #82786b;
  --line: #cfc6b5;
  --accent: #78573e;
  --size: 20px;
  color-scheme: light;
}
html[data-theme=dark] {
  --desk: #20201e;
  --paper: #302e29;
  --ink: #e4ddcf;
  --muted: #aba18f;
  --line: #4c463b;
  --accent: #c9a888;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--desk); font-family: system-ui, sans-serif; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; border-radius: 3px; }
button:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
button:disabled { opacity: .3; cursor: default; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.sr-only, .skip { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip:focus { position: fixed; top: 12px; left: 12px; width: auto; height: auto; clip-path: none; padding: 12px; z-index: 100; background: var(--paper); }
#reader:focus { outline: none; }
.menu-toggle { position: fixed; top: 13px; right: 14px; z-index: 15; width: 40px; height: 40px; display: grid; place-items: center; color: var(--muted); background: var(--desk); }
.page-view { padding: 32px 60px; min-height: 100dvh; display: grid; place-items: center; }
.book-stage {
  --height: min(calc((100vw - 120px) / 1.39), calc(100dvh - 64px), 806px);
  height: var(--height); width: calc(var(--height) * 1.39);
  display: flex; justify-content: center; position: relative;
  isolation: isolate; perspective: 2200px; touch-action: pan-y;
  filter: drop-shadow(0 16px 18px #00000015);
}
.book-stage.is-cover { width: calc(var(--height) * .647); }
/* Fine, offset rules form the cut edges of the paper block. */
.book-stage::before {
  content: ''; position: absolute; inset: 4px -4px -6px;
  border-radius: 3px 5px 7px 5px;
  background: repeating-linear-gradient(0deg, var(--line) 0 1px, var(--paper) 1px 3px);
  border: 1px solid var(--line); z-index: -1;
  box-shadow: 0 6px 12px #00000018;
}
.book-stage::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: calc(50% - 15px); width: 30px;
  background: linear-gradient(90deg, transparent, #00000009 30%, #00000025 49%, #00000030 51%, #ffffff0a 58%, transparent);
  pointer-events: none; z-index: 2;
}
.book-stage.is-cover::before { inset: 3px -3px -4px; background: #37342f; border-color: #302e28; }
.book-stage.is-cover::after { display: none; }
.sheet {
  position: relative; width: 50%; height: 100%; overflow: hidden; background-color: var(--paper);
  background-image: url('/paper.svg');
  border: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  box-shadow: inset -18px 0 28px -28px #0009;
}
.sheet.left-page { border-radius: 4px 0 0 6px; }
.sheet.right-page { border-radius: 0 4px 6px 0; box-shadow: inset 18px 0 28px -28px #0009; }
.sheet.left-page::after, .sheet.right-page::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, #00000002 80%, #0000000c 96%, #00000022);
}
.sheet.right-page::after { background: linear-gradient(90deg, #00000022, #00000007 4%, transparent 20%); }
.sheet.cover-sheet { width: 100%; background: #081012; border: 0; border-radius: 2px 4px 4px 2px; box-shadow: inset 6px 0 8px #0008; }
.cover-sheet img { display: block; width: 100%; height: 100%; object-fit: fill; }
.page-content { padding: 8% 10% 3%; height: calc(100% - 38px); overflow-y: auto; font-family: Georgia, 'Times New Roman', serif; font-size: calc(var(--size) * .8); line-height: 1.65; scrollbar-width: thin; scrollbar-color: var(--line) transparent; overscroll-behavior: contain; touch-action: pan-y; }
.page-content > p { margin: 0 0 1em; }
.page-content header { text-align: center; margin: 0 0 27px; }
.page-content h2 { font-size: 1.5em; line-height: 1.3; font-weight: normal; margin: 18px 0; }
.page-chapter { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; }
.page-subtitle { font-size: 11px; line-height: 1.5; color: var(--muted); }
.page-content pre { white-space: pre-wrap; font-size: 10px; line-height: 1.65; margin: 0; font-family: Georgia, serif; }
.front-page .page-content { display: flex; flex-direction: column; justify-content: center; text-align: center; gap: 25px; }
.front-page .page-content p { font-size: .9em; }
.folio { position: absolute; bottom: 17px; left: 0; right: 0; text-align: center; font: 12px Georgia, serif; color: var(--muted); }
.edge { position: absolute; top: 0; bottom: 0; width: 42px; padding: 0; z-index: 5; display: grid; align-items: center; opacity: 0; transition: opacity .2s; color: var(--muted); }
.edge.previous { left: -48px; justify-items: end; }
.edge.next { right: -48px; justify-items: start; }
.edge:hover { background: none; }
.book-stage:hover > .edge:not(:disabled), .edge:focus-visible { opacity: .65; }
.edge:disabled { visibility: hidden; }
/* Only one double-sided leaf moves; the remaining spread stays stationary. */
.turn-leaf { position: absolute; top: 0; height: 100%; width: 50%; z-index: 4; transform-style: preserve-3d; pointer-events: none; will-change: transform; }
.turn-leaf.forward { left: 50%; transform-origin: left center; }
.turn-leaf.backward { left: 0; transform-origin: right center; }
.turn-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.turn-face.back { transform: rotateY(180deg); }
.turn-face > .sheet { width: 100%; height: 100%; border-radius: 2px; }
.turn-face::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, #0002, transparent 24%, #0001 75%, #0003); }
.turn-bed { position: absolute; top: 0; width: 50%; height: 100%; z-index: 3; pointer-events: none; }
.turn-bed > .sheet { width: 100%; height: 100%; }
.single-leaf { width: 100%; left: 0 !important; }
#contents { position: fixed; inset: 0 0 0 auto; margin: 0; width: 380px; max-width: calc(100vw - 24px); height: 100dvh; max-height: 100dvh; background: var(--paper); color: var(--ink); padding: 20px 26px 50px; border: 0; border-left: 1px solid var(--line); overflow: auto; box-shadow: -12px 0 40px #0002; }
#contents::backdrop { background: #0005; }
.contents-heading { display: flex; align-items: center; justify-content: space-between; }
.contents-heading h2 { font: 24px Georgia, serif; }
.contents-heading button { font-size: 28px; width: 40px; height: 40px; }
.settings { border-bottom: 1px solid var(--line); padding-bottom: 20px; margin-bottom: 20px; font-size: 12px; }
.setting-row, #page-form { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; }
.setting-row button { min-width: 38px; min-height: 36px; }
.setting-row select { background: transparent; border: 0; padding: 7px 4px; text-align: right; font-size: 12px; }
#print-book { display: block; width: 100%; min-height: 38px; margin-top: 12px; border: 1px solid var(--line); text-align: center; }
#page-form { justify-content: flex-start; }
#page-form label { margin-right: auto; }
#page-form button { padding: 8px 10px; }
#page-number { width: 50px; background: transparent; border: 0; border-bottom: 1px solid var(--line); padding: 5px; text-align: center; appearance: textfield; }
#page-number::-webkit-inner-spin-button { appearance: none; }
#page-form span { color: var(--muted); }
nav h3 { font-size: 11px; line-height: 1.7; font-weight: 500; color: var(--muted); margin: 25px 0 10px; }
nav a { display: flex; gap: 14px; text-decoration: none; font-size: 13px; line-height: 1.6; padding: 8px 6px; border-radius: 3px; }
nav a:hover, nav a[aria-current=true] { background: var(--desk); }
nav a span { color: var(--muted); font-size: 11px; min-width: 20px; }
.scroll-view { padding: 40px 24px; background: var(--paper); }
.scroll-cover { display: flex; flex-direction: column; align-items: center; gap: 25px; margin-bottom: 50px; }
.scroll-cover img { width: min(330px, 80vw); height: auto; box-shadow: 0 12px 30px #0003; }
.scroll-cover a { font-size: 13px; text-decoration: none; }
.book { max-width: 640px; margin: auto; }
.chapter { padding-top: 70px; scroll-margin-top: 30px; font: var(--size)/1.85 Georgia, serif; overflow-wrap: break-word; }
.chapter header { margin-bottom: 40px; }
.chapter h2 { font-size: 1.8em; line-height: 1.2; font-weight: normal; margin: 15px 0; }
.chapter-number, .subtitle, .part { font-family: system-ui, sans-serif; font-size: 12px; color: var(--muted); }
.chapter > p { margin: 0 0 1.3em; }
.chapter .part { border-top: 1px solid var(--line); padding: 25px 0 40px; line-height: 1.9; }
.chapter .end { text-align: center; font-style: italic; margin: 60px 0; }
footer { max-width: 640px; margin: 60px auto 0; font-size: 12px; }
footer a { text-decoration: none; }
[hidden] { display: none !important; }
@media (max-width: 700px) {
  .page-view { padding: 58px 22px 26px; }
  .book-stage { --height: min(calc((100vw - 44px) / .695), calc(100dvh - 84px)); width: calc(var(--height) * .695); }
  .book-stage::after { display: none; }
  .sheet { width: 100%; border-radius: 3px 5px 5px 3px !important; }
  .sheet.right-page::after, .sheet.left-page::after { background: linear-gradient(90deg, #0000000b, transparent 5%, transparent 96%, #00000006); }
  .page-content { font-size: calc(var(--size) * .65); padding: 7% 8% 3%; line-height: 1.6; height: calc(100% - 32px); }
  .page-content h2 { margin: 12px 0; }
  .page-content header { margin-bottom: 20px; }
  .page-chapter, .page-subtitle { font-size: 10px; }
  .folio { bottom: 12px; font-size: 11px; }
  .page-content pre { font-size: 8px; }
  .edge { width: 34px; opacity: .35; }
  .edge.previous { left: -21px; justify-items: start; }
  .edge.next { right: -21px; justify-items: end; }
  .edge svg { width: 16px; height: 16px; }
  .scroll-view { padding: 60px 26px 30px; }
  .chapter { line-height: 1.75; }
}
@media (prefers-reduced-motion: reduce) { .edge { transition: none; } }
/* Print the continuous text, never the interactive page surfaces or clones. */
@media print {
  @page {
    size: auto;
    margin: 18mm 20mm 20mm;
    @bottom-center { content: counter(page); font: 9pt Georgia, serif; color: #555; }
  }
  :root, :root[data-theme=dark] {
    --paper: #fff;
    --ink: #000;
    --muted: #333;
    --line: #aaa;
    color-scheme: light;
    background: #fff;
  }
  html, body { margin: 0; padding: 0; background: #fff; color: #000; }
  .skip, .menu-toggle, .page-view, #contents, footer, .scroll-cover a { display: none !important; }
  .scroll-view, .scroll-view[hidden] { display: block !important; padding: 0; background: #fff; color: #000; }
  .scroll-cover { display: block; margin: 0; padding: 0; break-after: page; }
  .scroll-cover img { display: block; width: auto; height: auto; max-width: 100%; max-height: 210mm; margin: 0 auto; box-shadow: none; border: 0; }
  .book { width: auto; max-width: none; margin: 0; padding: 0; }
  .chapter { break-before: page; margin: 0; padding: 0; font: 11pt/1.5 Georgia, 'Times New Roman', serif; color: #000; overflow: visible; }
  .chapter header { margin: 0 0 8mm; break-inside: avoid; break-after: avoid; }
  .chapter h2 { margin: 3mm 0; font: 22pt/1.2 Georgia, serif; color: #000; break-after: avoid; }
  .chapter-number, .subtitle, .part { font: 9pt/1.5 Georgia, serif; color: #333; }
  .chapter .part { margin: 0 0 7mm; padding: 0 0 4mm; border-top: 0; border-bottom: 1px solid #aaa; break-inside: avoid; break-after: avoid; }
  .chapter > p { margin: 0 0 3.5mm; orphans: 3; widows: 3; }
  .chapter .end { margin: 10mm 0 0; color: #000; break-before: avoid; }
  a { color: #000; text-decoration: none; }
}
