/* =====================================================================
   Портфолио Марии Карпачевой — стили

   Порядок:      1. Шрифты   2. Токены   3. База   4. Компоненты
                 5. Главная   6. Кейс   7. Визуальный кейс   8. 404
                 9. Производительность и доступность

   Подход:       базовые значения — десктоп (макет Figma, 1440),
                 медиазапросы ниже уточняют их для меньших экранов.

   Точки перестройки (в CSS нельзя хранить их в переменных, поэтому список здесь):
     1199px  — планшет: типографика кейсов как во Framer на 810
     1023px  — поля страницы 16px, hero с картинкой для планшета
      809px  — телефон: колонки в одну, мобильные картинки, типографика 390
      639px  — карточки проектов по одной в ряд, hero с картинкой для телефона
      420px  — узкий телефон: компактная шапка и футер
   ===================================================================== */


/* =============================== 1. ШРИФТЫ =============================== */

@font-face {
  font-family: "Onest";
  /* WOFF2 21 КБ; предзагружается через <link rel="preload"> в <head>, кеш 30 дней */
  src: url("fonts/onest-medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: block;   /* текст ждёт шрифт и не «перещёлкивается» */
}

/* Запасной шрифт с метриками Onest: если основной задержится,
   текст займёт столько же места и ничего не сдвинется */
@font-face {
  font-family: "Onest Fallback";
  src: local("Arial"), local("ArialMT"), local("Liberation Sans"), local("Helvetica");
  size-adjust: 91.4%;
  ascent-override: 106.1%;
  descent-override: 33.4%;
  line-gap-override: 0%;
}


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

:root {
  /* цвета из Figma */
  --c-page: #ffffff;
  --c-black: #333333;
  --c-grey: rgba(51, 51, 51, 0.48);
  --c-grey-strong: rgba(51, 51, 51, 0.72);     /* текст на цветной плашке */
  --c-blue: #007aff;
  --c-blue-hero: #2949d6;
  --c-green: #0dc268;
  --c-tag: #0670e3;
  --c-hero-bg: #99caff;                          /* цвет левого края hero-картинки */
  --c-line: rgba(51, 51, 51, 0.12);
  --c-seg-bg: rgba(118, 118, 128, 0.12);
  --c-surface: #f2f2f4;                          /* фон под картинками, теги, плашки */
  --c-hover: rgba(41, 73, 214, 0.08);            /* подсветка пунктов при наведении */
  --c-yellow-bg: rgba(255, 219, 30, 0.2);        /* гипотеза, user flow (Т-Банк) */
  --c-blue-bg: rgba(103, 164, 245, 0.2);         /* гипотеза в кейсах Fidelio */

  /* «стекло» шапки и кнопок слайдера */
  --glass-bg: rgba(255, 255, 255, 0.62);
  --glass-border: rgba(255, 255, 255, 0.7);
  --glass-shadow:
    0 1px 2px rgba(20, 40, 100, 0.06),
    0 8px 28px rgba(20, 40, 100, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  --glass-blur: blur(20px) saturate(1.6);

  /* сетка */
  --container: 1280px;                           /* главная и визуальные кейсы */
  --case-width: 1104px;                          /* колонка продуктового кейса */
  --gutter: clamp(16px, 5.556vw, 80px);          /* 80px при 1440, 16px на телефоне */
  --radius-card: 16px;

  --ease-morph: cubic-bezier(0.22, 1, 0.36, 1);  /* анимация шапки, как у nikamakes.design */
}


/* =============================== 3. БАЗА =============================== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--c-page);
  color: var(--c-black);
  font-family: "Onest", "Onest Fallback", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 500;
  font-size: 16px;
  line-height: 1.25;
  -webkit-font-smoothing: antialiased;
}
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p, ul { margin: 0; padding: 0; font-weight: 500; }
ul { list-style: none; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--c-blue); outline-offset: 2px; }

.container {
  width: 100%;
  max-width: calc(var(--container) + var(--gutter) * 2);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.container--case   { max-width: calc(var(--case-width) + 32px); padding-inline: 16px; }
.container--visual { max-width: calc(var(--container) + 32px); padding-inline: 16px; }

/* цветные фрагменты текста */
.accent { color: var(--c-blue-hero); }
.dark   { color: var(--c-black); }
.green  { color: var(--c-green); }


/* =============================== 4. КОМПОНЕНТЫ =============================== */

/* ---------- Стекло: шапка и кнопки слайдера ---------- */
.header__nav,
.slider__btn {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .header__nav { background: rgba(255, 255, 255, 0.92); }
}

/* ---------- Шапка ---------- */
.header {
  position: fixed;
  top: 16px;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  justify-content: center;
  padding-inline: 16px;
  pointer-events: none;
}
.header__nav {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 4px;                 /* 4px между пунктами и до краёв, как в Figma */
  height: 60px;
  padding: 0 4px;
  border-radius: 16px;
}

/* пункты: фиксированная ширина, как во фреймах Figma, — шапка не меняет размер */
.header__link,
.header__back,
.header__avatar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 52px;
  border-radius: 12px;
  white-space: nowrap;
  font-size: 14px;
  line-height: 18px;
  letter-spacing: -0.08px;
}
.header__link { transition: background-color .2s ease, color .2s ease; }
.header__link[href*="disk.yandex"]      { width: 52px; }    /* CV */
.header__link[href*="mkarp_design"]     { width: 92px; }    /* Блог в тг */
.header__link[href*="karpacheva_maria"] { width: 102px; }   /* Связаться */
.header__link:hover,
.header__back:hover { background: var(--c-hover); color: var(--c-blue-hero); }

.header__avatar { width: 52px; }
.header__avatar img { width: 52px; height: 52px; border-radius: 12px; object-fit: cover; }

.header__divider {
  width: 1px;
  height: 32px;
  margin: 0 -0.5px;         /* в Figma линия нулевой ширины: итог 328px */
  background: var(--c-line);
}

/* Кнопка «Назад»: на кейсах раскрыта, на главной и 404 свёрнута.
   При переходе главная ↔ кейс шапка плавно раздвигается или схлопывается:
   script.js ставит на <html> класс nav-from-*, а через кадр снимает его. */
.header__back,
.header__avatar {
  overflow: hidden;
  transition:
    width .42s var(--ease-morph),
    margin .42s var(--ease-morph),
    opacity .3s ease,
    background-color .2s ease,
    color .2s ease;
}
.header__back { gap: 6px; width: 100px; color: var(--c-black); }
.header__back--home,
html.nav-from-home .header__back--case { width: 0; margin-right: -4px; opacity: 0; pointer-events: none; }
html.nav-from-case .header__back--home { width: 100px; margin-right: 0; opacity: 1; }

/* ---------- Карточка проекта (главная и 404) ---------- */
.card { display: flex; flex-direction: column; gap: 16px; }
.card[hidden] { display: none; }

.card__media {
  position: relative;
  aspect-ratio: 630 / 540;  /* при сужении уменьшаются и ширина, и высота */
  border-radius: var(--radius-card);
  overflow: hidden;
  background: var(--c-surface);
  isolation: isolate;
}
.card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  transition: transform .5s cubic-bezier(.2, .7, .2, 1);
}
.card__media::after {       /* затемнение при наведении */
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(30, 30, 30, 0.55);
  opacity: 0;
  transition: opacity .3s ease;
}
.card__cta {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 16px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .3s ease;
}
.card__chips {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  transition: opacity .3s ease, transform .3s ease;
}
.card__chips li {
  background: rgba(228, 228, 228, 0.85);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.card__text { display: flex; flex-direction: column; gap: 6px; }
.card__title { font-size: clamp(18px, 1.667vw, 24px); line-height: 1.1; letter-spacing: -0.02em; }
.card__subtitle { font-size: clamp(14px, 1.111vw, 16px); line-height: 1.25; color: var(--c-grey); }

/* наведение — только на устройствах с мышью; на телефоне теги видны сразу */
@media (hover: hover) {
  .card__chips { opacity: 0; transform: translateY(6px); }
  .card:hover .card__media::after, .card:focus-visible .card__media::after,
  .card:hover .card__cta,          .card:focus-visible .card__cta,
  .card:hover .card__chips,        .card:focus-visible .card__chips { opacity: 1; }
  .card:hover .card__chips,        .card:focus-visible .card__chips { transform: none; }
  .card:hover .card__media img { transform: scale(1.03); }
}

/* ---------- Тег-«чип»: на карточке и в шапке визуального кейса ---------- */
.card__chips li,
.case__tags li {
  display: flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 18px;
  letter-spacing: -0.08px;
  color: var(--c-black);
}

/* ---------- Сетка карточек ---------- */
.projects__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 20px;
  row-gap: clamp(32px, 2.778vw, 40px);
}

