@import url("../fonts/fonts.css");

/* =========================================================================
   CleverInit — Crowdfunding Handbook
   Layout & visual language after the Guidex documentation pattern:
   fixed 288px sidebar, 70px header, right-hand topic rail, card content.
   Bilingual (en / fa) with full RTL mirroring. Light + dark.
   ========================================================================= */

/* ---------- 1. Tokens ---------- */
:root {
  --brand:        #5f6af5;
  --brand-600:    #4a55e8;
  --brand-soft:   rgba(95, 106, 245, .10);
  --brand-line:   rgba(95, 106, 245, .28);

  --pink:  #ff4f7f;
  --green: #2bbb93;
  --amber: #ffa04f;
  --red:   #fb2f2f;
  --cyan:  #50d1f8;

  --bg:        #f6f8fb;
  --surface:   #ffffff;
  --surface-2: #fbfcfe;
  --sidebar:   #ffffff;
  --logobar:   #181e28;

  --ink:       #3f454e;
  --ink-head:  #2c313a;
  --ink-soft:  #6b7382;
  --ink-faint: #96a0b0;

  --line:      #e6eaf0;
  --line-soft: #eef1f6;

  --shadow-sm: 0 1px 2px rgba(24, 30, 40, .05);
  --shadow:    0 4px 18px rgba(24, 30, 40, .07);
  --shadow-lg: 0 18px 50px rgba(24, 30, 40, .16);

  --sb-w: 288px;
  --hd-h: 70px;
  --toc-w: 250px;
  --r: 10px;

  /* One neutral text face for body and headings. A reference document read for
     hours wants to disappear, not to have a voice of its own. */
  --f-body: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-head: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-mono: "SFMono-Regular", "Cascadia Mono", Consolas, monospace;

  color-scheme: light;
}

html[data-theme="dark"] {
  --bg:        #14181f;
  --surface:   #1b212b;
  --surface-2: #202836;
  --sidebar:   #1b212b;
  --logobar:   #12161d;

  --ink:       #aeb7c4;
  --ink-head:  #dbe1ea;
  --ink-soft:  #8b94a3;
  --ink-faint: #6c7585;

  --line:      #2b3341;
  --line-soft: #232b37;

  --brand-soft: rgba(95, 106, 245, .16);
  --brand-line: rgba(95, 106, 245, .40);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow:    0 4px 18px rgba(0, 0, 0, .38);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .55);

  color-scheme: dark;
}

/* Arabic and Persian swap the whole type stack. Vazirmatn covers both scripts. */
html[data-script="arabic"] {
  --f-body: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  --f-head: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 15px;
  line-height: 1.75;
  font-weight: 400;
  /* Inter is spaced for screens already; extra tracking only loosens it. */
  letter-spacing: normal;
  -webkit-font-smoothing: antialiased;
}
html[data-script="arabic"] body { line-height: 2.05; letter-spacing: 0; font-size: 15.5px; }

h1, h2, h3, h4, h5, h6 {
  font-family: var(--f-head);
  color: var(--ink-head);
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -.011em;
  margin: 0 0 .6em;
}
html[data-script="arabic"] :is(h1, h2, h3, h4, h5, h6) { font-weight: 700; letter-spacing: 0; }

/* Money columns line up only with tabular figures, and this document is mostly
   money columns. */
table { font-variant-numeric: tabular-nums; }
a { color: var(--brand); text-decoration: none; transition: color .18s ease; }
a:hover { color: var(--brand-600); }
img { max-width: 100%; height: auto; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2.2rem 0; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(120, 132, 150, .34); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: rgba(120, 132, 150, .55); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip {
  position: fixed; inset-inline-start: 12px; top: -60px; z-index: 200;
  background: var(--brand); color: #fff; padding: 10px 18px; border-radius: 8px;
  transition: top .2s ease;
}
.skip:focus { top: 12px; color: #fff; }

/* ---------- 3. Sidebar ---------- */
.sb {
  position: fixed; inset-block: 0; inset-inline-start: 0;
  width: var(--sb-w); z-index: 40;
  background: var(--sidebar);
  border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column;
  transition: transform .22s ease;
}
.sb-brand {
  height: var(--hd-h); flex: none;
  display: flex; align-items: center; gap: 12px;
  padding-inline: 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  border-inline-end: 1px solid var(--line);
  overflow: hidden;
}
html[data-theme="dark"] .sb-brand { background: var(--logobar); }
.sb-brand a { display: block; line-height: 0; }
.sb-brand img { height: 34px; width: auto; display: block; }
.sb-brand .logo-dark { display: none; }
html[data-theme="dark"] .sb-brand .logo-light { display: none; }
html[data-theme="dark"] .sb-brand .logo-dark  { display: block; }

.sb-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 18px 12px 40px; }

.sb-kicker {
  font-family: var(--f-head); font-size: 10.5px; font-weight: 800;
  letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint);
  padding: 18px 14px 8px; margin: 0;
}
html[data-script="arabic"] .sb-kicker { letter-spacing: 0; font-size: 11.5px; }
.sb-kicker:first-child { padding-top: 4px; }

