/* Self-hosted fonts (SIL Open Font License) */
@font-face{font-family:'Amiri';font-style:normal;font-weight:400;font-display:swap;src:url(fonts/amiri-arabic-400-normal.woff2) format('woff2');unicode-range:U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;}
@font-face{font-family:'Amiri';font-style:normal;font-weight:400;font-display:swap;src:url(fonts/amiri-latin-400-normal.woff2) format('woff2');unicode-range:U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;}
@font-face{font-family:'Amiri';font-style:normal;font-weight:700;font-display:swap;src:url(fonts/amiri-arabic-700-normal.woff2) format('woff2');unicode-range:U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;}
@font-face{font-family:'Amiri';font-style:normal;font-weight:700;font-display:swap;src:url(fonts/amiri-latin-700-normal.woff2) format('woff2');unicode-range:U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;}
@font-face{font-family:'Noto Naskh Arabic';font-style:normal;font-weight:400;font-display:swap;src:url(fonts/noto-naskh-arabic-arabic-400-normal.woff2) format('woff2');unicode-range:U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;}
@font-face{font-family:'Noto Naskh Arabic';font-style:normal;font-weight:400;font-display:swap;src:url(fonts/noto-naskh-arabic-latin-400-normal.woff2) format('woff2');unicode-range:U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;}
@font-face{font-family:'Noto Naskh Arabic';font-style:normal;font-weight:600;font-display:swap;src:url(fonts/noto-naskh-arabic-arabic-600-normal.woff2) format('woff2');unicode-range:U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;}
@font-face{font-family:'Noto Naskh Arabic';font-style:normal;font-weight:700;font-display:swap;src:url(fonts/noto-naskh-arabic-arabic-700-normal.woff2) format('woff2');unicode-range:U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;}
@font-face{font-family:'Noto Naskh Arabic';font-style:normal;font-weight:700;font-display:swap;src:url(fonts/noto-naskh-arabic-latin-700-normal.woff2) format('woff2');unicode-range:U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;}

