/* ==========================================================================
   Base: reset, typography, layout primitives, utilities
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 16px);
}

body {
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-weight: var(--fw-regular);
  color: var(--color-text);
  background: var(--color-background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

img, svg, video, canvas { display: block; max-width: 100%; }
img { height: auto; }
svg { flex-shrink: 0; }
input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }
table { border-collapse: collapse; }
[hidden] { display: none !important; }
::selection { background: rgba(91, 71, 240, .18); }

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
.night :focus-visible { outline-color: var(--night-primary); }

/* ---- Typography ---- */
h1, h2, h3, h4, h5, h6 { line-height: var(--lh-heading); font-weight: var(--fw-bold); text-wrap: balance; }
p { text-wrap: pretty; }

.t-display { font-size: var(--fs-display); line-height: var(--lh-display); font-weight: var(--fw-extrabold); letter-spacing: -.01em; }
.t-h1 { font-size: var(--fs-h1); line-height: 1.2; font-weight: var(--fw-extrabold); letter-spacing: -.01em; }
.t-h2 { font-size: var(--fs-h2); line-height: var(--lh-heading); font-weight: var(--fw-bold); }
.t-h3 { font-size: var(--fs-h3); line-height: 1.35; font-weight: var(--fw-bold); }
.t-h4 { font-size: var(--fs-h4); line-height: var(--lh-tight); font-weight: var(--fw-semibold); }
.t-body-lg { font-size: var(--fs-body-lg); line-height: 1.85; }
.t-body { font-size: var(--fs-body); }
.t-body-sm { font-size: var(--fs-body-sm); line-height: 1.7; }
.t-caption { font-size: var(--fs-caption); line-height: 1.6; font-weight: var(--fw-medium); }
.t-secondary { color: var(--color-text-secondary); }
.t-muted { color: var(--color-text-muted); }
.t-gradient { background: var(--gradient-brand-text); -webkit-background-clip: text; background-clip: text; color: transparent; }
.night .t-gradient { background-image: var(--gradient-night-text); }
.t-mono { font-family: var(--font-mono); direction: ltr; unicode-bidi: isolate; letter-spacing: 0; }
.t-num { font-variant-numeric: tabular-nums; }
.t-center { text-align: center; }
.t-balance { text-wrap: balance; }

.overline {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--fs-overline);
  font-weight: var(--fw-semibold);
  letter-spacing: .02em;
  color: var(--color-primary);
}
.overline::before {
  content: "";
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}
.night .overline { color: var(--night-primary); }

/* ---- Layout ---- */
.container { width: 100%; max-width: calc(var(--container) + var(--gutter) * 2); margin-inline: auto; padding-inline: var(--gutter); }
.container-wide { max-width: calc(var(--container-wide) + var(--gutter) * 2); }
.container-text { max-width: calc(var(--container-text) + var(--gutter) * 2); }

.section { padding-block: var(--section-y); position: relative; }
.section-sm { padding-block: clamp(40px, 6vw, 72px); }
.section-head { max-width: 720px; margin-bottom: clamp(32px, 5vw, 56px); display: grid; gap: var(--space-md); }
.section-head.is-center { margin-inline: auto; text-align: center; justify-items: center; }
.section-head p { color: var(--color-text-secondary); font-size: var(--fs-body-lg); line-height: 1.85; }
.night .section-head p { color: var(--night-text-muted); }

.stack { display: flex; flex-direction: column; gap: var(--stack-gap, var(--space-md)); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cluster-gap, var(--space-sm)); }
.split { display: grid; gap: clamp(32px, 5vw, 72px); align-items: center; }
@media (min-width: 1024px) {
  .split { grid-template-columns: 1fr 1fr; }
  .split-60 { grid-template-columns: 1.15fr .85fr; }
  .split-40 { grid-template-columns: .85fr 1.15fr; }
}
.grid-auto { display: grid; gap: var(--grid-gap, var(--space-lg)); grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--grid-min, 280px)), 1fr)); }

