/* ================================================================
   AL-KHWARIZMI — cinematic story page (EN + AR share this file)
   Gold = Baghdad, c. 820. Cyan = code, today. The page moves from
   one to the other as you scroll. Logical properties serve RTL.
================================================================ */

.kh-page {
  --kh-bg: #04050c;
  --kh-ink: #f6f0e3;
  --kh-soft: #cdc9d9;
  --kh-mute: #9592ab;
  --kh-gold: #e9c27a;
  --kh-gold-hi: #ffdc8f;
  --kh-gold-deep: #9c7130;
  --kh-cyan: #00c3ff;
  --kh-cyan-soft: rgba(0, 195, 255, 0.16);
  --kh-line: rgba(233, 194, 122, 0.2);
  --kh-line-soft: rgba(233, 194, 122, 0.1);
  --kh-card: rgba(11, 11, 22, 0.9);
  --kh-serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --kh-naskh: "Amiri", "Traditional Arabic", "Times New Roman", serif;
  --kh-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --kh-ease: cubic-bezier(0.22, 1, 0.36, 1);
  background: var(--kh-bg);
  color: var(--kh-soft);
}

/* Fonts survive lang.js, which forces Cairo on Arabic text with !important. */
.kh .kh-naskh, .kh .kh-naskh * { font-family: var(--kh-naskh) !important; }
.kh .kh-serif, .kh .kh-serif * { font-family: var(--kh-serif) !important; }
.kh .kh-mono, .kh .kh-mono * { font-family: var(--kh-mono) !important; }

/* ---------- Sky canvas + progress ---------- */
#kh-sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  display: block;
}
.kh-progress {
  position: fixed;
  top: 68px;
  inset-inline: 0;
  height: 2px;
  z-index: 99;
  pointer-events: none;
}
.kh-progress span {
  display: block;
  height: 100%;
  width: 100%;
  transform: scaleX(var(--p, 0));
  transform-origin: left center;
  background: linear-gradient(90deg, var(--kh-gold), var(--kh-gold-hi) 40%, var(--kh-cyan));
  box-shadow: 0 0 12px rgba(233, 194, 122, 0.55);
}
[dir="rtl"] .kh-progress span {
  transform-origin: right center;
  background: linear-gradient(270deg, var(--kh-gold), var(--kh-gold-hi) 40%, var(--kh-cyan));
}

.kh {
  position: relative;
  z-index: 1;
  overflow-x: clip;
}
.kh a { color: inherit; }
/* typography.css paints every h1/h2 with a white gradient; this page colours its own headings. */
.kh h1, .kh h2, .kh h3 { background: none; -webkit-text-fill-color: currentColor; letter-spacing: normal; }
.kh-wrap {
  width: min(1180px, 100%);
  margin-inline: auto;
  padding-inline: 28px;
}

/* ---------- Chapter rail (desktop) ---------- */
.kh-rail {
  position: fixed;
  top: 50%;
  inset-inline-end: 20px;
  z-index: 50;
  display: none;
  flex-direction: column;
  gap: 14px;
  transform: translateY(-50%);
}
.kh-rail a {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--kh-line);
  border-radius: 50%;
  background: rgba(4, 5, 12, 0.6);
  color: var(--kh-soft);
  font: 600 0.95rem/1 var(--kh-serif);
  text-decoration: none;
  transition: color 0.3s, border-color 0.3s, background-color 0.3s, transform 0.3s var(--kh-ease);
}
.kh-rail a span {
  position: absolute;
  inset-inline-end: calc(100% + 12px);
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(4, 5, 12, 0.9);
  border: 1px solid var(--kh-line);
  color: var(--kh-ink);
  font: 500 0.75rem/1.4 "Inter", "Cairo", sans-serif;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(6px);
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
[dir="rtl"] .kh-rail a span { transform: translateX(-6px); }
.kh-rail a:hover span, .kh-rail a:focus-visible span { opacity: 1; transform: none; }
.kh-rail a:hover, .kh-rail a.is-now {
  color: var(--kh-bg);
  background: var(--kh-gold);
  border-color: var(--kh-gold);
  transform: scale(1.08);
}
.kh-rail a:focus-visible { outline: 2px solid var(--kh-cyan); outline-offset: 3px; }
@media (min-width: 1240px) { .kh-rail { display: flex; } }

/* ---------- Reveal ---------- */
/* Opacity + transform only: both run on the compositor, so reveals stay smooth on slow devices. */
.kh-js .kh-rv {
  opacity: 0;
  transform: translateY(26px);
  transition: opacity 0.9s var(--kh-ease), transform 0.9s var(--kh-ease);
  transition-delay: calc(var(--d, 0) * 110ms);
}
.kh-js .kh-rv.is-in { opacity: 1; transform: none; }

/* ================================================================
   HERO
================================================================ */
.kh-hero {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  align-items: center;
  padding: 110px 0 70px;
  isolation: isolate;
}
.kh-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60% 55% at 72% 46%, rgba(233, 194, 122, 0.13), transparent 70%),
    radial-gradient(40% 40% at 20% 80%, rgba(0, 195, 255, 0.05), transparent 70%);
}
[dir="rtl"] .kh-hero::before {
  background:
    radial-gradient(60% 55% at 28% 46%, rgba(233, 194, 122, 0.13), transparent 70%),
    radial-gradient(40% 40% at 80% 80%, rgba(0, 195, 255, 0.05), transparent 70%);
}
.kh-hero-in {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  align-items: center;
  gap: 40px;
}
.kh-hero-glyph {
  position: absolute;
  inset-inline: 0;
  bottom: -2vw;
  z-index: -1;
  text-align: center;
  font: 700 clamp(6rem, 21vw, 19rem)/1 var(--kh-naskh);
  color: transparent;
  -webkit-text-stroke: 1px rgba(233, 194, 122, 0.09);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  opacity: 0;
  animation: kh-fade 3s 1.4s var(--kh-ease) forwards;
}

.kh-eyebrow {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 18px;
  color: var(--kh-gold);
  font: 600 0.8rem/1.4 "Inter", sans-serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.kh-eyebrow .kh-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--kh-gold); box-shadow: 0 0 10px var(--kh-gold); }