/* ---------- Футер ---------- */
.footer { margin-top: clamp(64px, 8.333vw, 120px); padding-bottom: 42px; }
.footer__inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding-top: 20px;
  border-top: 1px solid var(--c-line);
  color: var(--c-grey);
}
.footer__inner > :last-child { justify-self: end; }
.footer__inner a { transition: color .2s ease; }
.footer__inner a:hover { color: var(--c-blue); }


/* =============================== 5. ГЛАВНАЯ =============================== */

/* ---------- Hero: текст поверх картинки; картинка во всю ширину, 1440×500 ---------- */
.hero { position: relative; background: var(--c-hero-bg); }
.hero picture { display: block; }
.hero__image { width: 100%; height: auto; aspect-ratio: 1440 / 500; }
.hero__content {
  position: absolute;
  top: 30%;                 /* 150px из 500 при 1440, как в Figma */
  left: 0;
  right: 0;                 /* .container даёт тот же отступ, что у блока «Проекты» */
  z-index: 1;
}
.hero__title {
  max-width: 46.8vw;                          /* 673px при 1440 */
  font-size: clamp(32px, 3.889vw, 84px);      /* 56px */
  line-height: 1;
  letter-spacing: -0.028em;
  color: #000;
}
.hero__lead {
  max-width: max(28.7vw, 300px);              /* 413px */
  margin-top: 1.389vw;                        /* 20px */
  font-size: clamp(16px, 1.389vw, 30px);      /* 20px */
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--c-blue-hero);
}
.hero__tags { display: flex; gap: clamp(6px, 0.417vw, 10px); margin-top: 2.778vw; }   /* 40px */
.hero-tag {
  display: flex;
  align-items: center;
  height: clamp(40px, 3.889vw, 84px);         /* 56px */
  padding: 0 clamp(14px, 1.389vw, 30px);      /* 20px */
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: clamp(12px, 1.111vw, 24px);
  background: var(--c-tag);
  box-shadow: inset -3px -2px 10px rgba(255, 255, 255, 0.35);
  color: #fff;
  font-size: clamp(16px, 1.667vw, 36px);      /* 24px */
  line-height: 1.2;
  letter-spacing: -0.02em;
}

