/* ==========================================================================
   دروس النحو (Nahw Lessons)
   styles.css: mobile-first. A lessons menu slides in on phones and tablets
   and becomes a fixed sidebar at 64rem and wider.

   The colour palettes below are copied unchanged from the Sharḥ
   (/miata/styles.css), so the two parts of Manar look like one site, and
   the palette, light/dark and text-size choices are shared between them.
     data-palette      : "green" (default, green & gold) | "slate" (silver)
     data-color-scheme : "light" (default) | "dark"
     data-text-scale   : "sm" | "md" (default) | "lg"
   ========================================================================== */

/* ---------- 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;
  --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;
}

/* ---------- Lesson-specific tokens ---------- */
:root {
  --hl: #C81E1E;              /* the teacher's red: words being taught */
  --topbar-h: 3.5rem;
  --sidebar-w: 19.5rem;
  --read-w: 48rem;            /* comfortable reading width for a lesson */
}

:root[data-color-scheme="dark"] {
  --hl: #FF8A80;
}

/* ---------- Text-size scaling (same three steps as the Sharḥ) ---------- */
:root { --fs-zoom: 1; }
:root[data-text-scale="sm"] { --fs-zoom: 0.9; }
:root[data-text-scale="lg"] { --fs-zoom: 1.15; }

/* Reading content only. Navigation is never scaled. */
#lesson-content,
#search-results,
#home-list,
#continue-card,
#quizzes-list,
#words-list,
#exam-setup,
#exam-stage,
#exam-history {
  zoom: var(--fs-zoom);
}

[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 (as in the Sharḥ) ---------- */
*, *::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;
}

body.drawer-open { overflow: hidden; }

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, [tabindex="-1"]:focus { outline: none; }

/* Arabic: any element with lang="ar" gets the Arabic face and room for the
   vowel marks. Never letter-space or transform Arabic (it 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; }

mark {
  background: #D6E4F0;
  color: #1F2937;
  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;
}

.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 ---------- */
.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: .25rem;
  height: var(--topbar-h);
  padding: 0 max(.375rem, env(safe-area-inset-right, 0px)) 0 max(.375rem, env(safe-area-inset-left, 0px));
}

.brand { display: none; }

.topbar-context {
  flex: 1;
  min-width: 0;
  padding-inline: .25rem;
}

.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.35;
  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); }
.icon-btn[aria-current="page"] { background: rgba(255, 255, 255, .16); }

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

/* ---------- 3. Drawer (lessons menu) ----------
   Phones and tablets: a panel that slides in from the left, in the top
   bar's green. 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-progress {
  margin-top: .5rem;
  display: grid;
  gap: .375rem;
  max-width: 16rem;
  font-size: .875rem;
  color: var(--dr-muted);
}

.drawer-progress .meter { background: var(--dr-num-bg); }
.drawer-progress .meter-fill { background: var(--dr-accent); }

.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;
}

.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; }

/* Sections of the open lesson */
.dl-secs {
  list-style: none;
  margin: .125rem 0 .5rem 2.4rem;
  padding-left: .625rem;
  border-left: 1px solid var(--dr-line);
}

.dl-sec {
  display: flex;
  flex-direction: column;
  min-height: 2.5rem;
  justify-content: center;
  padding: .3rem .75rem;
  margin-left: -.6875rem;
  border-left: 3px solid transparent;
  color: var(--dr-muted);
  font-size: .9063rem;
  line-height: 1.35;
  text-decoration: none;
}

.dl-sec:hover { color: var(--dr-text); background: var(--dr-hover); }

.dl-sec[aria-current="location"] {
  color: var(--dr-text);
  font-weight: 600;
  border-left-color: var(--dr-accent);
}

.dl-sec .dl-sec-ar { font-size: 1.0625rem; line-height: 1.6; }

/* ---------- 4. Page layout ---------- */
.layout { display: block; }

.main {
  min-width: 0;
  padding: 1rem max(var(--gutter), env(safe-area-inset-right, 0px)) calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 2.5rem) max(var(--gutter), env(safe-area-inset-left, 0px));
}

