/* ==========================================================================
   Sharh Mi'ata 'Amil — Study Companion
   styles.css — mobile-first; two-column reading layout at >= 1024px.

   Theming: two independent axes, persisted in localStorage and set on
   <html> as data-palette and data-color-scheme.
     data-palette      : "mono" (default, black & white) | "green" (green & gold)
     data-color-scheme : "light" (default) | "dark"
   Default :root holds black/white + light. [data-palette="green"] overrides
   the palette. [data-color-scheme="dark"] overrides light→dark. Combined
   selector handles green+dark. Token names --green / --gold are retained
   across all palettes for compatibility. --green-surface is the dark
   surface colour for accent backgrounds (topbar, primary buttons); it
   stays dark even in dark mode, while --green flips bright for text.
   Constraint: .topbar must not get transform/filter/backdrop-filter/contain,
   because the mobile tab bar (position: fixed) is a child of it.
   ========================================================================== */

/* ---------- Palette: Black & White, Light (default) ---------- */
:root {
  --green: #0A0A0A;
  --green-surface: #0A0A0A;
  --green-600: #262626;
  --green-100: #E0E0E0;
  --green-50: #F0F0F0;
  --gold: #0A0A0A;
  --gold-ink: #0A0A0A;
  --gold-50: #F0F0F0;
  --gold-line: #E0E0E0;
  --bg: #FFFFFF;
  --surface: #F7F7F7;
  --text: #0A0A0A;
  --muted: #6B6B6B;
  --border: #E5E5E5;
  --border-strong: #999999;
  --danger: #C62828;
  --danger-50: #FBECEC;
  --danger-line: #E8B0B0;
  --ok-50: #EBEBEB;
  --on-green: #B8B8B8;
  --font-ar: "Amiri", "Noto Naskh Arabic", "Scheherazade New", "Geeza Pro", "Traditional Arabic", serif;
  --font-en: "Inter", "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --maxw: 72rem;
  --gutter: 1rem;
  --tabbar-h: 3.5rem;
  --topbar-h: 3.5rem;
  --sidebar-w: 19.5rem;
  --radius: 14px;
  color-scheme: light;
}

/* ---------- Palette override: Green & Gold, Light ---------- */
:root[data-palette="green"] {
  --green: #0B3D2E;
  --green-surface: #0B3D2E;
  --green-600: #155543;
  --green-100: #D3E5DC;
  --green-50: #EAF2EE;
  --gold: #C9A227;
  --gold-ink: #7A5C00;
  --gold-50: #F7F0D6;
  --gold-line: #E3D390;
  --bg: #FAF8F3;
  --surface: #FFFFFF;
  --text: #1F2937;
  --muted: #4B5563;
  --border: #DDD8C9;
  --border-strong: #8A8472;
  --danger: #9B1C1C;
  --danger-50: #FBECEC;
  --danger-line: #E4B8B8;
  --ok-50: #E3F1EA;
  --on-green: #D9E6E0;
}

/* ---------- Dark scheme — shared neutral overrides ---------- */
:root[data-color-scheme="dark"] {
  --bg: #0A0A0A;
  --surface: #1A1A1A;
  --text: #F0F0F0;
  --muted: #909090;
  --border: #2A2A2A;
  --border-strong: #555555;
  --danger: #E57373;
  --danger-50: #2E1A1A;
  --danger-line: #5A2828;
  --ok-50: #2A2A2A;
  --on-green: #B8B8B8;
  color-scheme: dark;
}

/* ---------- Black & White, Dark ---------- */
:root[data-color-scheme="dark"]:not([data-palette="green"]) {
  --green: #F5F5F5;
  --green-surface: #1F1F1F;
  --green-600: #2F2F2F;
  --green-100: #3A3A3A;
  --green-50: #1A1A1A;
  --gold: #F5F5F5;
  --gold-ink: #F5F5F5;
  --gold-50: #1A1A1A;
  --gold-line: #2A2A2A;
}

/* ---------- Green & Gold, Dark ---------- */
:root[data-color-scheme="dark"][data-palette="green"] {
  --green: #7FC7A4;
  --green-surface: #2F4A3F;
  --green-600: #3D5E52;
  --green-100: #2E4A3F;
  --green-50: #1B2A24;
  --gold: #E0C878;
  --gold-ink: #E0C878;
  --gold-50: #2A2518;
  --gold-line: #4A3E20;
}

/* ---------- Text-size scaling ---------- */
:root {
  --fs-zoom: 1;
}

:root[data-text-scale="sm"] {
  --fs-zoom: 0.9;
}

:root[data-text-scale="lg"] {
  --fs-zoom: 1.15;
}

/* Reading-content containers only — navigation chrome is never scaled. */
#entries,
#muqaddimah-content,
.fc-card,
#section-quiz-inline,
#exam-stage,
#search-results,
#glossary-table,
#sections-list,
#quiz-hub-list,
.muqaddimah-card {
  zoom: var(--fs-zoom);
}

/* The three "A" glyphs in the Appearance control, sized by choice. */
[data-seg="text-scale"] .seg-opt input[value="sm"]+span {
  font-size: .75rem;
}

[data-seg="text-scale"] .seg-opt input[value="md"]+span {
  font-size: 1rem;
}

[data-seg="text-scale"] .seg-opt input[value="lg"]+span {
  font-size: 1.25rem;
}

/* ---------- 1. Reset & base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.6 var(--font-en);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

h1,
h2,
h3,
h4,
p,
ul,
ol,
dl,
dd,
figure,
blockquote {
  margin: 0;
}

ul,
ol {
  padding: 0;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-en);
  line-height: 1.25;
}

a {
  color: var(--green);
  text-underline-offset: .15em;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

svg {
  display: block;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}

.main:focus,
.stage:focus,
[tabindex="-1"]:focus {
  outline: none;
}

/* Arabic: any element with lang="ar" gets the Arabic face and tashkil-safe leading.
   Never apply letter-spacing or text-transform to Arabic (breaks joining). */
