/* === Адаптив: портрет, ландшафт, touch, safe-area === */

:root {
  --sticky-bar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html {
  scroll-padding-top: calc(var(--header-h) + 12px);
  -webkit-text-size-adjust: 100%;
}

body {
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
}

[id] {
  scroll-margin-top: calc(var(--header-h) + 12px);
}

/* Touch-friendly controls */
.btn,
.quiz__option,
.quiz__check,
.faq__question,
.portfolio-item,
.review-screenshot,
.burger {
  touch-action: manipulation;
}

.btn {
  min-height: 44px;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.portfolio-item:active,
.review-screenshot:active {
  transform: scale(0.99);
}

/* Sticky bar + safe area (iPhone) */
.sticky-bar {
  padding:
    8px calc(12px + var(--safe-right))
    calc(8px + var(--safe-bottom))
    calc(12px + var(--safe-left));
}

.mobile-nav {
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  max-height: calc(100vh - var(--header-h) - var(--safe-top));
  max-height: calc(100dvh - var(--header-h) - var(--safe-top));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body.nav-open {
  overflow: hidden;
  touch-action: none;
}

body.nav-open .sticky-bar {
  display: none;
}

.lightbox {
  padding:
    calc(24px + var(--safe-top))
    calc(24px + var(--safe-right))
    calc(24px + var(--safe-bottom))
    calc(24px + var(--safe-left));
}

/* ——— Планшет (портрет) ——— */
@media (max-width: 1024px) {
  .container {
    width: min(1140px, calc(100% - 28px));
  }

  .hero {
    min-height: auto;
  }

  .hero__grid {
    padding: 40px 0 48px;
  }

  .messengers {
    justify-content: center;
  }

  .cta-section .form-card {
    max-width: 100%;
  }
}

/* ——— Телефон (портрет) ——— */
@media (max-width: 768px) {
  :root {
    --header-h: 64px;
  }

  body {
    padding-bottom: calc(var(--sticky-bar-h) + var(--safe-bottom) + 8px);
  }

  .container {
    width: min(1140px, calc(100% - 24px));
  }

  section {
    padding: 52px 0;
  }

  .section-head {
    margin-bottom: 32px;
  }

  /* Шапка */
  .header__actions .phone-link {
    display: none;
  }

  .header__actions .btn--primary {
    padding: 10px 14px;
    font-size: 0.84rem;
  }

  .logo__text {
    font-size: 0.95rem;
  }

  /* Hero — компактнее, без лишней высоты */
  .hero {
    min-height: auto;
    background-position: 65% center;
  }

  .hero__grid {
    padding: 28px 0 36px;
    gap: 24px;
  }

  .hero__visual {
    max-width: 100%;
  }

  .hero__content > * {
    max-width: 100%;
  }

  .hero__subtitle {
    margin-bottom: 20px;
  }

  .hero__bullets {
    margin-bottom: 22px;
  }

  .hero__cta {
    flex-direction: column;
    margin-bottom: 20px;
  }

  .hero__cta .btn {
    width: 100%;
    justify-content: center;
  }

  .hero__trust {
    gap: 8px;
  }

  .trust-chip {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
    justify-content: center;
    font-size: 0.78rem;
    padding: 8px 10px;
  }

  .hero-card--main {
    padding: 14px;
  }

  /* Калькулятор */
  .quiz__nav {
    flex-wrap: wrap;
    gap: 10px;
  }

  .quiz__nav .btn {
    flex: 1 1 calc(50% - 5px);
    min-width: 120px;
  }

  .quiz__result .quiz__price {
    font-size: clamp(1.35rem, 6vw, 1.75rem);
  }

  /* Мессенджеры и формы */
  .messengers {
    flex-direction: column;
    align-items: stretch;
  }

  .messengers .btn {
    width: 100%;
    justify-content: center;
  }

  .form-card {
    padding: 20px 16px;
  }

  .field input,
  .field textarea {
    font-size: 16px; /* без зума на iOS */
  }

  /* Отзывы — скриншоты читаемее */
  .review-screenshot {
    aspect-ratio: 9/16;
    max-height: 420px;
  }

  .review-screenshot img {
    object-fit: contain;
  }

  /* Футер */
  .footer {
    padding-bottom: calc(32px + var(--safe-bottom));
  }

  .footer__grid > div:first-child {
    grid-column: 1 / -1;
  }

  .footer__bottom {
    flex-direction: column;
    text-align: center;
  }

  /* CTA */
  .cta-section .messengers .btn--ghost-light {
    order: 3;
  }
}

/* ——— Узкие телефоны ——— */
@media (max-width: 400px) {
  .logo__text span {
    display: inline;
  }

  .about__stats {
    gap: 16px;
  }

  .about__stat {
    flex: 1 1 calc(50% - 8px);
  }

  .sticky-bar .btn {
    font-size: 0.78rem;
    padding: 11px 6px;
  }
}

/* ——— Ландшафт на телефоне (низкий экран) ——— */
@media (orientation: landscape) and (max-height: 520px) {
  :root {
    --header-h: 56px;
  }

  section {
    padding: 36px 0;
  }

  .hero {
    min-height: auto;
  }

  .hero__grid {
    display: grid;
    grid-template-columns: 1fr minmax(200px, 36%);
    grid-template-rows: auto;
    align-items: center;
    gap: 20px;
    padding: 16px 0 24px;
  }

  .hero__visual {
    order: 0;
    grid-column: 2;
    grid-row: 1;
    max-width: none;
    margin: 0;
    min-height: 0;
  }

  .hero__content {
    grid-column: 1;
    grid-row: 1;
  }

  .hero h1 {
    font-size: clamp(1.25rem, 4.5vw, 1.65rem);
    margin-bottom: 10px;
  }

  .hero__badge {
    margin-bottom: 10px;
    font-size: 0.72rem;
  }

  .hero__subtitle {
    font-size: 0.88rem;
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .hero__bullets {
    margin-bottom: 14px;
    gap: 6px;
  }

  .hero__bullets li {
    font-size: 0.82rem;
  }

  .hero__cta {
    flex-direction: row;
    flex-wrap: wrap;
    margin-bottom: 0;
    gap: 8px;
  }

  .hero__cta .btn {
    width: auto;
    flex: 1 1 auto;
    min-height: 40px;
    padding: 10px 14px;
    font-size: 0.82rem;
  }

  .hero__trust {
    display: none;
  }

  .hero-card--main {
    padding: 10px;
  }

  .assembly-widget__steps {
    margin-bottom: 8px;
    gap: 4px;
  }

  .assembly-widget__step {
    padding: 4px 8px;
    font-size: 0.65rem;
  }

  .assembly-widget__num {
    width: 18px;
    height: 18px;
    font-size: 0.62rem;
  }

  .assembly-widget__stage {
    height: 110px;
  }

  .assembly-widget__caption {
    margin-top: 8px;
    font-size: 0.68rem;
  }

  .assembly-corpus {
    width: 90px;
    height: 70px;
  }

  .mobile-nav {
    max-height: calc(100vh - var(--header-h));
    max-height: calc(100dvh - var(--header-h));
  }

  .sticky-bar {
    display: flex;
    padding-top: 6px;
    padding-bottom: calc(6px + var(--safe-bottom));
  }

  body {
    padding-bottom: calc(52px + var(--safe-bottom));
  }
}

/* ——— Ландшафт на планшете ——— */
@media (orientation: landscape) and (min-width: 769px) and (max-width: 1024px) {
  .hero__grid {
    grid-template-columns: 1.1fr 0.9fr;
    gap: 32px;
    padding: 32px 0 40px;
  }

  .hero__visual {
    order: 0;
    max-width: none;
  }

  .advantages {
    grid-template-columns: repeat(3, 1fr);
  }

  .portfolio-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .reviews-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ——— Большие телефоны / маленькие планшеты в ландшафте ——— */
@media (orientation: landscape) and (max-height: 520px) and (min-width: 600px) {
  .hero__grid {
    grid-template-columns: 1.15fr 0.85fr;
  }

  .assembly-widget__stage {
    height: 130px;
  }

  .hero__trust {
    display: flex;
  }
}

/* ——— Hover только там, где есть мышь ——— */
@media (hover: hover) and (pointer: fine) {
  .portfolio-item:hover {
    transform: scale(1.02);
  }
}

@media (hover: none) {
  .portfolio-item:hover {
    transform: none;
    box-shadow: none;
  }

  .portfolio-item:active {
    transform: scale(0.99);
    box-shadow: var(--shadow);
  }

  .review-card:hover {
    transform: none;
    box-shadow: none;
  }

  .review-card:active {
    transform: scale(0.99);
  }
}
