/* Private reader PWA */
body { background: var(--paper); min-height: 100vh; min-height: 100dvh; }
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.noscript { padding: 24px; text-align: center; }

/* ---------- Generic centered screens (invitation, login, denied) ---------- */
.screen { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--band); }
.panel { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 28px 24px; }
.panel h1 { font-family: var(--serif); font-size: 1.6rem; }
.panel .lock { width: 48px; height: 48px; border-radius: 50%; background: var(--band); display: grid; place-items: center; margin-bottom: 14px; font-size: 1.4rem; }
.panel .cover-sm { width: 120px; margin: 0 auto 18px; filter: drop-shadow(0 10px 16px rgba(0, 0, 0, .25)); }
.panel .muted { color: var(--muted); }
.panel .stack { display: grid; gap: 12px; margin-top: 18px; }
.denied h1 { text-transform: uppercase; letter-spacing: .06em; font-size: 1.15rem; font-family: var(--sans); }
.otp-input { letter-spacing: .5em; font-size: 1.4rem; text-align: center; font-variant-numeric: tabular-nums; }
.notice { padding: 12px 14px; border-radius: 8px; background: #fff8e6; border: 1px solid #f3dfae; color: #6a4a00; font-size: .93rem; }

/* ---------- Download page: a single full-screen hero, never scrolls ---------- */
.prep-top { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--band) 0%, var(--band) 62%, var(--paper) 62%); }
.prep-bar { flex: none; width: 100%; max-width: 1120px; margin: 0 auto; padding: calc(14px + env(safe-area-inset-top)) 20px 8px; display: flex; justify-content: space-between; align-items: center; }
.prep-bar .who { font-weight: 700; color: var(--accent); }
.prep { flex: 1; min-height: 0; width: 100%; max-width: 1040px; margin: 0 auto; padding: 0 20px calc(16px + env(safe-area-inset-bottom));
  display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 14px; align-items: center; }
.prep-cover { min-height: 0; height: 100%; display: flex; align-items: center; justify-content: center; }
.prep-cover img { max-height: 100%; max-width: min(260px, 70vw); width: auto; height: auto; object-fit: contain; filter: drop-shadow(0 16px 24px rgba(0, 0, 0, .28)); }
.prep h1 { font-size: clamp(1.35rem, 5.2vw, 2.6rem); line-height: 1.15; margin: 0 0 10px; }
.prep .btn-primary { width: 100%; max-width: 320px; min-height: 54px; font-weight: 500; font-size: 1.05rem; letter-spacing: .04em; border-radius: 4px; }
.prep .start { display: inline-block; margin: 12px 0 8px; font-weight: 700; letter-spacing: .03em; }
.prep .author { color: var(--muted); margin: 0 0 6px; }
.prep .desc { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; }
.prep .desc { color: #666; font-weight: 300; line-height: 1.55; margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: #e7f4ec; color: var(--ok); }
.chip.wait { background: #fff4dc; color: var(--warn); }
@media (max-height: 640px) { .prep .desc, .prep .author { display: none; } }
@media (min-width: 760px) {
  .prep-top { background: linear-gradient(180deg, var(--band) 0%, var(--band) 48%, var(--paper) 48%); }
  .prep { grid-template-rows: none; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 56px; }
  .prep-cover { height: min(70vh, 560px); }
  .prep-cover img { max-width: 100%; }
  .prep .desc { -webkit-line-clamp: 4; line-clamp: 4; }
}
/* ---------- Library ---------- */
.lib { max-width: 1000px; margin: 0 auto; padding: 20px 16px 48px; }
.lib-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.lib-head h1 { font-family: var(--serif); font-size: 1.8rem; margin: 0; }
.shelf { display: grid; gap: 22px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.shelf a { text-decoration: none; color: var(--ink); }
.shelf img, .shelf .ph { width: 100%; aspect-ratio: 5 / 6; object-fit: contain; filter: drop-shadow(0 8px 12px rgba(0, 0, 0, .2)); }
.shelf .ph { background: var(--band); border-radius: 6px; }
.shelf .t { font-weight: 600; margin-top: 10px; }
.bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(10, 12, 16, .6); display: grid; place-items: center; padding: 16px; }
.modal .panel { max-height: 90vh; overflow: auto; text-align: center; }
.modal .panel img { width: 96px; margin: 0 auto 12px; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .3)); }
.steps { text-align: left; padding-left: 1.2em; margin: 6px 0 16px; color: var(--ink-2); }
.steps li { margin-bottom: 6px; }

/* ---------- Reader ---------- */
.reader { --rbg: #fbf6e9; --rfg: #1f1d1a; --rmuted: #8a8273; --rchrome: rgba(251, 246, 233, .96);
  position: fixed; inset: 0; background: var(--rbg); color: var(--rfg); display: flex; flex-direction: column; user-select: none; -webkit-user-select: none; }