.sb-grp { margin-bottom: 2px; }
.sb-grp > button {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: none; border: 0; cursor: pointer;
  font-family: var(--f-body); font-size: 13.5px; font-weight: 500;
  color: var(--ink); text-align: start;
  padding: 9px 12px; border-radius: 8px; line-height: 1.45;
  transition: background .16s ease, color .16s ease;
}
.sb-grp > button:hover { background: var(--line-soft); color: var(--ink-head); }
.sb-grp > button .num {
  flex: none; min-width: 20px; height: 20px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; font-family: var(--f-head);
  background: var(--line-soft); color: var(--ink-faint);
}
.sb-grp > button .lbl { flex: 1; }
.sb-grp > button .chev {
  flex: none; width: 14px; height: 14px; color: var(--ink-faint);
  transition: transform .2s ease;
}
.sb-grp.open > button { color: var(--brand); font-weight: 600; }
.sb-grp.open > button .chev { transform: rotate(90deg); }
html[dir="rtl"] .sb-grp > button .chev { transform: scaleX(-1); }
html[dir="rtl"] .sb-grp.open > button .chev { transform: scaleX(-1) rotate(-90deg); }
.sb-grp.open > button .num { background: var(--brand-soft); color: var(--brand); }

.sb-links { display: none; padding: 2px 0 8px; }
.sb-grp.open .sb-links { display: block; }
.sb-links a {
  display: block; position: relative;
  padding: 6.5px 12px 6.5px 34px;
  font-size: 13px; font-weight: 400; line-height: 1.5;
  color: var(--ink-soft); border-radius: 7px;
  transition: background .16s ease, color .16s ease;
}
html[dir="rtl"] .sb-links a { padding: 6.5px 34px 6.5px 12px; }
.sb-links a::before {
  content: ""; position: absolute; inset-inline-start: 19px; top: 50%;
  width: 4px; height: 4px; margin-top: -2px; border-radius: 50%;
  background: var(--ink-faint); opacity: .55; transition: all .16s ease;
}
.sb-links a:hover { background: var(--line-soft); color: var(--ink-head); }
.sb-links a.on {
  background: var(--brand-soft); color: var(--brand); font-weight: 600;
}
.sb-links a.on::before { background: var(--brand); opacity: 1; transform: scale(1.6); }

