/* ==========================================================================
   Khavarzadeh.com — Design System
   Single public stylesheet. Layers: tokens → base → layout → components →
   pages → utilities. RTL-first (Persian), LTR adjustments via [dir="ltr"].
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Fonts
   -------------------------------------------------------------------------- */
@font-face {
  font-family: 'dana';
  src: url('../fonts/dana/dana-regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'dana';
  src: url('../fonts/dana/dana-medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'dana';
  src: url('../fonts/dana/dana-demibold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'dana';
  src: url('../fonts/dana/dana-bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* --------------------------------------------------------------------------
   2. Tokens
   -------------------------------------------------------------------------- */
:root {
  /* Ink theme (default) */
  --bg: #0a0d13;
  --bg-2: #0d1118;
  --surface: #11161f;
  --surface-2: #161c28;
  --border: #232b3b;
  --border-soft: #1a2130;
  --text: #e9ecf2;
  --text-2: #aab2c3;
  --text-3: #778095;
  --accent: #e8a33d;
  --accent-strong: #f3b551;
  --on-accent: #100c04;
  --series-a: #e8a33d; /* بینش / بازار */
  --series-b: #6c9bf2; /* داده / AI  */
  --pos: #4cc38a;
  --neg: #e5484d;
  --grid-line: rgba(233, 236, 242, 0.05);
  --dot-grid: rgba(233, 236, 242, 0.07);
  --scrim: rgba(10, 13, 19, 0.82);
  --focus-ring: #6c9bf2;

  /* type */
  --font-fa: 'dana', 'Vazir', Tahoma, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
  --fs-display: clamp(2rem, 1.2rem + 3.2vw, 3.3rem);
  --fs-h2: clamp(1.45rem, 1.1rem + 1.3vw, 2rem);
  --fs-h3: 1.22rem;
  --fs-body: 1rem;
  --fs-small: 0.875rem;
  --fs-caption: 0.8125rem;
  --fs-label: 0.6875rem;

  /* spacing rhythm */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 1rem;
  --sp-4: 1.5rem;
  --sp-5: 2.5rem;
  --sp-6: 4rem;
  --section-gap: clamp(4.5rem, 10vw, 7.5rem);

  /* shape */
  --radius: 10px;
  --radius-sm: 6px;

  /* layout */
  --container: 1160px;
  --gutter: clamp(1.25rem, 4vw, 2.5rem);

  /* motion */
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dur-fast: 180ms;
  --dur: 320ms;
  --dur-slow: 560ms;

  color-scheme: dark;
}

[data-theme='light'] {
  --bg: #faf9f6;
  --bg-2: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #f7f5f0;
  --border: #ddd8cc;
  --border-soft: #e7e3d8;
  --text: #191d26;
  --text-2: #4b5468;
  --text-3: #7a8296;
  --accent: #9a6a10;
  --accent-strong: #7c540a;
  --on-accent: #ffffff;
  --series-a: #b97f16;
  --series-b: #3767c9;
  --pos: #1d7d53;
  --neg: #c53539;
  --grid-line: rgba(25, 29, 38, 0.07);
  --dot-grid: rgba(25, 29, 38, 0.1);
  --scrim: rgba(250, 249, 246, 0.88);
  --focus-ring: #3767c9;
  color-scheme: light;
}

/* --------------------------------------------------------------------------
   3. Base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-fa);
  font-size: var(--fs-body);
  line-height: 2;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Legacy market/lab pages keep main.css typography; kh shell stays Dana. */
body.legacy-ui {
  line-height: 1.85;
}

html[lang='en'] body.legacy-ui {
  line-height: 1.7;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 700;
  line-height: 1.5;
  text-wrap: balance;
}

p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

ul, ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

figure {
  margin: 0;
}

hr {
  border: 0;
  border-top: 1px solid var(--border-soft);
  margin: var(--sp-5) 0;
}

::selection {
  background: var(--accent);
  color: var(--on-accent);
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
  border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.kh-skip-link {
  position: absolute;
  inset-inline-start: 1rem;
  top: -4rem;
  z-index: 200;
  background: var(--accent);
  color: var(--on-accent);
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: top var(--dur-fast) var(--ease);
}

.kh-skip-link:focus-visible {
  top: 1rem;
}

/* --------------------------------------------------------------------------
   4. Layout primitives
   -------------------------------------------------------------------------- */
.kh-container {
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
  padding-block-end: var(--sp-5);
}

.kh-container > .kh-section:first-child {
  padding-block-start: clamp(2rem, 5vw, 3.5rem);
}

.kh-container > .kh-breadcrumb {
  padding-top: var(--sp-3);
}

.kh-section {
  padding-block: calc(var(--section-gap) / 2);
}

.kh-section--band {
  background: var(--bg-2);
  border-block: 1px solid var(--border-soft);
}

/* Section header: mono index + title + baseline rule with axis ticks */
.kh-section-head {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

.kh-section-head__index {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.14em;
  color: var(--accent);
  translate: 0 -0.35rem;
}

.kh-section-head__title {
  font-size: var(--fs-h2);
  white-space: nowrap;
}

.kh-section-head__rule {
  flex: 1;
  align-self: center;
  height: 7px;
  min-width: 3rem;
  background:
    repeating-linear-gradient(
      to left,
      var(--border) 0 1px,
      transparent 1px 2.5rem
    )
    bottom / 100% 5px no-repeat,
    linear-gradient(var(--border), var(--border)) bottom / 100% 1px no-repeat;
}

.kh-section-head__more {
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: color var(--dur-fast) var(--ease);
}

.kh-section-head__more:hover {
  color: var(--accent);
}

/* Mono kicker label (signature) — latin text; bidi keeps char order,
   block alignment follows the page direction */
.kh-kicker {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-3);
  unicode-bidi: isolate;
}

/* Legend dot: category/meta marker */
.kh-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--accent);
  flex: none;
}

.kh-dot--b {
  background: var(--series-b);
}

/* Meta line (date · category · reading time) */
.kh-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  font-size: var(--fs-caption);
  color: var(--text-3);
}

.kh-meta a:hover {
  color: var(--accent);
}

.kh-meta__sep {
  opacity: 0.5;
}

/* --------------------------------------------------------------------------
   5. Buttons & links
   -------------------------------------------------------------------------- */
.kh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 46px;
  padding: 0.55rem 1.5rem;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  font-size: var(--fs-small);
  line-height: 1.6;
  border: 1px solid transparent;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.kh-btn:hover {
  background: var(--accent-strong);
}

.kh-btn:active {
  transform: translateY(1px);
}

.kh-btn--ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.kh-btn--ghost:hover {
  background: var(--surface);
  border-color: var(--text-3);
}

/* Arrow link — arrow points inline-forward (start side in RTL) */
.kh-arrow-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 600;
  font-size: var(--fs-small);
  color: var(--accent);
}

.kh-arrow-link .kh-icon {
  transition: translate var(--dur-fast) var(--ease);
}

.kh-arrow-link:hover .kh-icon {
  translate: -3px 0;
}

[dir='ltr'] .kh-arrow-link:hover .kh-icon {
  translate: 3px 0;
}

/* underline-on-hover text link */
.kh-ulink {
  background-image: linear-gradient(var(--accent), var(--accent));
  background-repeat: no-repeat;
  background-size: 0% 1px;
  background-position: bottom right;
  transition: background-size var(--dur) var(--ease), color var(--dur-fast) var(--ease);
}

[dir='ltr'] .kh-ulink {
  background-position: bottom left;
}

.kh-ulink:hover {
  color: var(--accent);
  background-size: 100% 1px;
}

/* Inline SVG icon default */
.kh-icon {
  width: 1.05em;
  height: 1.05em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[dir='ltr'] .kh-icon--flip {
  transform: scaleX(-1);
}

/* --------------------------------------------------------------------------
   6. Header
   -------------------------------------------------------------------------- */
.kh-header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur) var(--ease);
}

/* blur lives on a pseudo-element: backdrop-filter on the header itself would
   turn it into the containing block for the fixed mobile nav overlay */
.kh-header::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.kh-header.is-scrolled {
  border-bottom-color: var(--border-soft);
}

.kh-header__inner {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-height: 64px;
}

.kh-brand {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  line-height: 1.4;
}

.kh-brand__name {
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--text);
}

