/* Layout: the same shell as the user's بيان site — warm side rail with brand and nav on desktop, bottom tab bar on phones; content column on the warm ground, reading page as a white card. */
:root {
  --bg: #f4f2ec; --surface: #ffffff; --surface-warm: #faf8f2; --inset: #f7f4ec;
  --green: #2f6d63; --green-deep: #244f49; --green-tint: #e2eeec; --chap: #eef3f1; --chap-line: #dde7e4;
  --ink: #1d1b17; --ink-body: #2a2620; --ink-soft: #4a463f; --muted: #8a847a; --faint: #b3ad9f;
  --gold: #a9863a; --gold-line: #ecd6a6;
  --border: #e7e1d4; --divider: #eee7d9;
  --nav-ink: #5d6770; --nav-hover: #f1f4f3;
  --on-green: #ffffff;
  --shadow-card: 0 4px 14px rgba(16,40,30,.04);
  --shadow-sheet: 0 12px 30px rgba(16,40,30,.06);

  --f-ui: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --f-head: "Tajawal", "IBM Plex Sans Arabic", sans-serif;
  --f-text: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --read-size: 1.1rem;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--ink-body); font-family: var(--f-ui); font-size: 15px; line-height: 1.7; padding-inline: 0; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 50; background: var(--bg); }
::selection { background: #cdbb8f; color: #23201a; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 6px; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100%; }
.sidebar {
  flex: none; width: 236px; background: var(--surface-warm); border-inline-end: 1px solid var(--border);
  padding-block: 22px; padding-inline-start: max(16px, env(safe-area-inset-right, 0px)); padding-inline-end: 16px;
  position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; z-index: 20;
}
.sb-brand { display: flex; align-items: center; gap: 11px; padding: 4px 6px 18px; border-bottom: 1px solid var(--divider); margin-bottom: 14px; text-decoration: none; }
.mark { width: 38px; height: 38px; border-radius: 11px; background: var(--green); display: flex; align-items: center; justify-content: center; flex: none; }
.mark.sm { width: 34px; height: 34px; }
.sb-name { font-family: var(--f-head); font-weight: 800; font-size: 18px; color: var(--ink); line-height: 1.15; }
.sb-tag { font-size: 10.5px; color: var(--muted); margin-top: 2px; line-height: 1.35; }
.sb-nav { display: flex; align-items: center; gap: 11px; padding: 11px 12px; border-radius: 10px; font-size: 14px; font-weight: 500; margin-bottom: 4px; color: var(--nav-ink); text-decoration: none; transition: background .12s; }
.sb-nav:hover { background: var(--nav-hover); }
.sb-nav.active { background: var(--green-tint); color: var(--green-deep); font-weight: 600; }
.sb-nav[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.sb-foot { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid var(--divider); font-size: 11px; color: var(--faint); line-height: 1.7; }
.main {
  flex: 1; min-width: 0; padding-block: 28px 70px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.tabbar { display: none; }

/* ---------- top bar inside the content ---------- */
.bar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 6; background: var(--bg); border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.bar-in { max-width: 1000px; margin-inline: auto; display: flex; align-items: center; gap: 12px; padding-block: 4px 12px; flex-wrap: wrap; }
.brand { display: none; align-items: center; gap: 10px; text-decoration: none; }
.brand b { font-family: var(--f-head); font-weight: 800; font-size: 19px; color: var(--ink); line-height: 1.1; }
.brand small { display: block; font-size: 10.5px; color: var(--muted); }
.crumbs { color: var(--muted); font-size: 13.5px; display: flex; gap: 6px; align-items: center; min-width: 0; }
.crumbs a { text-decoration: none; color: var(--green); font-weight: 500; }
.crumbs span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); }

.btn {
  cursor: pointer; border-radius: 9px; font-size: 13.5px; padding: 8px 14px; min-height: 38px;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-weight: 500;
  transition: background .12s, color .12s, border-color .12s;
}
.btn:hover { background: var(--green-tint); color: var(--green); border-color: var(--green-tint); }
.btn.primary { background: var(--green); border-color: var(--green); color: var(--on-green); font-weight: 600; padding-inline: 22px; box-shadow: 0 6px 14px rgba(44,106,99,.22); }
.btn.primary:hover { background: var(--green-deep); color: var(--on-green); }
.btn[disabled] { opacity: .4; pointer-events: none; box-shadow: none; }

.wrap { max-width: 1000px; margin-inline: auto; }

/* ---------- home ---------- */
.intro { padding-block: 26px 6px; display: grid; gap: 6px; }
.intro h1, .book-head h1 { font-family: var(--f-head); font-weight: 800; color: var(--ink); margin: 0; line-height: 1.3; text-wrap: balance; }
.intro h1 { font-size: 22px; }
.intro p { margin: 0; color: var(--muted); font-size: 14px; max-width: 62ch; }
.search { margin-block: 18px 22px; }
.search input, .toc-tools input {
  width: 100%; border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  padding: 12px 16px; font-size: 15px; color: var(--ink-body);
}
.sub-h { font-family: var(--f-head); font-weight: 800; font-size: 16px; color: var(--ink); margin: 0 0 12px; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.book-card {
  position: relative; border-radius: 18px; padding: 16px 18px; min-height: 132px; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; color: var(--on-green); text-decoration: none;
  background: var(--green); transition: transform .12s;
}
.book-card:hover { transform: translateY(-3px); }
.book-card::after { content: attr(data-wm); position: absolute; inset-inline-start: 12px; top: -18px; font-family: var(--f-head); font-weight: 900; font-size: 92px; line-height: 1; color: rgba(255,255,255,.10); pointer-events: none; }
.book-card .spine { display: none; }
.book-card h3 { font-family: var(--f-head); font-weight: 800; font-size: 19px; margin: 0; line-height: 1.3; }
.book-card .who { font-size: 12.5px; opacity: .85; }
.meta-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font-size: 11px; background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.28); border-radius: 6px; padding: 1px 9px; }
.note { margin-top: 26px; font-size: 13px; color: var(--muted); background: var(--surface-warm); border: 1px solid var(--divider); border-radius: 12px; padding: 12px 16px; max-width: 72ch; }
.empty { color: var(--muted); padding: 24px 0; }

