/* ==========================================================================
   Переиспользуемый компонент: Кнопки прокрутки (::scroll-button) + Anchor
   ========================================================================== */
.ui-scroll-buttons {
  anchor-name: --scroll-container-anchor;

&::scroll-button(*) {
position-anchor: --scroll-container-anchor;
position: absolute;
width: 3rem;
height: 3rem;
border-radius: 50%;
margin-inline: -2.5rem;
border: none;
background: center / 3rem 3rem no-repeat #333c;
backdrop-filter: blur(1em);
z-index: 4;
cursor: pointer;
opacity: .7;
transition: opacity .25s ease, transform .25s ease, background-color .25s ease;
@media (width > 80em) { margin-inline: 0; }
}
&::scroll-button(*):hover:not(:disabled), &:focus-visible { opacity: 1; }
&::scroll-button(*):active { translate: 0 1px; }
&::scroll-button(*):disabled { opacity: .3; cursor: unset; display: none; }
&::scroll-button(inline-start) {
content: '';
background-image: url(/sprite_bg.svg#left);
position-area: left center;
box-shadow: -1px 1px 2px #3339;
}
&::scroll-button(inline-end) {
content: '';
background-image: url(/sprite_bg.svg#right);
position-area: right center;
box-shadow: 1px 1px 2px #3339;
}
}

/* ==========================================================================
   Переиспользуемый компонент: Маркеры пагинации (::scroll-marker)
   ========================================================================== */
.ui-scroll-markers {
  scroll-marker-group: after;

  &::scroll-marker-group {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: .5em;
    padding-block: 1em;
    anchor-name: --scroll-markers-anchor;
  }

  & > *::scroll-marker {
    content: "";
    inline-size: 1em;
    block-size: 1em;
    border-radius: 1em;
    background-color: rgb(0 0 0 / .25);
    border: none;
    cursor: pointer;
    transition: inline-size .5s ease, background-color .5s ease;

    &:hover {
      background-color: rgb(0 0 0 / .5);
    }

    &:target-current {
      inline-size: 2em;
      background-color: #111;
    }
  }
}

/* ==========================================================================
   Основной контейнер карусели с Scroll State Queries
   ========================================================================== */
.modern-carousel {
  --carousel-columns: 3;
  --carousel-gap: 1em;

  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: calc(
    (100% - (var(--carousel-columns) - 1) * var(--carousel-gap)) / var(--carousel-columns)
  );
  gap: var(--carousel-gap);

  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  position: relative;

  &::-webkit-scrollbar {
    display: none;
  }

  @media (max-width: 992px) {
    --carousel-columns: 2;
  }

  @media (max-width: 576px) {
    --carousel-columns: 1;
  }

  & > figure {
    position: relative;
    margin: 0;
    border-radius: 1em;
    overflow: hidden;
    background-color: #f4f4f6;
    scroll-snap-align: start;
    scroll-snap-stop: always;

    /* Активация отслеживания состояния привязки (Scroll State Query) */
    container-type: scroll-state;

    & > img {
      display: block;
      inline-size: 100%;
      block-size: auto;
      aspect-ratio: 1 / 1;
      object-fit: cover;
      transition: transform .5s ease;
    }

    &:hover > img {
      transform: scale(1.03);
    }

    & > figcaption {
      position: absolute;
      inset-inline: 0;
      inset-block-end: 0;
      padding: 1em;
      background: linear-gradient(to top, rgb(0 0 0 / .75) 0%, rgb(0 0 0 / .5) 75%, transparent 100%);
      color: #fff;
      transform: translateY(0);
      opacity: 1;
      transition: transform .5s ease, opacity .5s ease;

      & > ul {
        list-style: none;
        margin: 0;
        padding: 0;
        display: flex;
        flex-wrap: wrap;
        gap: .5em;
        align-items: center;

        & > li {
          display: inline-flex;
          align-items: center;
          gap: .25em;
          font-size: .75em;
          line-height: 1;

          & > a {
            color: #fff;
            text-decoration: none;
            border-bottom: 1px solid rgb(255 255 255 / 0.4);
            transition: border-color 0.2s ease, color 0.2s ease;

            &:hover {
              color: var(--brand-orange);
              border-bottom-color: var(--brand-orange);
            }
          }
        }
      }
    }

    /* Если карточка НЕ в состоянии snapped по оси inline — скрываем figcaption вниз */
    @container not scroll-state(snapped: inline) {
      & > figcaption {
        transform: translateY(100%);
        opacity: 0;
        pointer-events: none;
      }
    }
  }
}

/* Бейджи Скидка и Новинка */
.badge {
  display: inline-block;
  padding: 2px 6px;
  font-size: .5em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: .25em;
  line-height: 1;

  &.badge--sale {
    background-color: #c33;
    color: #eee;
  }

  &.badge--new {
    background-color: #33c;
    color: #eee;
  }
}
