:root {
  color-scheme:light;
  --bg:#f4f6f8;
  --surface:#fff;
  --ink:#182b3a;
  --muted:#526474;
  --accent:#09656b;
  --line:#c8d4dc;
  --tint:#eaf5f3;
  --good:#09684f;
  --bad:#a32435
}

* {
  box-sizing:border-box
}
html {
  scroll-behavior:smooth
}
body {
  margin:0;
  font-family:Tahoma,Arial,sans-serif;
  font-size:17px;
  line-height:2;
  background:var(--bg);
  color:var(--ink)
}
body.dark {
  color-scheme:dark;
  --bg:#101c26;
  --surface:#192b38;
  --ink:#e7eff5;
  --muted:#bdcbd5;
  --accent:#73ded2;
  --line:#526b7c;
  --tint:#223e46;
  --good:#7ee2b8;
  --bad:#ffabb5
}
header {
  background:#153543;
  color:#fff;
  padding:16px max(5%,calc((100% - 1020px)/2));
  border-bottom:5px solid #c2a15f
}
header h1 {
  font-size:clamp(1.3rem,4vw,2rem);
  margin:10px 0
}
header p {
  color:#d8e4e9
}
header a {
  color:#e0f7f4
}
nav {
  display:flex;
  flex-wrap:wrap;
  gap:10px 22px
}
nav a[aria-current] {
  text-decoration-thickness:3px;
  text-underline-offset:7px
}
main {
  max-width:1020px;
  margin:32px auto;
  padding:0 20px
}
article {
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:18px;
  padding:clamp(20px,5vw,48px);
  box-shadow:0 8px 30px #10293608
}
article h1 {
  font-size:clamp(1.6rem,4vw,2.3rem)
}
h1,h2,h3,legend {
  line-height:1.65
}
h2 {
  color:var(--accent);
  margin-top:2rem
}
small {
  color:var(--muted);
  font-weight:bold
}
a {
  color:var(--accent);
  text-underline-offset:4px
}
code,.formula,bdi {
  direction:ltr;
  unicode-bidi:isolate
}
code,.formula {
  font-family:Consolas,monospace;
  background:var(--tint);
  padding:4px 8px;
  border-radius:6px
}
.formula {
  display:block;
  text-align:center;
  font-size:clamp(.95rem,3vw,1.25rem);
  padding:15px;
  overflow-wrap:anywhere
}
button {
  font:inherit;
  cursor:pointer;
  background:#09656b;
  color:white;
  border:2px solid transparent;
  border-radius:9px;
  padding:7px 17px;
  margin:8px 0;
  min-height:44px
}
button:hover {
  background:#074a4f
}
button:focus-visible,a:focus-visible,input:focus-visible,summary:focus-visible {
  outline:3px solid #c17e15;
  outline-offset:4px
}
input {
  accent-color:var(--accent);
  inline-size:20px;
  block-size:20px;
  vertical-align:middle;
  margin-inline-end:9px
}
label {
  cursor:pointer;
  display:block;
  padding:6px 10px;
  border-radius:7px;
  min-height:44px
}
label:hover {
  background:var(--tint)
}
.toolbar {
  float:left;
  font-size:.85rem;
  background:#244c5b;
  border-color:#a3c9cd
}
/* Icon theme toggle: the moon offers dark mode, the sun offers light mode; aria-pressed carries the state. */
.theme-toggle {
  width:44px;
  height:44px;
  min-height:44px;
  padding:0;
  border-radius:50%;
  display:inline-grid;
  place-items:center
}
.theme-toggle svg {
  width:22px;
  height:22px;
  display:block
}
.theme-toggle .icon-sun,body.dark .theme-toggle .icon-moon {
  display:none
}
body.dark .theme-toggle .icon-sun {
  display:block
}
.quiz {
  border:1px solid var(--line);
  border-radius:12px;
  padding:22px;
  margin:28px 0
}
.quiz fieldset {
  border:0;
  padding:0;
  min-width:0
}
.quiz legend {
  font-weight:bold;
  padding:0;
  margin-bottom:12px
}
.feedback {
  min-height:2em
}
.good {
  color:var(--good)
}
.bad {
  color:var(--bad)
}
.lab,.callout {
  background:var(--tint);
  border-inline-start:4px solid var(--accent);
  border-radius:10px;
  padding:18px 24px;
  margin:25px 0
}
.lab h2 {
  margin-top:0
}
.argument-flow {
  display:flex;
  flex-wrap:wrap;
  gap:12px;
  padding:14px 0
}
.argument-flow span {
  padding:8px 15px;
  border:1px solid var(--line);
  border-radius:8px;
  background:var(--surface)
}
table {
  width:100%;
  border-collapse:collapse;
  font-size:.95rem;
  margin:18px 0;
  table-layout:fixed
}
th,td {
  border-bottom:1px solid var(--line);
  padding:10px 8px;
  text-align:start;
  overflow-wrap:anywhere
}
th {
  background:var(--tint)
}
caption {
  text-align:start;
  font-weight:bold
}
tr.selected-row {
  background:var(--tint);
  box-shadow:inset -4px 0 var(--accent)
}
progress {
  width:100%;
  height:15px;
  accent-color:var(--accent)
}
details {
  border:1px solid var(--line);
  padding:14px 20px;
  border-radius:10px;
  margin:24px 0
}
summary {
  cursor:pointer;
  font-weight:bold;
  color:var(--accent)
}
ul,ol {
  padding-inline-start:26px
}
.lesson-list {
  list-style:none;
  padding:0;
  counter-reset:lesson
}
.lesson-list li {
  counter-increment:lesson;
  border-bottom:1px solid var(--line);
  padding:18px 0
}
.lesson-list li::before {
  content:counter(lesson, decimal-leading-zero);
  font-family:Consolas,monospace;
  color:var(--muted);
  margin-inline-end:15px
}
.lesson-list a {
  font-weight:bold
}
footer {
  padding:24px;
  text-align:center;
  color:var(--muted);
  font-size:.85rem
}
.skip-link {
  position:absolute;
  top:-100px;
  right:15px;
  background:var(--surface);
  padding:10px;
  z-index:2
}
.skip-link:focus {
  top:10px
}
.feedback,.argument-flow span {
  animation:reveal .2s ease-out
}
@keyframes reveal {
  from {
  opacity:.4;
  transform:translateY(3px)
}
to {
  opacity:1;
  transform:translateY(0)
}

}
@media(prefers-reduced-motion:reduce) {
  html {
  scroll-behavior:auto
}
*,*::before,*::after {
  animation:none!important;
  transition:none!important
}

}
@media(max-width:600px) {
  body {
  font-size:16px
}
main {
  padding:0 10px;
  margin:18px auto
}
.lab,.quiz {
  padding:15px
}
th,td {
  padding:8px 4px
}
header {
  padding:10px 16px
}
nav {
  gap:7px 15px
}
article {
  border-radius:12px
}

}
@media print {
  header,.toolbar,.skip-link,button {
  display:none
}
body,body.dark {
  --bg:white;
  --surface:white;
  --ink:black;
  --accent:#164950;
  --line:#aaa;
  --tint:#f5f5f5;
  --muted:#444;
  --good:#09684f;
  --bad:#a32435;
  color-scheme:light
}
main {
  max-width:none;
  padding:0;
  margin:0
}
article {
  border:0;
  box-shadow:none;
  padding:0
}
.quiz,.lab {
  break-inside:avoid
}

}


