/* Manuscript: a codex read by lamplight. Umber ground, ruled leaf, amber lamp, red-ochre rubrication.
   Dark only by design (color-scheme: dark); no theme toggle. */

:root {
  color-scheme: dark;
  --bg: #1a120c;
  --bg-2: #211710;
  --panel: #241911;
  --ink: #eadcc2;
  --ink-hi: #f8ecd4;
  --ink-2: #c7b597;
  --ink-3: #a8957a;
  --amber: #e9b264;
  --amber-hi: #f6cf8e;
  --gold: #c9a063;
  --rubric: #d9785a;
  --line: rgba(214, 172, 108, .2);
  --line-2: rgba(214, 172, 108, .38);
  --rule: rgba(236, 208, 160, .045);

  --display: "Cormorant Garamond", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --text: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --quran: "Amiri Quran", "Amiri", "Scheherazade New", serif;
  --arabic: "Amiri", "Amiri Quran", serif;

  --measure: 40rem; /* ~70 characters of 19px Source Serif 4; rem so headings and quotes share one text edge */
  --margin: 13.5rem;
  --gutter: 3rem;
  --lh: 1.68;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 2rem; }

/* The leaf: faint mistara ruling + paper grain, lit by a lamp from above (body::before). */
body {
  position: relative;
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .92 0 0 0 0 .78 0 0 0 0 .55 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    repeating-linear-gradient(to bottom, transparent 0 calc(2.1rem - 1px), var(--rule) calc(2.1rem - 1px) 2.1rem);
  color: var(--ink);
  font: 400 1.1875rem/var(--lh) var(--text);
  font-optical-sizing: auto;
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
  overflow-x: hidden;
}
/* Lamp: a warm pool of light at the head of the page; breathes very slowly (static under reduced motion). */
body::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 68rem;
  background:
    radial-gradient(ellipse 46rem 30rem at 50% 6rem, rgba(244, 176, 88, .20), transparent 70%),
    radial-gradient(ellipse 90rem 52rem at 50% 0, rgba(196, 110, 52, .10), transparent 75%);
  pointer-events: none; z-index: 0;
}
/* Vignette: the edges of the leaf fall into shadow. Fixed, no blending, so scrolling stays cheap. */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(ellipse 120% 90% at 50% 35%, transparent 55%, rgba(8, 4, 2, .55));
}
body > * { position: relative; z-index: 1; }

a { color: var(--amber); text-decoration-line: underline; text-decoration-color: rgba(233, 178, 100, .38); text-decoration-thickness: 1px; text-underline-offset: .2em; transition: color .25s, text-decoration-color .25s; }
a:hover { color: var(--amber-hi); text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--amber-hi); outline-offset: 3px; border-radius: 2px; }
::selection { background: rgba(217, 120, 90, .4); color: var(--ink-hi); }
[lang="ar"] { font-family: var(--arabic); font-feature-settings: normal; font-variant-numeric: normal; }
strong, b { font-weight: 600; }
svg.orn { display: block; width: 16rem; max-width: 70%; height: auto; margin-inline: auto; color: var(--gold); }

.skip { position: absolute; left: 1rem; top: -4rem; z-index: 50; padding: .7rem 1rem; background: var(--amber); color: var(--bg); font-weight: 600; text-decoration: none; }
.skip:focus { top: 1rem; color: var(--bg); }

/* ---------- Header ---------- */
.wrap { max-width: 82rem; margin-inline: auto; padding-inline: clamp(1rem, 4vw, 2.5rem); }
.head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding-block: 1.5rem; }
.wordmark { font: italic 600 1.45rem/1 var(--display); color: var(--ink-hi); text-decoration: none; letter-spacing: .01em; }
.wordmark:hover { color: var(--amber-hi); }
.site-nav ul { list-style: none; display: flex; gap: clamp(1rem, 3vw, 2.25rem); }
.site-nav a { font-size: .74rem; font-weight: 500; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-2); text-decoration: none; }
.site-nav a:hover { color: var(--amber-hi); }

