/* LymphocyteCount.org — Arabic RTL layer
   Loaded alongside style.css when <html dir="rtl">.
   Only overrides direction-sensitive properties.
*/

/* --- Typography for Arabic --- */
:root[dir="rtl"] {
  --font-body: 'IBM Plex Sans Arabic', 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
  --font-display: 'IBM Plex Sans Arabic', 'Noto Serif Arabic', 'Segoe UI', Tahoma, serif;
  /* Wider measure — Arabic prose runs a bit longer per idea */
  --measure: 68ch;
}

/* Preload the fonts (link tag in <head> — this rule only helps when the fonts are also linked) */
[dir="rtl"] body {
  font-family: var(--font-body);
  /* Slightly larger to compensate for average glyph density */
  font-size: calc(var(--text-base) * 1.02);
  /* Arabic reads more comfortably with a bit more line height */
  line-height: 1.75;
}

[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3, [dir="rtl"] h4 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0; /* Arabic never uses negative letter-spacing */
}

/* Keep the brand wordmark and other Latin-in-Arabic bits in LTR */
[dir="rtl"] .brand span,
[dir="rtl"] .brand .org,
[dir="rtl"] [lang="en"],
[dir="rtl"] .ltr,
[dir="rtl"] code,
[dir="rtl"] .num b,
[dir="rtl"] time,
[dir="rtl"] .val,
[dir="rtl"] .ax {
  direction: ltr;
  unicode-bidi: embed;
}

/* --- Structural mirroring --- */
[dir="rtl"] body { direction: rtl; text-align: right; }

[dir="rtl"] ul, [dir="rtl"] ol { padding-left: 0; padding-right: 1.25em; }
[dir="rtl"] p, [dir="rtl"] ul, [dir="rtl"] ol { max-width: var(--measure); }

[dir="rtl"] .skip { left: auto; right: -999px; }
[dir="rtl"] .skip:focus { left: auto; right: 8px; }

/* Header nav */
[dir="rtl"] .nav { direction: rtl; }
[dir="rtl"] .nav-links { direction: rtl; }
[dir="rtl"] .nav-toggle svg { transform: none; }

/* Hero */
[dir="rtl"] .hero .wrap::before {
  left: auto; right: -12%;
}

/* Callouts — flip the left border to right */
[dir="rtl"] .callout {
  border-left: 0;
  border-right: 4px solid var(--accent);
  border-radius: var(--r-md) 0 0 var(--r-md);
}
[dir="rtl"] .callout.rose { border-left-color: transparent; border-right-color: var(--rose); }
[dir="rtl"] .callout.warn { border-left-color: transparent; border-right-color: var(--amber); }

/* CBC table */
[dir="rtl"] .cbc th, [dir="rtl"] .cbc td { text-align: right; }
[dir="rtl"] .cbc td:nth-child(2), [dir="rtl"] .cbc th:nth-child(2) { text-align: left; }
[dir="rtl"] .cbc tr.hl td:first-child { border-left: 0; border-right: 4px solid var(--accent); }

/* Grades table */
[dir="rtl"] table.grades th, [dir="rtl"] table.grades td { text-align: right; }

/* Legend swatches — flip margin */
[dir="rtl"] .sw { margin-right: 0; margin-left: .45em; }

/* Evidence cards small margin */
[dir="rtl"] @media (max-width: 640px) {
  [dir="rtl"] .ev .stat small { margin-left: 0; margin-right: .5em; }
}

/* Clip quote — flip left border */
[dir="rtl"] .clip blockquote {
  border-left: 0;
  border-right: 3px solid var(--accent-soft);
  padding-left: 0;
  padding-right: var(--s-3);
}

/* Pull-quote */
[dir="rtl"] blockquote.q {
  padding-left: 0;
  padding-right: var(--s-5);
  border-left: 0;
  border-right: 4px solid var(--rose);
}
[dir="rtl"] .pull {
  border-left: 0;
  border-right: 6px solid var(--accent);
}
[dir="rtl"] .pull.beth {
  border-left-color: transparent;
  border-right-color: var(--rose);
}

/* Steps list — position numbers on the right */
[dir="rtl"] .steps li { padding-left: 0; padding-right: 3rem; }
[dir="rtl"] .steps li::before {
  left: auto; right: 0;
}

/* Wallet card back list */
[dir="rtl"] .alc-card.back ol { padding-left: 0; padding-right: 1.1em; }

/* Pill inline */
[dir="rtl"] .pill-inline { margin-left: 0; margin-right: .3em; }

/* Mini card decorations — keep them positioned same (they're decorative squares) */