.brand {
  font-size:clamp(1.15rem,3.4vw,1.6rem);
  font-weight:bold;
  line-height:1.5;
  margin:4px 0
}
.source-note {
  font-size:.9rem;
  color:var(--muted)
}

select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px; width: 100%; min-height: 44px; }
select:focus-visible { outline: 3px solid #c17e15; outline-offset: 4px; }
/* References, bookmarks, and phone layouts. */
[hidden] { display: none !important; }
/* A link that jumps upward reveals the header, so leave room for it above the target. */
.lesson-section, .glossary-entry, h2[id] { scroll-margin-top: calc(var(--header-h, 0px) + var(--section-nav-h, 0px) + 16px); }
.lesson-toc { display:block; background:var(--tint); border:1px solid var(--line); border-radius:12px; padding:18px 24px; }
.lesson-toc ol { margin-bottom:0; }
.lesson-toc a { text-decoration-thickness:1px; }
.permalink { font-size:.8em; font-weight:normal; padding:4px 9px; text-decoration:none; }
:target { outline:2px solid var(--accent); outline-offset:6px; border-radius:3px; }
.reading-help { color:var(--muted); font-size:.9rem; }
.term-overlay { position:fixed; inset:0; z-index:100; background:#061622b8; display:flex; align-items:center; justify-content:center; padding:16px; }
.term-dialog { background:var(--surface); color:var(--ink); border:1px solid var(--line); border-radius:16px; padding:24px; max-width:620px; width:100%; max-height:85vh; overflow:auto; box-shadow:0 15px 65px #0005; }
.term-dialog h2 { margin-top:12px; clear:both; }
/* An English name under an Arabic term lines up with the Arabic (right), not with the far left edge. */
.term-dialog p[lang=en], .native-definition p[lang=en], .glossary-entry p[lang=en] { text-align:right; color:var(--muted); overflow-wrap:anywhere; }
.term-close { float:left; margin:0; }
.definition-open { overflow:hidden; }
.glossary-entry { border-top:1px solid var(--line); padding:12px 0 25px; }
#glossary-search { width:100%; min-height:48px; padding:10px; font:inherit; color:var(--ink); background:var(--surface); border:1px solid var(--line); border-radius:8px; }
.interaction-warning { padding:15px; border:2px solid #b77a22; border-radius:8px; }
.interactions-ready .interaction-warning { display:none; }
.manual-answer { font-size:.9rem; }
.manual-answer summary { font-weight:normal; }
@media(max-width:600px) { .term-dialog { padding:18px; } .lesson-toc { padding:15px; } .term-overlay { align-items:flex-end; padding:8px; } }
@media print { .term-overlay,.interaction-warning { display:none!important; } }

/* A term is a definition control; full navigation is an explicit link inside. */
button.term-link { display:inline; font:inherit; color:inherit; background:none; border:0; border-radius:0; padding:0; margin:0; min-height:0; text-decoration-line:underline; text-decoration-style:dotted; text-decoration-color:var(--accent); text-underline-offset:5px; cursor:pointer; }
button.term-link:hover { color:var(--accent); background:none; }
.native-definition { color:var(--ink); background:var(--surface); border:1px solid var(--line); border-radius:16px; padding:24px; width:min(620px,calc(100vw - 32px)); max-height:80dvh; overflow:auto; box-shadow:0 15px 65px #0005; }
.native-definition::backdrop { background:#06162270; }
.native-definition h2 { clear:both; margin-top:12px; }
@media(max-width:600px) { .native-definition { inset:auto 0 12px; margin-inline:auto; padding:18px; } }

.table-scroll { overflow-x:auto; margin:20px 0; }
.table-scroll table { min-width:560px; margin:0; }
.table-scroll table.compact { min-width:0; }
.table-scroll:focus-visible { outline:3px solid #c17e15; outline-offset:3px; }
/* Header lesson menu: a native details dropdown that stays usable as the course grows. */
/* The header stays at the top while reading, so the lesson menu and theme button are always one tap away.
   It slides away while scrolling down and returns on any scroll up (course.js), so it does not eat a phone screen. */
header { position:sticky; top:0; z-index:40; transition:transform .25s ease; }
header.header-hidden { transform:translateY(-100%); }
@media (prefers-reduced-motion:reduce) { header { transition:none; } }
.lesson-menu { border:0; padding:0; margin:0; border-radius:0; }
.lesson-menu > summary { cursor:pointer; color:#e0f7f4; font-weight:normal; text-decoration:underline; text-underline-offset:4px; list-style:none; }
.lesson-menu > summary::-webkit-details-marker { display:none; }
.lesson-menu > summary::after { content:" ▾"; }
.lesson-menu[open] > summary::after { content:" ▴"; }
.lesson-menu > ol { position:absolute; z-index:30; top:calc(100% - 2px); inset-inline:max(18px,calc((100% - 1020px)/2)) auto; width:min(28rem,calc(100% - 36px)); max-height:min(70vh,34rem); overflow:auto; margin:0; padding:12px 38px 12px 16px; background:var(--surface); color:var(--ink); border:1px solid var(--line); border-radius:12px; box-shadow:0 14px 34px #0004; }
.lesson-menu li { margin:6px 0; }
.lesson-menu ol a { color:var(--accent); }
.lesson-menu ol a[aria-current] { font-weight:bold; text-decoration-thickness:3px; }
/* Collapsible lesson sections (added by course.js). */
h2:has(> .section-toggle) { margin-bottom:.4rem; }
button.section-toggle { display:flex; flex-wrap:wrap; align-items:baseline; gap:.6em; width:100%; font:inherit; line-height:inherit; color:inherit; background:none; border:0; border-radius:6px; padding:0; margin:0; min-height:0; text-align:start; }
button.section-toggle:hover { background:none; text-decoration:underline; text-underline-offset:6px; }
button.section-toggle::after { content:"▾"; font-size:.8em; color:var(--muted); transition:transform .2s; }
.lesson-section.collapsed button.section-toggle::after { transform:rotate(90deg); }
.section-controls { display:flex; flex-wrap:wrap; gap:0 12px; margin:10px 0 0; }
.section-controls button { font-size:.9rem; background:transparent; color:var(--accent); border-color:var(--line); }
.section-controls button:hover { background:var(--surface); }
@media print {
  button.term-link { display:inline!important; }
  /* Chart bars and markers are backgrounds, which browsers drop when printing unless asked. */
  .freq-bar span, .swatch, .range-axis span { print-color-adjust:exact; -webkit-print-color-adjust:exact; }
  button.section-toggle { display:block!important; }
  button.section-toggle::after, .section-controls { display:none!important; }
  .section-body[hidden] { display:block!important; content-visibility:visible!important; }
}
/* Lesson 10: share of positive results that are true positives. Stripes, not colour alone, mark the false positives. */
.freq-bar {
  display:flex;
  height:30px;
  border:1px solid var(--line);
  border-radius:6px;
  overflow:hidden;
  margin:12px 0 6px
}
.freq-bar span {
  display:block;
  height:100%
}
.freq-bar .bar-true {
  background:var(--accent)
}
.freq-bar .bar-false {
  flex:1;
  background:repeating-linear-gradient(135deg,var(--muted) 0 3px,transparent 3px 8px)
}
.freq-legend {
  display:flex;
  flex-wrap:wrap;
  gap:4px 18px;
  font-size:.92rem;
  color:var(--muted);
  margin:0 0 12px;
  padding:0;
  list-style:none
}
.freq-legend .swatch {
  display:inline-block;
  width:14px;
  height:14px;
  border:1px solid var(--line);
  vertical-align:middle;
  margin-inline-end:6px
}
/* Lesson 11: causal diagrams drawn as inline SVG; colours follow the theme through currentColor. */
.dag {
  display:block;
  width:100%;
  max-width:560px;
  height:auto;
  margin:14px auto;
  color:var(--ink)
}
.dag.small {
  max-width:340px
}
.dag rect {
  fill:var(--surface);
  stroke:currentColor;
  stroke-width:1.5
}
.dag .edge {
  stroke:currentColor;
  stroke-width:1.6;
  fill:none
}
.dag text {
  fill:currentColor;
  font-size:15px
}
/* An adjusted variable gets a thick border (not colour alone) and a tinted fill. */
.dag .adjusted rect {
  stroke-width:4;
  fill:var(--tint)
}
/* A large diagram keeps readable labels on phones by scrolling sideways, like wide tables. */
.dag-scroll {
  overflow-x:auto
}
.dag-scroll .dag {
  min-width:500px
}
/* Lesson 12: where 95 of 100 estimates fall. The axis runs left to right like a number line; the band and its edges carry the meaning, not colour alone. */
.range-axis {
  position:relative;
  height:46px;
  margin:18px 0 28px;
  border-bottom:2px solid var(--muted)
}
.range-axis .range-band {
  position:absolute;
  bottom:8px;
  height:20px;
  background:var(--tint);
  border:2px solid var(--accent);
  border-radius:4px
}
.range-axis .range-true {
  position:absolute;
  bottom:0;
  width:3px;
  height:40px;
  margin-left:-1.5px;
  background:var(--ink)
}
.range-axis .range-zero {
  position:absolute;
  bottom:0;
  height:46px;
  border-left:2px dashed var(--muted)
}
.range-axis .tick {
  position:absolute;
  top:100%;
  transform:translateX(-50%);
  font-size:.85rem;
  color:var(--muted);
  padding-top:2px
}
/* How to read a formula: the Arabic reading, then the English reading on its own line. */
.reading { text-align:center; color:var(--muted); margin-top:-6px; }
.reading bdi[lang="en"] { display:block; }
/* English beside an Arabic heading or contents entry: on the same line when it fits, moving to the next line
   as one unit when it does not. As an inline-block it is also left out of the link underline. The gap is margin-right
   because the English box is left-to-right, so its own inline-start is the left side. */
.heading-en { display:inline-block; margin-right:.6em; text-align:right; font-size:.62em; font-weight:normal; color:var(--muted); }
button.section-toggle .section-title { flex:1; }
.lesson-toc .toc-en { display:inline-block; margin-right:.6em; text-align:right; font-size:.85em; color:var(--muted); }
/* A term button and the punctuation after it stay on one line. */
.term-wrap { white-space:nowrap; }
/* Inline formulas and variables: a code-like chip, so symbols stand apart from the Arabic around them. */
bdi.math { font-family:Consolas,"Cascadia Mono","DejaVu Sans Mono",monospace; font-size:.95em; background:var(--tint); border:1px solid var(--line); border-radius:4px; padding:0 .3em; white-space:nowrap; -webkit-box-decoration-break:clone; box-decoration-break:clone; }
.formula bdi.math { background:none; border:0; padding:0; font-size:inherit; white-space:normal; }
/* A table whose first column holds formulas: give that column room, since fixed layout splits widths evenly. */
table.lead-col thead th:first-child { width:46%; }
/* Section navigator (built by course.js). Narrow screens: a slim bar that stays at the top of the lesson and
   opens the list. Wide screens: a side column beside the lesson. The section being read is marked by a bar
   and bold text, not by colour alone. */
article.has-section-nav > .section-nav { position:sticky; z-index:20; top:calc(var(--header-h, 0px) + 8px); margin-bottom:16px; transition:top .25s ease; }
html.header-hidden article.has-section-nav > .section-nav { top:8px; }
@media (prefers-reduced-motion:reduce) { article.has-section-nav > .section-nav { transition:none; } }
.section-nav-toggle { width:100%; min-height:44px; display:flex; gap:.4em; align-items:baseline; text-align:start; background:var(--surface); color:var(--ink); border:1px solid var(--line); border-radius:10px; padding:8px 14px; box-shadow:0 4px 14px #0002; font-size:.95rem; font-weight:normal; }
.section-nav-toggle:hover { background:var(--surface); border-color:var(--accent); }
.section-nav-toggle::after { content:"▾"; margin-inline-start:auto; color:var(--muted); }
.section-nav.open .section-nav-toggle::after { content:"▴"; }
.section-nav-label { color:var(--muted); }
.section-nav-current { font-weight:bold; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; min-width:0; }
.section-nav-panel { display:none; }
.section-nav.open .section-nav-panel { display:flex; flex-direction:column; position:absolute; inset-inline:0; top:calc(100% + 6px); background:var(--surface); border:1px solid var(--line); border-radius:12px; padding:12px 14px; box-shadow:0 14px 34px #0004; max-height:min(70vh, 34rem); }
.section-nav-heading { font-weight:bold; margin:0 0 6px; }
.section-nav ol { position:relative; overflow:auto; min-height:0; margin:0; padding-inline-start:1.6em; }
.section-nav li { margin:2px 0; }
.section-nav a { display:block; padding:4px 8px; color:var(--ink); text-decoration:none; border-inline-start:3px solid transparent; border-radius:4px; line-height:1.6; }
.section-nav a:hover { text-decoration:underline; }
.section-nav a[aria-current] { border-inline-start-color:var(--accent); background:var(--tint); color:var(--accent); font-weight:bold; }
.section-nav .section-controls { margin-top:10px; }
@media (min-width:1200px) {
  body.with-section-nav main { max-width:1320px; }
  article.has-section-nav { display:grid; grid-template-columns:minmax(0,1fr) 16rem; column-gap:40px; align-items:start; }
  article.has-section-nav > .article-body { grid-column:1; grid-row:1; min-width:0; }
  article.has-section-nav > .section-nav { grid-column:2; grid-row:1; margin:0; }
  .section-nav-toggle { display:none; }
  .section-nav-panel, .section-nav.open .section-nav-panel { display:flex; flex-direction:column; position:static; box-shadow:none; background:var(--tint); border-radius:12px; padding:12px 14px; max-height:calc(100vh - var(--header-h, 0px) - 32px); }
  html.header-hidden .section-nav-panel { max-height:calc(100vh - 32px); }
}
@media print { .section-nav { display:none !important; } article.has-section-nav { display:block; } }
