/* ---------- Fonts (self-hosted, OFL) ---------- */
@font-face {
  font-family: "Inter";
  src: url("/assets/fonts/inter-latin.woff2") format("woff2-variations"), url("/assets/fonts/inter-latin.woff2") format("woff2");
  font-weight: 100 900; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/assets/fonts/vazirmatn-arabic.woff2") format("woff2-variations"), url("/assets/fonts/vazirmatn-arabic.woff2") format("woff2");
  font-weight: 100 900; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/assets/fonts/vazirmatn-latin.woff2") format("woff2-variations"), url("/assets/fonts/vazirmatn-latin.woff2") format("woff2");
  font-weight: 100 900; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Tokens ---------- */
:root {
  --bg: #f7f2ea;
  --surface: #fffdf9;
  --surface-2: #f1e9dd;
  --text: #23201c;
  --muted: #675e54;
  --line: #e4d9ca;
  --primary: #0f6b6f;
  --primary-ink: #ffffff;
  --primary-soft: #d8ebe8;
  --accent: #d9583b;
  --accent-soft: #fbe2d9;
  --shadow: 0 1px 2px rgb(60 40 20 / .06), 0 8px 24px rgb(60 40 20 / .08);
  --shadow-lift: 0 2px 4px rgb(60 40 20 / .08), 0 18px 40px rgb(60 40 20 / .14);
  --radius: 18px;
  --radius-sm: 10px;
  --wrap: 1120px;
  --gutter: clamp(16px, 4vw, 32px);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}
:root[lang="fa"] { --font: "Vazirmatn", Tahoma, system-ui, sans-serif; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1916; --surface: #24211d; --surface-2: #2e2a25; --text: #f2ece3; --muted: #b3a899;
    --line: #3b362f; --primary: #5bbcb9; --primary-ink: #0d1c1c; --primary-soft: #1d3634;
    --accent: #f08a6f; --accent-soft: #3e2b25;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
    --shadow-lift: 0 2px 4px rgb(0 0 0 / .35), 0 18px 40px rgb(0 0 0 / .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1916; --surface: #24211d; --surface-2: #2e2a25; --text: #f2ece3; --muted: #b3a899;
  --line: #3b362f; --primary: #5bbcb9; --primary-ink: #0d1c1c; --primary-soft: #1d3634;
  --accent: #f08a6f; --accent-soft: #3e2b25;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
  --shadow-lift: 0 2px 4px rgb(0 0 0 / .35), 0 18px 40px rgb(0 0 0 / .4);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 84px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 1rem/1.65 var(--font); font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased; overflow-x: clip;
}
:root[lang="fa"] body { line-height: 1.9; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -0.015em; }
:root[lang="fa"] :is(h1, h2, h3) { letter-spacing: 0; line-height: 1.45; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
a { color: var(--primary); text-underline-offset: 3px; }
img { max-width: 100%; height: auto; display: block; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.wrap { max-width: var(--wrap); margin-inline: auto; padding-inline: var(--gutter); }
.muted { color: var(--muted); }

.skip {
  position: absolute; inset-inline-start: 12px; top: -60px; z-index: 100;
  background: var(--primary); color: var(--primary-ink); padding: 10px 16px; border-radius: var(--radius-sm);
}
.skip:focus { top: 12px; }

/* ---------- Buttons & chips ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .5em; min-height: 46px; padding: 0 22px;
  border-radius: 999px; font-weight: 600; text-decoration: none; border: 2px solid transparent;
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), background .25s;
}
.btn--primary { background: var(--primary); color: var(--primary-ink); box-shadow: var(--shadow); }
.btn--primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.btn--ghost { border-color: var(--line); color: var(--text); background: var(--surface); }
.btn--ghost:hover { border-color: var(--primary); color: var(--primary); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips li {
  font-size: .85rem; padding: 4px 12px; border-radius: 999px;
  background: var(--primary-soft); color: var(--text); border: 1px solid transparent;
  transition: background .2s, border-color .2s;
}
.chips li:hover { border-color: var(--primary); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid transparent; transition: border-color .3s;
}
.topbar.is-scrolled { border-bottom-color: var(--line); }
.topbar__in { display: flex; align-items: center; gap: 16px; min-height: 64px; }
.brand { font-weight: 800; color: var(--text); text-decoration: none; font-size: 1.05rem; white-space: nowrap; }
.nav { margin-inline-start: auto; }
.nav ul { display: flex; gap: 4px; }
.nav a {
  display: block; padding: 6px 10px; border-radius: 8px; color: var(--muted);
  text-decoration: none; font-size: .92rem; font-weight: 500; transition: color .2s, background .2s;
}
.nav a:hover, .nav a.is-active { color: var(--text); background: var(--surface-2); }
.actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn .i-moon { fill: currentColor; stroke: none; }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: none; }
  :root:not([data-theme="light"]) .i-moon { display: block; }
}
.lang { display: flex; padding: 3px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.lang a {
  min-width: 40px; height: 32px; display: grid; place-items: center; padding: 0 10px; border-radius: 999px;
  text-decoration: none; color: var(--muted); font-weight: 700; font-size: .85rem;
}
.lang a[lang="fa"] { font-family: "Vazirmatn", Tahoma, sans-serif; }
.lang a[aria-current] { background: var(--primary); color: var(--primary-ink); }
.lang a:not([aria-current]):hover { color: var(--text); }

@media (max-width: 900px) {
  .nav { display: none; }
  .actions { margin-inline-start: auto; }
}

/* ---------- Hero ---------- */
.hero { position: relative; overflow: hidden; padding-block: clamp(56px, 10vw, 120px) clamp(48px, 7vw, 88px); }
.hero__canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .9; pointer-events: none; }
.hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to bottom, transparent 70%, var(--bg));
}
.hero__in { position: relative; z-index: 1; }
.eyebrow {
  display: inline-block; font-size: .85rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--primary); background: var(--primary-soft); padding: 6px 14px; border-radius: 999px; margin-bottom: 22px;
}
:root[lang="fa"] .eyebrow { letter-spacing: 0; text-transform: none; }
.hero__title { font-size: clamp(2.3rem, 6.4vw, 4.6rem); font-weight: 800; max-width: 14ch; }
:root[lang="fa"] .hero__title { max-width: 16ch; font-size: clamp(2.1rem, 6vw, 4.2rem); }
.hl {
  color: var(--primary);
  background: linear-gradient(transparent 62%, var(--accent-soft) 62%, var(--accent-soft) 92%, transparent 92%);
  background-repeat: no-repeat; background-size: 100% 100%;
}
.js .hl { background-size: 0% 100%; transition: background-size 1.1s .45s var(--ease); }
:root[dir="rtl"] .hl { background-position: right; }
.js .is-ready .hl { background-size: 100% 100%; }
.hero__grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: clamp(28px, 5vw, 64px); align-items: center; }
.hero__photo { position: relative; margin: 0; justify-self: end; width: 100%; max-width: 360px; }
.hero__photo::before {
  content: ""; position: absolute; inset: -14px; border: 2px dashed color-mix(in srgb, var(--primary) 55%, transparent);
  border-radius: 44% 56% 46% 54% / 54% 44% 56% 46%; animation: blob-spin 38s linear infinite;
}
.hero__photo::after {
  content: ""; position: absolute; width: 34%; aspect-ratio: 1; inset-inline-start: -8%; bottom: 6%; z-index: -1;
  border-radius: 50%; background: var(--accent-soft);
}
.hero__img {
  position: relative; width: 100%; height: auto; aspect-ratio: 4 / 5; object-fit: cover;
  border-radius: 44% 56% 46% 54% / 54% 44% 56% 46%; border: 6px solid var(--surface); box-shadow: var(--shadow-lift);
}
@keyframes blob-spin { to { transform: rotate(360deg); } }
@media (max-width: 760px) {
  .hero__grid { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .hero__photo { order: -1; justify-self: start; max-width: 156px; }
  .hero__img { aspect-ratio: 1; border-radius: 50%; border-width: 4px; }
  .hero__photo::before { inset: -9px; border-radius: 50%; }
}
.hero__sub { margin-top: 22px; max-width: 58ch; font-size: clamp(1.05rem, 1.6vw, 1.2rem); color: var(--muted); }
.hero__cta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 32px; }