.kh-brand__tag {
  font-family: var(--font-mono);
  font-size: 0.59rem;
  letter-spacing: 0.26em;
  color: var(--text-3);
  direction: ltr;
  unicode-bidi: isolate;
  text-transform: uppercase;
}

.kh-nav {
  display: flex;
  align-items: center;
  gap: clamp(0.9rem, 2vw, 1.8rem);
  margin-inline-start: auto;
}

.kh-nav a {
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--text-2);
  padding: 0.35rem 0.1rem;
  position: relative;
  transition: color var(--dur-fast) var(--ease);
}

.kh-nav a:hover {
  color: var(--text);
}

.kh-nav a[aria-current='page'] {
  color: var(--text);
}

.kh-nav a[aria-current='page']::after {
  content: '';
  position: absolute;
  inset-inline: 0;
  bottom: -2px;
  height: 2px;
  border-radius: 1px;
  background: var(--accent);
}

.kh-header__actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.kh-iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.kh-iconbtn:hover {
  color: var(--text);
  background: var(--surface);
}

.kh-lang-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.12em;
  color: var(--text-2);
  padding: 0.45rem 0.55rem;
  border-radius: var(--radius-sm);
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.kh-lang-link:hover {
  color: var(--text);
  background: var(--surface);
}

/* theme toggle: show one glyph per theme */
.kh-theme-toggle .kh-icon--sun { display: none; }
.kh-theme-toggle .kh-icon--moon { display: block; }
[data-theme='light'] .kh-theme-toggle .kh-icon--sun { display: block; }
[data-theme='light'] .kh-theme-toggle .kh-icon--moon { display: none; }

/* Mobile nav */
.kh-nav-toggle {
  display: none;
}

@media (max-width: 899px) {
  .kh-nav {
    position: fixed;
    inset: 0;
    z-index: 90;
    flex-direction: column;
    justify-content: center;
    gap: 0.4rem;
    background: var(--scrim);
    -webkit-backdrop-filter: blur(22px);
    backdrop-filter: blur(22px);
    margin: 0;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--dur) var(--ease), visibility var(--dur) var(--ease);
  }

  .kh-nav.is-open {
    opacity: 1;
    visibility: visible;
  }

  .kh-nav a {
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text);
    padding: 0.55rem 1rem;
  }

  .kh-nav a[aria-current='page']::after {
    inset-inline: 1rem;
  }

  .kh-nav-toggle {
    display: inline-flex;
    z-index: 110;
    margin-inline-start: auto;
  }

  .kh-header__inner {
    gap: var(--sp-2);
    min-width: 0;
  }

  .kh-brand {
    min-width: 0;
    flex: 1 1 auto;
  }

  .kh-header__actions {
    z-index: 110;
    flex-shrink: 0;
    gap: 0.15rem;
  }

  body.kh-nav-open {
    overflow: hidden;
  }
}

/* --------------------------------------------------------------------------
   7. Hero + correlation visual (signature element)
   -------------------------------------------------------------------------- */
.kh-hero {
  position: relative;
  padding-block: clamp(3.5rem, 9vh, 6.5rem) clamp(3rem, 7vh, 5rem);
  overflow: hidden;
}

.kh-hero::before {
  /* faint dot-grid texture, hero only */
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--dot-grid) 1px, transparent 1px);
  background-size: 26px 26px;
  -webkit-mask-image: radial-gradient(75% 90% at 50% 10%, #000 0%, transparent 78%);
  mask-image: radial-gradient(75% 90% at 50% 10%, #000 0%, transparent 78%);
  pointer-events: none;
}

.kh-hero__grid {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 6fr) minmax(0, 6fr);
  gap: clamp(2rem, 5vw, 4.5rem);
  align-items: center;
}

.kh-hero__kicker {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: var(--sp-4);
}

.kh-hero__kicker .kh-kicker {
  color: var(--accent);
}

.kh-hero__kicker::after {
  content: '';
  width: 3.5rem;
  height: 1px;
  background: var(--border);
}

.kh-hero__title {
  font-size: var(--fs-display);
  line-height: 1.45;
  margin-bottom: var(--sp-4);
}

.kh-hero__title em {
  font-style: normal;
  color: var(--accent);
}

.kh-hero__lede {
  color: var(--text-2);
  max-width: 34rem;
  margin-bottom: var(--sp-5);
}

.kh-hero__ctas {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: center;
}

/* Visual panel */
.kh-viz {
  position: relative;
}

/* rotating example caption above the hero chart */
.kh-viz__example {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  margin-bottom: var(--sp-2);
  min-height: 1.6rem;
}

.kh-viz__example-text {
  font-size: var(--fs-caption);
  font-weight: 600;
  color: var(--text-2);
  transition: opacity var(--dur) var(--ease);
}

.kh-viz__example-text.is-switching {
  opacity: 0;
}

#khVizVarA,
#khVizVarB {
  transition: opacity var(--dur) var(--ease);
}

.kh-viz.is-switching #khVizVarA,
.kh-viz.is-switching #khVizVarB {
  opacity: 0;
}

.kh-viz__canvas {
  display: block;
  width: 100%;
  height: clamp(260px, 38vw, 400px);
}

.kh-viz__legend {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-top: var(--sp-3);
  font-size: var(--fs-caption);
  color: var(--text-2);
}

.kh-viz__legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.kh-viz__legend-item .kh-dot {
  width: 14px;
  height: 3px;
  border-radius: 2px;
}

