/* Qwizin architecture docs — bilingual (LTR/RTL), light/dark, offline-first.
   Brand palette sampled from logo.png:
     #4e0f94  purple  — the QWIZIN wordmark (43% of logo ink)
     #f64697  magenta — the fork (11%) */

:root {
  --brand: #4e0f94;
  --brand-deep: #3a0a6f;
  --brand-pink: #f64697;

  --bg: #ffffff;
  --bg-2: #f9f8fb;
  --bg-3: #f0ecf6;
  --fg: #1a1523;
  --fg-2: #4a4459;
  --fg-3: #7a7288;
  --line: #e7e2ee;
  --line-2: #d2c9de;
  --accent: #4e0f94;
  --accent-2: #3a0a6f;
  --accent-bg: #f4ecfd;
  --ok: #2d8659;
  --ok-bg: #e8f5e9;
  --warn: #b8791f;
  --warn-bg: #fff4e5;
  --bad: #c94a4a;
  --bad-bg: #fde8e8;
  --code-bg: #f4f5f7;
  --shadow: 0 1px 3px rgba(16,20,28,.08), 0 8px 24px rgba(16,20,28,.06);
  --sans: "Segoe UI", system-ui, -apple-system, "Noto Sans Arabic", "Dubai", "Tahoma", sans-serif;
  --mono: "Cascadia Mono", "Consolas", "SF Mono", ui-monospace, monospace;
  --side-w: 292px;
  --toc-w: 216px;
  --top-h: 56px;
}

:root[data-theme="dark"] {
  --brand: #b78ceb;
  --brand-deep: #d4b8f5;
  --brand-pink: #f969ae;

  --bg: #16131c;
  --bg-2: #1c1825;
  --bg-3: #251f30;
  --fg: #e9e6ef;
  --fg-2: #b8b2c6;
  --fg-3: #8b8399;
  --line: #2e2839;
  --line-2: #40384f;
  --accent: #b78ceb;
  --accent-2: #d4b8f5;
  --accent-bg: #271b3c;
  --ok: #5cc08d;
  --ok-bg: #14291f;
  --warn: #dfa245;
  --warn-bg: #2c2416;
  --bad: #e8756f;
  --bad-bg: #2e1a1a;
  --code-bg: #1c2128;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }

/* Hard guard against horizontal scroll. `clip` rather than `hidden` — `hidden`
   turns the root into a scroll container, which silently breaks the
   `position: sticky` the sidebar and TOC depend on. */
html, body { overflow-x: clip; max-width: 100%; }

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--top-h) + 16px); }

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

[dir="rtl"] body, body[data-lang="ar"] { line-height: 1.92; font-size: 16px; }

/* Standard visually-hidden. NOT `left: -9999px` — in an RTL document that
   offset lands outside the scroll origin and manufactures a ~10,000px
   horizontal scroll region across every Arabic page. */
.skip {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; white-space: nowrap;
  clip: rect(0 0 0 0); clip-path: inset(50%);
}
.skip:focus {
  position: fixed; top: 8px; inset-inline-start: 8px;
  width: auto; height: auto; margin: 0; padding: 8px 14px;
  clip: auto; clip-path: none; z-index: 999;
  background: var(--accent); color: #fff; border-radius: 6px; text-decoration: none;
}

/* ------------------------------------------------------------------ topbar */

.top {
  position: sticky; top: 0; z-index: 60;
  height: var(--top-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  max-width: 100%;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}
@media (max-width: 560px) { .top { gap: 8px; padding: 0 10px; } }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--fg); text-decoration: none; white-space: nowrap; }
/* No `display` here — it would outrank the .light-only/.dark-only swap below
   on specificity and render both variants at once. */
.brand .logo { height: 26px; width: auto; flex: none; }
.brand-sub {
  font-size: 14px; font-weight: 600; color: var(--fg-2);
  padding-inline-start: 10px; border-inline-start: 1px solid var(--line-2);
}
@media (max-width: 640px) { .brand-sub { display: none; } }

/* Theme-paired logo variants — the wordmark's purple is too dark for a dark page.
   Exactly one is displayed; nothing else may set `display` on these. */
.light-only { display: block; }
.dark-only  { display: none; }
:root[data-theme="dark"] .light-only { display: none; }
:root[data-theme="dark"] .dark-only  { display: block; }

/* The magenta fork is the logo's accent — echo it rather than leaving it unused. */
.ni.active { box-shadow: inset 3px 0 0 var(--brand-pink); }
[dir="rtl"] .ni.active { box-shadow: inset -3px 0 0 var(--brand-pink); }
.prose h1 { border-bottom: 3px solid var(--brand-pink); padding-bottom: .3em; }
.results mark { background: color-mix(in srgb, var(--brand-pink) 28%, transparent); }
.toc-l a.active { border-color: var(--brand-pink); }

