/* ============================================================
   Al-Muqaddimah al-Jazariyyah
   RTL-first. Every size is drawn from the token scales below;
   no arbitrary spacing in the component rules.
   ============================================================ */

@font-face {
  font-family: 'Indopak';
  src: url('fonts/indopak.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Uthmanic';
  src: url('fonts/uthmanic.woff2') format('woff2');
  font-weight: 400; font-display: swap;
}

/* ============================================================
   Tokens
   ============================================================ */
:root {
  /* fonts */
  --font-ui: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-ar: 'Segoe UI', 'Noto Naskh Arabic', 'Geeza Pro', 'Tahoma', sans-serif;
  --font-display: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --font-quran: 'Indopak', 'Geeza Pro', 'Sakkal Majalla', serif;

  /* fluid type scale */
  --text-2xs: clamp(0.69rem, 0.67rem + 0.10vw, 0.75rem);
  --text-xs:  clamp(0.78rem, 0.75rem + 0.14vw, 0.86rem);
  --text-sm:  clamp(0.88rem, 0.84rem + 0.18vw, 0.98rem);
  --text-base:clamp(1rem, 0.95rem + 0.22vw, 1.13rem);
  --text-md:  clamp(1.13rem, 1.06rem + 0.30vw, 1.31rem);
  --text-lg:  clamp(1.27rem, 1.15rem + 0.50vw, 1.62rem);
  --text-xl:  clamp(1.6rem, 1.40rem + 0.85vw, 2.20rem);
  --text-2xl: clamp(2rem, 1.65rem + 1.50vw, 3.10rem);
  --text-3xl: clamp(2.4rem, 1.85rem + 2.45vw, 4.30rem);
  --verse-size: clamp(1.55rem, 1.20rem + 1.70vw, 2.80rem);

  /* fluid spacing scale */
  --sp-3xs: clamp(0.25rem, 0.23rem + 0.10vw, 0.31rem);
  --sp-2xs: clamp(0.5rem, 0.46rem + 0.18vw, 0.63rem);
  --sp-xs:  clamp(0.75rem, 0.70rem + 0.27vw, 0.94rem);
  --sp-s:   clamp(1rem, 0.93rem + 0.36vw, 1.25rem);
  --sp-m:   clamp(1.5rem, 1.39rem + 0.54vw, 1.88rem);
  --sp-l:   clamp(2rem, 1.86rem + 0.71vw, 2.5rem);
  --sp-xl:  clamp(3rem, 2.79rem + 1.07vw, 3.75rem);
  --sp-2xl: clamp(4rem, 3.71rem + 1.43vw, 5rem);
  --sp-3xl: clamp(5.5rem, 5.00rem + 2.50vw, 7.5rem);

  /* radii, structure, motion */
  --r-sm: 10px; --r-md: 16px; --r-lg: 24px; --r-pill: 999px;
  --nav-h: 3.75rem;
  --measure: 40rem;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dur: 0.5s;
  --ring: 0 0 0 3px color-mix(in srgb, var(--teal) 42%, transparent);

  --size-scale: 1;
}
[data-size='s']  { --size-scale: 0.9; }
[data-size='m']  { --size-scale: 1; }
[data-size='l']  { --size-scale: 1.12; }
[data-size='xl'] { --size-scale: 1.26; }

[data-script='uthmanic'] { --font-quran: 'Uthmanic', 'Geeza Pro', 'Sakkal Majalla', serif; }

/* ---- Light: pale marble ---- */
:root, [data-theme='light'] {
  --bg:        #f2eee6;
  --bg-2:      #eae4d8;
  --surface:   #fdfbf6;
  --surface-2: #f5f1e8;
  --ink:       #2b2318;
  --ink-soft:  #574a37;
  --muted:     #736550;
  --line:      #e2dac9;
  --line-soft: #ede7db;
  --teal:      #0f6b60;
  --teal-deep: #0a4d45;
  --gold:      #b0842f;
  --gold-soft: #cba85c;
  --gold-ink:  #8a6a1e;
  --shadow:    0 24px 60px -34px rgba(60, 44, 20, 0.4);
  --shadow-sm: 0 2px 10px -4px rgba(60, 44, 20, 0.28);
  --glow-gold: rgba(226, 200, 140, 0.24);
  --glow-teal: rgba(30, 120, 108, 0.05);
  --tess-ink: #6b5836;
  --tess-opacity: 0.035;
}

/* ---- Dark: deep warm night, lamplit gold & teal ---- */
[data-theme='dark'] {
  --bg:        #14110b;
  --bg-2:      #0c0a06;
  --surface:   #201b12;
  --surface-2: #1a160f;
  --ink:       #efe7d4;
  --ink-soft:  #d0c1a2;
  --muted:     #9c8d6f;
  --line:      #3a3021;
  --line-soft: #2a2317;
  --teal:      #57c9ba;
  --teal-deep: #39a494;
  --gold:      #e6c574;
  --gold-soft: #c39f4d;
  --gold-ink:  #e6c574;
  --shadow:    0 30px 70px -34px rgba(0, 0, 0, 0.85);
  --shadow-sm: 0 2px 14px -6px rgba(0, 0, 0, 0.7);
  --glow-gold: rgba(230, 197, 116, 0.11);
  --glow-teal: rgba(87, 201, 186, 0.10);
  --tess-ink: #e6c574;
  --tess-opacity: 0.032;
}

:root { --theme-fade: background-color var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease); }

