/* База: reset, документ, сетка, шкала текста, состояния движения. Сырых значений здесь нет – только токены. */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100dvh;
  background: var(--color-bg-page);
  color: var(--color-fg);
  font-family: var(--font-text);
  font-weight: var(--fw-book);
  font-size: var(--fs-body-m);
  line-height: var(--lh-body);
  letter-spacing: var(--ls-body);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
  transition: background-color var(--dur-800) var(--ease-inout), color var(--dur-800) var(--ease-inout);
}
/* Инверсия: пока тёмная глава в кадре, страница темнеет целиком (класс ставит motion.js, приём invert) */
html.is-inv body { background: var(--color-bg-dark); color: var(--color-fg-on-dark); }
:focus-visible { outline: var(--focus-width) solid var(--color-accent); outline-offset: var(--focus-offset); border-radius: var(--radius-xs); }
img, video, canvas, svg { display: block; max-width: 100%; }
img, video { height: auto; }
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; padding: 0; }
p, h1, h2, h3, h4 { overflow-wrap: break-word; }
h1, h2, h3 { text-wrap: balance; }
p, li { text-wrap: pretty; }

/* Сетка: контейнер с полями и 12 колонок. Ширина элементов – через grid-column, не через px */
.wrapper {
  width: 100%;
  max-width: calc(var(--container) + 2 * var(--page-margin));
  margin-inline: auto;
  padding-inline: var(--page-margin);
}
.grid-12 {
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  column-gap: var(--gutter);
}
.section {
  padding-block: var(--space-section);
}
.section--dark {
  background: var(--color-bg-dark);
  color: var(--color-fg-on-dark);
}
.section--sheet {
  background: var(--color-bg-sheet);
}

/* Шкала текста (из концепта D). Размер текста в правилах секций не ставится – только эти классы.
   clamp() – только у .display-xl (один H1), записан в базе */
.display-xl { font-family: var(--font-display); font-size: var(--fs-display-xl); line-height: var(--lh-display); letter-spacing: var(--ls-display); font-weight: var(--fw-light); }
.display-l  { font-family: var(--font-display); font-size: var(--fs-display-l);  line-height: var(--lh-display-l); letter-spacing: var(--ls-display-l); font-weight: var(--fw-light); }
.display-m  { font-family: var(--font-display); font-size: var(--fs-display-m);  line-height: var(--lh-display-m); letter-spacing: var(--ls-display-m); font-weight: var(--fw-light); }
.title-l    { font-size: var(--fs-title-l); line-height: var(--lh-title-l); letter-spacing: var(--ls-display-m); font-weight: var(--fw-regular); }
.title-xs   { font-size: var(--fs-title-xs); line-height: var(--lh-title); letter-spacing: var(--ls-title-xs); font-weight: var(--fw-regular); }
.word-xl    { font-size: var(--fs-word); line-height: var(--lh-word); letter-spacing: var(--ls-display); font-weight: var(--fw-light); }
.num-m      { font-size: var(--fs-num-m); line-height: var(--lh-num); letter-spacing: var(--ls-display-m); font-weight: var(--fw-light); }
.label-xl   { font-size: var(--fs-label-xl); line-height: var(--lh-small); }
.card-text  { font-size: var(--fs-label-m); line-height: var(--lh-card-text); }
.title-m    { font-size: var(--fs-title-m); line-height: var(--lh-title); letter-spacing: var(--ls-display-m); font-weight: var(--fw-regular); }
.title-s    { font-size: var(--fs-title-s); line-height: var(--lh-title-s); letter-spacing: var(--ls-title-s); font-weight: var(--fw-medium); }
.title-xxs  { font-size: var(--fs-title-xxs); line-height: var(--lh-title); font-weight: var(--fw-medium); }
.body-l     { font-size: var(--fs-body-l); line-height: var(--lh-lead); letter-spacing: var(--ls-lead); }
.body-m     { font-size: var(--fs-body-m); line-height: var(--lh-body); }
.body-s     { font-size: var(--fs-body-s); line-height: var(--lh-small); }
.ui-m       { font-size: var(--fs-ui-m); line-height: var(--lh-ui); }
.ui-xs      { font-size: var(--fs-ui-xs); line-height: var(--lh-ui); }
.ui-s       { font-size: var(--fs-ui-s); line-height: var(--lh-ui); }
.label-l    { font-size: var(--fs-label-l); line-height: var(--lh-small); }
.label-m    { font-size: var(--fs-label-m); line-height: var(--lh-small); }
.num-unit   { font-size: var(--fs-num-unit); color: var(--color-fg-faint); margin-left: var(--space-2); }
.step-num   { font-size: var(--fs-step-num); line-height: var(--lh-num); letter-spacing: var(--ls-num); font-weight: var(--fw-light); color: transparent; -webkit-text-stroke: 1px var(--color-step-stroke); }
.num-l      { font-size: var(--fs-num-l); line-height: var(--lh-num); letter-spacing: var(--ls-num); font-weight: var(--fw-light); }
.serif      { font-family: var(--font-serif); font-style: italic; font-weight: var(--fw-strong); }
.muted      { color: var(--color-fg-muted); }
.section--dark .muted { color: var(--color-fg-muted-on-dark); }

/* Смена почерка в H1 (приём glyph-swap, docs/motion.md): у каждой буквы два начертания, видно одно.
   Размеры антиквы – здесь, в шкале, потому что это кегль */
.glyph-word { display: inline-block; white-space: nowrap; }
.glyph { display: inline-block; position: relative; text-align: center; width: var(--wg, auto); transition: width var(--dur-600) var(--ease-out); }
.glyph.is-serif { width: var(--ws, auto); }
html:not(.has-motion) .glyph, html:not(.has-motion) .glyph__g, html:not(.has-motion) .glyph__s { transition: none; }
.glyph__g, .glyph__s { display: block; transition: transform var(--dur-450) var(--ease-out), opacity var(--dur-300); }
.glyph__s { position: absolute; inset: 0; font-family: var(--font-serif); font-style: italic; font-weight: var(--fw-strong); font-size: var(--fs-glyph-serif); line-height: var(--lh-glyph-serif); letter-spacing: 0; transform: translateY(40%); opacity: 0; }
.glyph.is-serif .glyph__g { transform: translateY(-40%); opacity: 0; }
.glyph.is-serif .glyph__s { transform: none; opacity: 1; }

@media (max-width: 1100px) { .display-l { font-size: var(--fs-display-l-tablet); } }
@media (max-width: 900px) { .step-num { font-size: var(--fs-step-num-mobile); } }
@media (max-width: 500px) {
  .display-l { font-size: var(--fs-display-l-mobile); }
  .display-m { font-size: var(--fs-display-m-mobile); }
  .title-m { font-size: var(--fs-title-m-mobile); }
}

/* Движение: пока JS не подготовил элемент, он скрыт – но только когда движение включено (html.has-motion).
   Без JS, в ?static и при prefers-reduced-motion класса нет, и всё видно сразу */
.has-motion [data-reveal]:not(.is-ready) { visibility: hidden; }

/* Холст сцены: единственное абсолютное позиционирование по умолчанию (docs/scene.md) */
[data-scene] { position: relative; }
[data-scene] canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: var(--z-scene); }
[data-scene] > :not(canvas) { position: relative; z-index: var(--z-content); }
[data-scene].is-live .scene__fallback { display: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

@media (max-width: 768px) {
  .section { padding-block: var(--space-section-mobile); }
}
