/* ==========================================================================
   Section: popular-category  →  assets/section-popular-category.css
   Figma 1089-3998: title row inside the page width, then a full-bleed row of category cards —
   437.33×696 at 1440 (Figma 438/437), three fill the 1320 page width with 4px gaps and the
   neighbours peek 56px at both edges; 40×40 arrows centred on the gaps beside the page width.
   The title's line box sits 75px below the Best Seller progress bar (Figma: frame 81px below
   with its header overflowing 6px above), the cards 24px below the title.
   ========================================================================== */
.popular-category {
  --card-gap: 4px;
  --per-view: 3;
  --edge: max(var(--page-gutter), calc((100% - var(--page-width)) / 2)); /* page-width offset from the viewport edge */
  padding-top: 75px;
}

.popular-category__inner {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Header row — title left, tabs right, bottom-aligned */
.popular-category__header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.popular-category__title {
  font-family: var(--font-display);
  font-size: var(--text-display-s-size);
  font-weight: 500;
  line-height: 1.2;
  color: var(--color-text-primary);
  white-space: nowrap;
}

.popular-category__panel[hidden] {
  display: none;
}

/* Carousel — full-bleed track padded to the page width, so snap positions line up with it */
.category-carousel {
  position: relative;
}

.category-carousel__track {
  display: flex;
  align-items: flex-start;
  gap: var(--card-gap);
  padding-inline: var(--edge);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: var(--edge);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.category-carousel__track::-webkit-scrollbar {
  display: none;
}

/* Arrows — 40×40 white, 2px radius, vertically centred, centred on the gap beside the page width */
.category-carousel__arrow {
  position: absolute;
  z-index: 2;
  top: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-top: -20px;
  border-radius: var(--radius-sm);
  background: var(--color-white);
  color: var(--color-icon-primary);
  cursor: pointer;
  transition: color var(--duration-fast) ease;
}

.category-carousel__arrow--prev {
  left: calc(var(--edge) - var(--card-gap) / 2 - 20px);
}

.category-carousel__arrow--next {
  right: calc(var(--edge) - var(--card-gap) / 2 - 20px);
}

.category-carousel__arrow:disabled {
  color: var(--color-icon-tertiary);
  cursor: default;
}

.category-carousel__arrow:focus-visible {
  outline: 2px solid var(--color-black);
  outline-offset: 2px;
}

/* Card — link with a cover photo, bottom shade and the category name.
   Image settings on .category-card: --focal-x / --focal-y / --zoom (same model as the hero). */
.category-card {
  position: relative;
  display: block;
  flex: 0 0 calc((100% - (var(--per-view) - 1) * var(--card-gap)) / var(--per-view));
  aspect-ratio: 1312 / 2088; /* 437.33 : 696 */
  overflow: hidden;
  background: var(--card-bg, #a6a6a6);
  color: var(--color-text-inverse);
  scroll-snap-align: start;
  text-decoration: none;
}

.category-card__image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--focal-x, 50%) var(--focal-y, 50%);
  transform: scale(var(--zoom, 1));
  transform-origin: var(--focal-x, 50%) var(--focal-y, 50%);
  transition: transform 700ms var(--ease-out);
}

.category-card:hover .category-card__image,
.category-card:focus-visible .category-card__image {
  transform: scale(calc(var(--zoom, 1) * 1.04));
}

/* Bottom shade: transparent to 60% black over the last ~19% (Figma 81.3% → 100%) */
.category-card__overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 81.3%, rgba(0, 0, 0, 0.6) 100%);
}

/* data-shade="extra": adds a full-height shade for bright photos (Figma card 6) */
.category-card[data-shade="extra"] .category-card__overlay {
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0) 81.3%, rgba(0, 0, 0, 0.6) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.6) 100%);
}

.category-card__label {
  position: absolute;
  left: 40px;
  bottom: 24px;
  font-family: var(--font-display);
  font-size: var(--text-display-s-size);
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

.category-card:focus-visible {
  outline: 2px solid var(--color-white);
  outline-offset: -4px;
}

@media (max-width: 989px) {
  .popular-category {
    --per-view: 2;
  }
}

@media (max-width: 749px) {
  .popular-category {
    --per-view: 1.25;
    padding-top: 48px;
  }

  .popular-category__inner {
    gap: 16px;
  }

  .popular-category__header {
    flex-wrap: wrap;
    row-gap: 12px;
  }

  .category-card__label {
    left: 20px;
    bottom: 16px;
    font-size: 24px;
  }

  .category-carousel__arrow--prev {
    left: 8px;
  }

  .category-carousel__arrow--next {
    right: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .category-card__image {
    transition: none;
  }

  .category-card:hover .category-card__image,
  .category-card:focus-visible .category-card__image {
    transform: scale(var(--zoom, 1));
  }
}