.view {
  display: block;
  max-width: var(--read-w);
  margin-inline: auto;
}

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

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

.view-head h1 {
  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; }

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

/* Bilingual titles: Arabic above English (as in the Sharḥ) */
.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.25rem;
  font-weight: 600;
  color: var(--text);
}

.titles .en:first-child {
  font-size: clamp(1.625rem, 6vw, 2rem);
  font-weight: 700;
  color: var(--green);
}

.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; }

/* ---------- 5. Buttons, inputs, segmented control (as in the Sharḥ) ---------- */
.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--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { background: #7F1616; }

.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::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);
}

.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); }

.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: lesson list ---------- */
.home-progress {
  display: grid;
  gap: .375rem;
  max-width: 20rem;
}

.continue-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;
}

.continue-card:hover { border-color: var(--gold); }
.continue-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.continue-label { font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--gold-ink); }
.continue-title { font-weight: 600; }
.continue-sub { font-size: .875rem; color: var(--muted); }

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

.card-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  height: 100%;
  min-height: 48px;
  padding: .625rem .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: 2rem;
  height: 2rem;
  background: var(--green-50);
  color: var(--green);
  border: 1px solid var(--green-100);
  border-radius: 50%;
  font-size: .8125rem;
  font-weight: 700;
}

.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-title-en { font-size: .8125rem; color: var(--muted); }

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

.done-tag {
  font-size: .75rem;
  font-weight: 700;
  color: var(--green);
}

/* ---------- 7. Lesson ---------- */
.lesson-head { margin-bottom: 1.25rem; }
.lesson-head .titles { margin-top: .25rem; }
.lesson-sub { margin-top: .25rem; font-size: 1.0625rem; color: var(--muted); }

.lesson-body {
  display: grid;
  gap: 1.25rem;
}

/* One card per section of the handout */
.lsec {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  scroll-margin-top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + .75rem);
}

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

.lsec--ex .lsec-head {
  background: var(--gold-50);
  border-bottom-color: var(--gold-line);
}

.lsec-title {
  display: flex;
  flex-direction: column;
  font-size: 1.1875rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--green);
}

.lsec-title .ar {
  font-size: 1.625rem;
  line-height: 1.7;
}

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

.lsec-body > * { min-width: 0; }

/* Subheading inside a section (Heading 3 in the handout) */
.lh3 {
  margin-top: .375rem;
  padding-bottom: .25rem;
  border-bottom: 1px solid var(--border);
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--green);
}

.lh3[lang="ar"] {
  font-size: 1.5rem;
  line-height: 1.7;
}

/* Paragraphs; numbered ones carry the teacher's number in a circle */
.lp { max-width: 70ch; }

.lp--num {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: .625rem;
  align-items: start;
}

.num {
  display: grid;
  place-items: center;
  min-width: 1.625rem;
  height: 1.625rem;
  margin-top: .0625rem;
  padding: 0 .3rem;
  background: var(--green-50);
  color: var(--green);
  border: 1px solid var(--green-100);
  border-radius: 999px;
  font: 700 .75rem/1 var(--font-en);
}

.lp[lang="ar"] { font-size: 1.35rem; line-height: 2; }
.lp[lang="ar"] .num { margin-top: .5rem; font-size: .75rem; }

/* Bullet list */
.lul {
  display: grid;
  gap: .375rem;
  padding-left: 1.25rem;
  max-width: 70ch;
}

.lul li::marker { color: var(--gold-ink); }

/* Example lines (centred in the handout, or Arabic on a line of its own) */
.disp {
  display: grid;
  gap: .125rem;
  padding: .75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--green-100);
  border-radius: 10px;
  text-align: center;
}

.disp-line { font-size: 1.0625rem; }
.disp-line[lang="ar"] { font-size: 1.625rem; line-height: 2.1; }

/* The teacher's highlight: the word or letters being taught */
.hl { color: var(--hl); }