.icon {
  height: 34px; min-width: 34px; padding: 0 10px;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg-2); color: var(--fg-2);
  font: inherit; font-size: 13.5px; cursor: pointer; text-decoration: none;
  transition: .15s;
}
.icon:hover { background: var(--bg-3); color: var(--fg); border-color: var(--line-2); }
.icon.lang { font-weight: 600; }
.burger { display: none; font-size: 17px; }
.floating { position: fixed; top: 16px; inset-inline-end: 16px; z-index: 70; }

/* ------------------------------------------------------------------ search */

.search { position: relative; flex: 1 1 140px; min-width: 0; max-width: 520px; margin-inline: auto; }
#q {
  width: 100%; height: 34px; padding: 0 13px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg-2); color: var(--fg);
  font: inherit; font-size: 14px;
}
#q:focus { outline: none; border-color: var(--accent); background: var(--bg); box-shadow: 0 0 0 3px var(--accent-bg); }
#q::placeholder { color: var(--fg-3); }

.results {
  position: absolute; top: 42px; inset-inline: 0;
  max-height: min(66vh, 560px); overflow-y: auto;
  background: var(--bg); border: 1px solid var(--line-2);
  border-radius: 10px; box-shadow: var(--shadow); padding: 6px;
}
.results .rcount { padding: 6px 10px; font-size: 12px; color: var(--fg-3); }
.results a { display: block; padding: 8px 10px; border-radius: 7px; text-decoration: none; color: var(--fg); }
.results a:hover, .results a.sel { background: var(--accent-bg); }
.results .rt { font-size: 12px; color: var(--accent); font-weight: 600; }
.results .rh { font-weight: 600; margin: 1px 0; font-size: 14px; }
.results .rx { font-size: 12.5px; color: var(--fg-2); line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.results mark { background: color-mix(in srgb, var(--warn) 34%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; }
.results .empty { padding: 18px; text-align: center; color: var(--fg-3); font-size: 14px; }

/* ------------------------------------------------------------------- shell */

/* Two columns by default. The third is added only when a TOC is actually
   rendered — otherwise the grid reserved 216px of dead space on every
   short page. */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0,1fr); align-items: start; }
.shell.has-toc { grid-template-columns: var(--side-w) minmax(0,1fr) var(--toc-w); }

@media (max-width: 1240px) {
  .shell.has-toc { grid-template-columns: var(--side-w) minmax(0,1fr); }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .shell, .shell.has-toc { grid-template-columns: minmax(0,1fr); }
}

/* ---------------------------------------------------------------- sidebar */

.side {
  position: sticky; top: var(--top-h);
  height: calc(100vh - var(--top-h));
  overflow-y: auto;
  padding: 20px 12px 48px;
  border-inline-end: 1px solid var(--line);
  background: var(--bg-2);
}
.ns { margin-bottom: 20px; }
.nh {
  font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--fg-3); padding: 0 10px; margin-bottom: 6px;
}
[dir="rtl"] .nh { letter-spacing: 0; text-transform: none; font-size: 12px; }
.ni {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; margin-bottom: 1px;
  border-radius: 7px; color: var(--fg-2); text-decoration: none;
  font-size: 14px; line-height: 1.4;
}
.ni:hover { background: var(--bg-3); color: var(--fg); }
.ni.active { background: var(--accent-bg); color: var(--accent-2); font-weight: 620; }
:root[data-theme="dark"] .ni.active { color: var(--accent-2); }
.ni .ic { font-size: 14px; flex: none; opacity: .9; }

@media (max-width: 900px) {
  .side {
    position: fixed; inset-block: var(--top-h) 0; inset-inline-start: 0;
    width: min(86vw, var(--side-w)); z-index: 55;
    box-shadow: var(--shadow);
    /* `visibility` matters: a purely transformed drawer stays in the layout,
       and in RTL it sits past the right edge — which is what was producing a
       dead scrollable strip on the Arabic pages. */
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform .24s ease, visibility .24s;
  }
  [dir="rtl"] .side { transform: translateX(100%); }
  .side.open { visibility: visible; transform: none; }

  /* Tap-anywhere-to-close backdrop. */
  body.nav-open::after {
    content: ''; position: fixed; inset: var(--top-h) 0 0;
    background: rgba(12, 8, 20, .44); z-index: 50;
  }

  .burger { display: inline-grid; }
  .search { max-width: none; }
}

/* -------------------------------------------------------------------- toc */