/* ---------- Проекты ---------- */
.projects { margin-top: clamp(40px, 4.444vw, 64px); }   /* 64px при 1440 */
.projects__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: clamp(24px, 2.778vw, 40px);
}
.projects__title { font-size: clamp(28px, 2.778vw, 40px); line-height: 1; letter-spacing: -0.02em; color: var(--c-blue); }
.projects__count { margin-left: 4px; color: var(--c-grey); }
.projects__empty { padding: 80px 0; text-align: center; color: var(--c-grey); }

/* переключатель «Продукт / Визуал / Концепты» */
.segmented {
  display: flex;
  gap: 4px;
  width: 467px;
  max-width: 100%;
  height: 44px;
  padding: 2px;
  border-radius: 10px;
  background: var(--c-seg-bg);
}
.segmented__option {
  flex: 1 1 0;
  min-width: 0;
  padding: 0 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 14px;
  line-height: 18px;
  letter-spacing: -0.08px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background-color .2s ease, box-shadow .2s ease;
}
.segmented__option.is-active { background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06); }


/* =============================== 6. КЕЙС =============================== */

.case { padding-top: 100px; }

/* ---------- Шапка кейса ---------- */
.case__intro {
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--c-line);
}
.case__back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  align-self: flex-start;
  color: var(--c-grey);
  transition: color .2s ease;
}
.case__back:hover { color: var(--c-blue); }
.case__heading { display: flex; flex-direction: column; gap: 16px; max-width: 895px; }
.case__title { font-size: 40px; line-height: 1.1; letter-spacing: -0.02em; color: var(--c-blue); }
.case__role { color: var(--c-grey); }

