/* ============================================================
   Beyond Good or Bad — earthy gold/terracotta coaching aesthetic
   ============================================================ */

:root,
[data-theme="light"] {
  /* Surfaces — coaching portal paper / cream */
  --color-bg: #FAFAF6;
  --color-surface: #FFFFFF;
  --color-surface-2: #FFFFFF;
  --color-surface-offset: #F5F4ED;
  --color-divider: #E9E7DE;
  --color-border: #E9E7DE;

  /* Text — portal ink */
  --color-text: #1A1A17;
  --color-text-muted: #4A4A42;
  --color-text-faint: #8C8C82;
  --color-text-inverse: #FFFFFF;

  /* Accents — portal gold + turquoise */
  --color-primary: #C79A1F;       /* portal gold */
  --color-primary-hover: #8A6A10;
  --color-primary-soft: #FBF3DD;
  --color-gold: #8A6A10;          /* deep gold */
  --color-gold-soft: #FBF3DD;
  --color-river: #1F8A8A;         /* portal turquoise for "river" notes */
  --color-river-soft: #E4F2F2;

  /* sidebar tints */
  --tint-science: #E4F2F2;        /* science = turquoise */
  --tint-science-bd: #A8DDDD;
  --tint-exercise: #FBF3DD;       /* exercise = gold */
  --tint-exercise-bd: #F0DCA0;
  --tint-practice: #FBF3DD;       /* practice = gold */
  --tint-practice-bd: #F0DCA0;
  --tint-quote: #F5F4ED;

  --shadow-sm: 0 1px 3px rgba(60, 40, 15, 0.07);
  --shadow-md: 0 8px 28px rgba(60, 40, 15, 0.10);
  --shadow-lg: 0 22px 60px rgba(60, 40, 15, 0.16);

  --radius-sm: 0.4rem;
  --radius-md: 0.7rem;
  --radius-lg: 1.1rem;
  --radius-xl: 1.6rem;
  --radius-full: 9999px;

  --transition-interactive: 200ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Type scale */
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.85rem);
  --text-sm: clamp(0.875rem, 0.82rem + 0.3vw, 0.98rem);
  --text-base: clamp(1.1rem, 1rem + 0.45vw, 1.3rem);
  --text-lg: clamp(1.2rem, 1.05rem + 0.7vw, 1.5rem);
  --text-xl: clamp(1.6rem, 1.2rem + 1.4vw, 2.4rem);
  --text-2xl: clamp(2.1rem, 1.4rem + 3vw, 3.6rem);
  --text-hero: clamp(2.8rem, 1.6rem + 5.5vw, 6rem);

  /* spacing */
  --space-1: 0.25rem;  --space-2: 0.5rem;  --space-3: 0.75rem;
  --space-4: 1rem;     --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem;     --space-10: 2.5rem; --space-12: 3rem;
  --space-16: 4rem;    --space-20: 5rem;   --space-24: 6rem;
  --space-32: 8rem;

  --content-narrow: 1100px;
  --content-default: 1360px;

  /* Fonts — match the coaching portal (Fraunces display + Geist body) */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Geist', 'Inter Tight', system-ui, sans-serif;
  --font-fa-display: 'Vazirmatn', 'Tahoma', sans-serif;
  --font-fa-body: 'Vazirmatn', 'Tahoma', sans-serif;
}

[data-theme="dark"] {
  --color-bg: #1a1611;
  --color-surface: #211c15;
  --color-surface-2: #272118;
  --color-surface-offset: #2c2519;
  --color-divider: #3a3122;
  --color-border: #453a28;
  --color-text: #ece3d2;
  --color-text-muted: #b3a589;
  --color-text-faint: #7d7159;
  --color-text-inverse: #1a1611;
  --color-primary: #E0B45A;
  --color-primary-hover: #ECC677;
  --color-primary-soft: #2c2417;
  --color-gold: #E0B45A;
  --color-gold-soft: #2c241744;
  --color-river: #5FB3AE;
  --color-river-soft: #1f302e;
  --tint-science: #1f2a27;
  --tint-science-bd: #3c534d;
  --tint-exercise: #2c2417;
  --tint-exercise-bd: #5a4827;
  --tint-practice: #2f2218;
  --tint-practice-bd: #6a4429;
  --tint-quote: #2a2316;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 22px 60px rgba(0, 0, 0, 0.6);
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  -webkit-text-size-adjust: none; text-size-adjust: none;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility; scroll-behavior: smooth;
  scroll-padding-top: var(--space-16);
}
body {
  min-height: 100dvh; line-height: 1.72;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background-color: var(--color-bg);
  transition: background-color 300ms ease, color 300ms ease;
}
img, picture, svg { display: block; max-width: 100%; height: auto; }
button { cursor: pointer; background: none; border: none; color: inherit; font: inherit; }
a { color: var(--color-primary); text-decoration-thickness: 1px; text-underline-offset: 3px; }
h1,h2,h3,h4 { text-wrap: balance; line-height: 1.18; font-family: var(--font-display); font-weight: 600; }
p { text-wrap: pretty; }
::selection { background: var(--color-gold-soft); color: var(--color-text); }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 3px; border-radius: var(--radius-sm); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- paper grain background ---------- */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  opacity: .5; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.045'/%3E%3C/svg%3E");
}
[data-theme="dark"] body::before { mix-blend-mode: screen; opacity: .35; }