strong { font-weight: 700; }

u {
  text-decoration-thickness: from-font;
  text-underline-offset: .18em;
}

/* Footnotes: the note sits right after the part that refers to it */
.fn-ref {
  font: 700 .7rem/0 var(--font-en);
  color: var(--gold-ink);
  vertical-align: super;
  padding: 0 .1em;
}

[lang="ar"] .fn-ref, .fn-ref + [lang="ar"] { font-family: var(--font-en); }

.fn {
  display: flex;
  gap: .5rem;
  padding: .5rem .75rem;
  background: var(--gold-50);
  border-left: 3px solid var(--gold);
  border-radius: 8px;
  font-size: .875rem;
  line-height: 1.55;
}

.fn-n {
  flex: none;
  font-weight: 700;
  color: var(--gold-ink);
}

.fn-body { min-width: 0; }
.fn-body > * + * { margin-top: .25rem; }

/* ---------- 8. Tables ---------- */
.tbl-wrap {
  max-width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.tbl {
  width: 100%;
  border-collapse: collapse;
}

.tbl th,
.tbl td {
  padding: .375rem .5rem;
  vertical-align: baseline;
  text-align: start;
  border-top: 1px solid var(--border);
}

.tbl td + td,
.tbl th + th,
.tbl th + td { border-inline-start: 1px solid var(--border); }

.tbl thead th {
  background: var(--green-50);
  color: var(--green);
  font-size: .875rem;
  font-weight: 700;
  line-height: 1.4;
  vertical-align: bottom;
  border-top: 0;
  border-bottom: 1px solid var(--green-100);
}

.tbl tbody tr:first-child > * { border-top: 0; }

.cl + .cl { margin-top: .125rem; }
.cl--end { text-align: right; }
.tbl .cl[lang="ar"] { font-size: 1.3125rem; line-height: 1.8; }
.tbl thead .cl[lang="ar"] { font-size: 1.1875rem; line-height: 1.75; }

/* Centred columns: example pairs and short comparison tables */
.tbl .col-c,
.tbl .col-c .cl { text-align: center; }

.tbl .col-no {
  width: 1%;
  white-space: nowrap;
  text-align: center;
  color: var(--muted);
  font-size: .8125rem;
  font-weight: 600;
}

.tbl thead .col-no { color: var(--green); }

/* A word grid that is too wide scrolls sideways, with soft edge shadows
   showing there is more to see. */
.tbl-wrap.is-scroll {
  background:
    linear-gradient(to right, var(--surface) 30%, transparent) left center / 2rem 100% no-repeat local,
    linear-gradient(to left, var(--surface) 30%, transparent) right center / 2rem 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, .16), transparent) left center / .75rem 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .16), transparent) right center / .75rem 100% no-repeat scroll,
    var(--surface);
}

.tbl-wrap.is-scroll:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }

/* When a table is too wide for the screen, each row becomes a card. Its
   cells sit side by side, each with its column name above it, and wrap
   onto the next line when there is no room (long sentences take a line
   of their own). */
@media screen {
  .tbl-wrap.is-cards {
    overflow: visible;
    background: transparent;
    border: 0;
    border-radius: 0;
  }

  .is-cards .tbl,
  .is-cards .tbl tbody { display: block; }

  .is-cards .tbl thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .is-cards .tbl tr {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: .5rem 1.5rem;
    padding: .75rem .875rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
  }

  .is-cards .tbl tr + tr { margin-top: .625rem; }

  .is-cards .tbl td {
    display: block;
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    padding: 0;
    border: 0;
    text-align: start;
  }

  .is-cards .tbl td:empty { display: none; }

  .is-cards .tbl td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: .125rem;
    font: 600 .75rem/1.4 var(--font-en);
    color: var(--muted);
  }

  .is-cards .tbl td[data-label-ar]::before {
    font-family: var(--font-ar);
    font-size: .9375rem;
    letter-spacing: normal;
    text-transform: none;
  }

  .is-cards .tbl .col-c .cl { text-align: start; }
  .is-cards .tbl .cl--end { text-align: start; }

  .is-cards .tbl .col-no {
    flex: none;
    display: grid;
    place-items: center;
    align-self: center;
    min-width: 1.75rem;
    height: 1.75rem;
    padding: 0 .3rem;
    background: var(--green-50);
    color: var(--green);
    border: 1px solid var(--green-100);
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 700;
  }

  .is-cards .tbl .col-no::before { content: none !important; }
}

