/* Базовый слой: сброс, типографика, контейнеры, секции.
 * Все значения — только через токены из tokens.css.
 */

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

html {
  /* clip, а не hidden: hidden создаёт новый контекст прокрутки и ломает position: sticky */
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  overflow-x: clip;
  margin: 0;
  min-height: 100dvh;
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-body);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

::selection { background: var(--color-accent); color: var(--color-accent-ink); }

/* ── Заголовки ─────────────────────────────────────────────────────────────
   Всегда прямые. Курсив в заголовках — надёжный признак сгенерированного макета. */
h1, h2, h3, h4 {
  margin: 0;
  font-family: var(--font-display);
  font-style: normal;
  font-weight: var(--weight-display);
  line-height: var(--leading-head);
  letter-spacing: var(--tracking-display);
  min-width: 0;
  /* Только аварийный клапан на очень узких экранах. Рвать «конструкций»
     на «конструкци/й» недопустимо — приоритет у переноса по пробелам. */
  overflow-wrap: break-word;
}

.head--hero {
  font-size: var(--text-display);
  line-height: var(--leading-display);
  font-weight: var(--weight-display-bold);
  /* Заголовок первого экрана не рвём внутри слова никогда */
  overflow-wrap: normal;
  hyphens: none;
}
.head--page  { font-size: var(--text-3xl); line-height: 1.1; font-weight: var(--weight-display-bold); }
.head--sect  { font-size: var(--text-2xl); }
.head--sub   { font-size: var(--text-xl); }
.head--card  { font-size: var(--text-lg); }

p { margin: 0 0 var(--space-md); }
p:last-child { margin-bottom: 0; }

.lede {
  max-width: var(--measure);
  font-size: var(--text-md);
  color: var(--color-ink-2);
}

.prose { max-width: var(--measure); color: var(--color-ink-2); }
.prose p + p { margin-top: var(--space-md); }
.prose strong { color: var(--color-ink); font-weight: var(--weight-body-bold); }

/* ── Моноширинный регистр: только измеряемое и учётное ─────────────────── */
.readout {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  line-height: var(--leading-mono);
  color: var(--color-accent);
}
.readout--xl { font-size: var(--text-2xl); font-weight: 700; }
.readout--lg { font-size: var(--text-lg); font-weight: 500; }
.readout--sm { font-size: var(--text-sm); font-weight: 400; }

.label {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 500;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--color-muted);
}

/* ── Ссылки ───────────────────────────────────────────────────────────────── */
a { color: var(--color-accent); text-decoration: none; }

a:not([class]) {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  text-decoration-color: var(--color-accent-dim);
  transition: text-decoration-color var(--dur-micro) var(--ease-out);
}
a:not([class]):hover { text-decoration-color: var(--color-accent); }

/* Кольцо фокуса появляется мгновенно — никогда не участвует в transition */
:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
:focus:not(:focus-visible) { outline: none; }

.skip-link {
  position: absolute;
  inset-inline-start: var(--space-md);
  inset-block-start: -100%;
  z-index: var(--z-tooltip);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-accent);
  color: var(--color-accent-ink);
  font-weight: var(--weight-body-bold);
  border-radius: var(--radius-sm);
}
.skip-link:focus { inset-block-start: var(--space-md); }

/* ── Раскладка ────────────────────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--container-pad);
}

.section { padding-block: var(--space-3xl); }
.section--tight { padding-block: var(--space-2xl); }
.section--loose { padding-block: var(--space-4xl) var(--space-3xl); }
.section--ruled { border-block-start: var(--rule-hair) solid var(--color-rule-2); }

/* Ритм секций намеренно неровный: одинаковые отступы читаются как шаблон */
.section + .section { padding-block-start: var(--space-2xl); }

/* align-content: start обязателен. Без него строки grid растягиваются
   на всю высоту контейнера: если сосед по внешней сетке оказался высоким,
   содержимое стопки разъезжается с огромными промежутками. */
.stack       { display: grid; align-content: start; gap: var(--space-md); }
.stack--lg   { gap: var(--space-lg); }
.stack--xl   { gap: var(--space-xl); }
.stack--2xl  { gap: var(--space-2xl); }

.hr {
  height: var(--rule-hair);
  margin: 0;
  border: 0;
  background: var(--color-rule-2);
}

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

/* ── Появление при загрузке ────────────────────────────────────────────────
   Ступенчатая задержка задаётся селекторами :nth-child, а не inline-стилем:
   строгая CSP запрещает и style-атрибуты тоже. Суммарно не более 500 мс. */
.reveal {
  opacity: 0;
  transform: translateY(8px);
  animation: reveal var(--dur-long) var(--ease-out) forwards;
}
.reveal:nth-child(1) { animation-delay:   0ms; }
.reveal:nth-child(2) { animation-delay:  60ms; }
.reveal:nth-child(3) { animation-delay: 120ms; }
.reveal:nth-child(4) { animation-delay: 180ms; }
.reveal:nth-child(5) { animation-delay: 240ms; }
.reveal:nth-child(6) { animation-delay: 300ms; }
.reveal:nth-child(7) { animation-delay: 360ms; }
.reveal:nth-child(n+8) { animation-delay: 420ms; }

@keyframes reveal { to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 150ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 150ms !important;
  }
  .reveal { transform: none; animation: reveal-flat 150ms linear forwards; }
  @keyframes reveal-flat { to { opacity: 1; } }
}

/* ── Печать ───────────────────────────────────────────────────────────────── */
@media print {
  .nav, .foot__links, .skip-link, .btn { display: none !important; }
  body { background: #fff; color: #000; }
}