/* ---------- Title page ---------- */
.page-head { text-align: center; padding: clamp(3.5rem, 9vw, 7.5rem) clamp(1rem, 5vw, 3rem) clamp(3.5rem, 8vw, 6.5rem); max-width: 64rem; margin-inline: auto; }
.page-head .orn { margin-bottom: clamp(2rem, 4vw, 3rem); }
h1 {
  font: 500 clamp(2.9rem, 8.2vw, 7rem)/.98 var(--display);
  letter-spacing: -.012em; color: var(--ink-hi);
  text-shadow: 0 0 2.5rem rgba(244, 176, 88, .22);
  text-wrap: balance;
}
h1 .l1, h1 .l2 { display: block; }
h1 .l2 { font-style: italic; font-weight: 400; color: var(--amber-hi); }
h1 .stop { color: var(--rubric); font-style: normal; }
.dek { max-width: 38em; margin: clamp(1.75rem, 3.5vw, 2.5rem) auto 0; font-size: clamp(1.08rem, 1.6vw, 1.28rem); line-height: 1.55; font-style: italic; color: var(--ink-2); text-wrap: pretty; }
.byline { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .55rem 1.1rem; margin-top: 2.25rem; font-size: .74rem; font-weight: 500; letter-spacing: .15em; text-transform: uppercase; color: var(--ink-2); }
.byline > * + *::before { content: ""; display: inline-block; width: .32rem; height: .32rem; margin-inline-end: 1.1rem; vertical-align: .18em; background: var(--rubric); transform: rotate(45deg); }

/* ---------- Layout: contents rail | text block | margin ---------- */
.article-grid { max-width: 82rem; margin-inline: auto; padding: 0 clamp(1rem, 4vw, 2.5rem) 4rem; }
.prose { font-size: 1.1875rem; }
.prose > * { max-width: var(--measure); }

/* ---------- Contents ---------- */
.toc { margin-bottom: 3rem; }
.toc-d { border-block: 1px solid var(--line); }
.toc summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; padding-block: .9rem; }
.toc summary::-webkit-details-marker { display: none; }
.toc summary::after { content: ""; width: .5rem; height: .5rem; border: solid var(--gold); border-width: 0 1px 1px 0; transform: rotate(45deg) translateY(-.15rem); transition: transform .3s; }
.toc-d[open] summary::after { transform: rotate(-135deg); }
.toc h2 { font-size: .72rem; font-weight: 500; letter-spacing: .2em; text-transform: uppercase; color: var(--gold); }
.toc ol { list-style: upper-roman; padding: 0 0 1rem 2.2rem; font-size: .95rem; }
.toc li { padding-block: .28rem; line-height: 1.35; }
.toc li::marker { font: italic 600 1rem var(--display); color: var(--rubric); }
.toc li.toc-end { list-style: none; margin-top: .5rem; }
.toc a { color: var(--ink-2); text-decoration: none; }
.toc a:hover, .toc a[aria-current="true"] { color: var(--amber-hi); }
.toc a[aria-current="true"] { text-shadow: 0 0 .9rem rgba(244, 176, 88, .45); }

/* ---------- Text ---------- */
.prose p { margin-top: 1.15em; text-wrap: pretty; hanging-punctuation: first; }
.prose > p:first-child { margin-top: 0; }
.prose h2 {
  position: relative; counter-increment: sec;
  margin-top: 5.5rem; padding-top: 3.25rem;
  font: 500 clamp(1.95rem, 3.4vw, 2.6rem)/1.08 var(--display);
  color: var(--ink-hi); letter-spacing: -.005em; text-wrap: balance;
}
.prose { counter-reset: sec; }
.prose > h2:first-child { margin-top: 0; }
/* Section opener: a gold ruled band with a rubricated numeral, as in a codex chapter head. */
.prose h2::before {
  content: counter(sec, upper-roman);
  position: absolute; top: 0; left: 0;
  font: italic 600 1.05rem/1 var(--display); letter-spacing: .03em; color: var(--rubric);
  padding-right: .9rem; background: transparent;
}
.prose h2::after {
  content: ""; position: absolute; top: .52rem; left: 2.6rem; right: 0; height: 4px;
  border-block: 1px solid var(--line-2); opacity: .8;
}
.prose h3 { margin-top: 3rem; font: italic 500 clamp(1.4rem, 2.3vw, 1.65rem)/1.2 var(--display); color: var(--amber-hi); text-wrap: balance; }
.prose h2 + p, .prose h3 + p { margin-top: 1.1rem; }
/* Opening paragraph: rubricated initial. */
.lead::first-letter { float: left; font: 600 4.4em/.78 var(--display); color: var(--rubric); margin: .1em .12em 0 0; text-shadow: 0 0 1.4rem rgba(217, 120, 90, .3); }
.prose p > [lang="ar"] { font-size: 1.15em; color: var(--amber-hi); }