.sb-foot {
  flex: none; border-top: 1px solid var(--line);
  padding: 12px 18px; font-size: 11.5px; color: var(--ink-faint);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.sb-foot .ver {
  font-family: var(--f-mono); font-size: 10.5px;
  background: var(--line-soft); padding: 2px 7px; border-radius: 5px;
}

.sb-backdrop {
  position: fixed; inset: 0; z-index: 39; background: rgba(15, 20, 28, .5);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}

/* ---------- 4. Header ---------- */
.hd {
  position: fixed; top: 0; inset-inline-end: 0; z-index: 30;
  inset-inline-start: var(--sb-w); height: var(--hd-h);
  display: flex; align-items: center; gap: 14px;
  padding-inline: 22px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.hd-burger {
  display: none; flex: none; width: 38px; height: 38px;
  align-items: center; justify-content: center;
  background: none; border: 1px solid var(--line); border-radius: 9px;
  color: var(--ink-soft); cursor: pointer;
}

.hd-search {
  flex: 1; max-width: 460px; display: flex; align-items: center; gap: 9px;
  height: 40px; padding-inline: 13px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 9px; cursor: text; color: var(--ink-faint);
  transition: border-color .18s ease, background .18s ease;
}
.hd-search:hover { border-color: var(--brand-line); }
.hd-search svg { flex: none; width: 15px; height: 15px; }
.hd-search span { flex: 1; font-size: 13.5px; }
.hd-search kbd {
  font-family: var(--f-mono); font-size: 10.5px; line-height: 1;
  padding: 4px 6px; border-radius: 5px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-faint);
}
html[data-script="arabic"] .hd-search kbd { display: none; }

.hd-sp { flex: 1; }
.hd-tools { flex: none; display: flex; align-items: center; gap: 8px; }

.tbtn {
  height: 38px; min-width: 38px; padding-inline: 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
  color: var(--ink-soft); cursor: pointer;
  font-family: var(--f-body); font-size: 12.5px; font-weight: 500;
  transition: all .18s ease;
}
.tbtn:hover { border-color: var(--brand-line); color: var(--brand); background: var(--brand-soft); }
.tbtn svg { width: 16px; height: 16px; }
.tbtn .i-sun  { display: none; }
html[data-theme="dark"] .tbtn .i-sun  { display: block; }
html[data-theme="dark"] .tbtn .i-moon { display: none; }

/* ---------- 4b. Language switcher ----------
   Seven languages is past the point where a row of pills fits, so the header
   carries the current language and opens a list. Every option is labelled in
   its own language, so the reader never has to recognise their own language
   through the current one. */
.langsw { position: relative; }
.langsw-btn {
  height: 38px; padding-inline: 11px 9px;
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
  color: var(--ink-soft); cursor: pointer;
  font-family: var(--f-body); font-size: 12.5px; font-weight: 600;
  transition: all .18s ease;
}
.langsw-btn:hover { border-color: var(--brand-line); color: var(--brand); background: var(--brand-soft); }
.langsw-btn .globe { flex: none; width: 15px; height: 15px; }
.langsw-btn .caret { flex: none; width: 13px; height: 13px; transition: transform .18s ease; }
.langsw.open .langsw-btn { border-color: var(--brand-line); color: var(--brand); background: var(--brand-soft); }
.langsw.open .langsw-btn .caret { transform: rotate(180deg); }

/* Both scripts must render whatever language the page is in. */
.lang-cur, .lang-opt { font-family: "Inter", "Vazirmatn", "Segoe UI", Tahoma, sans-serif; }
.lang-cur.s-arabic, .lang-opt.s-arabic .lo-name { font-family: "Vazirmatn", Tahoma, "Segoe UI", sans-serif; }
.lang-cur { max-width: 8.5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.langsw-menu {
  position: absolute; inset-inline-end: 0; top: calc(100% + 7px); z-index: 60;
  min-width: 186px; padding: 5px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px;
  box-shadow: var(--shadow-lg);
  display: none; flex-direction: column; gap: 1px;
}
.langsw.open .langsw-menu { display: flex; }
.lang-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 0; background: none; cursor: pointer; border-radius: 7px;
  padding: 7px 10px; font-size: 13px; font-weight: 600; text-align: start;
  color: var(--ink-soft); transition: background .14s ease, color .14s ease;
}
.lang-opt .lo-code { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; color: var(--ink-faint); }
.lang-opt:hover { background: var(--bg); color: var(--ink-head); }
.lang-opt.on { background: var(--brand); color: #fff; }
.lang-opt.on .lo-code { color: rgba(255, 255, 255, .78); }

/* ---------- 5. Shell ---------- */
.main {
  margin-inline-start: var(--sb-w);
  padding-top: var(--hd-h);
  min-height: 100vh;
  display: flex; flex-direction: column;
}
.wrap {
  flex: 1; width: 100%; max-width: 1500px; margin-inline: auto;
  padding: 30px 30px 70px;
  display: grid; grid-template-columns: minmax(0, 1fr) var(--toc-w); gap: 34px;
  align-items: start;
}
/* Nothing in the content column may widen the page; wide things scroll
   inside their own box instead. */
.col-main, .card, .doc, .doc-in { min-width: 0; max-width: 100%; }
.main { overflow-x: clip; }

/* ---------- 6. Page head ---------- */
.crumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--ink-faint); margin-bottom: 14px;
}
.crumbs a { color: var(--ink-soft); }
.crumbs a:hover { color: var(--brand); }
.crumbs .sep { opacity: .5; }
html[dir="rtl"] .crumbs .sep { transform: scaleX(-1); display: inline-block; }

.phead { margin-bottom: 26px; }
.phead .eyebrow {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--f-head); font-size: 10.5px; font-weight: 800;
  letter-spacing: .13em; text-transform: uppercase; color: var(--brand);
  background: var(--brand-soft); border: 1px solid var(--brand-line);
  padding: 4px 11px; border-radius: 20px; margin-bottom: 13px;
}
html[data-script="arabic"] .phead .eyebrow { letter-spacing: 0; font-size: 11.5px; }
.phead h1 { font-size: clamp(26px, 3.4vw, 37px); letter-spacing: -.015em; margin-bottom: .35em; }
html[data-script="arabic"] .phead h1 { letter-spacing: 0; }
.phead .lede {
  font-size: 16.5px; line-height: 1.75; color: var(--ink-soft); max-width: 74ch; margin: 0;
}