/* ---------- 9. Exercise and word lists ---------- */
.xlist-label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .25rem .75rem;
  font-size: .875rem;
  font-weight: 700;
  color: var(--green);
}

.xlist-label [lang="ar"] { font-size: 1.25rem; }

.xlist {
  display: grid;
  gap: .5rem;
  list-style: none;
}

.xi {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .5rem .875rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.xi .num { margin-top: .3rem; }
.xi-t { flex: 1; min-width: 0; padding-top: .125rem; }
.xi-t .cl[lang="ar"] { font-size: 1.5rem; line-height: 2; }
.xi-t .cl:not([lang="ar"]) { padding-block: .1rem; }
.xi-t .cl[lang="ar"] + .cl:not([lang="ar"]) { color: var(--muted); font-size: .9375rem; }

/* A space the teacher left for the learner's own answer */
.blank {
  display: block;
  height: 2.25rem;
  border-bottom: 2px dotted var(--border-strong);
}

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

.chip {
  padding: 0 .875rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.chip [lang="ar"], .chip[lang="ar"] { font-size: 1.375rem; line-height: 1.9; }

/* ---------- 10. Lesson footer ---------- */
.lesson-foot {
  display: grid;
  gap: 1rem;
  margin-top: 1.5rem;
}

.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; }

/* Brief flash on the block a search result points to */
.flash { animation: flash 1.6s ease-out; border-radius: 8px; }

@keyframes flash {
  0%, 30% { box-shadow: 0 0 0 4px var(--gold); }
  100% { box-shadow: 0 0 0 4px transparent; }
}

/* ---------- 11. Search ---------- */
.search-form { display: flex; gap: .5rem; }
.search-form .input { flex: 1; min-width: 0; }

.result-group + .result-group { margin-top: 1.25rem; }

.result-group-head {
  margin-bottom: .5rem;
  font-size: .875rem;
  font-weight: 700;
  color: var(--gold-ink);
}

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

.result-link {
  display: block;
  min-height: 44px;
  padding: .75rem 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); }
.result-snippet[lang="ar"] { font-size: 1.3125rem; line-height: 1.9; color: var(--text); }
.result-snippet mark { color: #1F2937; }
.result-more { font-size: .8125rem; font-weight: 600; color: var(--gold-ink); }

/* ---------- 12. Dialog & 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: var(--bg);
  border-radius: 10px;
  font-size: .9375rem;
  transform: translateX(-50%);
}


/* ---------- Bottom tab bar (phones) ----------
   Three top-level places are always visible at the bottom, within thumb
   reach, with text labels (as in the Sharḥ). On desktop they sit in the top
   bar. The lesson contents stay one tap away via the list button. */
.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; }
body.drawer-open .tabbar { visibility: hidden; }

/* ---------- Form fields (as in the Sharḥ) ---------- */
.controls { display: flex; flex-wrap: wrap; gap: .75rem; }
.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; }
select.input { appearance: auto; }

.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: 700;
  line-height: 1.5;
  white-space: nowrap;
}

.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); }
.badge--none { background: transparent; color: var(--muted); border-color: var(--border); font-weight: 600; }

/* ---------- Quizzes ---------- */
.quiz {
  display: grid;
  gap: .875rem;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--gold-line);
  border-radius: 14px;
  scroll-margin-top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + .75rem);
}

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

.quiz-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem .75rem;
}

.quiz-title {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--green);
}

