/* =========================
   .rider-grid — the grid of rider cards on every page that lists riders
   -----------------------------------------------------------------------------
   Loaded with the card styles by partials/_rider_card_styles.html. Four columns (five from 1600px on a page without ad
   rails), three below 992px, two below 768px
   and one below 576px, where the compact card takes a whole row; --wide has five from 992px, --featured shows each
   card at its full size. Every row is centred, also an incomplete last one. The cells (.rider-grid__cell,
   .is-duplicate for a duplicate) are read by filter.js, ordering.js, grid_deferred.js, rider_grid.js,
   duplicate_conversion.js and pack_detail_showcase.js. Blocks: .rider-grid.
   ========================= */

/* Flex rather than CSS grid, so an incomplete last row can be centred. The cell width is a share of the row. */
.rider-grid {
  --rider-grid-cell-width: calc(
    (100% - (var(--rider-grid-columns) - 1) * var(--rider-grid-gap)) / var(--rider-grid-columns)
  );
  /* Five on a wide page without ad rails (--page-grid-columns, _ads.css) */
  --rider-grid-columns: var(--page-grid-columns, 4);
  --rider-grid-gap: var(--space-lg);
  display: flex;
  flex-wrap: wrap;
  gap: var(--rider-grid-gap);
  justify-content: center;
}

/* A width rather than a flex-basis: the cell then never grows wider than its share for wide content. */
.rider-grid__cell {
  flex: none;
  width: var(--rider-grid-cell-width);
}

/* Five candidates side by side (player_pick.html) */
.rider-grid--wide {
  --rider-grid-columns: 5;
}

/* Featured riders (the top 3 of a profile): each card at its full size, but at least two side by side from 576px, so
   a shield never stands alone in a row. */
.rider-grid--featured {
  --rider-grid-cell-width: min(var(--rider-card-max-width), calc((100% - var(--rider-grid-gap)) / 2));
}

@media (max-width: 991.98px) {
  .rider-grid {
    --rider-grid-columns: 3;
  }
}

@media (max-width: 767.98px) {
  .rider-grid {
    --rider-grid-columns: 2;
  }
}

/* The compact cards stand below each other like a list. */
@media (max-width: 575.98px) {
  .rider-grid {
    --rider-grid-columns: 1;
    --rider-grid-gap: var(--space-md);
  }

  .rider-grid--featured {
    --rider-grid-cell-width: 100%;
  }
}
