@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/plex-arabic-400.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/plex-latin-400.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/plex-arabic-600.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/plex-latin-600.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/plex-arabic-700.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/plex-latin-700.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #fbfaf7;
  --panel: #ffffff;
  --ink: #16161a;
  --muted: #5f5f6b;
  --faint: #8c8c99;
  --line: #e4e1d9;
  --brand: #1f6f54;
  --brand-soft: #e8f2ed;
  --accent: #8a4b1f;
  --accent-soft: #fbefe4;
  --warn: #9a2c2c;
  --warn-soft: #fbe9e9;
  --violet: #4b3f8f;
  --violet-soft: #eeebfa;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  --arabic: "IBM Plex Sans Arabic", "SF Arabic", "Geeza Pro", "Noto Naskh Arabic", "Segoe UI", Tahoma, sans-serif;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214;
    --panel: #1a1a1e;
    --ink: #eceaf0;
    --muted: #a9a7b4;
    --faint: #76747f;
    --line: #2b2b31;
    --brand: #6fd3aa;
    --brand-soft: #16302a;
    --accent: #e0a46a;
    --accent-soft: #312419;
    --warn: #f08b8b;
    --warn-soft: #351c1c;
    --violet: #a99cf0;
    --violet-soft: #222046;
  }
}

* { box-sizing: border-box; }

html {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--brand) 40%, transparent) transparent;
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--brand) 40%, transparent);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--brand) 65%, transparent);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar a { color: var(--muted); text-decoration: none; font-size: 14px; }
.topbar a:hover { color: var(--brand); }
.topbar .brand {
  font-family: var(--serif);
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.topbar .where { color: var(--faint); font-size: 13px; }

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 36px 20px 96px;
}

.page-head { margin-bottom: 36px; }
.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brand);
  font-weight: 600;
}
h1 {
  font-family: var(--serif);
  font-size: clamp(30px, 5vw, 44px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}
.slide-ref {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
}
.lede { color: var(--muted); font-size: 18px; margin: 14px 0 0; }

h2 {
  font-family: var(--serif);
  font-size: 25px;
  letter-spacing: -0.01em;
  margin: 44px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
h3 { font-size: 17px; margin: 24px 0 8px; letter-spacing: -0.01em; }
p { margin: 0 0 14px; }
ul, ol { margin: 0 0 14px; padding-left: 22px; }
li { margin-bottom: 6px; }
strong { font-weight: 650; }
code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 18px 0;
}
.card > :last-child { margin-bottom: 0; }
.card h3 { margin-top: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 18px 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 18px 0; }
@media (max-width: 680px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
}

.formula {
  font-family: var(--mono);
  font-size: 16px;
  text-align: center;
  background: var(--brand-soft);
  border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin: 18px 0;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.8;
}
.formula .hl { color: var(--accent); font-weight: 700; }

.formula.math {
  white-space: normal;
  line-height: 2.6;
  font-size: 17px;
}
.formula.math .row { display: block; }
.formula.math .row + .row { margin-top: 10px; }
.formula .note { display: block; font-family: var(--sans); font-size: 13px; color: var(--faint); margin-top: 10px; line-height: 1.6; }

.formula sub, .formula sup, code sub, code sup, td sub, td sup, p sub, p sup, li sub, li sup {
  font-size: 0.7em;
  line-height: 0;
  position: relative;
}
.formula sub, code sub, td sub, p sub, li sub { bottom: -0.25em; }
.formula sup, code sup, td sup, p sup, li sup { top: -0.5em; }

.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  white-space: nowrap;
  line-height: 1.35;
  margin: 0 0.3em;
  text-align: center;
}
.frac > .num { padding: 0.1em 0.6em 0.2em; border-bottom: 1.5px solid currentColor; }
.frac > .den { padding: 0.28em 0.6em 0.1em; }

.frac sub, .frac sup {
  position: static;
  line-height: normal;
  bottom: auto;
  top: auto;
}
.frac sup { vertical-align: super; }
.frac sub { vertical-align: sub; }

li:has(.frac), p:has(.frac), td:has(.frac), dd:has(.frac) { line-height: 2.9; }
code:has(.frac) { padding-top: 3px; padding-bottom: 3px; display: inline-block; }

.root {
  display: inline-flex;
  align-items: stretch;
  vertical-align: middle;
  white-space: nowrap;
  line-height: 1.4;
}
.root > .deg { font-size: 0.7em; align-self: flex-start; margin-right: -0.2em; }
.root > .rad { border-top: 1.5px solid currentColor; padding: 0.15em 0.4em 0 0.3em; }
.root::before {
  content: "\221A";
  align-self: center;
}

pre {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.65;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 14px 0;
}
pre code { background: none; border: none; padding: 0; font-size: inherit; }

table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 14.5px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th {
  background: color-mix(in srgb, var(--brand) 8%, transparent);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
}
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { font-family: var(--mono); text-align: right; }
td.zero { color: var(--warn); }
td.pick { background: var(--accent-soft); font-weight: 650; }

.callout {
  border-left: 3px solid var(--brand);
  background: var(--brand-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 14px 18px;
  margin: 18px 0;
}
.callout > :last-child { margin-bottom: 0; }
.callout .tag {
  display: block;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--brand);
}