/* ---------- The verse: a framed page of a mushaf ---------- */
.verse {
  position: relative; max-width: 50rem !important; margin: 3.25rem auto 3.5rem;
  padding: clamp(3rem, 6vw, 4.25rem) clamp(1.25rem, 5vw, 4rem) clamp(2rem, 4vw, 2.75rem);
  text-align: center;
  background:
    radial-gradient(ellipse 80% 70% at 50% 0, rgba(244, 176, 88, .09), transparent 75%),
    linear-gradient(var(--panel), var(--bg-2));
  border: 1px solid var(--line-2);
  outline: 1px solid var(--line); outline-offset: -9px;
  box-shadow: 0 1.5rem 4rem -1.5rem rgba(0, 0, 0, .6), inset 0 0 0 1px rgba(0, 0, 0, .25);
}
/* Rosette bosses that sit on the frame, top and bottom. */
.verse::before, .verse::after {
  content: ""; position: absolute; left: 50%; width: 2.6rem; height: 2.6rem; margin-left: -1.3rem;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-21 -21 42 42' fill='none' stroke='%23c9a063' stroke-width='1.1'%3E%3Crect x='-10' y='-10' width='20' height='20'/%3E%3Crect x='-10' y='-10' width='20' height='20' transform='rotate(45)'/%3E%3Ccircle r='4.5' fill='%23d9785a' stroke='none'/%3E%3Ccircle r='18' stroke-opacity='.5'/%3E%3C/svg%3E") center / 100% no-repeat;
  border-radius: 50%;
}
.verse::before { top: -1.3rem; }
.verse::after { bottom: -1.3rem; }
.verse p[lang="ar"] {
  font-family: var(--quran); font-size: clamp(1.75rem, 3.6vw, 2.65rem); line-height: 2.25;
  color: #f3dcae; text-shadow: 0 0 1.8rem rgba(244, 176, 88, .18);
  text-wrap: balance; word-spacing: .04em;
}
.verse .tr { max-width: 44ch; margin: 1.6rem auto 0; padding-top: 1.5rem; font-style: italic; font-size: 1.08rem; line-height: 1.6; color: var(--ink-2); position: relative; }
.verse .tr::before { content: ""; position: absolute; top: 0; left: 50%; width: 4.5rem; margin-left: -2.25rem; border-top: 1px solid var(--line-2); }
.verse .tr strong { color: var(--ink-hi); font-style: italic; }
.verse figcaption { display: flex; flex-wrap: wrap; justify-content: center; gap: .3rem 1rem; margin-top: 1.6rem; font-size: .72rem; letter-spacing: .15em; text-transform: uppercase; color: var(--ink-3); }
.verse figcaption > * + *::before { content: ""; display: inline-block; width: .28rem; height: .28rem; margin-inline-end: 1rem; vertical-align: .2em; background: var(--rubric); transform: rotate(45deg); }

