@font-face {
  font-family: Vazirmatn;
  src: url("fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: Vazirmatn;
  src: url("fonts/Vazirmatn-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: Vazirmatn;
  src: url("fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --indigo: #1f1b4d;
  --indigo-mid: #2c2768;
  --indigo-2: #3d348b;
  --teal: #0f9d76;
  --teal-dk: #0b7a5c;
  --coral: #e4572e;
  --gold: #c9a227;
  --bg: #f4efe4;
  --paper: #fffdf8;
  --ink: #1c1814;
  --muted: #5a554c;
  --line: #e4ddd0;
  --shadow: 0 12px 32px rgba(31, 27, 77, 0.08);
  --radius: 18px;
  --header-h: 4.25rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12101a;
    --paper: #1b1826;
    --ink: #f4efe4;
    --muted: #b7b0a4;
    --line: #2c2940;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    --indigo: #16132e;
    --indigo-mid: #221e48;
  }
}

*,
*::before,
*::after { box-sizing: border-box; }

html {
  font-size: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Vazirmatn, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 2;
  min-height: 100vh;
}

img, video { max-width: 100%; height: auto; }

a {
  color: var(--indigo-2);
  text-underline-offset: 0.18em;
}
a:hover { color: var(--teal-dk); }

:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 3px;
}

.skip {
  position: absolute;
  right: 1rem;
  top: -4rem;
  background: var(--teal);
  color: #fff;
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  z-index: 100;
}
.skip:focus { top: 0.6rem; }

/* Header with candlestick / grid motif */
.site-header {
  background-color: var(--indigo);
  background-image:
    linear-gradient(180deg, rgba(31, 27, 77, 0.2), rgba(31, 27, 77, 0.55)),
    repeating-linear-gradient(90deg, transparent 0 22px, rgba(255,255,255,0.035) 22px 23px),
    repeating-linear-gradient(0deg, transparent 0 18px, rgba(255,255,255,0.03) 18px 19px);
  color: #f7f3ea;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 8px 24px rgba(15, 12, 40, 0.28);
}

.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0.7rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.2rem;
}
.brand svg { width: 36px; height: 36px; flex: none; }
.brand small {
  display: block;
  font-weight: 400;
  font-size: 0.72rem;
  opacity: 0.75;
  line-height: 1.4;
}

.nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  border-radius: 10px;
  padding: 0.35rem 0.7rem;
  font-family: inherit;
  font-size: 0.9rem;
}

.site-nav ul {
  display: flex;
  gap: 0.2rem 1.1rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-nav a {
  color: #efeae0;
  text-decoration: none;
  font-weight: 500;
  padding: 0.2rem 0;
  border-bottom: 2px solid transparent;
}
.site-nav a:hover,
.site-nav a[aria-current="page"] {
  border-bottom-color: var(--teal);
  color: #fff;
}

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.5rem 1.2rem 3rem;
}

