@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;
  --link: #3d348b;
}

@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;
    --link: #b7c4ff;
  }
}

*,
*::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: 1.95;
  min-height: 100vh;
}

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

a { color: var(--link); 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; }

.vh {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.22em;
}

.site-header {
  background-color: var(--indigo);
  background-image: linear-gradient(90deg, var(--indigo) 0%, var(--indigo-mid) 100%);
  color: #f7f3ea;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 8px 24px rgba(15, 12, 40, 0.22);
}
.site-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--coral), var(--gold) 35%, var(--teal) 70%, #7ee0c3);
  opacity: 0.9;
}

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

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

.brand svg { transition: transform 0.25s ease; }
.brand:hover svg { transform: rotate(-8deg) scale(1.05); }

.nav-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}
.nav-toggle::before {
  content: "";
  width: 15px;
  height: 11px;
  background:
    linear-gradient(currentColor 0 0) top / 100% 2px no-repeat,
    linear-gradient(currentColor 0 0) center / 100% 2px no-repeat,
    linear-gradient(currentColor 0 0) bottom / 100% 2px no-repeat;
}

.site-nav {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  background: var(--indigo-mid);
  padding: 0.5rem 1rem 1rem;
  box-shadow: 0 18px 30px rgba(15, 12, 40, 0.3);
}
.site-nav.open { display: block; }
.site-nav ul {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-nav a {
  color: #efeae0;
  text-decoration: none;
  font-weight: 500;
  display: block;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.site-nav a:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.site-nav a[aria-current="page"] {
  background: rgba(126, 224, 195, 0.18);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(126, 224, 195, 0.45);
}

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--teal);
  color: #fff !important;
  text-decoration: none;
  padding: 0.55rem 1.25rem;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(15, 157, 118, 0.28);
  transition: background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.btn:hover { background: var(--teal-dk); transform: translateY(-2px); box-shadow: 0 12px 24px rgba(15, 157, 118, 0.32); }
.btn .ic { transition: transform 0.2s ease; }
.btn:hover .ic { transform: translateX(-3px); }

.part { margin: 2rem 0; }
.part-head {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  margin-bottom: 0.8rem;
}
.part-head h2 { margin: 0; font-size: 1.35rem; line-height: 1.6; }
.kicker {
  color: var(--teal-dk);
  font-weight: 700;
  font-size: 0.82rem;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.05rem 1.1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
a.card:hover {
  border-color: var(--teal);
  transform: translateY(-3px);
  box-shadow: 0 18px 38px rgba(31, 27, 77, 0.13);
}
.card h3 {
  margin: 0.15rem 0 0;
  font-size: 1.06rem;
  line-height: 1.7;
}
.card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  flex: 1;
}
.badges, .chips { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.25rem; }
.badge, .chip {
  font-size: 0.78rem;
  background: #efe8d8;
  color: #1f1b4d;
  border-radius: 999px;
  padding: 0.08rem 0.6rem;
  font-weight: 500;
  text-decoration: none;
}
a.chip:hover { background: var(--teal); color: #fff; }
@media (prefers-color-scheme: dark) {
  .badge, .chip { background: #2a2640; color: #efe8d8; }
}

.soon { color: var(--muted); margin: 0.3rem 0; }

.crumb { font-size: 0.88rem; color: var(--muted); margin: 0 0 0.7rem; }
.crumb a { color: inherit; }

.lesson-head h1 {
  margin: 0.15rem 0 0.35rem;
  line-height: 1.5;
  font-size: clamp(1.4rem, 3vw, 2rem);
}
.en-title {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  direction: ltr;
  text-align: right;
}
.meta { color: var(--muted); font-size: 0.9rem; margin: 0.2rem 0; }
.summary {
  background: var(--paper);
  border-right: 4px solid var(--gold);
  border-radius: 12px;
  padding: 0.55rem 0.9rem;
  margin: 0.8rem 0 0.4rem;
}

.lesson-layout { display: grid; gap: 1.2rem; }
.toc-side {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  font-size: 0.88rem;
}
.toc-side strong { display: block; margin-bottom: 0.35rem; }
.toc-side ol { margin: 0; padding-right: 1.15rem; }
.toc-side a { color: var(--muted); text-decoration: none; }
.toc-side a:hover { color: var(--teal-dk); }

.prose h2 {
  font-size: 1.22rem;
  margin-top: 1.8rem;
  padding-right: 0.65rem;
  border-right: 4px solid var(--teal);
  line-height: 1.7;
}
.prose h3 { font-size: 1.05rem; margin-top: 1.2rem; }
.prose p { margin: 0.65rem 0; }
.prose ul, .prose ol { padding-right: 1.2rem; }
.table-scroll { overflow-x: auto; margin: 1rem 0; }
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  background: var(--paper);
  min-width: 28rem;
}
.prose th, .prose td {
  border: 1px solid var(--line);
  padding: 0.4rem 0.6rem;
  text-align: right;
  vertical-align: top;
}
.prose th { background: var(--indigo); color: #f7f3ea; }

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

.related ul { list-style: none; margin: 0.4rem 0 0; padding: 0; }
.related a {
  display: block;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.5rem 0.8rem;
  margin: 0.4rem 0;
  text-decoration: none;
  color: inherit;
}

.pager {
  display: flex;
  gap: 0.8rem;
  margin-top: 1.8rem;
  flex-wrap: wrap;
}
.pager a {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.85rem;
  text-decoration: none;
  color: inherit;
  flex: 1;
  min-width: 10rem;
}
.pager .next { margin-inline-start: auto; }

.search-box input {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}
#results { margin-top: 1rem; }

.site-footer {
  background:
    radial-gradient(30rem 12rem at 100% 0%, rgba(15, 157, 118, 0.18), transparent 70%),
    var(--indigo);
  color: #e8e2d4;
  padding: 2rem 1rem 2.2rem;
  margin-top: 1rem;
  border-top: 3px solid var(--teal);
}
.footer-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 2rem;
  justify-content: space-between;
}
.site-footer a { color: #9be7d0; }
.disclaimer { max-width: 36rem; font-size: 0.88rem; opacity: 0.92; margin: 0.3rem 0 0; }
.footer-sections {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.8rem;
  margin-top: 0.7rem;
}
.footer-sections a {
  text-decoration: none;
  font-size: 0.88rem;
  padding: 0.1rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  transition: background-color 0.2s ease;
}
.footer-sections a:hover { background: rgba(126, 224, 195, 0.2); color: #fff; }

@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
  .wrap { padding: 1.6rem 1.2rem 3rem; }
}

@media (min-width: 880px) {
  .nav-toggle { display: none; }
  .site-nav {
    display: block;
    position: static;
    background: transparent;
    padding: 0;
  }
  .site-nav { box-shadow: none; }
  .site-nav ul { flex-direction: row; gap: 0.2rem 0.35rem; }
  .site-nav a { padding: 0.3rem 0.95rem; }
  .lesson-layout {
    grid-template-columns: minmax(0, 1fr) 220px;
    align-items: start;
  }
  .toc-side { position: sticky; top: calc(var(--header-h) + 0.8rem); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  a.card, .btn, .btn .ic, .brand svg, .site-nav a, .footer-sections a { transition: none; }
  a.card:hover, .btn:hover, .btn:hover .ic, .brand:hover svg { transform: none; }
}