.reader.theme-light { --rbg: #ffffff; --rfg: #16181d; --rmuted: #8b8f98; --rchrome: rgba(255, 255, 255, .96); }
.reader.theme-dark { --rbg: #15171b; --rfg: #d8d4cc; --rmuted: #8b8f98; --rchrome: rgba(21, 23, 27, .96); }
.rbar { display: flex; align-items: center; gap: 4px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; background: var(--rchrome); border-bottom: 1px solid rgba(127, 127, 127, .18); z-index: 5; }
.rbar .ttl { flex: 1; min-width: 0; text-align: center; font-size: .9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--rmuted); }
.ibtn { min-width: 44px; min-height: 44px; border: 0; background: none; color: var(--rfg); border-radius: 8px; cursor: pointer; font: inherit; font-size: 1.05rem; display: inline-grid; place-items: center; padding: 0 6px; }
.ibtn:hover { background: rgba(127, 127, 127, .12); }
.ibtn[aria-pressed="true"] { color: var(--gold); }
.stage { position: relative; flex: 1; overflow: hidden; touch-action: pan-y; }
.viewport { position: absolute; inset: 18px 22px 30px; overflow: hidden; }
.flow { height: 100%; column-fill: auto; font-family: var(--serif); font-size: var(--fs, 19px); line-height: 1.62; hyphens: auto; -webkit-hyphens: auto; text-align: justify; overflow-wrap: break-word; }
.flow h1, .flow h2, .flow h3 { text-align: left; break-after: avoid; font-family: var(--serif); }
.flow h1 { font-size: 1.5em; margin: .4em 0 .8em; }
.flow p { margin: 0 0 .8em; }
.flow img { max-width: 100%; max-height: 60vh; height: auto; margin: .6em auto; break-inside: avoid; }
.flow a { color: inherit; text-decoration: underline; text-decoration-color: var(--gold); cursor: pointer; }
.flow blockquote { margin: .8em 1em; font-style: italic; }
.flow table { border-collapse: collapse; font-size: .9em; }
.flow td, .flow th { border: 1px solid rgba(127, 127, 127, .3); padding: .2em .4em; }
.pdfpage { position: absolute; inset: 8px; display: grid; place-items: center; }
.pdfpage canvas { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; box-shadow: 0 2px 10px rgba(0, 0, 0, .12); background: #fff; }
.theme-dark .pdfpage canvas { filter: invert(.88) hue-rotate(180deg); }
.reader.shielded .stage .book, .reader.shielded .stage .watermark { visibility: hidden; }
.reader.shielded .stage::after { content: "Reading paused. Return to the book to continue."; position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; padding: 1.5rem; text-align: center; font: 600 1rem var(--sans); color: #8b8f98; background: #000; }
.pageno { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; font-size: .75rem; color: var(--rmuted); }
.watermark { position: absolute; inset: 0; z-index: 3; pointer-events: none; overflow: hidden; display: flex; flex-wrap: wrap; align-content: space-around; justify-content: space-around; opacity: .05; transform: rotate(-24deg) scale(1.4); font-size: .85rem; color: var(--rfg); }
.rfoot { padding: 6px 14px calc(8px + env(safe-area-inset-bottom)); background: var(--rchrome); border-top: 1px solid rgba(127, 127, 127, .18); font-size: .8rem; color: var(--rmuted); z-index: 5; }
.rfoot .row { display: flex; justify-content: space-between; gap: 10px; }
.rfoot .bar { margin: 0 0 6px; background: rgba(127, 127, 127, .2); }
.rfoot .bar > i { background: var(--gold); }

.drawer { position: fixed; z-index: 50; top: 0; bottom: 0; right: 0; width: min(380px, 100vw); background: var(--surface); color: var(--ink); box-shadow: -8px 0 32px rgba(0, 0, 0, .2); display: flex; flex-direction: column; }
.drawer header { display: flex; justify-content: space-between; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; border-bottom: 1px solid var(--line); }
.drawer header h2 { font-size: 1.05rem; margin: 0; }
.drawer .body { overflow: auto; padding: 8px 0; flex: 1; }
.drawer .item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 12px 16px; font: inherit; color: var(--ink); cursor: pointer; border-bottom: 1px solid #f1efea; }
.drawer .item:hover { background: var(--paper); }
.drawer .item small { display: block; color: var(--muted); }
.drawer .pad { padding: 14px 16px; }
.drawer-scrim { position: fixed; inset: 0; z-index: 49; background: rgba(0, 0, 0, .3); }
.seg { display: flex; gap: 8px; margin: 8px 0 18px; }
.seg .btn { flex: 1; }
.seg .btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.mark { background: #fff1b8; }

@media print { body * { display: none !important; } body::after { content: "Printing is not available for protected books."; display: block !important; } }

/* Flaticon UIcons */
.fi { display: inline-flex; align-items: center; justify-content: center; line-height: 1; vertical-align: -0.12em; }
.ibtn .fi { font-size: 1.15rem; }
.panel .lock .fi { font-size: 1.35rem; color: var(--accent); }
.btn .fi { font-size: 1.05em; }
.btn-add { min-height: 56px; font-size: 1.08rem; }
.steps .fi { margin: 0 2px; }
.chip .fi { font-size: .9em; }
.credit { margin-top: 16px; }
.credit a { color: inherit; }

/* ---------- iPhone: add the book to the home screen ---------- */
.ios-add { min-height: 100vh; min-height: 100dvh; background: var(--band); padding: 20px 16px 120px; display: grid; justify-items: center; align-content: start; }
.ios-card { width: 100%; max-width: 440px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 24px 22px; }
.ios-card .cover-sm { width: 96px; margin: 0 auto 14px; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .25)); }
.ios-card h1 { font-family: var(--serif); font-size: 1.5rem; text-align: center; }
.ios-card > .muted { text-align: center; color: var(--muted); }
.ios-steps { list-style: none; padding: 0; margin: 18px 0; display: grid; gap: 12px; }
.ios-steps li { display: grid; grid-template-columns: 30px 1fr; gap: 12px; align-items: center; font-size: 1.02rem; }
.ios-steps .n { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .9rem; }
.ios-steps .key { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 8px; background: #eef1f8; color: #1f6feb; font-weight: 600; white-space: nowrap; }
.ios-pointer { position: fixed; left: 50%; bottom: calc(10px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; justify-items: center; gap: 2px; color: #1f6feb; font-weight: 700; font-size: .9rem; animation: nudge 1.6s ease-in-out infinite; }
.ios-pointer .fi { font-size: 1.6rem; }
@keyframes nudge { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, 8px); } }

/* ---------- 3D book (StPageFlip, MIT). Library CSS copied here because the CSP blocks injected styles. */
.stf__parent { position: relative; display: block; box-sizing: border-box; transform: translateZ(0); touch-action: pan-y; }
.sft__wrapper, .stf__wrapper { position: relative; width: 100%; box-sizing: border-box; }
/* Fixed-size book: the wrapper fills the host so pages sit inside it, not above it. */
.flip-host > .stf__wrapper, .flip-host > .sft__wrapper { height: 100%; }
.stf__parent canvas { position: absolute; width: 100%; height: 100%; left: 0; top: 0; }
.stf__block { position: absolute; width: 100%; height: 100%; box-sizing: border-box; perspective: 2000px; }
.stf__item { display: none; position: absolute; transform-style: preserve-3d; }
.stf__outerShadow, .stf__innerShadow, .stf__hardShadow, .stf__hardInnerShadow { position: absolute; left: 0; top: 0; }

.reader .book { position: absolute; inset: 8px; display: grid; place-items: center; }
.reader .flip-host { position: relative; }
.reader .page { background: var(--rpage, #fffdf7); color: var(--rfg); overflow: hidden; box-shadow: 0 0 1px rgba(0, 0, 0, .15); }
.reader.theme-light { --rpage: #ffffff; }
.reader.theme-dark { --rpage: #1d2026; }
.reader .page-inner { position: absolute; inset: 0; display: grid; place-items: center; }
.reader .page-inner .viewport { position: relative; inset: auto; overflow: hidden; width: 100%; height: 100%; }
.reader .page-inner canvas { max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain; display: block; }
.reader.theme-dark .page-inner canvas { filter: invert(.88) hue-rotate(180deg); }
.reader .page-inner[data-loading]::after { content: ""; width: 26px; height: 26px; border: 3px solid rgba(127, 127, 127, .25); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
.reader .page .pageno { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; font-size: .72rem; color: var(--rmuted); pointer-events: none; }
/* Spine shading on an open spread, like a real book. */
.reader .page.--left::after, .reader .page.--right::after { content: ""; position: absolute; top: 0; bottom: 0; width: 9%; pointer-events: none; }
.reader .page.--left::after { right: 0; background: linear-gradient(to left, rgba(0, 0, 0, .16), rgba(0, 0, 0, 0)); }
.reader .page.--right::after { left: 0; background: linear-gradient(to right, rgba(0, 0, 0, .16), rgba(0, 0, 0, 0)); }
.reader.spread .stage { background: radial-gradient(ellipse at center, rgba(0, 0, 0, .04), rgba(0, 0, 0, .12)); }
.reader.spread .flip-host { filter: drop-shadow(0 10px 24px rgba(0, 0, 0, .18)); }
.measure { position: absolute; left: -10000px; top: 0; visibility: hidden; pointer-events: none; }
.measure .flow { position: absolute; }
.navbtn { position: absolute; bottom: 10px; z-index: 6; width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: var(--rmuted); font-size: 1.4rem; cursor: pointer; display: none; place-items: center; }
.navbtn:hover { color: var(--rfg); background: rgba(127, 127, 127, .12); }
.navbtn.prev { left: 10px; } .navbtn.next { right: 10px; }
.reader.spread .navbtn { display: grid; }
@media (pointer: fine) { .navbtn { display: grid; } }