/* ---------- 7. Content card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow-sm);
  padding: 34px 38px;
}
.doc { max-width: 82ch; }
.doc > *:first-child { margin-top: 0; }
.doc > *:last-child  { margin-bottom: 0; }

.doc p { margin: 0 0 1.15em; }
.doc h2 {
  font-size: 25px; margin: 2.3em 0 .8em; padding-bottom: .4em;
  border-bottom: 1px solid var(--line-soft); scroll-margin-top: calc(var(--hd-h) + 20px);
}
.doc h3 {
  font-size: 20px; margin: 2.1em 0 .7em; scroll-margin-top: calc(var(--hd-h) + 20px);
}
.doc h4 {
  font-size: 16px; margin: 1.8em 0 .6em; color: var(--ink-head);
  scroll-margin-top: calc(var(--hd-h) + 20px);
}
.doc h2:first-child, .doc h3:first-child { margin-top: 0; }

.doc ul, .doc ol { margin: 0 0 1.2em; padding-inline-start: 1.35em; }
.doc li { margin-bottom: .5em; }
.doc li::marker { color: var(--brand); }
.doc ul ul, .doc ol ol, .doc ul ol, .doc ol ul { margin: .5em 0 .3em; }

.doc strong { color: var(--ink-head); font-weight: 600; }
/* A cross-reference to a chapter that is not in this build. */
.doc .unlinked {
  color: var(--ink-soft); border-bottom: 1px dotted var(--ink-faint);
  cursor: help;
}
.doc em { color: var(--ink-head); }

.doc blockquote {
  margin: 1.5em 0; padding: 4px 20px;
  border-inline-start: 3px solid var(--brand-line);
  color: var(--ink-soft); font-style: italic;
}