[lang="ar"] {
  font-family: var(--font-ar);
  font-size: 1.2em;
  line-height: 1.9;
  letter-spacing: normal;
  word-spacing: normal;
  text-transform: none;
}

[lang="ar"] [lang="ar"] {
  font-size: 1em;
}

bdi {
  unicode-bidi: isolate;
}


mark {
  background: #D6E4F0;
  color: var(--text);
  padding: 0 .12em;
  border-radius: 2px;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.print-only {
  display: none;
}

.skip-link {
  position: absolute;
  left: .5rem;
  top: -4rem;
  z-index: 100;
  padding: .75rem 1rem;
  background: var(--surface);
  color: var(--green);
  font-weight: 600;
  border: 2px solid var(--green);
  border-radius: 10px;
}

.skip-link:focus {
  top: .5rem;
}

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- 2. Top bar + primary navigation ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--green-surface);
  color: #fff;
  padding: env(safe-area-inset-top, 0px) 0 0;
}

.topbar :focus-visible {
  outline-color: var(--gold);
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 3.5rem;
  padding: .25rem max(.5rem, env(safe-area-inset-right, 0px)) .25rem max(1rem, env(safe-area-inset-left, 0px));
}

.brand {
  display: none;
}

.topbar-context {
  flex: 1;
  min-width: 0;
}

.topbar-eyebrow {
  font-size: .75rem;
  line-height: 1.3;
  color: var(--on-green);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-eyebrow:empty {
  display: none;
}

.topbar-title {
  font-weight: 600;
  font-size: 1.0625rem;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 50%;
  color: #fff;
  text-decoration: none;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, .14);
}

/* Mobile: bottom tab bar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tabbar-h);
  padding: .375rem .125rem;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
}

.tabbar a:hover {
  background: var(--green-50);
}

.tabbar a[aria-current="page"] {
  color: var(--green);
  font-weight: 700;
  box-shadow: inset 0 3px 0 var(--gold);
}

.tabbar a[aria-current="page"] .icon {
  stroke-width: 2.25;
}

.tabbar :focus-visible {
  outline: 3px solid var(--green);
  outline-offset: -4px;
}

.banner {
  padding: .5rem 1rem;
  background: var(--gold-50);
  border-bottom: 2px solid var(--gold);
  text-align: center;
  font-size: .875rem;
}

/* ---------- 2b. Sections menu (drawer) ----------
   Phones and tablets: a panel that slides in from the left, in the top
   bar's colour. Desktop (64rem+): a light sidebar that is always there.
   The colours are variables so the two looks share one set of rules. */
.drawer {
  --dr-bg: var(--green-surface);
  --dr-text: #fff;
  --dr-muted: var(--on-green);
  --dr-line: rgba(255, 255, 255, .14);
  --dr-hover: rgba(255, 255, 255, .08);
  --dr-current: rgba(255, 255, 255, .12);
  --dr-accent: var(--gold);
  --dr-num-bg: rgba(255, 255, 255, .1);
  --dr-num-line: rgba(255, 255, 255, .22);
  --dr-num-text: #fff;
  --dr-check: var(--gold);

  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 70;
  width: min(88vw, 22rem);
  display: flex;
  flex-direction: column;
  background: var(--dr-bg);
  color: var(--dr-text);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: env(safe-area-inset-top, 0px) 0 calc(env(safe-area-inset-bottom, 0px) + 1.5rem) env(safe-area-inset-left, 0px);
  transform: translateX(-102%);
  visibility: hidden;
  transition: transform .24s ease, visibility 0s linear .24s;
  box-shadow: 0 0 40px rgba(0, 0, 0, .3);
}

.drawer.is-open {
  transform: none;
  visibility: visible;
  transition: transform .24s ease;
}

.drawer :focus-visible {
  outline-color: var(--dr-accent);
  outline-offset: -3px;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 65;
  background: rgba(10, 18, 15, .55);
}

.drawer-head {
  padding: .5rem .5rem 1.125rem 1rem;
  border-bottom: 1px solid var(--dr-line);
}

.drawer-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.drawer-close {
  color: var(--dr-text);
  margin-left: -.5rem;
}

.drawer-close:hover {
  background: var(--dr-hover);
}

.drawer-brand-ar {
  font-family: var(--font-ar);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.5;
  color: var(--dr-accent);
  text-decoration: none;
  padding-inline: .5rem;
}

.drawer-brand-en {
  display: block;
  margin-top: .125rem;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
}

.drawer-group {
  padding: 1.125rem 1rem .375rem;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--dr-muted);
}

.dl { list-style: none; }

.dl-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 3.5rem;
  padding: .5rem 1rem;
  color: var(--dr-text);
  text-decoration: none;
}

.dl-link:hover { background: var(--dr-hover); }

.dl-link[aria-current="page"] {
  background: var(--dr-current);
  box-shadow: inset 4px 0 0 var(--dr-accent);
}

.dl-num {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.875rem;
  height: 1.875rem;
  background: var(--dr-num-bg);
  border: 1px solid var(--dr-num-line);
  border-radius: 50%;
  color: var(--dr-num-text);
  font-size: .8125rem;
  font-weight: 700;
}

/* A section whose quiz has been passed: the number itself fills in —
   the same idea as .card-num--done in the sections list, adapted to
   the drawer's own colour tokens. */
.dl-num--done {
  background: var(--dr-num-text);
  border-color: var(--dr-num-text);
  color: var(--dr-bg);
}