.kh-hero-ar {
  margin: 0 0 4px;
  color: var(--kh-gold);
  font-size: clamp(1.3rem, 2.4vw, 1.75rem);
  line-height: 1.6;
}
.kh-h1 { margin: 0 0 22px; }
.kh-h1-main {
  display: block;
  padding-bottom: 0.08em;
  font-weight: 600;
  font-size: clamp(3.2rem, 7.4vw, 6.4rem);
  line-height: 1;
  letter-spacing: -0.01em;
  background: linear-gradient(100deg, #fff4dc 0%, var(--kh-gold-hi) 30%, var(--kh-gold) 48%, #fff7e6 52%, var(--kh-gold) 58%, var(--kh-gold-deep) 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  clip-path: inset(0 100% 0 0);
  animation: kh-wipe 1.6s 0.9s var(--kh-ease) forwards, kh-sheen 5s 2.6s ease-in-out 1;
}
[dir="rtl"] .kh-h1-main { clip-path: inset(0 0 0 100%); font-weight: 700; font-size: clamp(3.6rem, 9.5vw, 7.4rem); line-height: 1.25; }
.kh-h1-sub {
  display: block;
  margin-top: 12px;
  color: var(--kh-ink);
  font: 500 clamp(1.3rem, 2.5vw, 1.95rem)/1.3 var(--kh-serif);
  opacity: 0;
  animation: kh-rise 1.2s 1.6s var(--kh-ease) forwards;
}
.kh-h1-sub em { color: var(--kh-cyan); font-style: italic; }
.kh-lead {
  max-width: 560px;
  margin: 0 0 26px;
  color: var(--kh-soft);
  font-size: 1.04rem;
  line-height: 1.75;
  opacity: 0;
  animation: kh-rise 1.2s 1.9s var(--kh-ease) forwards;
}
.kh-hero-eq {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  margin-bottom: 30px;
  opacity: 0;
  animation: kh-rise 1.2s 2.2s var(--kh-ease) forwards;
}
.kh-eq {
  display: inline-block;
  padding: 10px 18px;
  border: 1px solid var(--kh-line);
  border-radius: 999px;
  background: rgba(233, 194, 122, 0.06);
  color: var(--kh-gold-hi);
  font: italic 600 1.45rem/1 var(--kh-serif);
  direction: ltr;
  unicode-bidi: isolate;
  white-space: nowrap;
}
.kh-eq sup { font-size: 0.62em; line-height: 0; vertical-align: 0.6em; }
.kh-hero-eq small { color: var(--kh-mute); font-size: 0.9rem; line-height: 1.5; }
.kh-cue {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--kh-ink);
  font: 600 0.9rem/1 "Inter", sans-serif;
  text-decoration: none;
  opacity: 0;
  animation: kh-rise 1.2s 2.5s var(--kh-ease) forwards;
}
.kh-cue i {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--kh-line);
  border-radius: 50%;
  color: var(--kh-gold);
  animation: kh-bob 2.4s ease-in-out infinite;
}
.kh-cue:hover i { border-color: var(--kh-gold); }
.kh-cue:focus-visible { outline: 2px solid var(--kh-cyan); outline-offset: 4px; border-radius: 8px; }

/* Medallion: astrolabe rings around the portrait */
.kh-medal {
  position: relative;
  width: min(540px, 100%);
  aspect-ratio: 1;
  margin-inline: auto;
  --mx: 0;
  --my: 0;
}
.kh-rings {
  position: absolute;
  inset: 0;
  transform: translate(calc(var(--mx) * -6px), calc(var(--my) * -6px));
  transition: transform 0.6s var(--kh-ease);
}
/* Each spinning ring is its own <svg>, rotated as a whole: the GPU turns a cached layer
   instead of the browser repainting the drawing on every frame. */
