/* Language toggle + Arabic / RTL presentation.
 *
 * Barlow has no Arabic glyphs, so Arabic would otherwise fall back to
 * whatever the device happens to have. IBM Plex Sans Arabic is loaded
 * alongside it and applied only when the page is in Arabic, which keeps the
 * English rendering byte-for-byte unchanged.
 */

/* ---- the toggle itself ---- */
#lang-toggle {
  font-family: var(--font-heading), system-ui, sans-serif;
  font-weight: 600;
  font-size: 13px;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--color-text) 78%, transparent);
  background: transparent;
  border: 1px solid var(--color-divider);
  padding: 0 11px;
  min-height: 34px;
  cursor: pointer;
  align-self: center;
  white-space: nowrap;
  transition: border-color 120ms ease, color 120ms ease;
}
#lang-toggle:hover { border-color: var(--color-accent); color: var(--color-accent-700); }
#lang-toggle:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

/* The nav is laid out flex-nowrap, so it cannot give an extra item any room:
 * at phone width the toggle was pushed past the right edge of the screen and
 * was physically untappable. Let the bar wrap on narrow viewports, and trim
 * the toggle so it usually still fits on the first row. 44px is the minimum
 * comfortable touch target. */
@media (max-width: 760px) {
  html nav.nav { flex-wrap: wrap; row-gap: 6px; }
  #lang-toggle { padding: 0 9px; min-height: 44px; font-size: 12px; letter-spacing: 0.06em; }
}

/* ---- Arabic typography ---- */
html[lang="ar"] body,
html[lang="ar"] input,
html[lang="ar"] select,
html[lang="ar"] textarea,
html[lang="ar"] button {
  font-family: "IBM Plex Sans Arabic", "Noto Sans Arabic", var(--font-body), system-ui, sans-serif;
}
html[lang="ar"] h1, html[lang="ar"] h2, html[lang="ar"] h3, html[lang="ar"] h4,
html[lang="ar"] .nav-brand,
html[lang="ar"] .process-name,
html[lang="ar"] .process-num {
  font-family: "IBM Plex Sans Arabic", "Noto Sans Arabic", var(--font-heading), system-ui, sans-serif;
  letter-spacing: 0;           /* Arabic letterforms join; tracking breaks them */
}
/* Arabic ascenders/descenders need more room than Barlow Condensed assumes. */
html[lang="ar"] .process-name { line-height: 1.45; }
html[lang="ar"] h1 { line-height: 1.3; }
/* The brand stays Latin even in Arabic — it is a wordmark, not a word. */
html[lang="ar"] .nav-brand { font-family: var(--font-heading), system-ui, sans-serif; }

/* ---- RTL corrections ----
 * Flow, grid order and text alignment mirror on their own under dir="rtl".
 * Only the handful of physically-sided declarations need restating. */
html[dir="rtl"] .process-name { padding-right: 0; padding-left: var(--space-6); }

@media (max-width: 640px) {
  /* The vertical ruler's spine must sit on the side the text starts from. */
  html[dir="rtl"] .process-rule {
    border-left: 0;
    border-right: 1px solid var(--color-text);
    background-image:
      linear-gradient(to bottom, var(--color-text) 0 1px, transparent 1px),
      repeating-linear-gradient(to bottom, color-mix(in srgb, var(--color-text) 20%, transparent) 0 1px, transparent 1px 9px);
    background-position: right top, right top;
  }
  html[dir="rtl"] .process-name { padding-left: 0; }
}

/* Latin fragments inside Arabic copy (an email address, the brand) must not
   be reordered by the bidi algorithm. */
html[dir="rtl"] a[href^="mailto:"],
html[dir="rtl"] .nav-brand { direction: ltr; unicode-bidi: isolate; }