/* ---- Night sections ---- */
.night {
  background: var(--night-bg);
  color: var(--night-text);
  --color-text-secondary: var(--night-text-muted);
  --color-text-muted: var(--night-text-muted);
  --color-border: var(--night-border);
  isolation: isolate;
}
.night-grid::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px);
  background-size: 48px 48px;
  -webkit-mask-image: radial-gradient(90% 70% at 50% 40%, #000 30%, transparent 85%);
  mask-image: radial-gradient(90% 70% at 50% 40%, #000 30%, transparent 85%);
  pointer-events: none;
}
.night-aurora::after {
  content: "";
  position: absolute;
  inset: -20% 10% auto;
  height: 70%;
  z-index: -1;
  background: radial-gradient(50% 60% at 30% 40%, rgba(49, 87, 246, .28), transparent 70%),
              radial-gradient(40% 50% at 70% 30%, rgba(91, 71, 240, .22), transparent 70%);
  filter: blur(20px);
  pointer-events: none;
}
.tech-grid { position: relative; isolation: isolate; }
.tech-grid::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(42, 75, 224, .06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(42, 75, 224, .06) 1px, transparent 1px);
  background-size: 48px 48px;
  -webkit-mask-image: radial-gradient(80% 70% at 50% 0%, #000 25%, transparent 80%);
  mask-image: radial-gradient(80% 70% at 50% 0%, #000 25%, transparent 80%);
  pointer-events: none;
}

/* ---- Prose (CMS content) ---- */
.prose { max-width: var(--measure); color: var(--color-text-secondary); font-size: 1.0625rem; line-height: 1.95; }
.prose > * + * { margin-top: 1.1em; }
.prose h2, .prose h3, .prose h4 { color: var(--color-text); scroll-margin-top: calc(var(--header-h) + 24px); }
.prose h2 { font-size: 1.6rem; margin-top: 2em; }
.prose h3 { font-size: 1.3rem; margin-top: 1.7em; }
.prose h4 { font-size: 1.1rem; margin-top: 1.5em; }
.prose strong { color: var(--color-text); font-weight: var(--fw-semibold); }
.prose a { color: var(--color-primary); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; }
.prose a:hover { text-decoration-thickness: 2px; }
.prose ul, .prose ol { padding-inline-start: 1.4em; display: grid; gap: .4em; }
.prose ol { list-style: persian; }
.prose li::marker { color: var(--color-primary); font-weight: var(--fw-semibold); }
.prose li.task { list-style: none; position: relative; margin-inline-start: -1.4em; padding-inline-start: 2em; }
.prose .task-box { position: absolute; inset-inline-start: 0; top: .45em; width: 18px; height: 18px; border: 1.5px solid var(--color-border-strong); border-radius: 5px; background: var(--color-surface); }
.prose li.task.is-done .task-box { background: var(--color-primary); border-color: var(--color-primary); }
.prose blockquote { border-inline-start: 3px solid var(--color-primary); padding: .2em 1.2em; color: var(--color-text); background: var(--color-primary-soft); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.prose code { font-family: var(--font-mono); font-size: .88em; background: var(--color-surface-sunken); border: 1px solid var(--color-border); padding: .1em .4em; border-radius: 6px; color: var(--color-text); }
.prose .code-block { background: var(--night-bg); color: #D7DDF5; padding: 18px 20px; border-radius: var(--radius-md); overflow-x: auto; font-family: var(--font-mono); font-size: .86rem; line-height: 1.7; text-align: left; }
.prose .code-block code { background: none; border: 0; padding: 0; color: inherit; }
.prose hr { border: 0; border-top: 1px solid var(--color-border); margin-block: 2em; }
.prose .table-wrap { margin-block: 1.4em; }
.prose .table th, .prose .table td { font-size: .95rem; }

.callout { border: 1px solid var(--color-border); border-inline-start: 3px solid var(--color-info); background: var(--color-info-soft); border-radius: var(--radius-md); padding: 14px 18px; color: var(--color-text); }
.callout > * + * { margin-top: .5em; }
.callout-title { display: block; font-weight: var(--fw-semibold); }
.callout-warning { border-inline-start-color: var(--color-warning); background: var(--color-warning-soft); }
.callout-tip { border-inline-start-color: var(--color-success); background: var(--color-success-soft); }

/* ---- Utilities ---- */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; inset-inline-start: 16px; top: -100px; z-index: 1000; background: var(--color-primary); color: #fff; padding: 10px 16px; border-radius: var(--radius-sm); font-weight: var(--fw-semibold); }
.skip-link:focus { top: 16px; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.icon { width: var(--icon-md); height: var(--icon-md); }
.icon-sm { width: var(--icon-sm); height: var(--icon-sm); }
.icon-lg { width: var(--icon-lg); height: var(--icon-lg); }
.icon-flip { transform: scaleX(-1); }
.divider { height: 1px; background: var(--color-border); border: 0; }
.mt-0 { margin-top: 0; } .mt-sm { margin-top: var(--space-sm); } .mt-md { margin-top: var(--space-md); } .mt-lg { margin-top: var(--space-lg); } .mt-xl { margin-top: var(--space-xl); } .mt-2xl { margin-top: var(--space-2xl); }
.w-full { width: 100%; }
.nowrap { white-space: nowrap; }

/* ---- Reveal on scroll (JS adds .is-visible; without JS content stays visible) ---- */
.js [data-reveal] { opacity: 0; transform: translateY(16px); transition: opacity var(--dur-slow) var(--ease-out), transform 520ms var(--ease-out); transition-delay: var(--reveal-delay, 0ms); }
.js [data-reveal].is-visible { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .js [data-reveal] { opacity: 1; transform: none; }
}
