/* ==========================================================================
   layout.css — каркас: шапка, меню, hero-секции, сетки, подвал
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Шапка
   -------------------------------------------------------------------------- */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  height: var(--header-h);
  display: flex;
  align-items: center;
}

/* Подложка шапки — отдельным слоем, чтобы и заливку, и блюр можно было
   погасить книзу маской: нижнего края у шапки нет, она просто тает. */
.header::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 0;
  height: calc(var(--header-h) + clamp(1.5rem, 4vh, 3rem));
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease-out);
  background: linear-gradient(to bottom,
    rgba(10, 10, 10, 0.88) 0%,
    rgba(10, 10, 10, 0.72) 40%,
    rgba(10, 10, 10, 0) 100%);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 40%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 40%, transparent 100%);
}

/* Класс ставит main.js после первых пикселей скролла */
.header.is-scrolled::before { opacity: 1; }

.header__inner {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
}

/* Логотип-ник. Латиница — так и задумано. */
.logo {
  font-family: var(--font-display);
  font-size: var(--step-0);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  white-space: nowrap;
}

/* Пульсирующая точка «на связи» — единственное цветное место на сайте */
.logo__dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 0 rgba(255, 74, 61, 0.6);
  animation: pulse 2.6s var(--ease-out) infinite;
  flex: none;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255, 74, 61, 0.5); }
  70%  { box-shadow: 0 0 0 9px rgba(255, 74, 61, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 74, 61, 0); }
}

/* --- Навигация (десктоп) --- */
.nav { display: flex; align-items: center; gap: clamp(1.25rem, 2.5vw, 2.5rem); }

.nav__link {
  position: relative;
  font-size: var(--step--1);
  letter-spacing: 0.02em;
  color: var(--text-dim);
  padding-block: 0.4rem;
  transition: color var(--dur-fast) var(--ease-out);
}

.nav__link::after {
  content: '';
  position: absolute;
  left: 0; bottom: 0;
  width: 100%; height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--dur) var(--ease-out);
}

.nav__link:hover { color: var(--text); }
.nav__link:hover::after { transform: scaleX(1); }

/* Активная страница: светлый текст и постоянная линия */
.nav__link.is-active { color: var(--text); }
.nav__link.is-active::after { transform: scaleX(1); }

/* --- Кнопка-бургер (только мобильные) --- */
.burger {
  display: none;
  position: relative;
  z-index: 2;
  width: 44px; height: 44px;
  margin-right: -10px;
  align-items: center;
  justify-content: center;
}

.burger__box { position: relative; width: 22px; height: 10px; }

.burger__box span {
  position: absolute;
  left: 0;
  width: 100%; height: 1px;
  background: var(--text);
  transition: transform var(--dur) var(--ease-out), opacity var(--dur-fast) linear;
}

.burger__box span:first-child { top: 0; }
.burger__box span:last-child  { bottom: 0; }

/* Состояние «открыто» — крестик */
.is-menu-open .burger__box span:first-child { transform: translateY(4.5px) rotate(45deg); }
.is-menu-open .burger__box span:last-child  { transform: translateY(-4.5px) rotate(-45deg); }

/* --- Полноэкранное мобильное меню --- */
.menu {
  position: fixed;
  inset: 0;
  z-index: 49;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(var(--header-h) + 2rem) var(--gutter) 2.5rem;
  /* Закрыто: не видно, не кликается, не читается скринридером */
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease-out), visibility var(--dur);
}

.is-menu-open .menu { opacity: 1; visibility: visible; }

.menu__list { display: flex; flex-direction: column; gap: 0.25rem; }

.menu__link {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  font-size: var(--step-4);
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 1.1;
  padding-block: 0.35rem;
  /* Пункты выезжают по очереди: задержку задаёт --i в разметке */
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
  transition-delay: calc(var(--i, 0) * 60ms + 80ms);
}

.is-menu-open .menu__link { opacity: 1; transform: none; }

.menu__link .meta { font-size: 0.7rem; color: var(--text-faint); }
.menu__link.is-active { color: var(--text); }
.menu__link:not(.is-active) { color: var(--text-dim); }

.menu__foot {
  margin-top: auto;
  padding-top: 2.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  border-top: 1px solid var(--line);
}