/* Poster play button — direction-neutral, but the ::after triangle needs to flip */
[dir="rtl"] .yt-poster .play::after {
  left: auto; right: 30px;
  border-width: 16px 26px 16px 0;
  border-color: transparent var(--accent) transparent transparent;
}
[dir="rtl"] .film-player .yt-poster .play::after {
  left: auto; right: 38px;
  border-width: 20px 34px 20px 0;
}
[dir="rtl"] .dark .yt-poster .play::after {
  border-color: transparent var(--accent) transparent transparent;
}
@media (max-width: 800px) {
  [dir="rtl"] .film-player .yt-poster .play::after {
    left: auto; right: 26px;
    border-width: 15px 24px 15px 0;
  }
}

/* Timeline — flip the left border to right, dots to right */
[dir="rtl"] .timeline {
  border-left: 0;
  border-right: 3px solid var(--accent-soft);
  padding-left: 0;
  padding-right: var(--s-6);
}
[dir="rtl"] .timeline li { padding-left: 0; padding-right: var(--s-3); }
[dir="rtl"] .timeline li::before { left: auto; right: -8px; }

/* Source list numbers */
[dir="rtl"] .src-list li { padding-left: 0; padding-right: 3.5rem; }
[dir="rtl"] .src-list li::before {
  left: auto; right: 1rem;
}
[dir="rtl"] .src-list .tag { margin-left: 0; margin-right: .4rem; }

/* ALC card — keep the card mirrored properly */
[dir="rtl"] .alc-card { direction: rtl; text-align: right; }
[dir="rtl"] .alc-card .top em { margin-left: 0; margin-right: auto; }

/* Zone bar marker — flip translate math (marker is horizontal so mostly OK) */
[dir="rtl"] .zone-bar .marker { transform: scaleX(-1); }
[dir="rtl"] .zone-bar .marker::after { transform: translateX(50%) scaleX(-1); }

/* SVG charts — do NOT mirror; numbers on axes stay in Latin, so preserve LTR direction inside chart svgs */
[dir="rtl"] .chart svg,
[dir="rtl"] figure.chart svg { direction: ltr; }
[dir="rtl"] figure.chart figcaption { direction: rtl; text-align: right; }

/* Buttons — text stays natural (Arabic reads its own direction), icons flip */
[dir="rtl"] .btn svg { transform: scaleX(-1); }

/* Arrow characters used inline (→ ↓) — the → gets replaced in Arabic strings but if not, flip visually */
[dir="rtl"] .go, [dir="rtl"] .door .go { direction: rtl; }

/* Foot grid — keep multi-column but flip */
[dir="rtl"] .foot-grid ul { padding: 0; }
[dir="rtl"] .site-footer .brand span { direction: ltr; }

/* Nav underline / active — hover states are fine */

/* ============================================================
   Language switcher — SVG flag chips (renders on every browser)
   ============================================================ */
.lang-switch {
  display: inline-flex;
  gap: .35rem;
  align-items: center;
  margin-left: .75rem;
  padding: 0;
  background: transparent;
}
[dir="rtl"] .lang-switch { margin-left: 0; margin-right: .75rem; }
.lang-switch a {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 3px;
  border-radius: 6px;
  text-decoration: none;
  opacity: .55;
  transition: opacity .15s, transform .15s, box-shadow .15s;
  line-height: 0;
}
.lang-switch a .flag {
  display: block;
  width: 24px !important;
  height: 18px !important;
  min-width: 24px;
  flex-shrink: 0;
  border-radius: 3px;
  object-fit: cover;
  vertical-align: middle;
}
.lang-switch a:hover { opacity: 1; transform: scale(1.08); }
.lang-switch a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lang-switch a.active {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--accent), 0 1px 3px rgba(0,0,0,.15);
}
.dark .lang-switch a.active { box-shadow: 0 0 0 2px rgba(255,255,255,.85), 0 1px 3px rgba(0,0,0,.4); }

@media (max-width: 900px) {
  .lang-switch { margin: 0 0 0 auto; order: 2; }
  [dir="rtl"] .lang-switch { margin: 0 auto 0 0; }
  .lang-switch a .flag { width: 22px !important; height: 16px !important; min-width: 22px; }
}

/* Ensure the switcher works inside collapsed mobile menus */
.nav > .lang-switch { flex-shrink: 0; }

/* Prevent selective-scale from breaking Arabic ligatures */
[dir="rtl"] * { text-rendering: optimizeLegibility; }

/* Some hero elements use text-align:center via inline styles; keep those */