.dl-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.dl-ar {
  font-size: 1.1875rem;
  line-height: 1.6;
  font-weight: 700;
}

.dl-en {
  font-size: .875rem;
  line-height: 1.35;
  color: var(--dr-muted);
}

.dl-main > .dl-en:first-child {
  font-size: 1rem;
  font-weight: 600;
  color: var(--dr-text);
}

.dl-check {
  flex: none;
  color: var(--dr-check);
}

.dl-check .icon {
  width: 1.375rem;
  height: 1.375rem;
  stroke-width: 2.5;
}

body.drawer-open { overflow: hidden; }

/* ---------- 3. Main container & views ---------- */
.layout { display: block; }
.main {
  max-width: var(--maxw);
  margin-inline: auto;
  padding: 1rem max(var(--gutter), env(safe-area-inset-right, 0px)) calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 2rem) max(var(--gutter), env(safe-area-inset-left, 0px));
  overflow-x: clip;
}

.view {
  display: block;
  min-width: 0;
}

.view>*+* {
  margin-top: 1rem;
}

.view>.back-link+* {
  margin-top: .25rem;
}

.loading {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

.view-head h2 {
  font-size: 1.625rem;
  color: var(--green);
}

.lede {
  color: var(--muted);
  max-width: 65ch;
}

.eyebrow {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--gold-ink);
}

.subhead {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--green);
}

.stat-line {
  font-size: .875rem;
  color: var(--muted);
}

.help {
  font-size: .8125rem;
  color: var(--muted);
  margin-top: .25rem;
}

.error {
  color: var(--danger);
  font-weight: 600;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}

.plain-list {
  list-style: none;
}

.plain-list li {
  padding: .5rem 0;
  border-top: 1px solid var(--border);
}

.plain-list li:first-child {
  border-top: 0;
}

.stage {
  outline: none;
}

.stage>*+* {
  margin-top: 1rem;
}

.empty {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: 16px;
}

/* Bilingual titles (h2.titles > .ar + .en) */
.titles {
  display: flex;
  flex-direction: column;
  gap: .125rem;
}

.titles .ar {
  font-size: clamp(1.75rem, 7vw, 2.5rem);
  line-height: 1.7;
  font-weight: 700;
  color: var(--green);
}

.titles .en {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

/* ---------- 4. Bilingual pair layout ---------- */
/* .pair = Arabic block above English block; two columns on desktop (see media query) */
.pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: .5rem;
}

.pair>* {
  min-width: 0;
}

/* ---------- 5. Buttons, inputs, segmented control ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: 44px;
  min-width: 44px;
  padding: .5rem 1rem;
  background: var(--surface);
  color: var(--green);
  border: 1.5px solid var(--green);
  border-radius: 10px;
  font-size: .9375rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  text-decoration: none;
}

.btn:hover {
  background: var(--green-50);
}

.btn--primary {
  background: var(--green-surface);
  color: #fff;
}

.btn--primary:hover {
  background: var(--green-600);
}

.btn--ghost {
  border-color: var(--border-strong);
  color: var(--text);
}

.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn--danger:hover {
  background: #7F1616;
}

.btn--again {
  border-color: var(--danger);
  color: var(--danger);
}

.btn--again:hover {
  background: var(--danger-50);
}

.btn--known {
  background: var(--green-surface);
  color: #fff;
}

.btn--known:hover {
  background: var(--green-600);
}

.btn[aria-pressed="true"] {
  background: var(--green-surface);
  color: #fff;
}

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: .5;
  cursor: not-allowed;
}

.field {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  min-width: 0;
  flex: 1 1 12rem;
}

.field--grow {
  flex: 2 1 16rem;
}

.field label {
  font-size: .875rem;
  font-weight: 600;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}

.input {
  width: 100%;
  min-height: 44px;
  padding: .5rem .75rem;
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border-strong);
  border-radius: 10px;
}

.input:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 1px;
  border-color: var(--green);
}

.input[lang="ar"] {
  font-size: 1.4rem;
  direction: rtl;
}

.input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.seg {
  display: inline-flex;
  gap: 1.5px;
  max-width: 100%;
  margin: 0;
  padding: 0;
  min-width: 0;
  background: var(--green);
  border: 1.5px solid var(--green);
  border-radius: 10px;
  overflow: hidden;
}

.seg-opt {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.seg-opt input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.seg-opt span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: .5rem .625rem;
  background: var(--surface);
  color: var(--green);
  font-size: .875rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}


.seg-opt input:checked + span { background: var(--green-surface); color: #fff; }

:root[data-color-scheme="dark"] .seg-opt input:checked + span {
  box-shadow: inset 0 -2px 0 currentColor;
}

.seg-opt input:focus-visible+span {
  outline: 3px solid #fff;
  outline-offset: -6px;
  box-shadow: inset 0 0 0 3px var(--green);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .75rem;
}

.note {
  padding: .75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: .9375rem;
}



.badge {
  display: inline-block;
  padding: .125rem .5rem;
  background: var(--green-50);
  color: var(--green);
  border: 1px solid var(--green-100);
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.5;
}


.badge--pass {
  background: var(--green-surface);
  color: #fff;
  border-color: var(--green-surface);
}

.badge--fail {
  background: var(--danger-50);
  color: var(--danger);
  border-color: var(--danger-line);
}


.meter {
  display: block;
  height: 6px;
  background: var(--green-100);
  border-radius: 3px;
  overflow: hidden;
}

.meter-fill {
  display: block;
  height: 100%;
  background: var(--green);
  transform-origin: left center;
  transform: scaleX(var(--p, 0));
}



.card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
  list-style: none;
}

.card-grid--wide {
  grid-template-columns: minmax(0, 1fr);
}

.card-grid:not(.card-grid--wide)>li:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .25rem;
  height: 100%;
  min-height: 44px;
  padding: 1rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
}

.card:hover {
  border-color: var(--green);
}

.card .icon {
  color: var(--green);
}

.card-title {
  font-weight: 600;
}

.card-meta {
  font-size: .8125rem;
  color: var(--muted);
}

.card--feature {
  background: var(--green-surface);
  color: #fff;
  border-color: var(--green-surface);
}

.card--feature:hover {
  background: var(--green-600);
}

.card--feature .icon {
  color: var(--gold);
}

.card--feature .card-meta {
  color: var(--on-green);
}

/* Row cards: sections list, quiz hub list */
.card-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: .75rem;
  list-style: none;
}