.stats {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: clamp(40px, 6vw, 64px);
}
.stat {
  background: color-mix(in srgb, var(--surface) 85%, transparent); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; backdrop-filter: blur(6px);
}
.stat__num { display: block; font-size: clamp(1.7rem, 3.2vw, 2.4rem); font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; }
.stat__label { display: block; font-size: .9rem; color: var(--muted); line-height: 1.4; margin-top: 4px; }
@media (max-width: 720px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Sections ---------- */
.section { padding-block: clamp(56px, 8vw, 104px); }
.section:nth-of-type(even) { background: var(--surface-2); }
.section__head { margin-bottom: clamp(28px, 4vw, 44px); max-width: 640px; }
.section__kicker { font-weight: 700; color: var(--accent); font-size: .9rem; letter-spacing: .1em; }
.section__head h2 { font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 800; margin-top: 6px; }
.section__intro { color: var(--muted); margin-top: 8px; font-size: 1.08rem; }

/* ---------- Projects ---------- */
.projects { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.card {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  transition: transform .35s var(--ease), box-shadow .35s var(--ease), border-color .35s;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lift); border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); }
.card--featured { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); align-items: stretch; }
.card:not(.card--featured) { align-self: start; }
.card__media { margin: 0; background: linear-gradient(160deg, var(--primary-soft), var(--accent-soft)); display: grid; place-items: center; padding: 24px; }
.card__media img { border-radius: 22px; box-shadow: var(--shadow-lift); max-height: 520px; width: auto; }
.card__icon {
  font-size: 2rem; width: 64px; height: 64px; display: grid; place-items: center; margin: 24px 24px 0;
  border-radius: 16px; background: var(--primary-soft);
}
.card--featured .card__icon { width: auto; height: 100%; min-height: 260px; margin: 0; border-radius: 0; font-size: 5rem;
  background: linear-gradient(160deg, var(--primary-soft), var(--accent-soft)); }
