/* =============================================================================
   Base — reset, document surface, typography defaults, accessibility helpers.
   ========================================================================== */

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

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--text);
  background-color: var(--bg);
  /* Aurora field: three soft radial washes over the flat background. Fixed so
     it stays put while content scrolls, and cheap enough for mobile (no blur
     filters, no extra compositing layers). */
  background-image:
    radial-gradient(60rem 40rem at 100% -10%, var(--bg-tint-1), transparent 60%),
    radial-gradient(50rem 34rem at -10% 10%, var(--bg-tint-2), transparent 60%),
    radial-gradient(46rem 30rem at 60% 110%, var(--bg-tint-3), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

img, svg, video, canvas { display: block; max-width: 100%; }
img, video { height: auto; }

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

button { background: none; border: none; cursor: pointer; }

/* Touch behaviour, applied once for everything tappable:
   - `manipulation` drops the ~300ms double-tap-to-zoom wait on mobile Safari;
   - the grey iOS/Android tap flash is replaced by the components' own
     :active and focus styling, which is theme-aware. */
a, button, label, summary, [role="button"], input, select, textarea {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--dur-1) var(--ease);
}
@media (hover: hover) {
  a:hover { color: var(--primary-hover); }
}

h1, h2, h3, h4 { line-height: var(--lh-tight); font-weight: 700; text-wrap: balance; }
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }

p { text-wrap: pretty; }

ul, ol { padding: 0; list-style: none; }

hr { border: none; border-top: 1px solid var(--divider); margin: var(--space-5) 0; }

code, kbd, samp { font-family: var(--font-mono); font-size: 0.9em; direction: ltr; }

::selection { background: var(--primary-soft); color: var(--primary-soft-text); }

/* Focus: only for keyboard users, always visible against any surface. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* Scrollbars — themed rather than left as OS default, which reads as a light
   strip pasted onto a dark page. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-full);
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--text-subtle); background-clip: content-box; }

/* --- Numerals ------------------------------------------------------------- */
/* Persian digits are produced at format time (js/core/format.js), not by a
   font feature, so numbers stay copy-pasteable as real digits where it
   matters (inputs, links) and only display text is localized. */
.num { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.rtl { direction: rtl; }

/* --- Layout safety --------------------------------------------------------- */
/* A grid/flex item's automatic minimum size is its *content's* min-content
   width, so one long unbreakable string (a URL, a phone number, a nowrap
   pill) can push a whole column past the viewport — which is exactly how a
   page ends up scrolling sideways on a phone. Opting every layout child out
   of that once is far more reliable than patching each site individually. */
.grid > *,
.split > *,
.stack > *,
.stack-sm > *,
.stack-lg > *,
.row > *,
.row-wrap > *,
.row-between > * { min-width: 0; }

/* --- Utilities ------------------------------------------------------------ */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: fixed;
  inset-inline-start: var(--space-4);
  inset-block-start: -100px;
  z-index: 200;
  padding: var(--space-3) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  transition: inset-block-start var(--dur-2) var(--ease);
}
.skip-link:focus { inset-block-start: var(--space-4); }

.noscript {
  margin: var(--space-8) auto;
  max-width: 32rem;
  padding: var(--space-5);
  text-align: center;
  background: var(--warning-soft);
  color: var(--warning-soft-text);
  border-radius: var(--r-lg);
}

/* A link that stands on its own — a phone number, an email, a footer nav
   entry — is a target, not a word inside a sentence, so it carries its own
   hit box. WCAG 2.5.8 asks for 24px; touch pointers get the full 44px.
   `max-width` + `anywhere` keep a long address (which has no spaces to break
   at) inside its column instead of widening the page. */
.tap-link {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  max-width: 100%;
  overflow-wrap: anywhere;
}
@media (pointer: coarse) {
  .tap-link { min-height: 44px; }
}

.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.bold { font-weight: 700; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.hidden { display: none !important; }

.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
.stack-lg { display: flex; flex-direction: column; gap: var(--space-6); }
.row { display: flex; align-items: center; gap: var(--space-3); }
.row-wrap { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.spacer { flex: 1 1 auto; }
/* Stops an inline-flex pill (chip, badge, button) from stretching to the full
   width of a column flex container. */
.self-start { align-self: flex-start; }

/* --- Boot splash (pre-hydration) ------------------------------------------ */
.boot {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-5);
  color: var(--primary);
}
.boot__mark { animation: boot-pulse 1.6s var(--ease) infinite; }
.boot__text { color: var(--text-muted); font-size: var(--fs-sm); }

@keyframes boot-pulse {
  0%, 100% { opacity: 0.45; transform: scale(0.96); }
  50%      { opacity: 1;    transform: scale(1.04); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
