/* Quran Hifz - the mushaf as a real book (modules/book3d.js): app themes night / sepia / blue mosque, 3D book look
   (cover, page-stack edges, gutter, paper grain, wooden rehal), the page curl layers, and the Themes gallery. Loaded last. */

/* ================================================================ app themes (dark green-gold and light ivory are in style.css) */
body.th-night { --bg: #060708; --bar: #0d0f11; --bar2: #15181b; --gold: #c9a54a; --text: #ebe6d8; --muted: #9a9f9c; --btn: #1b1e21; --btnh: #262a2e;
  --accent: #3f8f6a; --card: #0a0b0c; --dk-bg: #08090a; --dk-bg2: #0e1012; --dk-line: #6f5f35; --dk-fg: #ebe6d8; --dk-mut: #9a9f9c; }
body.light.th-sepia { --bg: #e6d8bb; --bar: #5b4226; --bar2: #6c5131; --gold: #a8782c; --btn: #7b5c37; --btnh: #8c6b42; --accent: #8a6a2c; --card: #f6eedb;
  --dk-bg: #4d3820; --dk-bg2: #5a4227; --dk-line: #b38d4a; --dk-fg: #fbf2dc; --dk-mut: #e3d2b0; }
body.th-blue { --bg: #0a1828; --bar: #0f2238; --bar2: #15304f; --gold: #d8b65a; --text: #eef3fa; --muted: #9fb3ca; --btn: #1a3a5d; --btnh: #234d7a;
  --accent: #3a86c8; --card: #07121e; --dk-bg: #091626; --dk-bg2: #0d1e33; --dk-line: #8a7440; --dk-fg: #eef3fa; --dk-mut: #a9bdd4; }
body.th-night, body.th-blue, body.light.th-sepia { background: var(--bg); }
body.th-blue main { background: radial-gradient(ellipse 70% 60% at 50% 42%, #173a60 0%, rgba(10, 24, 40, 0) 70%); }
body.light.th-sepia main { background: radial-gradient(ellipse 70% 60% at 50% 42%, #f1e6cc 0%, rgba(230, 216, 187, 0) 70%); }
/* night paper: black page with gold-tinted text */
.qm-page.qm-paper-night { --qm-ink: #eadcb0; --qm-paper: #151719; --qm-paper2: #0c0d0e; }

/* ================================================================ 3D book */
:root {
  --b3-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .32 0 0 0 0 .25 0 0 0 0 .14 0 0 0 .55 -.18'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .09' numOctaves='3' seed='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .4 0 0 0 0 .3 0 0 0 0 .15 0 0 0 .4 -.16'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
}
#mushafHost .qm-page { --b3-e1: color-mix(in srgb, var(--qm-paper) 82%, #fff); --b3-e2: color-mix(in srgb, var(--qm-paper2) 72%, #5c4a2c); }
#mushafHost .qm-page.qm-dark, #mushafHost .qm-page.qm-paper-night { --b3-e1: color-mix(in srgb, var(--qm-paper) 70%, #b9a46a); --b3-e2: color-mix(in srgb, var(--qm-paper2) 85%, #000); }
body.b3-book #book.own, body.b3-rehal #book.own { padding: 16px 72px 20px; }
body.b3-rehal #book.own { position: relative; z-index: 0; padding-bottom: clamp(52px, 15vh, 180px); }
@media (max-width: 700px), (max-height: 520px) {
  body.b3-book #book.own, body.b3-rehal #book.own { padding: 10px 12px 14px; }
  body.b3-rehal #book.own { padding-bottom: clamp(36px, 11vh, 120px); }
}
body.b3-book #mushafHost .qm-spread, body.b3-rehal #mushafHost .qm-spread { box-shadow: none; }
/* paper: grain + fibres over the page colour; the gutter curves into the spine */
body.b3-book #mushafHost .qm-page, body.b3-rehal #mushafHost .qm-page {
  background-image: linear-gradient(to left, rgba(40, 25, 5, .20), rgba(40, 25, 5, .05) 4%, transparent 9%), var(--b3-grain),
    radial-gradient(ellipse at 50% 45%, var(--qm-paper) 55%, var(--qm-paper2) 100%);
  box-shadow: var(--b3-sh-1); }
body.b3-book #mushafHost .qm-spread > .qm-page:first-child, body.b3-rehal #mushafHost .qm-spread > .qm-page:first-child {
  background-image: linear-gradient(to right, rgba(40, 25, 5, .34), rgba(40, 25, 5, .12) 2.5%, rgba(255, 255, 255, .08) 5%, transparent 11%), var(--b3-grain),
    radial-gradient(ellipse at 50% 45%, var(--qm-paper) 55%, var(--qm-paper2) 100%);
  box-shadow: var(--b3-sh-r); border-radius: 0 5px 5px 0; }
body.b3-book #mushafHost .qm-spread > .qm-page:last-child, body.b3-rehal #mushafHost .qm-spread > .qm-page:last-child {
  background-image: linear-gradient(to left, rgba(40, 25, 5, .34), rgba(40, 25, 5, .12) 2.5%, rgba(255, 255, 255, .08) 5%, transparent 11%), var(--b3-grain),
    radial-gradient(ellipse at 50% 45%, var(--qm-paper) 55%, var(--qm-paper2) 100%);
  box-shadow: var(--b3-sh-l); border-radius: 5px 0 0 5px; }
body.b3-book #mushafHost > .qm-pre, body.b3-rehal #mushafHost > .qm-pre { box-shadow: none; }
/* hard cover under the page block (an element of its own, first in #mushafHost: painted under the pages) */
#mushafHost > .b3-cover { display: none; pointer-events: none; border-radius: 7px; align-self: center; justify-self: center;
  background: radial-gradient(ellipse at 50% 30%, #2a5a40 0%, #173827 60%, #0e2619 100%);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .25), inset 0 0 0 4px rgba(212, 175, 55, .35), inset 0 0 0 5px rgba(0, 0, 0, .2), 0 16px 34px rgba(0, 0, 0, .55), 0 3px 8px rgba(0, 0, 0, .4); }
body.b3-book #mushafHost > .b3-cover, body.b3-rehal #mushafHost > .b3-cover { display: block; }
body.th-blue #mushafHost > .b3-cover { background: radial-gradient(ellipse at 50% 30%, #24507f 0%, #143156 60%, #0b1f38 100%); }
body.light.th-sepia #mushafHost > .b3-cover, body.th-night #mushafHost > .b3-cover { background: radial-gradient(ellipse at 50% 30%, #6a4524 0%, #4a2e16 60%, #2f1c0c 100%); }
body.th-night #mushafHost > .b3-cover { background: radial-gradient(ellipse at 50% 30%, #2a2b2d 0%, #17181a 60%, #0b0c0d 100%); }
/* wooden rehal under the book */
#b3Rehal { position: absolute; z-index: -1; pointer-events: none; display: none; }
body.b3-rehal #b3Rehal { display: block; }
#b3Rehal svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* ================================================================ page curl (book3d.js sets clip-path / transform per frame) */
#mushafHost { touch-action: pan-y pinch-zoom; }
#mushafHost > .qm-pre.b3-turning { visibility: visible; }
#mushafHost > .b3-turning { animation: none !important; pointer-events: none; }
#mushafHost .b3-hide { visibility: hidden !important; }
#mushafHost > .b3-fx { display: none; position: relative; align-self: stretch; justify-self: stretch; width: 100%; height: 100%; z-index: 6; pointer-events: none; overflow: visible; }
#mushafHost > .b3-fx.on { display: block; }
/* clips that only move: a huge half-plane square on the fold line (.b3-hp), the flap page box (.b3-bm), the leaf's place (.b3-ub) */
.b3-fx .b3-hp, .b3-fx .b3-bm { position: absolute; left: 0; top: 0; overflow: hidden; transform-origin: 0 0; will-change: transform; }
.b3-fx .b3-ub { position: absolute; overflow: hidden; }
.b3-fx .b3-clone { position: absolute !important; left: 0; top: 0; margin: 0; transform-origin: 0 0; box-shadow: none !important; border-radius: 0 !important;
  visibility: visible !important; animation: none !important; will-change: transform; }
.b3-fx .b3-bm > .b3-clone { transform: none; }
.b3-fx .b3-pb { position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  background: linear-gradient(to left, rgba(40, 25, 5, .22), transparent 7%), var(--b3-grain), linear-gradient(100deg, var(--b3-pb1, #fbf4e2), var(--b3-pb, #efe3c3)); }
.b3-fx i { position: absolute; left: 0; top: 0; width: 100px; height: 100%; transform-origin: 0 0; will-change: transform; }
.b3-fx .b3-ub i { background: linear-gradient(to right, rgba(0, 0, 0, .46), rgba(0, 0, 0, .18) 30%, rgba(0, 0, 0, .05) 70%, rgba(0, 0, 0, 0)); }
.b3-fx .b3-bm > i { background: linear-gradient(to right, rgba(0, 0, 0, .30) 0%, rgba(0, 0, 0, .08) 4%, rgba(255, 255, 255, .30) 13%, rgba(255, 255, 255, .06) 34%,
  rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, .10) 88%, rgba(0, 0, 0, .20) 100%); }
/* the copied right page keeps its gutter on the spine side */
body.b3-book #mushafHost .b3-fx .qm-page.b3-cr, body.b3-rehal #mushafHost .b3-fx .qm-page.b3-cr {
  background-image: linear-gradient(to right, rgba(40, 25, 5, .34), rgba(40, 25, 5, .12) 2.5%, rgba(255, 255, 255, .08) 5%, transparent 11%), var(--b3-grain),
    radial-gradient(ellipse at 50% 45%, var(--qm-paper) 55%, var(--qm-paper2) 100%); }

/* ================================================================ themes gallery (Settings > Appearance > Themes) */
.b3-gal { display: flex; flex-direction: column; gap: 8px; }
.b3-now { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 14px; border: 1px solid var(--hf-line2, #d4af3766); background: var(--hf-soft, #ffffff0b); }
.b3-now .b3-mini { width: 46%; flex: none; }
.b3-nowt { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.b3-nowt b { font-size: 15px; color: var(--gold); }
.b3-nowt small { font-size: 12px; opacity: .85; line-height: 1.5; }
.b3-h { margin: 12px 2px 0; font-size: 13px; font-weight: 700; color: var(--gold); letter-spacing: .01em; }
.b3-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.b3-card { display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 6px 6px 7px; margin: 0; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--hf-line, #d4af373d); background: var(--hf-soft, #ffffff0b); color: inherit; font: inherit; text-align: center; transition: border-color .15s, transform .15s; }
.b3-card:hover { border-color: var(--hf-line2, #d4af3780); transform: translateY(-1px); }
.b3-card:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.b3-card.on { border-color: var(--gold); box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 50%, transparent); }
.b3-cl { font-size: 12px; line-height: 1.35; }
/* mini preview: app background + bottom bar, an open book (paper, frame, text lines), optional rehal */
.b3-mini { position: relative; display: block; aspect-ratio: 4 / 3; border-radius: 8px; overflow: hidden; background: var(--m-bg); box-shadow: inset 0 0 0 1px #0000001f; }
.b3-mini::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 11%; background: var(--m-bar); }
.b3m-book { position: absolute; left: 13%; right: 13%; top: 11%; bottom: 25%; display: flex; flex-direction: row-reverse; }
.b3m-p { flex: 1; position: relative; background: var(--m-pp); }
.b3m-p::before { content: ''; position: absolute; inset: 8%; border: var(--m-frb, 2px double #b98f2e); box-shadow: var(--m-frs, 0 0 0 1px #1d5c41); border-radius: 1px; }
.b3m-p::after { content: ''; position: absolute; inset: 21% 17% 16%; background: repeating-linear-gradient(to bottom, var(--m-ink) 0 1px, transparent 1px 4.5px); opacity: .5; }
.b3-mini-big .b3m-p::after { background: repeating-linear-gradient(to bottom, var(--m-ink) 0 1.4px, transparent 1.4px 6px); }
.b3m-bk-flat .b3m-book { box-shadow: 0 2px 6px #0007; }
.b3m-bk-book .b3m-book, .b3m-bk-rehal .b3m-book { filter: drop-shadow(0 3px 4px #0008); }
.b3m-bk-book .b3m-p:first-child, .b3m-bk-rehal .b3m-p:first-child { box-shadow: 1px .5px 0 var(--m-pp), 2px 1px 0 #0003, 3px 1.5px 0 var(--m-pp), 4px 2px 0 #0003;
  background-image: linear-gradient(to right, #0000004d, transparent 14%); }
.b3m-bk-book .b3m-p:last-child, .b3m-bk-rehal .b3m-p:last-child { box-shadow: -1px .5px 0 var(--m-pp), -2px 1px 0 #0003, -3px 1.5px 0 var(--m-pp), -4px 2px 0 #0003;
  background-image: linear-gradient(to left, #0000004d, transparent 14%); }
.b3m-rh { display: none; position: absolute; left: 8%; right: 8%; bottom: 11%; height: 17%;
  background: linear-gradient(#a06a36, #6b3f1c 45%, #3f230d);
  clip-path: polygon(0 0, 100% 0, 100% 22%, 97% 22%, 91% 100%, 69% 100%, 64% 62%, 50% 44%, 36% 62%, 31% 100%, 9% 100%, 3% 22%, 0 22%); }
.b3m-bk-rehal .b3m-rh { display: block; }
.b3m-bk-rehal .b3m-book { bottom: 27%; }
/* app colours */
.b3m-app-dark { --m-bg: #0f1d17; --m-bar: #0d1914; }
.b3m-app-light { --m-bg: #e9e2cf; --m-bar: #24463a; }
.b3m-app-night { --m-bg: #060708; --m-bar: #121416; }
.b3m-app-sepia { --m-bg: #e6d8bb; --m-bar: #4d3820; }
.b3m-app-blue { --m-bg: radial-gradient(ellipse at 50% 40%, #173a60, #0a1828 70%); --m-bar: #091626; }
.b3m-app-auto { --m-bg: linear-gradient(135deg, #0f1d17 50%, #e9e2cf 50%); --m-bar: linear-gradient(90deg, #0d1914 50%, #24463a 50%); }
/* papers */
.b3m-pp-light { --m-pp: #fbf3dc; --m-ink: #3a3020; }
.b3m-pp-white { --m-pp: #ffffff; --m-ink: #222; }
.b3m-pp-green { --m-pp: #eaf4e4; --m-ink: #1b3a26; }
.b3m-pp-sepia { --m-pp: #f0dfc0; --m-ink: #4a3215; }
.b3m-pp-night { --m-pp: #17191b; --m-ink: #e3cf95; }
.b3m-pp-dark { --m-pp: #12402d; --m-ink: #f1d98c; }
.b3m-pp-auto { --m-pp: linear-gradient(135deg, #12402d 50%, #fbf3dc 50%); --m-ink: #9a8a5a; }
/* frames */
.b3m-fr-taj { --m-frb: 2px double #b98f2e; --m-frs: 0 0 0 1px #1d5c41; }
.b3m-fr-plain { --m-frb: 1px solid #b98f2e; --m-frs: none; }
.b3m-fr-gold { --m-frb: 3px double #d4af37; --m-frs: 0 0 0 1.5px #e2c46f, inset 0 0 0 1px #e2c46f99; }
.b3m-fr-classic { --m-frb: 3px solid #1f4d36; --m-frs: 0 0 0 1px #b98f2e; }
.b3m-fr-minimal { --m-frb: 0 solid transparent; --m-frs: none; }