.kh-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.r-slow, .r-rev, .r-star, .r-orbit { will-change: transform; transform-origin: 50% 50%; }
.r-slow { animation: kh-spin 160s linear infinite; }
.r-rev { animation: kh-spin 110s linear infinite reverse; }
.r-star { animation: kh-spin 80s linear infinite; }
.r-orbit { animation: kh-spin 24s linear infinite; }
.kh-hero.is-off :is(.r-slow, .r-rev, .r-star, .r-orbit, .kh-halo, .kh-cue i) { animation-play-state: paused; }
/* Slow device detected by the page script: keep the rings drawn, stop them turning. */
.kh-lite :is(.r-slow, .r-rev, .r-star, .r-orbit, .kh-halo) { animation-play-state: paused; }
.kh-rings .ln { fill: none; stroke: var(--kh-gold); stroke-opacity: 0.34; stroke-width: 1.4; }
.kh-rings .ln-hi { fill: none; stroke: var(--kh-gold); stroke-opacity: 0.62; stroke-width: 1.6; }
.kh-rings .ln-cy { fill: none; stroke: var(--kh-cyan); stroke-opacity: 0.34; stroke-width: 1.4; stroke-dasharray: 3 9; }
.kh-rings .tk { fill: none; stroke: var(--kh-gold); stroke-opacity: 0.55; }
.kh-rings .draw {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: kh-draw 2.6s var(--kh-ease) forwards;
}
.kh-rings .d2 { animation-delay: 0.35s; }
.kh-rings .d3 { animation-delay: 0.7s; }
.kh-rings .d4 { animation-delay: 1.05s; }
.kh-rings .ring-txt {
  fill: var(--kh-gold);
  fill-opacity: 0.62;
  font: 500 13px/1 var(--kh-serif);
  letter-spacing: 0.18em;
  opacity: 0;
  animation: kh-fade 2s 1.2s ease forwards;
}
.kh-rings .orb { fill: var(--kh-gold-hi); filter: drop-shadow(0 0 6px var(--kh-gold)); }
.kh-rings .orb-c { fill: var(--kh-cyan); filter: drop-shadow(0 0 6px var(--kh-cyan)); }
.kh-halo {
  position: absolute;
  inset: 17%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, rgba(255, 214, 140, 0.32), rgba(233, 194, 122, 0.1) 46%, transparent 72%);
  will-change: transform, opacity;
  animation: kh-breathe 6s ease-in-out infinite;
}
.kh-portrait-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56%;
  transform: translate(calc(-50% + var(--mx) * 8px), calc(-47% + var(--my) * 8px));
  transition: transform 0.6s var(--kh-ease);
}
.kh-portrait {
  display: block;
  width: 100%;
  height: auto;
  opacity: 0;
  filter: brightness(0.15) sepia(0.3);
  transform: scale(1.06);
  animation: kh-emerge 2.8s 0.5s var(--kh-ease) forwards;
  -webkit-mask-image: radial-gradient(120% 96% at 50% 36%, #000 62%, transparent 88%);
  mask-image: radial-gradient(120% 96% at 50% 36%, #000 62%, transparent 88%);
}
.kh-medal-cap {
  position: absolute;
  inset-inline: 0;
  bottom: -6px;
  margin: 0;
  text-align: center;
  color: var(--kh-mute);
  font-size: 0.74rem;
  line-height: 1.5;
}

/* ================================================================
   CHAPTERS — shared
================================================================ */
.kh-ch {
  position: relative;
  padding: 120px 0;
}
.kh-ch-head { max-width: 780px; margin-bottom: 52px; }
.kh-ch-num {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 16px;
  color: var(--kh-gold);
  font: 600 0.78rem/1.4 "Inter", sans-serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.kh-ch-num i { flex: 0 0 56px; height: 1px; background: linear-gradient(90deg, var(--kh-gold), transparent); }
[dir="rtl"] .kh-ch-num i { background: linear-gradient(270deg, var(--kh-gold), transparent); }
.kh-h2 {
  margin: 0 0 18px;
  color: var(--kh-ink);
  font: 600 clamp(2.1rem, 4.6vw, 3.5rem)/1.08 var(--kh-serif);
  letter-spacing: -0.005em;
  text-transform: none;
}
[lang="ar"] .kh-h2 { font-weight: 700; }
.kh-h2 em { color: var(--kh-gold); font-style: italic; }
.kh-sub {
  margin: 0;
  max-width: 680px;
  color: var(--kh-soft);
  font-size: 1.05rem;
  line-height: 1.75;
}
.kh p { line-height: 1.75; }
.kh-body p { margin: 0 0 18px; color: var(--kh-soft); font-size: 1.02rem; }
.kh-body strong { color: var(--kh-ink); font-weight: 600; }

/* Quote */
.kh-quote {
  position: relative;
  margin: 28px 0 0;
  padding: 22px 26px 20px;
  border: 1px solid var(--kh-line);
  border-inline-start: 3px solid var(--kh-gold);
  border-radius: 4px 14px 14px 4px;
  background: linear-gradient(135deg, rgba(233, 194, 122, 0.07), rgba(233, 194, 122, 0.01));
}
[dir="rtl"] .kh-quote { border-radius: 14px 4px 4px 14px; }
.kh-quote .kh-q-ar {
  margin: 0;
  color: var(--kh-gold-hi);
  font-size: 1.32rem;
  line-height: 1.95;
  direction: rtl;
  text-align: right;
}
.kh-quote .kh-q-tr { margin: 12px 0 0; color: var(--kh-ink); font: italic 500 1.15rem/1.55 var(--kh-serif); }
.kh-quote cite { display: block; margin-top: 12px; color: var(--kh-mute); font-size: 0.8rem; font-style: normal; }

/* ================================================================
   CHAPTER 1 — story + stamp
================================================================ */
.kh-story {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 56px;
  align-items: start;
}
.kh-stamp {
  position: relative;
  margin: 0;
  padding: 36px 30px 22px;
  border: 1px solid var(--kh-line-soft);
  border-radius: 18px;
  background:
    radial-gradient(70% 60% at 50% 0%, rgba(255, 220, 150, 0.16), transparent 70%),
    rgba(10, 10, 20, 0.7);
  perspective: 900px;
}
.kh-stamp-img {
  display: block;
  width: min(300px, 80%);
  height: auto;
  margin: 0 auto;
  border-radius: 2px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.04);
  transform: rotateX(var(--ry, 0deg)) rotateY(var(--rx, 0deg)) rotate(-2.5deg);
  transition: transform 0.5s var(--kh-ease);
}
.kh-stamp figcaption { margin-top: 22px; color: var(--kh-mute); font-size: 0.84rem; line-height: 1.65; text-align: center; }
.kh-stamp figcaption b { display: block; margin-bottom: 4px; color: var(--kh-ink); font-weight: 600; }

.kh-facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 56px 0 0;
  padding: 0;
  list-style: none;
}
.kh-facts li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px;
  border: 1px solid var(--kh-line-soft);
  border-radius: 12px;
  background: var(--kh-card);
}
.kh-facts i {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: rgba(233, 194, 122, 0.1);
  color: var(--kh-gold);
  font-size: 1rem;
}
.kh-facts b { display: block; color: var(--kh-ink); font: 600 1.25rem/1.2 var(--kh-serif); }
.kh-facts span { display: block; margin-top: 2px; color: var(--kh-mute); font-size: 0.82rem; line-height: 1.5; }

.kh-books {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 22px 0 0;
  padding: 0;
  list-style: none;
}
.kh-books li {
  padding: 6px 12px;
  border: 1px solid var(--kh-line-soft);
  border-radius: 999px;
  color: var(--kh-soft);
  font-size: 0.82rem;
  line-height: 1.5;
}
.kh-books li b { color: var(--kh-gold); font-weight: 600; }

/* ================================================================
   CHAPTER 2 — the equation, solved with geometry
================================================================ */
.kh-problem {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 18px 30px;
  margin-bottom: 40px;
  padding: 26px 30px;
  border: 1px solid var(--kh-line);
  border-radius: 18px;
  background: linear-gradient(120deg, rgba(233, 194, 122, 0.08), rgba(0, 195, 255, 0.04));
}
.kh-problem .kh-naskh { margin: 0; color: var(--kh-gold-hi); font-size: clamp(1.4rem, 3vw, 2.1rem); line-height: 1.7; direction: rtl; }
.kh-problem .kh-tr { margin: 4px 0 0; color: var(--kh-soft); font: italic 500 1.12rem/1.5 var(--kh-serif); }
.kh-problem .kh-eq { font-size: clamp(1.4rem, 3vw, 2rem); padding: 12px 22px; }

