/* =========================================================================
   БАЗА — сброс, типографика, сетка, служебные утилиты.
   Цвет и размер берутся только из tokens.css.
   ========================================================================= */

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

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + var(--space-4));
}

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--color-canvas);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

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

/* ------------------------------------------------------------ ЗАГОЛОВКИ */
h1, h2, h3, h4 {
  margin: 0 0 var(--space-4);
  font-weight: var(--fw-bold);
  line-height: var(--lh-heading);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text);
  text-wrap: balance;
}

h1 { font-size: var(--fs-3xl); margin-bottom: var(--space-5); }
h2 { font-size: var(--fs-2xl); margin-top: var(--space-8); }
h3 { font-size: var(--fs-xl); margin-top: var(--space-6); }
h4 { font-size: var(--fs-lg); margin-top: var(--space-5); }

h2:first-child, h3:first-child, h4:first-child { margin-top: 0; }

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

.lead {
  font-size: var(--fs-lg);
  line-height: var(--lh-loose);
  color: var(--color-text-muted);
  max-width: 68ch;
}

.eyebrow {
  display: block;
  margin: 0 0 var(--space-3);
  font-size: var(--fs-3xs);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--color-text-subtle);
}

small, .text-sm { font-size: var(--fs-xs); }
.text-muted { color: var(--color-text-muted); }
.text-subtle { color: var(--color-text-subtle); }
.text-center { text-align: center; }
.nowrap { white-space: nowrap; }

strong, b { font-weight: var(--fw-bold); }

abbr[title] { text-decoration: none; border-bottom: 1px dotted var(--color-border-strong); cursor: help; }

/* --------------------------------------------------------------- ССЫЛКИ */
a {
  color: var(--color-text-link);
  text-decoration: underline;
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
  transition: color var(--motion-fast) var(--easing);
}

a:hover { color: var(--color-text-link-hover); }

:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------- СПИСКИ, HR */
ul, ol { margin: 0 0 var(--space-4); padding-left: 1.35em; }
li { margin-bottom: var(--space-2); }
li:last-child { margin-bottom: 0; }

.list-plain { list-style: none; padding-left: 0; }

.list-check { list-style: none; padding-left: 0; }
.list-check > li {
  position: relative;
  padding-left: 1.75rem;
  margin-bottom: var(--space-3);
}
.list-check > li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.45em;
  width: 0.85rem;
  height: 0.5rem;
  border-left: 2px solid var(--color-accent);
  border-bottom: 2px solid var(--color-accent);
  transform: rotate(-45deg);
}

dl { margin: 0 0 var(--space-4); }
dt { font-weight: var(--fw-bold); margin-top: var(--space-3); }
dd { margin: 0 0 var(--space-2); color: var(--color-text-muted); }

hr {
  border: 0;
  border-top: var(--border-width) solid var(--color-border);
  margin: var(--space-7) 0;
}

/* --------------------------------------------------------- КОД, ЦИТАТЫ */
code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.1em 0.36em;
  border-radius: var(--radius-sm);
}

pre {
  margin: 0 0 var(--space-4);
  padding: var(--space-4);
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: var(--radius-md);
  overflow-x: auto;
}
pre code { background: none; padding: 0; }

blockquote {
  margin: 0 0 var(--space-4);
  padding-left: var(--space-4);
  border-left: 3px solid var(--color-border-strong);
  color: var(--color-text-muted);
}

/* ------------------------------------------------------- МЕДИА, ТАБЛИЦЫ */
img, svg, video { max-width: 100%; height: auto; }

figure { margin: 0 0 var(--space-5); }
figcaption {
  margin-top: var(--space-3);
  font-size: var(--fs-xs);
  color: var(--color-text-subtle);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

/* --------------------------------------------------------------- СЕТКА */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

.container--narrow { max-width: var(--container-narrow); }

.section { padding-block: var(--space-8); }
.section--tight { padding-block: var(--space-7); }
.section--sunken { background: var(--color-canvas-sunken); }
.section--surface { background: var(--color-surface); }

.section__head { max-width: 72ch; margin-bottom: var(--space-6); }
.section__head h2 { margin-top: 0; }

.grid { display: grid; gap: var(--space-5); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 900px) {
  .grid--3, .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .grid--2, .grid--3, .grid--4 { grid-template-columns: minmax(0, 1fr); }
}

.stack > * + * { margin-top: var(--space-4); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }

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

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -100%;
  z-index: var(--z-toast);
  padding: var(--space-3) var(--space-4);
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border-radius: var(--radius-md);
  text-decoration: none;
}
.skip-link:focus { top: var(--space-3); color: var(--btn-primary-text); }

main { flex: 1 0 auto; }

/* Адаптивная типографика первого экрана */
@media (max-width: 760px) {
  :root {
    --fs-4xl: 2rem;
    --fs-3xl: 1.75rem;
    --fs-2xl: 1.4rem;
    --fs-xl: 1.2rem;
  }
}