/* ---------- Разделы ---------- */
.case__body {
  display: flex;
  flex-direction: column;
  gap: clamp(48px, 4.444vw, 64px);
  margin-top: 40px;
}
.case-section { --section-gap: clamp(24px, 2.778vw, 40px); display: flex; flex-direction: column; gap: var(--section-gap); }
.case-section > .case-h { margin-bottom: calc(20px - var(--section-gap)); }   /* заголовок ближе к содержимому: 20px */

.case-h { font-size: 32px; line-height: 1.19; letter-spacing: -0.02em; color: var(--c-black); }

.case-text { display: flex; flex-direction: column; gap: 8px; }
.case-text p,
.case-list { max-width: 1104px; font-size: 20px; line-height: 1.4; letter-spacing: -0.01em; color: var(--c-grey); }
.case-text p + p { margin-top: 12px; }
.case-list li { padding-left: 1.1em; text-indent: -1.1em; }
.case-list li::before { content: "– "; }

/* «Задача / Результаты» в две колонки; если «Результатов» нет — в одну */
.case-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.case-summary:has(> :only-child) { grid-template-columns: 1fr; }
.case-summary:has(> :only-child) .case-summary__text { max-width: 760px; }
.case-summary__item { display: flex; flex-direction: column; gap: 4px; }
.case-summary__text { font-size: 20px; line-height: 1.2; letter-spacing: -0.01em; color: var(--c-grey); }

/* ---------- Картинка ---------- */
.case-figure { display: flex; justify-content: center; margin: 0; border-radius: var(--radius-card); overflow: hidden; }
.case-figure--flat { border-radius: 0; }
.case-figure picture { display: block; width: 100%; }
.case-figure img { width: 100%; height: auto; }

/* только для десктопа / только для телефона (переключаются в медиазапросе телефона) */
.case-figure--mob,
.slide--mob { display: none; }

/* ---------- Гипотеза ---------- */
.hypothesis {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 20px;
  border-radius: var(--radius-card);
  background: var(--c-yellow-bg);
}
.hypothesis--blue { background: var(--c-blue-bg); }
.hypothesis__icon { flex: none; position: relative; width: 48px; height: 48px; }
.hypothesis__icon img { position: absolute; top: 0; left: -1.95px; width: 52px; height: 55px; max-width: none; }   /* SVG с тенью 52×55 */
.hypothesis__text { display: flex; flex-direction: column; gap: 4px; }
.hypothesis__title { font-size: 24px; line-height: 1.2; letter-spacing: -0.02em; color: var(--c-black); }
.hypothesis__text p { font-size: 20px; line-height: 1.2; letter-spacing: -0.01em; color: var(--c-grey); }

/* ---------- Нумерованный user flow ---------- */
.case-flow { padding: 24px; border-radius: var(--radius-card); background: var(--c-yellow-bg); }
.case-flow__title,
.case-more__title { font-size: clamp(20px, 1.667vw, 24px); line-height: 1.2; letter-spacing: -0.02em; color: var(--c-black); }
.case-flow__title { margin-bottom: 16px; }
.case-flow__list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
  font-size: 20px;
  line-height: 1.4;
  letter-spacing: -0.01em;
  color: var(--c-grey-strong);
}
.case-flow__list li { counter-increment: step; display: flex; align-items: baseline; gap: 10px; }   /* номер на базовой линии первой строки */
.case-flow__list li::before {
  content: counter(step) ".";
  flex: none;
  min-width: 1.4em;         /* контейнер номера одной ширины у всех пунктов */
  text-align: right;        /* номера выровнены по правому краю контейнера */
  color: var(--c-black);
  font-variant-numeric: tabular-nums;
}

