/* ==========================================================
   CLIENT LOGOS ("Kundenlogos" on the service pages: the group with the class client-logos)
   Every logo about the same visual weight: inc/client-logos.php gives each its proportions
   (--logo-ratio, width / height), and its width grows with them more slowly than the shape does,
   so a long word mark is wide and low, a square badge narrow and tall, neither swamping the other.
   Desktop: rows of --logo-cols (inc/client-logos.php: at most 6, the rows as even as they go), a
   shorter last row centred. Phones: two per row, centred in their halves; an odd last one in the
   middle.
   ========================================================== */

/* Two classes: over the framework's flex, gap and phone column classes on the same group */
.wp-block-group.client-logos {
  --logo-size: 58px;     /* a square logo's side; the others' area follows from it */
  --logo-max-width: 190px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  --logo-gap: 48px;
  gap: 56px var(--logo-gap);
  /* about 220px a column: a row of four sits as close as a row of five, not spread over the page */
  max-width: min(1100px, calc(var(--logo-cols, 5) * 220px));
  margin-inline: auto;
}

.client-logos > .wp-block-image {
  display: flex;
  flex: 0 0 calc((100% - (var(--logo-cols, 6) - 1) * var(--logo-gap)) / var(--logo-cols, 6));
  align-items: center;
  justify-content: center;
  margin: 0;
}

.client-logos > .wp-block-image img {
  display: block;
  /* width = size × ratio^0.6, height follows: ratio 1 → 58 × 58, 3 → 112 × 37, 8 → 202 × 25 (capped) */
  width: min(var(--logo-max-width), calc(var(--logo-size) * pow(var(--logo-ratio, 3), 0.6)));
  max-width: 100%;
  height: auto;
}

@container (max-width: 768px) {
  .wp-block-group.client-logos {
    --logo-size: 46px;
    --logo-max-width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-items: center;
    align-items: center;
    gap: 40px 24px;
    max-width: none;
    padding-inline: 8px;
  }

  .client-logos > .wp-block-image {
    width: 100%;
  }

  .client-logos > .wp-block-image:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}
