/* Daily Rock — Gallery Newspaper v0.3.1
 * Scoped compatibility restoration based on WordPress Gutenberg Gallery native
 * flex rules, for the opt-in gallery targets only. Never writes post content.
 */
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images,
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: normal !important;
    gap: var(--wp--style--unstable-gallery-gap, 16px) !important;
    max-width: 100% !important;
    box-sizing: border-box;
}

/* WordPress core/gallery flex layout uses FLEXIBLE figures, not equal-size tiles. */
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images > figure.wp-block-image,
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix > figure.wp-block-image {
    display: flex !important;
    flex: 1 1 auto !important;
    flex-direction: column !important;
    justify-content: center !important;
    width: calc(50% - (var(--wp--style--unstable-gallery-gap, 16px) / 2)) !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    margin: 0 !important;
}

:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images > figure.wp-block-image > a,
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images > figure.wp-block-image > div,
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix > figure.wp-block-image > a,
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix > figure.wp-block-image > div {
    margin: 0 !important;
    flex-direction: column;
    flex-grow: 1;
}

:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images > figure.wp-block-image img,
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix > figure.wp-block-image img {
    display: block;
    width: auto !important;
    max-width: 100% !important;
    height: auto !important;
}

/* Match Gutenberg's native behaviour when "Crop images to fit" is enabled. */
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images.is-cropped > figure.wp-block-image,
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix.is-cropped > figure.wp-block-image {
    align-self: inherit;
}
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images.is-cropped > figure.wp-block-image > a,
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix.is-cropped > figure.wp-block-image > a,
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images.is-cropped > figure.wp-block-image > div,
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix.is-cropped > figure.wp-block-image > div {
    display: flex;
}
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images.is-cropped > figure.wp-block-image img,
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix.is-cropped > figure.wp-block-image img,
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images.is-cropped > figure.wp-block-image > a,
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix.is-cropped > figure.wp-block-image > a {
    width: 100% !important;
    height: 100% !important;
    flex: 1 0 0% !important;
    object-fit: cover !important;
}
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images:not(.is-cropped) > figure.wp-block-image,
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix:not(.is-cropped) > figure.wp-block-image {
    margin-top: 0 !important;
    margin-bottom: auto !important;
}

/* Gutenberg default: 2 columns on narrow viewports; 3 from 600px up. */
@media (min-width: 600px) {
  :where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images > figure.wp-block-image,
  .td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix > figure.wp-block-image {
      width: calc(33.333333% - (var(--wp--style--unstable-gallery-gap, 16px) * 2 / 3)) !important;
  }
}
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix.columns-1 > figure.wp-block-image,
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images.columns-1 > figure.wp-block-image { width: 100% !important; }
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix.columns-2 > figure.wp-block-image,
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images.columns-2 > figure.wp-block-image { width: calc((100% - (var(--wp--style--unstable-gallery-gap, 16px) * 1)) / 2) !important; }
@media (min-width: 600px) {
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix.columns-3 > figure.wp-block-image,
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images.columns-3 > figure.wp-block-image { width: calc((100% - (var(--wp--style--unstable-gallery-gap, 16px) * 2)) / 3) !important; }
}
@media (min-width: 600px) {
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix.columns-4 > figure.wp-block-image,
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images.columns-4 > figure.wp-block-image { width: calc((100% - (var(--wp--style--unstable-gallery-gap, 16px) * 3)) / 4) !important; }
}
@media (min-width: 600px) {
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix.columns-5 > figure.wp-block-image,
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images.columns-5 > figure.wp-block-image { width: calc((100% - (var(--wp--style--unstable-gallery-gap, 16px) * 4)) / 5) !important; }
}
@media (min-width: 600px) {
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix.columns-6 > figure.wp-block-image,
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images.columns-6 > figure.wp-block-image { width: calc((100% - (var(--wp--style--unstable-gallery-gap, 16px) * 5)) / 6) !important; }
}
@media (min-width: 600px) {
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix.columns-7 > figure.wp-block-image,
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images.columns-7 > figure.wp-block-image { width: calc((100% - (var(--wp--style--unstable-gallery-gap, 16px) * 6)) / 7) !important; }
}
@media (min-width: 600px) {
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix.columns-8 > figure.wp-block-image,
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images.columns-8 > figure.wp-block-image { width: calc((100% - (var(--wp--style--unstable-gallery-gap, 16px) * 7)) / 8) !important; }
}

/* Preserve captions on a separate row like the Gutenberg gallery block. */
.td-post-content .wp-block-gallery.has-nested-images.dr-gallery-end-fix > figcaption,
:where(body.dr-gallery-test-laura) .td-post-content .wp-block-gallery.has-nested-images > figcaption {
    flex: 1 0 100% !important;
    text-align: center;
}
