/* « قلّب الكتاب بيدك » — a demo book standing and turning, that opens into a real
   two-page book with page curl (assets/flip-book.js). Only loaded by story.html. */
/* ---------- 3. flip book (two pages, real page turn) ---------- */
.fx{--rose:#E0287A;--rose-dk:#B81B61;background:var(--bg,#F8FAFC);padding-bottom:40px;
  /* the page-curl library draws the turning page and its shadows outside the book: without
     this the whole page became ~3x wider during each turn and slid sideways (07/10/2026) */
  overflow-x:hidden;overflow-x:clip}
.desk{max-width:860px;margin:6px auto 0;padding:24px 4px 40px;position:relative;
  background:radial-gradient(60% 55% at 50% 45%,#FFFFFF 0%,rgba(255,255,255,0) 75%)}

/* standing book (rotatable), opens into the flip book */
.stand-view{display:flex;flex-direction:column;align-items:center;transition:opacity .35s}
.stage3d{height:420px;width:100%;perspective:1400px;display:flex;align-items:center;justify-content:center;touch-action:pan-y;cursor:grab}
.stage3d:active{cursor:grabbing}
.b3d{--w:230px;--h:307px;--d:22px;width:var(--w);height:var(--h);position:relative;transform-style:preserve-3d;
  transform:rotateX(var(--rx,4deg)) rotateY(var(--ry,-25deg));transition:transform .8s cubic-bezier(.2,.8,.2,1)}
.b3d.idle{animation:float3 7s ease-in-out infinite}
@keyframes float3{0%,100%{transform:rotateX(4deg) rotateY(-25deg) translateY(0)}50%{transform:rotateX(4deg) rotateY(-14deg) translateY(-10px)}}
.f3{position:absolute;inset:0;backface-visibility:hidden}
.f3 img{width:100%;height:100%;object-fit:cover;display:block;pointer-events:none}
.front3{transform:translateZ(calc(var(--d)/2));border-radius:2px 6px 6px 2px;overflow:hidden;transform-origin:right center;
  transition:transform 1s cubic-bezier(.3,.7,.2,1);box-shadow:inset -8px 0 12px rgba(0,0,0,.18)}
.front3::after{content:"";position:absolute;inset:0;background:linear-gradient(105deg,rgba(255,255,255,.18) 0%,rgba(255,255,255,0) 35%)}
.back3{transform:rotateY(180deg) translateZ(calc(var(--d)/2));border-radius:6px 2px 2px 6px;overflow:hidden;box-shadow:inset 8px 0 12px rgba(0,0,0,.2)}
.inside3{transform:translateZ(calc(var(--d)/2 - 1px))}
/* Arabic book: binding on the RIGHT */
.spine3{width:var(--d);left:auto;right:calc(-1 * var(--d)/2);transform:rotateY(90deg);
  background:linear-gradient(90deg,#3A1A5E,#5B2C8F 45%,#3A1A5E);display:flex;align-items:center;justify-content:center}
.spine3 span{writing-mode:vertical-rl;color:#F6E7C1;font-size:12px;font-weight:700;white-space:nowrap}
.pages3{width:calc(var(--d) - 4px);right:auto;left:calc(-1 * var(--d)/2 + 2px);top:3px;bottom:3px;transform:rotateY(-90deg);
  background:repeating-linear-gradient(90deg,#FFFDF8 0 2px,#E6DCCB 2px 3px)}
.top3{bottom:auto;height:calc(var(--d) - 4px);top:calc(-1 * var(--d)/2 + 2px);left:3px;right:3px;transform:rotateX(90deg);
  background:repeating-linear-gradient(180deg,#FFFDF8 0 2px,#E6DCCB 2px 3px)}
.stage3d{position:relative}
.stage3d::after{content:"";position:absolute;left:50%;bottom:34px;width:240px;height:26px;transform:translateX(-50%);border-radius:50%;
  background:radial-gradient(closest-side,rgba(36,18,74,.32),rgba(36,18,74,0));pointer-events:none}
.stand-actions{display:flex;flex-direction:column;align-items:center;gap:8px;margin-top:4px}
.flip-bar[hidden],.fx-hint[hidden]{display:none!important}
/* both views share the same spot, so the standing book can land exactly on the open book's cover */
.desk{display:grid}
.desk>.stand-view,.desk>.open-book{grid-area:1/1;align-self:center}
.desk>.open-book{width:100%;max-width:740px;justify-self:center;margin:0}
.open-book.off{visibility:hidden;pointer-events:none}
.stand-view.off{visibility:hidden}
.stand-view.off .stand-actions{visibility:hidden}
.b3wrap{transition:transform .85s cubic-bezier(.45,.05,.25,1);transform-style:preserve-3d}
.stage3d.landing::after{opacity:0;transition:opacity .4s}
.stand-actions{transition:opacity .3s}.stand-view.leaving .stand-actions{opacity:0}
.fx .close-btn{width:auto!important;padding:0 14px;border-radius:24px!important;font-size:14px!important;background:#fff!important;color:var(--ink)!important;
  border:2px solid #E7DDF3!important;box-shadow:none!important}
@media (min-width:900px){.stage3d{height:480px}.b3d{--w:270px;--h:360px;--d:26px}}
/* a real opened book: hard cover boards behind, page block thickness on both sides,
   the dip of the pages into the spine, and a soft shadow on the table */
.open-book{position:relative;max-width:740px;margin:0 auto;padding:10px 12px 16px;--l:7px;--r:7px;
  transform:perspective(1600px) rotateX(9deg);transform-origin:50% 60%}
.open-book .board{position:absolute;inset:0;border-radius:10px;background:linear-gradient(180deg,#4A2384,#2E1257);
  box-shadow:0 40px 50px -22px rgba(36,18,74,.45),0 14px 20px -6px rgba(36,18,74,.22),inset 0 0 0 1px rgba(255,255,255,.12)}
.open-book .board::after{content:"";position:absolute;left:50%;top:0;bottom:0;width:18px;transform:translateX(-50%);
  background:linear-gradient(90deg,rgba(0,0,0,.35),rgba(255,255,255,.08) 50%,rgba(0,0,0,.35))}
.open-book .stack{position:absolute;top:8px;bottom:9px;background:repeating-linear-gradient(180deg,#FFFDF8 0 2px,#E6DCCB 2px 3px);
  border-radius:3px;box-shadow:0 1px 2px rgba(0,0,0,.2)}
.open-book .stack-l{left:6px;right:calc(50% + 2px);transform:translateX(calc(-1 * var(--l) + 6px)) translateY(4px)}
.open-book .stack-r{right:6px;left:calc(50% + 2px);transform:translateX(calc(var(--r) - 6px)) translateY(4px)}
#flipBook{margin:0 auto;position:relative;z-index:1}
.open-book .gutter{position:absolute;z-index:20;pointer-events:none;inset:0;
  background:
   linear-gradient(90deg,
     rgba(0,0,0,.16) 0%,rgba(0,0,0,.05) 2.5%,rgba(255,255,255,0) 6%,
     rgba(255,250,235,.10) 16%,rgba(255,255,255,0) 30%,
     rgba(70,40,10,.07) 38%,rgba(55,30,8,.20) 44%,rgba(35,18,4,.42) 48%,rgba(10,5,0,.62) 49.6%,rgba(0,0,0,.72) 50%,
     rgba(10,5,0,.62) 50.4%,rgba(35,18,4,.42) 52%,rgba(55,30,8,.20) 56%,rgba(70,40,10,.07) 62%,
     rgba(255,255,255,0) 70%,rgba(255,250,235,.10) 84%,rgba(255,255,255,0) 94%,rgba(0,0,0,.05) 97.5%,rgba(0,0,0,.16) 100%),
   linear-gradient(180deg,rgba(0,0,0,.07) 0%,rgba(0,0,0,0) 4%,rgba(0,0,0,0) 96%,rgba(0,0,0,.09) 100%)}
.open-book .gutter::after{content:"";position:absolute;inset:0;background:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .35 0 0 0 0 .2 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");opacity:.18;mix-blend-mode:multiply}
.open-book .gutter::before{content:"";position:absolute;left:50%;top:-4px;bottom:-4px;width:36px;transform:translateX(-50%);
  background:radial-gradient(60% 6px at 50% 0,rgba(0,0,0,.35),transparent),radial-gradient(60% 6px at 50% 100%,rgba(0,0,0,.35),transparent)}
.open-book .headband{position:absolute;left:50%;width:12px;height:3px;transform:translateX(-50%);z-index:0;border-radius:2px;
  background:repeating-linear-gradient(90deg,#7A2E4A 0 1.5px,#E9DCC4 1.5px 3px);opacity:.9}
.open-book .headband.top{top:8px}.open-book .headband.bottom{bottom:14px}
.open-book .ribbon{position:absolute;z-index:22;left:calc(50% + 6px);bottom:-34px;width:14px;height:58px;
  background:linear-gradient(90deg,#B81B61,#E0287A 45%,#B81B61);clip-path:polygon(0 0,100% 0,100% 100%,50% 82%,0 100%);
  box-shadow:0 2px 4px rgba(0,0,0,.3);transform:rotate(4deg);transform-origin:top center}
.open-book.closed-front .headband,.open-book.closed-back .headband,.open-book.closed-front .ribbon,.open-book.closed-back .ribbon{display:none}
/* closed: only the cover is shown, on one half */
.open-book.closed-front .board,.open-book.closed-front .stack-r,.open-book.closed-front .gutter{display:none}
.open-book.closed-back .board,.open-book.closed-back .stack-l,.open-book.closed-back .gutter{display:none}
.open-book.closed-front #flipBook,.open-book.closed-back #flipBook{filter:drop-shadow(0 18px 18px rgba(36,18,74,.3))}
/* a closed book sits in the middle of the desk, not on one half */
.open-book.ready .fb-shift,.open-book.ready .stack{transition:transform .95s cubic-bezier(.45,.05,.25,1)}  /* no slide on first paint */
.fb-shift{position:relative;z-index:1}
.open-book.closed-front .fb-shift{transform:translateX(25%)}
.open-book.closed-back .fb-shift{transform:translateX(-25%)}
.open-book.closed-front .stack-l{transform:translate(calc(50% - 7px),6px)}
.open-book.closed-back .stack-r{transform:translate(calc(-50% + 7px),6px)}
#flipBook .page{background:#FAF4E8;overflow:hidden}
#flipBook .page img{width:100%;height:100%;object-fit:cover;display:block;pointer-events:none;user-select:none}
#flipBook .page.hard{background:#3B1C6E}
/* last page: the ending is only glimpsed through a glowing keyhole */
#flipBook .page.more{container-type:inline-size;background:radial-gradient(circle at 50% 38%,#55308A 0%,#2A1450 55%,#170A2E 100%)}
#flipBook .page.more::before{content:"";position:absolute;inset:5cqw;border:1px solid rgba(233,196,106,.55);border-radius:2cqw;pointer-events:none}
/* the library sets its own display/position on pages: the layout lives in an inner box */
#flipBook .more-in{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:5cqw}
#flipBook .kh{position:relative;width:44cqw;aspect-ratio:100/160;animation:khGlow 3.2s ease-in-out infinite}
#flipBook .kh-view{position:absolute;inset:0;background-size:200cqw auto;background-position:30% 80%;animation:khPeek 10s ease-in-out infinite alternate;
  -webkit-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 160'%3E%3Cpath d='M50 14a36 36 0 0 1 20 66l14 66H16l14-66a36 36 0 0 1 20-66z'/%3E%3C/svg%3E") center/100% 100% no-repeat;
          mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 160'%3E%3Cpath d='M50 14a36 36 0 0 1 20 66l14 66H16l14-66a36 36 0 0 1 20-66z'/%3E%3C/svg%3E") center/100% 100% no-repeat}
#flipBook .kh svg{position:absolute;inset:0;width:100%;height:100%;fill:none;stroke:#E9C46A;stroke-width:3.2;overflow:visible}
@keyframes khGlow{0%,100%{filter:drop-shadow(0 0 2cqw rgba(255,196,90,.35))}50%{filter:drop-shadow(0 0 6cqw rgba(255,196,90,.75))}}
@keyframes khPeek{from{background-position:25% 76%}to{background-position:70% 92%}}
#flipBook .kh-txt{margin:0;color:#F6E7C1;font-size:7cqw;font-weight:700;letter-spacing:.2px}
@media (prefers-reduced-motion:reduce){#flipBook .kh,#flipBook .kh-view{animation:none}}
#flipBook .more-cta{padding:3cqw 7cqw;border-radius:99px;background:var(--rose);color:#fff;font-weight:700;
  font-size:6.5cqw;text-decoration:none;text-shadow:none;box-shadow:0 4px 12px rgba(0,0,0,.25)}
.flip-bar{display:flex;align-items:center;justify-content:center;gap:14px;margin-top:16px}
.flip-bar button{width:48px;height:48px;border-radius:50%;border:0;background:var(--ink);color:#fff;font-size:20px;cursor:pointer;
  box-shadow:0 6px 16px rgba(36,18,74,.25)}
.flip-bar button:disabled{opacity:.3;cursor:default}
.progress{width:min(240px,50vw);height:6px;border-radius:9px;background:#E3D9EE;overflow:hidden;direction:rtl}
.progress i{display:block;height:100%;width:0;background:var(--rose);border-radius:9px;transition:width .5s}
.fx-hint{font-size:13px;color:var(--muted);text-align:center;margin-top:10px}

.fx .lead{text-align:center;color:var(--muted);margin:-10px 0 4px;font-size:14px}
.fx .lead small{display:block;font-size:12.5px;margin-top:2px}
@media (prefers-reduced-motion:reduce){.b3d.idle{animation:none}.b3d,.b3wrap,.front3{transition:none}}

/* phones: the same open book, just using the full width */
@media (max-width:700px){.fx .desk{padding:16px 0 28px;margin:0 -10px}.fx .open-book{padding:6px 6px 10px}}
/* while the cover images load: book colours instead of an empty white box */
.front3,.back3{background:linear-gradient(160deg,#E9C98F,#B9824E 55%,#7E4B2B)}
.inside3{background:#FAF1DE}
