/* ==========================================================================
   Sharh Mi'ata 'Amil — Study Companion
   styles.css — mobile-first; two-column reading layout at >= 1024px.
   Light theme only (no dark mode). Palette: green #0B3D2E, gold #C9A227,
   off-white #FAF8F3, charcoal #1F2937.
   Contrast notes: gold is used for accents/borders and as text only on the
   deep-green top bar (5.0:1). On light surfaces, gold text uses --gold-ink.
   Constraint: .topbar must not get transform/filter/backdrop-filter/contain,
   because the mobile tab bar (position: fixed) is a child of it.
   ========================================================================== */

:root {
  --green: #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;
  --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;
  --radius: 14px;
  color-scheme: light;
}

/* ---------- 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; }
.ar-inline { font-size: 1.15em; unicode-bidi: isolate; }
mark { background: #F3E4A0; 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);
  color: #fff;
  padding: env(safe-area-inset-top, 0px) 0 4px;
}
.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;
  border-radius: 50%;
  color: #fff;
  text-decoration: none;
}
.icon-btn:hover { background: rgba(255, 255, 255, .14); }
.topbar-progress {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 4px;
  background: rgba(255, 255, 255, .22);
  overflow: hidden;
}
.topbar-progress-fill {
  position: absolute;
  inset: 0;
  background: var(--gold);
  transform-origin: left center;
  transform: scaleX(var(--p, 0));
  transition: transform .2s ease;
}

/* Mobile: bottom tab bar */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 60;
  display: grid;
  grid-template-columns: repeat(5, 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;
}

/* ---------- 3. Main container & views ---------- */
.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. Language display toggle ---------- */
/* Arabic-only / English-only apply to the reader (#view-section) via these classes:
   .ar-block / .en-block on any element; .titles .ar / .en in the section header. */
[data-lang-mode="ar"] .en-block,
[data-lang-mode="ar"] #view-section .titles .en { display: none !important; }
[data-lang-mode="en"] .ar-block,
[data-lang-mode="en"] #view-section .titles .ar { display: none !important; }

/* .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); 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); color: #fff; }
.btn--known:hover { background: var(--green-600); }
.btn[aria-pressed="true"] { background: var(--green); 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;
  max-width: 100%;
  margin: 0;
  padding: 0;
  min-width: 0;
  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 + .seg-opt span { border-left: 1.5px solid var(--green); }
.seg-opt input:checked + span { background: var(--green); color: #fff; }
.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; }
.toolbar .seg { width: 100%; }

.note {
  padding: .75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: .9375rem;
}
.note--gold { background: var(--gold-50); border-color: var(--gold-line); border-left: 4px solid var(--gold); }

.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--gold { background: var(--gold-50); color: var(--gold-ink); border-color: var(--gold-line); }
.badge--pass { background: var(--green); color: #fff; border-color: var(--green); }
.badge--fail { background: var(--danger-50); color: var(--danger); border-color: var(--danger-line); }
.flag {
  padding: 0 .3rem;
  background: var(--gold-50);
  border: 1px solid var(--gold-line);
  border-radius: 4px;
  font-size: .875em;
}

.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));
}

/* ---------- 6. Home ---------- */
.hero {
  padding: 1.5rem 1rem;
  background: var(--green);
  color: #fff;
  text-align: center;
  border-radius: 16px;
  border-bottom: 4px solid var(--gold);
}
.hero .titles { align-items: center; }
.hero .titles .ar { color: #fff; }
.hero .titles .en { color: #fff; font-weight: 500; }
.hero-attrib, .hero-edition { margin-top: .5rem; font-size: .875rem; color: var(--on-green); }
.greeting { color: var(--muted); }
.progress-panel {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.ring { position: relative; flex: none; width: 7rem; height: 7rem; }
.ring svg { width: 100%; height: 100%; }
.ring-track { fill: none; stroke: var(--green-100); stroke-width: 10; }
.ring-value { fill: none; stroke: var(--green); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset .3s ease; }
.ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-pct { font-size: 1.5rem; font-weight: 700; line-height: 1; color: var(--green); }
.ring-cap { font-size: .75rem; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; }
.stats > div { padding: .75rem .5rem; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; text-align: center; }
.stats dt { font-size: .75rem; color: var(--muted); line-height: 1.3; }
.stats dd { font-size: 1.25rem; font-weight: 700; color: var(--green); }
.progress-panel .stats, .stats--stacked { grid-template-columns: minmax(0, 1fr); flex: 1; min-width: 0; }
.progress-panel .stats > div, .stats--stacked > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
  padding: .5rem .75rem;
  text-align: start;
}
.progress-panel .stats > div { background: var(--bg); }

.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); color: #fff; border-color: var(--green); }
.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; }
.card-row {
  display: flex;
  align-items: center;
  gap: .875rem;
  min-height: 44px;
  padding: .875rem 1rem;
  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: 2.25rem; height: 2.25rem;
  background: var(--green-50);
  color: var(--green);
  border: 1px solid var(--green-100);
  border-radius: 50%;
  font-size: .875rem;
  font-weight: 700;
}
.card-num--done { background: var(--green); color: #fff; border-color: var(--green); }
.card-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .125rem; }
.card-title-ar { font-size: 1.25rem; line-height: 1.8; color: var(--green); font-weight: 700; }
.card-side { flex: none; display: flex; align-items: center; gap: .5rem; 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.is-studied { border-color: var(--green); }
.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-translit { font-style: italic; color: var(--muted); }
.entry-gloss { margin-top: .125rem; font-weight: 600; }
.entry-meta { display: flex; flex-wrap: wrap; gap: .375rem; margin-top: .5rem; }
.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); }