.kh-viz__r {
  margin-inline-start: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.08em;
  color: var(--text-3);
  direction: ltr;
  unicode-bidi: isolate;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.55rem;
  transition: color var(--dur) var(--ease);
}

@media (max-width: 899px) {
  .kh-hero__grid {
    grid-template-columns: 1fr;
    gap: var(--sp-5);
  }

  .kh-viz__canvas {
    height: clamp(200px, 52vw, 300px);
  }
}

/* --------------------------------------------------------------------------
   8. Quiet facts row (achievements inside the about block)
   -------------------------------------------------------------------------- */
.kh-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3) var(--sp-5);
  margin-top: var(--sp-4);
}

.kh-facts li {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: var(--fs-caption);
  color: var(--text-3);
  line-height: 1.8;
  border-inline-start: 2px solid var(--border);
  padding-inline-start: 0.75rem;
}

.kh-facts__value {
  font-weight: 700;
  font-size: var(--fs-small);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  flex: none;
}

/* --------------------------------------------------------------------------
   9. Focus areas (services) — editorial numbered rows
   -------------------------------------------------------------------------- */
.kh-focus {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 clamp(2rem, 5vw, 4.5rem);
}

.kh-focus__item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-3);
  padding-block: var(--sp-4);
  border-top: 1px solid var(--border-soft);
}

.kh-focus__num {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.1em;
  color: var(--accent);
  padding-top: 0.55rem;
  direction: ltr;
}

.kh-focus__title {
  font-size: var(--fs-h3);
  font-weight: 600;
  margin-bottom: var(--sp-1);
}

.kh-focus__desc {
  color: var(--text-2);
  font-size: var(--fs-small);
  line-height: 1.9;
}

.kh-focus__more {
  display: inline-flex;
  margin-top: var(--sp-2);
}

@media (max-width: 899px) {
  .kh-focus {
    grid-template-columns: 1fr;
  }
}

/* --------------------------------------------------------------------------
   10. Experience timeline — time axis
   -------------------------------------------------------------------------- */
.kh-timeline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-4);
  position: relative;
  padding-top: var(--sp-4);
}

.kh-timeline::before {
  /* the axis */
  content: '';
  position: absolute;
  top: 0;
  inset-inline: 0;
  height: 1px;
  background: var(--border);
}

.kh-timeline__item {
  position: relative;
  padding-top: var(--sp-3);
}

.kh-timeline__item::before {
  /* axis tick */
  content: '';
  position: absolute;
  top: -4px;
  inset-inline-start: 0;
  width: 1px;
  height: 9px;
  background: var(--accent);
}

.kh-timeline__years {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.08em;
  color: var(--accent);
  display: block;
  margin-bottom: var(--sp-2);
}

.kh-timeline__title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: var(--sp-1);
}

.kh-timeline__desc {
  font-size: var(--fs-caption);
  color: var(--text-2);
  line-height: 1.9;
}

@media (max-width: 640px) {
  .kh-timeline {
    grid-template-columns: 1fr;
    gap: 0;
    padding-top: 0;
  }

  .kh-timeline::before {
    inset-inline: auto;
    inset-inline-start: 3px;
    top: 6px;
    bottom: 6px;
    width: 1px;
    height: auto;
  }

  .kh-timeline__item {
    padding: 0 0 var(--sp-4);
    padding-inline-start: var(--sp-4);
  }

  .kh-timeline__item::before {
    top: 10px;
    inset-inline-start: 0;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
  }
}

/* --------------------------------------------------------------------------
   11. Stories (insights) — editorial feature + rows
   -------------------------------------------------------------------------- */
.kh-stories {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: clamp(2rem, 5vw, 4rem);
  align-items: start;
}

.kh-story-feature {
  display: block;
}

.kh-story-feature .kh-thumb {
  margin-bottom: var(--sp-4);
}

.kh-story-feature__title {
  font-size: clamp(1.35rem, 1.1rem + 1vw, 1.8rem);
  line-height: 1.6;
  margin-bottom: var(--sp-2);
  transition: color var(--dur-fast) var(--ease);
}

.kh-story-feature:hover .kh-story-feature__title {
  color: var(--accent);
}

.kh-story-list {
  display: flex;
  flex-direction: column;
}

.kh-story-row {
  display: block;
  padding-block: var(--sp-4);
  border-top: 1px solid var(--border-soft);
}

.kh-story-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.kh-story-row__title {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.8;
  margin-bottom: var(--sp-1);
  transition: color var(--dur-fast) var(--ease);
}

.kh-story-row:hover .kh-story-row__title {
  color: var(--accent);
}

@media (max-width: 899px) {
  .kh-stories {
    grid-template-columns: 1fr;
  }
}

/* Thumbnail with graceful data-pattern fallback */
.kh-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border-soft);
}

.kh-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--dur-slow) var(--ease), opacity var(--dur) var(--ease);
}

a:hover .kh-thumb img {
  transform: scale(1.025);
}

.kh-thumb--sq {
  aspect-ratio: 1 / 1;
}

/* pattern placeholder: dot grid + sparkline */
.kh-thumb--pattern {
  display: flex;
  align-items: flex-end;
  background-image: radial-gradient(var(--dot-grid) 1px, transparent 1px);
  background-size: 22px 22px;
}

.kh-thumb--pattern svg {
  width: 100%;
  height: 55%;
}

.kh-thumb--pattern .kh-thumb__label {
  position: absolute;
  top: 0.9rem;
  inset-inline-start: 1rem;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.18em;
  color: var(--text-3);
  direction: ltr;
  unicode-bidi: isolate;
}

/* --------------------------------------------------------------------------
   12. Cards grid (videos / archive)
   -------------------------------------------------------------------------- */
.kh-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
  gap: var(--sp-5) var(--sp-4);
}

.kh-card {
  display: block;
}

.kh-card .kh-thumb {
  margin-bottom: var(--sp-3);
}

.kh-card__title {
  font-size: 1.02rem;
  font-weight: 600;
  line-height: 1.8;
  margin-bottom: var(--sp-1);
  transition: color var(--dur-fast) var(--ease);
}

.kh-card:hover .kh-card__title {
  color: var(--accent);
}

/* play badge for videos */
.kh-play-badge {
  position: absolute;
  inset-inline-end: 0.8rem;
  bottom: 0.8rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--scrim);
  border: 1px solid var(--border);
  color: var(--text);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.kh-play-badge svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
  stroke: none;
  margin-inline-end: -2px;
}

/* --------------------------------------------------------------------------
   13. Clients strip
   -------------------------------------------------------------------------- */
.kh-clients {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3) var(--sp-3);
}

/* logos sit on a small white tile so any brand color stays legible on ink */
.kh-clients__tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  min-width: 118px;
  padding: 0.7rem 1.1rem;
  background: #fff;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  transition: transform var(--dur-fast) var(--ease);
}

.kh-clients__tile:hover {
  transform: translateY(-2px);
}