/* ---------- book page ---------- */
.book-head { padding-block: 22px 4px; display: grid; gap: 4px; }
.book-head h1 { font-size: clamp(24px, 4vw, 30px); }
.book-head .who { color: var(--green); font-size: 15px; font-weight: 500; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-block: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-card); overflow: hidden; }
.facts div { padding: 12px 16px; border-inline-start: 1px solid var(--divider); margin-inline-start: -1px; border-top: 1px solid var(--divider); margin-top: -1px; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
h2.sec { font-family: var(--f-head); font-weight: 800; font-size: 16px; color: var(--ink); margin: 28px 0 12px; }
.vols { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.vol { display: grid; gap: 2px; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); text-decoration: none; box-shadow: var(--shadow-card); }
.vol:hover { border-color: var(--green); }
.vol b { font-family: var(--f-head); font-size: 17px; font-weight: 800; color: var(--green); }
.vol span { font-size: 12px; color: var(--muted); }
.toc-tools { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.toc { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.toc li a { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: baseline; padding: 10px 16px; text-decoration: none; color: var(--ink-soft); border-top: 1px solid var(--divider); }
.toc li:first-child a { border-top: 0; }
.toc li a:hover { background: var(--chap); }
.toc li.l1 a { font-family: var(--f-head); font-weight: 800; color: var(--green-deep); background: var(--chap); }
.toc li.l2 a, .toc li.l3 a { padding-inline-start: 30px; }
.toc .t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc .pg { font-size: 11.5px; color: var(--faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.more { margin-top: 10px; }

/* ---------- reader ---------- */
.rtools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-inline-start: auto; }
.rtools select, .rtools input { border: 1px solid var(--border); background: var(--surface); border-radius: 9px; min-height: 38px; padding: 4px 10px; color: var(--ink-soft); }
.rtools input { width: 4.2em; text-align: center; font-variant-numeric: tabular-nums; }
.rtools label { font-size: 13px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.sheet { max-width: 48rem; margin: 20px auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-sheet); padding: clamp(20px, 4vw, 44px) clamp(16px, 5vw, 56px) 22px; }
.runhead { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--divider); padding-bottom: 10px; margin-bottom: 18px; }
.runhead span:first-child { color: var(--green); font-weight: 600; background: var(--green-tint); border-radius: 999px; padding: 1px 12px; white-space: nowrap; }
.runhead span:last-child { text-align: end; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; align-self: center; }
.text { font-family: var(--f-text); font-size: var(--read-size); line-height: 2; color: var(--ink); text-align: justify; }
.text p { margin: 0 0 .75em; text-indent: 1.2em; }
.text p.cont { text-indent: 0; }
.text h3 { font-family: var(--f-head); font-weight: 800; font-size: 1em; color: var(--green-deep); margin: 1.3em 0 .6em; line-height: 1.7; text-wrap: balance; }
.text h3.l1 { font-size: 1.12em; background: var(--chap); border: 1px solid var(--chap-line); border-radius: 10px; padding: 8px 14px; text-align: center; }
.text h3.l2, .text h3.l3 { display: flex; align-items: center; gap: 10px; text-align: right; }
.text h3.l2 > *, .text h3 { text-align-last: auto; }
.text h3.l2::before, .text h3.l3::before { content: ""; width: 6px; height: 6px; border-radius: 2px; background: var(--gold); flex: none; transform: rotate(45deg); }
.verse { display: grid; grid-template-columns: 1fr 1fr; gap: .2em 2.5em; margin: .3em 0 .9em; text-align: center; background: var(--inset); border-radius: 10px; padding: .4em 1em; }
.orig { display: inline-block; font-family: var(--f-ui); font-size: .62em; line-height: 1.5; color: var(--gold); background: var(--surface-warm); border: 1px solid var(--gold-line); border-radius: 6px; padding: 0 6px; margin-inline: 4px; vertical-align: .25em; text-indent: 0; font-variant-numeric: tabular-nums; cursor: help; }
.folio { margin-top: 20px; padding-top: 10px; border-top: 1px solid var(--divider); text-align: center; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.pager { max-width: 48rem; margin: 16px auto 0; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.pager .pos { font-size: 12px; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.progress { max-width: 48rem; margin: 12px auto 0; height: 4px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--green); width: 0; transition: width .2s ease; }

/* contents drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(29,27,23,.28); z-index: 60; }
.drawer {
  position: fixed; top: 0; bottom: 0; inset-inline-start: 0; width: min(420px, 92vw); z-index: 61;
  background: var(--surface-warm); border-inline-end: 1px solid var(--border); display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 14px calc(env(safe-area-inset-bottom, 0px) + 14px);
  padding-inline-start: max(14px, env(safe-area-inset-right, 0px));
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.drawer .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.drawer .head b { font-family: var(--f-head); font-weight: 800; font-size: 16px; color: var(--ink); }
.drawer .toc { overflow-y: auto; flex: 1; }
.drawer .toc li.cur a { background: var(--green-tint); color: var(--green-deep); }

@media (max-width: 680px) {
  .sidebar { display: none; }
  .main { padding-block: 10px calc(86px + env(safe-area-inset-bottom, 0px)); }
  .brand { display: inline-flex; }
  .bar-in { padding-top: 6px; }
  .tabbar {
    display: flex; position: fixed; inset: auto 0 0 0; z-index: 40;
    height: calc(62px + env(safe-area-inset-bottom, 0px)); padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
    background: rgba(244,242,236,.92); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
  }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; }
  .tabbar a.active { color: var(--green); font-weight: 600; }
  .tabbar a[aria-disabled="true"] { opacity: .45; pointer-events: none; }
  .rtools { margin-inline-start: 0; width: 100%; }
  .rtools .hide-sm { display: none; }
  .verse { grid-template-columns: 1fr; gap: 0; }
  .verse span:nth-child(even) { padding-inline-start: 2em; }
  .text { text-align: right; }
  .sheet { border-radius: 14px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- added for the multi-book site ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 18px; }
.filters select { border: 1px solid var(--border); background: var(--surface); border-radius: 9px; min-height: 38px; padding: 4px 10px; color: var(--ink-soft); max-width: 100%; }
.filters .count { margin-inline-start: auto; font-size: 13px; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.credit { margin: 26px 0 0; font-size: 12px; color: var(--muted); text-align: center; overflow-wrap: anywhere; }
.reader-credit { max-width: 48rem; margin: 0 auto; }
.btn[aria-disabled="true"] { opacity: .4; pointer-events: none; box-shadow: none; }
.text h3.l2, .text h3.l3, .text h3.l4 { display: flex; align-items: center; gap: 10px; text-align: right; }
.text h3.l4 { font-size: .96em; }
.text h3.l2::before, .text h3.l3::before, .text h3.l4::before { content: ""; width: 6px; height: 6px; border-radius: 2px; background: var(--gold); flex: none; transform: rotate(45deg); }
.toc li.l2 a, .toc li.l3 a, .toc li.l4 a { padding-inline-start: 30px; }
.toc li.l3 a, .toc li.l4 a { font-size: 14px; }
.text { overflow-wrap: anywhere; }

/* ---------- reading page laid out like the old library ---------- */
.page-title {
  max-width: 48rem; margin: 20px auto 0; background: var(--green); color: var(--on-green);
  font-family: var(--f-head); font-weight: 800; font-size: 17px; line-height: 1.5;
  padding: 10px 20px; border-radius: 16px 16px 0 0; text-wrap: balance;
}
.sheet.titled { margin-top: 0; border-top: 0; border-radius: 0 0 18px 18px; }
.sheet.titled .runhead { justify-content: flex-start; }
.sheet.titled .runhead span:first-child { background: none; color: var(--muted); font-weight: 400; padding: 0; white-space: normal; }
.folio { font-size: 14px; color: var(--ink-soft); }
.pnav { max-width: 48rem; margin: 18px auto 0; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; }
.pnav a, .pnav span {
  min-width: 38px; height: 38px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--ink-soft);
  text-decoration: none; font-variant-numeric: tabular-nums; font-size: 14px; transition: background .12s, color .12s;
}
.pnav a:hover { background: var(--green-tint); color: var(--green-deep); border-color: var(--green-tint); }
.pnav .cur { background: var(--green); border-color: var(--green); color: var(--on-green); font-weight: 600; }
.pnav .gap { border: 0; background: none; min-width: 16px; padding: 0; color: var(--faint); }
.pnav .off { opacity: .35; }
.goto { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 12px; font-size: 13.5px; color: var(--muted); }
.goto input { width: 5em; min-height: 38px; text-align: center; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); font-variant-numeric: tabular-nums; }
.index-btn {
  display: block; width: 100%; max-width: 48rem; margin: 18px auto 0; padding: 12px; text-align: center; text-decoration: none; cursor: pointer;
  background: var(--surface-warm); border: 1px solid var(--border); border-radius: 12px;
  font-family: var(--f-head); font-weight: 800; font-size: 16px; color: var(--green-deep); transition: background .12s;
}
.index-btn:hover { background: var(--green-tint); }
@media (max-width: 680px) {
  .page-title { font-size: 15px; padding: 9px 14px; border-radius: 14px 14px 0 0; }
  .sheet.titled { border-radius: 0 0 14px 14px; }
}

/* ---------- full-text search ---------- */
.sform { display: flex; gap: 8px; margin-block: 18px 6px; }
.sform input { flex: 1; min-width: 0; }
.sform .btn { flex: none; min-height: 46px; }
.tip { margin: 0 0 16px; font-size: 12.5px; color: var(--muted); }
.count-line { color: var(--muted); font-size: 13.5px; margin: 6px 0 12px; }
.facets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.facet { font-size: 13px; text-decoration: none; padding: 4px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--ink-soft); display: inline-flex; gap: 6px; }
.facet:hover { border-color: var(--green); }
.facet b { color: var(--green); font-weight: 600; font-variant-numeric: tabular-nums; }
.hits { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.hits:empty { display: none; }
.hits a { display: grid; gap: 4px; padding: 12px 16px; text-decoration: none; border-top: 1px solid var(--divider); }
.hits li:first-child a { border-top: 0; }
.hits a:hover { background: var(--chap); }
.hits .where { font-size: 12.5px; color: var(--green); font-weight: 600; }
.hits .snip { color: var(--ink-body); line-height: 1.9; }
mark { background: #f3e2b3; color: var(--ink); border-radius: 3px; padding: 0 1px; }
.rtools .btn svg { width: 16px; height: 16px; }
.hits li.tier { padding: 8px 16px; font-size: 12.5px; font-weight: 600; color: var(--gold); background: var(--surface-warm); border-top: 1px solid var(--divider); }
.hits li.tier:first-child { border-top: 0; }

/* ---------- library search: titles or book texts ---------- */
.home-search { display: grid; gap: 8px; }
.home-search .sform { margin: 0; }
.seg { display: inline-flex; justify-self: start; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; cursor: pointer; padding: 6px 14px; border-radius: 7px; font-size: 13.5px; color: var(--muted); font-weight: 500; }
.seg button:hover { color: var(--green-deep); }
.seg button[aria-selected="true"] { background: var(--green-tint); color: var(--green-deep); font-weight: 600; }

[hidden] { display: none !important; }

/* ---------- about page ---------- */
.prose { max-width: 46rem; padding-block: 22px 10px; }
.prose h1 { font-family: var(--f-head); font-weight: 800; font-size: clamp(22px, 3.6vw, 28px); color: var(--ink); margin: 0 0 10px; }
.prose h2 { font-family: var(--f-head); font-weight: 800; font-size: 17px; color: var(--green-deep); margin: 28px 0 8px; }
.prose p, .prose li { font-size: 15.5px; line-height: 1.95; color: var(--ink-body); }
.prose p { margin: 0 0 10px; }
.prose ul { margin: 0 0 10px; padding-inline-start: 22px; }
.prose a { color: var(--green); font-weight: 500; }
.prose .links { list-style: none; padding: 0; display: grid; gap: 6px; }
.prose .links li { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; }
.prose .links span { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.credit a { color: var(--green); }

/* Linked notes are supplemental: they do not change the reading page numbers. */
.note-ref { font: inherit; font-size: .8em; color: var(--green-deep); background: var(--green-tint); border: 0; border-radius: 4px; cursor: pointer; padding: 0 .25em; }
.note-ref:focus-visible { outline: 2px solid var(--green-deep); outline-offset: 3px; }
.footnotes { border-top: 1px solid var(--border); margin-top: 2rem; padding-top: 1rem; line-height: 1.9; }
.footnotes h2 { font-size: 1rem; margin: 0 0 1rem; }
.footnotes p { font-size: .95rem; margin: .6rem 0; scroll-margin-top: 5rem; }
.footnotes p:focus { outline: 2px solid var(--green-deep); outline-offset: 5px; }
.footnotes small { display: block; color: var(--faint); font-size: .75rem; }
.recovery-credit { color: var(--faint); font-size: .8rem; line-height: 1.8; max-width: 46rem; margin: 1rem auto; }
