/* =====================================================================
   BOOK — PAGED READER (shared by every book: /css/book.css)
   Reading modes: Swipe (usual), Scroll (body.m-scroll) and Flip (body.m-flip), chosen in the ☰ sheet
   The text is below, one section element per page of the printed book.
   Each section (data-page="12" data-ch="Chapter 1. ILAH") is one page;
   data-ch is the chapter shown in the header while that page is open.
   A paragraph that runs over to the next page continues as <p class="cont">.
   Headings with an id (h1, h2 …) are listed in Contents.
   ===================================================================== */

:root {
  --fs: 18px;                     /* text size (A- / A+ changes it) */
  --bg: #f4efe3; --card: #fffdf8; --ink: #24302b; --muted: #6b766f; --line: #e3dccb;
  --green: #0b4a3b; --green-2: #083a2e; --gold: #c9a24a; --gold-soft: #e9d7a8;
  --accent: #0f5c4a; --hit: #fff1b8; --band: #f3ecda;
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --top: 52px; --bottom: 58px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0f1613; --card: #161f1b; --ink: #e2e8e4; --muted: #94a19a; --line: #26322d;
  --accent: #6cc2a3; --hit: #4a4220; --band: #1c2823; } }
:root[data-theme="dark"] {
  --bg: #0f1613; --card: #161f1b; --ink: #e2e8e4; --muted: #94a19a; --line: #26322d;
  --accent: #6cc2a3; --hit: #4a4220; --band: #1c2823; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
/* The reader is pinned to the screen so the header can never slide out of view. */
body { position: fixed; top: 0; right: 0; bottom: 0; left: 0;
  background: var(--bg); color: var(--ink); font-family: var(--sans);
  display: flex; flex-direction: column; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Header ---------- */
#top { flex: none; position: relative; z-index: 3; height: calc(var(--top) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0;
  display: flex; align-items: center; gap: 8px; color: #fff;
  background: linear-gradient(180deg, var(--green), var(--green-2)); border-bottom: 2px solid var(--gold); }
#top .back { flex: none; height: 38px; padding: 0 10px 0 6px; display: flex; align-items: center; gap: 2px;
  border: 1px solid rgba(255,255,255,.22); border-radius: 10px; background: rgba(255,255,255,.08);
  color: #fff; text-decoration: none; font-size: 14px; }
#top .back svg { width: 20px; height: 20px; }
#top .back:hover { background: rgba(255,255,255,.18); }
@media (max-width: 420px) { #top .back span { display: none; } #top .back { padding: 0 8px; } }
#top .title { flex: 1; min-width: 0; text-align: center; line-height: 1.2; }
#top .title b { display: block; font: 600 16px var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#top .title span { display: block; font-size: 12px; color: var(--gold-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn { flex: none; width: 38px; height: 38px; border: 1px solid rgba(255,255,255,.22); border-radius: 10px;
  background: rgba(255,255,255,.08); color: #fff; display: grid; place-items: center; padding: 0; }
.iconbtn svg { width: 20px; height: 20px; }

/* ---------- Pages: three side by side, the middle one is shown ----------
   left pane = previous page, middle = current, right pane = next page */
#view { flex: 1; min-height: 0; position: relative; z-index: 1; overflow: hidden; isolation: isolate; contain: paint; }
#track { display: flex; height: 100%; transform: translateX(-100%); }
#track.moving { will-change: transform; }
#track.anim { transition: transform .28s ease; }
.pane { flex: 0 0 100%; height: 100%; overflow-y: auto; overflow-x: hidden; position: relative;
  touch-action: pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
#store { display: none; }
body.grabbing, body.grabbing * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }
@media (hover: hover) { #view { cursor: grab; } section { cursor: auto; } }
.pane { user-select: none; -webkit-user-select: none; } section { user-select: text; -webkit-user-select: text; }

/* ---------- The book page ---------- */
section { display: block; max-width: 720px; margin: 0 auto; padding: 16px 20px 26px;
  font-family: var(--serif); font-size: var(--fs); line-height: 1.65; text-align: left; overflow-wrap: break-word; }
section::after { content: "Page " attr(data-page) " of " var(--pages); display: block; margin-top: 24px; text-align: center;
  font: 12px var(--sans); color: var(--muted); letter-spacing: .04em; }
section p { margin: 0 0 .85em; }
section h2 { margin: 18px 0 6px; text-align: center; font-size: 1.5em; line-height: 1.3; color: var(--accent); }
section h3 { margin: 6px 0 14px; text-align: center; font-size: 1.12em; line-height: 1.35; }
section h3[id] { margin: 10px -6px 16px; padding: 10px 14px; background: var(--band); border: 1px solid var(--line);
  border-top: 3px solid var(--gold); border-radius: 12px; color: var(--accent); letter-spacing: .02em; }
section h4 { margin: 20px 0 8px; font-size: 1.04em; line-height: 1.35; color: var(--accent); }
section > :first-child { margin-top: 2px; }
section .hit { background: var(--hit); border-radius: 6px; box-shadow: 0 0 0 4px var(--hit); }
section a { color: var(--accent); }

/* Big side arrows on computers */
.side { display: none; position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 46px; height: 74px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  color: var(--accent); font-size: 30px; box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.side:disabled { opacity: .3; cursor: default; }
#sprev { left: 16px; } #snext { right: 28px; }
@media (hover: hover) and (min-width: 980px) { .side { display: block; } }

/* ---------- Bottom bar ---------- */
#bot { flex: none; position: relative; z-index: 3; height: calc(var(--bottom) + env(safe-area-inset-bottom));
  padding: 0 10px env(safe-area-inset-bottom); display: flex; align-items: center; gap: 10px;
  background: linear-gradient(180deg, var(--green), var(--green-2)); border-top: 2px solid var(--gold); color: #fff; }
#bar { position: absolute; left: 0; top: -2px; height: 2px; background: #fff; width: 0; transition: width .25s; }
#bot .nav { flex: 0 0 auto; height: 40px; min-width: 44px; padding: 0 12px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); font-size: 14px; }
#bot .nav:disabled { opacity: .3; cursor: default; }
#where { flex: 1; height: 40px; border: 0; border-radius: 10px; background: rgba(255,255,255,.12);
  font-size: 15px; display: flex; align-items: center; justify-content: center; gap: 6px; }
#where small { color: var(--gold-soft); font-size: 12px; }

/* ---------- Go-to sheet ---------- */
#sheet { position: fixed; inset: 0; z-index: 20; display: none; background: rgba(0,0,0,.4); }
#sheet.open { display: flex; align-items: flex-end; justify-content: center; }
#sheet .box { width: 100%; max-width: 560px; max-height: 86vh; max-height: 86dvh; display: flex; flex-direction: column;
  background: var(--card); color: var(--ink); border-radius: 18px 18px 0 0; overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -6px 30px rgba(0,0,0,.25); }
@media (min-width: 700px) { #sheet.open { align-items: center; } #sheet .box { border-radius: 16px; max-height: 80vh; } }
.sh-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 4px; }
.sh-head h2 { flex: 1; margin: 0; font: 600 17px var(--serif); }
.sh-head .iconbtn { color: var(--ink); border-color: var(--line); background: transparent; }
.progress { margin: 4px 14px 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--band); font-size: 13px; }
.progress .row { display: flex; justify-content: space-between; gap: 8px; }
.progress b { color: var(--accent); }
.progress .meter { height: 6px; margin-top: 8px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress .meter i { display: block; height: 100%; width: 0; background: var(--gold); border-radius: 3px; }
.progress button { border: 0; background: none; padding: 0; color: var(--muted); font-size: 12px; text-decoration: underline; }
.tools { display: flex; gap: 8px; padding: 0 14px 10px; align-items: center; }
.tools button { height: 36px; min-width: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--band); }
.tools .grow { flex: 1; }
.jump { display: flex; gap: 10px; align-items: center; padding: 0 14px 10px; }
.jump input[type=range] { flex: 1; accent-color: var(--green); }
.jump input[type=number] { width: 72px; height: 36px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--card); color: var(--ink); text-align: center; font-size: 15px; }
.sh-label { margin: 0; padding: 8px 14px 6px; border-top: 1px solid var(--line); font: 600 12px var(--sans);
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.list { flex: 1; overflow-y: auto; padding: 0 8px 12px; overscroll-behavior: contain; }
#toc { list-style: none; margin: 0; padding: 0; }
#toc a { display: flex; align-items: baseline; gap: 10px; padding: 7px 8px 7px 22px; border-radius: 10px; color: inherit; text-decoration: none; font-size: 14px; }
#toc a.ch { padding-left: 8px; margin-top: 4px; font: 600 16px var(--serif); color: var(--accent); }
#toc a:hover, #toc a.cur { background: var(--band); }
#toc span { flex: 1; min-width: 0; }
#toc em { flex: none; font-style: normal; font-size: 12px; color: var(--muted); }
#toc a.done em::before { content: "✓ "; color: var(--gold); }
.credit { margin: 0; padding: 8px 14px 12px; font-size: 12px; color: var(--muted); text-align: center; border-top: 1px solid var(--line); }

@media (max-width: 600px) {
  :root { --fs: 17px; }
  section { padding: 12px 16px 22px; line-height: 1.6; }
}
@media (min-width: 700px) { section { text-align: justify; -webkit-hyphens: auto; hyphens: auto; } }
/* Computers: the page as a card, controls centred */
@media (min-width: 800px) {
  section { background: var(--card); border: 1px solid var(--line); border-radius: 14px;
    margin: 22px auto 26px; padding: 30px 48px 22px; box-shadow: 0 2px 14px rgba(0,0,0,.05); }
  #bot { justify-content: center; }
  #where { flex: 0 1 340px; }
}
@media (prefers-reduced-motion: reduce) { #track.anim { transition: none; } }

/* ---------- Reading mode buttons (in the ☰ sheet) ---------- */
.modes { display: flex; gap: 6px; align-items: center; padding: 0 14px 10px; font-size: 13px; color: var(--muted); }
.modes span { margin-right: 2px; }
.modes button { flex: 1; height: 34px; border: 1px solid var(--line); border-radius: 9px; background: var(--band); font-size: 14px; }
.modes button.on { background: var(--green); border-color: var(--green); color: #fff; }

/* ---------- Flip (page curl): the three pages lie on top of each other ----------
   The fold line moves across the page; #curl is the turned-over part (the back of the paper). */
body.m-flip #track { display: block; position: relative; transform: none !important; overflow: hidden; }
body.m-flip .pane { position: absolute; inset: 0; background: var(--bg); }
body.m-flip .pane:nth-child(1) { z-index: 3; clip-path: inset(0 100% 0 0); }   /* previous: hidden until turned back */
body.m-flip .pane:nth-child(2) { z-index: 2; }                                /* current */
body.m-flip .pane:nth-child(3) { z-index: 1; }                                /* next, underneath */
#curl { display: none; }
body.m-flip #curl { display: block; position: absolute; top: 0; bottom: 0; left: 100%; width: 0; z-index: 4; opacity: 0;
  pointer-events: none; border-radius: 0 6px 6px 0;
  background: linear-gradient(90deg, var(--curl-a) 0%, var(--curl-b) 55%, var(--curl-c) 88%, var(--curl-d) 100%);
  box-shadow: -3px 0 10px rgba(0,0,0,.08), 6px 0 18px rgba(0,0,0,.10); }
:root { --curl-a: #efe9da; --curl-b: #fdfbf5; --curl-c: #f5f0e4; --curl-d: #e6decb; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --curl-a: #1b2521; --curl-b: #2a3631; --curl-c: #222d29; --curl-d: #131b18; } }
:root[data-theme="dark"] { --curl-a: #1b2521; --curl-b: #2a3631; --curl-c: #222d29; --curl-d: #131b18; }
/* Light, thin scroll bars on the pages (all modes) */
.pane, #scroller { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.pane::-webkit-scrollbar, #scroller::-webkit-scrollbar { width: 8px; }
.pane::-webkit-scrollbar-track, #scroller::-webkit-scrollbar-track { background: transparent; }
.pane::-webkit-scrollbar-thumb, #scroller::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
.pane::-webkit-scrollbar-thumb:hover, #scroller::-webkit-scrollbar-thumb:hover { background-color: var(--gold-soft); }
body.m-flip #track.anim .pane { transition: clip-path .5s cubic-bezier(.35,.6,.25,1); }
body.m-flip #track.anim #curl { transition: left .5s cubic-bezier(.35,.6,.25,1), width .5s cubic-bezier(.35,.6,.25,1), opacity .5s step-end; }

/* ---------- Scroll: every page one under the other ---------- */
body.m-scroll #track { display: none; }
body.m-scroll .side { display: none !important; }
body.m-scroll #view { cursor: auto; }
#scroller { display: none; }
body.m-scroll #scroller { display: block; height: 100%; overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
body.m-scroll section + section { border-top: 1px dashed var(--line); }
@media (min-width: 800px) { body.m-scroll section + section { border-top: 1px solid var(--line); margin-top: 0; } }

/* ---------- Print: the whole book ---------- */
@media print {
  html, body { height: auto !important; overflow: visible; display: block; position: static; background: #fff; }
  #top, #bot, #view, #sheet { display: none !important; }
  #store { display: block; }
  section { page-break-after: always; color: #000; font-size: 12pt; background: none; border: 0; box-shadow: none; max-width: none; }
}
