/* Mursal Library page-turn viewer. One file, no libraries. */
:root {
  --green: #0E6B5C; --green-d: #09493F; --mint: #6FD3B8; --amber: #F2B04B;
  --ink: #14201B; --muted: #56665E; --line: #DDE3DF; --bg: #F3F5F2;
  --stage: #2B3430; --bar: 56px; --head: 52px;
  --font: 'IBM Plex Sans Arabic', Tahoma, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--stage); color: var(--ink); overflow: hidden; }
button { font: inherit; }

/* height follows the visible screen on phones (the browser's address bar and keyboard come and go) */
.mr { position: fixed; top: 0; left: 0; right: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; user-select: none; -webkit-user-select: none; }

/* header */
.mr-head { height: var(--head); flex: none; display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: #fff; border-bottom: 1px solid var(--line); }
.mr-brand { display: flex; align-items: center; gap: 8px; color: var(--green-d); text-decoration: none; font-weight: 700; font-size: 15px; white-space: nowrap; }
.mr-brand img { width: 28px; height: 28px; }
.mr-title { flex: 1; min-width: 0; text-align: center; line-height: 1.25; }
.mr-title b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mr-title span { font-size: 12px; color: var(--muted); }
.mr-head .mr-btn { color: var(--green-d); }

/* stage */
.mr-stage { flex: 1; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #3A4540 0%, var(--stage) 70%); touch-action: pan-y; }
.mr-loading { color: #cfd8d3; font-size: 15px; }

/* spread (desktop) */
.mr-book { position: relative; display: flex; flex-direction: row; width: calc(var(--pw) * 2); height: var(--ph);
  perspective: calc(var(--pw) * 4); transition: transform .5s ease; }
.mr-book.only-left { transform: translateX(calc(var(--pw) * .5)); }   /* centre the lone left page (cover) */
.mr-book.only-right { transform: translateX(calc(var(--pw) * -.5)); }
.mr-side { position: relative; width: var(--pw); height: var(--ph); }
.mr-page { position: absolute; inset: 0; background: #fff; overflow: hidden; }
.mr-page img { width: 100%; height: 100%; display: block; object-fit: fill; -webkit-user-drag: none; }
.mr-page.blank { background: transparent; }
.mr-side.r .mr-page:not(.blank) { box-shadow: 6px 0 22px rgba(0,0,0,.35); }
.mr-side.l .mr-page:not(.blank) { box-shadow: -6px 0 22px rgba(0,0,0,.35); }
/* spine shading */
.mr-side.r .mr-page:not(.blank)::after, .mr-side.l .mr-page:not(.blank)::after { content: ""; position: absolute; top: 0; bottom: 0; width: 7%; pointer-events: none; }
.mr-side.r .mr-page::after { left: 0; background: linear-gradient(to right, rgba(0,0,0,.18), transparent); }
.mr-side.l .mr-page::after { right: 0; background: linear-gradient(to left, rgba(0,0,0,.18), transparent); }

/* the turning leaf */
.mr-leaf { position: absolute; top: 0; width: var(--pw); height: var(--ph); transform-style: preserve-3d; z-index: 5;
  will-change: transform; transition: none; }
.mr-leaf.anim { transition: transform var(--flip, .6s) cubic-bezier(.3,.1,.3,1); }
.mr-leaf.hinge-r { left: 0; transform-origin: right center; }   /* hinged on its right edge (spine, or the phone page's edge) */
.mr-leaf.hinge-l { right: 0; transform-origin: left center; }
.mr-book.single .mr-leaf.hinge-r { left: 0; }
.mr-leaf .face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: #fff; overflow: hidden; }
.mr-leaf .face img { width: 100%; height: 100%; display: block; }
.mr-leaf .face.b { transform: rotateY(180deg); }
.mr-leaf .face.paper { background: linear-gradient(to right, #e9e6df, #f7f5f0 40%, #fbfaf7); }
/* the bend: darker near the hinge as the page lifts */
.mr-leaf .face::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: var(--shade, 0);
  background: linear-gradient(to left, rgba(0,0,0,.28), rgba(0,0,0,.06) 35%, rgba(255,255,255,.08) 70%, rgba(0,0,0,0)); }
.mr-leaf.hinge-l .face::after { background: linear-gradient(to right, rgba(0,0,0,.28), rgba(0,0,0,.06) 35%, rgba(255,255,255,.08) 70%, rgba(0,0,0,0)); }

/* single page (phone) */
.mr-book.single { width: var(--pw); }
.mr-book.single .mr-page { box-shadow: 0 6px 24px rgba(0,0,0,.4); }

/* edges to click */
.mr-hit { position: absolute; top: 0; bottom: 0; width: 18%; z-index: 4; cursor: pointer; }
.mr-hit.next { left: 0; } .mr-hit.prev { right: 0; }

/* bottom bar */
.mr-bar { height: var(--bar); flex: none; display: flex; align-items: center; justify-content: center; gap: 4px;
  background: #fff; border-top: 1px solid var(--line); padding: 0 8px env(safe-area-inset-bottom); }
.mr-btn { width: 42px; height: 42px; border: 0; background: transparent; border-radius: 10px; color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.mr-btn:hover { background: var(--bg); }
.mr-btn:disabled { opacity: .3; cursor: default; background: transparent; }
.mr-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mr-count { min-width: 92px; height: 38px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  font-weight: 600; font-size: 14px; cursor: pointer; color: var(--ink); }
.mr-sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; }

/* panels: thumbnails, search, share */
.mr-panel { position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 20; background: rgba(20,32,27,.55); display: none; }
.mr-panel.open { display: flex; justify-content: flex-start; }
.mr-sheet { width: min(420px, 100%); height: 100%; background: #fff; display: flex; flex-direction: column; }
.mr-sheet h3 { margin: 0; padding: 14px 16px; font-size: 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.mr-sheet .body { flex: 1; overflow: auto; padding: 12px 16px; }
.mr-thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mr-thumbs button { border: 2px solid transparent; padding: 0; background: none; cursor: pointer; border-radius: 6px; overflow: hidden; text-align: center; font-size: 12px; color: var(--muted); }
.mr-thumbs button.cur { border-color: var(--green); }
.mr-thumbs img { width: 100%; display: block; aspect-ratio: var(--ar); background: var(--bg); }
.mr-search { display: flex; gap: 8px; }
.mr-search input { flex: 1; height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; font: inherit; font-size: 15px; }
.mr-search input:focus { outline: 2px solid var(--mint); border-color: var(--green); }
.mr-results { margin-top: 12px; }
.mr-results button { display: block; width: 100%; text-align: justify; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 10px 0; cursor: pointer; font-size: 14px; line-height: 1.7; color: var(--ink); }
.mr-results b { color: var(--green); display: block; font-size: 13px; }
.mr-results mark { background: #FCE7BF; color: inherit; border-radius: 3px; padding: 0 2px; }
.mr-note { color: var(--muted); font-size: 13px; text-align: justify; line-height: 1.8; }
.mr-field { margin-bottom: 16px; }
.mr-field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.mr-field textarea, .mr-field input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px; font: 13px/1.6 monospace; direction: ltr; resize: none; background: var(--bg); }
.mr-copy { margin-top: 6px; height: 38px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--green); color: #fff; font-weight: 600; cursor: pointer; }

/* zoom */
.mr-zoom { position: absolute; inset: 0; z-index: 30; background: #1b2320; display: none; }
.mr-zoom.open { display: block; }
.mr-zoom .scroller { direction: ltr; position: absolute; inset: 0; overflow: auto; touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; }
.mr-zoom img { display: block; margin: 0 auto; max-width: none; background: #fff; }
.mr-zoom .tools { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; z-index: 2; }
.mr-zoom .tools .mr-btn { background: rgba(255,255,255,.92); box-shadow: 0 2px 8px rgba(0,0,0,.3); }

.mr-toast { position: absolute; bottom: calc(var(--bar) + 14px); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 8px 16px; border-radius: 20px; font-size: 14px; z-index: 40; opacity: 0; transition: opacity .2s; pointer-events: none; }
.mr-toast.show { opacity: 1; }

/* embedded in another site: no header */
.mr.embed .mr-head { display: none; }

@media (max-width: 560px) {
  .mr-brand span { display: none; }
  .mr-count { min-width: 76px; }
  .mr-btn { width: 38px; }
  .mr-hide-sm { display: none; }
}

/* ---------- Mursal ad strips above and below the reader ----------
   Full width, as low as an ad allows: phones 320x50, computers 728x90 shown at about 485x60.
   A strip only shows once an ad is really in it, so with no campaign the page gets the space back. */
.mr-ad { flex: none; display: none; position: relative; justify-content: center; align-items: center; background: #fff; overflow: hidden; padding: 3px 0; }
.mr-ad.top { border-bottom: 1px solid var(--line); }
.mr-ad.bottom { border-top: 1px solid var(--line); padding-bottom: calc(3px + env(safe-area-inset-bottom)); }
.mr-ad:has(iframe) { display: flex; }
.mr-ad-in { width: 100%; max-width: 485px; }
@media (max-width: 767px) { .mr-ad-in { max-width: none; } }
.mr-ad ins.mursal { display: block; width: 100%; margin: 0 !important; }
.mr-ad .mursal-label { display: none !important; }
.mr-ad .mursal-box { margin: 0 auto; }
.mr-ad::after { content: "إعلان"; position: absolute; top: 3px; left: 4px; font: 9px/1.5 var(--font); color: #56665E; background: rgba(255,255,255,.88); padding: 0 4px; border-radius: 3px; pointer-events: none; }
/* inside the app: full screen, no header (its buttons are in the bar) */
.mr.inapp .mr-head { display: none; }
.mr.inapp .mr-bar { padding-bottom: 0; }

/* books: links on the pages, contents and bookmarks */
.mr-link { position: absolute; z-index: 3; border-radius: 3px; cursor: pointer; }
.mr-link:hover { background: rgba(242,176,75,.22); }
.mr-btn.on svg { fill: currentColor; }
.mr-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.mr-tabs button { flex: 1; height: 36px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font: inherit; font-size: 14px; color: var(--ink); }
.mr-tabs button.on { background: var(--green); border-color: var(--green); color: #fff; }
.mr-toc > button, .mr-bm > button:first-child { display: flex; width: 100%; gap: 10px; align-items: baseline; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 9px 0; cursor: pointer; font: inherit; font-size: 14px; color: var(--ink); text-align: right; }
.mr-toc .t { flex: 1; } .mr-toc .n { color: var(--muted); font-size: 12px; white-space: nowrap; }
.mr-toc .l1 { font-weight: 700; } .mr-toc .l2 { padding-right: 14px; } .mr-toc .l3 { padding-right: 28px; font-size: 13px; color: var(--muted); }
.mr-toc button.cur, .mr-toc button.cur .n { color: var(--green); }
.mr-bm { display: flex; align-items: center; gap: 4px; }
.mr-bm .mr-btn { flex: none; }
.mr-back { position: absolute; bottom: 74px; left: 50%; transform: translateX(-50%); z-index: 15; display: none; border: 0; border-radius: 20px; padding: 8px 18px; background: var(--green-d); color: #fff; font: inherit; font-size: 14px; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.3); }
.mr-back.show { display: block; }
