/* =========================================================================
   Спутник акына — стили сайта-КНИГИ.
   Принцип: радикальный минимализм, off-black/off-white, мягкий книжный шрифт,
   спокойная типографика. Всё на токенах — править в одном месте (секция 2).
   Структура:
     1. Шрифты (self-hosted)
     2. Токены (палитра, типошкала, отступы, анимация) + плавная тема
     3. База и сброс
     4. Каркас: шапка (+следы-прогресс), колонка, подвал, переключатель темы
     5. Текст главы (.prose)
     6. Заголовок главы, дата, навигация
     7. Оглавление (.toc)
     8. 404 и вспомогательное
     9. Переходы между страницами, адаптив, reduced-motion
   ========================================================================= */

/* 1. ШРИФТЫ ---------------------------------------------------------------
   Вариативные (один файл = все насыщенности). Кириллица и латиница — отдельно. */

@font-face {
  font-family: "Literata"; font-style: normal; font-weight: 200 900; font-display: swap;
  src: url("/assets/fonts/literata-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Literata"; font-style: normal; font-weight: 200 900; font-display: swap;
  src: url("/assets/fonts/literata-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2122, U+2212, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Literata"; font-style: italic; font-weight: 200 900; font-display: swap;
  src: url("/assets/fonts/literata-cyrillic-italic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Literata"; font-style: italic; font-weight: 200 900; font-display: swap;
  src: url("/assets/fonts/literata-latin-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2122, U+2212, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Golos Text"; font-style: normal; font-weight: 400 900; font-display: swap;
  src: url("/assets/fonts/golos-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Golos Text"; font-style: normal; font-weight: 400 900; font-display: swap;
  src: url("/assets/fonts/golos-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2122, U+2212, U+FEFF, U+FFFD;
}

/* 2. ТОКЕНЫ --------------------------------------------------------------- */

/* Регистрируем переменные, которые должны ПЛАВНО интерполироваться:
   цвета → синхронная смена темы; --read → плавный прогресс чтения.
   (--dark и --hover НЕ регистрируем: первый меняется мгновенно, второй — косметика.) */
@property --bg        { syntax: "<color>";  inherits: true; initial-value: #faf9f6; }
@property --text      { syntax: "<color>";  inherits: true; initial-value: #1b1b1a; }
@property --muted     { syntax: "<color>";  inherits: true; initial-value: #6f6c66; }
@property --rule      { syntax: "<color>";  inherits: true; initial-value: #e7e3da; }
@property --underline { syntax: "<color>";  inherits: true; initial-value: #cbc6ba; }
@property --read      { syntax: "<number>"; inherits: true; initial-value: 0; }

:root {
  /* — Палитра (светлая). --dark и --hover остаются обычными переменными. — */
  --dark: 0;
  --bg: #faf9f6;            /* off-white */
  --text: #1b1b1a;          /* off-black */
  --muted: #6f6c66;         /* служебное: даты, подписи */
  --rule: #e7e3da;          /* линии-разделители и базовый след */
  --underline: #cbc6ba;     /* подчёркивание ссылок */
  --hover: rgba(0, 0, 0, .04);

  /* — Шрифты — */
  --font-serif: "Literata", Georgia, "Times New Roman", serif;
  --font-sans: "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-num: var(--font-sans);  /* «структурные числа» (номера глав, маркеры списков) */

  /* — Типошкала: ВСЕГО 3 роли (+ шапка отдельно) — */
  --fs-body: clamp(1.0625rem, 0.98rem + 0.42vw, 1.3125rem); /* текст, Literata, 17→21px */
  --fs-heading: clamp(2rem, 1.6rem + 2.4vw, 3rem);          /* заголовки, Golos, 32→48px */
  --fs-small: 0.875rem;                                     /* мелкие подписи, 14px */
  --step-h2: 1.4;          /* H2 = body × 1.4 */
  --step-h3: 1.15;         /* H3 = body × 1.15 */
  --leading: 1.62;
  --measure: 42rem;        /* колонка чтения (~66 знаков) */
  --page-pad: clamp(1.1rem, 5vw, 2rem);

  /* — Шапка (вне типошкалы). Значения — для страниц глав; на главной крупнее (ниже). — */
  --fs-brand: 0.95rem;
  --brand-slot: 36px;
  --brand-logo: 30px;
  --brand-icon: 20px;
  --brand-gap: 6px;

  /* — Отступы: единая сетка (база 4px) — */
  --space-1: 0.25rem;  --space-2: 0.5rem;  --space-3: 0.75rem; --space-4: 1rem;
  --space-5: 1.5rem;   --space-6: 2rem;    --space-7: 3rem;    --space-8: 4rem;  --space-9: 6rem;

  /* — Анимация: ОДИН словарь длительностей и кривых — */
  --dur-fast: 0.18s;   /* ховеры, фокус, подчёркивания */
  --dur-mid: 0.3s;     /* переход страниц, своп иконок */
  --dur-slow: 0.45s;   /* смена темы + переключатель (единая длительность!) */
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);  /* ховеры, въезд */
  --ease-soft: cubic-bezier(0.66, 0, 0.34, 1);    /* палитра + слоты переключателя */

  /* — Маска следов прогресса чтения — */
  --footprints: url("/assets/footprints.svg");
}

/* Тёмная палитра: (1) по системе, если тема не выбрана вручную; (2) при data-theme="dark". */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --dark: 1; --bg: #121212; --text: #e9e6df; --muted: #9c988f;
    --rule: #2b2b29; --underline: #4a463d; --hover: rgba(255, 255, 255, .05);
  }
}
:root[data-theme="dark"] {
  --dark: 1; --bg: #121212; --text: #e9e6df; --muted: #9c988f;
  --rule: #2b2b29; --underline: #4a463d; --hover: rgba(255, 255, 255, .05);
}

/* На ГЛАВНОЙ шапка крупнее — переопределяем только токены бренда. */
.page-home {
  --fs-brand: 1.4rem;
  --brand-slot: 64px;
  --brand-logo: 52px;
  --brand-icon: 30px;
  --brand-gap: 10px;
}

/* ДИРИЖЁР плавной темы: анимируем САМИ переменные на :root — все потребители
   (фон, текст, линии, даты, иконки, шапка, следы) меняются СИНХРОННО, без вспышек. */
:root {
  transition:
    --bg var(--dur-slow) var(--ease-soft),
    --text var(--dur-slow) var(--ease-soft),
    --muted var(--dur-slow) var(--ease-soft),
    --rule var(--dur-slow) var(--ease-soft),
    --underline var(--dur-slow) var(--ease-soft);
}

/* 3. БАЗА И СБРОС --------------------------------------------------------- */

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

/* Убираем системную синюю вспышку при тапе (выбивается из ч/б).
   Своя тихая обратная связь остаётся через :active. */
* { -webkit-tap-highlight-color: transparent; }

html {
  color-scheme: light dark;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: var(--fs-body);
  line-height: var(--leading);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  font-synthesis: none;
  min-height: 100vh;          /* прижимаем подвал к низу */
  display: flex;
  flex-direction: column;
}

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

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
  transition: text-decoration-color var(--dur-fast) var(--ease-out);
}
/* Подсветка: на мыши — при наведении; на тач-экране — кратко при нажатии (не залипает) */
@media (hover: hover) { a:hover { text-decoration-color: currentColor; } }
a:active { text-decoration-color: currentColor; }

img { max-width: 100%; height: auto; }

/* Видимое кольцо фокуса для клавиатуры (доступность) */
:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; border-radius: 2px; }

/* 4. КАРКАС --------------------------------------------------------------- */

.content,
.site-footer {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--page-pad);
}

.content { flex: 1 0 auto; padding-block: var(--space-5) var(--space-9); }

/* Шапка зафиксирована сверху (sticky), во всю ширину; содержимое — в колонке. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
}
@supports (backdrop-filter: blur(1px)) {
  .site-header {
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
}
.site-header__inner {
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--page-pad);
  padding-block: var(--space-3);
  display: flex;
  align-items: center;
}
.page-home .site-header__inner { padding-block: var(--space-4); }

.brand { display: flex; align-items: center; gap: var(--space-3); }
.page-home .brand { gap: var(--space-4); }
.brand__name {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: var(--fs-brand);
  letter-spacing: 0.01em;
  text-decoration: none;
  color: inherit;
}
.page-home .brand__name { letter-spacing: 0; }

/* — Переключатель темы: иконка (луна/солнце) и логотип меняются местами. — */
.switch {
  --slot: var(--brand-slot);
  --gap: var(--brand-gap);
  position: relative;
  width: calc(var(--slot) * 2 + var(--gap));
  height: var(--slot);
  flex: none;
}
.switch__toggle,
.switch__logo {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--slot);
  height: var(--slot);
  display: grid;
  place-items: center;
  transition: transform var(--dur-slow) var(--ease-soft);
}
.switch__logo   { transform: translateX(calc(var(--dark) * (var(--slot) + var(--gap)))); }
.switch__toggle { transform: translateX(calc((1 - var(--dark)) * (var(--slot) + var(--gap)))); }

.switch__logo { text-decoration: none; }
.switch__logo img {
  display: block;
  width: var(--brand-logo);
  height: auto;
  filter: invert(var(--dark));  /* чёрная графика → белая в тёмной теме */
  transition: filter var(--dur-slow) var(--ease-soft);
}

.switch__toggle {
  margin: 0; padding: 0; border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 50%;
}
/* мягкий кружок при наведении/фокусе + увеличенная зона нажатия */
.switch__toggle::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: var(--hover);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
}
@media (hover: hover) { .switch__toggle:hover::before { opacity: 1; } }
.switch__toggle:active::before { opacity: 1; }

.switch__icons { position: relative; width: var(--brand-icon); height: var(--brand-icon); }
.switch__icons .ic {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity var(--dur-slow) var(--ease-soft), transform var(--dur-slow) var(--ease-soft);
}
.ic--sun  { opacity: calc(1 - var(--dark)); transform: rotate(calc(var(--dark) * -90deg)) scale(calc(1 - var(--dark) * 0.35)); }
.ic--moon { opacity: var(--dark);           transform: rotate(calc((1 - var(--dark)) * 90deg)) scale(calc(1 - (1 - var(--dark)) * 0.35)); }

/* — Следы-прогресс чтения по нижней кромке шапки (только на главах) — */
.reading-progress {
  position: relative;
  height: 14px;
  pointer-events: none;
}
.reading-progress::before,
.reading-progress::after {
  content: "";
  position: absolute;
  inset: 0;
  -webkit-mask: var(--footprints) repeat-x left center / 44px 14px;
  mask: var(--footprints) repeat-x left center / 44px 14px;
}
.reading-progress::before { background: var(--rule); }     /* весь путь — едва заметно */
.reading-progress::after {                                  /* пройденный путь — чуть заметнее */
  background: var(--muted);
  clip-path: inset(0 calc((1 - var(--read)) * 100%) 0 0);
}

/* — Подвал: одна маленькая иконка (RSS на главной / «Поделиться» на главах) — */
.site-footer {
  flex-shrink: 0;
  padding-block: var(--space-8);
  text-align: center;
}
.iconbtn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--muted);
  background: transparent;
  border: 0;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
@media (hover: hover) { .iconbtn:hover { color: var(--text); background: var(--hover); } }
.iconbtn:active { color: var(--text); background: var(--hover); transform: scale(0.94); }
.iconbtn .ic {
  width: 20px; height: 20px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
/* «Поделиться» → галочка при копировании */
.iconbtn__icons { position: relative; width: 20px; height: 20px; }
.iconbtn__icons .ic { position: absolute; inset: 0; transition: opacity var(--dur-mid) var(--ease-out), transform var(--dur-mid) var(--ease-out); }
.ic--check { opacity: 0; transform: scale(0.6); }
.is-copied .ic--share { opacity: 0; transform: scale(0.6); }
.is-copied .ic--check { opacity: 1; transform: scale(1); }

/* 5. ТЕКСТ ГЛАВЫ ---------------------------------------------------------- */

.prose { overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose p { margin: 0 0 1.4em; }              /* ~одна строка, относительно абзаца */
.prose li > p { margin: 0; }                  /* «рыхлые» списки: не разрывать пункты */

.prose h2, .prose h3 {
  font-family: var(--font-sans);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: var(--space-6) 0 var(--space-2);
}
.prose h2 { font-size: calc(var(--fs-body) * var(--step-h2)); }
.prose h3 { font-size: calc(var(--fs-body) * var(--step-h3)); }

.prose ul, .prose ol { margin: 0 0 1.4em; padding-left: 1.4em; }
.prose li { margin: var(--space-1) 0; }
.prose li::marker { color: var(--muted); }
/* Единый стиль чисел: маркеры нумерованных списков — тем же гротеском (как номера глав) */
.prose ol { font-variant-numeric: tabular-nums; }
.prose ol > li::marker { font-family: var(--font-num); color: var(--muted); }

.prose blockquote {
  margin: var(--space-5) 0;
  padding-left: var(--space-4);
  border-left: 2px solid var(--rule);
  color: var(--muted);
  font-style: italic;
}

.prose hr { border: 0; border-top: 1px solid var(--rule); margin: var(--space-6) 0; }

/* Фотографии — во всю ширину колонки; мягкий плейсхолдер на время загрузки */
.prose img {
  display: block;
  width: 100%;
  margin: var(--space-6) 0;
  border-radius: 2px;
  background: var(--hover);
}

.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--hover);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

/* 6. ЗАГОЛОВОК ГЛАВЫ, ДАТА, НАВИГАЦИЯ ------------------------------------ */

.chapter__date {
  display: block;
  text-align: center;
  font-family: var(--font-sans);
  font-size: var(--fs-small);
  color: var(--muted);
  margin-bottom: var(--space-2);
}

/* Заголовок главы — первый H1 (#) из markdown */
.prose > h1:first-child {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: var(--fs-heading);
  line-height: 1.12;
  letter-spacing: -0.02em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  margin: 0 0 var(--space-6);
}

.chapter-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;  /* пред. · Поделиться · след. */
  gap: var(--space-4);
  align-items: center;
  margin-top: var(--space-7);
  padding-top: var(--space-5);
  border-top: 1px solid var(--rule);
  font-family: var(--font-sans);
  font-size: var(--fs-small);
}
.chapter-nav a { text-decoration: none; color: var(--muted); transition: color var(--dur-fast) var(--ease-out); }
@media (hover: hover) { .chapter-nav a:hover { color: var(--text); } }
.chapter-nav a:active { color: var(--text); }
.chapter-nav__cell--prev { text-align: left; }
.chapter-nav__cell--share { display: flex; justify-content: center; }
.chapter-nav__cell--next { text-align: right; }

/* 7. ОГЛАВЛЕНИЕ ----------------------------------------------------------- */

.toc { list-style: none; margin: var(--space-4) 0 0; padding: 0; }
.toc__item { border-top: 1px solid var(--rule); }
.toc__item:last-child { border-bottom: 1px solid var(--rule); }

.toc__link {
  display: block;
  padding: var(--space-5) var(--space-2);
  border-radius: var(--space-3);  /* мягкие, скруглённые углы подсветки */
  text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease-out);
}
@media (hover: hover) { .toc__link:hover { background: var(--hover); } }
.toc__link:active { background: var(--hover); }
.toc__link:focus-visible { outline-offset: -2px; }

.toc__title {
  font-family: var(--font-num);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  display: block;
}
.toc__excerpt {
  font-family: var(--font-serif);
  font-size: var(--fs-small);
  color: var(--muted);
  display: block;
  margin-top: var(--space-1);
}

/* 8. 404 И ВСПОМОГАТЕЛЬНОЕ ------------------------------------------------ */

.notfound { text-align: center; padding: var(--space-7) 0; }
.notfound__code {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: var(--fs-heading);
  margin: 0 0 var(--space-2);
}
.notfound__text { color: var(--muted); }

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

.skip-link {
  position: absolute;
  left: -9999px; top: 0;
  background: var(--text);
  color: var(--bg);
  padding: 0.6em 1em;
  z-index: 30;
}
.skip-link:focus { left: 0.5rem; top: 0.5rem; }

/* 9. ПЕРЕХОДЫ, АДАПТИВ, REDUCED-MOTION ----------------------------------- */

/* Мягкий кроссфейд между страницами; шапку и подвал из анимации исключаем,
   чтобы не мигали/не прыгали. */
@view-transition { navigation: auto; }
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: var(--dur-mid);
  animation-timing-function: var(--ease-out);
}
.site-header { view-transition-name: site-header; }
.site-footer { view-transition-name: site-footer; }
::view-transition-group(site-header),
::view-transition-group(site-footer) { animation: none; }

/* Маленькие телефоны: лёгкий откат размеров шапки на главной (чтобы не переносилась) */
@media (max-width: 30rem) {
  .page-home { --fs-brand: 1.15rem; --brand-slot: 48px; --brand-logo: 40px; --brand-icon: 24px; }
}

/* Очень большие экраны — ТВ и проекторы: крупнее текст и шире колонка */
@media (min-width: 100rem) {
  :root { --measure: 46rem; --fs-body: 1.5rem; }
}

/* Уважаем системную настройку «меньше движения» */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}