/* Cards in the same grid row share the row's height. Expandable section
   items (button + sub-tree) are excluded — they must keep their natural
   height so the sub-tree can sit below the button. */
.card-list>li>.card-row:not(.card-row--expandable) {
  height: 100%;
}

.card-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 48px;
  padding: .5rem .875rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
}

.card-row:hover {
  border-color: var(--green);
}

.card-num {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.875rem;
  height: 1.875rem;
  background: var(--green-50);
  color: var(--green);
  border: 1px solid var(--green-100);
  border-radius: 50%;
  font-size: .75rem;
  font-weight: 600;
}

.card-num--done {
  background: var(--green-surface);
  color: #fff;
  border-color: var(--green-surface);
}

.card-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .125rem;
}

.card-title-ar {
  font-size: 1.0625rem;
  line-height: 1.5;
  color: var(--green);
  font-weight: 700;
}

.card-side {
  flex: none;
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--green);
}

/* Muqaddimah card (introduction) — distinct from numbered section cards */
.muqaddimah-card {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 48px;
  padding: .75rem .875rem;
  background: var(--gold-50);
  color: var(--text);
  border: 1px solid var(--gold-line);
  border-left: 4px solid var(--gold);
  border-radius: var(--radius);
  text-decoration: none;
}

.muqaddimah-card:hover {
  border-color: var(--gold);
}

.muqaddimah-card-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .125rem;
}

.muqaddimah-card-ar {
  font-size: 1.25rem;
  line-height: 1.5;
  font-weight: 700;
  color: var(--green);
}


/* ---------- 7. Section reader ---------- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  min-height: 44px;
  color: var(--green);
  font-weight: 600;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

.entries {
  display: grid;
  gap: 1.25rem;
}

/* JS-generated entry markup:
   article.entry[id=unique_id] > header.entry-head + div.entry-body + footer.entry-foot
   .block > h4.block-title + content;  ol.examples > li.example;  .irab (panel, [hidden] when collapsed) */
.entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  scroll-margin-top: 5rem;
}


.entry-head {
  padding: 1rem;
  background: var(--green-50);
  border-bottom: 1px solid var(--green-100);
}

.entry-ar {
  font-size: clamp(2rem, 8vw, 2.75rem);
  line-height: 1.7;
  font-weight: 700;
  color: var(--green);
}

.entry-gloss { margin-top: .125rem; font-weight: 600; }

/* Original matn band: bare Arabic, sits between the entry header and the
   body. Cream background with a gold hairline below, so it reads as a
   distinct layer — source above, commentary below. */
.entry-matn {
  position: relative;
  padding: 1.25rem 1.5rem;
  background: var(--gold-50);
  border-bottom: 1px solid var(--gold-line);
}
.entry-matn-label {
  display: block;
  margin-bottom: .5rem;
  font-family: var(--font-ar);
  font-size: .75rem;
  font-weight: 700;
  color: var(--gold-ink);
  text-align: right;
}
.entry-matn-text {
  margin: 0;
  font-family: var(--font-ar);
  font-size: 1.25rem;
  line-height: 2.1;
  color: var(--text);
  text-align: right;
}

.entry-body {
  display: grid;
  gap: 1.25rem;
  padding: 1rem;
}

.entry-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .75rem 1rem;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.block>*+* {
  margin-top: .5rem;
}

.block-title {
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--gold-ink);
}

.prose { max-width: 70ch; }
.prose > * + * { margin-top: .75rem; }
.def-label { font-weight: 600; color: var(--green); }

/* Muqaddimah — extra vertical rhythm so the bilingual passage breathes. */
#muqaddimah-content .pair { row-gap: 1.75rem; }
#muqaddimah-content .en-block .def-label { margin-top: 1.5rem; }
#muqaddimah-content .en-block .def-label:first-child { margin-top: 0; }
#muqaddimah-content .en-block .prose { margin-top: .5rem; }
#muqaddimah-content > * + * { margin-top: 2rem; }
#view-muqaddimah .view-head { margin-bottom: 2rem; }

/* Structured senses block — preferred over prose Explanation for entries
   that supply senses[]. Bilingual; not hidden by lang-mode toggles. */
.senses-overview {
  margin-bottom: 1rem;
}

.senses {
  display: grid;
  gap: 1.25rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

.sense {
  padding: 1rem 0;
  border-top: 1px solid var(--border);
}

.sense:first-child {
  border-top: 0;
  padding-top: 0;
}

.sense-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .25rem .5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--green);
  margin-bottom: .5rem;
  line-height: 1.4;
}

.sense-num {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  background: var(--green-50);
  color: var(--green);
  border: 1px solid var(--green-100);
  border-radius: 50%;
  font-size: .75rem;
  font-weight: 700;
}

.sense-ar {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.7;
}

.sense-translit {
  font-style: italic;
  color: var(--muted);
  font-weight: 500;
}

.sense-sep {
  color: var(--muted);
  font-weight: 400;
}

.sense-def,
.sense-rec,
.sense-why {
  max-width: 70ch;
  margin-top: .375rem;
}