/* ---------- Quoted sources: marginalia head + quote. One recipe for all ~40 blocks. ---------- */
.hadith { margin-top: 2.4rem; }
.hadith + .hadith { margin-top: 2.6rem; }
.hadith-head { display: block; margin-bottom: .7rem; line-height: 1.3; }
.who { font: 600 1.18rem/1.2 var(--display); color: var(--ink-hi); letter-spacing: .005em; }
.who .d { margin-left: .35rem; font: italic 400 .84rem/1 var(--text); letter-spacing: .02em; color: var(--rubric); white-space: nowrap; }
.work { display: block; margin-top: .2rem; font-style: italic; font-size: .86rem; color: var(--ink-3); }
.work a { font-style: normal; font-variant-numeric: lining-nums; white-space: nowrap; }
.hadith blockquote { padding-left: 1.3rem; border-left: 1px solid rgba(217, 120, 90, .55); color: var(--ink-2); font-size: 1.06rem; line-height: 1.66; }
.hadith blockquote p { margin-top: .75em; }
.hadith blockquote p:first-child { margin-top: 0; }
.hadith blockquote strong { font-weight: 500; color: var(--ink-hi); }
.hadith blockquote em { font-style: italic; color: var(--rubric); font-size: .92em; }
.hadith blockquote p[lang="ar"] { font-size: 1.6rem; line-height: 1.9; color: #f3dcae; }
.hadith .note { margin: 0 0 .6rem; padding-left: 1.3rem; font-style: italic; font-size: .95rem; line-height: 1.55; color: var(--ink-3); }
.hadith blockquote + .note { margin: .7rem 0 0; }
.hadith .note strong { color: var(--ink-2); }

/* Reference lists (later scholars, sources) */
.refs { list-style: none; margin-top: 1.4rem; font-size: .98rem; line-height: 1.5; }
.refs li { padding: .62rem 0; border-bottom: 1px solid var(--line); color: var(--ink-3); }
.refs li:first-child { border-top: 1px solid var(--line); }
.refs b { font: 600 1.08rem/1.3 var(--display); color: var(--ink-hi); }

/* ---------- Sources ---------- */
.end-section { max-width: none !important; margin-top: 6rem; padding-top: 3rem; border-top: 1px solid var(--line-2); }
.end-section h2 { margin: 0; padding: 0; font: 500 clamp(1.95rem, 3.4vw, 2.6rem)/1.1 var(--display); color: var(--ink-hi); counter-increment: none; }
.end-section h2::before { content: none; }
.end-section h2::after { content: none; }
.end-section .refs { counter-reset: src; font-size: .9rem; }
.end-section .refs li { counter-increment: src; padding-left: 2.1rem; text-indent: -2.1rem; break-inside: avoid; }
.end-section .refs li::before { content: counter(src); display: inline-block; width: 2.1rem; text-indent: 0; font: italic 600 .95rem/1 var(--display); color: var(--rubric); }
.end-section .refs b { font-size: 1rem; }
.orig { margin-top: 2.25rem !important; font-style: italic; color: var(--ink-3); font-size: .95rem; }

/* ---------- Colophon ---------- */
.site-foot { margin-top: 3rem; padding: 4rem 1rem 3.5rem; text-align: center; font-size: .72rem; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); }
.site-foot .orn { width: 11rem; margin-bottom: 1.75rem; opacity: .8; }
.site-foot p + p { margin-top: .6rem; }

/* ---------- Wide: rail + text + margin ---------- */
@media (min-width: 64rem) {
  .article-grid { display: grid; grid-template-columns: 13.5rem minmax(0, 1fr); column-gap: clamp(3rem, 5vw, 5.5rem); align-items: start; }
  .toc { position: sticky; top: 2rem; margin: 0; max-height: calc(100vh - 4rem); overflow-y: auto; }
  .toc-d { border: 0; }
  .toc summary { pointer-events: none; padding-top: 0; }
  .toc summary::after { display: none; }
  .toc ol { padding-left: 1.9rem; border-left: 1px solid var(--line); margin-left: .1rem; font-size: .9rem; }
  .toc li { padding-block: .34rem; }
  .end-section .refs { columns: 2; column-gap: 3rem; }
  .end-section .refs li:first-child { border-top: 0; }
}

/* Wide enough for marginalia: scholar and reference move into the outer margin, beside the quote. */
@media (min-width: 84rem) {
  .prose { display: grid; grid-template-columns: minmax(0, var(--measure)) var(--margin); column-gap: var(--gutter); align-content: start; }
  .prose > * { grid-column: 1; }
  .prose > .verse, .prose > .end-section { grid-column: 1 / -1; }
  .prose h2::before { left: auto; right: calc(100% + 1.25rem); top: -.5rem; font-size: 2.1rem; padding: 0; }
  .prose h2::after { left: 0; }
  .hadith { grid-column: 1 / -1 !important; display: grid; grid-template-columns: minmax(0, var(--measure)) var(--margin); column-gap: var(--gutter); max-width: none; }
  .hadith > * { grid-column: 1; }
  .hadith-head { grid-column: 2; grid-row: 1 / span 3; align-self: start; margin: 0; padding: .15rem 0 .2rem 1.1rem; border-left: 1px solid var(--line-2); }
  .who .d { display: block; margin: .3rem 0 0; }
  .work { margin-top: .45rem; }
  .hadith .note + blockquote { margin-top: 0; }
}

/* ---------- Motion: slow lamp breath + gentle reveal; all of it off under reduced motion ---------- */
@media (prefers-reduced-motion: no-preference) {
  body::before { animation: lamp 9s ease-in-out infinite alternate; }
  @keyframes lamp { from { opacity: .82; } to { opacity: 1; } }
  .io [data-reveal] { opacity: 0; transform: translateY(.6rem); transition: opacity 1.1s ease, transform 1.1s ease; }
  .io [data-reveal].in { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  body { background: #fff; color: #000; }
  body::before, body::after, .site-head, .skip, .toc, .site-foot { display: none !important; }
  a { color: #000; }
}
