/* The open-book reader for shelf and desk books. Lives inside the shared #story
   dialog so closing, Escape, backdrop clicks, focus return and the paused 3D
   scene all follow the existing modal. The closed volume flies in from the
   clicked shelf or desk book (--fly-* are set by book-reader.js), then opens. */
/* Caveat (SIL OFL 1.1, licence beside the file), latin subset, bundled locally.
   Fetched only when a book's handwritten note is first rendered. */
@font-face{font-family:"Caveat";font-style:normal;font-weight:400 700;font-display:swap;src:url("./assets/fonts/caveat-latin.woff2") format("woff2");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}
#story[data-kind="book"]{width:100vw;max-width:100vw;height:100dvh;max-height:100dvh;inset:0;margin:0;padding:0;display:grid;place-items:center;background:transparent;box-shadow:none;border-radius:0;overflow:hidden}
#story[data-kind="book"]::backdrop{background:transparent;backdrop-filter:none;-webkit-backdrop-filter:none}
#story[data-kind="book"] #close-story{position:fixed;top:max(16px,env(safe-area-inset-top));right:max(16px,env(safe-area-inset-right));float:none;margin:0;width:44px;height:44px;font-size:24px;background:#f3f0e6;color:#3a3832;box-shadow:0 6px 22px #0005;z-index:6}
#story[data-kind="book"] #story-content{display:contents}
.book-stage{--paper:#f7f2e7;--paper-deep:#ebe4d3;--ink:#2b2823;--hand-ink:#27304a;--ink-soft:#6c665a;--rule:#d9d1be;position:relative;width:100%;height:100%;display:grid;place-items:center;perspective:1900px;perspective-origin:50% 48%;overflow:hidden;cursor:zoom-out;-webkit-tap-highlight-color:transparent}
/* The scrim dims and blurs the studio as the book leaves the shelf, and clears as it returns. */
.book-stage::before{content:"";position:absolute;inset:0;background:#14171599;-webkit-backdrop-filter:blur(9px);backdrop-filter:blur(9px);opacity:0;transition:opacity .45s ease;pointer-events:none}
.book-stage[data-state="flying"]::before,.book-stage[data-state="opening"]::before,.book-stage[data-state="open"]::before,.book-stage[data-state="closing"]::before{opacity:1}
/* Each volume takes its own cover proportion (--cover-aspect is width / height from the cover image). */
.book{--board:#3a3a3a;--cover-aspect:2 / 3;--page-h:min(calc(clamp(250px,30vw,372px) / (var(--cover-aspect))),calc(100dvh - 124px));--page-w:calc(var(--page-h) * (var(--cover-aspect)));position:relative;width:calc(var(--page-w) * 2);height:var(--page-h);margin:0;cursor:auto;transform-style:preserve-3d;--shift:calc(var(--page-w) * -.5);transform-origin:75% 50%;transform:translate(calc(var(--shift) + var(--fly-x,0px)),var(--fly-y,24px)) scale(var(--fly-s,.88));opacity:var(--fly-o,0);transition:transform .62s cubic-bezier(.33,.72,.2,1),opacity .28s ease}
/* closed and returning: the closed cover sits on its shelf source (transform-origin is the cover's centre).
   flying and closing: the closed cover is centred in the foreground. opening and open: the spread is centred. */
.book-stage[data-state="closed"] .book{transition:none}
.book-stage[data-state="flying"] .book,.book-stage[data-state="closing"] .book{transform:translate(var(--shift),0px) scale(1);opacity:1}
.book-stage[data-state="open"] .book,.book-stage[data-state="opening"] .book{transform:translate(0px,0px) scale(1);opacity:1}
.book-stage[data-state="opening"] .book,.book-stage[data-state="open"] .book{transition:transform .95s cubic-bezier(.45,.05,.2,1),opacity .28s ease}
/* Closing runs a little quicker than opening: the cover shuts in .7s, then the book flies home. */
.book-stage[data-state="closing"] .book{transition:transform .7s cubic-bezier(.45,.05,.2,1),opacity .28s ease}
.book-stage[data-state="closing"] .book-cover{transition:transform .7s cubic-bezier(.45,.05,.2,1),opacity .2s}
.book-stage[data-state="closing"] .book-page-scroll{transition:opacity .25s .2s}
.book-volume{position:absolute;inset:0;transform-style:preserve-3d}
/* The first page, with the page block's thickness stepping out behind it and the back board beyond that. */
.book-page{position:absolute;left:50%;top:0;width:50%;height:100%;background:var(--paper);border-radius:0 3px 3px 0;box-shadow:1px 1px 0 #efe9db,2px 2px 0 #ddd5c3,3px 3px 0 #efe9db,4px 4px 0 #ddd5c3,5px 5px 0 #efe9db,6px 6px 0 #d2cab6,0 26px 54px -18px #0009}
.book-page::before{content:"";position:absolute;inset:-4px -4px -4px 0;background:var(--board);border-radius:0 5px 5px 0;transform:translate(7px,7px);z-index:-1;filter:brightness(.9)}
.book-page::after{content:"";position:absolute;inset:0;pointer-events:none;border-radius:inherit;background:linear-gradient(90deg,#00000026,#0000000a 7%,#0000 14%)}
.book-page-scroll{position:absolute;inset:0;overflow:auto;overscroll-behavior:contain;scrollbar-width:none;padding:calc(var(--page-h) * .085) calc(var(--page-w) * .11) calc(var(--page-h) * .11) calc(var(--page-w) * .13);color:var(--ink);font-family:Georgia,"Times New Roman",serif;opacity:0;transition:opacity .35s .45s}
.book-page-scroll::-webkit-scrollbar{display:none}
.book-page-scroll:focus-visible{outline:2px solid #8a9a7a;outline-offset:-6px}
.book-stage[data-state="open"] .book-page-scroll,.book-stage[data-state="opening"] .book-page-scroll{opacity:1}
.book-page-head{display:none}
/* Jon's note is handwritten: Caveat runs small, so it is set larger than the serif it replaces. */
.book-text,.book-signature{font-family:"Caveat","Bradley Hand","Segoe Print","Noteworthy",cursive;font-weight:500;font-size:calc(clamp(21px,calc(var(--page-w) * .07),27px) * var(--fit,1));line-height:1.34;color:var(--hand-ink);font-kerning:normal;-webkit-font-smoothing:antialiased}
.book-text{text-wrap:pretty;overflow-wrap:break-word}
.book-text p{margin:0 0 .7em}
.book-signature{margin:.5em .1em 0 0;text-align:right;font-weight:600;font-size:calc(clamp(23px,calc(var(--page-w) * .077),30px) * var(--fit,1));line-height:1.2;white-space:nowrap;transform:rotate(-2deg);transform-origin:100% 50%}
.book-page-foot{position:absolute;left:0;right:0;bottom:0;display:flex;justify-content:center;align-items:center;gap:12px;padding:6px 0 10px;font:11px/1 Arial,Helvetica,sans-serif;letter-spacing:.08em;color:var(--ink-soft);background:linear-gradient(#f7f2e700,var(--paper) 45%);border-radius:0 0 3px 0}
.book-turn{width:34px;height:34px;border:1px solid var(--rule);border-radius:50%;color:var(--ink);font:20px/1 Georgia,serif;display:grid;place-items:center;background:var(--paper)}
.book-turn:disabled{opacity:.3;cursor:default}
/* The cover turns about the spine. Its inside face is the endpaper that carries the title. */
.book-cover{position:absolute;left:50%;top:-4px;width:calc(50% + 4px);height:calc(100% + 8px);transform-origin:left center;transform-style:preserve-3d;transform:translateZ(1px) rotateY(0);transition:transform .95s cubic-bezier(.45,.05,.2,1),opacity .2s;z-index:2}
.book-stage[data-state="open"] .book-cover,.book-stage[data-state="opening"] .book-cover{transform:translateZ(1px) rotateY(-180deg)}
.book-cover-front,.book-cover-inside{position:absolute;inset:0;backface-visibility:hidden;-webkit-backface-visibility:hidden;border-radius:0 5px 5px 0;overflow:hidden}
.book-cover-front{background:var(--board);box-shadow:0 30px 60px -22px #000c,inset 0 1px 0 #ffffff33}
.book-cover-front img{display:block;width:100%;height:100%;object-fit:contain;background:var(--board)}
.book-cover-front::before{content:"";position:absolute;left:0;top:0;bottom:0;width:16px;z-index:1;background:linear-gradient(90deg,#00000066,#0000002e 35%,#ffffff2b 62%,#00000012 80%,#0000)}
.book-cover-front::after{content:"";position:absolute;inset:0;z-index:1;pointer-events:none;background:linear-gradient(115deg,#ffffff1c,#0000 30%,#0000 70%,#00000026)}
.book-cover-inside{transform:rotateY(180deg);background:var(--board);padding:4px 0 4px 4px;border-radius:5px 0 0 5px}
.book-leaf-inner{position:relative;height:100%;background:var(--paper);border-radius:3px 0 0 3px;padding:calc(var(--page-h) * .11) calc(var(--page-w) * .12) calc(var(--page-h) * .1) calc(var(--page-w) * .11);color:var(--ink);font-family:Georgia,"Times New Roman",serif;display:flex;flex-direction:column}
.book-leaf-inner::after{content:"";position:absolute;inset:0;pointer-events:none;background:linear-gradient(270deg,#0000002b,#0000000c 8%,#0000 16%)}
.book-title{font-size:clamp(19px,calc(var(--page-w) * .072),27px);line-height:1.2;font-weight:400;letter-spacing:-.01em;margin:0 0 10px;text-wrap:balance}
.book-author{font:italic clamp(13px,calc(var(--page-w) * .04),15px)/1.5 Georgia,serif;color:var(--ink-soft);margin:0}
.book-colophon{margin-top:auto;font:10px/1.6 Arial,Helvetica,sans-serif;letter-spacing:.14em;text-transform:uppercase;color:#9a9282}
.book-page-head{margin-bottom:calc(var(--page-h) * .04);padding-bottom:calc(var(--page-h) * .03);border-bottom:1px solid var(--rule)}
/* Narrow screens read a single page: the cover turns away off the left edge, nothing scrolls sideways. */
@media(max-width:700px),(pointer:coarse) and (max-width:1024px) and (orientation:portrait){
  .book-stage{perspective:1400px}
  .book{--page-h:min(calc((100vw - 44px) / (var(--cover-aspect))),calc(100dvh - 116px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));--shift:0px;transform-origin:50% 50%;width:var(--page-w)}
  .book-page{left:0;width:100%;border-radius:3px}
  .book-page::before{inset:-4px}
  .book-page-head{display:block}
  .book-cover{left:0;width:calc(100% + 4px)}
  .book-stage[data-state="open"] .book-cover{opacity:0;pointer-events:none;transition:transform .95s cubic-bezier(.45,.05,.2,1),opacity .25s .75s}
  .book-turn{width:44px;height:44px}
  .book-page-scroll{padding:calc(var(--page-h) * .07) calc(var(--page-w) * .09) calc(var(--page-h) * .12)}
}
@media(max-height:560px) and (orientation:landscape){
  .book{--page-h:calc(100dvh - 72px)}
  #story[data-kind="book"] #close-story{top:max(8px,env(safe-area-inset-top));right:max(8px,env(safe-area-inset-right))}
}
@media(prefers-reduced-motion:reduce){
  .book,.book-cover,.book-page-scroll,.book-stage::before{transition:none!important}
}