.toc { position: sticky; top: var(--top-h); max-height: calc(100vh - var(--top-h)); overflow-y: auto; padding: 24px 16px 48px; }
.toc-h { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--fg-3); margin-bottom: 8px; }
[dir="rtl"] .toc-h { letter-spacing: 0; text-transform: none; font-size: 12px; }
.toc-l a {
  display: block; padding: 3px 0 3px 10px;
  border-inline-start: 2px solid var(--line);
  color: var(--fg-3); text-decoration: none; font-size: 12.5px; line-height: 1.5;
}
[dir="rtl"] .toc-l a { padding: 3px 10px 3px 0; }
.toc-l a:hover { color: var(--fg); border-color: var(--line-2); }
.toc-l a.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.toc-l a.l3 { padding-inline-start: 22px; font-size: 12px; }
.toc-l a.l4 { padding-inline-start: 32px; font-size: 12px; opacity: .8; }

/* ------------------------------------------------------------------- prose */

.doc { min-width: 0; max-width: 100%; padding: 30px 40px 100px; }
@media (max-width: 1240px) { .doc { padding: 28px 32px 90px; } }
@media (max-width: 700px)  { .doc { padding: 22px 18px 72px; } }
/* Centred so a wide screen without a TOC doesn't leave the text stranded. */
.prose { max-width: 82ch; margin-inline: auto; min-width: 0; }
[dir="rtl"] .prose { max-width: 80ch; }
.credit { margin-inline: auto; }

.prose h1 { font-size: 1.85em; line-height: 1.3; margin: .2em 0 .6em; font-weight: 700; letter-spacing: -.01em; }
.prose h2 { font-size: 1.38em; margin: 2em 0 .6em; padding-bottom: .3em; border-bottom: 1px solid var(--line); font-weight: 670; }
.prose h3 { font-size: 1.14em; margin: 1.7em 0 .5em; font-weight: 660; }
.prose h4 { font-size: 1em; margin: 1.4em 0 .4em; font-weight: 660; color: var(--fg-2); }
[dir="rtl"] .prose h1, [dir="rtl"] .prose h2 { letter-spacing: 0; }

.anchor { opacity: 0; margin-inline-start: 8px; color: var(--fg-3); text-decoration: none; font-weight: 400; font-size: .8em; }
h2:hover .anchor, h3:hover .anchor, h4:hover .anchor { opacity: 1; }

.prose { overflow-wrap: break-word; }
.prose p { margin: .85em 0; }
.prose a { color: var(--accent); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 32%, transparent); }
.prose a:hover { border-bottom-color: var(--accent); }
.prose ul, .prose ol { margin: .8em 0; padding-inline-start: 1.5em; }
.prose li { margin: .3em 0; }
.prose li > ul, .prose li > ol { margin: .3em 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.4em 0; }
.prose img { max-width: 100%; height: auto; }

.prose code {
  font-family: var(--mono); font-size: .875em;
  background: var(--code-bg); padding: .14em .4em; border-radius: 4px;
  border: 1px solid var(--line);
  direction: ltr; unicode-bidi: embed; display: inline-block;
}
.prose pre {
  background: var(--code-bg); border: 1px solid var(--line);
  border-radius: 9px; padding: 14px 16px; overflow-x: auto;
  direction: ltr; text-align: left; font-size: 13px; line-height: 1.6;
}
.prose pre code { background: none; border: 0; padding: 0; font-size: inherit; display: inline; }

.prose blockquote {
  margin: 1.2em 0; padding: .8em 1.1em;
  border-inline-start: 3px solid var(--accent);
  background: var(--accent-bg); border-radius: 0 9px 9px 0;
  color: var(--fg);
}
[dir="rtl"] .prose blockquote { border-radius: 9px 0 0 9px; }
.prose blockquote > :first-child { margin-top: 0; }
.prose blockquote > :last-child { margin-bottom: 0; }

/* Warning/status blockquotes tinted by their leading emoji. */
.prose blockquote.w-bad  { border-color: var(--bad);  background: var(--bad-bg); }
.prose blockquote.w-warn { border-color: var(--warn); background: var(--warn-bg); }
.prose blockquote.w-ok   { border-color: var(--ok);   background: var(--ok-bg); }

/* ------------------------------------------------------------------ tables */

