/* Media in article/page content; homepage cards and featured images keep their styling. */
:is(.article-content, .single-content) {
  min-width: 0;
}

:is(.article-content, .single-content) :is(.wp-block-image, .wp-block-gallery, .wp-block-embed, .wp-block-video, .wp-video, .gallery) {
  max-width: 100%;
  margin-block: 28px;
}

:is(.article-content, .single-content) :is(img, video) {
  max-width: 100%;
  height: auto;
}

:is(.article-content, .single-content) .wp-block-image img {
  border-radius: 12px;
}

/* Keep editorial photos compact, including tall police stills. */
:is(.article-content, .single-content) img:not(.avatar):not(.emoji):not(.wp-smiley) {
  width: auto;
  max-width: min(100%, 560px);
  max-height: 480px;
  object-fit: contain;
  margin-inline: auto;
}

:is(.article-content, .single-content) :is(.wp-block-image, .wp-block-video, .wp-block-embed) > figcaption {
  margin-top: 10px;
  font-size: .85em;
  line-height: 1.5;
  text-align: center;
}

/* Keep the editor's column count and crop/no-crop choice on larger screens. */
:is(.article-content, .single-content) .wp-block-gallery {
  gap: 16px;
}

:is(.article-content, .single-content) .wp-block-gallery .wp-block-image {
  min-width: 0;
  margin-block: 0;
}

:is(.article-content, .single-content) .wp-block-gallery:not(.is-cropped) .wp-block-image img {
  width: auto !important;
  max-width: 100%;
  max-height: 360px;
  height: auto !important;
  object-fit: contain;
}

:is(.article-content, .single-content) .wp-block-gallery.is-cropped .wp-block-image img {
  max-width: 100%;
  max-height: none;
  object-fit: cover;
}

/* Snel Publiceren uses the classic [gallery] shortcode, including older articles. */
:is(.article-content, .single-content) .gallery {
  --kampen-gallery-columns: 2;
  display: grid;
  grid-template-columns: repeat(var(--kampen-gallery-columns), minmax(0, 1fr));
  gap: 16px;
  clear: both;
}
:is(.article-content, .single-content) .gallery-columns-1 { --kampen-gallery-columns: 1; }
:is(.article-content, .single-content) .gallery-columns-3 { --kampen-gallery-columns: 3; }
:is(.article-content, .single-content) .gallery-columns-4 { --kampen-gallery-columns: 4; }
:is(.article-content, .single-content) .gallery-columns-5 { --kampen-gallery-columns: 5; }
:is(.article-content, .single-content) .gallery-columns-6 { --kampen-gallery-columns: 6; }
:is(.article-content, .single-content) .gallery-columns-7 { --kampen-gallery-columns: 7; }
:is(.article-content, .single-content) .gallery-columns-8 { --kampen-gallery-columns: 8; }
:is(.article-content, .single-content) .gallery-columns-9 { --kampen-gallery-columns: 9; }
:is(.article-content, .single-content) .gallery .gallery-item {
  float: none !important;
  width: auto !important;
  min-width: 0;
  max-width: 100%;
  margin: 0 !important;
  text-align: center;
}
:is(.article-content, .single-content) .gallery .gallery-icon a {
  display: block;
}
:is(.article-content, .single-content) .gallery .gallery-icon img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 360px;
  object-fit: contain;
  border: 0 !important;
  border-radius: 12px;
  margin-inline: auto;
}
:is(.article-content, .single-content) .gallery .gallery-caption {
  margin: 10px 0 0;
  font-size: .85em;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
/* Legacy shortcode markup can contain line breaks between rows. */
:is(.article-content, .single-content) .gallery > br { display: none; }

/* A video block remains full-width; short/portrait clips retain their own ratio. */
:is(.article-content, .single-content) :is(.wp-block-video video, .wp-video) {
  width: 100% !important;
}

/* Classic-editor embeds and pasted iframe HTML. Do not resize maps or other embeds. */
:is(.article-content, .single-content) iframe:is([src*="youtube.com/"], [src*="youtube-nocookie.com/"], [src*="player.vimeo.com/"]) {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: 12px;
  margin-block: 28px;
}

/* Gutenberg supplies the saved aspect ratio. Avoid double height from its spacer. */
:is(.article-content, .single-content) :is(.wp-block-embed-youtube, .wp-block-embed-vimeo) {
  --kampen-video-ratio: 16 / 9;
}
:is(.article-content, .single-content) .wp-embed-aspect-4-3 { --kampen-video-ratio: 4 / 3; }
:is(.article-content, .single-content) .wp-embed-aspect-1-1 { --kampen-video-ratio: 1 / 1; }
:is(.article-content, .single-content) .wp-embed-aspect-9-16 { --kampen-video-ratio: 9 / 16; }
:is(.article-content, .single-content) .wp-embed-aspect-1-2 { --kampen-video-ratio: 1 / 2; }
:is(.article-content, .single-content) .wp-embed-aspect-18-9 { --kampen-video-ratio: 18 / 9; }
:is(.article-content, .single-content) .wp-embed-aspect-21-9 { --kampen-video-ratio: 21 / 9; }

:is(.article-content, .single-content) :is(.wp-block-embed-youtube, .wp-block-embed-vimeo) .wp-block-embed__wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: var(--kampen-video-ratio);
}
:is(.article-content, .single-content) :is(.wp-block-embed-youtube, .wp-block-embed-vimeo) .wp-block-embed__wrapper::before {
  display: none;
}
:is(.article-content, .single-content) :is(.wp-block-embed-youtube, .wp-block-embed-vimeo) iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  aspect-ratio: auto;
}

@media (max-width: 600px) {
  :is(.article-content, .single-content) .gallery {
    grid-template-columns: minmax(0, 1fr);
    margin-block: 22px;
  }
  :is(.article-content, .single-content) .wp-block-gallery.has-nested-images figure.wp-block-image:not(#individual-image) {
    width: 100%;
    flex: 0 0 100%;
  }
  :is(.article-content, .single-content) :is(.wp-block-gallery, .wp-block-embed, .wp-block-video, .wp-video) {
    margin-block: 22px;
  }
}