/* Hero */
.hero {
  background-color: var(--indigo);
  color: #f7f3ea;
  position: relative;
  overflow: hidden;
  padding: 3.2rem 1.2rem 3.6rem;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(90deg, transparent 0 28px, rgba(255,255,255,0.04) 28px 29px),
    repeating-linear-gradient(0deg, transparent 0 22px, rgba(255,255,255,0.035) 22px 23px);
  pointer-events: none;
}
.hero::after {
  /* CSS candlesticks along the bottom */
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 88px;
  background:
    linear-gradient(#0f9d76, #0f9d76) 8% 40% / 8px 38px no-repeat,
    linear-gradient(#0f9d76, #0f9d76) 8% 20% / 2px 62px no-repeat,
    linear-gradient(#e4572e, #e4572e) 16% 50% / 8px 28px no-repeat,
    linear-gradient(#e4572e, #e4572e) 16% 30% / 2px 52px no-repeat,
    linear-gradient(#0f9d76, #0f9d76) 24% 35% / 8px 44px no-repeat,
    linear-gradient(#0f9d76, #0f9d76) 24% 18% / 2px 68px no-repeat,
    linear-gradient(#e4572e, #e4572e) 32% 55% / 8px 22px no-repeat,
    linear-gradient(#e4572e, #e4572e) 32% 35% / 2px 48px no-repeat,
    linear-gradient(#0f9d76, #0f9d76) 40% 30% / 8px 50px no-repeat,
    linear-gradient(#0f9d76, #0f9d76) 40% 12% / 2px 72px no-repeat,
    linear-gradient(#e4572e, #e4572e) 72% 48% / 8px 30px no-repeat,
    linear-gradient(#e4572e, #e4572e) 72% 28% / 2px 56px no-repeat,
    linear-gradient(#0f9d76, #0f9d76) 84% 38% / 8px 40px no-repeat,
    linear-gradient(#0f9d76, #0f9d76) 84% 18% / 2px 64px no-repeat;
  opacity: 0.45;
  pointer-events: none;
}
.hero-inner {
  max-width: 1120px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}
.hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  margin: 0 0 0.4rem;
  line-height: 1.45;
}
.hero .tagline {
  font-size: 1.2rem;
  color: #d9c37a;
  margin: 0 0 1rem;
  font-weight: 500;
}
.hero p.lede {
  max-width: 40rem;
  font-size: 1.05rem;
  opacity: 0.92;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
  margin: 1.6rem 0 1.4rem;
  max-width: 36rem;
}
.stat {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  padding: 0.7rem 0.9rem;
  text-align: center;
}
.stat b {
  display: block;
  font-size: 1.6rem;
  color: #7ee0c3;
  line-height: 1.3;
}
.stat span { font-size: 0.85rem; opacity: 0.85; }

.btn {
  display: inline-block;
  background: var(--teal);
  color: #fff !important;
  text-decoration: none;
  padding: 0.55rem 1.3rem;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(15, 157, 118, 0.28);
}
.btn:hover { background: var(--teal-dk); }

.btn-ghost {
  background: transparent;
  color: inherit !important;
  border: 1px solid currentColor;
  box-shadow: none;
}

/* Cards / parts */
.part {
  margin: 2.4rem 0;
}
.part-head {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  margin-bottom: 1rem;
}
.part-head h2 {
  margin: 0;
  font-size: 1.45rem;
}
.kicker {
  color: var(--teal-dk);
  font-weight: 700;
  font-size: 0.85rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.05rem 1.15rem 1.15rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
a.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 16px 36px rgba(31, 27, 77, 0.12);
}
.card .n {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  background: var(--indigo);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
}
.card h3 {
  margin: 0.2rem 0 0;
  font-size: 1.08rem;
  line-height: 1.7;
}
.card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  flex: 1;
}
.badges { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.3rem; }
.badge {
  font-size: 0.75rem;
  background: #efe8d8;
  color: var(--indigo);
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  font-weight: 500;
}
@media (prefers-color-scheme: dark) {
  .badge { background: #2a2640; color: #efe8d8; }
}

/* Lesson layout */
.crumb {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 0.6rem;
}
.crumb a { color: inherit; }
.lesson-head h1 {
  margin: 0.2rem 0 0.4rem;
  line-height: 1.55;
  font-size: clamp(1.45rem, 3vw, 2rem);
}
.meta { color: var(--muted); font-size: 0.92rem; }

.lesson-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 2rem;
  align-items: start;
}
.toc-side {
  position: sticky;
  top: calc(var(--header-h) + 0.8rem);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  font-size: 0.86rem;
}
.toc-side strong { display: block; margin-bottom: 0.4rem; }
.toc-side ol { margin: 0; padding-right: 1.1rem; }
.toc-side a { color: var(--muted); text-decoration: none; }
.toc-side a:hover { color: var(--teal-dk); }

.prose h2 {
  font-size: 1.28rem;
  margin-top: 2rem;
  padding-right: 0.7rem;
  border-right: 4px solid var(--teal);
  line-height: 1.7;
}
.prose h3 { font-size: 1.08rem; margin-top: 1.4rem; }
.prose p { margin: 0.7rem 0; }
.prose ul, .prose ol { padding-right: 1.2rem; }
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  margin: 1rem 0;
  background: var(--paper);
}
.prose th, .prose td {
  border: 1px solid var(--line);
  padding: 0.45rem 0.65rem;
  text-align: right;
}
.prose th { background: var(--indigo); color: #f7f3ea; }

figure.chart {
  margin: 1.4rem 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.6rem 0.6rem 0.9rem;
}
figure.chart img {
  width: 100%;
  border-radius: 10px;
  display: block;
}
figure.chart figcaption {
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 0.4rem;
}

.callout {
  background: #eaf7f2;
  border: 1px solid #b7e2d3;
  border-radius: 16px;
  padding: 1rem 1.2rem;
  margin: 1.4rem 0;
}
.callout h2 { border: 0; padding: 0; margin-top: 0; color: var(--teal-dk); }
@media (prefers-color-scheme: dark) {
  .callout { background: #16352d; border-color: #1f5a48; }
  .callout h2 { color: #7ee0c3; }
}

.quiz details {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.9rem;
  margin: 0.55rem 0;
}
.quiz summary {
  cursor: pointer;
  font-weight: 500;
}
.quiz summary p { display: inline; margin: 0; }
.quiz .answer {
  margin-top: 0.4rem;
  color: var(--teal-dk);
}

.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2.2rem;
  flex-wrap: wrap;
}
.pager a {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
  text-decoration: none;
  color: inherit;
  flex: 1;
  min-width: 12rem;
}

.video-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.8rem;
  align-items: center;
}
.video-card .dur {
  font-variant-numeric: tabular-nums;
  color: var(--teal-dk);
  font-weight: 700;
}

.player {
  background: #000;
  border-radius: 16px;
  overflow: hidden;
}
.player video { width: 100%; display: block; background: #000; }

.downloads {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 1rem 0;
}
.downloads a {
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.8rem;
  text-decoration: none;
}

.credit {
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 1.2rem;
}

.placeholder {
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 2rem 1.2rem;
  text-align: center;
  color: var(--muted);
}

.site-footer {
  background: var(--indigo);
  color: #e8e2d4;
  padding: 2rem 1.2rem;
  margin-top: 2rem;
}
.footer-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 2rem;
  justify-content: space-between;
  align-items: flex-start;
}
.site-footer a { color: #9be7d0; }
.disclaimer { max-width: 36rem; font-size: 0.88rem; opacity: 0.9; }

@media (max-width: 820px) {
  .lesson-layout { grid-template-columns: 1fr; }
  .toc-side { position: static; }
  .nav-toggle { display: inline-block; }
  .site-nav {
    display: none;
    position: absolute;
    left: 0; right: 0;
    top: 100%;
    background: var(--indigo-mid);
    padding: 0.6rem 1.2rem 1rem;
  }
  .site-nav.open { display: block; }
  .site-nav ul { flex-direction: column; }
  .stats { grid-template-columns: 1fr 1fr 1fr; }
  .header-inner { position: relative; }
}

@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
}