/* =========================================================
   Header / nav
   ========================================================= */
.site-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) clamp(var(--space-4), 4vw, var(--space-12));
  background: color-mix(in oklab, var(--color-bg) 86%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-divider);
}
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand svg { width: 34px; height: 34px; color: var(--color-primary); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: var(--text-sm); letter-spacing: .02em; }
.brand-sub { font-size: var(--text-xs); color: var(--color-text-muted); letter-spacing: .14em; text-transform: uppercase; }
[dir="rtl"] .brand-sub { letter-spacing: 0; text-transform: none; }

.header-controls { display: flex; align-items: center; gap: var(--space-2); }

.lang-toggle {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px; border-radius: var(--radius-full);
  background: var(--color-surface-offset); border: 1px solid var(--color-border);
}
.lang-toggle button {
  padding: var(--space-1) var(--space-4); border-radius: var(--radius-full);
  font-size: var(--text-sm); font-weight: 500; color: var(--color-text-muted);
  transition: var(--transition-interactive);
}
.lang-toggle button[aria-pressed="true"] {
  background: var(--color-primary); color: #fff7ee; box-shadow: var(--shadow-sm);
}
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border-radius: var(--radius-full); border: 1px solid var(--color-border);
  background: var(--color-surface-offset); color: var(--color-text-muted);
  transition: var(--transition-interactive);
}
.icon-btn:hover { color: var(--color-primary); border-color: var(--color-primary); }

/* =========================================================
   Hero
   ========================================================= */
.hero { position: relative; z-index: 1; overflow: hidden; }
.hero-figure { position: relative; width: 100%; }
.hero-figure img {
  width: 100%; height: clamp(380px, 64vh, 760px); object-fit: cover; object-position: center 38%;
}
.hero-figure::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom,
     color-mix(in oklab, var(--color-bg) 30%, transparent) 0%,
     transparent 30%,
     transparent 55%,
     color-mix(in oklab, var(--color-bg) 92%, transparent) 100%);
}
.hero-overlay {
  position: absolute; inset-inline: 0; bottom: clamp(var(--space-6), 6vh, var(--space-20));
  z-index: 2; text-align: center;
  padding-inline: var(--space-6);
}
.hero-kicker {
  display: inline-block; font-size: var(--text-sm); letter-spacing: .22em;
  text-transform: uppercase; color: var(--color-primary); font-weight: 600;
  margin-bottom: var(--space-4);
  padding: var(--space-1) var(--space-4); border-radius: var(--radius-full);
  background: color-mix(in oklab, var(--color-surface) 75%, transparent);
  backdrop-filter: blur(6px);
}
[dir="rtl"] .hero-kicker { letter-spacing: 0; text-transform: none; }
.hero-title {
  font-size: var(--text-hero); font-weight: 600; line-height: 1.02;
  color: var(--color-text);
  text-shadow: 0 2px 24px color-mix(in oklab, var(--color-bg) 80%, transparent);
}
.hero-sub {
  margin: var(--space-5) auto 0; max-width: 30ch;
  font-family: var(--font-display); font-style: italic;
  font-size: var(--text-lg); color: var(--color-text-muted);
}
[dir="rtl"] .hero-sub { font-style: normal; }

/* =========================================================
   Article layout
   ========================================================= */
.article { position: relative; z-index: 1; }
.wrap { width: min(var(--content-default), 92vw); margin-inline: auto; }
.measure { width: min(var(--content-narrow), 90vw); margin-inline: auto; }

section.part { padding-block: clamp(var(--space-16), 8vw, var(--space-32)); }
section.part + section.part { border-top: 1px solid var(--color-divider); }