.sense-label {
  font-weight: 700;
  color: var(--gold-ink);
}

.sense-examples {
  display: grid;
  gap: .75rem;
  list-style: none;
  padding: 0;
  margin: .875rem 0;
}

.sense-ex {
  padding: .75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--green-100);
  border-radius: 10px;
}

.sense-ex-ar {
  font-size: 1.375rem;
  line-height: 2;
}

.sense-ex-en {
  color: var(--text);
}

.sense-ex-source {
  font-size: .875rem;
  color: var(--muted);
}

.sense-ex-subtype {
  font-size: .875rem;
  font-weight: 600;
  color: var(--gold-ink);
  margin-top: .25rem;
}

.sense-ex-note {
  font-size: .875rem;
  color: var(--muted);
  margin-top: .25rem;
}

.examples {
  display: grid;
  gap: 1rem;
  list-style: none;
}

.example {
  padding: .75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--green-100);
  border-radius: 10px;
}

.ex-num {
  display: inline-block;
  margin-bottom: .25rem;
  font-size: .75rem;
  font-weight: 700;
  color: var(--gold-ink);
}

.ex-ar {
  font-size: 1.5rem;
  line-height: 2.1;
}

.ex-source {
  margin-top: .5rem;
  font-size: .8125rem;
  color: var(--muted);
}


.refs {
  display: grid;
  gap: .875rem;
}

.ref {
  padding: .875rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  border-radius: 10px;
}

.ref>*+* {
  margin-top: .375rem;
}

.ref-cite {
  font-weight: 700;
  color: var(--green);
}

.ref-ar {
  font-size: 1.5rem;
  line-height: 2.1;
}

.ref-note {
  font-size: .9375rem;
  color: var(--muted);
}

.notes {
  padding-inline-start: 1.25rem;
}

.notes li+li {
  margin-top: .375rem;
}

/* Section summary — rendered at the bottom of a section view,
   above the section-foot. Reuses the Notes block visual style
   (.block + .block-title + .notes list); only the term spans
   are new. Prints with the section. */
.section-summary {
  margin-top: 1.25rem;
}

.section-summary-list li+li {
  margin-top: .5rem;
}

.summary-term-ar {
  font-family: var(--font-ar);
  font-weight: 700;
  font-size: 1.1em;
  unicode-bidi: isolate;
}

.summary-term-translit {
  font-style: italic;
  color: var(--muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  list-style: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  min-height: 44px;
  padding: .375rem .875rem;
  color: var(--green);
  border: 1.5px solid var(--green);
  border-radius: 999px;
  font-size: .875rem;
  font-weight: 600;
  text-decoration: none;
}

.chip:hover {
  background: var(--green-50);
}

#section-quiz-inline { scroll-margin-top: 5rem; }
.section-foot > * + * { margin-top: 1rem; }

.pager {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: .75rem;
}

.pager-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-height: 44px;
  padding: .75rem 1rem;
  background: var(--surface);
  color: var(--green);
  border: 1.5px solid var(--green);
  border-radius: var(--radius);
  text-decoration: none;
}

.pager-link:hover {
  background: var(--green-50);
}

.pager-link--next {
  justify-content: flex-end;
  text-align: right;
}

.pager-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pager-label {
  font-size: .75rem;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
}

.pager-title {
  font-weight: 600;
}

/* ---------- 7b. Sections list — expandable sub-tree (paginated sections) ---------- */
.section-item--expandable {
  display: block;
}

.section-item--expandable.is-expanded {
  grid-column: 1 / -1;
}

.card-row--expandable {
  width: 100%;
  text-align: start;
  appearance: none;
  -webkit-appearance: none;
}

.card-row--expandable .card-side .icon {
  transition: transform .2s ease;
}

.card-row--expandable[aria-expanded="true"] .card-side .icon {
  transform: rotate(90deg);
}

