/* =========================================================
   Блок «Категории»
   Переменные продублированы с запасными значениями — если
   в теме уже есть :root с такими же именами, они переопределятся.
   ========================================================= */
:root {
  --color-text: #2e241d;
  --color-card: #f6f6f2;
  --font-base: "Gilroy", "Montserrat", "Segoe UI", Arial, sans-serif;
  --radius-card: 16px;
  --shadow-card: 0 4px 16px rgba(46, 36, 29, 0.08);
}

.categories {
  font-family: var(--font-base);
  color: var(--color-text);
}

.categories__inner {
  max-width: 1440px;
  margin-inline: auto;
  padding: 40px 16px;
}

.categories__title {
  margin: 0 0 24px;
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1.15;
}

/* ---------- Сетка (мобильный: 2 колонки) ---------- */
.categories__list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* последняя «одинокая» карточка — на всю ширину */
.categories__item:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

/* ---------- Карточка ---------- */
.categories__card {
  position: relative;
  display: flex;
  align-items: flex-end;
  height: 100%;
  min-height: 168px;
  padding: 16px;
  overflow: hidden;
  border-radius: var(--radius-card);
  background: var(--color-card);
  box-shadow: var(--shadow-card);
  color: inherit;
  text-decoration: none;
  transition: box-shadow 0.25s, transform 0.25s;
}

.categories__card:hover {
  box-shadow: 0 8px 24px rgba(46, 36, 29, 0.14);
  transform: translateY(-2px);
}

.categories__card:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 3px;
}

.categories__name {
  position: relative;
  z-index: 1;
  max-width: 100%;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.25;
}

.categories__arrow {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
  transition: transform 0.25s;
}

.categories__card:hover .categories__arrow {
  transform: translate(2px, -2px);
}

/* Картинка: на мобильном — сверху по центру */
.categories__img {
  position: absolute;
  top: 12px;
  left: 50%;
  width: auto;
  max-width: 80%;
  height: auto;
  max-height: 52%;
  object-fit: contain;
  transform: translateX(-50%);
}

/* Широкая карточка на мобильном: текст слева, картинка справа */
.categories__item:last-child:nth-child(odd) .categories__img {
  top: auto;
  right: 16px;
  bottom: 12px;
  left: auto;
  max-width: 50%;
  max-height: 80%;
  transform: none;
}

.categories__item:last-child:nth-child(odd) .categories__name {
  max-width: 45%;
}

/* ---------- Десктоп: 6 колонок, ряды 3 + 2 ---------- */
@media (min-width: 900px) {
  .categories__inner {
    padding: 64px 80px;
  }

  .categories__title {
    margin-bottom: 40px;
    font-size: 2.5rem;
  }

  .categories__list {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 20px;
  }

  .categories__item {
    grid-column: span 2;
  }

  /* 4-я и 5-я в каждой пятёрке — по половине ряда */
  .categories__item:nth-child(5n + 4),
  .categories__item:nth-child(5n + 5) {
    grid-column: span 3;
  }

  /* сбрасываем мобильное правило «последняя на всю ширину» */
  .categories__item:last-child:nth-child(odd) {
    grid-column: span 2;
  }
  .categories__item:last-child:nth-child(5n + 4),
  .categories__item:last-child:nth-child(5n + 5) {
    grid-column: span 3;
  }

  .categories__card {
    min-height: 248px;
    padding: 24px;
  }

  .categories__name {
    max-width: 42%;
    font-size: 1.5rem;
  }

  .categories__arrow {
    top: 24px;
    right: 24px;
  }

  .categories__img,
  .categories__item:last-child:nth-child(odd) .categories__img {
    top: auto;
    right: 24px;
    bottom: 24px;
    left: auto;
    max-width: 58%;
    max-height: 62%;
    transform: none;
  }

  .categories__item:last-child:nth-child(odd) .categories__name {
    max-width: 42%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .categories__card,
  .categories__arrow {
    transition: none;
  }
  .categories__card:hover {
    transform: none;
  }
}