.examples { display: grid; gap: 1rem; list-style: none; }
.example { padding: .875rem; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; }
.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); }
.btn--irab { margin-top: .75rem; font-size: .875rem; }
.btn--irab[aria-expanded="true"] { background: var(--green-50); }

.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; }
.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); }

/* I'rab panel + table. Stacked "cards" on mobile/tablet, real table at >= 1024px. */
.irab { margin-top: .75rem; padding: 1rem; background: var(--green-50); border: 1px solid var(--green-100); border-radius: 12px; }
.irab > * + * { margin-top: .75rem; }
.irab-source { font-size: .875rem; color: var(--muted); }
.irab-disclaimer { padding-left: .75rem; border-left: 3px solid var(--gold); font-size: .875rem; color: var(--text); }
.irab-table { width: 100%; border-collapse: collapse; }
.irab-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;
}
.irab-table, .irab-table tbody, .irab-table tr, .irab-table td { display: block; }
.irab-table tr { padding: .75rem 0; border-top: 1px solid var(--green-100); }
.irab-table tr:first-child { border-top: 0; padding-top: 0; }
.irab-table td { padding: .25rem 0; }
.irab-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);
}
.irab-word { font-size: 1.5rem; font-weight: 700; color: var(--green); }

.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; }

/* ---------- 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-mark { flex: none; font-weight: 700; }
.q-option.is-correct .q-mark { color: var(--green); }
.q-option.is-wrong .q-mark { color: var(--danger); }
.match-row { display: grid; gap: .375rem; padding: .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.q-feedback { padding: .875rem 1rem; border: 1.5px solid; border-radius: 12px; }
.q-feedback > * + * { margin-top: .375rem; }
.q-feedback--correct { background: var(--ok-50); border-color: var(--green); }
.q-feedback--wrong { background: var(--danger-50); border-color: var(--danger); }
.q-feedback-title { font-weight: 700; }
.q-actions { display: flex; flex-wrap: wrap; gap: .75rem; }

.q-nav { display: flex; flex-wrap: wrap; gap: .375rem; list-style: none; }
.q-nav-btn {
  min-width: 44px; min-height: 44px;
  padding: 0;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
}
.q-nav-btn.is-answered { background: var(--green-50); border-color: var(--green); color: var(--green); }
.q-nav-btn.is-current { background: var(--green); border-color: var(--green); color: #fff; }

.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); }
.review { display: grid; gap: .75rem; list-style: none; }
.review-item { padding: .875rem 1rem; background: var(--surface); border: 1px solid var(--border); border-left-width: 4px; border-radius: 10px; }
.review-item > * + * { margin-top: .375rem; }
.review-item.is-correct { border-left-color: var(--green); }
.review-item.is-wrong { border-left-color: var(--danger); }
.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; }

/* ---------- 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); }

/* ---------- 11. Profile ---------- */
.profile-current { font-size: 1.25rem; font-weight: 700; color: var(--green); }
.profile-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem .75rem;
  padding: .75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.profile-name { font-weight: 600; }

/* ---------- 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(11, 61, 46, .55); }
.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 (max-width: 22.5rem) {
  .ring { width: 6rem; height: 6rem; }
  .ring-pct { font-size: 1.25rem; }
  .progress-panel { gap: .75rem; padding: .75rem; }
}

@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; }
  .toolbar .seg { width: 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; }
  .main { 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;
    grid-template-areas: "brand nav context search";
    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) 4px;
  }
  .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; }
  .icon-btn { 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; }
  [data-lang-mode="ar"] .pair, [data-lang-mode="en"] .pair { grid-template-columns: minmax(0, 1fr); }
  [data-lang-mode="ar"] .pair > *, [data-lang-mode="en"] .pair > * { grid-column: 1 / -1; grid-row: auto; }

  .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; }

  .irab-table thead { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; white-space: normal; display: table-header-group; }
  .irab-table { display: table; }
  .irab-table tbody { display: table-row-group; }
  .irab-table tr { display: table-row; padding: 0; border: 0; }
  .irab-table th, .irab-table td { display: table-cell; padding: .625rem .75rem; vertical-align: top; text-align: start; border-top: 1px solid var(--green-100); }
  .irab-table th { font-size: .75rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); border-top: 0; }
  .irab-table td::before { display: none; }
}

/* ---------- 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"], .q-nav-btn.is-current { outline: 2px solid Highlight; }
  .topbar-progress-fill, .meter-fill { background: Highlight; }
}

/* ---------- 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, .toast, .skip-link, .no-print, .back-link, .toolbar,
  .entry-foot, .section-foot, .pager, .loading, dialog, .btn--irab { display: none !important; }
  .view:not(#view-section) { 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, .irab-table tr { break-inside: avoid; }
  .irab[hidden] { display: block !important; }
  .irab { background: #fff; border: 1px solid #999; }
  .example, .ref, .note, .note--gold { background: #fff; }
  .titles .ar, .entry-ar, .card-title-ar, .irab-word, .block-title, .ref-cite { color: #000; }
  a { color: inherit; text-decoration: none; }
  mark { background: none; }
}