/* ============================================================
   Library reading theme — shared across all book pages
   Extends the husainalkhaldy.com "altitude" system, mirrored RTL.
   ============================================================ */
:root{
  --bg:#0a0f1e; --bg-2:#0c1224; --elev:#111a33;
  --surface:rgba(255,255,255,.028); --surface-2:rgba(255,255,255,.05);
  --line:rgba(255,255,255,.09); --line-strong:rgba(255,255,255,.16);
  --text:#eaeefb; --muted:#98a2c2; --faint:#657092;
  --accent:#e9b45c; --accent-soft:#f0c884; --ice:#84b9d8;
  --maxw:1200px; --read:74ch;
  --ease:cubic-bezier(.2,.7,.2,1);
  --serif:"Amiri", serif;
  --body:"Noto Naskh Arabic","Amiri",serif;
  --mono:"Space Mono",monospace;

  /* ---------- reader preferences (book.js writes these) ----------
     The reading column is sized from these three, not from the body's
     clamp() — `article{font-size:_rem}` keys off the 16px root, so the
     body clamp never reached the text at all. */
  --read-size:19px;      /* base; the panel steps it 16 → 24 */
  --read-measure:62ch;   /* line length */
  --read-lh:1.95;
  --read-font:var(--serif);
  --read-scale:1;        /* per-face optical correction, set with --read-font */
}
/* Faces the reader can pick. Each carries its own optical size correction so a
   step on the size slider means the same thing whichever face is chosen. */