/* ---------- Слайдер ---------- */
.slider { position: relative; }
.slider__track {
  display: flex;
  gap: 20px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  border-radius: var(--radius-card);
}
.slider__track::-webkit-scrollbar { display: none; }
.slider__track img { flex: 0 0 100%; width: 100%; height: auto; border-radius: var(--radius-card); scroll-snap-align: start; }
.slider__btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: 16px;
  color: var(--c-black);
  cursor: pointer;
  transition: opacity .25s ease, color .2s ease, background-color .2s ease;
}
.slider__btn:hover { color: var(--c-blue-hero); background: rgba(255, 255, 255, 0.8); }
.slider__btn--prev { left: 16px; }
.slider__btn--next { right: 16px; }
.slider__btn[disabled] { opacity: 0; pointer-events: none; }

/* ---------- Ссылка на полный кейс: вся плашка — кнопка ---------- */
.case-more {
  display: flex;
  justify-content: center;
  padding: 28px 24px;
  border-radius: var(--radius-card);
  background: var(--c-surface);
  text-align: center;
  transition: background-color .2s ease;
}
.case-more__title,
.case-more__accent { transition: color .2s ease; }
.case-more__accent { color: var(--c-blue); }
.case-more:hover { background: var(--c-hover); }
.case-more:hover .case-more__title,
.case-more:hover .case-more__accent { color: var(--c-blue-hero); }


/* =============================== 7. ВИЗУАЛЬНЫЙ КЕЙС =============================== */
/* Галерея как на Behance: картинки вплотную друг к другу */

.case__intro.case__intro--visual { border-bottom: 0; padding-bottom: 0; }   /* двойной класс: сильнее правил адаптива */
.case__lead { font-size: 20px; line-height: 1.3; letter-spacing: -0.01em; color: var(--c-grey); }
.case__tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.case__tags li { background: var(--c-surface); }

.gallery {
  width: min(var(--container), 100% - 32px);   /* 1280px, на узких экранах поля по 16px */
  margin: 40px auto 0;
  border-radius: var(--radius-card);
  overflow: hidden;
  background: var(--c-surface);
}
.gallery img { display: block; width: 100%; height: auto; }


/* =============================== 8. СТРАНИЦА 404 =============================== */

.notfound { padding-top: 140px; }   /* как в Figma: заголовок на 140px от верха */
.notfound__head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 541px;
  margin: 0 auto 40px;
  text-align: center;
}
.notfound__title { font-size: clamp(28px, 2.778vw, 40px); line-height: 1; letter-spacing: -0.02em; color: var(--c-blue); }
.notfound__text { font-size: clamp(17px, 1.389vw, 20px); line-height: 1.2; letter-spacing: -0.01em; color: var(--c-grey); }


/* =============================== АДАПТИВ =============================== */

/* ---------- ≤1199: планшет — типографика кейсов как во Framer на 810 ---------- */
@media (max-width: 1199px) {
  .case__back { font-size: 14px; }
  .case-summary__text { font-size: 16px; line-height: 1.4; }
  .case-text p, .case-list, .case-flow__list { font-size: 16px; }
  .hypothesis__title { line-height: 1.17; }
  .hypothesis__text p { font-size: 16px; line-height: 1.4; }
  .case-flow__title, .case-more__title { font-size: 24px; }
}

/* ---------- ≤1023: поля 16px; hero — своя картинка-фон для планшета (810×776) и телефона (390×844, на весь экран) ----------
   Текст лежит поверх картинки, как в макетах. Все размеры hero заданы в единицах --u (1px макета):
   на ширине макета это ровно 1px, на других — пропорционально, но не крупнее 1.1px,
   чтобы текст не разрастался на промежуточных ширинах. */