.kh-clients img {
  height: 40px;
  width: auto;
  max-width: 120px;
  object-fit: contain;
  opacity: 0.75;
  filter: grayscale(1);
  transition: opacity var(--dur) var(--ease), filter var(--dur) var(--ease);
}

.kh-clients__tile:hover img {
  opacity: 1;
  filter: none;
}

/* brands without a logo yet: quiet chip matching the tile height */
.kh-clients__name {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 64px;
  min-width: 118px;
  padding: 0.7rem 1.3rem;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 600;
  font-size: var(--fs-small);
  text-align: center;
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   14. About block
   -------------------------------------------------------------------------- */
.kh-about {
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(0, 7fr);
  gap: clamp(2rem, 6vw, 5rem);
  align-items: center;
}

.kh-portrait {
  position: relative;
}

.kh-portrait::before {
  /* offset dot-grid frame */
  content: '';
  position: absolute;
  inset: 1.2rem -1.2rem -1.2rem 1.2rem;
  background-image: radial-gradient(var(--dot-grid) 1px, transparent 1px);
  background-size: 14px 14px;
  border-radius: var(--radius);
}

[dir='ltr'] .kh-portrait::before {
  inset: 1.2rem 1.2rem -1.2rem -1.2rem;
}

.kh-portrait img {
  position: relative;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 100%;
  object-fit: cover;
  aspect-ratio: 4 / 5;
}

.kh-roles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-block: var(--sp-4);
}

.kh-role-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--fs-caption);
  color: var(--text-2);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 0.28rem 0.85rem;
}

@media (max-width: 899px) {
  .kh-about {
    grid-template-columns: 1fr;
  }

  .kh-portrait {
    max-width: 330px;
    margin-inline: auto;
  }
}

/* --------------------------------------------------------------------------
   15. Forms
   -------------------------------------------------------------------------- */
.kh-field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-bottom: var(--sp-4);
}

.kh-field label {
  font-size: var(--fs-caption);
  font-weight: 600;
  color: var(--text-2);
}

.kh-input {
  width: 100%;
  min-height: 48px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  font: inherit;
  line-height: 1.7;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.kh-input::placeholder {
  color: var(--text-3);
}

.kh-input:focus {
  outline: none;
  border-color: var(--accent);
}

textarea.kh-input {
  resize: vertical;
  min-height: 140px;
}

/* Django messages */
.kh-alert {
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
  font-size: var(--fs-small);
}

.kh-alert--success {
  border-inline-start-color: var(--pos);
}

.kh-alert--danger,
.kh-alert--error {
  border-inline-start-color: var(--neg);
}

/* --------------------------------------------------------------------------
   16. Contact block
   -------------------------------------------------------------------------- */
.kh-contact {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: clamp(2rem, 6vw, 5rem);
  align-items: start;
}

.kh-contact__list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  margin-top: var(--sp-5);
}

.kh-contact__list--flush {
  margin-top: 0;
}

.kh-contact__item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.kh-contact__item dt {
  font-size: var(--fs-caption);
  color: var(--text-3);
}

.kh-contact__item dd {
  margin: 0;
  font-weight: 600;
  direction: ltr;
  unicode-bidi: isolate;
}

/* keep the value visually aligned with its label in both page directions */
[dir='rtl'] .kh-contact__item dd {
  text-align: right;
}

[dir='ltr'] .kh-contact__item dd {
  text-align: left;
}

.kh-contact__item dd a:hover {
  color: var(--accent);
}

.kh-social {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.kh-social :is(a, button) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  background: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.kh-social a:hover,
.kh-social button:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.kh-social button.is-copied {
  color: var(--accent);
  border-color: var(--accent);
}

@media (max-width: 899px) {
  .kh-contact {
    grid-template-columns: 1fr;
  }
}

/* --------------------------------------------------------------------------
   17. Footer
   -------------------------------------------------------------------------- */
.kh-footer {
  margin-top: var(--section-gap);
  border-top: 1px solid var(--border-soft);
  background: var(--bg-2);
}

.kh-footer__spark {
  display: block;
  width: 100%;
  height: 46px;
  opacity: 0.7;
}

.kh-footer__grid {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) repeat(3, minmax(0, 1fr));
  gap: var(--sp-5) clamp(1.25rem, 3vw, 2.5rem);
  padding-block: var(--sp-5);
}

.kh-footer__identity p {
  color: var(--text-3);
  font-size: var(--fs-small);
  max-width: 26rem;
  margin-top: var(--sp-2);
}

.kh-footer h4 {
  font-size: var(--fs-caption);
  font-weight: 600;
  color: var(--text-3);
  margin-bottom: var(--sp-3);
}

.kh-footer__col ul {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.kh-footer__col a {
  font-size: var(--fs-small);
  color: var(--text-2);
}

.kh-footer__col a:hover {
  color: var(--accent);
}

.kh-footer__bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  border-top: 1px solid var(--border-soft);
  padding-block: var(--sp-4);
  font-size: var(--fs-caption);
  color: var(--text-3);
}

.kh-footer__copy {
  direction: ltr;
  unicode-bidi: isolate;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.06em;
}

@media (max-width: 899px) {
  .kh-footer__grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-4) var(--sp-5);
  }

  .kh-footer__identity {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .kh-footer__grid {
    grid-template-columns: 1fr;
    gap: var(--sp-4);
  }

  .kh-footer__bottom {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--sp-2);
  }

  .kh-footer__meta-links {
    gap: 0.5rem 0.85rem;
  }
}

/* --------------------------------------------------------------------------
   17b. Correlation lab (interactive closing section)
   -------------------------------------------------------------------------- */
.kh-lab__head {
  max-width: 44rem;
  margin-bottom: var(--sp-5);
}

.kh-lab__title {
  font-size: var(--fs-h2);
  line-height: 1.6;
  margin-top: var(--sp-3);
}

.kh-lab__title em {
  font-style: normal;
  color: var(--accent);
  display: block;
}

.kh-lab__lede {
  margin-top: var(--sp-3);
  max-width: 38rem;
}

.kh-lab__stage {
  position: relative;
}

.kh-lab__canvas {
  display: block;
  width: 100%;
  height: clamp(320px, 42vw, 460px);
  cursor: grab;
  touch-action: pan-y;
  border-radius: var(--radius);
}

.kh-lab__canvas.is-dragging {
  cursor: grabbing;
}

.kh-lab__canvas:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 4px;
}

.kh-lab__hint {
  position: absolute;
  top: 18%;
  inset-inline-start: 50%;
  translate: 50% 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--fs-caption);
  font-weight: 600;
  pointer-events: none;
  animation: kh-hint-nudge 2.2s var(--ease) infinite;
  transition: opacity var(--dur) var(--ease), visibility var(--dur) var(--ease);
}

[dir='ltr'] .kh-lab__hint {
  translate: -50% 0;
}

.kh-lab__hint.is-hidden {
  opacity: 0;
  visibility: hidden;
}

@keyframes kh-hint-nudge {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(7px); }
}