/* About panel in Settings */
.about-list {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: .375rem 1rem;
  margin-top: .5rem;
}
.about-list dt {
  font-weight: 600;
  color: var(--green);
}
.about-list dd {
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.sub-tree {
  position: relative;
  margin-top: .25rem;
  padding-left: 2.75rem;
  padding-bottom: .25rem;
}

.sub-tree__connector {
  position: absolute;
  left: 2.125rem;
  top: 0;
  bottom: .5rem;
  width: 0;
  border-left: 1px dotted var(--gold-line);
  pointer-events: none;
}

.sub-tree__list {
  display: grid;
  gap: .5rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

.sub-tree__item {
  min-width: 0;
}

/* Sub-card: grid layout — number | stacked ar+en | chevron.
   Stacking prevents the truncation that flex caused on narrow screens. */
.sub-tree__link {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  column-gap: .625rem;
  min-height: 44px;
  padding: .5rem .75rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--green-100);
  border-radius: 8px;
  text-decoration: none;
}

.sub-tree__link:hover {
  border-color: var(--green);
}

/* Unvisited state: soft green tint, not the tan border colour. */
.sub-tree__num {
  grid-row: 1;
  align-self: center;
  display: grid;
  place-items: center;
  width: 1.625rem;
  height: 1.625rem;
  background: var(--green-50);
  color: var(--green);
  border: 1px solid var(--green-100);
  border-radius: 50%;
  font-size: .75rem;
  font-weight: 700;
  line-height: 1;
}


/* Arabic on its own line, right-aligned. */
.sub-tree__ar {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  font-size: .9375rem;
  color: var(--green);
  font-weight: 600;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sub-tree__chev {
  grid-row: 1;
  align-self: center;
  display: inline-flex;
  align-items: center;
  color: var(--green);
}

.sub-tree__chev .icon {
  width: 1rem;
  height: 1rem;
}

/* ---------- 8. Quiz, exam ---------- */
/* JS-generated: .q-card > .q-count, .q-prompt, .q-options > label.q-option, .q-feedback, .q-actions;
   .result (score summary), .breakdown > li.breakdown-row, .review > li.review-item, .q-nav > button.q-nav-btn */
.q-card {
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.q-card>*+* {
  margin-top: .75rem;
}

.q-count {
  font-size: .875rem;
  color: var(--muted);
}

.q-prompt {
  font-size: 1.125rem;
  font-weight: 600;
}

.q-prompt-ar {
  display: block;
  margin-block: .25rem;
  font-size: 1.75rem;
  font-weight: 400;
  line-height: 2;
}

.q-options {
  display: grid;
  gap: .625rem;
  list-style: none;
}

.q-option {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  min-height: 44px;
  padding: .75rem 1rem;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  cursor: pointer;
}

.q-option input {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  margin: .2rem 0 0;
  accent-color: var(--green);
}

.q-option:hover {
  border-color: var(--green);
}

.q-option:has(input:checked) {
  border-color: var(--green);
  background: var(--green-50);
}

.q-option:has(input:focus-visible) {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}

.q-option.is-correct {
  border-color: var(--green);
  background: var(--ok-50);
}

.q-option.is-wrong {
  border-color: var(--danger);
  background: var(--danger-50);
}

.q-option-text {
  flex: 1;
  min-width: 0;
}


.q-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}


/* Inline section quiz — one question at a time, auto-advance on answer. */
.inline-quiz {
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.inline-quiz>*+* {
  margin-top: .75rem;
}

.inline-quiz-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
}

.iq-options {
  display: grid;
  gap: .625rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

.iq-option {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  width: 100%;
  min-height: 44px;
  padding: .75rem 1rem;
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  font: inherit;
  text-align: start;
}

.iq-option:hover:not(:disabled) {
  border-color: var(--green);
}

.iq-option:disabled {
  cursor: default;
}

.iq-option.is-correct {
  border-color: var(--green);
  background: var(--ok-50);
}

.iq-option.is-wrong {
  border-color: var(--danger);
  background: var(--danger-50);
}

.iq-option-text {
  flex: 1;
  min-width: 0;
}

.iq-feedback { text-align: center; padding: .5rem 0 .25rem; }
.iq-feedback.is-correct { color: var(--green); font-weight: 700; }
.iq-feedback.is-wrong { color: var(--danger); }
.iq-feedback-title { font-weight: 700; }
.iq-feedback-expl {
  margin: .5rem auto 0;
  max-width: 55ch;
  font-size: .9375rem;
  font-weight: 400;
  color: var(--muted);
  text-align: start;
}

.result {
  padding: 1.5rem 1rem;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.result>*+* {
  margin-top: .5rem;
}

.result-score {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--green);
}

.result--fail .result-score {
  color: var(--danger);
}

.result-verdict {
  font-weight: 600;
}

.breakdown {
  display: grid;
  gap: .625rem;
  list-style: none;
}

.breakdown-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .25rem .75rem;
  align-items: center;
  padding: .625rem .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.breakdown-row .meter {
  grid-column: 1 / -1;
}

.breakdown-score {
  font-weight: 700;
  color: var(--green);
}


.panel {
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.panel>*+* {
  margin-top: .75rem;
}

.panel--danger {
  border-color: var(--danger-line);
}

/* ---------- 9. Flashcards ---------- */
.fc-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 16rem;
  padding: 1.5rem 1rem;
  text-align: center;
  background: var(--surface);
  border: 1.5px solid var(--green);
  border-radius: 20px;
}

.fc-face {
  width: 100%;
}

.fc-face>*+* {
  margin-top: .5rem;
}

.fc-ar {
  font-size: clamp(2.25rem, 10vw, 3.25rem);
  line-height: 1.8;
  font-weight: 700;
  color: var(--green);
}

.fc-translit {
  font-style: italic;
  color: var(--muted);
}

.fc-back {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.fc-gloss {
  font-size: 1.125rem;
  font-weight: 700;
}

.fc-def {
  max-width: 52ch;
  margin-inline: auto;
}

.fc-actions {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin-top: 1rem;
}

.fc-actions .btn {
  width: 100%;
}

.fc-rate {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
}

/* Four-type flashcard additions (Types A/B/D/E). Existing .fc-* rules above
   are untouched; these are additive. No new colours — existing tokens only. */
.fc-front-en {
  font-size: 1.125rem;
  font-weight: 500;
}

.fc-sentence {
  font-size: clamp(1.25rem, 3.5vw, 1.5rem);
  line-height: 1.9;
  font-weight: 600;
  color: var(--green);
}

.fc-prompt {
  margin-top: .5rem;
  font-size: .875rem;
  color: var(--muted);
}


.fc-target {
  font-family: var(--font-ar);
  font-weight: 700;
  unicode-bidi: isolate;
}

.fc-sense {
  font-size: clamp(1.75rem, 7vw, 2.25rem);
  line-height: 1.8;
  font-weight: 700;
  color: var(--green);
}

.fc-sense-en {
  font-size: 1.0625rem;
  font-weight: 500;
}

.fc-reason {
  margin-top: .375rem;
  font-size: .8125rem;
  color: var(--muted);
}

.fc-ar-para {
  font-size: clamp(1.1rem, 3vw, 1.35rem);
  line-height: 2;
  font-weight: 700;
  color: var(--green);
}

/* ---------- 10. Glossary & search ---------- */
/* Glossary/i'rab tables reflow to stacked cards below 768px (no horizontal scroll). */
.glossary-table {
  width: 100%;
  border-collapse: collapse;
}

.glossary-table thead {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.glossary-table,
.glossary-table tbody,
.glossary-table tr,
.glossary-table td {
  display: block;
}

.glossary-table tr {
  margin-bottom: .75rem;
  padding: .75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.glossary-table td {
  padding: .25rem 0;
}

.glossary-table td::before {
  content: attr(data-label);
  display: block;
  direction: ltr;
  text-align: left;
  font-family: var(--font-en);
  font-size: .6875rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
}

.g-term {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--green);
}

.g-translit {
  font-style: italic;
}

.search-form {
  display: flex;
  gap: .5rem;
}

.search-form .input {
  flex: 1;
  min-width: 0;
}

.result-list {
  display: grid;
  gap: .75rem;
  list-style: none;
}

.result-link {
  display: block;
  min-height: 44px;
  padding: .875rem 1rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
}

.result-link:hover {
  border-color: var(--green);
}

.result-link>*+* {
  margin-top: .25rem;
}

.result-title {
  font-weight: 600;
  color: var(--green);
}

.result-snippet {
  font-size: .9375rem;
  color: var(--muted);
}


/* ---------- 12. Dialogs & toast ---------- */
.dialog {
  width: min(92vw, 26rem);
  padding: 1.25rem;
  background: var(--surface);
  color: var(--text);
  border: 0;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .28);
}

.dialog::backdrop {
  background: rgba(15, 23, 32, .6);
}

.dialog h2 {
  font-size: 1.25rem;
  color: var(--green);
}

.dialog form>*+* {
  margin-top: .75rem;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .75rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + .75rem);
  z-index: 80;
  max-width: min(92vw, 28rem);
  padding: .75rem 1rem;
  background: var(--text);
  color: #fff;
  border-radius: 10px;
  font-size: .9375rem;
  transform: translateX(-50%);
}

/* ---------- 13. Breakpoints ---------- */

@media (min-width: 40rem) {
  .card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .card-grid--wide {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-grid:not(.card-grid--wide)>li:last-child:nth-child(odd) {
    grid-column: auto;
  }

  .fc-actions .btn {
    width: auto;
  }

  .fc-actions {
    flex-direction: row;
    justify-content: center;
  }

  .fc-rate {
    min-width: 20rem;
  }

  .pager {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pager-link--next {
    grid-column: 2;
  }

  .match-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
    align-items: center;
  }
}

@media (min-width: 48rem) {
  .card-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .glossary-table {
    border: 1px solid var(--border);
    background: var(--surface);
  }

  .glossary-table thead {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }

  .glossary-table {
    display: table;
  }

  .glossary-table tbody {
    display: table-row-group;
  }

  .glossary-table thead {
    display: table-header-group;
  }

  .glossary-table tr {
    display: table-row;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
  }

  .glossary-table td,
  .glossary-table th {
    display: table-cell;
    padding: .625rem .75rem;
    vertical-align: top;
    text-align: start;
  }

  .glossary-table th {
    background: var(--green);
    color: #fff;
    font-size: .8125rem;
    font-weight: 600;
  }

  .glossary-table td {
    border-top: 1px solid var(--border);
  }

  .glossary-table td::before {
    display: none;
  }

  .g-term {
    direction: rtl;
    text-align: right;
  }
}

@media (min-width: 64rem) {
  :root {
    --gutter: 1.5rem;
  }

  #btn-contents,
  .drawer-close,
  .scrim {
    display: none !important;
  }

  .layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    align-items: start;
    max-width: calc(var(--maxw) + var(--sidebar-w));
    margin-inline: auto;
  }

  .drawer {
    --dr-bg: var(--surface);
    --dr-text: var(--text);
    --dr-muted: var(--muted);
    --dr-line: var(--border);
    --dr-hover: var(--green-50);
    --dr-current: var(--green-50);
    --dr-accent: var(--gold);
    --dr-num-bg: var(--green-50);
    --dr-num-line: var(--green-100);
    --dr-num-text: var(--green);
    --dr-check: var(--green);

    position: sticky;
    top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    z-index: 1;
    width: auto;
    height: calc(100vh - var(--topbar-h) - env(safe-area-inset-top, 0px));
    padding-top: 0;
    border-right: 1px solid var(--border);
    box-shadow: none;
    transform: none;
    visibility: visible;
    transition: none;
  }

  .drawer :focus-visible { outline-color: var(--green); }
  .drawer-head { padding: 1rem; }
  .drawer-head-row { display: none; }
  .drawer-brand-en { display: none; }
  .dl-ar { color: var(--green); }
  .dl-link[aria-current="page"] .dl-en:first-child { color: var(--green); }

  .main {
    max-width: none;
    margin-inline: 0;
    padding-bottom: 3rem;
  }

  .toast {
    bottom: 1.5rem;
  }

  /* Top bar becomes a single row: brand | nav | page title | search */
  .topbar {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto auto auto;
    grid-template-areas: "brand nav context hub search settings";
    align-items: center;
    column-gap: 1rem;
    padding-inline: max(var(--gutter), calc((100% - var(--maxw)) / 2 + var(--gutter)));
    padding-block: env(safe-area-inset-top, 0px) 0;
  }

  #btn-hub {
    grid-area: hub;
  }

  #btn-settings {
    grid-area: settings;
  }

  .topbar-row {
    display: contents;
  }

  .brand {
    grid-area: brand;
    display: flex;
    align-items: baseline;
    gap: .75rem;
    min-height: 44px;
    color: #fff;
    text-decoration: none;
  }

  .brand-ar {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.6;
  }

  .brand-en {
    font-size: .875rem;
    color: var(--on-green);
  }

  .topbar-context {
    grid-area: context;
    text-align: end;
    padding-inline: 1rem;
  }

  #btn-search {
    grid-area: search;
  }

  .tabbar {
    position: static;
    grid-area: nav;
    display: flex;
    gap: .25rem;
    background: transparent;
    border: 0;
    padding: 0;
  }

  .tabbar a {
    flex-direction: row;
    gap: .5rem;
    min-height: 44px;
    padding: .5rem .875rem;
    color: var(--on-green);
    border-radius: 8px;
    font-size: .9375rem;
  }

  .tabbar a:hover {
    background: rgba(255, 255, 255, .12);
  }

  .tabbar a[aria-current="page"] {
    background: rgba(255, 255, 255, .14);
    color: #fff;
    box-shadow: inset 0 -3px 0 var(--gold);
  }

  .tabbar :focus-visible {
    outline: 3px solid var(--gold);
    outline-offset: 1px;
  }

  /* Reading layout: Arabic on the right, English on the left */
  .pair {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .5rem 2rem;
  }

  .pair>.ar-block {
    grid-column: 2;
    grid-row: 1;
  }

  .pair>.en-block {
    grid-column: 1;
    grid-row: 1;
  }

  .pair> :only-child {
    grid-column: 1 / -1;
  }

  .card-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .card-grid--wide {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .entry-head,
  .entry-body,
  .entry-foot {
    padding-inline: 1.5rem;
  }

}

/* ---------- 14. Motion, forced colors ---------- */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

@media (forced-colors: active) {

  .seg-opt input:checked+span,
  .tabbar a[aria-current="page"] {
    outline: 2px solid Highlight;
  }

  .meter-fill {
    background: Highlight;
  }
}


/* ---------- 12b. Biography triggers and dialog ---------- */
.bio-trigger {
  display: inline;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  line-height: inherit;
  color: inherit;
  text-align: inherit;
  text-decoration: underline dotted var(--gold);
  text-decoration-thickness: 1px;
  text-underline-offset: .25em;
  cursor: pointer;
}
.bio-trigger:hover {
  color: var(--gold-ink);
  text-decoration-color: var(--gold-ink);
}
.bio-trigger:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
  border-radius: 3px;
}
.dialog--bio {
  width: min(92vw, 34rem);
}
.dialog--bio .bio-head {
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}
.dialog--bio .bio-head h2 {
  display: block;
  font-size: 1.25rem;
  color: var(--green);
  line-height: 1.4;
}
.dialog--bio .bio-name-ar {
  font-size: 1.375rem;
  font-weight: 700;
}
.dialog--bio .bio-name-en {
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}
.dialog--bio .bio-dates {
  margin-top: .25rem;
  font-size: .875rem;
  color: var(--muted);
}
.dialog--bio .bio-body {
  padding: 1rem 0;
}
.dialog--bio .bio-body > * + * {
  margin-top: 1rem;
}
.dialog--bio .bio-body .subhead {
  margin-top: 1.25rem;
}
.dialog--bio .bio-body .subhead:first-child {
  margin-top: 0;
}