.kh-proof {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 44px;
  align-items: start;
}
.kh-fig {
  position: relative;
  margin: 0;
  padding: 18px 18px 14px;
  border: 1px solid var(--kh-line-soft);
  border-radius: 18px;
  background: rgba(8, 8, 18, 0.78);
}
.kh-readout {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 46px;
  margin-bottom: 6px;
  color: var(--kh-gold-hi);
  font: italic 600 1.45rem/1 var(--kh-serif);
  direction: ltr;
}
.kh-readout span { animation: kh-pop 0.6s var(--kh-ease); }
.kh-fig-svg { display: block; width: 100%; height: auto; max-height: 520px; overflow: visible; }
.kh-fig-svg text { font-family: var(--kh-serif); font-style: italic; font-weight: 600; }
.f-grid line { stroke: rgba(255, 255, 255, 0.05); stroke-width: 1; }
.f-sq { fill: rgba(233, 194, 122, 0.22); stroke: var(--kh-gold-hi); stroke-width: 2; }
.f-strip { fill: rgba(233, 194, 122, 0.1); stroke: var(--kh-gold); stroke-width: 1.5; }
.f-corner { fill: rgba(0, 195, 255, 0.2); stroke: var(--kh-cyan); stroke-width: 1.5; }
.f-big { fill: none; stroke: var(--kh-gold-hi); stroke-width: 3; }
.f-lbl { fill: var(--kh-ink); font-size: 30px; text-anchor: middle; dominant-baseline: middle; }
.f-lbl-s { fill: var(--kh-gold); font-size: 17px; text-anchor: middle; dominant-baseline: middle; }
.f-lbl-c { fill: var(--kh-cyan); font-size: 18px; text-anchor: middle; dominant-baseline: middle; }
.f-dim line, .f-dim path { stroke: var(--kh-soft); stroke-width: 1.2; fill: none; }
.f-dim text { fill: var(--kh-soft); font-size: 19px; text-anchor: middle; }
.f-dim.is-hot line, .f-dim.is-hot path { stroke: var(--kh-cyan); }
.f-dim.is-hot text { fill: var(--kh-cyan); font-size: 24px; }
.f-dim.is-cut path { stroke: #ff6b6b; stroke-dasharray: 4 4; }
.f-dim.is-cut text { fill: #ff8f8f; text-decoration: line-through; }

.kh-fig [data-s] { transition: opacity 0.7s var(--kh-ease), transform 0.8s var(--kh-ease); }
.kh-js .kh-fig [data-s] { opacity: 0; }
.kh-js .kh-fig [data-s].is-on { opacity: 1; }
.kh-js .kh-fig [data-s].is-gone { opacity: 0; }
.kh-js .kh-fig .f-corner { transform-box: fill-box; transform-origin: center; transform: scale(0.15); }
.kh-js .kh-fig .f-corner.is-on { transform: none; }
.kh-js .kh-fig .f-big { stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset 1.6s var(--kh-ease), opacity 0.4s; }
.kh-js .kh-fig .f-big.is-on { stroke-dashoffset: 0; filter: drop-shadow(0 0 8px rgba(255, 220, 143, 0.6)); }
.kh-fig .f-strip.is-pulse { animation: kh-pulse 1.2s ease-in-out 2; }

.kh-fig-ctl {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}
.kh-dots { display: flex; gap: 6px; }
.kh-dots button {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.kh-dots button::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  transition: background-color 0.3s, transform 0.3s;
}
.kh-dots button.is-now::before { background: var(--kh-gold); transform: scale(1.35); box-shadow: 0 0 8px var(--kh-gold); }
.kh-dots button.is-done::before { background: rgba(233, 194, 122, 0.5); }
.kh-dots button:focus-visible { outline: 2px solid var(--kh-cyan); border-radius: 50%; }
.kh-btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--kh-line);
  border-radius: 999px;
  background: transparent;
  color: var(--kh-ink);
  font: 600 0.82rem/1 "Inter", "Cairo", sans-serif;
  cursor: pointer;
  transition: border-color 0.25s, background-color 0.25s;
}
.kh-btn-ghost:hover { border-color: var(--kh-gold); background: rgba(233, 194, 122, 0.08); }
.kh-btn-ghost:focus-visible { outline: 2px solid var(--kh-cyan); outline-offset: 2px; }

.kh-steps { margin: 0; padding: 0; list-style: none; counter-reset: st; }
.kh-steps li {
  position: relative;
  margin: 0 0 8px;
  padding: 14px 18px 14px 58px;
  border: 1px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  opacity: 0.42;
  transition: opacity 0.5s, background-color 0.5s, border-color 0.5s;
}
[dir="rtl"] .kh-steps li { padding: 14px 58px 14px 18px; }
.kh-steps li::before {
  counter-increment: st;
  content: counter(st);
  position: absolute;
  inset-inline-start: 16px;
  top: 16px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--kh-line);
  border-radius: 50%;
  color: var(--kh-gold);
  font: 600 0.85rem/1 var(--kh-serif);
}
.kh-steps li:first-child::before { content: "\2234"; }
.kh-steps li.is-done { opacity: 0.72; }
.kh-steps li.is-now {
  opacity: 1;
  border-color: var(--kh-line);
  background: linear-gradient(120deg, rgba(233, 194, 122, 0.1), rgba(233, 194, 122, 0.02));
}
.kh-steps li.is-now::before { background: var(--kh-gold); color: var(--kh-bg); border-color: var(--kh-gold); }
.kh-steps li:focus-visible { outline: 2px solid var(--kh-cyan); outline-offset: 2px; }
.kh-steps .kh-naskh { display: block; color: var(--kh-gold-hi); font-size: 1.22rem; line-height: 1.75; direction: rtl; }
.kh-steps .kh-tr { display: block; color: var(--kh-soft); font-size: 0.92rem; line-height: 1.55; }
.kh-steps .kh-m { display: inline-block; margin-top: 6px; color: var(--kh-cyan); font: italic 600 1.08rem/1.2 var(--kh-serif); direction: ltr; unicode-bidi: isolate; }
.kh-note { margin: 18px 0 0; color: var(--kh-mute); font-size: 0.88rem; line-height: 1.7; }

.kh-ms {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.7fr);
  gap: 32px;
  align-items: center;
  margin-top: 64px;
}
.kh-ms-photo {
  position: relative;
  margin: 0;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid var(--kh-line-soft);
  box-shadow: 0 40px 80px rgba(0, 0, 0, 0.5);
}
.kh-ms-photo img {
  display: block;
  width: 100%;
  height: auto;
  transform: scale(1.1);
  filter: saturate(0.85) brightness(0.9);
  transition: transform 6s var(--kh-ease), filter 2s;
}
.kh-ms-photo.is-in img { transform: scale(1); filter: none; }
.kh-ms-photo::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 60%, rgba(4, 5, 12, 0.55));
  pointer-events: none;
}
.kh-ms-tx h3 { margin: 0 0 10px; color: var(--kh-ink); font: 600 1.6rem/1.2 var(--kh-serif); }
.kh-ms-tx p { margin: 0 0 10px; color: var(--kh-soft); font-size: 0.95rem; }
.kh-ms-tx small { display: block; color: var(--kh-mute); font-size: 0.78rem; line-height: 1.6; }