/* lede / opening */
.lede > div[lang] > p:first-of-type::first-letter {
  float: inline-start; font-family: var(--font-display); font-weight: 600;
  font-size: 3.6em; line-height: .82; padding-inline-end: .08em; padding-top: .04em;
  color: var(--color-primary);
}
[dir="rtl"] .lede > div[lang] > p:first-of-type::first-letter { float: none; font-size: 1em; padding: 0; color: inherit; }

.part-eyebrow {
  display: flex; align-items: center; gap: var(--space-3);
  font-size: var(--text-sm); font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--color-primary);
  margin-bottom: var(--space-4);
}
[dir="rtl"] .part-eyebrow { letter-spacing: 0; text-transform: none; }
.part-eyebrow::before { content: ""; width: 30px; height: 2px; background: var(--color-primary); flex: none; }

h2.part-title { font-size: var(--text-xl); margin-bottom: var(--space-6); color: var(--color-text); }
h3.lab-practice { font-size: var(--text-lg); margin-top: var(--space-8); margin-bottom: var(--space-2); color: var(--color-text); }

.prose > p { margin-bottom: var(--space-5); }
.prose em { color: var(--color-primary); font-style: italic; }
[dir="rtl"] .prose em { font-style: normal; font-weight: 700; color: var(--color-primary); }
.prose strong { font-weight: 700; color: var(--color-text); }

/* =========================================================
   Figures (section illustrations)
   ========================================================= */
figure.illus { margin-block: clamp(var(--space-10), 5vw, var(--space-16)); }
figure.illus img {
  width: 100%; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); border: 1px solid var(--color-border);
}
figure.illus.portrait img {
  max-width: 460px; margin-inline: auto;
}
figure.illus figcaption {
  margin-top: var(--space-3); text-align: center;
  font-size: var(--text-xs); color: var(--color-text-faint);
  font-family: var(--font-display); font-style: italic;
}
[dir="rtl"] figure.illus figcaption { font-style: normal; }

/* float illustration alongside text on wide screens (portraits) */
@media (min-width: 1000px) {
  figure.illus.float-end {
    float: inline-end; width: 360px; margin-inline-start: var(--space-10);
    margin-top: var(--space-1); margin-bottom: var(--space-6);
  }
  .prose::after { content: ""; display: block; clear: both; }
}

/* =========================================================
   Callout boxes — science / exercise / practice / how-to
   ========================================================= */
.callout {
  /* Keep the card's background and border outside adjacent floated artwork. */
  display: flow-root;
  margin-block: var(--space-8);
  padding: var(--space-6) var(--space-6) var(--space-6);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  position: relative;
  box-shadow: var(--shadow-sm);
}
.callout .c-label {
  display: flex; align-items: center; gap: var(--space-2);
  font-family: var(--font-display); font-weight: 600;
  font-size: var(--text-base); margin-bottom: var(--space-2);
}
.callout .c-emoji { font-size: 1.15em; line-height: 1; }
.callout p { margin: 0; font-size: var(--text-sm); line-height: 1.66; }
.callout p + p { margin-top: var(--space-3); }

.callout.science { background: var(--tint-science); border-color: var(--tint-science-bd); }
.callout.science .c-label { color: var(--color-river); }
[data-theme="dark"] .callout.science .c-label { color: var(--color-river); }

.callout.exercise { background: var(--tint-exercise); border-color: var(--tint-exercise-bd); }
.callout.exercise .c-label { color: var(--color-gold); }

.callout.practice { background: var(--tint-practice); border-color: var(--tint-practice-bd); }
.callout.practice .c-label { color: var(--color-primary); }

.callout.howto {
  background: var(--color-surface-2); border-style: dashed;
}
.callout.howto .c-label { color: var(--color-text); }

/* edge accent bar */
.callout::before {
  content: ""; position: absolute; inset-block: 0; inset-inline-start: 0;
  width: 4px; border-radius: var(--radius-full) 0 0 var(--radius-full);
}
[dir="rtl"] .callout::before { border-radius: 0 var(--radius-full) var(--radius-full) 0; }
.callout.science::before { background: var(--color-river); }
.callout.exercise::before { background: var(--color-gold); }
.callout.practice::before { background: var(--color-primary); }
.callout.howto::before { background: var(--color-text-faint); }

/* =========================================================
   Life Lab practices list
   ========================================================= */