/* ---------- 12c. Supplement badge on further notes ---------- */
.supplementary-note {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .375rem .5rem;
}
.supplement-badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .0625rem .5rem;
  background: var(--gold-50);
  color: var(--gold-ink);
  border: 1px solid var(--gold-line);
  border-radius: 999px;
  font-family: var(--font-en);
  font-size: .6875rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.supplement-badge:hover {
  background: var(--gold-line);
}
.supplement-badge:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}
.supplement-badge__q {
  display: inline-grid;
  place-items: center;
  width: .875rem;
  height: .875rem;
  background: var(--gold-ink);
  color: var(--gold-50);
  border-radius: 50%;
  font-size: .625rem;
  font-weight: 700;
  line-height: 1;
}
/* ---------- 15. Print: one section as a clean, readable document ---------- */
@media print {
  @page {
    margin: 16mm 14mm;
  }

  html {
    font-size: 11pt;
  }

  body {
    background: #fff;
    color: #000;
  }

  .topbar,
  .tabbar,
  .banner,
  .drawer,
  .scrim,
  .toast,
  .skip-link,
  .no-print,
  .back-link,
  .toolbar,
  .entry-foot,
  .section-foot,
  .pager,
  .loading,
  dialog {
    display: none !important;
  }

  .view:not(#view-section):not(#view-muqaddimah) {
    display: none !important;
  }

  .main {
    max-width: none;
    padding: 0;
    overflow: visible;
  }

  .print-only {
    display: block !important;
  }

  .print-book {
    margin-bottom: .5rem;
    font-size: 9pt;
    color: #333;
  }

  .view>*+* {
    margin-top: .75rem;
  }

  .entries {
    gap: 1rem;
  }

  .entry {
    border: 0;
    border-bottom: 1px solid #999;
    border-radius: 0;
    overflow: visible;
  }

  .entry-head {
    background: #fff;
    border-bottom: 1px solid #ccc;
    padding-inline: 0;
  }

  .entry-body {
    padding-inline: 0;
  }

  .entry-head,
  .block-title {
    break-after: avoid;
  }

  .example,
  .ref {
    break-inside: avoid;
  }

  .entry[hidden] {
    display: block !important;
  }

  .example,
  .ref,
  .note,
  .note--gold {
    background: #fff;
  }

  .titles .ar,
  .entry-ar,
  .card-title-ar,
  .block-title,
  .ref-cite {
    color: #000;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

  mark {
    background: none;
  }
}

/* ---------- 16. Quiz feedback with Next button; editorial notes ---------- */
.iq-feedback.is-correct,
.iq-feedback.is-wrong {
  color: var(--text);
  font-weight: 400;
}
.iq-feedback.is-correct .iq-feedback-title {
  color: var(--green);
  font-weight: 700;
}
.iq-feedback.is-wrong .iq-feedback-title {
  color: var(--danger);
  font-weight: 700;
}
.iq-feedback-next {
  margin-top: .75rem;
  text-align: center;
}