/* ================================================================
   CHAPTER 3 — his sentence becomes a function
================================================================ */
.kh-map {
  border: 1px solid var(--kh-line-soft);
  border-radius: 18px;
  overflow: hidden;
  background: rgba(6, 7, 16, 0.85);
}
.kh-map-head, .kh-map-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr);
  align-items: center;
}
.kh-map-head {
  padding: 12px 22px;
  border-bottom: 1px solid var(--kh-line-soft);
  color: var(--kh-mute);
  font: 600 0.74rem/1.4 "Inter", "Cairo", sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.kh-map-head span:first-child { color: var(--kh-gold); }
.kh-map-head span:last-child { color: var(--kh-cyan); }
.kh-map-row {
  padding: 10px 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  transition: opacity 0.7s var(--kh-ease), transform 0.7s var(--kh-ease), background-color 0.4s;
  transition-delay: calc(var(--i, 0) * 180ms);
}
.kh-js .kh-map-row { opacity: 0; transform: translateX(-14px); }
[dir="rtl"].kh-js .kh-map-row { transform: translateX(14px); }
.kh-js .kh-map.is-in .kh-map-row { opacity: 1; transform: none; }
.kh-map-row > * { min-width: 0; }
.kh-map-row:hover { background: rgba(233, 194, 122, 0.04); }
.kh-map-row:last-child { border-bottom: 0; }
.kh-map-w { display: flex; flex-direction: column; align-items: flex-end; text-align: end; }
.kh-map-w .kh-naskh { display: block; color: var(--kh-gold-hi); font-size: 1.15rem; line-height: 1.7; direction: rtl; }
.kh-map-w small { display: block; color: var(--kh-mute); font-size: 0.8rem; line-height: 1.5; }
.kh-map-arrow { position: relative; height: 2px; margin: 0 8px; background: linear-gradient(90deg, var(--kh-gold), var(--kh-cyan)); opacity: 0.6; }
[dir="rtl"] .kh-map-arrow { background: linear-gradient(270deg, var(--kh-gold), var(--kh-cyan)); }
.kh-map-arrow::after {
  content: "";
  position: absolute;
  inset-inline-end: -2px;
  top: -4px;
  border: 5px solid transparent;
  border-inline-start: 7px solid var(--kh-cyan);
  border-inline-end: 0;
}
.kh-map-c code {
  display: block;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(0, 195, 255, 0.06);
  color: #d9f4ff;
  font-size: 0.9rem;
  line-height: 1.5;
  direction: ltr;
  text-align: left;
  white-space: pre;
  overflow-x: auto;
}
.kh-map-sig code { background: transparent; color: var(--kh-mute); }
.tk-k { color: #c792ea; }
.tk-f { color: #82aaff; }
.tk-n { color: var(--kh-gold-hi); }
.tk-c { color: #6b7a99; font-style: italic; }
.tk-v { color: #7fdbff; }

.kh-rule {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 22px;
  align-items: center;
  margin-top: 30px;
  padding: 26px 30px;
  border-radius: 18px;
  border: 1px solid rgba(0, 195, 255, 0.22);
  background: linear-gradient(120deg, rgba(0, 195, 255, 0.08), rgba(233, 194, 122, 0.05));
}
.kh-rule-ic {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: rgba(0, 195, 255, 0.12);
  color: var(--kh-cyan);
  font: italic 700 1.7rem/1 var(--kh-serif);
}
.kh-rule .kh-naskh { margin: 0 0 6px; color: var(--kh-gold-hi); font-size: 1.3rem; line-height: 1.8; direction: rtl; }
.kh-rule p { margin: 0; color: var(--kh-soft); font-size: 0.98rem; }
.kh-rule p + p { margin-top: 8px; }
.kh-rule strong { color: var(--kh-ink); }

.kh-run {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  gap: 28px;
  margin-top: 30px;
  padding: 26px;
  border: 1px solid var(--kh-line-soft);
  border-radius: 18px;
  background: rgba(8, 8, 18, 0.8);
}
.kh-run h3 { margin: 0 0 8px; color: var(--kh-ink); font: 600 1.5rem/1.2 var(--kh-serif); }
.kh-run > div > p { margin: 0 0 18px; color: var(--kh-mute); font-size: 0.9rem; }
.kh-run form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kh-field label { display: block; margin-bottom: 6px; color: var(--kh-soft); font-size: 0.82rem; font-weight: 500; }
.kh-field input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--kh-line);
  border-radius: 10px;
  background: rgba(4, 5, 12, 0.9);
  color: var(--kh-ink);
  font: 600 1.05rem/1 var(--kh-mono);
  direction: ltr;
  text-align: left !important;
}
.kh-field input:focus { outline: none; border-color: var(--kh-cyan); box-shadow: 0 0 0 3px rgba(0, 195, 255, 0.15); }
.kh-run .kh-btn-solid { grid-column: 1 / -1; }
.kh-btn-solid {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 46px;
  padding: 0 22px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(120deg, var(--kh-gold-hi), var(--kh-gold));
  color: #1a1206;
  font: 700 0.92rem/1 "Inter", "Cairo", sans-serif;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.25s var(--kh-ease), box-shadow 0.25s;
}
.kh .kh-btn-solid { color: #1a1206; }
.kh-btn-solid:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(233, 194, 122, 0.3); }
.kh-btn-solid:focus-visible { outline: 2px solid var(--kh-cyan); outline-offset: 3px; }
.kh-trace {
  margin: 0;
  padding: 18px 20px;
  min-height: 250px;
  border-radius: 12px;
  background: #03040a;
  border: 1px solid rgba(0, 195, 255, 0.14);
  list-style: none;
}
.kh-trace li {
  display: grid;
  grid-template-columns: minmax(96px, 0.9fr) minmax(0, 1.4fr);
  gap: 12px;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
  animation: kh-type 0.45s var(--kh-ease) both;
  animation-delay: calc(var(--i, 0) * 260ms);
}
.kh-trace li:last-child { border-bottom: 0; }
.kh-trace .t-l { color: var(--kh-mute); font-size: 0.85rem; }
.kh-trace .t-e { color: #d9f4ff; font-size: 0.95rem; direction: ltr; text-align: left; overflow-wrap: anywhere; }
.kh-trace .t-e b { color: var(--kh-gold-hi); font-weight: 700; }
.kh-trace .t-ok { color: #4ef0a1; }
.kh-trace .t-err { grid-column: 1 / -1; color: #ff9f9f; }

/* ================================================================
   CHAPTER 4 — from a name to a word
================================================================ */
.kh-name-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 210px;
  margin-bottom: 28px;
  border: 1px solid var(--kh-line-soft);
  border-radius: 22px;
  background:
    radial-gradient(60% 80% at 50% 50%, rgba(233, 194, 122, 0.08), transparent 70%),
    rgba(6, 7, 16, 0.7);
  overflow: hidden;
}
.kh-name-big {
  margin: 0;
  padding: 0 16px;
  color: var(--kh-ink);
  font: 600 clamp(2.6rem, 9vw, 6.4rem)/1.2 var(--kh-serif);
  text-align: center;
  letter-spacing: 0.02em;
  text-shadow: 0 0 40px rgba(233, 194, 122, 0.35);
  transition: opacity 0.5s, filter 0.5s;
  direction: ltr;
  min-height: 1.2em;
}
.kh-name-big.is-ar { font-family: var(--kh-naskh) !important; color: var(--kh-gold-hi); direction: rtl; font-weight: 700; }
.kh-name-big.is-swap { opacity: 0; transform: scale(0.96); }
.kh-name-big .sc { color: var(--kh-cyan); opacity: 0.85; }
.kh-name-era {
  position: absolute;
  bottom: 16px;
  inset-inline: 0;
  margin: 0;
  text-align: center;
  color: var(--kh-gold);
  font: 600 0.76rem/1.4 "Inter", "Cairo", sans-serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.kh-name-line {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 26px 0 0;
  list-style: none;
}
.kh-name-line::before {
  content: "";
  position: absolute;
  top: 7px;
  inset-inline: 10%;
  height: 1px;
  background: linear-gradient(90deg, var(--kh-gold), var(--kh-cyan));
  opacity: 0.45;
}
[dir="rtl"] .kh-name-line::before { background: linear-gradient(270deg, var(--kh-gold), var(--kh-cyan)); }
.kh-name-line li {
  position: relative;
  padding: 14px 14px 12px;
  border: 1px solid var(--kh-line-soft);
  border-radius: 12px;
  background: var(--kh-card);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.4s, background-color 0.4s, transform 0.4s var(--kh-ease);
}
.kh-name-line li::before {
  content: "";
  position: absolute;
  top: -24px;
  left: 50%;
  width: 11px;
  height: 11px;
  margin-left: -5.5px;
  border-radius: 50%;
  background: var(--kh-bg);
  border: 1px solid var(--kh-gold);
  transition: background-color 0.4s, box-shadow 0.4s;
}
.kh-name-line li.is-now { border-color: var(--kh-line); background: rgba(233, 194, 122, 0.08); transform: translateY(-3px); }
.kh-name-line li.is-now::before { background: var(--kh-gold); box-shadow: 0 0 12px var(--kh-gold); }
.kh-name-line li:focus-visible { outline: 2px solid var(--kh-cyan); outline-offset: 2px; }
.kh-name-line b { display: block; color: var(--kh-ink); font: 600 1.2rem/1.3 var(--kh-serif); }
.kh-name-line b.kh-naskh { color: var(--kh-gold-hi); font-size: 1.25rem; }
.kh-name-line small { display: block; margin-top: 4px; color: var(--kh-gold); font-size: 0.72rem; line-height: 1.4; }
.kh-name-line span { display: block; margin-top: 6px; color: var(--kh-mute); font-size: 0.8rem; line-height: 1.5; }
.kh-name-more {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 30px;
  margin-top: 40px;
}
.kh-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.kh-chips li {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--kh-line-soft);
  border-radius: 10px;
  background: var(--kh-card);
  color: var(--kh-soft);
  font-size: 0.85rem;
  line-height: 1.5;
}
.kh-chips li i { color: var(--kh-gold); font-style: normal; }
.kh-chips li b { color: var(--kh-ink); font-weight: 600; }
.kh-chips li em { color: var(--kh-cyan); font: italic 600 1rem/1 var(--kh-serif); }

/* ================================================================
   CHAPTER 5 — zero and the place of a digit
================================================================ */
.kh-zero {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 44px;
  align-items: start;
}
.kh-num-lab {
  padding: 26px;
  border: 1px solid var(--kh-line-soft);
  border-radius: 18px;
  background: rgba(8, 8, 18, 0.82);
}
.kh-num-in { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 24px; }
.kh-num-in .kh-field { flex: 1; }
.kh-lab-h { margin: 0 0 12px; color: var(--kh-mute); font: 600 0.72rem/1.4 "Inter", "Cairo", sans-serif; letter-spacing: 0.14em; text-transform: uppercase; }
.kh-places, .kh-bits {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  direction: ltr;
}
.kh-places li {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 58px;
  padding: 12px 8px 10px;
  border: 1px solid var(--kh-line);
  border-radius: 12px;
  background: rgba(233, 194, 122, 0.05);
  animation: kh-drop 0.6s var(--kh-ease) both;
  animation-delay: calc(var(--i, 0) * 90ms);
}
.kh-places li.is-zero { border-color: rgba(0, 195, 255, 0.5); background: rgba(0, 195, 255, 0.08); box-shadow: 0 0 22px rgba(0, 195, 255, 0.15); }
.kh-places b { color: var(--kh-ink); font: 600 2rem/1 var(--kh-serif); }
.kh-places li.is-zero b { color: var(--kh-cyan); }
.kh-places span { color: var(--kh-mute); font: 500 0.78rem/1 var(--kh-mono); }
.kh-expand { margin: 0 0 24px; color: var(--kh-gold-hi); font: 600 0.95rem/1.6 var(--kh-mono); direction: ltr; text-align: left; overflow-wrap: anywhere; }
.kh-bits { gap: 4px; }
.kh-bits li {
  display: grid;
  justify-items: center;
  gap: 4px;
  width: 30px;
  padding: 8px 0 6px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  animation: kh-drop 0.5s var(--kh-ease) both;
  animation-delay: calc(var(--i, 0) * 50ms + 400ms);
}
.kh-bits li.on { border-color: rgba(0, 195, 255, 0.55); background: rgba(0, 195, 255, 0.12); box-shadow: 0 0 14px rgba(0, 195, 255, 0.2); }
.kh-bits b { color: var(--kh-mute); font: 700 1rem/1 var(--kh-mono); }
.kh-bits li.on b { color: var(--kh-cyan); }
.kh-bits span { color: #5d5b72; font: 500 0.58rem/1 var(--kh-mono); }
.kh-bin-eq { margin: 0; color: var(--kh-cyan); font: 600 0.95rem/1.6 var(--kh-mono); direction: ltr; text-align: left; overflow-wrap: anywhere; }
.kh-num-err { margin: -14px 0 18px; color: #ff9f9f; font-size: 0.85rem; min-height: 1.2em; }

/* ================================================================
   CHAPTER 6 — the line from Baghdad to your screen
================================================================ */
.kh-spine {
  position: relative;
  margin: 0;
  padding: 0;
  list-style: none;
  --sp: 0;
}
.kh-spine::before, .kh-spine::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
}
.kh-spine::before { background: rgba(255, 255, 255, 0.06); }
.kh-spine::after {
  background: linear-gradient(180deg, var(--kh-gold), var(--kh-gold-hi) 35%, var(--kh-cyan));
  transform: scaleY(var(--sp));
  transform-origin: top;
  box-shadow: 0 0 14px rgba(233, 194, 122, 0.4);
}
.kh-spine > li {
  position: relative;
  width: calc(50% - 40px);
  margin-bottom: 26px;
}
.kh-spine > li:nth-child(odd) { margin-inline-end: auto; }
.kh-spine > li:nth-child(even) { margin-inline-start: auto; }
.kh-spine > li::before {
  content: "";
  position: absolute;
  top: 26px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--kh-bg);
  border: 2px solid var(--kh-gold);
  box-shadow: 0 0 0 5px rgba(4, 5, 12, 0.9);
  transition: background-color 0.5s, border-color 0.5s, box-shadow 0.5s;
}
.kh-spine > li:nth-child(odd)::before { inset-inline-end: -47px; }
.kh-spine > li:nth-child(even)::before { inset-inline-start: -47px; }
.kh-spine > li.is-in::before { background: var(--kh-cyan); border-color: var(--kh-cyan); box-shadow: 0 0 0 5px rgba(4, 5, 12, 0.9), 0 0 16px var(--kh-cyan); }
.kh-link {
  padding: 20px 22px;
  border: 1px solid var(--kh-line-soft);
  border-radius: 16px;
  background: var(--kh-card);
  transition: border-color 0.35s, transform 0.35s var(--kh-ease);
}
.kh-link:hover { border-color: var(--kh-line); transform: translateY(-3px); }
.kh-link-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.kh-link-top i {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(233, 194, 122, 0.16), rgba(0, 195, 255, 0.14));
  color: var(--kh-gold-hi);
  font-size: 1.05rem;
}
.kh-link h3 { margin: 0; color: var(--kh-ink); font: 600 1.35rem/1.2 var(--kh-serif); }
.kh-link dl { display: grid; gap: 8px; margin: 0; }
.kh-link dl div { display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: 10px; align-items: baseline; }
.kh-link dt { font: 700 0.66rem/1.6 "Inter", "Cairo", sans-serif; letter-spacing: 0.14em; text-transform: uppercase; }
.kh-link dt.then { color: var(--kh-gold); }
.kh-link dt.now { color: var(--kh-cyan); }
.kh-link dd { margin: 0; color: var(--kh-soft); font-size: 0.9rem; line-height: 1.6; }
.kh-link .kh-f {
  display: inline-block;
  margin-top: 12px;
  padding: 5px 12px;
  border-radius: 8px;
  background: rgba(0, 195, 255, 0.07);
  border: 1px solid rgba(0, 195, 255, 0.16);
  color: #d9f4ff;
  font-size: 0.86rem;
  direction: ltr;
  unicode-bidi: isolate;
}

.kh-method {
  margin-top: 90px;
  padding: 38px 36px;
  border: 1px solid var(--kh-line);
  border-radius: 22px;
  background:
    radial-gradient(70% 90% at 0% 0%, rgba(233, 194, 122, 0.1), transparent 60%),
    radial-gradient(60% 80% at 100% 100%, rgba(0, 195, 255, 0.08), transparent 60%),
    rgba(8, 8, 18, 0.85);
}
.kh-method > p { max-width: 720px; }
.kh-method ol {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 26px 0 26px;
  padding: 0;
  list-style: none;
  counter-reset: md;
}
.kh-method li {
  position: relative;
  padding: 18px 18px 16px;
  border: 1px solid var(--kh-line-soft);
  border-radius: 14px;
  background: rgba(4, 5, 12, 0.6);
}
.kh-method li::before {
  counter-increment: md;
  content: "0" counter(md);
  display: block;
  margin-bottom: 8px;
  color: var(--kh-gold);
  font: italic 600 1.5rem/1 var(--kh-serif);
}
.kh-method li h3 { margin: 0 0 6px; color: var(--kh-ink); font: 600 1.15rem/1.3 "Inter", "Cairo", sans-serif; }
.kh-method li p { margin: 0; color: var(--kh-soft); font-size: 0.9rem; line-height: 1.65; }
.kh-method li .kh-naskh { color: var(--kh-gold-hi); font-size: 1.05rem; }
.kh-method-links { display: flex; flex-wrap: wrap; gap: 10px; }
.kh-method-links a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid var(--kh-line-soft);
  border-radius: 10px;
  color: var(--kh-ink);
  font-size: 0.88rem;
  font-weight: 500;
  text-decoration: none;
  transition: border-color 0.25s, background-color 0.25s;
}
.kh-method-links a img { width: 22px; height: 22px; }
.kh-method-links a:hover { border-color: var(--kh-gold); background: rgba(233, 194, 122, 0.06); }
.kh-method-links a:focus-visible { outline: 2px solid var(--kh-cyan); outline-offset: 2px; }

/* ================================================================
   FINALE
================================================================ */
.kh-finale {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100svh;
  padding: 120px 0;
  text-align: center;
}
.kh-finale-in { max-width: 900px; margin-inline: auto; }
.kh-fin-q {
  margin: 0 0 18px;
  color: var(--kh-gold-hi);
  font-size: clamp(1.8rem, 4.4vw, 3.3rem);
  line-height: 1.75;
  direction: rtl;
  text-shadow: 0 0 40px rgba(233, 194, 122, 0.3);
}
.kh-fin-q .w {
  display: inline-block;
  transition: opacity 0.9s var(--kh-ease), filter 0.9s var(--kh-ease), transform 0.9s var(--kh-ease);
  transition-delay: calc(var(--i, 0) * 120ms);
}
.kh-js .kh-fin-q .w { opacity: 0; transform: translateY(14px); }
.kh-js .kh-finale.is-in .kh-fin-q .w { opacity: 1; transform: none; }
.kh-fin-tr { margin: 0 auto 34px; max-width: 720px; color: var(--kh-ink); font: italic 500 clamp(1.15rem, 2.2vw, 1.5rem)/1.5 var(--kh-serif); }
.kh-fin-src { display: block; margin-top: 8px; color: var(--kh-mute); font: 500 0.8rem/1.5 "Inter", "Cairo", sans-serif; font-style: normal; }
.kh-fin-turn { margin: 0 auto 26px; max-width: 640px; color: var(--kh-soft); font-size: 1.05rem; line-height: 1.8; }
.kh-fin-dixit {
  margin: 0 0 40px;
  color: var(--kh-ink);
  font: 600 clamp(1.6rem, 3.6vw, 2.6rem)/1.35 var(--kh-serif);
}
.kh-fin-dixit em { color: var(--kh-gold); font-style: italic; }
.kh-fin-dixit span { display: block; color: var(--kh-cyan); }
[lang="ar"] .kh-fin-dixit { font-weight: 700; }
.kh-fin-cta { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.kh-fin-cta .kh-btn-ghost { height: 46px; padding: 0 22px; font-size: 0.92rem; text-decoration: none; }
.kh-fin-sign { margin: 46px 0 0; color: var(--kh-mute); font-size: 0.82rem; letter-spacing: 0.08em; }

.kh-credits {
  position: relative;
  z-index: 1;
  padding: 0 0 50px;
}
.kh-credits p { margin: 0 auto; max-width: 900px; color: #6f6c86; font-size: 0.74rem; line-height: 1.7; text-align: center; }
.kh-credits a { color: #8f8ca7; }

/* ================================================================
   KEYFRAMES
================================================================ */
@keyframes kh-fade { to { opacity: 1; } }
@keyframes kh-rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes kh-wipe { to { clip-path: inset(0 0 0 0); } }
@keyframes kh-sheen { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@keyframes kh-spin { to { transform: rotate(360deg); } }
@keyframes kh-draw { to { stroke-dashoffset: 0; } }
@keyframes kh-breathe { 0%, 100% { opacity: 0.75; transform: scale(1); } 50% { opacity: 1; transform: scale(1.05); } }
@keyframes kh-emerge {
  0% { opacity: 0; filter: brightness(0.15) sepia(0.3); transform: scale(1.06); }
  60% { opacity: 1; }
  100% { opacity: 1; filter: brightness(1.02) sepia(0.12) contrast(1.04); transform: scale(1); }
}
@keyframes kh-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(5px); } }
@keyframes kh-pop { from { opacity: 0; transform: translateY(8px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes kh-pulse { 0%, 100% { fill: rgba(233, 194, 122, 0.1); } 50% { fill: rgba(233, 194, 122, 0.38); } }
@keyframes kh-type { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
@keyframes kh-drop { from { opacity: 0; transform: translateY(-10px) scale(0.9); } to { opacity: 1; transform: none; } }

/* ================================================================
   RESPONSIVE
================================================================ */
@media (max-width: 1024px) {
  .kh-hero-in { grid-template-columns: 1fr; gap: 26px; }
  .kh-medal { order: -1; width: min(420px, 86vw); }
  .kh-hero { padding-top: 96px; }
  .kh-story, .kh-proof, .kh-zero, .kh-run, .kh-ms, .kh-name-more { grid-template-columns: 1fr; }
  .kh-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kh-name-line { grid-template-columns: repeat(5, minmax(150px, 1fr)); overflow-x: auto; padding-bottom: 10px; scroll-snap-type: x mandatory; }
  .kh-name-line li { scroll-snap-align: start; }
  .kh-name-line::before { inset-inline: 70px; }
  .kh-method ol { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .kh-wrap { padding-inline: 16px; }
  .kh-ch { padding: 84px 0; }
  .kh-ch-head { margin-bottom: 36px; }
  .kh-hero { padding: 88px 0 56px; }
  .kh-hero-glyph { bottom: 6vh; }
  .kh-medal { width: min(340px, 88vw); }
  .kh-lead { font-size: 0.98rem; }
  .kh-eq { font-size: 1.25rem; }
  .kh-facts { grid-template-columns: 1fr; gap: 8px; }
  .kh-problem { padding: 20px; }
  .kh-fig { padding: 12px 8px 10px; }
  .kh-steps li { padding: 12px 14px 12px 52px; }
  [dir="rtl"] .kh-steps li { padding: 12px 52px 12px 14px; }
  .kh-map-head { display: none; }
  .kh-map-row { grid-template-columns: 1fr; gap: 8px; padding: 14px 16px; }
  .kh-map-w { align-items: flex-start; text-align: start; }
  .kh-map-arrow { width: 2px; height: 14px; margin: 0 12px; background: linear-gradient(180deg, var(--kh-gold), var(--kh-cyan)); }
  .kh-map-arrow::after { inset-inline-end: auto; inset-inline-start: -4px; top: auto; bottom: -6px; border: 5px solid transparent; border-top: 7px solid var(--kh-cyan); border-bottom: 0; }
  .kh-map-c code { font-size: 0.82rem; }
  .kh-rule { grid-template-columns: 1fr; padding: 22px 20px; }
  .kh-run { padding: 18px; }
  .kh-run form { grid-template-columns: 1fr 1fr; }
  .kh-trace { padding: 14px; }
  .kh-trace li { grid-template-columns: 1fr; gap: 2px; }
  .kh-num-lab { padding: 18px; }
  .kh-places li { min-width: 50px; }
  .kh-bits li { width: 26px; }
  .kh-spine::before, .kh-spine::after { left: 9px; margin-left: 0; }
  [dir="rtl"] .kh-spine::before, [dir="rtl"] .kh-spine::after { left: auto; right: 9px; }
  .kh-spine > li, .kh-spine > li:nth-child(odd), .kh-spine > li:nth-child(even) { width: auto; margin-inline-start: 34px; margin-inline-end: 0; }
  .kh-spine > li:nth-child(odd)::before, .kh-spine > li:nth-child(even)::before { inset-inline-start: -31px; inset-inline-end: auto; }
  .kh-link dl div { grid-template-columns: 1fr; gap: 0; }
  .kh-method { padding: 26px 18px; margin-top: 60px; }
  .kh-quote { padding: 18px 18px 16px; }
  .kh-quote .kh-q-ar { font-size: 1.15rem; }
}

/* Motion off: everything visible, nothing spins. */
@media (prefers-reduced-motion: reduce) {
  .kh-page *, .kh-page *::before, .kh-page *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0s !important;
  }
  .r-slow, .r-rev, .r-star, .r-orbit, .kh-halo, .kh-cue i { animation: none !important; }
  .kh-js .kh-rv, .kh-js .kh-map-row, .kh-js .kh-fin-q .w { opacity: 1; transform: none; filter: none; }
}

