/* NARSYSS — Arabic typography and right-to-left layout.
 * Loaded after the site stylesheet. Rules only apply when <html lang="ar" dir="rtl">.
 *
 * Physical utilities (left/right, pl/pr) are mirrored with two specificity levels:
 *   [dir=rtl] .x        (0,2,0) resets the original side
 *   html[dir=rtl] .x    (0,2,1) sets the opposite side
 * so an element with both pl-* and pr-* still gets both sides right.
 */

/* ───────── Hide until translated (only while Arabic is loading) ───────── */
html.i18n-pending body { opacity: 0; }
body { transition: opacity .25s ease; }

/* ───────── Typography ───────── */
html[lang="ar"] {
  --font-app-sans: "Thmanyah Sans", "Geist", "Geist Fallback", system-ui, sans-serif;
  --font-app-heading: "Thmanyah Sans", "Geist", "Geist Fallback", system-ui, sans-serif;
  --font-app-mono: "Geist Mono", "Thmanyah Sans", "Geist Mono Fallback", ui-monospace, monospace;
}
/* Letter-spacing breaks the joins between Arabic letters. */
html[lang="ar"] body,
html[lang="ar"] body * { letter-spacing: 0 !important; }

/* Arabic needs more vertical room than the tight Latin display settings. Thmanyah sets the dots of a final ي
   (e.g. after ع in "الاصطناعي") about half an em below the baseline; on tighter lines they landed on the hamza and
   shadda of the line below, so the ي read as ى. 1.6 keeps them clear. */
html[lang="ar"] h1, html[lang="ar"] h2, html[lang="ar"] h3,
html[lang="ar"] h4, html[lang="ar"] h5, html[lang="ar"] h6 { line-height: 1.6; }
html[lang="ar"] .text-giant    { line-height: 1.5; }
html[lang="ar"] .text-display  { line-height: 1.6; }
html[lang="ar"] .text-title    { line-height: 1.6; }
html[lang="ar"] .text-subtitle { line-height: 1.6; }
html[lang="ar"] .text-ui       { line-height: 1.45; }
html[lang="ar"] p, html[lang="ar"] li, html[lang="ar"] dd,
html[lang="ar"] blockquote, html[lang="ar"] figcaption,
html[lang="ar"] address, html[lang="ar"] .text-body { line-height: 1.85; }
html[lang="ar"] .label-mono,
html[lang="ar"] .label-mono-lc { font-size: .75rem; line-height: 1.5; }

/* Typed emails/phones stay left-to-right. (Phone numbers in text are isolated by i18n.js.) */
html[dir="rtl"] input[type="email"],
html[dir="rtl"] input[type="tel"],
html[dir="rtl"] input[type="url"] { direction: ltr; text-align: right; }
html[dir="rtl"] input[type="email"]::placeholder,
html[dir="rtl"] input[type="tel"]::placeholder { text-align: right; }

/* ───────── Text alignment ───────── */
[dir="rtl"] .text-left  { text-align: right; }
[dir="rtl"] .text-right { text-align: left; }

/* ───────── Padding (pl ↔ pr) ───────── */
[dir="rtl"] .pl-1\.5, [dir="rtl"] .pl-10 { padding-left: 0; }
[dir="rtl"] .pr-5, [dir="rtl"] .pr-6, [dir="rtl"] .pr-7 { padding-right: 0; }
html[dir="rtl"] .pl-1\.5 { padding-right: calc(var(--spacing) * 1.5); }
html[dir="rtl"] .pl-10   { padding-right: calc(var(--spacing) * 10); }
html[dir="rtl"] .pr-5    { padding-left: calc(var(--spacing) * 5); }
html[dir="rtl"] .pr-6    { padding-left: calc(var(--spacing) * 6); }
html[dir="rtl"] .pr-7    { padding-left: calc(var(--spacing) * 7); }

/* ───────── Positions (left ↔ right) ───────── */
[dir="rtl"] .left-0, [dir="rtl"] .left-3\.5, [dir="rtl"] .left-6, [dir="rtl"] .left-\[7px\] { left: auto; }
[dir="rtl"] .right-3, [dir="rtl"] .-right-20 { right: auto; }
html[dir="rtl"] .left-0       { right: 0; }
html[dir="rtl"] .left-3\.5    { right: calc(var(--spacing) * 3.5); }
html[dir="rtl"] .left-6       { right: calc(var(--spacing) * 6); }
html[dir="rtl"] .left-\[7px\] { right: 7px; }
html[dir="rtl"] .right-3      { left: calc(var(--spacing) * 3); }
html[dir="rtl"] .-right-20    { left: calc(var(--spacing) * -20); }

@media (min-width: 40rem) {
  [dir="rtl"] .sm\:pr-10 { padding-right: 0; }
  html[dir="rtl"] .sm\:pr-10 { padding-left: calc(var(--spacing) * 10); }
  [dir="rtl"] .sm\:left-7 { left: auto; }
  html[dir="rtl"] .sm\:left-7 { right: calc(var(--spacing) * 7); }
}
@media (min-width: 64rem) {
  [dir="rtl"] .lg\:pl-0, [dir="rtl"] .lg\:pl-10 { padding-left: 0; }
  html[dir="rtl"] .lg\:pl-0  { padding-right: 0; }
  html[dir="rtl"] .lg\:pl-10 { padding-right: calc(var(--spacing) * 10); }
  [dir="rtl"] .lg\:left-\[calc\(16\.6667\%-1px\)\],
  [dir="rtl"] .lg\:left-\[calc\(16\.6667\%-8px\)\] { left: auto; }
  html[dir="rtl"] .lg\:left-\[calc\(16\.6667\%-1px\)\] { right: calc(16.6667% - 1px); }
  html[dir="rtl"] .lg\:left-\[calc\(16\.6667\%-8px\)\] { right: calc(16.6667% - 8px); }
}