/* ============================================================
   Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  scroll-padding-block-start: calc(var(--nav-h) + var(--sp-xs));
}
body {
  min-height: 100dvh;
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  transition: var(--theme-fade);
  overflow-x: hidden;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.15; font-weight: 600; text-wrap: balance; }
p { text-wrap: pretty; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }
svg { display: block; }
/* ring follows each element's own radius; transparent outline surfaces in forced-colors mode */
:focus-visible { outline: 2px solid transparent; outline-offset: 2px; box-shadow: var(--ring); }
::selection { background: color-mix(in srgb, var(--teal) 26%, transparent); }

/* geometric star marks, styled once, reused everywhere */
.s-square { fill: none; stroke: var(--gold); stroke-width: 4.4; stroke-linejoin: round; }
.s-oct { fill: var(--teal); opacity: 0.92; }
.s-dot { fill: var(--surface); }

/* ============================================================
   Ambience: glows + tessellation
   ============================================================ */
.ambience { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.glow { position: absolute; }
.glow-gold {
  inset-block-start: -22vmax; inset-inline: 0; margin-inline: auto;
  inline-size: min(92vw, 950px); block-size: 62vmax;
  background: radial-gradient(50% 50% at 50% 42%, var(--glow-gold) 0%, transparent 68%);
  transition: opacity var(--dur) var(--ease);
}
.glow-teal {
  inset-block-start: 16vmax; inset-inline-start: -14vmax;
  inline-size: 64vmax; block-size: 64vmax;
  background: radial-gradient(circle at 50% 50%, var(--glow-teal) 0%, transparent 66%);
  transition: opacity var(--dur) var(--ease);
}
.tessellation {
  position: absolute; inset: 0;
  opacity: var(--tess-opacity);
  background-color: var(--tess-ink);
  -webkit-mask-image: var(--tess-svg); mask-image: var(--tess-svg);
  -webkit-mask-size: 116px 116px; mask-size: 116px 116px;
  transition: opacity var(--dur) var(--ease);
}
:root {
  --tess-svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 96 96'%3E%3Cg fill='none' stroke='%23000' stroke-width='0.8' stroke-linejoin='round'%3E%3Cpath d='M28.12 0 L67.88 0 L96 28.12 L96 67.88 L67.88 96 L28.12 96 L0 67.88 L0 28.12 Z'/%3E%3Cpath d='M28.12 0 L96 67.88 L0 67.88 L67.88 0 L67.88 96 L0 28.12 L96 28.12 L28.12 96 Z'/%3E%3Cpath d='M41.79 33 L54.21 33 L63 41.79 L63 54.21 L54.21 63 L41.79 63 L33 54.21 L33 41.79 Z'/%3E%3C/g%3E%3C/svg%3E");
}

/* ============================================================
   Utility chrome
   ============================================================ */
main { position: relative; z-index: 1; }

.skip-link {
  position: fixed; inset-block-start: var(--sp-2xs); inset-inline-start: 50%;
  translate: -50% -160%; z-index: 60;
  background: var(--teal-deep); color: #fff;
  padding: var(--sp-2xs) var(--sp-s); border-radius: var(--r-pill);
  font-size: var(--text-xs); transition: translate 0.25s var(--ease);
}
.skip-link:focus-visible { translate: -50% 0; }

.reading-progress { position: fixed; inset-block-start: 0; inset-inline: 0; block-size: 3px; z-index: 55; }
#progress-fill {
  display: block; block-size: 100%; inline-size: 0%;
  background: linear-gradient(0.25turn in oklab, var(--gold), var(--teal));
}

