/* =========================================================================
   base.css — сброс, типографика, базовые элементы, сетка контейнеров.
   Цветовых литералов здесь нет: только var() из 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-h) + var(--sp-6));
}

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

body {
  margin: 0;
  background: var(--color-canvas);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--fs-m);
  line-height: var(--lh-base);
  font-weight: var(--fw-regular);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overflow-wrap: break-word;
}

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

/* ---------- заголовки: иерархия без пропусков уровней ---------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: var(--fw-bold);
  line-height: var(--lh-heading);
  color: var(--color-text);
  margin: 0 0 var(--sp-4);
  text-wrap: balance;
  overflow-wrap: break-word;
}

h1 {
  font-size: var(--fs-3xl);
  line-height: var(--lh-tight);
  letter-spacing: -0.015em;
  margin-bottom: var(--sp-5);
}

h2 {
  font-size: var(--fs-2xl);
  letter-spacing: -0.01em;
  margin-top: var(--sp-8);
}

h3 {
  font-size: var(--fs-xl);
  margin-top: var(--sp-6);
}

h4 {
  font-size: var(--fs-l);
  margin-top: var(--sp-5);
}

h5, h6 {
  font-size: var(--fs-m);
  margin-top: var(--sp-5);
}

:where(h1, h2, h3, h4, h5, h6):first-child { margin-top: 0; }

@media (min-width: 30rem) {
  h1 { font-size: var(--fs-4xl); }
}

@media (min-width: 48rem) {
  h1 { font-size: var(--fs-5xl); }
  h2 { font-size: var(--fs-3xl); }
}

p, ul, ol, dl, table, figure, blockquote, pre {
  margin: 0 0 var(--sp-4);
}

p { max-width: var(--measure); }
.u-wide p { max-width: none; }

ul, ol { padding-left: 1.4em; }

li { margin-bottom: var(--sp-2); }
li:last-child { margin-bottom: 0; }

li > ul,
li > ol { margin-top: var(--sp-2); }

dt { font-weight: var(--fw-bold); }
dd { margin: 0 0 var(--sp-3); }

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

small { font-size: var(--fs-xs); }

abbr[title] {
  text-decoration: underline dotted;
  text-underline-offset: 0.2em;
  cursor: help;
}

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

/* ---------- ссылки ---------- */
a {
  color: var(--link-text);
  background-color: var(--link-bg);
  text-decoration: underline;
  text-underline-offset: 0.16em;
  text-decoration-thickness: 1px;
  transition: color var(--dur-fast) var(--ease);
}

a:hover {
  color: var(--link-hover-text);
  background-color: var(--link-hover-bg);
  text-decoration-thickness: 2px;
}

a:visited {
  color: var(--link-visited-text);
  background-color: var(--link-visited-bg);
}

/* ---------- фокус с клавиатуры ---------- */
:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-s);
}

:focus:not(:focus-visible) { outline: none; }

/* ---------- медиа ---------- */
img, svg, video, canvas {
  max-width: 100%;
  height: auto;
  display: block;
}

figure { margin-inline: 0; }

figcaption {
  color: var(--figcap-text);
  background-color: var(--figcap-bg);
  font-size: var(--fs-xs);
  line-height: var(--lh-base);
  margin-top: var(--sp-3);
}

/* ---------- код и обозначения норм ---------- */
code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

code {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-s);
  overflow-wrap: anywhere;
}

pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: var(--sp-4);
  border-radius: var(--radius-m);
  overflow-x: auto;
}

pre code { background: none; padding: 0; }

/* ---------- формы: базовые размеры ---------- */
input, select, textarea, button {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

/* ---------- контейнеры ---------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--sp-4);
}

@media (min-width: 48rem) {
  .container { padding-inline: var(--sp-5); }
}

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

.section {
  padding-block: var(--sp-7);
}

@media (min-width: 48rem) {
  .section { padding-block: var(--sp-8); }
}

.section--tight { padding-block: var(--sp-6); }

.section--surface { background: var(--color-surface); }
.section--soft { background: var(--color-surface-soft); }

.section--band {
  background: var(--band-bg);
  color: var(--band-text);
}

.section--band h1,
.section--band h2,
.section--band h3,
.section--band h4 { color: var(--band-text); }

.section--band a { color: var(--band-link); }
.section--band .lead,
.section--band .subtle,
.section--band .muted { color: var(--band-muted); }

/* ---------- вспомогательные ---------- */
.lead {
  font-size: var(--fs-l);
  line-height: var(--lh-loose);
  color: var(--color-text-muted);
  max-width: var(--measure);
}

.muted { color: var(--color-text-muted); }
.subtle { color: var(--color-text-subtle); font-size: var(--fs-xs); }

.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;
}

.u-nowrap { white-space: nowrap; }
.u-mt-0 { margin-top: 0; }
.u-mb-0 { margin-bottom: 0; }

/* ---------- сетки ---------- */
.grid {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: 1fr;
}

@media (min-width: 40rem) {
  .grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 60rem) {
  .grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid--2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
}

@media (min-width: 40rem) and (max-width: 59.99rem) {
  .grid--3, .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- ссылка «к содержимому» ---------- */
.skip-link {
  position: absolute;
  left: var(--sp-3);
  top: calc(-1 * var(--sp-9));
  z-index: 100;
  background: var(--skip-bg);
  color: var(--skip-text);
  padding: var(--sp-3) var(--sp-4);
  border-radius: 0 0 var(--radius-m) var(--radius-m);
  text-decoration: none;
  transition: top var(--dur-fast) var(--ease);
}

.skip-link:focus {
  top: 0;
  color: var(--skip-text);
}