/* ───────── Directional icons & motion ───────── */
[dir="rtl"] .lucide-arrow-right,
[dir="rtl"] .lucide-arrow-up-right { transform: scaleX(-1); }

/* Cohort chart: time runs right-to-left, matching the mirrored "Month 01 … Month 12" labels. */
[dir="rtl"] svg[role="img"][viewBox="0 0 100 100"] { transform: scaleX(-1); }

/* Icons are mirrored, so rotations turn the other way. */
html[dir="rtl"] .rotate-\[135deg\] { rotate: -135deg; }
html[dir="rtl"] .group-hover\/action\:rotate-45:is(:where(.group\/action):hover *) { rotate: -45deg; }

/* Arrow nudge on hover: from the right instead of the left. */
html[dir="rtl"] .-translate-x-1 { --tw-translate-x: calc(var(--spacing) * 1); }
html[dir="rtl"] .group-hover\:translate-x-0:is(:where(.group):hover *) { --tw-translate-x: 0px; }
html[dir="rtl"] .group-hover\:translate-x-1:is(:where(.group):hover *) { --tw-translate-x: calc(var(--spacing) * -1); }

/* Marquees: the track keeps the English geometry (starts at the left edge, overflows to the right), because
 * iOS Safari leaves parts of a wide animated layer unpainted when it overflows to the left, which showed up as a
 * half-empty ticker. Items keep right-to-left text, and the track runs the other way (rightwards) instead. */
html[dir="rtl"] :has(> .animate-marquee),
html[dir="rtl"] :has(> .animate-marquee-reverse) { direction: ltr; }
html[dir="rtl"] .animate-marquee > * > *,
html[dir="rtl"] .animate-marquee-reverse > * > * { direction: rtl; }
@keyframes narsyss-marquee-rtl         { 0% { transform: translate(-50%); } to { transform: translate(0); } }
@keyframes narsyss-marquee-reverse-rtl { 0% { transform: translate(0); }    to { transform: translate(-50%); } }
html[dir="rtl"] .animate-marquee         { animation-name: narsyss-marquee-rtl; }
html[dir="rtl"] .animate-marquee-reverse { animation-name: narsyss-marquee-reverse-rtl; }

/* ───────── Language toggle ───────── */
.narsyss-lang-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2.5rem;
  min-width: 2.5rem;
  padding: 0 1rem;
  border-radius: 9999px;
  background: rgb(255 255 255 / .45);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--color-ink);
  font-size: .875rem;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .3s, color .3s;
}
.narsyss-lang-toggle[lang="ar"] { font-family: "Thmanyah Sans", var(--font-app-sans); }
.narsyss-lang-toggle[lang="en"] { font-family: "Geist", "Geist Fallback", sans-serif; }
.narsyss-lang-toggle:hover { background: var(--color-ink); color: #fff; }
.narsyss-lang-toggle:focus-visible { outline: 2px solid var(--color-volt); outline-offset: 2px; }

/* Scoped NARSYSS / Liftline wrappers define their own font variables: switch those to Arabic too. */
html[lang="ar"] .nx, html[lang="ar"] .ll {
  --font-app-sans: "Thmanyah Sans", "Geist", "Geist Fallback", system-ui, sans-serif;
  --font-app-heading: "Thmanyah Sans", "Geist", "Geist Fallback", system-ui, sans-serif;
  --font-app-mono: "Geist Mono", "Thmanyah Sans", "Geist Mono Fallback", ui-monospace, monospace;
}
/* Liftline headings are set tight for Latin; Arabic needs room */
html[lang="ar"] [data-ll] .text-h1, html[lang="ar"] [data-ll] .text-display { line-height: 1.6; }
html[lang="ar"] [data-ll] .text-h2 { line-height: 1.6; }
html[lang="ar"] [data-ll] h1, html[lang="ar"] [data-ll] h2, html[lang="ar"] [data-ll] h3, html[lang="ar"] [data-ll] .font-heading { line-height: 1.6; }
html[lang="ar"] [data-ll] .leading-\[1\.05\], html[lang="ar"] [data-ll] .leading-\[1\.1\], html[lang="ar"] [data-ll] .leading-snug { line-height: 1.4; }

/* Range sliders: in RTL the thumb starts on the right, so the fill grows from the right too. */
[dir="rtl"] .range-input {
  background: linear-gradient(to left, var(--ember) 0%, var(--ember) var(--fill, 50%), #f4f1ea29 var(--fill, 50%), #f4f1ea29 100%);
}

/* Home hero slogan: italic in English only (Arabic has no true italic, a fake slant reads badly). */
html[dir="rtl"] .nx-slogan { font-style: normal; }

/* Logo in the page language: "Narsyss" in English, "نرجِس" (Thmanyah) in Arabic. */
html:not([lang="ar"]) .nx-logo-ar,
html[lang="ar"] .nx-logo-en { display: none !important; }
html[lang="ar"] .nx-logo-ar { display: block; }
