:root {
  --navy: #10283f;
  --navy-2: #183d5b;
  --ink: #172534;
  --muted: #637383;
  --paper: #f5f7f9;
  --surface: #ffffff;
  --line: #dce4e9;
  --gold: #c8933f;
  --verse: #166b4f;
  --verse-bg: #edf8f3;
  --hadith: #23608d;
  --hadith-bg: #eef6fc;
  --tafsir: #906022;
  --tafsir-bg: #fff7e8;
  --analysis: #7e3a46;
  --analysis-bg: #fff2f3;
  --resource: #236777;
  --resource-bg: #eef8fa;
  --shadow: 0 18px 48px rgba(13, 37, 56, .08);
  --body-size: 1.18rem;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Noto Naskh Arabic", serif;
  line-height: 1.95;
}
button, a { font: inherit; }
button { color: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 20rem minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow: auto;
  background: linear-gradient(180deg, #10283f 0%, #0d2235 100%); color: #fff; padding: 1.35rem 1rem;
  border-left: 1px solid rgba(255,255,255,.08); z-index: 30;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.22) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 99px; }
.brand { display: flex; gap: .85rem; align-items: center; padding: .4rem .45rem 1.25rem; }
.brand-mark {
  display: grid; place-items: center; width: 2.85rem; height: 2.85rem; border-radius: .85rem;
  background: var(--gold); color: var(--navy); font-family: "Noto Kufi Arabic", sans-serif; font-weight: 800;
}
.brand strong { display: block; font: 700 1rem/1.5 "Noto Kufi Arabic", sans-serif; }
.brand small { display: block; color: #b8c8d5; font-size: .82rem; margin-top: .15rem; }
.library-link, .guide-link, .nav-part-button, .nav-topic {
  width: 100%; border: 0; text-align: right; cursor: pointer; color: inherit;
}
.library-link {
  display: flex; justify-content: space-between; align-items: center; padding: .7rem .8rem; border-radius: .75rem;
  background: rgba(255,255,255,.07); font-weight: 700; margin-bottom: .7rem;
}
.library-link.active { background: var(--gold); color: var(--navy); }
.guide-link {
  display: flex; justify-content: space-between; align-items: center; padding: .62rem .8rem; border-radius: .75rem;
  background: transparent; color: #b9cad5; margin: -.25rem 0 .7rem; font-size: .86rem;
}
.guide-link:hover, .guide-link.active { background: rgba(255,255,255,.08); color: #fff; }
.guide-link.active { box-shadow: inset -3px 0 var(--gold); }
.count { font-family: system-ui, sans-serif; font-size: .8rem; opacity: .8; }
.nav-part { border-top: 1px solid rgba(255,255,255,.08); }
.nav-part-button {
  display: grid; grid-template-columns: 2rem minmax(0,1fr) 1.3rem; gap: .65rem; align-items: center;
  background: transparent; padding: .8rem .6rem; color: #d8e2e9; border-radius: .7rem; transition: background .18s ease;
}
.nav-part-button:hover { background: rgba(255,255,255,.055); }
.nav-part-index {
  display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: .62rem;
  background: rgba(200,147,63,.14); color: var(--gold); font: 800 .76rem/1 system-ui, sans-serif;
}
.nav-part-copy { min-width: 0; }
.nav-part-copy strong { display: block; font: 600 .79rem/1.55 "Noto Kufi Arabic", sans-serif; }
.nav-part-copy small { display: block; color: #829cac; font: 500 .7rem/1.5 "Noto Kufi Arabic", sans-serif; margin-top: .12rem; }
.nav-chevron { color: #829cac; font: 700 1rem/1 system-ui, sans-serif; transition: transform .2s ease, color .2s ease; }
.nav-part.expanded .nav-part-button { background: rgba(255,255,255,.065); }
.nav-part.expanded .nav-chevron { transform: rotate(180deg); color: var(--gold); }
.nav-topics {
  display: grid; gap: .12rem; max-height: 0; overflow: hidden; opacity: 0; padding: 0 .1rem;
  transition: max-height .35s ease, opacity .2s ease, padding .25s ease;
}
.nav-part.expanded .nav-topics { max-height: 62rem; opacity: 1; padding: .25rem .1rem .7rem; }
.nav-topic {
  display: grid; grid-template-columns: 1.7rem 1fr; gap: .45rem; align-items: start;
  position: relative; background: transparent; padding: .48rem .62rem; border-radius: .58rem; color: #9fb5c4; font-size: .84rem; line-height: 1.55;
}
.nav-topic:hover, .nav-topic.active { background: rgba(255,255,255,.09); color: #fff; }
.nav-topic.active { box-shadow: inset -3px 0 var(--gold); background: rgba(200,147,63,.12); }
.nav-number { font: 700 .72rem/1.65 system-ui, sans-serif; color: var(--gold); padding-top: .12rem; }
.sidebar-footer { color: #a9bdca; font-size: .78rem; padding: 1rem .55rem; display: flex; gap: .45rem; align-items: center; flex-wrap: wrap; }
.legend-dot { width: .48rem; height: .48rem; border-radius: 50%; display: inline-block; }
.verse-dot { background: #66c7a7; }.hadith-dot { background: #71b1df; }.tafsir-dot { background: #e6b55f; }

.main-shell { min-width: 0; }
.topbar {
  height: 4.3rem; padding: 0 clamp(1rem, 3vw, 3rem); display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20; background: rgba(245,247,249,.94); backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(16,40,63,.08);
}
.crumb { font-family: "Noto Kufi Arabic", sans-serif; color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar { display: flex; gap: .42rem; align-items: center; }
.icon-button, .text-button {
  border: 1px solid var(--line); background: var(--surface); border-radius: .7rem; cursor: pointer; min-height: 2.4rem;
}
.icon-button { width: 2.4rem; display: grid; place-items: center; font-family: system-ui, sans-serif; font-weight: 700; }
.text-button { padding: .35rem .8rem; font-weight: 700; font-size: .9rem; }
.icon-button:hover, .text-button:hover { border-color: var(--gold); }
.progress-track { position: fixed; top: 4.25rem; left: 0; right: 20rem; height: 3px; z-index: 25; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--gold); transition: width .1s linear; }

main { width: min(100%, 82rem); margin: 0 auto; padding: clamp(1.5rem, 4vw, 4rem); }
.library-header { display: grid; grid-template-columns: 1.2fr .8fr; gap: 2rem; align-items: end; margin-bottom: 2rem; }
.eyebrow { color: var(--gold); font: 700 .82rem/1.6 "Noto Kufi Arabic", sans-serif; letter-spacing: .02em; }
h1, h2, h3 { font-family: "Noto Kufi Arabic", sans-serif; line-height: 1.65; margin-top: 0; }
.library-header h1 { font-size: clamp(2rem, 4.5vw, 4.3rem); max-width: 15ch; margin: .6rem 0 1rem; letter-spacing: -.04em; }
.library-header p { color: var(--muted); font-size: 1.15rem; max-width: 48rem; margin: 0; }
.hero-actions { margin-top: 1.25rem; }
.hero-actions button {
  border: 0; border-radius: .85rem; background: var(--gold); color: var(--navy); padding: .68rem 1rem;
  cursor: pointer; font: 700 .84rem/1.6 "Noto Kufi Arabic", sans-serif; box-shadow: 0 9px 22px rgba(200,147,63,.2);
}
.hero-actions button:hover { filter: brightness(1.04); transform: translateY(-1px); }
.hero-actions span { margin-right: .45rem; font-family: system-ui, sans-serif; }
.reading-key { background: var(--navy); color: #fff; border-radius: 1.25rem; padding: 1.2rem; box-shadow: var(--shadow); }
.reading-key strong { font-family: "Noto Kufi Arabic", sans-serif; }
.key-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: .65rem; margin-top: .85rem; }
.key-item { display: flex; align-items: center; gap: .45rem; color: #cbd7df; font-size: .88rem; }
.part-section { margin-top: 2.8rem; }
.part-heading { display: flex; align-items: center; gap: .8rem; margin-bottom: 1rem; }
.part-heading .part-index {
  font: 800 .9rem/1 system-ui, sans-serif; color: var(--navy); background: var(--gold); padding: .58rem .68rem; border-radius: .55rem;
}
.part-heading h2 { margin: 0; font-size: clamp(1.15rem, 2vw, 1.55rem); }
.part-route { display: flex; flex-wrap: wrap; gap: .65rem; margin: -.2rem 0 1rem; }
.part-route button {
  display: flex; align-items: baseline; gap: .55rem; border: 1px solid var(--line); background: transparent;
  border-radius: 999px; padding: .42rem .78rem; cursor: pointer; color: var(--navy-2);
}
.part-route button:hover { background: var(--surface); border-color: var(--gold); }
.part-route span { font: 700 .78rem/1.5 "Noto Kufi Arabic", sans-serif; }
.part-route small { color: var(--muted); font-size: .72rem; }
.topic-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.topic-card {
  display: grid; grid-template-columns: 3.4rem 1fr auto; gap: .9rem; align-items: center; text-align: right;
  border: 1px solid var(--line); border-radius: 1rem; background: var(--surface); padding: 1rem; cursor: pointer;
  box-shadow: 0 7px 22px rgba(16,40,63,.04); transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.topic-card:hover { transform: translateY(-3px); border-color: #b9c8d2; box-shadow: var(--shadow); }
.topic-card-number { width: 3rem; height: 3rem; border-radius: .8rem; background: #eaf0f4; color: var(--navy); display: grid; place-items: center; font: 800 .95rem system-ui, sans-serif; }
.topic-card strong { display: block; font: 600 .92rem/1.8 "Noto Kufi Arabic", sans-serif; }
.topic-card small { color: var(--muted); }
.topic-card-arrow { color: var(--gold); font: 800 1.4rem system-ui, sans-serif; }

.article { max-width: 63rem; margin: 0 auto; }
.article-head {
  position: relative; overflow: hidden; margin-bottom: 2rem; padding: clamp(1.35rem, 3vw, 2.15rem);
  background: linear-gradient(135deg, rgba(255,255,255,.98), rgba(238,243,247,.8));
  border: 1px solid var(--line); border-radius: 1.3rem; box-shadow: 0 12px 35px rgba(16,40,63,.055);
}
.article-head::after {
  content: ""; position: absolute; width: 10rem; height: 10rem; left: -4.5rem; bottom: -6rem;
  border: 1.6rem solid rgba(200,147,63,.1); border-radius: 50%; pointer-events: none;
}
.article-meta { display: flex; flex-wrap: wrap; gap: .55rem; align-items: center; color: var(--muted); font-size: .9rem; margin-bottom: .7rem; }
.article-meta .pill { background: #e7edf1; color: var(--navy); padding: .22rem .62rem; border-radius: 999px; font: 700 .78rem/1.6 system-ui, sans-serif; }
.reading-time { display: inline-flex; align-items: center; gap: .3rem; margin-inline-start: auto; font-size: .82rem; }
.reading-time::before { content: "◷"; font-family: system-ui, sans-serif; color: var(--gold); }
.article h1 { position: relative; z-index: 1; font-size: clamp(1.55rem, 3.2vw, 2.65rem); margin: 0; letter-spacing: -.025em; max-width: 26ch; }
.article-intro-line { width: 5rem; height: .32rem; background: var(--gold); border-radius: 99px; margin-top: 1.3rem; }
.overview-page .article-head { border-color: color-mix(in srgb, var(--gold) 42%, var(--line)); }
.summary-page .article-head { background: linear-gradient(135deg, rgba(248,243,232,.98), rgba(255,255,255,.9)); border-color: #e4d1a7; }
.summary-page .article-meta .pill { background: var(--gold); color: var(--navy); }
.article-outline {
  display: grid; grid-template-columns: auto 1fr; gap: .8rem 1rem; align-items: center; margin: -1rem 0 1.5rem;
  padding: .75rem .9rem; border: 1px solid var(--line); border-radius: .95rem; background: color-mix(in srgb, var(--surface) 82%, transparent);
}
.article-outline > span { color: var(--muted); font: 700 .72rem/1.5 "Noto Kufi Arabic", sans-serif; white-space: nowrap; }
.article-outline > div { display: flex; flex-wrap: wrap; gap: .42rem; }
.outline-button { border: 0; border-radius: 999px; padding: .3rem .65rem; cursor: pointer; background: #e9eef2; color: var(--navy); font-size: .76rem; }
.outline-button.verse { background: var(--verse-bg); color: var(--verse); }
.outline-button.hadith { background: var(--hadith-bg); color: var(--hadith); }
.outline-button.tafsir { background: var(--tafsir-bg); color: var(--tafsir); }
.outline-button.analysis { background: var(--analysis-bg); color: var(--analysis); }
.outline-button.resources { background: var(--resource-bg); color: var(--resource); }
.outline-button:hover { box-shadow: inset 0 0 0 1px currentColor; }
.content-stack { display: grid; gap: 1.35rem; }
.content-stack > [id] { scroll-margin-top: 5.5rem; }
.content-block {
  position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 1.15rem;
  padding: 0; font-size: var(--body-size); box-shadow: 0 8px 25px rgba(16,40,63,.04);
}
.content-block::before { content: ""; position: absolute; inset-block: 0; right: 0; width: 5px; background: #bac6cf; }
.block-heading {
  display: flex; align-items: center; gap: .65rem; padding: .85rem 1.25rem .78rem 1rem;
  border-bottom: 1px solid color-mix(in srgb, currentColor 13%, transparent);
}
.block-heading h2 { margin: 0; font-size: .82rem; letter-spacing: .01em; }
.block-icon { display: grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: .58rem; font-family: system-ui, sans-serif; font-weight: 800; }
.block-copy { padding: 1.15rem clamp(1.1rem, 2.7vw, 1.65rem) 1.3rem; }
.content-block p { margin: 0; }
.content-block p.with-divider { margin-top: 1.1rem; padding-top: 1.1rem; border-top: 1px solid color-mix(in srgb, currentColor 11%, transparent); }
.content-block p.mini-heading { font-weight: 700; font-size: .98em; padding-top: .9rem; }
.content-block.verse { background: var(--verse-bg); border-color: #cfe7dc; color: #174f3d; }
.content-block.verse::before { background: var(--verse); }.content-block.verse .block-icon { color: #fff; background: var(--verse); }
.content-block.hadith { background: var(--hadith-bg); border-color: #d2e5f2; color: #234c68; }
.content-block.hadith::before { background: var(--hadith); }.content-block.hadith .block-icon { color: #fff; background: var(--hadith); }
.content-block.tafsir { background: var(--tafsir-bg); border-color: #f0dfbd; color: #694816; }
.content-block.tafsir::before { background: var(--tafsir); }.content-block.tafsir .block-icon { color: #fff; background: var(--tafsir); }
.content-block.analysis { background: var(--analysis-bg); border-color: #efd4d8; }
.content-block.analysis::before { background: var(--analysis); }.content-block.analysis .block-icon { color: #fff; background: var(--analysis); }
.content-block.prose { overflow: visible; background: transparent; border: 0; box-shadow: none; border-radius: 0; font-size: calc(var(--body-size) * 1.01); }
.content-block.prose::before { display: none; }
.content-block.prose .block-copy { padding: .2rem .15rem; }
.content-block.prose p.with-divider { border-color: var(--line); }
.subheading { font-size: 1.12rem; margin: 1rem 0 -.15rem; padding-right: 1rem; border-right: 4px solid var(--gold); color: var(--navy-2); }
.resource-box {
  display: grid; grid-template-columns: minmax(11rem, .42fr) 1fr; gap: 1.2rem; align-items: center;
  background: var(--resource-bg); border: 1px solid #cfe3e8; border-radius: 1.15rem; padding: 1.15rem 1.25rem;
}
.resource-heading { display: flex; gap: .75rem; align-items: center; }
.resource-heading > span { display: grid; place-items: center; width: 2.35rem; height: 2.35rem; border-radius: .7rem; background: var(--resource); color: #fff; font-family: system-ui, sans-serif; font-weight: 800; }
.resource-box h3 { color: var(--resource); font-size: .88rem; margin: 0; }
.resource-box p { color: var(--muted); font-size: .8rem; margin: .15rem 0 0; }
.resource-list { display: flex; flex-wrap: wrap; justify-content: flex-start; gap: .55rem; }
.source-button {
  display: inline-flex; gap: .45rem; align-items: center; text-decoration: none; color: var(--resource); background: var(--surface);
  border: 1px solid #bdd8df; border-radius: .7rem; padding: .52rem .78rem; font: 700 .8rem/1.5 "Noto Kufi Arabic", sans-serif;
  transition: transform .18s ease, background .18s ease;
}
.source-button:hover { background: var(--resource); color: #fff; transform: translateY(-2px); }
.source-button::after { content: "↗"; font-family: system-ui, sans-serif; font-size: .9rem; }
.figure { margin: .25rem 0; background: var(--surface); border: 1px solid var(--line); border-radius: 1.15rem; overflow: hidden; box-shadow: 0 8px 25px rgba(16,40,63,.04); }
.figure img { display: block; max-width: 100%; width: 100%; height: auto; }
.figure figcaption { color: var(--muted); font-size: .85rem; padding: .75rem 1rem; }
.figure figcaption span { display: inline-block; margin-left: .55rem; color: var(--navy); font: 700 .72rem/1.5 "Noto Kufi Arabic", sans-serif; }
.article-nav { display: grid; grid-template-columns: 1fr auto 1fr; gap: .7rem; margin-top: 2.2rem; padding-top: 1.4rem; border-top: 1px solid var(--line); }
.article-nav button { border: 1px solid var(--line); background: var(--surface); border-radius: .8rem; cursor: pointer; padding: .65rem .9rem; font-weight: 700; }
.article-nav button:hover { border-color: var(--gold); }.article-nav .next { justify-self: end; }.article-nav .prev { justify-self: start; }
.article-nav button:disabled { opacity: .35; cursor: not-allowed; }

.empty { background: var(--surface); border-radius: 1rem; padding: 2rem; border: 1px solid var(--line); }
.mobile-only { display: none; }
.scrim { display: none; }
.toast { position: fixed; bottom: 1.3rem; left: 1.3rem; background: var(--navy); color: #fff; padding: .65rem 1rem; border-radius: .7rem; opacity: 0; transform: translateY(.6rem); pointer-events: none; transition: .2s ease; z-index: 60; }
.toast.show { opacity: 1; transform: translateY(0); }

body.dark {
  --paper: #0d1821; --surface: #142532; --ink: #e9f0f4; --muted: #a5b5bf; --line: #29404f;
  --verse-bg: #12382d; --hadith-bg: #142f44; --tafsir-bg: #3a2b16; --analysis-bg: #3b2228; --resource-bg: #15343d;
  --shadow: 0 22px 55px rgba(0,0,0,.28); color-scheme: dark;
}
body.dark .topbar { background: rgba(13,24,33,.9); }
body.dark .topic-card-number, body.dark .article-meta .pill { background: #223846; color: #e9f0f4; }
body.dark .article-head { background: linear-gradient(135deg, rgba(20,37,50,.98), rgba(14,30,41,.9)); }
body.dark .summary-page .article-head { background: linear-gradient(135deg, rgba(57,45,28,.98), rgba(20,37,50,.92)); border-color: #6f5830; }
body.dark .subheading, body.dark .figure figcaption span { color: #e7edf1; }

@media (max-width: 980px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; right: 0; transform: translateX(105%); width: min(88vw, 22rem); transition: transform .25s ease; }
  body.menu-open .sidebar { transform: translateX(0); }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 29; }
  body.menu-open .scrim { display: block; }
  .mobile-only { display: grid; }
  .progress-track { right: 0; }
  .library-header { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .topbar { padding: 0 .75rem; }
  .crumb { display: none; }
  .text-button { font-size: 0; width: 2.4rem; padding: 0; }
  .text-button::before { content: "↗"; font-size: 1rem; }
  main { padding: 1.25rem .9rem 2.5rem; }
  .topic-grid { grid-template-columns: 1fr; }
  .library-header h1 { font-size: 2.25rem; }
  .article-head { padding: 1.15rem; border-radius: 1rem; }
  .reading-time { width: 100%; margin-inline-start: 0; }
  .block-heading { padding: .75rem 1rem .7rem .85rem; }
  .block-copy { padding: 1rem 1.05rem 1.15rem; }
  .resource-box { grid-template-columns: 1fr; gap: .9rem; }
  .resource-list { justify-content: flex-start; }
  .article-outline { grid-template-columns: 1fr; margin-top: -.65rem; }
  .part-route small { display: none; }
  .article-nav { grid-template-columns: 1fr 1fr; }.article-nav .home { display: none; }
}
@media print {
  .sidebar, .topbar, .progress-track, .article-nav { display: none !important; }
  .app-shell { display: block; } main { padding: 0; width: 100%; }
  .content-block, .resource-box { break-inside: avoid; box-shadow: none; }
}
