/* ===== A5 book page (logical size 437 x 620, ratio 1.4188). Used by editor, preview and print. ===== */
:root{--pw:437px;--ph:620px;--fs:11px;--pfont:'Cairo',sans-serif}

.pg{
  position:relative;flex:none;width:var(--pw);height:var(--ph);overflow:hidden;border-radius:3px;
  display:flex;gap:10px;padding:12px 10px;background:var(--pgbg,linear-gradient(160deg,#E9C6F0,#F9C5D8 60%,#F7D6E0));
  font-family:var(--pfont);direction:rtl;
  -webkit-print-color-adjust:exact;print-color-adjust:exact;
}
.pg .bgart{position:absolute;inset:0;pointer-events:none;background-image:var(--pgart,none);background-size:var(--pgsize,auto)}
.pg.book{padding:34px 18px 30px}
.pg .col{position:relative;flex:1;min-width:0;display:flex;flex-direction:column;gap:3px;z-index:1}
.pg .col+.col::before{content:"";position:absolute;top:0;bottom:0;right:-6.75px;border-right:1.5px dashed #777;opacity:.85}
.pg .col>:first-child{margin-top:0}
.pg .col>*{flex:none}

/* header + folio: only drawn in book mode, but never in the editor */
.pg .hdr,.pg .folio{position:absolute;z-index:2;font-size:9px;color:#8a7f72;display:none}
.pg.book .hdr,.pg.book .folio{display:block}
.pg .hdr{top:12px;left:18px;right:18px;display:none;justify-content:space-between}
.pg.book .hdr{display:flex}
.pg .folio{bottom:10px;left:0;right:0;text-align:center;font-weight:700}

/* date chip + system line */
.d{align-self:center;background:#D8EEF5;border-radius:6px;font-size:11px;line-height:1.5;padding:4px 22px;color:#789;margin:2px 0;text-align:center}
.d.sys{background:rgba(255,255,255,.7);color:#777;font-size:10px;padding:3px 12px;max-width:92%}
.chapter{align-self:stretch;text-align:center;margin:6px 0 6px}
.chapter small{display:block;font-size:10px;font-weight:700;color:#B5832F}
.chapter b{display:block;font-family:'Amiri',serif;font-size:21px;color:#3B2A1C;line-height:1.4}
.chapter i{display:block;width:44px;height:1.5px;background:#C9A227;margin:2px auto 0}

/* bubbles */
.m{
  position:relative;display:flex;flex-wrap:wrap;align-items:flex-end;column-gap:6px;width:fit-content;max-width:90%;
  padding:3px 7px;border-radius:8px;font-size:var(--fs);line-height:calc(var(--fs) * 1.55);
  box-shadow:0 1px 1px rgba(0,0,0,.12);background:var(--bub,#fff);font-family:var(--pfont);word-break:break-word;
}
.m.right{align-self:flex-start;--bub:#DCF3C2}
.m.left{align-self:flex-end;--bub:#fff}
.m.f{margin-top:6px}
.m.right.f{border-top-right-radius:2px}
.m.left.f{border-top-left-radius:2px}
.m.right.f::after{content:"";position:absolute;top:0;right:-7px;border:7px solid transparent;border-top-color:var(--bub);border-left-color:var(--bub);border-right:0}
.m.left.f::after{content:"";position:absolute;top:0;left:-7px;border:7px solid transparent;border-top-color:var(--bub);border-right-color:var(--bub);border-left:0}
.m b{flex:0 0 100%;display:block;font-size:9px;line-height:12px;color:var(--nm,#1c4b8f);font-weight:700}
.m .tx{white-space:pre-wrap;min-width:0}
.m .tx.del{color:#8a8a8a;font-style:italic}
.m i{flex:0 0 auto;margin:0 auto 0 0;font-style:normal;font-size:8px;line-height:calc(var(--fs) * 1.55);height:calc(var(--fs) * 1.55);color:#999}
.m img{flex:0 0 100%;width:140px;height:84px;object-fit:cover;border-radius:6px;display:block;margin:2px 0 1px;background:#e8e0d8}
.m.sticker img{width:84px;height:84px;object-fit:contain;background:transparent}
.m .ph{flex:0 0 100%;width:140px;height:84px;margin:2px 0 1px;border-radius:6px;background:rgba(0,0,0,.07);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;font-size:10px;color:#6b6055;text-align:center;padding:4px;overflow:hidden}
.m .ph span{font-size:20px;line-height:1}
.m .ph em{font-style:normal;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;direction:ltr}
.m.polaroid{background:#fff;padding:5px 5px 4px;border-radius:2px;transform:rotate(-2deg);box-shadow:0 3px 8px rgba(0,0,0,.25)}
.m.polaroid::after{display:none}
.m.polaroid img{width:130px;height:96px;margin:0}
.m.polaroid .cap{flex:0 0 100%;text-align:center;font-family:'Amiri',serif;font-size:11px;color:#555;line-height:15px;padding-top:2px}

/* voice note: two rows, play + waveform, then duration and time */
.m.vo{display:block}
.vn2{display:flex;direction:ltr;align-items:center;gap:6px;height:18px}
.vn2 .pl{width:0;height:0;border-left:10px solid #7a8a80;border-top:6px solid transparent;border-bottom:6px solid transparent;margin:0 2px 0 0;flex:none}
.vn2 .wv{display:flex;align-items:center;flex:none}
.vn2 .bars{display:flex;justify-content:space-between;align-items:center;gap:2px;height:16px;position:relative;width:100px;overflow:hidden}
.vn2 u{display:block;width:2px;border-radius:1px;background:#9aa6a0;flex:none}
.vn2 .dot{position:absolute;left:0;width:9px;height:9px;border-radius:50%;background:#3b9be0;top:3.5px}
.vf{display:flex;direction:ltr;justify-content:space-between;align-items:center;height:12px}
.vf em,.vf i{font-style:normal;font-size:8px;color:#999;line-height:12px;height:12px;margin:0}
.vf i{direction:rtl}
.vf em{padding-left:17px}
.m.vo b{margin-bottom:1px}

/* edit mode affordances */
.editing .m,.editing .d{cursor:pointer;outline:1px dashed transparent}
.editing .m:hover,.editing .d:hover{outline-color:#8A5BA0}
.m.sel,.d.sel{outline:2px solid #8A5BA0 !important}
.pg.plain{background:linear-gradient(100deg,#FFFDF7,#FBF4E6);padding:0}
.pg.plain[data-kind="blank"]{background:#fff}

/* ===== foreign-language (left to right) books: the page, its two columns and the bubbles are mirrored ===== */
body[data-bdir="ltr"] .pg{direction:ltr}
body[data-bdir="ltr"] .pg .col+.col::before{right:auto;left:-6.75px;border-right:0;border-left:1.5px dashed #777}
body[data-bdir="ltr"] .m.right{align-self:flex-end}
body[data-bdir="ltr"] .m.left{align-self:flex-start}
body[data-bdir="ltr"] .m i{margin:0 0 0 auto}
body[data-bdir="ltr"] .vf i{direction:ltr}
body[data-bdir="ltr"] .spread{direction:ltr}

/* tap-to-play (editor + preview only; print.css hides none of this because print pages never receive taps) */
.vn2.on .pl{width:10px;height:12px;border:0;border-left:3px solid #3b9be0;border-right:3px solid #3b9be0;box-sizing:border-box}
.vn2 u.pd{background:#3b9be0}
.vn2{cursor:pointer}
.m img{cursor:zoom-in}
.mp-ov{position:fixed;inset:0;z-index:1000;background:rgba(10,10,10,.88);display:flex;align-items:center;justify-content:center;animation:mpin .15s ease-out}
.mp-ov .mp-media{max-width:96vw;max-height:88vh;border-radius:6px;background:#000;box-shadow:0 8px 40px rgba(0,0,0,.5)}
.mp-x{position:absolute;top:max(14px,env(safe-area-inset-top));right:14px;width:44px;height:44px;border:0;border-radius:50%;background:rgba(255,255,255,.18);color:#fff;font-size:22px;line-height:44px;cursor:pointer}
@keyframes mpin{from{opacity:0}to{opacity:1}}