@media (prefers-reduced-motion: reduce) {
  .kh-lab__hint {
    animation: none;
  }
}

.kh-lab__readout {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-4) var(--sp-6);
  margin-top: var(--sp-4);
  border-top: 1px solid var(--border-soft);
  padding-top: var(--sp-4);
}

.kh-lab__stat {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.kh-lab__stat-label {
  font-size: var(--fs-caption);
  color: var(--text-3);
}

.kh-lab__stat-value {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  unicode-bidi: isolate;
  text-align: start;
  transition: color var(--dur-fast) var(--ease);
}

.kh-lab__stat--main .kh-lab__stat-value {
  font-size: 1.9rem;
  font-weight: 700;
}

.kh-lab__stat-value--sm {
  font-size: 0.95rem;
}

.kh-lab__reset {
  margin-inline-start: auto;
}

.kh-lab__note {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  margin-top: var(--sp-4);
  font-size: var(--fs-caption);
  color: var(--text-3);
}

@media (max-width: 640px) {
  .kh-lab__readout {
    gap: var(--sp-3) var(--sp-4);
  }

  .kh-lab__stat--main {
    order: -1;
    flex-basis: 100%;
  }

  .kh-lab__reset {
    margin-inline-start: 0;
  }

  .kh-lab__note {
    flex-direction: column;
    gap: 0.2rem;
  }
}

/* --------------------------------------------------------------------------
   18. Page header (inner pages)
   -------------------------------------------------------------------------- */
.kh-page-head {
  padding-block: clamp(2.5rem, 6vw, 4.5rem) var(--sp-5);
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: var(--sp-5);
}

.kh-page-head .kh-kicker {
  display: block;
  margin-bottom: var(--sp-3);
  color: var(--accent);
}

.kh-page-head__title {
  font-size: var(--fs-display);
  line-height: 1.4;
}

.kh-page-head__lede {
  color: var(--text-2);
  max-width: 40rem;
  margin-top: var(--sp-3);
}

/* Filters / search row */
.kh-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

.kh-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 230px;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding-inline: 0.9rem;
  transition: border-color var(--dur-fast) var(--ease);
}

.kh-search:focus-within {
  border-color: var(--accent);
}

.kh-search input {
  flex: 1;
  min-height: 46px;
  background: none;
  border: 0;
  color: var(--text);
  font: inherit;
}

.kh-search input:focus {
  outline: none;
}

.kh-search .kh-icon {
  color: var(--text-3);
}

.kh-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.kh-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 38px;
  padding: 0.2rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: var(--fs-caption);
  font-weight: 500;
  color: var(--text-2);
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.kh-chip:hover {
  color: var(--text);
  border-color: var(--text-3);
}

.kh-chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   19. Article (prose) — CKEditor content
   -------------------------------------------------------------------------- */
.kh-article-head {
  max-width: 46rem;
  margin-inline: auto;
  text-align: center;
  padding-block: clamp(2rem, 5vw, 3.5rem) 0;
}

.kh-container > .kh-breadcrumb + .kh-article-head {
  padding-block-start: var(--sp-4);
}

.kh-article-head__title {
  font-size: clamp(1.6rem, 1.2rem + 1.8vw, 2.5rem);
  line-height: 1.6;
  margin-block: var(--sp-3);
}

.kh-article-head .kh-meta {
  justify-content: center;
}

.kh-article-hero {
  max-width: 52rem;
  margin: var(--sp-5) auto 0;
}

.kh-article-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: clamp(2rem, 5vw, 4rem);
  align-items: start;
  padding-top: var(--sp-5);
}

.kh-article-main {
  min-width: 0;
  max-width: 46rem;
  margin-inline: auto;
  width: 100%;
}

.kh-article-aside {
  position: sticky;
  top: 84px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

@media (max-width: 1023px) {
  .kh-article-layout {
    grid-template-columns: 1fr;
  }

  .kh-article-aside {
    position: static;
    order: 2;
    margin-top: var(--sp-5);
    padding-top: var(--sp-5);
    border-top: 1px solid var(--border-soft);
  }
}

@media (max-width: 640px) {
  .kh-article-head {
    padding-block-start: var(--sp-3);
  }

  .kh-container > .kh-breadcrumb + .kh-article-head {
    padding-block-start: var(--sp-2);
  }

  .kh-article-head__title {
    font-size: clamp(1.35rem, 1.05rem + 2.5vw, 1.85rem);
  }

  .kh-article-hero {
    margin-top: var(--sp-4);
  }

  .kh-article-layout {
    padding-top: var(--sp-4);
  }

  .kh-share {
    align-items: flex-start;
    gap: var(--sp-2);
  }

  .kh-toc:has(#khTocList:empty) {
    display: none;
  }
}

.kh-prose {
  font-size: 1.02rem;
  line-height: 2.15;
  color: var(--text);
  overflow-wrap: anywhere;
}

/* Neutralize legacy CKEditor inline styles in article bodies */
.kh-prose [style*="color"] {
  color: var(--text) !important;
}

.kh-prose [style*="background"] {
  background: transparent !important;
}

.kh-prose [style*="font-size"] {
  font-size: inherit !important;
}

.kh-prose [style*="width"]:not(img):not(svg):not(iframe):not(video) {
  width: auto !important;
  max-width: 100%;
}

.kh-prose figure {
  margin: 1.6em 0;
}

.kh-prose figure.image {
  margin-inline: 0;
}

.kh-prose figure.image img {
  width: 100%;
  height: auto;
}

.kh-prose h2,
.kh-prose h3 {
  text-wrap: balance;
}

.kh-prose > * + * {
  margin-top: 1.1em;
}

.kh-prose h2,
.kh-prose h3,
.kh-prose h4 {
  margin-top: 2em;
  line-height: 1.7;
}

.kh-prose h2 {
  font-size: 1.45rem;
  padding-inline-start: 0.85rem;
  border-inline-start: 3px solid var(--accent);
}

.kh-prose h3 {
  font-size: 1.2rem;
}

.kh-prose h4 {
  font-size: 1.05rem;
}

.kh-prose a {
  color: var(--series-b);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--series-b) 40%, transparent);
  text-underline-offset: 4px;
}

.kh-prose a:hover {
  text-decoration-color: var(--series-b);
}

.kh-prose img {
  border-radius: var(--radius);
  margin-inline: auto;
  border: 1px solid var(--border-soft);
}

.kh-prose blockquote {
  margin: 1.6em 0;
  padding: var(--sp-3) var(--sp-4);
  border-inline-start: 3px solid var(--series-b);
  background: var(--surface);
  border-radius: var(--radius-sm);
  color: var(--text-2);
}

.kh-prose ul,
.kh-prose ol {
  padding-inline-start: 1.4rem;
}

.kh-prose ul {
  list-style: disc;
}

.kh-prose ol {
  list-style: persian;
}

[dir='ltr'] .kh-prose ol {
  list-style: decimal;
}