.memory { border-left-color: var(--violet); background: var(--violet-soft); }
.memory .tag { color: var(--violet); }
.trap { border-left-color: var(--warn); background: var(--warn-soft); }
.trap .tag { color: var(--warn); }
.worked { border-left-color: var(--accent); background: var(--accent-soft); }
.worked .tag { color: var(--accent); }

.steps { counter-reset: s; list-style: none; padding: 0; margin: 18px 0; }
.steps li {
  counter-increment: s;
  position: relative;
  padding: 10px 0 10px 44px;
  border-bottom: 1px dashed var(--line);
}
.steps li:last-child { border-bottom: none; }
.steps li::before {
  content: counter(s);
  position: absolute;
  left: 0;
  top: 10px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--bg);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.diagram {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin: 18px 0;
  overflow-x: auto;
  text-align: center;
}
.diagram svg { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.diagram figcaption { margin-top: 10px; font-size: 13px; color: var(--faint); text-align: center; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.chip {
  font-family: var(--mono);
  font-size: 13px;
  padding: 5px 11px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--panel);
}
.chip.keep { background: var(--violet-soft); border-color: var(--violet); color: var(--violet); }
.chip.target { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 700; }
.chip.drop { opacity: 0.45; text-decoration: line-through; }

.quiz { margin-top: 56px; padding-top: 10px; border-top: 2px solid var(--line); }
.q {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 16px 0;
}
.q-text { font-weight: 650; margin-bottom: 12px; }
.opt {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.opt:hover { border-color: var(--brand); }
.opt.correct { background: var(--brand-soft); border-color: var(--brand); font-weight: 650; }
.opt.wrong { background: var(--warn-soft); border-color: var(--warn); }
.opt:disabled { cursor: default; }
.explain {
  display: none;
  margin: 10px 0 0;
  padding: 11px 14px;
  border-radius: 8px;
  background: var(--brand-soft);
  border-left: 3px solid var(--brand);
  font-size: 14.5px;
}
.q.answered .explain { display: block; }

.pager {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.pager a {
  flex: 1;
  text-decoration: none;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
}
.pager a:hover { border-color: var(--brand); }
.pager a span { display: block; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); margin-bottom: 3px; }
.pager a.next { text-align: right; }

.toc { display: grid; gap: 10px; margin: 20px 0 40px; }
.toc a {
  display: flex;
  align-items: baseline;
  gap: 12px;
  text-decoration: none;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 16px;
  transition: border-color 0.12s ease, transform 0.12s ease;
}
.toc a:hover { border-color: var(--brand); transform: translateX(2px); }
.toc .n { font-family: var(--mono); font-size: 12px; color: var(--brand); min-width: 28px; font-weight: 700; }
.toc .t { font-weight: 600; }
.toc .s { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--faint); white-space: nowrap; }
.toc .d { display: block; font-size: 13px; color: var(--muted); font-weight: 400; margin-top: 2px; }

.section-label {
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
  margin: 36px 0 2px;
}

.ar {
  font-family: var(--arabic);
  direction: rtl;
  text-align: right;
  unicode-bidi: isolate;
}
:is(p, div).ar {
  font-size: 15.5px;
  line-height: 1.95;
}
.ar bdi, .ar code, .ar strong, .ar em { font-style: normal; }
.ar bdi, .ar strong, .ar em { font-family: inherit; }
.ar strong { font-weight: 600; }
.ar code { font-size: 0.88em; }
li > .ar { margin: 2px 0 8px; }
.callout .ar { border-right-color: color-mix(in srgb, currentColor 22%, transparent); }
.lede + .ar { font-size: 16px; color: var(--muted); }

.ar-toggle {
  margin-left: auto;
  font-family: var(--arabic);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--brand);
  background: var(--brand-soft);
  border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.ar-toggle:hover { background: color-mix(in srgb, var(--brand) 18%, transparent); }
html:not([data-lang="ar"]) .ar-toggle { color: var(--faint); background: transparent; border-color: var(--line); }

@media print {
  .ar-toggle { display: none; }
}

.prio {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  border-radius: 4px;
  padding: 3px 6px;
  white-space: nowrap;
  flex-shrink: 0;
  align-self: baseline;
}
.prio.p1 { color: var(--warn); background: var(--warn-soft); }
.prio.p2 { color: var(--accent); background: var(--accent-soft); }
.prio.p3 { color: var(--faint); background: transparent; border: 1px solid var(--line); }

.page-head .prio { display: inline-block; margin-left: 8px; vertical-align: middle; font-size: 11px; padding: 4px 8px; }

.toc a.is-p1 { border-left: 3px solid var(--warn); }
.toc a.is-p2 { border-left: 3px solid var(--accent); }

.prio-key {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.prio-key span.item { display: inline-flex; align-items: center; gap: 7px; }

html:not([data-lang="ar"]) .ar { display: none !important; }
html[data-lang="ar"] .en { display: none !important; }
html[data-lang="ar"] :is(p, div).ar { font-size: 16.5px; margin: 0 0 14px; }
html[data-lang="ar"] :is(h1, h2, h3, h4).ar { font-family: var(--arabic); }
html[data-lang="ar"] .callout .ar,
html[data-lang="ar"] .q .ar,
html[data-lang="ar"] li > .ar { font-size: 15.5px; margin: 2px 0 8px; }
html[data-lang="ar"] .lede + .ar { font-size: 17.5px; }
html[data-lang="ar"] .ar-toggle { color: var(--brand); background: var(--brand-soft); }