.quiz-title .icon { color: var(--gold-ink); }
.quiz-sub { color: var(--muted); font-size: .9375rem; max-width: 60ch; }

.quiz-progress {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: .75rem;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--muted);
}

.q-group { font-size: .875rem; font-weight: 700; color: var(--gold-ink); }
.q-ask { font-weight: 600; }
.q-ask [lang="ar"] { font-size: 1.15em; }

.q-prompt {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.q-prompt .num { margin-top: .55rem; }
.q-prompt-text { flex: 1; min-width: 0; }
.q-prompt .cl[lang="ar"] { font-size: 1.75rem; line-height: 2.1; }
.q-prompt .cl:not([lang="ar"]) { font-size: 1.125rem; font-weight: 500; line-height: 1.5; padding-block: .25rem; }
.q-prompt .cl[lang="ar"] + .cl:not([lang="ar"]) { font-size: 1rem; color: var(--muted); font-weight: 400; }

.q-form { display: grid; gap: .75rem; }

.q-input {
  font-size: 1.0625rem;            /* 16px+ so phones do not zoom in */
}

.q-input[readonly] { background: var(--bg); }

.q-options {
  display: grid;
  gap: .5rem;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

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

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

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

.q-dot {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
}

.q-option:has(input:checked) { border-color: var(--green); background: var(--green-50); }
.q-option:has(input:checked) .q-dot { border-color: var(--green); background: var(--green); box-shadow: inset 0 0 0 3px var(--surface); }
.q-option:has(input:focus-visible) { outline: 3px solid var(--green); outline-offset: 2px; }

.q-option-text { flex: 1; min-width: 0; }
.q-option-text[lang="ar"] { font-size: 1.75rem; line-height: 2.1; text-align: right; }   /* large enough to tell ُ from ٌ */
.q-option-text:not([lang="ar"]) { font-size: 1rem; line-height: 1.4; }

.q-option .q-mark { flex: none; display: none; }
.q-options.is-done .q-option { cursor: default; }
.q-options.is-done .q-option:hover { border-color: var(--border-strong); }
.q-option.is-correct { border-color: var(--green); background: var(--ok-50); }
.q-option.is-correct .q-mark { display: block; color: var(--green); }
.q-option.is-wrong { border-color: var(--danger); background: var(--danger-50); }
.q-option.is-wrong .q-mark { display: block; color: var(--danger); }
.q-option .q-mark .icon { width: 1.375rem; height: 1.375rem; stroke-width: 2.5; }

.q-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1rem;
}

.link-btn {
  min-height: 44px;
  padding: 0 .25rem;
  background: none;
  border: 0;
  color: var(--green);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: .15em;
}

.q-hint { font-size: .875rem; color: var(--danger); font-weight: 600; }
.q-hint:empty { display: none; }

.q-feedback {
  display: grid;
  gap: .375rem;
  padding: .75rem 1rem;
  border: 1px solid;
  border-radius: 12px;
}

.q-feedback.is-correct { background: var(--ok-50); border-color: var(--green-100); }
.q-feedback.is-wrong { background: var(--danger-50); border-color: var(--danger-line); }

.q-feedback-title {
  display: flex;
  align-items: center;
  gap: .375rem;
  font-weight: 700;
}

.q-feedback.is-correct .q-feedback-title { color: var(--green); }
.q-feedback.is-wrong .q-feedback-title { color: var(--danger); }
.q-feedback-title .icon { stroke-width: 2.5; }

.q-line { font-size: .9375rem; }
.q-line b { font-weight: 600; color: var(--muted); }
.q-line [lang="ar"] { font-size: 1.5rem; line-height: 1.9; }
.q-line mark { background: #FDE7A9; color: #1F2937; border-radius: 3px; padding: 0 .15em; }

/* Result */
.q-result { display: grid; gap: .75rem; }

.q-score {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .25rem 1rem;
}

.q-score-num { font-size: 2.25rem; font-weight: 700; line-height: 1.1; color: var(--green); }
.q-result.is-fail .q-score-num { color: var(--danger); }
.q-score-detail { color: var(--muted); font-weight: 600; }

.q-review { display: grid; gap: .5rem; list-style: none; }

.q-review li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: .25rem .625rem;
  padding: .5rem .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.q-review .rv-mark { padding-top: .25rem; }
.q-review .rv-mark .icon { width: 1.125rem; height: 1.125rem; stroke-width: 2.75; }
.q-review .is-right .rv-mark { color: var(--green); }
.q-review .is-wrong .rv-mark { color: var(--danger); }
.q-review .rv-q [lang="ar"] { font-size: 1.4375rem; line-height: 1.9; }
.q-review .rv-a { grid-column: 2; font-size: .875rem; color: var(--muted); }
.q-review .rv-a [lang="ar"] { font-size: 1.375rem; color: var(--text); }

/* The exercise as printed, kept for reference under the quiz */
.quiz-source { border-top: 1px dashed var(--border); padding-top: .5rem; }
.quiz-source > summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  color: var(--green);
  font-weight: 600;
}
.quiz-source[open] > summary { margin-bottom: .5rem; }
.quiz-source > *:not(summary) + * { margin-top: .75rem; }

.practice-note {
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Quizzes tab, lesson quiz list ---------- */
.feature-card {
  display: flex;
  align-items: center;
  gap: .875rem;
  min-height: 56px;
  padding: 1rem;
  background: var(--green-surface);
  color: #fff;
  border-radius: var(--radius);
  text-decoration: none;
}

.feature-card:hover { background: var(--green-600); }
.feature-card .icon { color: var(--gold); }
.feature-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.feature-title { font-weight: 700; font-size: 1.0625rem; }
.feature-meta { font-size: .8125rem; color: var(--on-green); }

.quiz-lesson { margin-top: 1.5rem; }
.quiz-lesson-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem .75rem; margin-bottom: .5rem; }
.quiz-lesson-title { font-size: 1rem; font-weight: 700; color: var(--green); }
.quiz-lesson-title [lang="ar"] { font-size: 1.25rem; }

.quiz-links { display: grid; gap: .5rem; list-style: none; }

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

.quiz-link:hover { border-color: var(--green); }
.quiz-link-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.quiz-link-title { font-weight: 600; }
.quiz-link-meta { font-size: .8125rem; color: var(--muted); }
.quiz-link .icon { color: var(--green); }

/* ---------- Words ---------- */
.word-lesson + .word-lesson { margin-top: 1.75rem; }
.word-group + .word-group { margin-top: 1.25rem; }
.word-group-head { margin-bottom: .5rem; font-size: .875rem; font-weight: 700; color: var(--gold-ink); }

.word-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: .5rem;
  list-style: none;
}