@media (max-width: 1023px) {
  :root { --gutter: 16px; }
  .hero { --u: min(100vw / 810, 1.1px); }
  .hero__image { aspect-ratio: 810 / 776; }
  .hero__content { top: 0; padding-top: calc(var(--u) * 108); }
  .hero__title { max-width: calc(var(--u) * 540); font-size: calc(var(--u) * 48); line-height: calc(var(--u) * 48); }
  .hero__lead { max-width: calc(var(--u) * 400); margin-top: calc(var(--u) * 17); font-size: calc(var(--u) * 20); line-height: calc(var(--u) * 24); letter-spacing: -0.015em; }
  .hero__tags { margin-top: calc(var(--u) * 23); gap: calc(var(--u) * 8); }
  .hero-tag {
    height: calc(var(--u) * 44);
    padding: 0 calc(var(--u) * 16);
    border-radius: calc(var(--u) * 14);
    font-size: calc(var(--u) * 18);
  }
}
@media (max-width: 639px) {
  /* телефон: hero на всю видимую высоту экрана, но не выше 700px (svh — без панелей браузера);
     картинка 390×844 прижата к верху, лишнее снизу обрезается */
  .hero { --u: min(100vw / 390, 1.1px); height: min(100vh, 700px); height: min(100svh, 700px); min-height: calc(var(--u) * 520); overflow: hidden; }
  .hero picture { height: 100%; }
  .hero__image { height: 100%; aspect-ratio: auto; object-fit: cover; object-position: 50% 0; }
  .hero__content { padding-top: calc(var(--u) * 109); }
  .hero__title { max-width: calc(var(--u) * 370); font-size: calc(var(--u) * 32); line-height: calc(var(--u) * 31); letter-spacing: -0.033em; }
  .hero__lead { max-width: calc(var(--u) * 340); margin-top: calc(var(--u) * 16); font-size: calc(var(--u) * 17); line-height: calc(var(--u) * 20); letter-spacing: 0; }
}

/* ---------- ≤809: телефон ---------- */
@media (max-width: 809px) {
  /* главная */
  .projects__head { flex-direction: column; align-items: stretch; }
  .segmented { width: 100%; }

  /* кейс: раскладка */
  .case { padding-top: 96px; }
  .case__intro { gap: 24px; padding-bottom: 24px; }
  .case-summary { grid-template-columns: 1fr; gap: 24px; }
  .hypothesis { gap: 12px; padding: 16px; }
  .case-flow { padding: 20px 16px; }
  .slider__btn { width: 44px; height: 44px; }
  .slider__btn--prev { left: 8px; }
  .slider__btn--next { right: 8px; }

  /* кейс: типографика как во Framer на 390 */
  .case__title { font-size: 32px; line-height: 1.19; letter-spacing: -0.01em; }
  .case__role { font-size: 14px; }
  .case-h { font-size: 24px; line-height: 1.17; letter-spacing: 0; }
  .case-summary__text { line-height: 1.35; }
  .hypothesis__title { font-size: 18px; line-height: 1.4; letter-spacing: -0.04em; }
  .hypothesis__text p { line-height: 1.35; }
  .case-flow__title, .case-more__title { font-size: 20px; }

  /* кейс: мобильные версии картинок и слайдов */
  .case-figure--desk, .slide--desk { display: none; }
  .case-figure--mob { display: flex; }
  .slide--mob { display: block; }

  /* визуальный кейс: картинки от края до края экрана */
  .case__lead { font-size: 16px; }
  .gallery { width: 100%; margin-top: 32px; border-radius: 0; }

  /* 404 */
  .notfound { padding-top: 108px; }
}

/* ---------- ≤639: карточки проектов по одной ---------- */
@media (max-width: 639px) {
  .projects__grid { grid-template-columns: 1fr; }
  .card__chips { left: 12px; bottom: 12px; }
}

/* ---------- ≤420: узкий телефон ---------- */
@media (max-width: 420px) {
  /* в шапке на кейсе стрелка «Назад» встаёт на место аватара — ширина шапки не меняется */
  .header__back--case { width: 52px; }
  .header__back-text { display: none; }
  html.nav-from-case .header__back--home { width: 52px; }
  .page-case .header__avatar,
  html.nav-from-case .header__avatar { width: 0; margin-right: -4px; opacity: 0; }
  html.nav-from-home .page-case .header__avatar { width: 52px; margin-right: 0; opacity: 1; }

  .footer__inner { gap: 8px; font-size: 14px; }
}