.card__body { padding: 20px 24px 24px; display: flex; flex-direction: column; gap: 8px; }
.card--featured .card__body { padding: 28px; justify-content: center; }
.card__tag { font-size: .8rem; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
:root[lang="fa"] .card__tag { text-transform: none; letter-spacing: 0; }
.card__title { font-size: 1.3rem; font-weight: 750; }
.card--featured .card__title { font-size: clamp(1.5rem, 2.6vw, 2rem); }
.card__summary { color: var(--muted); }
.card__toggle {
  align-self: flex-start; margin-top: 6px; display: none; gap: 8px; align-items: center;
  background: none; border: 0; padding: 6px 0; font: inherit; font-weight: 650; color: var(--primary); cursor: pointer;
}
.card__toggle::after {
  content: ""; width: 9px; height: 9px; border: solid currentColor; border-width: 0 2px 2px 0;
  transform: rotate(45deg) translateY(-2px); transition: transform .3s var(--ease);
}
.card__toggle[aria-expanded="true"]::after { transform: rotate(225deg) translateY(-2px); }
.js .card__toggle { display: inline-flex; }
.card__story { display: grid; gap: 14px; margin-top: 6px; }
.js .card__story { grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows .45s var(--ease), opacity .35s; }
.js .card__story > * { min-height: 0; overflow: hidden; }
.js .card__story.is-open { grid-template-rows: 1fr; opacity: 1; }
.js .card__story:not(.is-open) .chips { display: none; }
.story { display: grid; gap: 12px; margin: 0; }
.story__row { border-inline-start: 3px solid var(--primary-soft); padding-inline-start: 14px; }
.story dt { font-weight: 700; font-size: .85rem; color: var(--primary); }
.story dd { margin: 2px 0 0; color: var(--text); font-size: .97rem; }
.card--placeholder {
  background: transparent; border: 2px dashed var(--line); box-shadow: none; padding: 28px 24px; text-align: center;
  display: grid; justify-items: center; gap: 8px;
}
.card--placeholder:hover { border-color: var(--accent); transform: none; box-shadow: none; }
.card__plus {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; font-size: 1.8rem; font-weight: 300;
  color: var(--accent); background: var(--accent-soft);
}
@media (max-width: 640px) {
  .projects { grid-template-columns: minmax(0, 1fr); }
  .card--featured { grid-template-columns: minmax(0, 1fr); }
  .card__media img { max-height: 380px; }
}

/* ---------- Timeline ---------- */
.timeline { position: relative; display: grid; gap: 22px; padding-inline-start: 34px; }
.timeline__line { position: absolute; inset-block: 8px; inset-inline-start: 9px; width: 3px; border-radius: 3px; background: var(--line); }
.timeline__line span {
  position: absolute; inset-inline: 0; top: 0; height: 100%; border-radius: inherit;
  background: linear-gradient(var(--primary), var(--accent)); transform-origin: top; transform: scaleY(var(--progress, 1));
}
.js .timeline__line span { transform: scaleY(var(--progress, 0)); }
.tl { position: relative; }
.tl__dot {
  position: absolute; inset-inline-start: -32px; top: 22px; width: 17px; height: 17px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--primary); box-shadow: 0 0 0 5px var(--bg);
}
.section:nth-of-type(even) .tl__dot { box-shadow: 0 0 0 5px var(--surface-2); }
.tl__card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 24px; box-shadow: var(--shadow); }
.tl__period { font-size: .85rem; font-weight: 650; color: var(--accent); }
.tl__role { font-size: 1.2rem; font-weight: 750; margin-top: 4px; }
.tl__org { color: var(--primary); font-weight: 600; margin-top: 2px; }
.tl__points { margin-top: 10px; display: grid; gap: 6px; }
.tl__points li, .degree li { position: relative; padding-inline-start: 18px; color: var(--muted); }
.tl__points li::before, .degree li::before {
  content: ""; position: absolute; inset-inline-start: 2px; top: .7em; width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
}