.word {
  display: flex;
  flex-direction: column;
  padding: .375rem .75rem .5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.word-ar { font-size: 1.375rem; line-height: 1.8; text-align: right; }
.word-ar2 { font-size: 1rem; color: var(--muted); }
.word-en { font-size: .875rem; color: var(--muted); line-height: 1.35; white-space: pre-line; }

/* ---------- Exam ---------- */
.exam-setup > * + * { margin-top: 1rem; }
.exam-field { margin: 0; padding: 0; border: 0; min-width: 0; }
.exam-field legend { margin-bottom: .5rem; }

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: .5rem;
}

.check-grid label,
.check-row {
  display: flex;
  align-items: center;
  gap: .625rem;
  min-height: 44px;
  padding: .25rem .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.check-row { display: inline-flex; }
input[type="checkbox"] { width: 1.25rem; height: 1.25rem; margin: 0; accent-color: var(--green-surface); flex: none; }

.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; }

.check-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.check-title { font-weight: 600; }
.check-meta { font-size: .8125rem; color: var(--muted); }

/* Quiz passed: a tick at the end of the part in the lesson contents */
.dl-sec-label { display: flex; align-items: center; gap: .5rem; }
.dl-sec-label > span:first-child { flex: 1; min-width: 0; }
.dl-sec-done { flex: none; color: var(--dr-check); }
.dl-sec-done .icon { width: 1.125rem; height: 1.125rem; stroke-width: 2.75; }