:root {
  --fs: 20px;
  --paper: #fbf8f2;
  --paper-2: #f3ede1;
  --ink: #2a241d;
  --ink-soft: #6b6156;
  --rule: #e2d8c6;
  --accent: #8c2f1f;
  --accent-soft: #f2e2d9;
  --hl: #fbe7a6;
  --shadow: 0 10px 30px rgba(60, 40, 20, .12);
  --body-font: "Noto Naskh Arabic", "Amiri", "Geeza Pro", "Traditional Arabic", serif;
  --display-font: "Amiri", "Noto Naskh Arabic", serif;
  --measure: 40rem;
  color-scheme: light;
}
:root[data-theme="sepia"] {
  --paper: #f1e6cf; --paper-2: #e8dabd; --ink: #3b2f20; --ink-soft: #6f5f49; --rule: #d6c39f;
  --accent: #7d3a12; --accent-soft: #e9d4b3; --hl: #f4d77e;
}
:root[data-theme="dark"] {
  --paper: #18150f; --paper-2: #221e17; --ink: #e9e1d3; --ink-soft: #a89c8a; --rule: #3a3329;
  --accent: #e39a7d; --accent-soft: #3a2a22; --hl: #5c4a17; --shadow: 0 10px 30px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 5rem; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--body-font); line-height: 1.9;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); }
img { max-width: 100%; height: auto; }
button { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.topbar-inner { max-width: 72rem; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .45rem 1rem; }
.brand { font-family: var(--display-font); font-weight: 700; font-size: 1.2rem; color: var(--ink); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { display: flex; gap: .25rem; }
.icon-btn { display: inline-grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 10px; background: transparent; color: var(--ink); cursor: pointer; }
.icon-btn:hover, .icon-btn:focus-visible { background: var(--paper-2); outline: none; }
.progress { height: 2px; background: transparent; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transform-origin: right; }

/* ---------- drawers / panels ---------- */
.scrim { position: fixed; inset: 0; background: rgba(20, 14, 8, .35); z-index: 40; }
.drawer {
  position: fixed; inset-block: 0; inset-inline-start: 0; width: min(24rem, 88vw); z-index: 50;
  background: var(--paper); box-shadow: var(--shadow); overflow-y: auto; padding: 1rem 1.1rem 2rem;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; font-size: 1.1rem; }
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list a { display: block; padding: .6rem .7rem; border-radius: 10px; text-decoration: none; color: var(--ink); line-height: 1.6; }
.toc-list a:hover { background: var(--paper-2); }
.toc-list a.current { background: var(--accent-soft); }
.toc-label { display: block; font-size: .8rem; color: var(--accent); font-weight: 700; }
.toc-title { display: block; }
.drawer-pdf { display: block; margin-top: 1rem; padding: .7rem; text-align: center; border: 1px solid var(--rule); border-radius: 10px; text-decoration: none; }
.panel {
  position: fixed; top: 3.6rem; inset-inline-end: max(1rem, calc((100vw - 72rem) / 2 + 1rem)); z-index: 50;
  background: var(--paper); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow); padding: .8rem 1rem; min-width: 17rem;
}
.panel-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .35rem 0; }
.seg { display: flex; border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: .3rem .75rem; cursor: pointer; }
.seg button + button { border-inline-start: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

/* ---------- reader ---------- */
.reader { padding: 2.5rem 1.25rem 4rem; }
.reader article { max-width: var(--measure); margin: 0 auto; }
.ch-head { text-align: center; margin: 1rem 0 2.5rem; }
.ch-label { color: var(--accent); font-weight: 700; letter-spacing: 0; font-size: 1rem; }
.ch-head h1 { font-family: var(--display-font); font-size: clamp(1.9rem, 5vw, 2.7rem); line-height: 1.5; margin: .3rem 0 .4rem; font-weight: 700; }
.ch-meta { color: var(--ink-soft); font-size: .9rem; }
.ch-head::after { content: "❦"; display: block; color: var(--accent); margin-top: 1.2rem; font-size: 1.2rem; }
.outline { border: 1px solid var(--rule); border-radius: 12px; padding: .2rem 1rem; margin: 0 0 2rem; background: var(--paper-2); }
.outline summary { cursor: pointer; padding: .5rem 0; font-weight: 600; }
.outline ul { margin: 0 0 .6rem; padding-inline-start: 1.2rem; line-height: 1.8; }
.outline a { color: var(--ink); text-decoration: none; }
.outline a:hover { color: var(--accent); }

.text { font-size: var(--fs); }
.text p { margin: 0 0 1.05em; text-align: justify; text-justify: inter-word; hyphens: none; }
.text p.center { text-align: center; }
.text h3 {
  clear: both; font-family: var(--display-font); font-size: 1.3em; color: var(--accent);
  margin: 2em 0 .7em; line-height: 1.6;
}
.text h2.sub { font-family: var(--display-font); text-align: center; font-size: 1.6em; margin: 2.2em 0 1em; }
.text strong { font-weight: 700; color: color-mix(in srgb, var(--ink) 85%, var(--accent)); }
.text :target { background: var(--hl); border-radius: 6px; box-shadow: 0 0 0 .3em var(--hl); transition: background 2s; }
.dedication { text-align: center; margin: 0 auto 1rem; padding: 2rem 1.5rem; border-block: 1px solid var(--rule); }
.dedication h2 { font-family: var(--display-font); margin: 0 0 .6rem; color: var(--accent); font-size: 1.3em; }
.dedication p { text-align: center !important; font-family: var(--display-font); font-size: 1.2em; line-height: 2; margin: 0 !important; }

.fig { margin: .35em 0 1em; }
.fig img { display: block; width: 100%; border-radius: 6px; background: var(--paper-2); }
.fig a { display: block; cursor: zoom-in; }
.fig figcaption { font-size: .78em; color: var(--ink-soft); text-align: center; margin-top: .35em; line-height: 1.5; }
.fig.float { float: left; width: var(--w, 30%); margin-inline-start: 1.3em; clear: left; }
.fig.wide { clear: both; margin: 1.4em 0; }
.clear { clear: both; }

.pager { clear: both; display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 3.5rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); }
.pager a { display: block; padding: .9rem 1.1rem; border: 1px solid var(--rule); border-radius: 14px; text-decoration: none; color: var(--ink); line-height: 1.5; }
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; color: var(--ink-soft); font-size: .8rem; }
.pager span { font-weight: 700; color: var(--accent); }
.pager .next { grid-column: 2; text-align: left; }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(10, 8, 5, .9); display: grid; place-items: center; padding: 1rem; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 92vh; border-radius: 6px; }
.lightbox .icon-btn { position: absolute; top: .8rem; inset-inline-start: .8rem; color: #fff; }
.lightbox .icon-btn:hover { background: rgba(255,255,255,.12); }

/* ---------- home ---------- */
.home { background: var(--paper); }
.cover {
  min-height: 86vh; display: grid; place-items: center; padding: 3rem 1.25rem;
  background:
    radial-gradient(60rem 30rem at 50% -10%, var(--accent-soft), transparent 70%),
    var(--paper);
  border-bottom: 1px solid var(--rule);
}
.cover-inner { max-width: 44rem; text-align: center; }
.eyebrow { color: var(--accent); font-weight: 700; margin: 0 0 1.4rem; letter-spacing: 0; }
.book-title { font-family: var(--display-font); font-size: clamp(2.4rem, 8vw, 4.2rem); line-height: 1.6; margin: 0 0 .6rem; }
.book-author { font-size: 1.15rem; color: var(--ink-soft); margin: 0 0 2rem; }
.cover-quote {
  font-family: var(--display-font); font-size: clamp(1.15rem, 2.8vw, 1.4rem); line-height: 2.05;
  margin: 0 auto 2.2rem; padding: 1.2rem 1.5rem; max-width: 36rem; color: var(--ink);
  border-block: 1px solid var(--rule); position: relative;
}
.cta { display: flex; flex-wrap: wrap; gap: .7rem; justify-content: center; }
.btn {
  display: inline-block; padding: .75rem 1.5rem; border-radius: 999px; text-decoration: none; font-weight: 700;
  border: 1.5px solid var(--accent); color: var(--accent); background: transparent;
}
.btn.primary { background: var(--accent); color: var(--paper); }
.btn:hover { filter: brightness(1.08); }
.btn[hidden] { display: none; }
.cover-facts { color: var(--ink-soft); margin-top: 1.6rem; font-size: .95rem; }
.home-toc { max-width: 52rem; margin: 0 auto; padding: 3rem 1.25rem 4rem; }
.home-toc h2 { font-family: var(--display-font); text-align: center; font-size: 2rem; margin: 0 0 1.5rem; }
.toc-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.toc-grid a {
  display: grid; grid-template-columns: 7.5rem 1fr auto; align-items: baseline; gap: 1rem;
  padding: .95rem 1.2rem; border: 1px solid var(--rule); border-radius: 14px; text-decoration: none; color: var(--ink);
  background: color-mix(in srgb, var(--paper-2) 45%, var(--paper));
}
.toc-grid a:hover { border-color: var(--accent); }
.toc-grid .n { color: var(--accent); font-weight: 700; font-size: .95rem; }
.toc-grid .t { font-family: var(--display-font); font-size: 1.25rem; line-height: 1.5; }
.toc-grid .m { color: var(--ink-soft); font-size: .85rem; white-space: nowrap; }
.home-note { text-align: center; color: var(--ink-soft); margin-top: 2.5rem; }

/* ---------- search ---------- */
.search-form input {
  width: 100%; font: inherit; font-size: 1.15rem; padding: .85rem 1.1rem; border-radius: 14px;
  border: 1.5px solid var(--rule); background: var(--paper-2); color: var(--ink);
}
.search-form input:focus { outline: none; border-color: var(--accent); }
.search-status { color: var(--ink-soft); }
.results { list-style: none; padding: 0; margin: 0; }
.results li { border-bottom: 1px solid var(--rule); }
.results a { display: block; padding: 1rem .2rem; text-decoration: none; color: var(--ink); }
.results a:hover { background: var(--paper-2); }
.results .where { color: var(--accent); font-size: .85rem; font-weight: 700; }
.results .snip { display: block; line-height: 1.9; }
.results mark { background: var(--hl); color: inherit; border-radius: 3px; padding: 0 .1em; }

@media (max-width: 640px) {
  :root { --fs: 18px; }
  .reader { padding: 1.5rem 1.1rem 3rem; }
  .text p { text-align: start; }
  .fig.float { width: max(var(--w, 30%), 38%); margin-inline-start: 1em; }
  .toc-grid a { grid-template-columns: 1fr auto; gap: .2rem .8rem; }
  .toc-grid .n { grid-column: 1; }
  .toc-grid .t { grid-column: 1 / -1; grid-row: 2; }
  .toc-grid .m { grid-column: 2; grid-row: 1; }
  .panel { inset-inline: .75rem; min-width: 0; }
}
@media print {
  .topbar, .drawer, .panel, .pager, .outline { display: none !important; }
}
.book-en { font-family: Georgia, "Times New Roman", serif; font-style: italic; color: var(--ink-soft); font-size: clamp(1rem, 2.6vw, 1.2rem); margin: -.4rem 0 1.2rem; }