.doc code {
  font-family: var(--f-mono); font-size: .875em;
  background: var(--brand-soft); color: var(--brand-600);
  padding: 2px 6px; border-radius: 5px;
  word-break: break-word;
}
html[data-theme="dark"] .doc code { color: #a9b1ff; }
html[data-script="arabic"] .doc code { direction: ltr; display: inline-block; }

/* Tables scroll inside their own box; the page never scrolls sideways. */
.tw { overflow-x: auto; margin: 1.6em 0; border: 1px solid var(--line); border-radius: 10px; }
.doc table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 480px; }
.doc thead th {
  background: var(--surface-2); color: var(--ink-head);
  font-family: var(--f-head); font-weight: 700; font-size: 12px;
  letter-spacing: .05em; text-transform: uppercase;
  text-align: start; padding: 12px 15px; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
html[data-script="arabic"] .doc thead th { letter-spacing: 0; text-transform: none; font-size: 13px; }
.doc tbody td { padding: 11px 15px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.doc tbody tr:last-child td { border-bottom: 0; }
.doc tbody tr:hover td { background: var(--surface-2); }
.doc th:first-child, .doc td:first-child { padding-inline-start: 18px; }

/* ---------- 8. Callouts ---------- */
.cal {
  margin: 1.6em 0; padding: 16px 18px 16px 48px;
  border-radius: 11px; border: 1px solid; position: relative;
  font-size: 14.2px;
}
html[dir="rtl"] .cal { padding: 16px 48px 16px 18px; }
.cal > *:first-child { margin-top: 0; }
.cal > *:last-child { margin-bottom: 0; }
.cal p { margin-bottom: .7em; }
.cal ul, .cal ol { margin-bottom: .7em; }
.cal .cal-t {
  font-family: var(--f-head); font-weight: 800; font-size: 12.5px;
  letter-spacing: .06em; text-transform: uppercase; margin-bottom: .5em;
}
html[data-script="arabic"] .cal .cal-t { letter-spacing: 0; text-transform: none; font-size: 14px; }
.cal::before {
  content: ""; position: absolute; inset-inline-start: 17px; top: 18px;
  width: 18px; height: 18px; background-size: contain; background-repeat: no-repeat;
}

.cal.note { background: rgba(95,106,245,.07);  border-color: rgba(95,106,245,.26); }
.cal.note .cal-t { color: var(--brand); }
.cal.tip  { background: rgba(43,187,147,.08);  border-color: rgba(43,187,147,.28); }
.cal.tip  .cal-t { color: #1f9c79; }
.cal.warn { background: rgba(255,160,79,.10);  border-color: rgba(255,160,79,.34); }
.cal.warn .cal-t { color: #c9741f; }
.cal.law  { background: rgba(80,209,248,.08);  border-color: rgba(80,209,248,.30); }
.cal.law  .cal-t { color: #1b93bb; }
.cal.eg   { background: rgba(255,79,127,.07);  border-color: rgba(255,79,127,.26); }
.cal.eg   .cal-t { color: #d63963; }

html[data-theme="dark"] .cal.tip  .cal-t { color: #4fd6ae; }
html[data-theme="dark"] .cal.warn .cal-t { color: #ffb877; }
html[data-theme="dark"] .cal.law  .cal-t { color: #7fdcff; }
html[data-theme="dark"] .cal.eg   .cal-t { color: #ff86a7; }

.cal.note::before { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f6af5' stroke-width='2.1' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9.5'/%3E%3Cpath d='M12 11v5M12 7.6v.1'/%3E%3C/svg%3E"); }
.cal.tip::before  { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232bbb93' stroke-width='2.1' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 18h6M10 21.5h4'/%3E%3Cpath d='M12 2.5a6.5 6.5 0 0 0-3.7 11.8c.5.4.7.9.7 1.5v.2h6v-.2c0-.6.2-1.1.7-1.5A6.5 6.5 0 0 0 12 2.5z'/%3E%3C/svg%3E"); }
.cal.warn::before { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e08a2e' stroke-width='2.1' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.3 3.4 1.9 18a2 2 0 0 0 1.7 3h16.8a2 2 0 0 0 1.7-3L13.7 3.4a2 2 0 0 0-3.4 0z'/%3E%3Cpath d='M12 9v4M12 17v.1'/%3E%3C/svg%3E"); }
.cal.law::before  { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231b93bb' stroke-width='2.1' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3v18M4 7h16M6.5 21h11'/%3E%3Cpath d='M4 7 1.5 14h5L4 7zM20 7l-2.5 7h5L20 7z'/%3E%3C/svg%3E"); }
.cal.eg::before   { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23d63963' stroke-width='2.1' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='2.5' width='16' height='19' rx='2.5'/%3E%3Cpath d='M8 7h8M8 11.5h3M8 16h6'/%3E%3C/svg%3E"); }

/* Verbatim regulation quote inside a law callout */
.cal.law blockquote {
  border-inline-start-color: rgba(80,209,248,.5);
  font-style: normal; font-size: 13.6px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  border-radius: 0 8px 8px 0; padding: 12px 16px; margin: .9em 0;
}
html[dir="rtl"] .cal.law blockquote { border-radius: 8px 0 0 8px; }

/* ---------- 9. Phase entry blocks ---------- */
.ph-meta {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; font-family: var(--f-head);
  padding: 4px 11px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-soft);
}
.chip.done  { border-color: rgba(43,187,147,.4);  background: rgba(43,187,147,.10);  color: #1f9c79; }
.chip.part  { border-color: rgba(255,160,79,.45); background: rgba(255,160,79,.12);  color: #c9741f; }
.chip.todo  { border-color: var(--line);          background: var(--surface-2);      color: var(--ink-faint); }
.chip.band  { border-color: var(--brand-line);    background: var(--brand-soft);     color: var(--brand); }
html[data-theme="dark"] .chip.done { color: #4fd6ae; }
html[data-theme="dark"] .chip.part { color: #ffb877; }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.doc h2.sect-h {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--f-head); font-size: 12px; font-weight: 800;
  letter-spacing: .11em; text-transform: uppercase; color: var(--ink-faint);
  margin: 2.4em 0 1em; padding-bottom: 0; border-bottom: 0;
  scroll-margin-top: calc(var(--hd-h) + 20px);
}
html[data-script="arabic"] .doc h2.sect-h { letter-spacing: 0; text-transform: none; font-size: 14px; }
.doc h2.sect-h::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.doc h2.sect-h .ic { width: 16px; height: 16px; color: var(--brand); flex: none; }
.doc h2.sect-h:first-child { margin-top: 0; }

.analogy {
  margin: 1.5em 0; padding: 18px 22px;
  background: linear-gradient(135deg, var(--brand-soft), rgba(255,79,127,.06));
  border: 1px solid var(--brand-line); border-radius: 12px;
  font-size: 15px; color: var(--ink-head);
}
.analogy .cal-t {
  font-family: var(--f-head); font-weight: 800; font-size: 11.5px;
  letter-spacing: .11em; text-transform: uppercase; color: var(--brand);
  margin-bottom: .45em;
}
html[data-script="arabic"] .analogy .cal-t { letter-spacing: 0; text-transform: none; font-size: 13.5px; }

.termlist { display: grid; gap: 10px; margin: 1.2em 0; }
.term {
  padding: 13px 16px; border: 1px solid var(--line);
  border-inline-start: 3px solid var(--brand); border-radius: 9px;
  background: var(--surface-2); font-size: 14px;
}
.term b { font-family: var(--f-head); color: var(--ink-head); display: block; margin-bottom: 2px; font-size: 14.5px; }

.reglist { display: grid; gap: 9px; margin: 1.2em 0; }
.reg {
  display: grid; grid-template-columns: minmax(150px, auto) 1fr; gap: 4px 18px;
  padding: 12px 16px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface-2); font-size: 13.8px;
}
.reg .r {
  font-family: var(--f-mono); font-size: 12.2px; color: var(--brand);
  font-weight: 600; direction: ltr; text-align: start;
}
@media (max-width: 640px) { .reg { grid-template-columns: 1fr; } }

/* ---------- 10. Index / grid pages ---------- */
.grid { display: grid; gap: 16px; margin: 1.6em 0; }
.grid.g2 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid.g3 { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }

.tile {
  display: block; padding: 20px 22px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--surface);
  transition: all .2s ease; position: relative; overflow: hidden;
}
.tile::after {
  content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 3px;
  background: var(--brand); transform: scaleY(0); transform-origin: top; transition: transform .22s ease;
}
.tile:hover { border-color: var(--brand-line); box-shadow: var(--shadow); transform: translateY(-2px); }
.tile:hover::after { transform: scaleY(1); }
.tile .n {
  font-family: var(--f-mono); font-size: 11px; font-weight: 700;
  color: var(--brand); background: var(--brand-soft);
  padding: 2px 8px; border-radius: 5px; display: inline-block; margin-bottom: 9px;
}
.tile h4 { font-size: 15px; margin: 0 0 6px; line-height: 1.4; }
.tile p { font-size: 13px; color: var(--ink-soft); margin: 0; line-height: 1.6; }

.stat {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px; margin: 1.8em 0;
}
.stat > div {
  padding: 18px 20px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2); text-align: center;
}
.stat .v {
  font-family: var(--f-head); font-size: 28px; font-weight: 800;
  color: var(--brand); line-height: 1.1; display: block;
}
.stat .k { font-size: 12px; color: var(--ink-soft); margin-top: 5px; display: block; }

/* ---------- 10b. Hero (home page) ---------- */
.hero {
  margin: -6px 0 30px;
  padding: 40px 42px 42px;
  border-radius: 16px;
  border: 1px solid var(--brand-line);
  background:
    radial-gradient(1100px 340px at 12% -30%, rgba(95,106,245,.16), transparent 70%),
    radial-gradient(760px 300px at 96% 0%, rgba(255,79,127,.12), transparent 68%),
    var(--surface);
  position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 34px 34px; opacity: .5;
  -webkit-mask-image: radial-gradient(560px 260px at 84% 118%, #000, transparent 72%);
          mask-image: radial-gradient(560px 260px at 84% 118%, #000, transparent 72%);
}
.hero > * { position: relative; z-index: 1; }
.hero-tag {
  display: inline-block; font-family: var(--f-head);
  font-size: 10.5px; font-weight: 800; letter-spacing: .15em; text-transform: uppercase;
  color: var(--brand); background: var(--brand-soft);
  border: 1px solid var(--brand-line); padding: 5px 13px; border-radius: 20px; margin-bottom: 18px;
}
html[data-script="arabic"] .hero-tag { letter-spacing: 0; text-transform: none; font-size: 12px; }
.hero h1 {
  font-size: clamp(30px, 4.6vw, 50px); line-height: 1.12;
  letter-spacing: -.028em; margin: 0 0 .4em; max-width: 18ch;
}
html[data-script="arabic"] .hero h1 { letter-spacing: 0; line-height: 1.3; max-width: 22ch; }
.hero-lede {
  font-size: 16.5px; line-height: 1.8; color: var(--ink-soft); max-width: 68ch; margin: 0 0 26px;
}
.hero-cta { display: flex; flex-wrap: wrap; gap: 11px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 22px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface);
  font-family: var(--f-head); font-size: 14px; font-weight: 700; color: var(--ink-head);
  transition: all .2s ease;
}
.btn:hover { border-color: var(--brand-line); color: var(--brand); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
@media (max-width: 720px) { .hero { padding: 28px 20px 30px; } }

/* ---------- 11. Figures / diagrams ---------- */
figure.fig { margin: 2em 0; max-width: 100%; }
figure.fig .fig-box {
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2);
  padding: 22px; overflow-x: auto; max-width: 100%;
}
/* The drawing keeps a legible minimum size and scrolls inside its own box —
   it must never widen the page. */
figure.fig svg { display: block; margin-inline: auto; width: 100%; min-width: 640px; height: auto; }
@media (max-width: 720px) { figure.fig .fig-box { padding: 14px; } }
figure.fig figcaption {
  margin-top: 11px; font-size: 12.8px; color: var(--ink-soft); text-align: center;
}
figure.fig figcaption b { color: var(--ink-head); font-family: var(--f-head); }

/* Diagram palette — driven by CSS vars so both themes work from one SVG. */
.fig-box { --d-line: var(--line); --d-ink: var(--ink-head); --d-soft: var(--ink-soft); }
svg .d-fill    { fill: var(--surface); }
svg .d-fill-2  { fill: var(--bg); }
svg .d-stroke  { stroke: var(--line); }
svg .d-brand   { fill: var(--brand); }
svg .d-brand-s { stroke: var(--brand); }
svg .d-soft    { fill: var(--brand-soft); }
svg .d-t       { fill: var(--ink-head); font-family: var(--f-head); font-weight: 700; }
svg .d-l       { fill: var(--ink-soft); font-family: var(--f-body); font-weight: 400; }
svg .d-w       { fill: #fff; font-family: var(--f-head); font-weight: 700; }
svg .d-ok      { fill: var(--green); }
svg .d-warn    { fill: var(--amber); }
svg .d-bad     { fill: var(--red); }
svg .d-ok-s    { stroke: var(--green); }
svg .d-bad-s   { stroke: var(--red); }
svg .d-arrow   { stroke: var(--ink-faint); fill: none; }
/* Figures keep LTR reading order even on Persian pages. */
html[dir="rtl"] figure.fig .fig-box { direction: ltr; }

/* Phase-page body wrappers inherit the document typography. */
.doc-in > *:first-child { margin-top: 0; }
.doc-in > *:last-child  { margin-bottom: 0; }

/* Long, dense reference pages (glossary, trap list) breathe a little more. */
.doc h3 + .tw, .doc h4 + .tw { margin-top: .9em; }
.doc h3 + p, .doc h4 + p { margin-top: 0; }

/* ---------- 12. Right-hand topic rail ---------- */
.toc { position: sticky; top: calc(var(--hd-h) + 30px); align-self: start; }
.toc-in { max-height: calc(100vh - var(--hd-h) - 70px); overflow-y: auto; padding-inline-end: 4px; }
.toc h5 {
  font-family: var(--f-head); font-size: 10.5px; font-weight: 800;
  letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint);
  margin: 0 0 12px; padding-inline-start: 13px;
}
html[data-script="arabic"] .toc h5 { letter-spacing: 0; text-transform: none; font-size: 12.5px; }
.toc a {
  display: block; padding: 5.5px 13px; font-size: 12.7px; line-height: 1.55;
  color: var(--ink-soft); border-inline-start: 2px solid var(--line);
  transition: all .16s ease;
}
.toc a:hover { color: var(--ink-head); border-inline-start-color: var(--ink-faint); }
.toc a.on { color: var(--brand); border-inline-start-color: var(--brand); font-weight: 600; }
.toc a.lv4 { padding-inline-start: 26px; font-size: 12.2px; }
.toc-empty { font-size: 12.5px; color: var(--ink-faint); padding-inline-start: 13px; }

/* ---------- 13. Prev / next ---------- */
.pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 34px;
}
.pager a {
  display: flex; align-items: center; gap: 13px;
  padding: 16px 20px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); transition: all .2s ease;
}
.pager a:hover { border-color: var(--brand-line); box-shadow: var(--shadow); }
.pager a.nx { grid-column: 2; flex-direction: row-reverse; text-align: end; }
.pager a.pv:only-child { grid-column: 1; }
.pager .ar {
  flex: none; width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
}
.pager .ar svg { width: 15px; height: 15px; }
html[dir="rtl"] .pager .ar svg { transform: scaleX(-1); }
.pager .tx { min-width: 0; }
.pager .k { display: block; font-size: 11px; color: var(--ink-faint); font-family: var(--f-head); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
html[data-script="arabic"] .pager .k { letter-spacing: 0; text-transform: none; font-size: 12px; }
.pager .t { display: block; font-size: 14px; font-weight: 600; color: var(--ink-head); font-family: var(--f-head); margin-top: 2px; }
@media (max-width: 620px) { .pager { grid-template-columns: 1fr; } .pager a.nx { grid-column: 1; } }

/* ---------- 14. Search overlay ---------- */
.srch {
  position: fixed; inset: 0; z-index: 90; display: none;
  background: rgba(16, 21, 30, .55); backdrop-filter: blur(3px);
  padding: 9vh 20px 20px;
}
.srch.open { display: block; }
.srch-box {
  max-width: 680px; margin-inline: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 15px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.srch-in { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.srch-in svg { flex: none; width: 18px; height: 18px; color: var(--ink-faint); }
.srch-in input {
  flex: 1; border: 0; background: none; outline: none;
  font-family: var(--f-body); font-size: 16px; color: var(--ink-head);
}
.srch-in input::placeholder { color: var(--ink-faint); }
.srch-in .esc {
  font-family: var(--f-mono); font-size: 10.5px; padding: 4px 8px; border-radius: 5px;
  background: var(--bg); border: 1px solid var(--line); color: var(--ink-faint);
}
.srch-res { max-height: 58vh; overflow-y: auto; padding: 8px; }
.srch-res a {
  display: block; padding: 11px 14px; border-radius: 9px; transition: background .14s ease;
}
.srch-res a:hover, .srch-res a.sel { background: var(--brand-soft); }
.srch-res .bc { font-size: 11px; color: var(--ink-faint); margin-bottom: 2px; }
.srch-res .ti { font-size: 14.5px; font-weight: 600; font-family: var(--f-head); color: var(--ink-head); }
.srch-res .sn { font-size: 12.7px; color: var(--ink-soft); margin-top: 3px; line-height: 1.55; }
.srch-res mark { background: rgba(255,160,79,.32); color: inherit; border-radius: 3px; padding: 0 2px; }
.srch-none { padding: 34px 20px; text-align: center; color: var(--ink-faint); font-size: 14px; }
.srch-foot {
  padding: 10px 20px; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--ink-faint);
  display: flex; gap: 16px; flex-wrap: wrap;
}
html[data-script="arabic"] .srch-foot { display: none; }

/* ---------- 15. Footer ---------- */
.ft {
  border-top: 1px solid var(--line); background: var(--surface);
  padding: 26px 34px; font-size: 12.7px; color: var(--ink-faint);
  display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center;
}
.ft a { color: var(--ink-soft); }
.ft a:hover { color: var(--brand); }

/* ---------- 16. Progress bar ---------- */
.prog {
  position: fixed; top: 0; inset-inline-start: 0; height: 2px; width: 0;
  background: linear-gradient(90deg, var(--brand), var(--pink));
  z-index: 100; transition: width .12s linear;
}

/* ---------- 16b. Language loading ----------
   Only English and Persian ship inside the first load. The other five arrive
   as one file each, so there is a short moment with nothing to show. */
.loadmsg {
  display: flex; align-items: center; gap: 11px;
  color: var(--ink-faint); font-size: 14.5px; margin: 8px 0;
}
.spin {
  flex: none; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--brand);
  animation: hb-spin .7s linear infinite;
}
@keyframes hb-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; border-top-color: var(--brand); } }

.packfail {
  margin-bottom: 16px; padding: 11px 15px; border-radius: 10px;
  background: var(--warn-soft, var(--brand-soft)); border: 1px solid var(--line);
  color: var(--ink-soft); font-size: 13.5px;
}

/* German compounds and long Dutch words must wrap rather than widen a column. */
.sb-links a, .toc a, .pager .t, .tile h4, .srch-res .ti { overflow-wrap: anywhere; }

/* ---------- 17. Responsive ---------- */
@media (max-width: 1240px) {
  .wrap { grid-template-columns: minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 1024px) {
  .sb { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  html[dir="rtl"] .sb { transform: translateX(100%); }
  body.nav-open .sb { transform: translateX(0); }
  body.nav-open .sb-backdrop { opacity: 1; pointer-events: auto; }
  .hd { inset-inline-start: 0; }
  .main { margin-inline-start: 0; }
  .hd-burger { display: flex; }
  .hd-search kbd { display: none; }
}
@media (max-width: 720px) {
  .wrap { padding: 20px 15px 50px; }
  .card { padding: 22px 18px; border-radius: 12px; }
  .hd { padding-inline: 14px; gap: 9px; }
  .hd-search span { display: none; }
  .hd-search { max-width: 44px; flex: none; justify-content: center; padding-inline: 0; }
  .tbtn.lbl-btn span { display: none; }
  .phead h1 { font-size: 25px; }
  .phead .lede { font-size: 15px; }
  .doc h2 { font-size: 21px; } .doc h3 { font-size: 17.5px; }
  .cal { padding: 14px 15px 14px 44px; }
  html[dir="rtl"] .cal { padding: 14px 44px 14px 15px; }
}

/* ---------- 18. Print ---------- */
@media print {
  .sb, .hd, .toc, .pager, .srch, .sb-backdrop, .prog, .ft, .skip { display: none !important; }
  .main { margin: 0; padding: 0; }
  .wrap { display: block; max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .doc h2, .doc h3 { break-after: avoid; }
  .cal, .tw, figure.fig { break-inside: avoid; }
  a { color: #000; }
}