:root[data-rfont="amiri"]{--read-font:"Amiri",serif;--read-scale:1.1;--read-lh:1.9}
:root[data-rfont="naskh"]{--read-font:"Noto Naskh Arabic","Amiri",serif;--read-scale:1;--read-lh:1.95}
:root[data-rfont="plex"] {--read-font:"IBM Plex Sans Arabic",system-ui,sans-serif;--read-scale:.95;--read-lh:1.9}
*{box-sizing:border-box;margin:0;padding:0}
html{scroll-behavior:smooth;-webkit-text-size-adjust:100%}
body{
  background:var(--bg);color:var(--text);
  font-family:var(--body);
  /* 1.05vw only cleared the 16.5px floor above a ~1570px viewport and only hit
     19px at ~1810px, so every ordinary screen got the floor. Anchor to rem so
     the curve actually runs across the range it claims. */
  font-size:clamp(16.5px,1rem + .35vw,19px);line-height:1.95;
  overflow-x:hidden;-webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
}
::selection{background:var(--accent);color:#1a1205}
a{color:inherit}

/* ---------- atmosphere ---------- */
.atmos{position:fixed;inset:0;z-index:-2;overflow:hidden;pointer-events:none}
.glow{position:absolute;left:50%;top:-14%;width:130vw;height:82vh;transform:translateX(-50%);
  background:radial-gradient(60% 60% at 50% 40%,rgba(233,180,92,.15),rgba(233,180,92,.03) 42%,transparent 70%);filter:blur(6px)}
.horizon{position:absolute;left:50%;bottom:-32vh;width:150vw;height:70vh;transform:translateX(-50%);
  background:radial-gradient(50% 60% at 50% 100%,rgba(132,185,216,.10),transparent 70%)}
.contours{position:absolute;inset:0;color:var(--accent);opacity:.09;mix-blend-mode:screen}
.contours svg{position:absolute;left:-8vw;top:5vh;width:min(66vw,860px);height:auto;animation:drift 36s var(--ease) infinite alternate}
@keyframes drift{from{transform:translateY(0) rotate(0)}to{transform:translateY(26px) rotate(2deg)}}
.grain{position:fixed;inset:0;z-index:-1;pointer-events:none;opacity:.05;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")}

/* ---------- reading progress ---------- */
.progress{position:fixed;top:0;left:0;height:2px;width:0;z-index:60;
  background:linear-gradient(90deg,var(--accent),var(--accent-soft));box-shadow:0 0 12px rgba(233,180,92,.5)}

/* ---------- header ---------- */
header{position:fixed;top:0;left:0;right:0;z-index:50;transition:background .4s,backdrop-filter .4s,border-color .4s;border-bottom:1px solid transparent}
header.scrolled{background:rgba(10,15,30,.74);backdrop-filter:blur(14px) saturate(120%);border-color:var(--line)}
nav{max-width:var(--maxw);margin:0 auto;padding:15px clamp(18px,4vw,48px);display:flex;align-items:center;justify-content:space-between;gap:1em}
.mark{display:flex;align-items:center;gap:.6em;font-family:var(--serif);font-weight:700;font-size:1.12rem;color:var(--text);text-decoration:none;white-space:nowrap}
.mark svg{width:26px;height:26px;flex:none}
.navlinks{display:flex;gap:1.7em;align-items:center;font-family:var(--body)}
.navlinks a{color:var(--muted);text-decoration:none;font-size:.94rem;position:relative;transition:color .25s}
.navlinks a::after{content:"";position:absolute;right:0;bottom:-5px;width:0;height:1px;background:var(--accent);transition:width .3s var(--ease)}
.navlinks a:hover{color:var(--text)}
.navlinks a:hover::after{width:100%}
.navlinks .cta{color:var(--accent)}
.toc-toggle{display:none;background:none;border:1px solid var(--line-strong);color:var(--text);border-radius:100px;padding:.5em 1.1em;font-family:var(--body);font-size:.9rem;cursor:pointer}
@media(max-width:900px){.navlinks a:not(.cta){display:none}.toc-toggle{display:inline-block}}

/* ---------- shell ---------- */
.wrap{max-width:var(--maxw);margin:0 auto;padding:0 clamp(18px,4vw,48px)}
.eyebrow{font-family:var(--mono);font-size:.72rem;letter-spacing:.22em;text-transform:uppercase;color:var(--accent);display:inline-flex;align-items:center;gap:.7em;direction:ltr}
.eyebrow::before{content:"";width:24px;height:1px;background:var(--accent);opacity:.6}

/* ---------- book layout ---------- */
.layout{display:grid;grid-template-columns:minmax(0,1fr) 300px;gap:clamp(2em,4vw,4.4em);
  max-width:var(--maxw);margin:0 auto;padding:130px clamp(18px,4vw,48px) 40px;align-items:start}
@media(max-width:900px){.layout{grid-template-columns:1fr;padding-top:104px}}

/* part banner */
.part-banner{margin-bottom:2.6em;padding-bottom:1.8em;border-bottom:1px solid var(--line)}
.part-kicker{font-family:var(--mono);font-size:.74rem;letter-spacing:.2em;color:var(--faint);direction:ltr;margin-bottom:1em}
.part-kicker b{color:var(--ice);font-weight:400}
.part-title{font-family:var(--serif);font-weight:700;font-size:clamp(2.4rem,6vw,4rem);line-height:1.1;color:#f5f7fe;letter-spacing:0}
.part-title em{color:var(--accent);font-style:normal}
.part-sub{color:var(--muted);font-size:1.05rem;margin-top:.7em;max-width:52ch}

/* executive summary (موجز) — sits after the banner, before the essay body */
.lede{max-width:var(--read-measure);margin:0 0 2.4em;padding:1.2em 1.4em;border:1px solid var(--line);
  border-inline-start:3px solid var(--accent);border-radius:14px;background:var(--surface)}
.lede-k{display:block;font-family:var(--mono);font-size:.7rem;letter-spacing:.12em;text-transform:uppercase;
  color:var(--accent);opacity:.9;margin-bottom:.55em}
.lede p{margin:0;font-family:var(--serif);font-size:1.02rem;line-height:1.95;color:var(--text)}

/* article body */
article{max-width:var(--read-measure);
  font-family:var(--read-font);
  font-size:calc(var(--read-size) * var(--read-scale));
  line-height:var(--read-lh)}
article h1{font-family:var(--serif);font-weight:700;font-size:clamp(1.9rem,4vw,2.7rem);line-height:1.25;
  color:#f3f6ff;margin:2.4em 0 .1em;padding-top:.5em;scroll-margin-top:120px;position:relative}
article h1::before{content:"";position:absolute;top:0;right:0;width:56px;height:2px;background:var(--accent);opacity:.8}
article h2{font-family:var(--serif);font-weight:700;font-size:clamp(1.4rem,2.7vw,1.85rem);line-height:1.35;
  color:var(--accent-soft);margin:1.9em 0 .5em;scroll-margin-top:120px}
article h3{font-family:var(--read-font);font-weight:700;font-size:1.18em;color:var(--ice);margin:1.5em 0 .4em;scroll-margin-top:120px}
article h4{font-family:var(--read-font);font-weight:700;font-size:1.04em;color:var(--text);margin:1.3em 0 .3em}
/* Not justified: browsers justify Arabic by stretching the word gaps only — they
   don't elongate with kashida — so `justify` opens rivers down the column. */
article p{margin:0 0 1.15em;color:#dce2f5;text-align:start}
article p b,article strong{color:#fff;font-weight:700}
article em{color:var(--accent-soft);font-style:normal}
article a{color:var(--ice);text-decoration:none;border-bottom:1px solid rgba(132,185,216,.35);transition:color .2s,border-color .2s}
article a:hover{color:var(--accent);border-color:var(--accent)}
article ul,article ol{margin:0 0 1.2em;padding-inline-start:1.4em;color:#dce2f5}
article li{margin:.35em 0}
article ul li::marker{color:var(--accent)}
article blockquote{margin:1.3em 0;padding:1em 1.3em;border-inline-start:2px solid var(--accent);
  background:linear-gradient(90deg,rgba(233,180,92,.05),transparent);border-radius:0 10px 10px 0;color:var(--muted)}
article blockquote p:last-child{margin-bottom:0}
article table{width:100%;border-collapse:collapse;margin:1.4em 0;font-size:.94rem}
article th,article td{border:1px solid var(--line);padding:.6em .8em;text-align:right}
article th{background:var(--surface-2);color:var(--text);font-weight:700}
article hr{border:none;border-top:1px solid var(--line);margin:2em 0}
/* Latin runs stay LTR & mono-ish for legibility */
article span[dir="ltr"],article :lang(en){direction:ltr;unicode-bidi:isolate}

/* ---------- sticky TOC ---------- */
.toc{position:sticky;top:110px;max-height:calc(100vh - 140px);overflow-y:auto;
  padding-inline-start:1.3em;border-inline-start:1px solid var(--line);font-family:var(--body)}
.toc h4{font-family:var(--mono);font-size:.7rem;letter-spacing:.18em;text-transform:uppercase;color:var(--faint);margin-bottom:1.1em;direction:ltr}
/* The rule above is sized for the Latin "Contents". Letter-spacing pulls Arabic
   script apart at the cursive joins, so an Arabic heading opts out of it. */
.toc h4.ar{font-family:var(--body);font-size:.82rem;letter-spacing:0;text-transform:none;direction:rtl}
.toc ul{list-style:none}
.toc a{display:block;color:var(--muted);text-decoration:none;font-size:.9rem;line-height:1.45;padding:.32em 0;transition:color .2s}
.toc a:hover{color:var(--text)}
.toc a.h2{padding-inline-start:1em;font-size:.84rem;color:var(--faint)}
.toc a.active{color:var(--accent)}
.toc li.chap{margin-top:.5em}
.toc::-webkit-scrollbar{width:5px}
.toc::-webkit-scrollbar-thumb{background:var(--line-strong);border-radius:4px}
@media(max-width:900px){
  .toc{position:fixed;inset:0 0 0 auto;width:min(84vw,340px);top:0;max-height:100vh;z-index:70;
    background:var(--bg-2);border-inline-start:1px solid var(--line);padding:90px 1.4em 2em;
    /* the drawer is pinned to the right edge (inset right:0), so it hides to the
       RIGHT: +105%. A negative value slides it into the page, over the text. */
    transform:translateX(105%);transition:transform .4s var(--ease);box-shadow:0 0 60px rgba(0,0,0,.5)}
  :root[dir] .toc{transform:translateX(105%)}
  :root[dir] .toc.open,.toc.open{transform:none}
}

/* scrim for mobile toc */
.scrim{position:fixed;inset:0;background:rgba(4,7,16,.6);opacity:0;visibility:hidden;transition:.3s;z-index:65}
.scrim.show{opacity:1;visibility:visible}

/* ---------- part navigation footer ---------- */
.partnav{display:flex;justify-content:space-between;gap:1em;margin-top:3.5em;padding-top:2em;border-top:1px solid var(--line)}
.partnav a{display:flex;flex-direction:column;gap:.3em;text-decoration:none;color:var(--muted);
  border:1px solid var(--line);border-radius:14px;padding:1em 1.3em;transition:border-color .3s,transform .3s,color .3s;max-width:46%}
.partnav a:hover{border-color:var(--accent);color:var(--text);transform:translateY(-3px)}
.partnav .dir{font-family:var(--mono);font-size:.68rem;letter-spacing:.14em;color:var(--faint);direction:ltr}
.partnav .nm{font-family:var(--serif);font-weight:700;font-size:1.05rem}
.partnav a.next{text-align:start;margin-inline-start:auto}
.partnav a.prev{text-align:start}
.partnav .disabled{visibility:hidden}

/* pill part switcher */
.pills{display:flex;flex-wrap:wrap;gap:.5em;margin-top:1.4em}
.pills a{font-family:var(--mono);font-size:.8rem;color:var(--muted);text-decoration:none;border:1px solid var(--line);
  border-radius:100px;padding:.4em 1em;transition:.25s;direction:ltr}
.pills a:hover{border-color:var(--line-strong);color:var(--text)}
.pills a.cur{background:var(--accent);color:#1a1205;border-color:var(--accent)}

/* ---------- footer ---------- */
footer{border-top:1px solid var(--line);padding:2.4em 0;margin-top:2em}
.foot{display:flex;justify-content:space-between;align-items:center;gap:1.2em;flex-wrap:wrap;color:var(--faint);font-size:.86rem}
.foot a{color:var(--muted);text-decoration:none}
.foot a:hover{color:var(--accent)}
.foot .mono{font-family:var(--mono);letter-spacing:.05em;direction:ltr}

@media(prefers-reduced-motion:reduce){.contours svg{animation:none}*{scroll-behavior:auto}}

/* ---------- mobile: touch polish + site links inside the TOC drawer ---------- */
body{-webkit-tap-highlight-color:transparent}
.bookcard:active,.pcard:active,.partnav a:active{transform:scale(.99);border-color:var(--line-strong)}
.wrap{padding-left:max(clamp(18px,4vw,48px),env(safe-area-inset-left));padding-right:max(clamp(18px,4vw,48px),env(safe-area-inset-right))}
.toc-sitenav{display:none}
@media(max-width:900px){
  .layout{padding-left:max(clamp(18px,4vw,48px),env(safe-area-inset-left));padding-right:max(clamp(18px,4vw,48px),env(safe-area-inset-right))}
  .toc-sitenav{display:flex;flex-wrap:wrap;gap:.6em 1.3em;padding-bottom:1.1em;margin-bottom:1.2em;border-bottom:1px solid var(--line)}
  .toc-sitenav a{color:var(--muted);text-decoration:none;font-family:var(--body);font-size:1.05rem;padding:.15em 0;transition:color .2s}
  .toc-sitenav a:active{color:var(--accent)}
}

/* ---------- Apple-style full-screen menu (cover / landing pages only) ---------- */
.menu-btn{display:none;position:relative;width:44px;height:44px;padding:0;border:0;background:none;cursor:pointer;z-index:60;flex:none;-webkit-tap-highlight-color:transparent}
.menu-btn span{position:absolute;left:11px;right:11px;height:2px;border-radius:2px;background:var(--text);transition:transform .35s var(--ease),opacity .2s var(--ease)}
.menu-btn span:nth-child(1){top:16px}.menu-btn span:nth-child(2){top:22px}.menu-btn span:nth-child(3){top:28px}
body.menu-open .menu-btn span:nth-child(1){transform:translateY(6px) rotate(45deg)}
body.menu-open .menu-btn span:nth-child(2){opacity:0}
body.menu-open .menu-btn span:nth-child(3){transform:translateY(-6px) rotate(-45deg)}
.mobile-menu{position:fixed;inset:0;z-index:55;display:flex;flex-direction:column;justify-content:center;
  padding:calc(env(safe-area-inset-top) + 92px) clamp(28px,8vw,56px) calc(env(safe-area-inset-bottom) + 40px);
  background:rgba(10,15,30,.88);backdrop-filter:blur(22px) saturate(120%);-webkit-backdrop-filter:blur(22px) saturate(120%);
  opacity:0;visibility:hidden;transition:opacity .42s var(--ease),visibility .42s var(--ease)}
body.menu-open .mobile-menu{opacity:1;visibility:visible}
body.menu-open{overflow:hidden}
body.menu-open header{z-index:60}
.mm-inner{display:flex;flex-direction:column;gap:.1em;text-align:right}
.mobile-menu a{font-family:var(--serif);font-weight:700;font-size:clamp(2rem,9vw,2.8rem);color:var(--text);text-decoration:none;padding:.26em 0;line-height:1.15;
  opacity:0;transform:translateY(16px);transition:opacity .5s var(--ease),transform .5s var(--ease),color .25s}
.mobile-menu a:active{color:var(--accent)}
body.menu-open .mobile-menu a{opacity:1;transform:none}
body.menu-open .mobile-menu a:nth-child(1){transition-delay:.05s}
body.menu-open .mobile-menu a:nth-child(2){transition-delay:.11s}
body.menu-open .mobile-menu a:nth-child(3){transition-delay:.17s}
@media(min-width:901px){.mobile-menu{display:none}}
@media(max-width:900px){.menu-btn{display:block}}
@media(prefers-reduced-motion:reduce){.mobile-menu,.mobile-menu a,.menu-btn span{transition:none}.mobile-menu a{opacity:1;transform:none}}

/* ============================================================
   /books library index + book cover
   ============================================================ */
.lib{max-width:960px;margin:0 auto;padding:150px clamp(18px,5vw,48px) 90px}
.lib .eyebrow{margin-bottom:1.4em}
.lib h1{font-family:var(--serif);font-weight:700;font-size:clamp(2.6rem,8vw,5rem);line-height:1.05;color:#f5f7fe;margin-bottom:.35em}
.lib .lede{color:var(--muted);font-size:1.15rem;max-width:54ch;line-height:1.7;margin-bottom:3.2em}
.booklist{display:grid;gap:20px}
.bookcard{display:grid;grid-template-columns:auto 1fr auto;gap:1.6em;align-items:center;
  border:1px solid var(--line);border-radius:20px;padding:1.8em 2em;background:var(--surface);
  text-decoration:none;color:inherit;overflow:hidden;position:relative;transition:transform .4s var(--ease),border-color .4s,background .4s}
.bookcard:hover{transform:translateY(-4px);border-color:var(--line-strong);background:var(--surface-2)}
.bookcard .spine{width:52px;height:74px;border-radius:5px;flex:none;position:relative;
  background:linear-gradient(160deg,#14203f,#0b1226);border:1px solid var(--line-strong);box-shadow:inset 0 0 20px rgba(0,0,0,.4)}
.bookcard .spine::before{content:"";position:absolute;inset:0 auto 0 8px;width:2px;background:var(--accent);opacity:.7}
.bookcard .bt{font-family:var(--serif);font-weight:700;font-size:1.5rem;color:#f3f6ff;line-height:1.25}
.bookcard .bmeta{color:var(--muted);font-size:.95rem;margin-top:.35em}
.bookcard .arw{color:var(--faint);transition:.3s}
.bookcard:hover .arw{color:var(--accent);transform:translateX(-6px)}
.bookcard .arw svg{width:22px;height:22px}
.lib-note{margin-top:2.6em;font-family:var(--mono);font-size:.8rem;color:var(--faint);letter-spacing:.04em;direction:ltr}

/* book cover */
.cover{max-width:900px;margin:0 auto;padding:150px clamp(18px,5vw,48px) 70px;text-align:center}
.cover .eyebrow{justify-content:center;margin-bottom:1.6em}
.cover h1{font-family:var(--serif);font-weight:700;font-size:clamp(2.7rem,8vw,5.2rem);line-height:1.08;color:#f5f7fe}
.cover h1 em{color:var(--accent);font-style:normal}
.cover .author{font-family:var(--serif);font-size:1.5rem;color:var(--muted);margin-top:.5em}
.cover .blurb{color:var(--muted);font-size:1.1rem;line-height:1.75;max-width:56ch;margin:1.8em auto 0}
.cover .startbtn{display:inline-flex;align-items:center;gap:.6em;margin-top:2.4em;background:var(--accent);color:#1a1205;
  border-radius:100px;padding:.9em 1.7em;font-family:var(--body);font-weight:700;text-decoration:none;transition:.3s}
.cover .startbtn:hover{background:var(--accent-soft);transform:translateY(-2px)}
.parts-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:16px;margin-top:3.4em;text-align:start}
.pcard{border:1px solid var(--line);border-radius:16px;padding:1.4em 1.5em;text-decoration:none;color:inherit;
  background:var(--surface);transition:transform .35s var(--ease),border-color .35s,background .35s;position:relative;overflow:hidden}
.pcard:hover{transform:translateY(-4px);border-color:var(--line-strong);background:var(--surface-2)}
.pcard .pn{font-family:var(--mono);font-size:.72rem;letter-spacing:.16em;color:var(--accent);direction:ltr}
.pcard .ph{font-family:var(--serif);font-weight:700;font-size:1.3rem;color:#f3f6ff;margin:.5em 0 .3em}
.pcard .pd{color:var(--muted);font-size:.9rem;line-height:1.55}

/* ============================================================
   LIGHT THEME — warm paper (sepia)
   Follows the device by default (prefers-color-scheme); the floating
   toggle (book.js) sets data-theme on <html> to override + persist.
   ============================================================ */
:root[data-theme="light"]{
  --bg:#f4ecdb; --bg-2:#efe5d1; --elev:#e9ddc4;
  --surface:rgba(74,52,24,.04); --surface-2:rgba(74,52,24,.07);
  --line:rgba(74,52,24,.16); --line-strong:rgba(74,52,24,.28);
  --text:#2b2317; --muted:#5e5240; --faint:#8b7d62;
  --accent:#a5701a; --accent-soft:#8c5d11; --ice:#3d6a83;
}
@media(prefers-color-scheme:light){
  :root:not([data-theme="dark"]){
    --bg:#f4ecdb; --bg-2:#efe5d1; --elev:#e9ddc4;
    --surface:rgba(74,52,24,.04); --surface-2:rgba(74,52,24,.07);
    --line:rgba(74,52,24,.16); --line-strong:rgba(74,52,24,.28);
    --text:#2b2317; --muted:#5e5240; --faint:#8b7d62;
    --accent:#a5701a; --accent-soft:#8c5d11; --ice:#3d6a83;
  }
}
/* hardcoded bright text → warm ink on paper (both override + device-follow) */
:root[data-theme="light"] .part-title,
:root[data-theme="light"] article h1,
:root[data-theme="light"] .lib h1,
:root[data-theme="light"] .bookcard .bt,
:root[data-theme="light"] .cover h1,
:root[data-theme="light"] .pcard .ph{color:#241c10}
:root[data-theme="light"] article p,
:root[data-theme="light"] article li,
:root[data-theme="light"] article ul,
:root[data-theme="light"] article ol{color:#342a1b}
:root[data-theme="light"] article p b,
:root[data-theme="light"] article strong{color:#1b140a}
:root[data-theme="light"] .glow{opacity:.55}
:root[data-theme="light"] .horizon{opacity:.5}
:root[data-theme="light"] .contours{mix-blend-mode:multiply;opacity:.06}
/* chrome that hardcodes a dark navy fill → warm paper in light mode */
:root[data-theme="light"] header.scrolled{background:rgba(244,236,219,.82)}
:root[data-theme="light"] .mobile-menu{background:rgba(244,236,219,.93)}
@media(prefers-color-scheme:light){
  :root:not([data-theme="dark"]) .part-title,
  :root:not([data-theme="dark"]) article h1,
  :root:not([data-theme="dark"]) .lib h1,
  :root:not([data-theme="dark"]) .bookcard .bt,
  :root:not([data-theme="dark"]) .cover h1,
  :root:not([data-theme="dark"]) .pcard .ph{color:#241c10}
  :root:not([data-theme="dark"]) article p,
  :root:not([data-theme="dark"]) article li,
  :root:not([data-theme="dark"]) article ul,
  :root:not([data-theme="dark"]) article ol{color:#342a1b}
  :root:not([data-theme="dark"]) article p b,
  :root:not([data-theme="dark"]) article strong{color:#1b140a}
  :root:not([data-theme="dark"]) .glow{opacity:.55}
  :root:not([data-theme="dark"]) .horizon{opacity:.5}
  :root:not([data-theme="dark"]) .contours{mix-blend-mode:multiply;opacity:.06}
  :root:not([data-theme="dark"]) header.scrolled{background:rgba(244,236,219,.82)}
  :root:not([data-theme="dark"]) .mobile-menu{background:rgba(244,236,219,.93)}
}

/* ============================================================
   NIGHT THEME — true black, for OLED phones read in the dark.
   ============================================================ */
:root[data-theme="black"]{
  --bg:#000; --bg-2:#08080a; --elev:#131317;
  --surface:rgba(255,255,255,.032); --surface-2:rgba(255,255,255,.06);
  --line:rgba(255,255,255,.10); --line-strong:rgba(255,255,255,.19);
  --text:#e6e6ea; --muted:#95959e; --faint:#63636c;
  --accent:#e0ac57; --accent-soft:#eec27f; --ice:#8ab6d0;
}
:root[data-theme="black"] .glow,
:root[data-theme="black"] .horizon{opacity:.35}
:root[data-theme="black"] .contours{opacity:.05}
:root[data-theme="black"] .grain{opacity:.03}
:root[data-theme="black"] header.scrolled{background:rgba(0,0,0,.8)}
:root[data-theme="black"] .mobile-menu{background:rgba(0,0,0,.92)}
/* soften the hardcoded near-whites — they glare on a pure-black panel at night */
:root[data-theme="black"] article p,
:root[data-theme="black"] article li,
:root[data-theme="black"] article ul,
:root[data-theme="black"] article ol{color:#c9c9d2}
:root[data-theme="black"] article h1,
:root[data-theme="black"] .part-title,
:root[data-theme="black"] .essay h2,
:root[data-theme="black"] .lib h1,
:root[data-theme="black"] .cover h1,
:root[data-theme="black"] .bookcard .bt,
:root[data-theme="black"] .pcard .ph{color:#ededf2}
:root[data-theme="black"] article p b,
:root[data-theme="black"] article strong{color:#fff}

/* ============================================================
   BLACK & WHITE — maximum-contrast reading: pure black on pure
   white, no tint and no atmosphere. Placed after the light and
   black blocks so it wins on source order when the device is light.
   ============================================================ */
:root[data-theme="bw"]{
  --bg:#fff; --bg-2:#fff; --elev:#f2f2f2;
  --surface:rgba(0,0,0,.05); --surface-2:rgba(0,0,0,.09);
  --line:rgba(0,0,0,.28); --line-strong:rgba(0,0,0,.46);
  --text:#000; --muted:#2b2b2b; --faint:#4b4b4b;
  --accent:#000; --accent-soft:#000; --ice:#000;
}
:root[data-theme="bw"] .glow,
:root[data-theme="bw"] .horizon,
:root[data-theme="bw"] .contours,
:root[data-theme="bw"] .grain{opacity:0}
:root[data-theme="bw"] header.scrolled{background:rgba(255,255,255,.9)}
:root[data-theme="bw"] .mobile-menu{background:rgba(255,255,255,.96)}
:root[data-theme="bw"] .part-title,
:root[data-theme="bw"] article h1,
:root[data-theme="bw"] .essay h2,
:root[data-theme="bw"] .lib h1,
:root[data-theme="bw"] .cover h1,
:root[data-theme="bw"] .cover-title,
:root[data-theme="bw"] .bookcard .bt,
:root[data-theme="bw"] .pcard .ph{color:#000}
:root[data-theme="bw"] article p,
:root[data-theme="bw"] article li,
:root[data-theme="bw"] article ul,
:root[data-theme="bw"] article ol{color:#000}
:root[data-theme="bw"] article p b,
:root[data-theme="bw"] article strong{color:#000}
:root[data-theme="bw"] article a{border-bottom-color:rgba(0,0,0,.45)}
:root[data-theme="bw"] ::selection{background:#000;color:#fff}
/* anything filled with --accent (black here) needs white ink on top: the
   picker's pressed state, the "start reading" button, and the nav pills */
:root[data-theme="bw"] .rp-seg button[aria-pressed="true"],
:root[data-theme="bw"] .startbtn,
:root[data-theme="bw"] .cover .startbtn,
:root[data-theme="bw"] .pills a.cur{color:#fff}

/* ============================================================
   READER CONTROLS  (injected by book.js)
   Phone-first: the panel is a bottom sheet within thumb reach; from 700px up
   it becomes a card floating above the launcher.
   ============================================================ */
.theme-toggle,.reader-fab{position:fixed;z-index:45;bottom:calc(env(safe-area-inset-bottom) + 18px);inset-inline-end:18px;
  width:48px;height:48px;border-radius:50%;display:flex;align-items:center;justify-content:center;
  background:var(--surface-2);border:1px solid var(--line-strong);color:var(--text);cursor:pointer;
  backdrop-filter:blur(10px) saturate(120%);-webkit-backdrop-filter:blur(10px) saturate(120%);
  box-shadow:0 6px 24px rgba(0,0,0,.18);-webkit-tap-highlight-color:transparent;
  transition:border-color .25s,color .25s,transform .18s}
.theme-toggle:hover,.reader-fab:hover{border-color:var(--accent);color:var(--accent)}
.theme-toggle:active,.reader-fab:active{transform:scale(.9)}
.theme-toggle svg,.reader-fab svg{width:21px;height:21px;display:block}
body.rp-open .reader-fab{opacity:0;pointer-events:none}

.reader-scrim{position:fixed;inset:0;z-index:78;background:rgba(4,7,16,.55);
  opacity:0;visibility:hidden;transition:opacity .3s var(--ease),visibility .3s var(--ease)}
body.rp-open .reader-scrim{opacity:1;visibility:visible}

.reader-panel{position:fixed;z-index:80;
  inset-inline:0;bottom:0;
  background:var(--bg-2);border-top:1px solid var(--line-strong);
  border-radius:20px 20px 0 0;box-shadow:0 -20px 60px rgba(0,0,0,.45);
  padding:.6em clamp(18px,5vw,26px) calc(env(safe-area-inset-bottom) + 22px);
  transform:translateY(101%);transition:transform .4s var(--ease);
  max-height:88vh;overflow-y:auto;overscroll-behavior:contain}
body.rp-open .reader-panel{transform:none}
/* grab handle — reads as a sheet you can dismiss */
.reader-panel::before{content:"";display:block;width:38px;height:4px;border-radius:99px;
  background:var(--line-strong);margin:.5em auto 1.1em}

.rp-head{display:flex;align-items:center;justify-content:space-between;gap:1em;margin-bottom:.4em}
.rp-title{font-family:var(--mono);font-size:.68rem;letter-spacing:.18em;text-transform:uppercase;color:var(--accent);direction:ltr}
/* letter-spacing pulls Arabic letters apart at the joins — the mono eyebrow
   treatment is Latin-only. Arabic gets the text face at its natural spacing. */
[dir="rtl"] .rp-title{font-family:var(--body);font-size:.95rem;letter-spacing:0;text-transform:none;direction:rtl;font-weight:700}
.rp-close{width:40px;height:40px;flex:none;display:flex;align-items:center;justify-content:center;
  background:none;border:0;color:var(--faint);cursor:pointer;border-radius:50%;font-size:1.5rem;line-height:1;
  -webkit-tap-highlight-color:transparent;transition:color .2s,background .2s}
.rp-close:hover{color:var(--text);background:var(--surface-2)}

.rp-row{display:flex;align-items:center;justify-content:space-between;gap:1em;
  padding:.85em 0;border-top:1px solid var(--line)}
.rp-label{font-family:var(--body);font-size:.95rem;color:var(--muted);white-space:nowrap}

/* segmented control — every target is ≥44px tall for thumbs */
.rp-seg{display:flex;gap:6px;flex:none}
/* the A− / A+ stepper stays LTR even on Arabic pages: minus-left, plus-right is
   the convention readers already have, and it isn't running text. */
.rp-seg.rp-size{direction:ltr}
.rp-seg button{min-width:46px;height:44px;padding:0 .85em;
  display:flex;align-items:center;justify-content:center;gap:.3em;
  background:var(--surface);border:1px solid var(--line);border-radius:12px;
  color:var(--muted);font-family:var(--body);font-size:.92rem;cursor:pointer;
  -webkit-tap-highlight-color:transparent;
  transition:border-color .2s,color .2s,background .2s}
.rp-seg button:hover{border-color:var(--line-strong);color:var(--text)}
.rp-seg button[aria-pressed="true"]{background:var(--accent);border-color:var(--accent);color:#1a1205;font-weight:700}
.rp-seg button:disabled{opacity:.35;cursor:default}
.rp-seg .rp-val{min-width:44px;height:44px;display:flex;align-items:center;justify-content:center;
  font-family:var(--mono);font-size:.85rem;color:var(--text);direction:ltr}
/* each face previews itself */
.rp-seg button[data-font="amiri"]{font-family:"Amiri",serif}
.rp-seg button[data-font="naskh"]{font-family:"Noto Naskh Arabic",serif}
.rp-seg button[data-font="plex"]{font-family:"IBM Plex Sans Arabic",system-ui,sans-serif}
/* theme swatches */
.rp-seg button[data-theme]{gap:.45em}
.rp-seg button[data-theme] i{width:13px;height:13px;border-radius:50%;flex:none;
  border:1px solid rgba(128,128,128,.45)}
.rp-seg button[data-theme="light"] i{background:#f4ecdb}
.rp-seg button[data-theme="dark"] i{background:#0a0f1e}
.rp-seg button[data-theme="black"] i{background:#000}
.rp-seg button[data-theme="bw"] i{background:linear-gradient(135deg,#fff 0 50%,#000 50% 100%)}
/* four themes now — let the row wrap rather than overflow the panel */
.rp-seg[data-group="theme"]{flex-wrap:wrap;justify-content:flex-end}

.rp-reset{width:100%;margin-top:1em;height:46px;background:none;border:1px dashed var(--line-strong);
  border-radius:12px;color:var(--faint);font-family:var(--body);font-size:.9rem;cursor:pointer;
  -webkit-tap-highlight-color:transparent;transition:color .2s,border-color .2s}
.rp-reset:hover{color:var(--accent);border-color:var(--accent)}

/* the font row wraps on narrow phones rather than shrinking below 44px */
@media(max-width:420px){
  .rp-row{flex-wrap:wrap;gap:.6em}
  .rp-seg{width:100%}
  .rp-seg button{flex:1;min-width:0}
  .rp-seg .rp-val{flex:0 0 44px}
}
/* desktop / tablet: a card that hangs above the launcher instead of a sheet */
@media(min-width:700px){
  .reader-panel{inset-inline:auto 18px;bottom:78px;width:360px;border-radius:20px;
    border:1px solid var(--line-strong);transform:translateY(12px) scale(.97);
    opacity:0;visibility:hidden;box-shadow:0 24px 70px rgba(0,0,0,.4);
    transition:opacity .28s var(--ease),transform .28s var(--ease),visibility .28s}
  body.rp-open .reader-panel{opacity:1;visibility:visible;transform:none}
  .reader-panel::before{display:none}
  .reader-scrim{background:transparent}
  body.rp-open .reader-fab{opacity:1;pointer-events:auto;border-color:var(--accent);color:var(--accent)}
}

/* ---------- reading time (injected into the part banner) ---------- */
.readmeta{display:flex;align-items:center;gap:.6em;margin-top:1.1em;
  font-family:var(--mono);font-size:.72rem;letter-spacing:.12em;color:var(--faint);direction:ltr}
.readmeta .dot{width:3px;height:3px;border-radius:50%;background:var(--faint);opacity:.7}
:root[dir="rtl"] .readmeta,[dir="rtl"] .readmeta{direction:rtl;font-family:var(--body);
  font-size:.85rem;letter-spacing:0}

/* ---------- "pick up where you left off" chip ---------- */
.resume-chip{position:fixed;z-index:46;bottom:calc(env(safe-area-inset-bottom) + 18px);
  inset-inline-end:78px;inset-inline-start:18px;max-width:min(420px,calc(100vw - 96px));
  display:flex;align-items:center;gap:.7em;height:48px;padding:0 1.1em;
  background:var(--elev);border:1px solid var(--line-strong);border-radius:99px;
  color:var(--text);font-family:var(--body);font-size:.92rem;cursor:pointer;text-align:start;
  box-shadow:0 10px 34px rgba(0,0,0,.32);-webkit-tap-highlight-color:transparent;
  transform:translateY(14px);opacity:0;transition:opacity .4s var(--ease),transform .4s var(--ease);
  overflow:hidden;white-space:nowrap}
.resume-chip.show{opacity:1;transform:none}
.resume-chip b{color:var(--accent);font-weight:700;font-family:var(--mono);font-size:.85rem;direction:ltr}
[dir="rtl"] .resume-chip b{font-family:var(--body);font-size:.95rem;direction:rtl}
.resume-chip svg{width:17px;height:17px;flex:none;color:var(--accent)}
.resume-chip .rc-x{margin-inline-start:auto;padding-inline-start:.5em;color:var(--faint);font-size:1.2rem;line-height:1}
@media(min-width:700px){.resume-chip{inset-inline-start:auto;max-width:none}}
@media print{.theme-toggle,.reader-fab,.reader-panel,.reader-scrim,.resume-chip{display:none}}

/* ── Tablets (901–1200px): iPad Pro portrait, iPad landscape, small laptops ──
   The 300px TOC rail plus a 4vw gap squeezed the reading column down to ~586px
   at 1024px — narrower than the ~682px a 768px iPad gets in single-column mode.
   The larger tablet was reading worse than the smaller one. Narrow the rail and
   the gutters instead, so the text keeps its full measure. */
@media(min-width:901px) and (max-width:1200px){
  .layout{
    grid-template-columns:minmax(0,1fr) 224px;
    gap:2.2em;
    padding-top:112px;
    padding-inline:clamp(18px,3vw,34px);
  }
  .toc{top:96px;font-size:.92rem;padding-inline-start:1.05em}
  .toc h4{margin-bottom:.9em}
  .parts-grid{grid-template-columns:repeat(auto-fill,minmax(210px,1fr))}
}

/* Coarse pointers (touch tablets): give tap targets room and stop hover styles
   from sticking after a tap. */
@media(hover:none) and (pointer:coarse) and (min-width:901px){
  .toc a{padding-block:.34em}
  .partnav a{padding:1.1em 1.4em}
}

/* Essays nest h1.part-title > h2 > h3. Carry the old visual weights across so a
   correct outline doesn't cost the section rules and colours. */
.essay h2{font-family:var(--serif);font-weight:700;font-size:clamp(1.9rem,4vw,2.7rem);line-height:1.25;
  color:#f3f6ff;margin:2.4em 0 .1em;padding-top:.5em;scroll-margin-top:120px;position:relative}
.essay h2::before{content:"";position:absolute;top:0;right:0;width:56px;height:2px;background:var(--accent);opacity:.8}
.essay h3{font-family:var(--serif);font-weight:700;font-size:clamp(1.4rem,2.7vw,1.85rem);line-height:1.35;
  color:var(--accent-soft);margin:1.9em 0 .5em;scroll-margin-top:120px}
.essay h4{font-family:var(--body);font-weight:700;font-size:1.18rem;color:var(--ice);margin:1.5em 0 .4em;scroll-margin-top:120px}
/* .essay h2 hardcodes bright ink like article h1 / .part-title do, so it needs the
   same warm-ink treatment on paper — h3 and h4 above ride vars and flip on their own. */
:root[data-theme="light"] .essay h2{color:#241c10}
@media(prefers-color-scheme:light){
  :root:not([data-theme="dark"]) .essay h2{color:#241c10}
}

/* ---------- AI disclosure note ----------
   Bilingual (ar + en) card shown at the head of every book and essay index. */
.ai-note{border:1px solid var(--line-strong);border-radius:16px;
  padding:1.25em 1.5em;margin:0 0 2.4em;background:rgba(255,255,255,.025);
  position:relative;overflow:hidden}
.ai-note::before{content:"";position:absolute;inset-inline-start:0;top:0;bottom:0;
  width:3px;background:var(--accent);opacity:.65}
.ai-note .ai-h{display:flex;align-items:center;gap:.6em;flex-wrap:wrap;
  font-family:var(--mono);font-size:.68rem;letter-spacing:.16em;text-transform:uppercase;
  color:var(--accent);margin-bottom:1em;direction:ltr}
.ai-note p{margin:.7em 0;font-size:.97rem;line-height:1.95;color:var(--muted)}
.ai-note p[lang="ar"]{direction:rtl;text-align:right;font-family:var(--serif);font-size:1.02rem}
.ai-note p[lang="en"]{direction:ltr;text-align:left;font-style:italic;
  padding-top:.9em;border-top:1px solid var(--line)}
.ai-note strong{color:var(--text);font-weight:600}
@media(max-width:600px){.ai-note{padding:1.1em 1.15em;border-radius:13px}}

/* ---- proper names -------------------------------------------------------
   People and places, marked at build time by generate.py (class .nm).
   Muted gold in the reading column so 42 chapters of dense text stay readable;
   headings keep the full --accent gold. Both themes get their own value —
   the light theme's accent is much darker, so reusing one colour fails there. */
.nm{font-weight:700;color:#c9a266}
:root[data-theme="light"] .nm{color:#8a6114}
@media (prefers-color-scheme: light){
  :root:not([data-theme="dark"]) .nm{color:#8a6114}
}
/* Inside headings and banners a name is already accent-coloured — don't double up. */
article h1 .nm,article h2 .nm,article h3 .nm,.part-title .nm,.toc .nm{color:inherit;font-weight:inherit}

/* ---- chapter paging ----------------------------------------------------- */
.pagenav{display:flex;justify-content:space-between;gap:16px;margin-top:3.5em;
  padding-top:1.6em;border-top:1px solid var(--line)}
.pagenav a{color:var(--muted);text-decoration:none;font-size:.95rem;line-height:1.5;
  max-width:46%;transition:color .2s}
.pagenav a:hover{color:var(--accent)}
.pagenav .pn-next{text-align:end}

/* ---- landing-page chapter index ---------------------------------------- */
.book-toc{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));
  gap:26px 34px;margin:2em 0 1em;text-align:start}
.toc-part h3{font-family:var(--serif);font-size:1.15rem;margin:0 0 .15em;font-weight:600}
.toc-part h3 a{color:var(--accent);text-decoration:none}
.toc-part h3 a:hover{text-decoration:underline}
.toc-part-n{display:block;font-family:var(--mono);font-size:.66rem;letter-spacing:.14em;
  text-transform:uppercase;color:var(--faint);direction:ltr;margin-bottom:.7em}
.toc-chs{margin:0;padding-inline-start:1.3em}
.toc-chs li{margin:.28em 0}
.toc-chs a{color:var(--muted);text-decoration:none;font-size:.95rem;line-height:1.5}
.toc-chs a:hover{color:var(--text)}