/* Полоска прогресса чтения — по самому верху экрана.
   У шапки больше нет нижней границы, и линия на её месте висела бы в воздухе. */
.progress {
  position: fixed;
  top: 0; left: 0;
  height: 1px;
  width: 100%;
  background: var(--text);
  transform: scaleX(0);
  transform-origin: left;
  z-index: 51;
  opacity: 0.5;
}

@media (max-width: 860px) {
  .nav { display: none; }
  .burger { display: flex; }
}

/* --------------------------------------------------------------------------
   2. Hero: главный экран
   -------------------------------------------------------------------------- */
.hero {
  position: relative;
  min-height: 100svh;          /* svh корректно учитывает мобильные панели */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding-top: var(--header-h);
  padding-bottom: clamp(2rem, 6vh, 4rem);
  overflow: hidden;
  isolation: isolate;
}

/* Подложка с видео/постером */
.hero__media {
  position: absolute;
  inset: 0;
  z-index: -2;
}

.hero__media img,
.hero__media video {
  width: 100%; height: 100%;
  object-fit: cover;
}

/* Видео лежит поверх постера и проявляется, только когда реально загрузилось.
   Если файла нет — остаётся постер, и это незаметно. */
.hero__media video {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1.2s linear;
}

.hero__media video.is-playing { opacity: 1; }

/* Низ героя уходит в фон страницы: переход к «Что я делаю» идёт
   растворением, а не обрывом кадра по горизонтальной линии. */
.hero::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: clamp(11rem, 32vh, 24rem);
  z-index: -1;
  pointer-events: none;
  /* Последние проценты — уже чистый фон: иначе у самого низа остаётся
     процент-другой кадра и граница всё равно читается полоской. */
  background: linear-gradient(to bottom,
    rgba(10, 10, 10, 0) 0%,
    rgba(10, 10, 10, 0.4) 35%,
    rgba(10, 10, 10, 0.78) 62%,
    rgba(10, 10, 10, 0.97) 85%,
    var(--bg) 94%);
}

/* Затемнение: снизу плотнее, чтобы текст читался */
.hero__media::after {
  content: '';
  position: absolute;
  inset: 0;
  /* Ровная подложка плюс градиент: имя читается и на светлом кадре */
  background:
    linear-gradient(to top, rgba(10,10,10,0.95) 0%, rgba(10,10,10,0.45) 45%, rgba(10,10,10,0.7) 100%),
    rgba(10, 10, 10, 0.35);
  z-index: 1;
}

.hero__inner {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Имя растянуто почти от края до края: типографика — главный герой экрана.
   Кегль считается от ширины окна, поэтому строка держит края на любом экране. */
.hero__title {
  font-family: var(--font-display);
  font-weight: 400;
  text-transform: uppercase;
  font-size: clamp(2.6rem, 14.2vw, 15rem);
  line-height: 0.9;
  letter-spacing: -0.015em;
  margin-bottom: clamp(1.5rem, 3.5vw, 2.5rem);
  white-space: nowrap;

  /* Вход: объектив наводит резкость — имя собирается из расфокуса */
  animation: hero-focus 1.9s var(--ease-out) both;
}

@keyframes hero-focus {
  0% {
    opacity: 0;
    filter: blur(28px);
    transform: scale(1.035);
  }
  55% { opacity: 1; }
  100% {
    opacity: 1;
    filter: blur(0);
    transform: scale(1);
  }
}

/* Края букв в капсе размываются чуть мягче — иначе «V» и «D» теряют форму */
.hero__title .optic { --optic-fade: 0.1em; --optic-blur: 0.028em; }

/* Строка под именем: капслок тем же шрифтом, что и имя, но мелко.
   Разрядка небольшая — это предложение, а не мета-подпись. */
.hero__line {
  font-family: var(--font-display);
  font-size: var(--step-0);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  line-height: 1.55;
  transition-delay: 900ms;
  color: var(--text-dim);
  max-width: 42ch;
  margin-inline: auto;
  margin-bottom: clamp(1.75rem, 4vw, 2.75rem);
  text-wrap: balance;   /* строки делятся поровну, а не «длинная + хвост» */
}

/* На телефоне кегль не роняем — капслок и так читается мельче,
   а вот разрядку убавляем, чтобы строка укладывалась в ширину */
@media (max-width: 560px) {
  .hero__line { letter-spacing: 0.05em; }
}

.hero__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.75rem; }