/* ============================================================
   Topbar + controls
   ============================================================ */
.topbar {
  position: sticky; inset-block-start: 0; z-index: 40;
  block-size: var(--nav-h);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-s);
  padding-inline: clamp(var(--sp-xs), 2vw, var(--sp-l));
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(1.15) blur(14px);
  -webkit-backdrop-filter: saturate(1.15) blur(14px);
  border-block-end: 1px solid var(--line-soft);
  transition: var(--theme-fade);
}
.brand { display: inline-flex; align-items: center; gap: var(--sp-2xs); }
.brand-mark { inline-size: 2rem; block-size: 2rem; flex: none; }
.brand-mark .s-square { stroke-width: 4.8; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-family: var(--font-ar); font-size: var(--text-sm); font-weight: 700; }
.brand-text i { font-family: var(--font-display); font-style: italic; font-size: var(--text-2xs); color: var(--muted); letter-spacing: 0.04em; }

.controls { display: flex; align-items: center; gap: var(--sp-3xs); }
.nav-btn {
  display: inline-flex; align-items: center; gap: var(--sp-2xs);
  padding: var(--sp-2xs) var(--sp-xs);
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  color: var(--ink-soft);
  font-family: var(--font-ar); font-size: var(--text-xs);
  transition: background 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.15s var(--ease);
}
.nav-btn svg { inline-size: 1.25rem; block-size: 1.25rem; flex: none; stroke: currentColor; stroke-width: 1.75; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.nav-btn:hover { background: var(--surface-2); border-color: var(--line-soft); }
.nav-btn:active { transform: scale(0.95); }
.nav-btn[aria-pressed='true'] { background: var(--teal); color: #fff; border-color: var(--teal); }

.ico-moon { display: none; }
[data-theme='dark'] .ico-sun { display: none; }
[data-theme='dark'] .ico-moon { display: block; }

.icon-btn { display: inline-grid; place-items: center; inline-size: 2.25rem; block-size: 2.25rem; border-radius: var(--r-pill); color: var(--ink-soft); transition: background 0.2s var(--ease); }
.icon-btn svg { inline-size: 1.25rem; block-size: 1.25rem; stroke: currentColor; stroke-width: 1.9; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: var(--surface-2); }

/* collapse labels early, but keep a consistent icon-only row */
@media (max-width: 52rem) {
  .nav-btn span:not(.script-label) { display: none; }
  .nav-btn { padding: var(--sp-2xs); }
}
@media (max-width: 30rem) {
  .brand-text { display: none; }
  .script-label { display: none; }
}

/* ============================================================
   Drawer
   ============================================================ */
.scrim { position: fixed; inset: 0; z-index: 45; background: color-mix(in srgb, #000 45%, transparent); opacity: 0; transition: opacity 0.35s var(--ease); }
.scrim.show { opacity: 1; }

.drawer {
  position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 50;
  inline-size: min(88vw, 22rem);
  display: flex; flex-direction: column;
  padding: var(--sp-s);
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  box-shadow: var(--shadow);
  translate: 104% 0;
  transition: translate 0.42s var(--ease);
}
.drawer.open { translate: 0 0; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding-block-end: var(--sp-xs); border-block-end: 1px solid var(--line-soft); margin-block-end: var(--sp-2xs); }
.drawer-title { font-family: var(--font-ar); font-size: var(--text-md); font-weight: 700; }

.chapter-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.chapter-link {
  display: grid; grid-template-columns: 2rem 1fr auto; align-items: center; gap: var(--sp-xs);
  padding: var(--sp-2xs) var(--sp-xs); border-radius: var(--r-md); border: 1px solid transparent;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}
.chapter-link:hover { background: var(--surface-2); }
.chapter-link .num {
  display: grid; place-items: center; inline-size: 2rem; block-size: 2rem; border-radius: 50%;
  font-family: var(--font-ui); font-size: var(--text-xs); font-variant-numeric: tabular-nums;
  color: var(--teal-deep); background: color-mix(in srgb, var(--teal) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--teal) 24%, transparent);
}
.chapter-link .titles { display: flex; flex-direction: column; line-height: 1.25; min-inline-size: 0; }
.chapter-link .ar { font-family: var(--font-quran); font-size: var(--text-base); }
.chapter-link .en { font-family: var(--font-display); font-size: var(--text-xs); color: var(--muted); }
.chapter-link .range { font-size: var(--text-xs); color: var(--muted); font-variant-numeric: tabular-nums; direction: ltr; }
.chapter-link[aria-current='true'] { background: color-mix(in srgb, var(--teal) 12%, transparent); border-color: color-mix(in srgb, var(--teal) 34%, transparent); }
.chapter-link[aria-current='true'] .num { background: var(--teal); color: #fff; border-color: var(--teal); }

/* ============================================================
   Hero — one screen, full width, three columns
   ============================================================ */
.hero {
  min-block-size: calc(100svh - var(--nav-h));
  display: grid; place-items: center;
  padding-block: var(--sp-l) var(--sp-xl);
}
.hero-inner {
  display: grid;
  grid-template-columns: 1fr minmax(auto, 32rem) 1fr;
  align-items: center; gap: var(--sp-xl);
  inline-size: 100%; max-inline-size: 78rem;
  margin-inline: auto; padding-inline: var(--sp-m);
}
.hero-aside { max-inline-size: 20rem; direction: ltr; text-align: start; }
.hero-author { justify-self: start; }
.hero-poem { justify-self: end; }
.aside-h { font-family: var(--font-ar); font-size: var(--text-md); font-weight: 700; color: var(--ink); margin-block-end: var(--sp-2xs); }
.aside-h span { font-family: var(--font-display); font-style: italic; font-weight: 400; font-size: var(--text-sm); color: var(--muted); }
.hero-aside p { font-family: var(--font-display); font-size: var(--text-sm); line-height: 1.7; color: var(--ink-soft); }
.hero-aside i { color: var(--teal-deep); font-style: italic; }

.hero-center { display: flex; flex-direction: column; align-items: center; text-align: center; }
.hero-arch { inline-size: clamp(9rem, 20vw, 13rem); margin-block-end: var(--sp-s); }
.hero-arch svg { inline-size: 100%; block-size: auto; overflow: visible; }
.arch-line { fill: none; stroke-linecap: round; }
.arch-outer { stroke: var(--gold); stroke-width: 2.4; }
.arch-inner { stroke: var(--teal); stroke-width: 1.6; opacity: 0.9; }
.arch-base { stroke: var(--gold); stroke-width: 2.4; stroke-linecap: round; }
.arch-star .s-square { stroke-width: 5.5; }
.arch-star .s-dot { fill: var(--bg); }

.arch-line, .arch-base { stroke-dasharray: 640; stroke-dashoffset: 640; animation: draw 2s var(--ease) forwards; }
.arch-inner { animation-delay: 0.2s; }
.arch-base { animation-delay: 0.9s; animation-duration: 0.6s; }
.arch-star { opacity: 0; animation: pop 0.7s var(--ease) 1.2s forwards; transform-box: fill-box; transform-origin: center; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pop { from { opacity: 0; scale: 0.6; } to { opacity: 1; scale: 1; } }

.hero-eyebrow { font-size: var(--text-xs); letter-spacing: 0.04em; color: var(--teal-deep); margin-block-end: var(--sp-2xs); }
.hero-title { font-family: var(--font-quran); font-weight: 400; font-size: var(--text-3xl); line-height: 1.35; color: var(--ink); }
.hero-latin { font-family: var(--font-display); font-style: italic; font-size: var(--text-xl); color: var(--gold); margin-block-start: var(--sp-3xs); }
.hero-author-line { font-family: var(--font-ar); font-size: var(--text-sm); color: var(--muted); margin-block-start: var(--sp-2xs); }
.hero-author-line span { direction: ltr; font-variant-numeric: tabular-nums; }

.hero-meta { display: flex; justify-content: center; gap: var(--sp-l); margin-block: var(--sp-m); }
.hero-meta div { display: flex; flex-direction: column; align-items: center; }
.hero-meta dt { order: 2; font-size: var(--text-2xs); color: var(--muted); letter-spacing: 0.03em; }
.hero-meta dd { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 600; color: var(--teal-deep); font-variant-numeric: tabular-nums; }

.scroll-cue { display: inline-flex; flex-direction: column; align-items: center; gap: var(--sp-3xs); color: var(--muted); font-size: var(--text-xs); }
.scroll-cue svg { inline-size: 1.3rem; block-size: 1.3rem; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; animation: nudge 1.8s var(--ease) infinite; }
@keyframes nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(4px); } }

@media (max-width: 60rem) {
  .hero-inner { display: flex; flex-direction: column; gap: var(--sp-l); max-inline-size: 36rem; }
  .hero-center { order: -1; }
  .hero-aside { max-inline-size: 34rem; text-align: center; justify-self: center; }
  .hero-aside p { text-align: center; }
}

/* ============================================================
   Poem
   ============================================================ */
.poem { max-inline-size: min(62rem, 94vw); margin-inline: auto; padding-block-end: var(--sp-2xl); }
.loading { text-align: center; color: var(--muted); padding: var(--sp-2xl); font-family: var(--font-quran); }

.chapter { scroll-margin-block-start: calc(var(--nav-h) + var(--sp-xs)); }

/* compact geometric chapter divider */
.chapter-head {
  display: flex; align-items: center; gap: var(--sp-s);
  padding-block: var(--sp-xl) var(--sp-m);
}
.chapter-head .rule { flex: 1; block-size: 1px; background: linear-gradient(to var(--rule-dir, right), transparent, var(--line)); }
.chapter-head .rule.start { --rule-dir: left; }
.chapter-head .knot { inline-size: 1.4rem; block-size: 1.4rem; flex: none; }
.chapter-head .knot .s-square { stroke-width: 6; }
.chapter-head .titles { text-align: center; flex: none; }
.chapter-head h2 { font-family: var(--font-quran); font-weight: 400; font-size: var(--text-xl); color: var(--ink); }
.chapter-head .sub { font-family: var(--font-display); font-size: var(--text-xs); color: var(--muted); letter-spacing: 0.02em; }
.chapter-head .sub b { color: var(--teal-deep); font-weight: 600; font-style: italic; }
.chapter-head .sub .n { font-variant-numeric: tabular-nums; direction: ltr; }

/* verse */
.verse {
  position: relative;
  padding-block: var(--sp-s);
  padding-inline: var(--sp-xl);
  text-align: center;
}
.verse + .verse { border-block-start: 1px solid var(--line-soft); }

/* gentle reveal as each verse scrolls in */
.verse { opacity: 0; translate: 0 16px; }
.verse.in { opacity: 1; translate: 0 0; transition: opacity 0.55s var(--ease), translate 0.55s var(--ease); }

.verse-num {
  position: absolute; inset-block-start: var(--sp-s); inset-inline-start: 0;
  inline-size: 1.9rem; block-size: 1.9rem;
  display: grid; place-items: center; border-radius: 50%;
  font-family: var(--font-ui); font-size: var(--text-2xs); font-variant-numeric: tabular-nums;
  color: var(--muted); border: 1px solid var(--line);
  user-select: none; cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.verse-num:hover { color: var(--teal-deep); border-color: color-mix(in srgb, var(--teal) 42%, transparent); }

/* symmetric halves keep the separator on the true centre axis; the fit scales each
   hemistich to fit its half so the two never collide */
.hemistiches { display: grid; grid-template-columns: 1fr auto 1fr; align-items: baseline; column-gap: var(--sp-s); }
.hemi {
  font-family: var(--font-quran);
  font-size: calc(var(--verse-size) * var(--size-scale) * var(--vfit, 1));
  line-height: 2; color: var(--ink);
  min-inline-size: 0; white-space: nowrap;
  transition: color 0.3s var(--ease), filter 0.3s var(--ease);
}
.hemi.right { text-align: start; }
.hemi.left { text-align: end; }
[data-script='uthmanic'] .hemi { line-height: 2.2; }

.sep { justify-self: center; align-self: center; inline-size: 1.1rem; block-size: 1.1rem; flex: none; }
.sep .s-square { stroke: var(--gold); stroke-width: 6; }

.verse-en {
  max-inline-size: var(--measure); margin: var(--sp-2xs) auto 0;
  font-family: var(--font-display); font-size: calc(var(--text-sm) * var(--size-scale));
  line-height: 1.65; color: var(--muted); direction: ltr;
}

@media (max-width: 40rem) {
  .verse { padding-inline: var(--sp-s); }
  .verse-num { position: static; margin-inline: auto; margin-block-end: var(--sp-2xs); }
  .hemistiches { grid-template-columns: 1fr; gap: var(--sp-3xs); }
  .hemi.left, .hemi.right { text-align: center; }
  .sep { rotate: 90deg; inline-size: 0.9rem; block-size: 0.9rem; margin: var(--sp-3xs) auto; }
}

/* ============================================================
   Memorisation mode
   ============================================================ */
[data-memorise='true'] .verse { cursor: pointer; }
[data-memorise='true'] .hemi.left { filter: blur(9px); color: color-mix(in srgb, var(--ink) 55%, transparent); user-select: none; }
[data-memorise='true'] .verse.revealed .hemi.left { filter: blur(0); color: var(--ink); }
[data-memorise='true'] .verse-en { filter: blur(6px); transition: filter 0.3s var(--ease); }
[data-memorise='true'] .verse.revealed .verse-en { filter: blur(0); }
[data-memorise='true'] .verse:not(.revealed) { background: color-mix(in srgb, var(--teal) 6%, transparent); }

.toast {
  position: fixed; inset-block-end: var(--sp-s); inset-inline: 0; margin-inline: auto;
  inline-size: max-content; max-inline-size: 90vw; z-index: 42;
  padding: var(--sp-2xs) var(--sp-s); background: var(--teal-deep); color: #fff;
  border-radius: var(--r-pill); font-family: var(--font-ar); font-size: var(--text-xs);
  box-shadow: var(--shadow); opacity: 0; translate: 0 140%;
  transition: opacity 0.35s var(--ease), translate 0.35s var(--ease); pointer-events: none;
}
.toast.show { opacity: 1; translate: 0 0; }

/* ============================================================
   Footer + back-to-top
   ============================================================ */
.site-footer { text-align: center; padding: var(--sp-2xl) var(--sp-s) var(--sp-xl); border-block-start: 1px solid var(--line-soft); }
.footer-knot { inline-size: 2rem; block-size: 2rem; margin-inline: auto; margin-block-end: var(--sp-s); }
.footer-ayah { font-family: var(--font-quran); font-size: var(--text-lg); color: var(--teal-deep); line-height: 2; }
.footer-sub { font-size: var(--text-xs); color: var(--muted); margin-block-start: var(--sp-2xs); direction: ltr; letter-spacing: 0.05em; }

.to-top {
  position: fixed; inset-block-end: var(--sp-s); inset-inline-end: var(--sp-s); z-index: 41;
  display: grid; place-items: center; inline-size: 2.9rem; block-size: 2.9rem; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--teal-deep);
  box-shadow: var(--shadow); opacity: 0; translate: 0 120%; visibility: hidden;
  transition: opacity 0.3s var(--ease), translate 0.3s var(--ease), visibility 0.3s var(--ease), background 0.2s var(--ease);
}
.to-top svg { inline-size: 1.3rem; block-size: 1.3rem; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.to-top.show { opacity: 1; translate: 0 0; visibility: visible; }
.to-top:hover { background: var(--surface-2); }

/* ============================================================
   Switchable variant words
   ============================================================ */
.var {
  font: inherit; color: inherit; padding: 0 0.05em; cursor: pointer; position: relative;
  text-decoration: underline; text-decoration-style: dotted;
  text-underline-offset: 0.16em; border-radius: 6px;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}
.var-alt   { color: var(--teal-deep); text-decoration-color: color-mix(in srgb, var(--teal) 55%, transparent); }
.var-print { color: var(--gold-ink);  text-decoration-color: color-mix(in srgb, var(--gold-ink) 55%, transparent); }
.var:hover { background: color-mix(in srgb, currentColor 12%, transparent); }
.var.is-alt { text-decoration-style: solid; background: color-mix(in srgb, currentColor 10%, transparent); }

.variant-legend {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: var(--sp-2xs) var(--sp-m);
  max-inline-size: var(--measure); margin: var(--sp-l) auto 0; padding: var(--sp-2xs) var(--sp-s);
  font-family: var(--font-ar); font-size: var(--text-xs); color: var(--muted); text-align: center;
}
.variant-legend .lead { flex: 1 1 100%; }
.variant-legend .keys { display: inline-flex; gap: var(--sp-s); }
.variant-legend .key { display: inline-flex; align-items: center; gap: var(--sp-3xs); }
.variant-legend .key i { inline-size: 0.7rem; block-size: 0.7rem; border-radius: 3px; }
.variant-legend .k-alt { background: var(--teal-deep); }
.variant-legend .k-print { background: var(--gold); }

/* ============================================================
   About dialog + text links
   ============================================================ */
.hero-about {
  margin-block-start: var(--sp-2xs); font-family: var(--font-ar); font-size: var(--text-xs);
  color: var(--teal-deep);
  border-block-end: 1px solid color-mix(in srgb, var(--teal) 40%, transparent); padding-block-end: 1px;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.hero-about:hover { color: var(--teal); border-color: var(--teal); }

.footer-links { margin-block-start: var(--sp-xs); }
.link { color: var(--teal-deep); font-family: var(--font-ar); font-size: var(--text-xs); text-decoration: underline; text-underline-offset: 2px; }
.link:hover { color: var(--teal); }

dialog.about {
  margin: auto; inline-size: min(42rem, 92vw); max-block-size: 88vh; padding: 0;
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow); overflow: clip;
}
dialog.about::backdrop { background: color-mix(in srgb, #000 55%, transparent); backdrop-filter: blur(3px); }
.about-body { padding: var(--sp-l); overflow-y: auto; max-block-size: 88vh; direction: ltr; text-align: start; }
.about-mark { inline-size: 2.4rem; block-size: 2.4rem; margin-inline: auto; margin-block-end: var(--sp-xs); }
.about h2 { font-family: var(--font-quran); font-weight: 400; font-size: var(--text-xl); text-align: center; }
.about-lede { text-align: center; font-family: var(--font-display); font-style: italic; color: var(--muted); margin-block-end: var(--sp-m); }
.about h3 { font-family: var(--font-display); font-size: var(--text-md); color: var(--teal-deep); margin-block: var(--sp-m) var(--sp-2xs); }
.about p { font-family: var(--font-display); font-size: var(--text-sm); line-height: 1.75; color: var(--ink-soft); margin-block-end: var(--sp-xs); }
.about i { color: var(--teal-deep); font-style: italic; }
.about b { color: var(--ink); font-weight: 600; }
.about-note { font-size: var(--text-xs) !important; color: var(--muted) !important; border-block-start: 1px solid var(--line-soft); padding-block-start: var(--sp-s); margin-block-start: var(--sp-s); }
.about-close {
  position: absolute; inset-block-start: var(--sp-xs); inset-inline-end: var(--sp-xs); z-index: 2;
  display: grid; place-items: center; inline-size: 2.25rem; block-size: 2.25rem; border-radius: 50%;
  color: var(--muted); background: var(--surface); transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.about-close svg { inline-size: 1.25rem; block-size: 1.25rem; stroke: currentColor; stroke-width: 1.9; fill: none; stroke-linecap: round; }
.about-close:hover { background: var(--surface-2); color: var(--ink); }

/* ============================================================
   Performance & scroll ergonomics
   ============================================================ */
html { scrollbar-gutter: stable; }
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted) 55%, transparent) transparent; }
/* chapters below the fold skip rendering until near the viewport */
.chapter { content-visibility: auto; contain-intrinsic-size: auto 40rem; }
.verse { scroll-margin-block-start: calc(var(--nav-h) + var(--sp-s)); }

/* deep-linked or copied verse: brief flash + native text-fragment highlight */
.verse:target, .verse.flash { animation: verse-flash 2.4s var(--ease); }
@keyframes verse-flash {
  0%, 100% { background: transparent; }
  12% { background: color-mix(in srgb, var(--teal) 14%, transparent); }
}
::target-text { background: color-mix(in srgb, var(--gold) 32%, transparent); color: inherit; }

/* ============================================================
   Per-verse tools (permalink · copy · share)
   ============================================================ */
/* tools live in the number gutter so they never overlap the centred couplet */
.verse-tools {
  position: absolute; inset-inline-start: 0; inset-block-start: calc(var(--sp-s) + 2.3rem);
  display: flex; flex-direction: column; gap: var(--sp-3xs);
  opacity: 0; transition: opacity 0.2s var(--ease);
}
.verse:hover .verse-tools, .verse:focus-within .verse-tools { opacity: 1; }
@media (hover: none) { .verse-tools { opacity: 0.5; } }
.verse-tool {
  display: grid; place-items: center; inline-size: 1.9rem; block-size: 1.9rem;
  border-radius: 50%; color: var(--muted); background: color-mix(in srgb, var(--surface) 70%, transparent);
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.verse-tool svg { inline-size: 1rem; block-size: 1rem; stroke: currentColor; stroke-width: 1.9; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.verse-tool:hover { color: var(--teal-deep); background: var(--surface-2); }
@media (max-width: 40rem) {
  .verse-tools { position: static; flex-direction: row; justify-content: center; margin-block-start: var(--sp-2xs); opacity: 0.5; }
}

/* ============================================================
   Drawer search
   ============================================================ */
.drawer-search {
  display: flex; align-items: center; gap: var(--sp-2xs);
  margin-block-end: var(--sp-2xs); padding-inline: var(--sp-xs);
  border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface-2);
}
.drawer-search svg { inline-size: 1.1rem; block-size: 1.1rem; flex: none; stroke: var(--muted); stroke-width: 1.9; fill: none; stroke-linecap: round; }
.drawer-search input {
  flex: 1; min-inline-size: 0; border: 0; background: none; color: var(--ink);
  font-family: var(--font-ar); font-size: var(--text-sm); padding-block: var(--sp-2xs);
}
.drawer-search input:focus { outline: none; }
.drawer-search:focus-within { border-color: color-mix(in srgb, var(--teal) 45%, transparent); box-shadow: var(--ring); }
.drawer-empty { text-align: center; color: var(--muted); font-family: var(--font-ar); font-size: var(--text-sm); padding: var(--sp-m) 0; }
.chapter-link[hidden] { display: none; }

/* ============================================================
   Footer colophon / duʿāʾ request
   ============================================================ */
.footer-dua {
  max-inline-size: 34rem; margin: var(--sp-s) auto 0;
  font-family: var(--font-display); font-size: var(--text-sm); line-height: 1.7; color: var(--ink-soft);
}
.footer-dua a, .footer-links a { color: var(--teal-deep); text-decoration: underline; text-underline-offset: 2px; }
.footer-dua a:hover, .footer-links a:hover { color: var(--teal); }
.footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-s); align-items: center; }

/* ============================================================
   Dialog entry animation (progressive)
   ============================================================ */
dialog.about { opacity: 0; translate: 0 1rem; transition: opacity 0.3s var(--ease), translate 0.3s var(--ease), overlay 0.3s allow-discrete, display 0.3s allow-discrete; }
dialog.about[open] { opacity: 1; translate: 0 0; }
@starting-style { dialog.about[open] { opacity: 0; translate: 0 1rem; } }

/* ============================================================
   Extra user-preference refinements
   ============================================================ */
@media (prefers-reduced-transparency: reduce) {
  .topbar { background: var(--surface); backdrop-filter: none; }
  dialog.about::backdrop { backdrop-filter: none; }
  .verse-tool { background: var(--surface-2); }
}
@media (prefers-contrast: more) {
  :root { --line: var(--muted); --line-soft: var(--muted); }
  .var { text-decoration-thickness: 2px; }
}

/* comfortable touch targets on coarse pointers (Lighthouse tap-target audit) */
@media (pointer: coarse) {
  .nav-btn { min-block-size: 2.75rem; }
  .icon-btn { inline-size: 2.75rem; block-size: 2.75rem; }
  .verse-tool { inline-size: 2.6rem; block-size: 2.6rem; }
  .verse-num { min-inline-size: 2.5rem; min-block-size: 2.5rem; }
  .drawer-close { inline-size: 2.75rem; block-size: 2.75rem; }
}

/* ============================================================
   Motion preferences
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .verse { opacity: 1; translate: none; }
  .arch-line, .arch-base { stroke-dashoffset: 0; }
  .arch-star { opacity: 1; }
}

/* ============================================================
   Print — clean the poem onto paper, drop all chrome
   ============================================================ */
@media print {
  .topbar, .drawer, .scrim, .reading-progress, .to-top, .ambience,
  .verse-tools, .scroll-cue, .variant-legend, .skip-link, dialog.about, .hero-arch { display: none !important; }

  html, body { background: #fff; color: #000; }
  main { z-index: auto; }
  /* force every chapter to render — content-visibility would drop off-screen ones */
  .chapter { content-visibility: visible !important; contain-intrinsic-size: auto !important; break-before: page; }
  .chapter:first-of-type { break-before: avoid; }

  .hero { min-block-size: auto; padding-block: 0 var(--sp-m); }
  .hero-inner { display: block; }
  .hero-aside { display: none; }

  .verse { opacity: 1 !important; translate: none !important; break-inside: avoid; padding-inline: 0; }
  .verse-num { position: static; margin: 0 auto var(--sp-2xs); color: #555; border-color: #bbb; }
  .hemi { color: #000; }
  .verse-en { color: #333; }
  .var { color: #000; text-decoration-color: #999; }
  a { color: #000; }
  .chapter-head .rule { background: #ccc; }
  .footer-ayah, .chapter-head h2, .hero-title { color: #000; }
}
