/* Printed late (see inc/article-gallery-styles.php) so it beats WP block + Rocket used CSS. */

:is(.prose-article, .guide-content, .entry-content) :is(.gallery, .wp-block-gallery, .blocks-gallery-grid),
:is(.prose-article, .guide-content, .entry-content) .wp-block-gallery.is-layout-flex,
:is(.prose-article, .guide-content, .entry-content) .wp-block-gallery.has-nested-images,
:is(.prose-article, .guide-content, .entry-content) .wp-block-gallery.columns-default {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  align-items: stretch !important;
  justify-items: stretch !important;
  gap: 0.75rem !important;
  width: 100% !important;
  margin: 2rem 0 !important;
  padding: 0 !important;
}

/* Leftover 4th / 7th / 10th in a 3-column gallery: full-width row. */
:is(.prose-article, .guide-content, .entry-content) :is(.wp-block-gallery.columns-default, .wp-block-gallery.columns-3, .gallery-columns-3) > :nth-child(3n + 1):last-child,
:is(.prose-article, .guide-content, .entry-content) .wp-block-gallery:not(.columns-2):not(.columns-4):not(.columns-5):not(.columns-6) > :nth-child(3n + 1):last-child {
  grid-column: 1 / -1 !important;
}

:is(.prose-article, .guide-content, .entry-content) :is(.gallery, .wp-block-gallery):has(> :last-child:nth-child(1)) {
  grid-template-columns: minmax(0, 1fr) !important;
}

:is(.prose-article, .guide-content, .entry-content) :is(.gallery, .wp-block-gallery):has(> :last-child:nth-child(2)) {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

:is(.prose-article, .guide-content, .entry-content) :is(.gallery-columns-2, .wp-block-gallery.columns-2) {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

:is(.prose-article, .guide-content, .entry-content) :is(.gallery-columns-3, .wp-block-gallery.columns-3) {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
}

:is(.prose-article, .guide-content, .entry-content) :is(.gallery-columns-4, .wp-block-gallery.columns-4) {
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
}

:is(.prose-article, .guide-content, .entry-content) :is(.gallery-columns-5, .wp-block-gallery.columns-5) {
  grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
}

:is(.prose-article, .guide-content, .entry-content) :is(.gallery-columns-6, .wp-block-gallery.columns-6) {
  grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
}

:is(.prose-article, .guide-content, .entry-content) :is(.gallery, .wp-block-gallery) > :is(.gallery-item, .blocks-gallery-item, .wp-block-image, figure) {
  display: block !important;
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  margin: 0 !important;
  flex-grow: 0 !important;
}

:is(.prose-article, .guide-content, .entry-content) :is(.gallery-icon, .gallery-icon a, .wp-block-gallery a, .blocks-gallery-item a) {
  display: block !important;
  width: 100% !important;
}

:is(.prose-article, .guide-content, .entry-content) :is(.gallery, .wp-block-gallery, .blocks-gallery-grid) img,
:is(.prose-article, .guide-content, .entry-content) .wp-block-gallery.has-nested-images figure.wp-block-image img,
:is(.prose-article, .guide-content, .entry-content) .wp-block-gallery.has-nested-images figure.wp-block-image:not(#individual-image) img,
:is(.prose-article, .guide-content, .entry-content) .wp-block-gallery.has-nested-images.is-cropped figure.wp-block-image:not(#individual-image) img {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
}

:is(.prose-article, .guide-content, .entry-content) .wp-block-gallery.is-cropped img {
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

@media (max-width: 639px) {
  :is(.prose-article, .guide-content, .entry-content) :is(.gallery-columns-3, .gallery-columns-4, .gallery-columns-5, .gallery-columns-6, .wp-block-gallery.columns-3, .wp-block-gallery.columns-4, .wp-block-gallery.columns-5, .wp-block-gallery.columns-6, .wp-block-gallery.columns-default) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  :is(.prose-article, .guide-content, .entry-content) :is(.gallery, .wp-block-gallery) > :nth-child(3n + 1):last-child {
    grid-column: auto !important;
  }

  :is(.prose-article, .guide-content, .entry-content) :is(.gallery, .wp-block-gallery) > :nth-child(2n + 1):last-child {
    grid-column: 1 / -1 !important;
  }
}

@media (max-width: 479px) {
  :is(.prose-article, .guide-content, .entry-content) :is(.gallery-columns-2, .gallery-columns-3, .gallery-columns-4, .gallery-columns-5, .gallery-columns-6, .wp-block-gallery.columns-2, .wp-block-gallery.columns-3, .wp-block-gallery.columns-4, .wp-block-gallery.columns-5, .wp-block-gallery.columns-6, .wp-block-gallery.columns-default) {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  :is(.prose-article, .guide-content, .entry-content) :is(.gallery, .wp-block-gallery) > :last-child {
    grid-column: auto !important;
  }
}
