/* Reader. Palette matches assets/site.css (maroon and gold). */
:root {
  --paper: #FBF8F6;
  --surface: #FFFFFF;
  --ink: #261A17;
  --canopy: #4A1219;
  --bustan: #7A1F2B;
  --btn: #7A1F2B;
  --brass: #946B22;
  --muted: #5C4C46;
  --line: #E7DDD7;
  --edge: #94817A;
  --note: #F6EFEA;
  --add: #DDEFE4;
  --del: #F7E0DC;
  --warn: #8A5A08;
  --radius: 12px;
  --shadow: none;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #161010; --surface: #221917; --ink: #F1E8E3; --canopy: #3D0F15; --bustan: #EBA5AC; --btn: #AE4152;
    --brass: #E3BF78; --num: #E3BF78; --muted: #C4B2AA; --line: #5A4540; --edge: #8A706A; --note: #2F2421; --add: #1E3A2C; --del: #45261F;
    --warn: #E0A458; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #161010; --surface: #221917; --ink: #F1E8E3; --canopy: #3D0F15; --bustan: #EBA5AC; --btn: #AE4152;
    --brass: #E3BF78; --num: #E3BF78; --muted: #C4B2AA; --line: #5A4540; --edge: #8A706A; --note: #2F2421; --add: #1E3A2C; --del: #45261F;
    --warn: #E0A458; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.6 "Public Sans", system-ui, sans-serif;
}
a { color: var(--bustan); }
[lang="ar"], .ar { font-family: "Noto Naskh Arabic", Amiri, serif; direction: rtl; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--canopy); color: #F8EDE6;
}
.brand { color: inherit; text-decoration: none; font: 600 19px/1 "Public Sans", sans-serif; white-space: nowrap; }
.book { flex: 1; min-width: 0; font-size: 14px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modes { display: flex; gap: 4px; background: rgb(255 255 255 / .08); border-radius: 999px; padding: 3px; }
.modes a { color: inherit; text-decoration: none; padding: 5px 14px; border-radius: 999px; font-size: 14px; }
.modes a.on { background: #FFFFFF; color: #4A1219; }
.modes b { font-weight: 600; color: #D2A84A; margin-left: 2px; }
.modes a.on b { color: var(--warn); }
.toggle { font-size: 14px; display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.icon { background: none; border: 0; color: inherit; font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon:hover { background: rgb(255 255 255 / .1); }
.menu { display: none; }

/* Layout */
.layout { display: grid; grid-template-columns: 320px 1fr; min-height: calc(100vh - 56px); }
.nav {
  position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto;
  border-right: 1px solid var(--line); padding: 16px; background: var(--surface);
}
.nav input {
  width: 100%; padding: 9px 12px; margin-bottom: 12px;
  border: 1px solid var(--edge); border-radius: 8px; background: var(--paper); color: var(--ink); font: inherit;
}
.toc-section { margin-bottom: 6px; }
.toc-section > button {
  width: 100%; text-align: left; background: none; border: 0; color: var(--ink); cursor: pointer;
  padding: 8px 6px; border-radius: 8px; font: 500 14px/1.35 "Public Sans", sans-serif; display: grid; gap: 2px;
}
.toc-section > button:hover { background: var(--note); }
.toc-section > button .ar { font-size: 15px; color: var(--muted); text-align: right; }
.toc-section ol { list-style: none; margin: 0 0 8px; padding: 0 0 0 10px; border-left: 2px solid var(--edge); display: none; }
.toc-section.open ol { display: block; }
.toc-section li a {
  display: block; padding: 5px 8px; border-radius: 6px; text-decoration: none; color: var(--ink); font-size: 13.5px; line-height: 1.4;
}
.toc-section li a:hover { background: var(--note); }
.toc-section li a.on { background: var(--btn); color: #fff; }
.toc-section li a .dot { color: var(--bustan); margin-left: 4px; }

main { padding: 32px clamp(16px, 4vw, 56px) 80px; max-width: 980px; width: 100%; }
main:focus { outline: none; }
.loading { color: var(--muted); }

/* Chapter */
.chapter-head { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.chapter-head .section { font-size: 15px; color: var(--brass); margin: 0 0 6px; }
.chapter-head h1 { font: 600 32px/1.15 "Public Sans", sans-serif; letter-spacing: -0.015em; margin: 0 0 8px; }
.chapter-head .ar { font-size: 26px; line-height: 1.6; color: var(--muted); margin: 0; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 36px; font-size: 14px; }
.pager a { text-decoration: none; }

/* Entry */
.entry {
  background: var(--surface); border: 1px solid var(--edge); border-radius: var(--radius);
  padding: 22px 26px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.entry-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.num {
  font: 600 13px/1 "Public Sans", sans-serif; color: var(--num, #6F4F16); background: var(--note);
  border-radius: 999px; padding: 5px 10px; min-width: 34px; text-align: center;
}
.flag { font-size: 12px; border-radius: 999px; padding: 3px 9px; border: 1px solid currentColor; color: var(--warn); }
.flag.ok { color: var(--bustan); }
.entry .arabic { font-size: clamp(24px, 3vw, 31px); line-height: 1.95; margin: 4px 0 14px; }
.entry .english { font: 18px/1.7 "Public Sans", Amiri, sans-serif; margin: 0 0 6px; }
.entry details { margin-top: 12px; border-top: 1px dashed var(--edge); padding-top: 10px; }
.entry summary { cursor: pointer; font-size: 13.5px; color: var(--muted); }
.cite { background: var(--note); border-radius: 10px; padding: 12px 16px; margin-top: 10px; font-size: 14.5px; white-space: pre-line; }
.cite.ar { font-size: 18px; line-height: 1.9; }
.app-en { margin-top: 12px; padding: 12px 16px; border-left: 3px solid var(--brass); font-size: 15px; color: var(--muted); }
.app-en b { display: block; font-size: 13px; color: var(--brass); margin-bottom: 4px; }
body:not(.show-app-en) .app-en { display: none; }

/* Review */
.review-head h1 { font: 600 32px/1.15 "Public Sans", sans-serif; letter-spacing: -0.015em; margin: 0 0 6px; }
.review-head p { color: var(--muted); margin: 0 0 18px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.filters button {
  border: 1px solid var(--edge); background: var(--surface); color: var(--ink); border-radius: 999px;
  padding: 6px 14px; font: 14px "Public Sans", sans-serif; cursor: pointer;
}
.filters button.on { background: var(--canopy); color: #FFFFFF; border-color: var(--canopy); }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 8px 0 12px; }
.compare > div { background: var(--paper); border-radius: 10px; padding: 12px 16px; }
.compare h4 { margin: 0 0 6px; font: 600 13px "Public Sans", sans-serif; color: var(--muted); direction: ltr; text-align: left; }
.compare .ar { font-size: 21px; line-height: 1.9; }
.diff { display: flex; flex-wrap: wrap; gap: 6px; direction: rtl; margin: 6px 0; }
.diff span { font: 17px/1.6 "Noto Naskh Arabic", serif; padding: 1px 8px; border-radius: 6px; }
.diff .del { background: var(--del); }
.diff .add { background: var(--add); }
.legend { font-size: 13px; color: var(--muted); }
.legend .del, .legend .add { padding: 0 6px; border-radius: 4px; }
.legend .del { background: var(--del); } .legend .add { background: var(--add); }
.chapter-link { font-size: 13px; }
.empty { color: var(--muted); }
mark { background: #F2D98B; color: inherit; border-radius: 3px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .menu { display: block; }
  .nav { position: fixed; inset: 56px 0 0 0; width: min(340px, 88vw); z-index: 9; transform: translateX(-100%); transition: transform .24s cubic-bezier(.22,.8,.24,1); }
  .nav.open { transform: none; box-shadow: 0 18px 50px rgb(0 0 0 / .25); }
  .book, .toggle { display: none; }
  .compare { grid-template-columns: 1fr; }
  .entry { padding: 18px; }
}

[hidden] { display: none !important; }
@media (max-width: 860px) {
  .top { gap: 8px; padding: 10px 12px; }
  .modes a { padding: 5px 10px; }
}
.toc-section li a.on .dot { color: #fff; }
.filters button.on { background: var(--btn); border-color: var(--btn); color: #fff; }
.modes a.on b { color: #7A1F2B; }