.kh-prose li {
  margin-top: 0.4em;
}

.kh-prose li::marker {
  color: var(--accent);
}

.kh-prose pre {
  direction: ltr;
  text-align: left;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.8;
}

.kh-prose code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  direction: ltr;
  unicode-bidi: isolate;
}

.kh-prose pre code {
  background: none;
  padding: 0;
}

.kh-prose .kh-table-wrap,
.kh-prose .table-wrap {
  overflow-x: auto;
  margin-top: 1.1em;
}

.kh-prose table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  font-size: var(--fs-small);
  line-height: 1.8;
}

.kh-prose th,
.kh-prose td {
  border: 1px solid var(--border-soft);
  padding: 0.6rem 0.9rem;
  text-align: start;
}

.kh-prose th {
  background: var(--surface);
  font-weight: 600;
}

.kh-prose iframe,
.kh-prose video {
  max-width: 100%;
  border-radius: var(--radius);
}

.kh-prose hr {
  margin: 2em auto;
  width: 120px;
  border-top: 1px solid var(--border);
}

/* TOC */
.kh-toc {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.kh-toc summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--text-2);
}

.kh-toc summary::-webkit-details-marker {
  display: none;
}

.kh-toc summary .kh-icon {
  margin-inline-start: auto;
  transition: transform var(--dur-fast) var(--ease);
}

.kh-toc[open] summary .kh-icon {
  transform: rotate(180deg);
}

.kh-toc ol {
  padding: 0 var(--sp-4) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  counter-reset: toc;
}

.kh-toc li a {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.3rem 0;
  font-size: var(--fs-caption);
  color: var(--text-2);
  counter-increment: toc;
  transition: color var(--dur-fast) var(--ease);
}

.kh-toc li a::before {
  content: counter(toc, decimal-leading-zero);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  color: var(--text-3);
  direction: ltr;
}

.kh-toc li a:hover,
.kh-toc li a.is-active {
  color: var(--accent);
}

.kh-toc li[data-level='3'] a {
  padding-inline-start: 1.4rem;
}

/* share row */
.kh-share {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.kh-share__label {
  font-size: var(--fs-caption);
  color: var(--text-3);
  margin-inline-end: 0.4rem;
}

/* comments */
.kh-comments {
  margin-top: var(--sp-6);
  border-top: 1px solid var(--border-soft);
  padding-top: var(--sp-5);
}

.kh-comments__title {
  font-size: 1.35rem;
  line-height: 1.5;
}

.kh-comments__form-title {
  font-size: 1.1rem;
  line-height: 1.5;
  margin-top: var(--sp-5);
}

.kh-comment {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: var(--sp-4);
  margin-top: var(--sp-3);
  background: var(--surface);
}

.kh-comment__head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: var(--sp-2);
  font-size: var(--fs-caption);
  color: var(--text-3);
}

.kh-comment__author {
  font-weight: 600;
  color: var(--text);
  font-size: var(--fs-small);
}

.kh-comment p {
  color: var(--text-2);
  font-size: var(--fs-small);
  line-height: 2;
}

/* comment / django form paragraphs */
.kh-form-django p {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 0 0 var(--sp-4);
}

.kh-form-django label {
  font-size: var(--fs-caption);
  font-weight: 600;
  color: var(--text-2);
}

.kh-form-django input,
.kh-form-django textarea {
  width: 100%;
  min-height: 48px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  font: inherit;
  line-height: 1.7;
}

.kh-form-django textarea {
  min-height: 130px;
  resize: vertical;
}

.kh-form-django input:focus,
.kh-form-django textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.kh-form-django .helptext,
.kh-form-django .errorlist {
  font-size: var(--fs-caption);
  color: var(--text-3);
}

.kh-form-django .errorlist {
  color: var(--neg);
}

/* related list (aside) */
.kh-mini-list {
  display: flex;
  flex-direction: column;
}

.kh-mini-list a {
  display: block;
  padding-block: var(--sp-3);
  border-top: 1px solid var(--border-soft);
  font-size: var(--fs-small);
  font-weight: 500;
  line-height: 1.9;
  color: var(--text-2);
  transition: color var(--dur-fast) var(--ease);
}

.kh-mini-list a:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.kh-mini-list a:hover {
  color: var(--accent);
}

.kh-aside-title {
  font-size: var(--fs-caption);
  font-weight: 600;
  color: var(--text-3);
  margin-bottom: var(--sp-2);
}

/* breadcrumb */
.kh-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-top: var(--sp-4);
  font-size: var(--fs-caption);
  color: var(--text-3);
}

.kh-breadcrumb a:hover {
  color: var(--accent);
}

.kh-breadcrumb__sep {
  opacity: 0.5;
}

.kh-breadcrumb .is-current {
  color: var(--text-2);
  max-width: min(100%, 28rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* featured split layout on list pages */
.kh-feature-split {
  display: grid;
  grid-template-columns: minmax(0, 6fr) minmax(0, 5fr);
  gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: center;
  padding-bottom: var(--sp-5);
  border-bottom: 1px solid var(--border-soft);
}

.kh-feature-split .kh-thumb {
  margin-bottom: 0;
}

@media (max-width: 899px) {
  .kh-feature-split {
    grid-template-columns: 1fr;
  }
}

/* publications accordion */
.kh-pubs {
  display: flex;
  flex-direction: column;
}

.kh-pub {
  border-top: 1px solid var(--border-soft);
}

.kh-pub:last-child {
  border-bottom: 1px solid var(--border-soft);
}

.kh-pub summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-1);
  transition: color var(--dur-fast) var(--ease);
}

.kh-pub summary::-webkit-details-marker {
  display: none;
}

.kh-pub summary:hover {
  color: var(--accent);
}

.kh-pub__index {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.1em;
  color: var(--accent);
  flex: none;
}

.kh-pub__title {
  flex: 1;
  font-weight: 600;
  font-size: var(--fs-small);
  line-height: 1.9;
}

.kh-pub summary .kh-icon {
  align-self: center;
  flex: none;
  color: var(--text-3);
  transition: transform var(--dur-fast) var(--ease);
}

.kh-pub[open] summary .kh-icon {
  transform: rotate(180deg);
}

.kh-pub__body {
  padding: 0 var(--sp-1) var(--sp-4) calc(var(--sp-3) + 1.4rem);
  color: var(--text-2);
  font-size: var(--fs-small);
  line-height: 2;
}

.kh-pub[dir='ltr'] .kh-pub__body {
  padding: 0 calc(var(--sp-3) + 1.4rem) var(--sp-4) var(--sp-1);
  padding-left: calc(var(--sp-3) + 1.4rem);
  padding-right: var(--sp-1);
}

.kh-pub__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
  margin-top: var(--sp-3);
}

/* CTA band */
.kh-cta-band {
  text-align: center;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--bg-2);
  padding: var(--sp-6) var(--sp-4);
}

.kh-cta-band p {
  max-width: 34rem;
  margin-inline: auto;
  margin-top: var(--sp-2);
}