.tw { overflow-x: auto; margin: 1.3em 0; border: 1px solid var(--line); border-radius: 10px; }
.prose table { border-collapse: collapse; width: 100%; font-size: 14px; }
[dir="rtl"] .prose table { font-size: 14.5px; }
.prose th, .prose td { padding: 9px 13px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose thead th { background: var(--bg-2); font-weight: 660; white-space: nowrap; font-size: 13px; }
.prose tbody tr:last-child td { border-bottom: 0; }
.prose tbody tr:hover { background: var(--bg-2); }
.prose td code { white-space: nowrap; }

/* ---------------------------------------------------------------- diagrams */

/* Diagrams keep a light canvas in both themes — their source hardcodes light
   rect bands, so a dark canvas would only half-invert them. */
.diagram {
  margin: 1.6em 0; padding: 18px 14px;
  background: #fbfcfd; border: 1px solid var(--line); border-radius: 11px;
  overflow-x: auto; direction: ltr; text-align: center;
}
:root[data-theme="dark"] .diagram { border-color: var(--line-2); }
.diagram pre.mermaid { background: none; border: 0; padding: 0; margin: 0; text-align: center; }
.diagram svg { max-width: 100%; height: auto; }
.diagram .lbl { display: block; margin-top: 10px; font-size: 12px; color: var(--fg-3); }

/* ----------------------------------------------------------------- landing */

body.landing { background: linear-gradient(170deg, var(--bg-2), var(--bg) 55%); min-height: 100vh; }
.hero { max-width: 880px; margin: 0 auto; padding: 76px 24px 90px; text-align: center; }
.hero-logo { height: 92px; width: auto; margin: 0 auto 26px; }
@media (max-width: 720px) { .hero-logo { height: 68px; } }
.hero h1 { font-size: 2.15em; margin: 0 0 6px; font-weight: 700; letter-spacing: -.015em; }
.hero .sub { font-size: 1.5em; color: var(--fg-2); margin: 0 0 18px; font-weight: 600; }
.hero .note { color: var(--fg-3); font-size: 14px; line-height: 1.9; margin-bottom: 42px; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 52px; }
@media (max-width: 720px) { .cards { grid-template-columns: 1fr; } }
.card {
  display: block; padding: 26px 24px; text-align: start;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px;
  text-decoration: none; color: var(--fg); transition: .18s; box-shadow: var(--shadow);
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card .flag {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .08em;
  color: #fff; background: var(--brand-pink); padding: 3px 9px; border-radius: 5px; margin-bottom: 12px;
}
:root[data-theme="dark"] .card .flag { color: #2a1030; }
.card h2 { margin: 0 0 6px; font-size: 1.35em; }
.card p { margin: 0 0 16px; color: var(--fg-2); font-size: 14px; line-height: 1.6; }
.card .go { color: var(--accent); font-weight: 620; font-size: 14px; }

.blockers { text-align: start; background: var(--bad-bg); border: 1px solid color-mix(in srgb, var(--bad) 32%, transparent); border-radius: 14px; padding: 22px 24px; }
.blockers h3 { margin: 0 0 14px; font-size: 1.03em; color: var(--fg); }
.bl { display: grid; gap: 10px; }
.bl > div { display: grid; grid-template-columns: 190px 1fr 150px; gap: 12px; align-items: baseline; font-size: 13.5px; padding-bottom: 10px; border-bottom: 1px solid color-mix(in srgb, var(--bad) 18%, transparent); }
.bl > div:last-child { border-bottom: 0; padding-bottom: 0; }
@media (max-width: 720px) { .bl > div { grid-template-columns: 1fr; gap: 2px; } }
.bl b { color: var(--fg); }
.bl span { color: var(--fg-2); }
.bl em { color: var(--bad); font-style: normal; font-weight: 620; font-size: 12.5px; }
.blockers .foot { margin: 16px 0 0; font-size: 13px; color: var(--fg-2); line-height: 1.8; }

/* ------------------------------------------------------------------ credit */

.credit {
  max-width: 82ch; margin-top: 64px; padding-top: 20px;
  border-top: 1px solid var(--line);
}
.credit .cx { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.credit .cn { font-size: 13.5px; color: var(--fg-2); }
.credit .cn strong { color: var(--fg); font-weight: 650; }
.credit .cs { font-size: 12.5px; color: var(--fg-3); }

.landing-credit {
  max-width: none; margin-top: 48px; text-align: center;
  border-top-color: color-mix(in srgb, var(--line) 70%, transparent);
}
.landing-credit .cx { justify-content: center; gap: 10px 28px; }
.landing-credit .cs { color: var(--fg-2); font-size: 13.5px; }
.landing-credit .cs strong { color: var(--fg); font-weight: 650; }

/* ------------------------------------------------------------------- print */

@media print {
  .top, .side, .toc, .anchor, .skip { display: none !important; }
  .shell { display: block; }
  .doc { padding: 0; }
  .prose { max-width: none; }
  .diagram, .tw { break-inside: avoid; }
  .prose h2, .prose h3 { break-after: avoid; }
  body { font-size: 11pt; }
  a { color: inherit; border: 0; }
}