/* Нижняя строка hero: подсказка о скролле + локация */
.hero__foot {
  position: absolute;
  left: 0; right: 0;
  bottom: clamp(1rem, 3vh, 2rem);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding-inline: var(--gutter);
  max-width: var(--maxw);
  margin-inline: auto;
  pointer-events: none;
}

.scroll-hint { display: flex; align-items: center; gap: 0.7rem; }

/* Вертикальная линия, бегущая вниз — живой «индикатор скролла» */
.scroll-hint__line {
  position: relative;
  width: 1px; height: 46px;
  background: var(--line-strong);
  overflow: hidden;
}

.scroll-hint__line::after {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 1px; height: 50%;
  background: var(--text);
  animation: scroll-run 2.4s var(--ease-in-out) infinite;
}

@keyframes scroll-run {
  0%   { transform: translateY(-100%); }
  100% { transform: translateY(200%); }
}

/* Компактный hero для внутренних страниц */
.page-hero {
  padding-top: calc(var(--header-h) + clamp(4rem, 14vh, 9rem));
  padding-bottom: clamp(2.5rem, 7vh, 5rem);
  border-bottom: 1px solid var(--line);
}

.page-hero__title { margin-bottom: 1.25rem; }

/* --------------------------------------------------------------------------
   3. Сетки
   -------------------------------------------------------------------------- */
/* Работы: 2 колонки на десктопе, крупно — видео должно дышать */
.grid-work {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
  gap: clamp(1.25rem, 3vw, 2.5rem) clamp(1.25rem, 2.5vw, 2rem);
}

/* Три превью для мини-блоков (Лаборатория / Дневник на главной, форматы работы).
   Колонок ровно три: при auto-fit на средних экранах оставалось две,
   а третья карточка уезжала вниз и рядом с ней зияла пустая ячейка. */
.grid-three {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(0.75rem, 2vw, 1.5rem);
}

@media (max-width: 820px) {
  .grid-three { grid-template-columns: minmax(0, 1fr); }

  /* Дневник на главной — шесть кадров, им две колонки идут ровно */
  [data-diary-preview] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  [data-diary-preview] { grid-template-columns: minmax(0, 1fr); }
}

/* --------------------------------------------------------------------------
   4. Подвал
   -------------------------------------------------------------------------- */
.footer {
  border-top: 1px solid var(--line);
  padding-block: clamp(3rem, 7vh, 5rem) 2rem;
}

.footer__top {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  gap: clamp(2rem, 5vw, 4rem);
  margin-bottom: clamp(3rem, 8vh, 5rem);
}

.footer__col-title {
  margin-bottom: 1.1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--line);
}

.footer__links { display: flex; flex-direction: column; gap: 0.6rem; }

.footer__link {
  color: var(--text-dim);
  width: fit-content;
  transition: color var(--dur-fast) var(--ease-out), transform var(--dur) var(--ease-out);
}

.footer__link:hover { color: var(--text); transform: translateX(4px); }

.footer__bottom {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

/* Крупный ник внизу — финальная подпись автора */
.footer__sign {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 13vw, 12rem);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: -0.025em;
  line-height: 0.85;
  color: transparent;
  -webkit-text-stroke: 1px rgba(255, 255, 255, 0.14);
  margin-bottom: clamp(2rem, 5vh, 3.5rem);
  user-select: none;
  white-space: nowrap;
}

/* Избранное на главной: первая работа во всю ширину — задаёт ритм,
   как открывающий кадр. Остальные идут парами. */
@media (min-width: 1024px) {
  .grid-work--featured { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .grid-work--featured > .card:first-child { grid-column: 1 / -1; }

  .grid-work--featured > .card:first-child .card__media { aspect-ratio: 21 / 9; }

  .grid-work--featured > .card:first-child .card__title { font-size: var(--step-2); }
}

/* Браузер заранее знает, что эти два слоя будут двигаться при скролле */
.hero__media,
.hero__inner { will-change: transform; }