/* status pages (sent / errors) */
.kh-status-page {
  max-width: 34rem;
  margin-inline: auto;
  text-align: center;
  padding-block: clamp(4rem, 12vh, 8rem);
}

.kh-status-page__spark {
  width: 150px;
  height: 55px;
  margin: 0 auto var(--sp-4);
  display: block;
}

.kh-status-page .kh-btn {
  margin-inline: 0.3rem;
  margin-top: 0.5rem;
}

/* audio block in article */
.kh-voice {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
  padding: var(--sp-3) var(--sp-4);
}

.kh-voice audio {
  display: block;
  width: 100%;
  margin-top: var(--sp-2);
}

/* --------------------------------------------------------------------------
   20. Pagination
   -------------------------------------------------------------------------- */
.kh-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  margin-top: var(--sp-6);
}

.kh-pagination a,
.kh-pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 42px;
  padding-inline: 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  font-family: var(--font-mono);
  font-size: var(--fs-caption);
  color: var(--text-2);
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.kh-pagination a:hover {
  color: var(--text);
  border-color: var(--text-3);
}

.kh-pagination .is-current {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

.kh-pagination .kh-ellipsis {
  border: 0;
  min-width: auto;
}

/* --------------------------------------------------------------------------
   21. Empty / status states
   -------------------------------------------------------------------------- */
.kh-empty {
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-2);
}

.kh-empty svg {
  width: 120px;
  height: 44px;
  margin: 0 auto var(--sp-3);
  display: block;
  opacity: 0.6;
}

.kh-empty__title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--sp-1);
}

.kh-empty p {
  font-size: var(--fs-small);
}

/* --------------------------------------------------------------------------
   22. Reveal on scroll
   -------------------------------------------------------------------------- */
[data-reveal] {
  opacity: 0;
  translate: 0 14px;
  transition: opacity var(--dur-slow) var(--ease), translate var(--dur-slow) var(--ease);
}

[data-reveal].is-visible {
  opacity: 1;
  translate: 0 0;
}

@media (prefers-reduced-motion: reduce) {
  [data-reveal] {
    opacity: 1;
    translate: 0 0;
  }
}

/* --------------------------------------------------------------------------
   23. Small-screen typography adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  :root {
    --section-gap: clamp(3rem, 8vw, 4.5rem);
  }

  .kh-kicker {
    font-size: 0.625rem;
    letter-spacing: 0.13em;
  }

  .kh-brand__tag {
    font-size: 0.53rem;
    letter-spacing: 0.16em;
  }

  .kh-header__inner {
    gap: var(--sp-3);
  }

  .kh-page-head {
    padding-block: clamp(1.75rem, 5vw, 2.75rem) var(--sp-4);
    margin-bottom: var(--sp-4);
  }

  .kh-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
  }

  .kh-search {
    min-width: 0;
    max-width: none;
    width: 100%;
  }

  .kh-filter-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-inline: calc(-1 * var(--gutter));
    padding-inline: var(--gutter);
    padding-block-end: 0.15rem;
  }

  .kh-filter-chips::-webkit-scrollbar {
    display: none;
  }

  .kh-chip {
    flex-shrink: 0;
  }

  .kh-card-grid {
    grid-template-columns: 1fr;
    gap: var(--sp-4);
  }

  .kh-pagination {
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .kh-pagination a,
  .kh-pagination span {
    min-width: 40px;
    height: 40px;
  }

  .kh-clients__tile {
    min-width: 0;
    flex: 1 1 calc(50% - 0.5rem);
    max-width: calc(50% - 0.5rem);
  }

  .kh-role-chip {
    font-size: 0.75rem;
    padding: 0.22rem 0.65rem;
  }

  .kh-about-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .kh-about-actions .kh-btn {
    width: 100%;
  }

  .kh-feature-split {
    gap: var(--sp-4);
    padding-bottom: var(--sp-4);
  }
}

@media (max-width: 480px) {
  .kh-brand__tag {
    display: none;
  }

  .kh-brand__name {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .kh-hero__ctas {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-2);
  }

  .kh-hero__ctas .kh-btn {
    min-height: 44px;
    padding-inline: 0.85rem;
    font-size: 0.8125rem;
  }

  .kh-hero__kicker::after {
    display: none;
  }

  .kh-section-head {
    flex-wrap: wrap;
    row-gap: 0.4rem;
  }

  .kh-section-head__title {
    white-space: normal;
  }

  .kh-section-head__more {
    margin-inline-start: auto;
  }
}

/* --------------------------------------------------------------------------
   24. Utilities
   -------------------------------------------------------------------------- */
.kh-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.kh-text-2 { color: var(--text-2); }
.kh-text-3 { color: var(--text-3); }
.kh-mt-2 { margin-top: var(--sp-2); }
.kh-mt-3 { margin-top: var(--sp-3); }
.kh-mt-4 { margin-top: var(--sp-4); }
.kh-mt-5 { margin-top: var(--sp-5); }
.kh-ltr { direction: ltr; unicode-bidi: isolate; text-align: start; }

/* --------------------------------------------------------------------------
   25. kh2 integration bridge (Phase 3)
   Legacy pages load main.css inside .legacy-ui; kh.css owns the shell.
   -------------------------------------------------------------------------- */
.kh-lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  margin: 0;
}

.kh-lang-switch .kh-lang-link.is-active {
  color: var(--accent);
  border-color: var(--border);
}

.kh-footer__social {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  margin-top: var(--sp-3);
  font-size: var(--fs-small);
}

.kh-footer__social a {
  color: var(--text-2);
}

.kh-footer__social a:hover {
  color: var(--accent);
}

.kh-footer__disclaimer {
  margin: var(--sp-4) 0 0;
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border-soft);
  font-size: var(--fs-small);
  color: var(--text-3);
  line-height: 1.8;
}

.kh-footer__meta-links {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
}

.kh-footer__enamad {
  margin-top: var(--sp-4);
}

/* Restore main.css tokens inside legacy content (kh shell overrides :root --bg/--text/--border). */
html[data-theme='light'] body.legacy-ui :is(main, .demo-banner),
html[data-theme='dark'] body.legacy-ui :is(main, .demo-banner) {
  --font-fa: 'Vazirmatn', 'Vazirmatn Static', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-en: 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-num: 'Vazirmatn', ui-monospace, 'SF Mono', 'IBM Plex Mono', monospace;
  --fs-base: 0.9375rem;
  --lh-body: 1.85;
  --lh-tight: 1.25;
  --radius-sm: 3px;
  --radius: 5px;
  --radius-lg: 8px;
}