/* ---------- Teaching, research ---------- */
.mini-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 16px; }
.mini { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; transition: transform .3s var(--ease), border-color .3s; }
.mini:hover { transform: translateY(-3px); border-color: var(--primary); }
.mini h3 { font-size: 1.05rem; font-weight: 700; }
.mini p { color: var(--primary); font-weight: 600; margin-top: 4px; }
.mini p.muted { color: var(--muted); font-weight: 400; font-size: .92rem; }

.pubs { display: grid; gap: 14px; }
.pub { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 24px; display: grid; gap: 6px; }
.pub__meta { display: flex; gap: 10px; align-items: center; font-size: .82rem; }
.pub__kind { font-weight: 650; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--text); }
.pub__year { color: var(--muted); font-weight: 600; }
.pub__title { font-size: 1.08rem; font-weight: 650; line-height: 1.45; }
.pub__title a { color: var(--text); text-decoration-color: var(--primary); }
.pub__title a:hover { color: var(--primary); }
.pub__title a::after { content: " ↗"; color: var(--primary); }
.pub__detail { color: var(--muted); font-size: .93rem; }

/* ---------- Education ---------- */
.edu { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 28px; }
.degree { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; display: grid; gap: 4px; align-content: start; }
.degree__year { font-weight: 700; color: var(--accent); font-size: .9rem; }
.degree h3 { font-size: 1.15rem; font-weight: 750; }
.degree__school { color: var(--primary); font-weight: 600; }
.degree ul { margin-top: 8px; display: grid; gap: 4px; }
.certs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.cert-group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; }
.cert-group h3 { font-size: 1rem; font-weight: 750; margin-bottom: 12px; }
.cert-group ul { display: grid; gap: 10px; }
.cert { display: grid; gap: 1px; padding-inline-start: 12px; border-inline-start: 2px solid var(--line); }
.cert__title { font-weight: 600; font-size: .95rem; line-height: 1.4; }
.cert__meta { color: var(--muted); font-size: .84rem; }
.cert--highlight { border-inline-start-color: var(--accent); }
.cert--highlight .cert__title::after {
  content: "★"; color: var(--accent); margin-inline-start: 6px; font-size: .85em;
}
@media (max-width: 900px) { .certs { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) { .edu { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Skills ---------- */
.skills { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.skill-group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; }
.skill-group h3 { font-size: 1rem; font-weight: 750; margin-bottom: 12px; }
.skill-group:nth-child(2) .chips li { background: var(--accent-soft); }
@media (max-width: 900px) { .skills { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Contact ---------- */
.contact {
  background: linear-gradient(140deg, var(--primary-soft), var(--accent-soft)); border-radius: calc(var(--radius) + 6px);
  padding: clamp(28px, 5vw, 56px); display: grid; gap: 22px; justify-items: start;
}
.contact__text { font-size: clamp(1.15rem, 2.2vw, 1.45rem); font-weight: 600; max-width: 34ch; }
.contact__links { display: flex; flex-wrap: wrap; gap: 12px; }
.contact__plain { font-weight: 700; }
.contact__email { direction: ltr; unicode-bidi: isolate; }

/* ---------- Footer & 404 ---------- */
.footer { border-top: 1px solid var(--line); padding-block: 24px; color: var(--muted); font-size: .9rem; }
.footer__in { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
.notfound main { min-height: 100vh; display: grid; place-content: center; justify-items: start; gap: 16px; }

/* ---------- Reveal motion (only when JS is running) ---------- */
.js .reveal { opacity: 0; transform: translateY(18px); transition: opacity .7s var(--ease), transform .7s var(--ease); }
.js .reveal.is-visible { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
  .js .reveal { opacity: 1; transform: none; }
  .js .timeline__line span { transform: scaleY(1); }
  .card:hover, .btn--primary:hover, .mini:hover { transform: none; }
}
