/* Tiles of the blocks Collection (products, categories, guides), Accessories and Saved (front end and editor preview) */
.sg-tiles {
  --cols: 4;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 24px;

  &.has-cols-2 { --cols: 2; }
  &.has-cols-3 { --cols: 3; }
  &.has-cols-5 { --cols: 5; }
  &.has-cols-6 { --cols: 6; }
}

@media (max-width: 1023px) {
  .sg-tiles:not(.is-carousel, .has-cols-2) { --cols: 3; }
}
@media (max-width: 700px) {
  .sg-tiles:not(.is-carousel) { --cols: 2; gap: 16px; }
}

.sg-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--wp--preset--color--grey);
  color: var(--wp--custom--body);
  text-decoration: none;
  transition: transform 220ms var(--wp--custom--ease-out), box-shadow 220ms ease;
}

/* product image: inside an inner padding (8 %), never touching the edge of the tile, also not when zoomed on hover */
.sg-tile__img {
  box-sizing: border-box;
  aspect-ratio: 1;
  padding: 8%;
  overflow: hidden;
  background: var(--wp--preset--color--grey);

  & img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    mix-blend-mode: multiply;
    transition: transform 600ms var(--wp--custom--ease-out);
  }
}

/* photos (guides) fill the box */
.sg-tiles.is-photo .sg-tile__img { padding: 0; }
.sg-tiles.is-photo .sg-tile__img img { object-fit: cover; mix-blend-mode: normal; }

/* phones: lower tiles (e.g. carousel of the shop home) */
@media (max-width: 700px) {
  .sg-tile__img { aspect-ratio: 4 / 3; }
}

.sg-tile__body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px 18px;
  flex: 1;
}

.sg-tile__kicker {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--wp--preset--color--teal);
}

.sg-tile__title {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.35;
  font-weight: 700;
  color: var(--wp--preset--color--ink);
  transition: color 200ms ease;
}

.sg-tile__arrow {
  margin-top: auto;
  padding-top: 6px;
  align-self: flex-end;
  color: var(--wp--preset--color--teal);
  transition: transform 220ms var(--wp--custom--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .sg-tile:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 26px -20px rgba(14, 110, 100, .6);

    & .sg-tile__title { color: var(--wp--preset--color--teal); }
    & .sg-tile__arrow { transform: translateX(4px); }
    & .sg-tile__img img { transform: scale(1.03); } /* inside the padded box: stays clear of the edge */
  }
}

@media (prefers-reduced-motion: reduce) {
  .sg-tile,
  .sg-tile__img img,
  .sg-tile__arrow { transition: none; }
  .sg-tile:hover .sg-tile__img img { transform: none; }
}


/* first tile as a link (block "Collection", also before post cards): teal, text at the top, arrow at the bottom, as large as the others */
.sg-tile--link {
  justify-content: space-between;
  gap: 24px;
  padding: 24px 22px 22px;
  background: var(--wp--preset--color--teal);
  color: #fff;

  & .sg-tile__link-text {
    font-size: clamp(18px, 1.6vw, 22px);
    font-weight: 700;
    line-height: 1.25;
  }

  & .sg-tile__arrow {
    padding-top: 0;
    color: #fff;
    font-size: 24px;
  }

  &:focus-visible { outline: 2px solid var(--wp--preset--color--ink); outline-offset: 3px; }
}

@media (hover: hover) and (pointer: fine) {
  .sg-tile--link:hover { background: var(--wp--preset--color--teal-dark); }
}

/* "stays in place while scrolling" (carousel): the link tile sticks at the start, the other tiles scroll past it
   (opaque, above them) and snap right next to it. Phones: a flat bar above the carousel instead (render.php). */
.sg-tile--bar {
  flex-direction: row;
  align-items: center;
  min-height: 0;
  margin-bottom: 16px;
  padding: 18px 22px;
}
@media (max-width: 700px) {
  .has-sticky-first > .sg-tile--link.is-sticky { display: none; }
}
@media (min-width: 701px) {
  .sg-tile--bar { display: none; }

  .is-carousel.has-sticky-first {
    scroll-padding-inline-start: calc((100% - (var(--cols) - 1) * var(--gap)) / var(--cols) + var(--gap));

    & > .sg-tile--link.is-sticky {
      position: sticky;
      inset-inline-start: 0;
      z-index: 2;
      box-shadow: var(--gap, 24px) 0 0 0 var(--sg-tiles-bg, #fff); /* covers the gap: tiles disappear cleanly behind it */
    }
  }

  /* gap cover in the colour of the section */
  .sg-section.has-bg-grey .has-sticky-first { --sg-tiles-bg: var(--wp--preset--color--grey); }
  .sg-section.has-bg-mint .has-sticky-first { --sg-tiles-bg: var(--wp--preset--color--mint); }
  .sg-section.has-bg-cream .has-sticky-first { --sg-tiles-bg: var(--wp--preset--color--cream); }
  .sg-section.has-bg-teal .has-sticky-first { --sg-tiles-bg: var(--wp--preset--color--teal); }
  .sg-section.has-bg-dark .has-sticky-first { --sg-tiles-bg: var(--wp--custom--dark, #0d1a33); } /* = section background */
}

/* on teal and dark sections the link tile is white with teal text (teal on teal would vanish) */
.sg-section:is(.has-bg-teal, .has-bg-dark) .sg-tile--link {
  background: #fff;
  color: var(--wp--preset--color--teal);

  & .sg-tile__arrow { color: var(--wp--preset--color--teal); }
}
@media (hover: hover) and (pointer: fine) {
  .sg-section:is(.has-bg-teal, .has-bg-dark) .sg-tile--link:hover { background: var(--wp--preset--color--mint); }
}

.sg-accessories > .sg-tiles { margin-top: 20px; }

.sg-section.has-bg-grey .sg-tile,
.sg-section.has-bg-grey .sg-tile__img {
  background: var(--wp--preset--color--white);
}