/* =============================== 9. ПРОИЗВОДИТЕЛЬНОСТЬ И ДОСТУПНОСТЬ =============================== */

/* Браузер не просчитывает разделы кейса и картинки галереи, пока до них не доскроллили.
   contain-intrinsic-size — примерная высота, чтобы полоса прокрутки не прыгала;
   «auto» запоминает реальную высоту после первого показа. */
.case__body > .case-section:not(:first-child) { content-visibility: auto; contain-intrinsic-size: auto 900px; }
.gallery > img:nth-child(n+3)                  { content-visibility: auto; contain-intrinsic-size: auto 1000px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

/* =============================== 10. ПОЯВЛЕНИЕ ЭЛЕМЕНТОВ =============================== */

/* Класс .anim ставится в <head> (если в системе не отключена анимация). Элементы стартуют
   прозрачными и чуть ниже; script.js добавляет .is-in, когда элемент попадает на экран,
   по очереди с шагом ~90 мс. Тексты разбиваются на строки — строки выезжают по одной.
   В кейсах анимируется только первый экран: всё ниже script.js сразу показывает без анимации (.no-tr). */
:root { --ease-out: cubic-bezier(.22, 1, .36, 1); }

/* тексты, которые разбиваются на строки: до разбиения скрыты целиком */
.anim .page-case .case__title:not(.is-split), .anim .page-case .case__role:not(.is-split),
.anim .page-case .case__lead:not(.is-split), .anim .page-case .case-summary__text:not(.is-split),
.anim .page-case .case-text > p:not(.is-split) { opacity: 0; }

.w { display: inline-block; }   /* слово внутри разбитого текста */

/* Hero: строки и теги размечены в HTML и появляются на чистом CSS сразу с первой отрисовкой —
   не ждут скрипт, поэтому не задерживают показ первого экрана (важно для PageSpeed на телефонах) */
.hero-line { display: block; }
@keyframes hero-rise { from { opacity: 0; transform: translateY(var(--rise, 0.6em)); } }
.anim .hero-line, .anim .hero-tag {
  animation: hero-rise .9s var(--ease-out) both;
  animation-delay: calc(80ms + var(--i, 0) * 90ms);
}
.anim .hero-tag { --rise: 24px; }

.anim .w:not(.is-in) { opacity: 0; transform: translateY(0.6em); }
.anim .card:not(.is-in),
.anim .page-case .case__back:not(.is-in), .anim .page-case .case__tags > li:not(.is-in),
.anim .page-case .case-h:not(.is-in), .anim .page-case .hypothesis:not(.is-in) {
  opacity: 0;
  transform: translateY(32px);
}
/* картинки «проявляются»: прозрачность + лёгкое приближение */
.anim .page-case .case-figure:not(.is-in), .anim .page-case .slider:not(.is-in),
.anim .page-case .gallery > img:not(.is-in) {
  opacity: 0;
  transform: translateY(40px) scale(.98);
  transform-origin: 50% 0;
}

.anim .is-in { transition: opacity .7s var(--ease-out), transform .9s var(--ease-out); }
.anim .case-figure.is-in, .anim .slider.is-in, .anim .gallery > img.is-in {
  transition: opacity 1s var(--ease-out), transform 1.2s var(--ease-out);
}
.anim .is-in.no-tr { transition: none; }

/* первая картинка кейса — на CSS, с небольшой задержкой после заголовка: показывается, не дожидаясь скрипта */
.anim .page-case .case__body > .case-section:first-child .case-figure,
.anim .page-case .gallery > img:first-child {
  opacity: 1;
  transform: none;
  transform-origin: 50% 0;
  animation: case-figure-in 1.1s var(--ease-out) .45s both;
}
@keyframes case-figure-in { from { opacity: 0; transform: translateY(40px) scale(.98); } }