html[data-theme='light'] body.legacy-ui :is(main, .demo-banner) {
  --bg: #FCFBF8;
  --bg-raised: #FFFFFF;
  --bg-sunken: #F4F2EC;
  --bg-card: #FFFFFF;
  --bg-card-hover: #FAF8F4;
  --border: rgba(35, 31, 24, 0.11);
  --border-strong: rgba(35, 31, 24, 0.22);
  --text: #1A1712;
  --text-muted: #575146;
  --text-dim: #857E71;
  --brand: #B4552D;
  --brand-bright: #C9663C;
  --brand-deep: #8E3F1F;
  --brand-wash: rgba(180, 85, 45, 0.08);
  --brand-line: rgba(180, 85, 45, 0.30);
  --positive: #33684E;
  --positive-wash: rgba(51, 104, 78, 0.10);
  --negative: #A0432F;
  --negative-wash: rgba(160, 67, 47, 0.10);
  --neutral: #857E71;
  --neutral-wash: rgba(133, 126, 113, 0.10);
  --warn: #8A6A12;
  --warn-wash: rgba(138, 106, 18, 0.10);
  --demo: #6B5AA6;
  --demo-wash: rgba(107, 90, 166, 0.10);
}

html[data-theme='dark'] body.legacy-ui :is(main, .demo-banner) {
  --bg: #14120F;
  --bg-raised: #1C1A16;
  --bg-sunken: #100E0C;
  --bg-card: #1C1A16;
  --bg-card-hover: #242119;
  --border: rgba(222, 217, 207, 0.12);
  --border-strong: rgba(222, 217, 207, 0.24);
  --text: #EDEAE3;
  --text-muted: #B0AAA0;
  --text-dim: #857E71;
  --brand: #DD7B50;
  --brand-bright: #EC9068;
  --brand-deep: #B4552D;
  --brand-wash: rgba(221, 123, 80, 0.12);
  --brand-line: rgba(221, 123, 80, 0.32);
  --positive: #7FB398;
  --positive-wash: rgba(127, 179, 152, 0.13);
  --negative: #DD8A76;
  --negative-wash: rgba(221, 138, 118, 0.13);
  --neutral: #948D80;
  --neutral-wash: rgba(148, 141, 128, 0.13);
  --warn: #C6A24A;
  --warn-wash: rgba(198, 162, 74, 0.13);
  --demo: #A392D8;
  --demo-wash: rgba(163, 146, 216, 0.14);
}

body.legacy-ui main {
  font-family: var(--font-fa);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  color: var(--text);
  max-width: 100%;
  overflow-x: clip;
}

html[lang='en'] body.legacy-ui main {
  font-family: var(--font-en);
  line-height: 1.7;
}

body.legacy-ui .demo-banner {
  font-family: var(--font-fa);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
}

html[lang='en'] body.legacy-ui .demo-banner {
  font-family: var(--font-en);
  line-height: 1.7;
}

body.legacy-ui .kh-footer {
  margin-top: clamp(3rem, 7vw, 5.5rem);
}

body.legacy-ui main :is(table, pre, svg, canvas, .frame-block) {
  max-width: 100%;
}

.legacy-ui :is(article, .note-item, .insight-card, .finding) :is(ul, ol) {
  list-style: revert;
  padding-inline-start: 1.35em;
}

/* --------------------------------------------------------------------------
   Phase 4 — About narrative, form bridge, pagination helpers
   -------------------------------------------------------------------------- */
.kh-about__quote {
  font-size: var(--fs-lead);
  line-height: 1.85;
  color: var(--text-2);
  border-inline-start: 3px solid var(--accent);
  padding-inline-start: var(--sp-4);
  margin: 0;
}

.kh-about-narrative__body {
  max-width: 42rem;
}

.kh-chapter {
  padding-block: var(--sp-5);
  border-block-start: 1px solid var(--border-soft);
}

.kh-chapter:first-child {
  border-block-start: 0;
  padding-block-start: 0;
}

.kh-chapter__no {
  font-size: var(--fs-caption);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: var(--sp-2);
}

.kh-chapter__title {
  font-size: clamp(1.15rem, 2.5vw, 1.45rem);
  margin-bottom: var(--sp-3);
}

.kh-chapter__body p {
  margin: 0;
}

.kh-beliefs {
  list-style: none;
  padding: 0;
  margin: var(--sp-4) 0 0;
  display: grid;
  gap: var(--sp-4);
}

.kh-beliefs li {
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-weight: 600;
}

.kh-beliefs li span {
  display: block;
  margin-top: 0.35rem;
  font-weight: 400;
  color: var(--text-2);
  font-size: var(--fs-small);
}

.kh-about-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
}

.kh-chip--inline {
  text-decoration: none;
}

.kh-chip__count {
  opacity: 0.65;
  font-size: 0.9em;
}

.kh-form .field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-bottom: var(--sp-4);
}

.kh-form .field__label {
  font-size: var(--fs-caption);
  font-weight: 600;
  color: var(--text-2);
}

.kh-form .field__input {
  width: 100%;
  min-height: 48px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 1rem;
  font: inherit;
  line-height: 1.7;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.kh-form textarea.field__input {
  min-height: 8rem;
  resize: vertical;
}

.kh-form .field__input:focus {
  outline: none;
  border-color: var(--accent);
}

.kh-form .field__error {
  color: var(--danger, #c0392b);
  font-size: var(--fs-caption);
}

.field--honeypot {
  position: absolute;
  inset-inline-start: -9999px;
  opacity: 0;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Redesigned public pages — base.html shell without main.css
   -------------------------------------------------------------------------- */
body:not(.legacy-ui) .demo-banner {
  background: color-mix(in srgb, var(--series-b) 12%, var(--bg));
  border-block-end: 1px solid var(--border-soft);
  color: var(--series-b);
  font-size: var(--fs-caption);
  font-weight: 500;
  line-height: 1.75;
  padding-block: var(--sp-2);
}

body:not(.legacy-ui) .demo-banner strong {
  font-weight: 700;
}

body:not(.legacy-ui) .demo-banner .wrap,
body:not(.legacy-ui) main > .wrap {
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

body:not(.legacy-ui) .breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  font-size: var(--fs-caption);
  color: var(--text-3);
  padding-block: var(--sp-3);
}

body:not(.legacy-ui) .breadcrumbs a:hover {
  color: var(--accent);
}

body:not(.legacy-ui) .breadcrumbs__sep {
  opacity: 0.45;
}

body:not(.legacy-ui) .message-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

body:not(.legacy-ui) .message-list li {
  border: 1px solid var(--border-soft);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: var(--sp-3) var(--sp-4);
  margin-block-end: var(--sp-3);
  font-size: var(--fs-small);
}

body:not(.legacy-ui) .message-list .success {
  border-inline-start-color: var(--pos);
}

body:not(.legacy-ui) .message-list .error,
body:not(.legacy-ui) .message-list .danger {
  border-inline-start-color: var(--neg);
}

@media (max-width: 560px) {
  body:not(.legacy-ui) .demo-banner {
    font-size: 0.6875rem;
    line-height: 1.6;
  }

  body:not(.legacy-ui) .demo-banner .demo-banner__long {
    display: none;
  }
}

