/* Books — the library shelf and the reader (builds on /assets/site.css) */
[hidden] { display: none !important; }

/* ---------- the shelf ---------- */
.shelf .book { transition: transform .2s ease, box-shadow .2s ease; }
.shelf .book:hover { transform: translateY(-4px); box-shadow: 0 0 0 4px rgba(255,210,63,.6), var(--shadow); }
.shelf .cover-btn { display: block; padding: 0; border: 0; background: none; cursor: pointer; width: 100%; }
.shelf .cover-btn img { display: block; }
.book-actions { display: flex; flex-direction: column; gap: 6px; margin-top: auto; align-items: flex-start; }
.book-actions .btn { padding: 10px 18px; font-size: 1rem; }
.book-actions .restart { background: none; border: 0; padding: 2px 0; font: 700 .85rem var(--font-body); color: var(--ink-soft); text-decoration: underline; cursor: pointer; }
.shelf-tip { text-align: center; color: var(--ink-soft); font-weight: 700; margin-top: 26px; }
@media (max-width: 480px) { .book-actions .btn { padding: 8px 12px; font-size: .9rem; } }

/* ---------- the reader ---------- */
.reader {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; color: #fff;
  background: radial-gradient(ellipse at 50% 42%, #463a6a 0%, #2a2244 55%, #1b1630 100%);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
body.reading { overflow: hidden; }
.r-top { flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 12px 4px; }
.r-btn { flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center;
  background: rgba(255,255,255,.14); color: #fff; transition: background .2s; }
.r-btn:hover { background: rgba(255,255,255,.26); }
.r-btn svg { width: 24px; height: 24px; }
.r-title { flex: 1; min-width: 0; text-align: center; line-height: 1.15; }
.r-title b { display: block; font: 800 1.2rem var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #ffe08a; }
.r-title span { font-weight: 700; font-size: .9rem; opacity: .85; }
.fs-off { display: none; }
.reader.is-fs .fs-on { display: none; }
.reader.is-fs .fs-off { display: block; }

.r-stage { position: relative; flex: 1; min-height: 0; margin: 4px 10px; touch-action: pinch-zoom; overflow: hidden; }
.r-book { position: absolute; inset: 0; }
.sheet { position: absolute; left: 50%; top: 50%; width: var(--w); height: var(--h); transform: translate(-50%, -50%);
  perspective: 2800px; border-radius: 6px; box-shadow: 0 18px 50px rgba(0,0,0,.55); background: #f4ead2; }
.face { position: absolute; top: 0; bottom: 0; background-repeat: no-repeat; background-color: #f4ead2; }
.sheet.square .face { left: 0; right: 0; border-radius: 6px; background-size: cover; }
.sheet.square .face.half-L { background-size: 200% 100%; background-position: 0 0; }
.sheet.square .face.half-R { background-size: 200% 100%; background-position: 100% 0; }
.sheet.spread .face { width: 50%; background-size: 200% 100%; }
.sheet.spread .face.L { left: 0; background-position: 0 0; border-radius: 6px 0 0 6px; }
.sheet.spread .face.R { right: 0; background-position: 100% 0; border-radius: 0 6px 6px 0; }
/* a soft fold down the middle of an open book */
.sheet.spread::after { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 7%; transform: translateX(-50%); z-index: 3; pointer-events: none;
  background: linear-gradient(90deg, rgba(0,0,0,0), rgba(0,0,0,.12) 40%, rgba(0,0,0,.22) 50%, rgba(0,0,0,.12) 60%, rgba(0,0,0,0)); }

/* turning a page: the leaf swings over the spine */
.leaf { position: absolute; top: 0; bottom: 0; width: 50%; z-index: 2; transform-style: preserve-3d; transition: transform .65s cubic-bezier(.45,.05,.3,1); }
.leaf.fwd { left: 50%; transform-origin: 0 50%; }
.leaf.bwd { left: 0; transform-origin: 100% 50%; }
.leaf.fwd.go { transform: rotateY(-180deg); }
.leaf.bwd.go { transform: rotateY(180deg); }
.leaf .lf { position: absolute; inset: 0; -webkit-backface-visibility: hidden; backface-visibility: hidden; background-size: 200% 100%; background-repeat: no-repeat; background-color: #f4ead2; }
.leaf .lf.b { transform: rotateY(180deg); }
.leaf .lf::after { content: ""; position: absolute; inset: 0; opacity: 0; transition: opacity .65s; pointer-events: none; }
.leaf.fwd .lf::after { background: linear-gradient(90deg, rgba(0,0,0,.28), rgba(0,0,0,0) 60%); }
.leaf.bwd .lf::after { background: linear-gradient(270deg, rgba(0,0,0,.28), rgba(0,0,0,0) 60%); }
.leaf.go .lf::after { opacity: 1; }

/* sliding (one page at a time, and to or from a cover) */
.sheet.in-next { animation: inNext .4s ease-out both; }
.sheet.in-prev { animation: inPrev .4s ease-out both; }
.sheet.out-next { animation: outNext .4s ease-in both; }
.sheet.out-prev { animation: outPrev .4s ease-in both; }
@keyframes inNext { from { opacity: 0; transform: translate(-38%, -50%); } }
@keyframes inPrev { from { opacity: 0; transform: translate(-62%, -50%); } }
@keyframes outNext { to { opacity: 0; transform: translate(-62%, -50%); } }
@keyframes outPrev { to { opacity: 0; transform: translate(-38%, -50%); } }

.r-nav { position: absolute; top: 50%; z-index: 5; width: 58px; height: 58px; margin-top: -29px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: rgba(255,250,240,.92); color: var(--red); box-shadow: 0 4px 16px rgba(0,0,0,.4); transition: transform .2s, opacity .2s; }
.r-nav svg { width: 30px; height: 30px; }
.r-nav:hover { transform: scale(1.08); }
.r-nav.prev { left: 6px; }
.r-nav.next { right: 6px; }
.r-nav[disabled] { opacity: 0; pointer-events: none; }
@media (max-width: 700px) { .r-nav { width: 46px; height: 46px; margin-top: -23px; opacity: .85; } .r-nav svg { width: 24px; height: 24px; } }

.r-loading { position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; font-weight: 800; font-size: 1.1rem; }
.r-bottom { flex: none; padding: 8px 28px 14px; }
.r-bottom input { width: 100%; accent-color: #ffd23f; height: 28px; cursor: pointer; }

/* the end */
.r-end { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px; background: rgba(20,14,30,.55); animation: fade .3s; }
@keyframes fade { from { opacity: 0; } }
.r-end-card { background: var(--card); color: var(--ink); border-radius: 28px; padding: 22px 22px 20px; text-align: center; width: min(560px, 100%);
  max-height: 100%; overflow: auto; box-shadow: 0 10px 0 rgba(59,42,30,.18), 0 30px 60px rgba(0,0,0,.3); animation: pop .5s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.r-end-card h2 { font-size: 2.4rem; color: var(--red); margin: 0; }
.r-end-card p { font-weight: 700; color: var(--ink-soft); margin: 2px 0 0; }
.r-end-books { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0 18px; }
.r-end-books button { border: 0; padding: 0; background: none; cursor: pointer; font: 800 .82rem/1.15 var(--font-body); color: var(--ink); transition: transform .2s; }
.r-end-books button:hover { transform: translateY(-3px); }
.r-end-books img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,.2); display: block; margin-bottom: 6px; }
.r-end-links { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* a phone held upright: one page, with big arrows underneath it */
.reader.tall .sheet { top: calc(50% - 42px); }
.reader.tall .r-nav { top: auto; bottom: 6px; margin-top: 0; width: 66px; height: 66px; opacity: 1; }
.reader.tall .r-nav svg { width: 32px; height: 32px; }
.reader.tall .r-nav.prev { left: 14%; }
.reader.tall .r-nav.next { right: 14%; }
.reader.tall .r-nav[disabled] { opacity: .3; }

/* ---------- a bigger view: the book fills the screen, the bars float over it and fade away ---------- */
.reader { display: block; }
.r-stage { position: absolute; margin: 0; top: env(safe-area-inset-top); bottom: env(safe-area-inset-bottom); left: env(safe-area-inset-left); right: env(safe-area-inset-right); }
.r-top { position: absolute; z-index: 8; top: 0; left: 0; right: 0; padding: calc(env(safe-area-inset-top) + 6px) calc(env(safe-area-inset-right) + 10px) 18px calc(env(safe-area-inset-left) + 10px);
  background: linear-gradient(rgba(22,16,38,.8), rgba(22,16,38,0)); transition: opacity .45s; }
.r-bottom { position: absolute; z-index: 8; bottom: 0; left: 0; right: 0; padding: 18px calc(env(safe-area-inset-right) + 28px) calc(env(safe-area-inset-bottom) + 8px) calc(env(safe-area-inset-left) + 28px);
  background: linear-gradient(rgba(22,16,38,0), rgba(22,16,38,.8)); transition: opacity .45s; }
.r-btn { width: 42px; height: 42px; }
.r-nav { width: 50px; height: 50px; margin-top: -25px; opacity: .8; transition: opacity .45s, transform .2s; }
.r-nav:hover { opacity: 1; }
.r-nav svg { width: 26px; height: 26px; }
.reader.calm .r-top, .reader.calm .r-bottom, .reader.calm:not(.tall) .r-nav { opacity: 0; pointer-events: none; }
.reader.calm { cursor: none; }
.reader.tall .sheet { top: calc(50% - 38px); }
.reader.tall .r-nav { bottom: 58px; width: 64px; height: 64px; opacity: 1; }
.reader.tall .r-nav[disabled] { opacity: .3; }

/* opening and closing the book: the sheet itself is see-through, each page has its own shadow, and it slides to the middle */
.sheet.opening { background: none; box-shadow: none; transition: transform .65s cubic-bezier(.45,.05,.3,1); }
.sheet.opening::after { display: none; }
.sheet.opening .face, .sheet.opening .leaf .lf { box-shadow: 0 18px 50px rgba(0,0,0,.5); }
.sheet.opening .face.R, .sheet.opening .leaf.fwd .lf:not(.b) { border-radius: 0 6px 6px 0; }
.sheet.opening .face.L, .sheet.opening .leaf.bwd .lf:not(.b) { border-radius: 6px 0 0 6px; }

/* one page at a time: the page turns over from its left edge */
.leaf1 { position: absolute; inset: 0; z-index: 2; transform-origin: 0 50%; transition: transform .6s cubic-bezier(.45,.05,.3,1); }
.leaf1.in { transform: rotateY(-100deg); }
.leaf1.out.go { transform: rotateY(-100deg); }
.leaf1.in.go { transform: rotateY(0deg); }
.leaf1 .lf { position: absolute; inset: 0; border-radius: 6px; -webkit-backface-visibility: hidden; backface-visibility: hidden; background-repeat: no-repeat; background-color: #f4ead2; }
.leaf1 .lf::after { content: ""; position: absolute; inset: 0; border-radius: 6px; background: linear-gradient(90deg, rgba(0,0,0,.25), rgba(0,0,0,0) 70%); opacity: 0; transition: opacity .6s; }
.leaf1.out.go .lf::after { opacity: 1; }
.leaf1.in .lf::after { opacity: 1; }
.leaf1.in.go .lf::after { opacity: 0; }

/* "The End": the book number above each title, and links back to the shelf and the home page */
.r-end-books .bk-num { display: block; color: var(--red); font: 800 .72rem var(--font-body); letter-spacing: .06em; text-transform: uppercase; margin-bottom: 1px; }
.r-end-home { margin: 14px 0 0 !important; font-weight: 800; }
.r-end-home a { color: var(--ink-soft); text-decoration: underline; }
.r-end-home a:hover { color: var(--red); }

/* the full-screen button says what it does; on iPhones it shows how to hide Safari's bars instead */
.r-btn.r-fs { width: auto; padding: 0 14px 0 11px; border-radius: 999px; gap: 7px; display: inline-flex; font: 800 .9rem var(--font-body); color: #fff; }
.r-btn.r-fs svg { width: 22px; height: 22px; }
@media (max-width: 420px) { .r-btn.r-fs { width: 42px; padding: 0; justify-content: center; } .r-btn.r-fs span { display: none; } }
.r-tip { position: absolute; inset: 0; z-index: 12; display: grid; place-items: start center; padding: calc(env(safe-area-inset-top) + 60px) 16px 16px; background: rgba(20,14,30,.45); animation: fade .25s; }
.r-tip-card { background: var(--card); color: var(--ink); border-radius: 22px; padding: 18px 20px; width: min(420px, 100%); text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.r-tip-card b { font: 800 1.2rem var(--font-display); color: var(--red); }
.r-tip-card p { margin: 6px 0 14px; font-weight: 700; color: var(--ink-soft); line-height: 1.45; }
.r-tip-card p b { font: inherit; color: var(--ink); background: #fff3d6; border-radius: 6px; padding: 0 5px; }

/* phones and tablets: the page behind never scrolls, the arrows stay when the bars fade, and a one-time hint */
html.reading, html.reading body { overflow: hidden; overscroll-behavior: none; height: 100%; }
.reader.touch.calm:not(.tall) .r-nav { opacity: .7; pointer-events: auto; }
.r-hint { position: absolute; z-index: 7; left: 50%; bottom: 14px; transform: translateX(-50%); margin: 0; white-space: nowrap; pointer-events: none;
  background: rgba(255,250,240,.95); color: var(--ink); font: 800 .9rem var(--font-body); padding: 8px 16px; border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0,0,0,.3); animation: fade .3s; }

/* held upright: a spread stays whole, each page as wide as the screen, and slides sideways */
.reader.tall .r-book { display: flex; align-items: center; padding-bottom: 84px; overflow-x: auto; overflow-y: hidden;
  overscroll-behavior: contain; touch-action: pan-x pinch-zoom; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.reader.tall .r-book::-webkit-scrollbar { display: none; }
.reader.tall .sheet.pan { position: relative; left: auto; top: auto; transform: none; flex: 0 0 auto; margin: 0 auto; }
.sheet.fade-in { animation: fadeIn .3s ease-out both; }
@keyframes fadeIn { from { opacity: 0; } }