/* Full-screen reader (reader.js). Self-contained: works on the app and on
   shared links, light or dark site theme. */
html.rd-open, html.rd-open body { overflow: hidden; }
.rd {
  --paperc: #fffdf7; --inkc: #1c2459; --accent: var(--blue, #2f55d4); --pinkc: var(--pink, #a3246b);
  position: fixed; inset: 0; z-index: 1000; display: grid; grid-template-rows: auto 1fr auto;
  background: #0d1238; color: #fff; font-family: "Atkinson", "Readex", system-ui, sans-serif;
  animation: rd-in .35s cubic-bezier(.2, .8, .2, 1);
  /* No double-tap zoom while turning pages on phones (pinch still works). */
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none;
}
.rd * { touch-action: manipulation; }
.rd.rd-leaving { animation: rd-out .25s ease forwards; }
@keyframes rd-in { from { opacity: 0; transform: scale(1.02); } }
@keyframes rd-out { to { opacity: 0; transform: scale(.985); } }

/* The current picture, blurred and huge, lights the room. */
.rd-ambient { position: absolute; inset: -10%; z-index: 0; overflow: hidden; pointer-events: none; }
.rd-ambient img { width: 100%; height: 100%; object-fit: cover; filter: blur(60px) saturate(1.4) brightness(.65); transform: scale(1.1); transition: opacity .6s; }
.rd-ambient::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at center, transparent 30%, rgba(8, 10, 40, .65)); }
.rd-textonly .rd-ambient img { display: none; }
.rd-textonly .rd-ambient { background: var(--rd-bg, linear-gradient(135deg, #2f55d4, #a3246b)) center / cover; filter: blur(30px) brightness(.7); }

.rd-bar, .rd-stage, .rd-foot { position: relative; z-index: 1; }
.rd-bar { display: flex; align-items: center; gap: 1rem; padding: 12px clamp(12px, 3vw, 28px); }
.rd-title { font: 700 1.05rem/1.2 "Grandstander", "Lalezar", system-ui; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34vw; }
.rd[dir="rtl"] .rd-title { font-family: "Lalezar", system-ui; font-weight: 400; }
.rd-count { font-size: .9rem; opacity: .8; }
.rd-tools { margin-inline-start: auto; display: flex; gap: 6px; align-items: center; }
.rd-btn { display: inline-flex; align-items: center; gap: .45rem; height: 42px; min-width: 42px; justify-content: center; padding: 0 10px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, .2); background: rgba(255, 255, 255, .1); color: #fff; font: 700 .9rem/1 inherit; cursor: pointer; backdrop-filter: blur(10px); transition: background .2s, transform .25s cubic-bezier(.34, 1.56, .64, 1); }
.rd-btn:hover { background: rgba(255, 255, 255, .22); transform: translateY(-1px); }
.rd-btn[aria-pressed="true"], .rd-auto.on { background: #ffd23f; color: #1c2459; border-color: #ffd23f; }
.rd-auto { padding-inline: 14px 16px; }
.rd-close { background: rgba(255, 255, 255, .92); color: #1c2459; }
@media (max-width: 640px) { .rd-auto span, .rd-title { display: none; } .rd-tools { gap: 4px; } .rd-btn { height: 38px; min-width: 38px; padding: 0 8px; } }

.rd-stage { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: clamp(6px, 2vw, 24px); padding: 0 clamp(6px, 2vw, 24px); min-height: 0; perspective: 2600px; }
.rd-nav { width: 52px; height: 52px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgba(255, 255, 255, .14); color: #fff; cursor: pointer; backdrop-filter: blur(8px); transition: background .2s, transform .3s cubic-bezier(.34, 1.56, .64, 1), opacity .2s; }
.rd-nav:hover:not(:disabled) { background: rgba(255, 255, 255, .3); transform: scale(1.08); }
.rd-nav:disabled { opacity: 0; pointer-events: none; }

/* ---------------------------------------------------------------- open book (wide screens) */
.rd-book { position: relative; justify-self: center; display: grid; grid-template-columns: 1fr 1fr; transform-style: preserve-3d;
  /* As big as fits: two square-ish pages side by side. */
  width: min(100%, calc((100dvh - 150px) * 2 * var(--ratio))); max-width: 1500px; aspect-ratio: calc(2 * var(--ratio));
  filter: drop-shadow(0 40px 60px rgba(0, 0, 0, .45)); container-type: inline-size; touch-action: pan-y; user-select: none; }
.rd-book::before { content: ""; position: absolute; inset: -1.2cqi -1cqi; border-radius: 1.6cqi; background: #2f55d4; box-shadow: .9cqi .9cqi 0 #a3246b; transform: translateZ(-1px); }
.rd-side { position: relative; overflow: hidden; }
.rd-l { border-radius: 1cqi 0 0 1cqi; } .rd-r { border-radius: 0 1cqi 1cqi 0; }
.rd[dir="rtl"] .rd-l { border-radius: 0 1cqi 1cqi 0; } .rd[dir="rtl"] .rd-r { border-radius: 1cqi 0 0 1cqi; }
.rd-spine { position: absolute; top: 0; bottom: 0; left: calc(50% - 1.5cqi); width: 3cqi; background: linear-gradient(90deg, transparent, rgba(28, 36, 89, .28), transparent); pointer-events: none; z-index: 3; }
.rd-pg { position: absolute; inset: 0; background: var(--paperc); color: var(--inkc); }
.rd-pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rd-pic-empty { background: linear-gradient(135deg, #e9edff, #ffe6f2); }
.rd-pic-end img { filter: saturate(.6) brightness(.9); }
.rd-words { display: grid; align-content: center; justify-items: center; text-align: center; padding: 5cqi 4.5cqi; gap: 1.4cqi;
  background: var(--paperc) linear-gradient(90deg, rgba(28, 36, 89, .09), transparent 8%); }
.rd[dir="rtl"] .rd-words { background: var(--paperc) linear-gradient(270deg, rgba(28, 36, 89, .09), transparent 8%); }
.rd-text { font-size: calc(var(--fs, 1) * clamp(15px, 2.15cqi, 34px)); line-height: 1.6; font-weight: 600; max-width: 34ch; }
.rd-text p { margin: 0 0 .7em; }
.rd-text2 { font-weight: 400; opacity: .75; font-size: .9em; }
.rd[dir="rtl"] .rd-text { font-family: "Readex", system-ui; line-height: 1.85; }
.rd-words h2 { margin: 0; font: 700 clamp(22px, 3.4cqi, 60px)/1.1 "Grandstander", "Lalezar", system-ui; color: var(--accent); text-wrap: balance; }
.rd[dir="rtl"] .rd-words h2 { font-family: "Lalezar", system-ui; font-weight: 400; }
.rd[lang="ar"] .rd-kicker { letter-spacing: 0; }
.rd-kicker { font-size: clamp(11px, 1.1cqi, 16px); letter-spacing: .25em; text-transform: none; color: #8a90b5; font-weight: 700; }
.rd-orn { color: var(--pinkc); letter-spacing: .5em; font-size: clamp(14px, 1.6cqi, 26px); }
.rd-no { position: absolute; bottom: 2.2cqi; inset-inline: 0; text-align: center; font-size: clamp(11px, 1.1cqi, 15px); color: #8a90b5; }
.rd-listen { display: inline-flex; gap: .4rem; align-items: center; margin-top: .4rem; padding: .5rem 1rem; border-radius: 999px; border: 2px solid #dde1f1; background: #fff; color: var(--inkc); font: 700 clamp(12px, 1.2cqi, 16px)/1 inherit; cursor: pointer; transition: transform .25s cubic-bezier(.34, 1.56, .64, 1), border-color .2s; }
.rd-listen:hover { transform: scale(1.05); border-color: var(--accent); }
.rd-end-actions { display: flex; gap: .6rem; flex-wrap: wrap; justify-content: center; margin-top: 1cqi; }
.rd-cta { padding: .8rem 1.4rem; border-radius: 999px; border: 0; background: var(--accent); color: #fff; font: 700 clamp(13px, 1.3cqi, 18px)/1 inherit; text-decoration: none; cursor: pointer; box-shadow: 3px 3px 0 var(--pinkc); }
.rd-cta-2 { background: #ffd23f; color: var(--inkc); }

/* The turning leaf */
.rd-leaf { position: absolute; top: 0; bottom: 0; right: 0; width: 50%; z-index: 5; transform-style: preserve-3d; transform-origin: 0 50%; transition: transform .95s cubic-bezier(.6, .04, .3, 1); }
.rd-leaf.fwd { transform: rotateY(0deg); } .rd-leaf.fwd.go { transform: rotateY(-180deg); }
.rd-leaf.back { transform: rotateY(-180deg); } .rd-leaf.back.go { transform: rotateY(0deg); }
.rd[dir="rtl"] .rd-leaf { right: auto; left: 0; transform-origin: 100% 50%; }
.rd[dir="rtl"] .rd-leaf.fwd.go, .rd[dir="rtl"] .rd-leaf.back { transform: rotateY(180deg); }
.rd[dir="rtl"] .rd-leaf.back.go { transform: rotateY(0deg); }
.rd-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; border-radius: 0 1cqi 1cqi 0; }
.rd-face.backside { transform: rotateY(180deg); border-radius: 1cqi 0 0 1cqi; }
.rd[dir="rtl"] .rd-face { border-radius: 1cqi 0 0 1cqi; } .rd[dir="rtl"] .rd-face.backside { border-radius: 0 1cqi 1cqi 0; }
/* A shadow sweeps across the page as it lifts. */
.rd-face::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, rgba(0, 0, 0, .25), transparent 40%); opacity: 0; transition: opacity .95s; }
.rd-leaf.go .rd-face::after { opacity: 1; }

/* ---------------------------------------------------------------- one page at a time (phones, text-only) */
.rd-single .rd-book { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1.15fr) minmax(0, 1fr); aspect-ratio: auto; width: min(100%, 640px, calc((100dvh - 150px) * .78)); height: min(calc(100dvh - 140px), 900px); filter: drop-shadow(0 30px 50px rgba(0, 0, 0, .45)); }
.rd-single .rd-book::before { inset: -8px; border-radius: 22px; box-shadow: 5px 5px 0 #a3246b; }
.rd-single .rd-spine { display: none; }
.rd-single .rd-l { border-radius: 16px 16px 0 0; }
.rd-textonly.rd-single .rd-book { grid-template-rows: minmax(0, 1fr); }
.rd-single .rd-r { border-radius: 0 0 16px 16px; min-height: 0; }
.rd-single .rd-words { padding: 22px 22px 34px; background: var(--paperc); overflow-y: auto; align-content: center; }
.rd-single .rd-text { font-size: calc(var(--fs, 1) * clamp(17px, 4.4cqi, 26px)); }
.rd-single .rd-words h2 { font-size: clamp(26px, 7cqi, 44px); }
.rd-single .rd-no, .rd-single .rd-kicker, .rd-single .rd-listen, .rd-single .rd-cta { font-size: 14px; }
.rd-single .rd-no { bottom: 10px; }
/* Text-only books: words on the chosen background picture. */
.rd-textonly.rd-single .rd-l { display: none; }
.rd-textonly.rd-single .rd-r { border-radius: 16px; }
.rd-textonly .rd-words { background: linear-gradient(rgba(255, 253, 247, .84), rgba(255, 253, 247, .9)), var(--rd-bg, none) center / cover, var(--paperc); }
.rd-book.out-fwd { animation: rd-out-fwd .26s ease-in forwards; } .rd-book.in-fwd { animation: rd-in-fwd .38s cubic-bezier(.2, .8, .2, 1); }
.rd-book.out-back { animation: rd-out-back .26s ease-in forwards; } .rd-book.in-back { animation: rd-in-back .38s cubic-bezier(.2, .8, .2, 1); }
@keyframes rd-out-fwd { to { opacity: 0; transform: translateX(-12%) rotateY(18deg); } }
@keyframes rd-in-fwd { from { opacity: 0; transform: translateX(12%) rotateY(-18deg); } }
@keyframes rd-out-back { to { opacity: 0; transform: translateX(12%) rotateY(-18deg); } }
@keyframes rd-in-back { from { opacity: 0; transform: translateX(-12%) rotateY(18deg); } }
.rd[dir="rtl"] .rd-book.out-fwd { animation-name: rd-out-back; } .rd[dir="rtl"] .rd-book.in-fwd { animation-name: rd-in-back; }
.rd[dir="rtl"] .rd-book.out-back { animation-name: rd-out-fwd; } .rd[dir="rtl"] .rd-book.in-back { animation-name: rd-in-fwd; }
@media (max-width: 640px) { .rd-nav { position: absolute; bottom: 8px; width: 46px; height: 46px; z-index: 4; } .rd-prev { inset-inline-start: 10px; } .rd-next { inset-inline-end: 10px; } .rd-stage { grid-template-columns: 1fr; } }

/* Bedtime light: warmer, dimmer pages. */
.rd-night { --paperc: #f3e6cc; }
.rd-night .rd-pg { filter: brightness(.82) sepia(.18); }
.rd-night .rd-ambient img { filter: blur(60px) saturate(1.1) brightness(.4); }

.rd-foot { padding: 10px clamp(12px, 3vw, 28px) 14px; }
.rd-progress { height: 4px; border-radius: 999px; background: rgba(255, 255, 255, .18); overflow: hidden; }
.rd-progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffd23f, #a3246b); border-radius: inherit; transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.rd[dir="rtl"] .rd-progress span { margin-inline-start: auto; }

/* Shared-link invitation to open reading mode. */
.rd-invite { touch-action: manipulation; --accent: var(--blue, #2f55d4); --pinkc: var(--pink, #a3246b); --inkc: #1c2459; position: fixed; inset: 0; z-index: 900; display: grid; place-items: center; padding: 20px; background: rgba(13, 18, 56, .55); backdrop-filter: blur(6px); animation: rd-in .3s ease; }
.rd-invite-card { width: min(100%, 420px); text-align: center; padding: 26px; border-radius: 26px; background: #fff; color: #1c2459; box-shadow: 0 40px 80px -30px rgba(0, 0, 0, .6); }
.rd-invite-card img { display: block; margin: 0 auto; width: 62%; aspect-ratio: var(--ratio, 1/1); object-fit: cover; border-radius: 14px; box-shadow: 6px 6px 0 #a3246b; transform: rotate(-3deg); animation: rd-float 5s ease-in-out infinite; }
@keyframes rd-float { 50% { transform: rotate(-1deg) translateY(-8px); } }
.rd-invite-card h2 { margin: 18px 0 6px; font: 700 1.6rem/1.15 "Grandstander", "Lalezar", system-ui; }
.rd-invite-card p { margin: 0 0 18px; color: #4a5285; }
.rd-invite-card .rd-cta { display: inline-block; font-size: 1.05rem; padding: 1rem 1.8rem; }
.rd-invite-card .rd-later { display: block; margin: 12px auto 0; border: 0; background: none; color: #4a5285; font: 600 .95rem/1 inherit; cursor: pointer; text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
  .rd, .rd *, .rd-invite, .rd-invite * { animation: none !important; transition: none !important; }
}
.rd-logo { max-width: min(40%, 180px); max-height: 18cqi; object-fit: contain; margin: 0 auto 1.5cqi; display: block; }

/* 1.7.1: words on the picture (one page, words over its lower part) */
.rd-over .rd-book { grid-template-columns: 1fr; grid-template-rows: 1fr; aspect-ratio: var(--ratio); width: min(100%, calc((100dvh - 150px) * var(--ratio))); height: auto; }
.rd-over .rd-spine { display: none; }
.rd-over .rd-l { border-radius: 1cqi; grid-area: 1 / 1; }
.rd-over .rd-r { grid-area: 1 / 1; align-self: end; position: relative; z-index: 2; border-radius: 0 0 1cqi 1cqi; overflow: visible; min-height: 0; }
.rd-over .rd-r .rd-pg { position: relative; inset: auto; }
.rd-over .rd-words { background: linear-gradient(to bottom, rgba(255, 253, 247, 0), rgba(255, 253, 247, .9) 28%, rgba(255, 253, 247, .96)); padding: 9cqi 6cqi 6cqi; align-content: end; }
.rd-over .rd-text { font-size: calc(var(--fs, 1) * clamp(15px, 3.6cqi, 30px)); }
.rd-single.rd-over .rd-book { grid-template-rows: 1fr; height: auto; aspect-ratio: var(--ratio); width: min(100%, 640px, calc((100dvh - 150px) * var(--ratio))); }
.rd-single.rd-over .rd-l { border-radius: 16px; }
.rd-single.rd-over .rd-words { padding: 64px 20px 28px; overflow: visible; }

/* 1.7.2: designed pages (words already on the picture) */
.rd-baked .rd-book { grid-template-columns: 1fr; grid-template-rows: 1fr; aspect-ratio: var(--ratio); width: min(100%, calc((100dvh - 150px) * var(--ratio))); height: auto; }
.rd-baked .rd-spine, .rd-baked .rd-r { display: none; }
.rd-baked .rd-l { border-radius: 1cqi; }
.rd-single.rd-baked .rd-book { grid-template-rows: 1fr; height: auto; aspect-ratio: var(--ratio); width: min(100%, 640px, calc((100dvh - 150px) * var(--ratio))); }
.rd-single.rd-baked .rd-l { border-radius: 16px; }

/* 1.7.3: words above or below the picture */
.rd-stack .rd-book { grid-template-columns: 1fr; grid-template-rows: auto auto; aspect-ratio: auto; height: auto; width: min(100%, calc((100dvh - 150px) * var(--ratio) * .74)); }
.rd-stack .rd-spine { display: none; }
.rd-stack .rd-l { aspect-ratio: var(--ratio); border-radius: 1cqi 1cqi 0 0; }
.rd-stack .rd-r { border-radius: 0 0 1cqi 1cqi; }
.rd-stack .rd-r .rd-pg { position: relative; inset: auto; }
.rd-stack .rd-words { padding: 3.5cqi 5cqi 5cqi; align-content: center; }
.rd-stack .rd-text { font-size: calc(var(--fs, 1) * clamp(15px, 3.2cqi, 28px)); }
.rd-stack-above .rd-r { order: -1; border-radius: 1cqi 1cqi 0 0; }
.rd-stack-above .rd-l { border-radius: 0 0 1cqi 1cqi; }
.rd-single.rd-stack .rd-book { grid-template-rows: auto auto; height: auto; width: min(100%, 640px); }
.rd-single.rd-stack .rd-words { padding: 18px 20px 26px; overflow: visible; }

/* 1.7.3/1.7.4: lively books, a few drawn ornaments drifting up behind the pages */
.rd-floaties { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.rd-floaties span { position: absolute; bottom: -60px; width: var(--sz); height: var(--sz); line-height: 0; opacity: 0; will-change: transform, opacity;
  animation: rd-float var(--dur) linear var(--delay) infinite; filter: drop-shadow(0 2px 6px rgba(0,0,0,.25)); }
.rd-floaties .fl-c0 { color: #e3bf78; } .rd-floaties .fl-c1 { color: #f2b8c2; } .rd-floaties .fl-c2 { color: #fff4e8; }
@keyframes rd-float {
  0% { transform: translate(0, 0) rotate(-8deg); opacity: 0; }
  10% { opacity: .6; }
  50% { transform: translate(calc(var(--sway) * 40px), -55vh) rotate(8deg); }
  85% { opacity: .4; }
  100% { transform: translate(0, -110vh) rotate(-6deg); opacity: 0; }
}
.rd-night .rd-floaties span { opacity: .4; }
@media (prefers-reduced-motion: reduce) { .rd-floaties { display: none; } }