.lab-intro { margin-bottom: var(--space-6); }
.practices { display: grid; gap: var(--space-5); margin-top: var(--space-8); }
.practice-card {
  display: grid; grid-template-columns: auto 1fr; gap: var(--space-4) var(--space-5);
  align-items: start;
  padding: var(--space-5) var(--space-6);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
}
.practice-num {
  display: grid; place-items: center; width: 44px; height: 44px; flex: none;
  border-radius: var(--radius-full);
  background: var(--color-primary-soft); color: var(--color-primary);
  font-family: var(--font-display); font-weight: 600; font-size: var(--text-lg);
}
.practice-card h4 { font-family: var(--font-display); font-size: var(--text-lg); margin-bottom: var(--space-1); color: var(--color-text); }
.practice-card p { font-size: var(--text-sm); margin: 0; color: var(--color-text-muted); }

/* =========================================================
   Quote (Rumi)
   ========================================================= */
.rumi {
  margin-block: var(--space-12);
  padding: clamp(var(--space-8), 5vw, var(--space-16));
  background: var(--tint-quote); border-radius: var(--radius-lg);
  text-align: center; position: relative; overflow: hidden;
  border: 1px solid var(--color-border);
}
.rumi blockquote {
  font-family: var(--font-display); font-style: italic;
  font-size: var(--text-lg); line-height: 1.9; color: var(--color-text);
  max-width: 34ch; margin-inline: auto;
}
[dir="rtl"] .rumi blockquote { font-style: normal; font-size: var(--text-xl); line-height: 2.1; }
.rumi cite {
  display: block; margin-top: var(--space-5); font-style: normal;
  font-size: var(--text-sm); letter-spacing: .15em; text-transform: uppercase;
  color: var(--color-primary); font-family: var(--font-body); font-weight: 600;
}
[dir="rtl"] .rumi cite { letter-spacing: 0; text-transform: none; }
.rumi .closing-line {
  margin-top: var(--space-8); font-family: var(--font-display);
  font-size: var(--text-lg); color: var(--color-primary);
}

/* =========================================================
   Sources / footer
   ========================================================= */
.sources { background: var(--color-surface); border-top: 1px solid var(--color-divider); }
.sources h3 { font-family: var(--font-display); font-size: var(--text-lg); margin-bottom: var(--space-4); color: var(--color-text); }
.sources p.intro { font-size: var(--text-sm); color: var(--color-text-muted); margin-bottom: var(--space-5); }
.sources ul { list-style: none; display: grid; gap: var(--space-3); }
.sources li { font-size: var(--text-sm); color: var(--color-text-muted); padding-inline-start: var(--space-4); position: relative; }
.sources li::before { content: "—"; position: absolute; inset-inline-start: 0; color: var(--color-primary); }
[dir="rtl"] .sources li { padding-inline-start: 0; padding-inline-end: var(--space-4); }

.site-footer {
  text-align: center; padding: var(--space-12) var(--space-6);
  font-size: var(--text-sm); color: var(--color-text-faint);
  border-top: 1px solid var(--color-divider);
}
.site-footer .footmark { font-family: var(--font-display); color: var(--color-text-muted); font-size: var(--text-base); margin-bottom: var(--space-2); }

/* =========================================================
   Reading progress bar
   ========================================================= */
.progress {
  position: fixed; top: 0; inset-inline-start: 0; height: 3px; z-index: 60;
  width: 0%; background: linear-gradient(90deg, var(--color-gold), var(--color-primary));
  transition: width 80ms linear;
}

/* =========================================================
   Language visibility
   ========================================================= */
[data-lang="en"] [lang="fa"] { display: none; }
[data-lang="fa"] [lang="en"] { display: none; }

/* RTL font application */
[dir="rtl"] body, [dir="rtl"] .prose, [dir="rtl"] .callout, [dir="rtl"] .practice-card,
[dir="rtl"] .hero-sub, [dir="rtl"] .sources, [dir="rtl"] .brand-name {
  font-family: var(--font-fa-body);
}
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3, [dir="rtl"] h4,
[dir="rtl"] .hero-title, [dir="rtl"] .rumi blockquote {
  font-family: var(--font-fa-display); font-weight: 700;
}
[dir="rtl"] { line-height: 1.95; }
[dir="rtl"] .prose > p { margin-bottom: var(--space-6); }

/* reveal on scroll */
.reveal { opacity: 0; transform: translateY(22px); transition: opacity .7s ease, transform .7s cubic-bezier(.16,1,.3,1); }
.reveal.in { opacity: 1; transform: none; }

@media (max-width: 560px) {
  .brand-sub { display: none; }
  .hero-figure img { object-position: center 42%; }
}