/* Answer marked: the picked wrong option in red, the right one in green */
.q-options.is-done .q-option.is-correct { border-color: var(--green); background: var(--ok-50); }
.q-options.is-done .q-option.is-wrong { border-color: var(--danger); background: var(--danger-50); }
.q-options.is-done .q-option.is-wrong .q-dot { border-color: var(--danger); background: var(--danger); box-shadow: inset 0 0 0 3px var(--surface); }
.q-options.is-done .q-option:not(.is-correct):not(.is-wrong) { opacity: .7; }

.q-ask [lang="ar"] { white-space: nowrap; }
.q-meanings { list-style: none; margin-top: .25rem; display: grid; gap: .125rem; }

/* Review list: the question with its number, as in the lesson */
.q-review .rv-q { display: flex; align-items: flex-start; gap: .5rem; min-width: 0; }
.q-review .rv-q .num { margin-top: .35rem; }
.q-review .rv-q-text { flex: 1; min-width: 0; }

/* Single English words in quizzes and word cards: a capital I with serifs,
   so "Ill" can't be read as "lll" (Inter's cv08; ignored if the font lacks it). */
.q-prompt, .q-option-text, .q-line, .q-review, .word-en { font-feature-settings: "cv08" 1; }

/* While typing an answer on a phone the keyboard needs the room */
body.is-typing .tabbar { display: none; }

/* ---------- 13. Breakpoints ---------- */
@media (min-width: 40rem) {
  .tbl th, .tbl td { padding: .4rem .75rem; }
  .pager { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pager-link--next { grid-column: 2; }
  .lsec-head { padding: .875rem 1.25rem; }
  .lsec-body { padding: 1.25rem; }
}

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

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

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

  .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: .75rem;
    height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    padding-inline: max(1rem, env(safe-area-inset-left, 0px)) max(1rem, env(safe-area-inset-right, 0px));
  }

  .topbar-row { display: contents; }
  .brand { grid-area: brand; }
  #btn-hub { grid-area: hub; }
  #btn-search { grid-area: search; }
  #btn-settings { grid-area: settings; }

  .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; }
  .toast { bottom: 1.5rem; }

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

  .brand-ar {
    font-family: var(--font-ar);
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.6;
    color: var(--gold);
  }

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

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

  .layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    align-items: start;
  }

  .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; }
  .drawer-progress { margin-top: 0; color: var(--muted); }
  .drawer-progress .meter { background: var(--green-100); }
  .drawer-progress .meter-fill { background: var(--green); }
  .dl-ar { color: var(--green); }
  .dl-link[aria-current="page"] .dl-en:first-child { color: var(--green); }

  .main { padding-top: 1.5rem; padding-bottom: 3rem; }
}

/* ---------- 14. Motion, forced colours, print ---------- */
@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,
  .dl-link[aria-current="page"],
  .dl-sec[aria-current="location"] { outline: 2px solid Highlight; }
  .hl { color: Highlight; }
  .meter-fill { background: Highlight; }
}

@media print {
  .topbar, .tabbar, .drawer, .scrim, .netbar, .skip-link, .back-link, .lesson-foot, .toast, .quiz { display: none !important; }
  .quiz-source { display: block !important; border: 0; }
  .quiz-source > summary { display: none; }
  body { background: #fff; color: #000; }
  .layout { display: block; }
  .main { padding: 0; }
  .view { max-width: none; }
  #lesson-content { zoom: 1; }
  .lsec { border: 0; border-radius: 0; break-inside: auto; }
  .lsec-head { background: none !important; border-bottom: 2px solid #000; padding-inline: 0; }
  .lsec-body { padding-inline: 0; }
  .tbl-wrap { overflow: visible; border-color: #999; }
  .tbl thead th { background: #eee !important; color: #000; }
  .hl { color: #C81E1E !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
