/*
 * Wildbirds native edge-to-edge photography
 * CSS is applied on the first paint. No image-resizing script is used.
 */

/* Default reading-column geometry. */
body.single .wildbirds-edge-post,
body.single .wildbirds-edge-post .post-inner-wrapper {
    --wb-photo-width: 100%;
    --wb-photo-margin: 0px;
    --wb-photo-inset: 0px;
}

/* REHub's standard post card uses 25px of inner padding. */
body.single:not(.noinnerpadding) .main-side.single > .rh-post-wrapper {
    --wb-card-padding: 25px;
    --wb-card-border: 1px;
    padding-left: var(--wb-card-padding) !important;
    padding-right: var(--wb-card-padding) !important;
    border-left-width: var(--wb-card-border) !important;
    border-right-width: var(--wb-card-border) !important;
}

body.single.noinnerpadding .main-side.single > .rh-post-wrapper {
    --wb-card-padding: 0px;
    --wb-card-border: 0px;
    padding-left: 0 !important;
    padding-right: 0 !important;
    border-left-width: 0 !important;
    border-right-width: 0 !important;
}

body.single .main-side.single > .rh-post-wrapper > .wildbirds-edge-post {
    --wb-photo-width: calc(100% + var(--wb-card-padding, 0px) + var(--wb-card-padding, 0px));
    --wb-photo-margin: calc(0px - var(--wb-card-padding, 0px));
    --wb-photo-inset: var(--wb-card-padding, 0px);
}

/* Standalone photos, simple image captions, and photo-only column rows.
   Direct children only, so custom galleries, diet and bird widgets remain
   untouched. Explicitly floated images and thumbnails are excluded. */
body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) >
:is(.wp-block-image, .wp-caption, .top_featured_image, .wp-block-post-featured-image,
    .wildbirds-standalone-photo, .wildbirds-image-row,
    figure:has(> img:only-child), img:not(.emoji, .avatar, .wp-smiley, .size-thumbnail)):not(.alignleft, .alignright, .size-thumbnail, .no-image-bleed, [data-no-image-bleed], .wwbba-bird, .wwbba-flag, .wp-block-gallery):not(:has(img.alignleft, img.alignright, img.size-thumbnail, img.emoji, img.avatar, img.wp-smiley, .no-image-bleed, [data-no-image-bleed])) {
    box-sizing: border-box !important;
    width: var(--wb-photo-width) !important;
    max-width: none !important;
    min-width: 0 !important;
    margin-left: var(--wb-photo-margin) !important;
    margin-right: var(--wb-photo-margin) !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    border-radius: 0 !important;
    float: none !important;
}

/* Raw Gutenberg markup also works when the server-side block marker is absent. */
body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) >
.wp-block-columns:has(> .wp-block-column > .wp-block-image):not(:has(> .wp-block-column > :not(.wp-block-image))):not(.no-image-bleed, [data-no-image-bleed]):not(:has(.no-image-bleed, [data-no-image-bleed], img.alignleft, img.alignright, img.size-thumbnail)) {
    box-sizing: border-box !important;
    width: var(--wb-photo-width) !important;
    max-width: none !important;
    min-width: 0 !important;
    margin-left: var(--wb-photo-margin) !important;
    margin-right: var(--wb-photo-margin) !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* Images, links and picture wrappers fill the expanded block. Keep the
   original image proportions, and let Gutenberg control the column gap. */
body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) >
:is(.wp-block-image, .wp-caption, .top_featured_image, .wp-block-post-featured-image,
    .wildbirds-standalone-photo, .wildbirds-image-row,
    figure:has(> img:only-child)):not(.alignleft, .alignright, .size-thumbnail, .no-image-bleed, [data-no-image-bleed], .wp-block-gallery):not(:has(img.alignleft, img.alignright, img.size-thumbnail, img.emoji, img.avatar, img.wp-smiley, .no-image-bleed, [data-no-image-bleed])):is(figure, div, p, .wp-block-columns) {
    border-radius: 0 !important;
}

body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) >
:is(.wp-block-image, .wp-caption, .top_featured_image, .wp-block-post-featured-image,
    .wildbirds-standalone-photo, .wildbirds-image-row,
    figure:has(> img:only-child)):not(.alignleft, .alignright, .size-thumbnail, .no-image-bleed, [data-no-image-bleed], .wp-block-gallery):not(:has(img.alignleft, img.alignright, img.size-thumbnail, img.emoji, img.avatar, img.wp-smiley, .no-image-bleed, [data-no-image-bleed])):is(figure, div, p, .wp-block-columns) :is(img, picture, figure.wp-block-image, figure.aligncenter, .wp-block-image > a, figure > a, p > a),
body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) >
.wp-block-columns:has(> .wp-block-column > .wp-block-image):not(:has(> .wp-block-column > :not(.wp-block-image))):not(.no-image-bleed, [data-no-image-bleed]):not(:has(.no-image-bleed, [data-no-image-bleed], img.alignleft, img.alignright, img.size-thumbnail))
> .wp-block-column :is(.wp-block-image, .wp-block-image > a, figure, picture, img) {
    display: block !important;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    border-radius: 0 !important;
}

body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) >
:is(.wp-block-image, .wp-caption, .top_featured_image, .wp-block-post-featured-image,
    .wildbirds-standalone-photo, .wildbirds-image-row,
    figure:has(> img:only-child)):not(.alignleft, .alignright, .size-thumbnail, .no-image-bleed, [data-no-image-bleed], .wp-block-gallery):not(:has(img.alignleft, img.alignright, img.size-thumbnail, img.emoji, img.avatar, img.wp-smiley, .no-image-bleed, [data-no-image-bleed])) img,
body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) >
.wp-block-columns:has(> .wp-block-column > .wp-block-image):not(:has(> .wp-block-column > :not(.wp-block-image))):not(.no-image-bleed, [data-no-image-bleed]):not(:has(.no-image-bleed, [data-no-image-bleed], img.alignleft, img.alignright, img.size-thumbnail)) img,
body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) >
img:not(.alignleft, .alignright, .size-thumbnail, .avatar, .emoji, .wp-smiley, .wwbba-bird, .wwbba-flag, .no-image-bleed, [data-no-image-bleed]) {
    display: block !important;
    height: auto !important;
    max-height: none !important;
    object-fit: cover;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

/* Preserve normal text-column widths in Gutenberg's special full layout. */
body.single .fullgutenberg .wildbirds-edge-post {
    --wb-photo-width: min(100%, 850px);
    --wb-photo-margin: auto;
}
body.single .fullgutenberg.fullgutenberg_reg .wildbirds-edge-post {
    --wb-photo-width: min(100%, 1200px);
}
body.single .fullgutenberg.fullgutenberg_ext .wildbirds-edge-post {
    --wb-photo-width: min(100%, 1530px);
}

/* Featured images in REHub's reading-optimized modes. */
body.single .wildbirds-edge-post #rh_wide_inimage,
body.single #rh_p_l_fullwidth_opt #rh_wide_inimage {
    width: 100% !important;
    max-width: none !important;
}
body.single .wildbirds-edge-post #rh_wide_inimage > figure,
body.single #rh_p_l_fullwidth_opt #rh_wide_inimage > figure {
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    border-radius: 0 !important;
    background-size: cover !important;
}

/* Single-column REHub breakpoint. The default card uses the actual padding
   and border widths, not 100vw, avoiding scrollbar-induced stripes. */
@media (max-width: 1023px) {
    body.single .rh-container:has(> .rh-content-wrap > .main-side.single > .rh-post-wrapper) {
        --wb-page-padding: 15px;
        width: 100% !important;
        box-sizing: border-box !important;
        padding-left: var(--wb-page-padding) !important;
        padding-right: var(--wb-page-padding) !important;
    }

    /* Centered reading layouts without the standard padded card. */
    body.single .wildbirds-edge-post,
    body.single .wildbirds-edge-post .post-inner-wrapper,
    body.single :is(.fullgutenberg, .fullgutenberg.fullgutenberg_reg, .fullgutenberg.fullgutenberg_ext) .wildbirds-edge-post {
        --wb-photo-width: 100vw;
        --wb-photo-margin: calc((100% - 100vw) / 2);
    }

    /* Exact full viewport width for the standard REHub post card. */
    body.single .main-side.single > .rh-post-wrapper > .wildbirds-edge-post {
        --wb-outer-inset: calc(var(--wb-page-padding, 15px) + var(--wb-card-padding, 0px) + var(--wb-card-border, 0px));
        --wb-photo-width: calc(100% + var(--wb-outer-inset) + var(--wb-outer-inset));
        --wb-photo-margin: calc(0px - var(--wb-outer-inset));
        --wb-photo-inset: var(--wb-outer-inset);
    }

    body.single .wildbirds-edge-post #rh_wide_inimage,
    body.single #rh_p_l_fullwidth_opt #rh_wide_inimage {
        box-sizing: border-box !important;
        width: 100vw !important;
        max-width: none !important;
        margin-left: calc((100% - 100vw) / 2) !important;
        margin-right: calc((100% - 100vw) / 2) !important;
    }

    /* Keep photo captions legible after the image itself touches the screen. */
    body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) >
    :is(.wp-block-image, .wp-caption, .top_featured_image, .wp-block-post-featured-image, .wildbirds-image-row)
    :is(figcaption, .wp-caption-text) {
        padding-left: 15px;
        padding-right: 15px;
    }
}

/* REHub already removes the white card's padding and border on phones. */
@media (max-width: 479px) {
    body.single:not(.dark_body):not(.noinnerpadding) .main-side.single > .rh-post-wrapper {
        --wb-card-padding: 0px;
        --wb-card-border: 0px;
    }
}

/* Mixed photo/text rows.
   Leave the grid or flex tracks, gap, text and row width unchanged.
   Extend only a photo's outer-facing edge into the article inset.
   A middle column has no outer edge and keeps its original width. */
body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-columns:has(> .wp-block-column > :not(.wp-block-image)):not(.wildbirds-image-row, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]) > .wp-block-column:not(.no-image-bleed, [data-no-image-bleed]) > .wp-block-image:not(.alignleft, .alignright, .size-thumbnail, .no-image-bleed, [data-no-image-bleed]):not(:has(img.alignleft, img.alignright, img.size-thumbnail, img.emoji, img.avatar, img.wp-smiley, .no-image-bleed, [data-no-image-bleed])),
body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-media-text:not(.is-image-fill, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]) > .wp-block-media-text__media:has(img):not(.no-image-bleed, [data-no-image-bleed]):not(:has(img.size-thumbnail, .no-image-bleed, [data-no-image-bleed])) {
    --wb-mixed-start: 0px;
    --wb-mixed-end: 0px;
    box-sizing: border-box !important;
    width: calc(100% + var(--wb-mixed-start) + var(--wb-mixed-end)) !important;
    max-width: none !important;
    min-width: 0 !important;
    margin-left: calc(0px - var(--wb-mixed-start)) !important;
    margin-right: calc(0px - var(--wb-mixed-end)) !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    border-radius: 0 !important;
}

body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-columns:has(> .wp-block-column > :not(.wp-block-image)):not(.wildbirds-image-row, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]) > .wp-block-column:not(.no-image-bleed, [data-no-image-bleed]):first-child > .wp-block-image:not(.alignleft, .alignright, .size-thumbnail, .no-image-bleed, [data-no-image-bleed]):not(:has(img.alignleft, img.alignright, img.size-thumbnail, img.emoji, img.avatar, img.wp-smiley, .no-image-bleed, [data-no-image-bleed])),
body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-media-text:not(.is-image-fill, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]):not(.has-media-on-the-right) > .wp-block-media-text__media:has(img):not(.no-image-bleed, [data-no-image-bleed]):not(:has(img.size-thumbnail, .no-image-bleed, [data-no-image-bleed])) {
    --wb-mixed-start: var(--wb-photo-inset);
}

body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-columns:has(> .wp-block-column > :not(.wp-block-image)):not(.wildbirds-image-row, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]) > .wp-block-column:not(.no-image-bleed, [data-no-image-bleed]):last-child > .wp-block-image:not(.alignleft, .alignright, .size-thumbnail, .no-image-bleed, [data-no-image-bleed]):not(:has(img.alignleft, img.alignright, img.size-thumbnail, img.emoji, img.avatar, img.wp-smiley, .no-image-bleed, [data-no-image-bleed])),
body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-media-text:not(.is-image-fill, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]).has-media-on-the-right > .wp-block-media-text__media:has(img):not(.no-image-bleed, [data-no-image-bleed]):not(:has(img.size-thumbnail, .no-image-bleed, [data-no-image-bleed])) {
    --wb-mixed-end: var(--wb-photo-inset);
}

/* Native image proportions, including linked images and picture wrappers. */
body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-columns:has(> .wp-block-column > :not(.wp-block-image)):not(.wildbirds-image-row, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]) > .wp-block-column:not(.no-image-bleed, [data-no-image-bleed]) > .wp-block-image:not(.alignleft, .alignright, .size-thumbnail, .no-image-bleed, [data-no-image-bleed]):not(:has(img.alignleft, img.alignright, img.size-thumbnail, img.emoji, img.avatar, img.wp-smiley, .no-image-bleed, [data-no-image-bleed])) :is(a, picture, img),
body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-media-text:not(.is-image-fill, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]) > .wp-block-media-text__media:has(img):not(.no-image-bleed, [data-no-image-bleed]):not(:has(img.size-thumbnail, .no-image-bleed, [data-no-image-bleed])) :is(a, picture, img) {
    display: block !important;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    border-radius: 0 !important;
}

body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-columns:has(> .wp-block-column > :not(.wp-block-image)):not(.wildbirds-image-row, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]) > .wp-block-column:not(.no-image-bleed, [data-no-image-bleed]) > .wp-block-image:not(.alignleft, .alignright, .size-thumbnail, .no-image-bleed, [data-no-image-bleed]):not(:has(img.alignleft, img.alignright, img.size-thumbnail, img.emoji, img.avatar, img.wp-smiley, .no-image-bleed, [data-no-image-bleed])) img,
body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-media-text:not(.is-image-fill, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]) > .wp-block-media-text__media:has(img):not(.no-image-bleed, [data-no-image-bleed]):not(:has(img.size-thumbnail, .no-image-bleed, [data-no-image-bleed])) img {
    height: auto !important;
    max-height: none !important;
    object-fit: cover;
    border: 0 !important;
    box-shadow: none !important;
}

/* At WordPress's native stacking breakpoint, the photo column is the
   article's full text width. Reuse the existing full-bleed calculation.
   Rows explicitly set not to stack retain their side-by-side layout. */
@media (max-width: 781px) {
    body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-columns:has(> .wp-block-column > :not(.wp-block-image)):not(.wildbirds-image-row, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]):not(.is-not-stacked-on-mobile) > .wp-block-column:not(.no-image-bleed, [data-no-image-bleed]) > .wp-block-image:not(.alignleft, .alignright, .size-thumbnail, .no-image-bleed, [data-no-image-bleed]):not(:has(img.alignleft, img.alignright, img.size-thumbnail, img.emoji, img.avatar, img.wp-smiley, .no-image-bleed, [data-no-image-bleed])) {
        width: var(--wb-photo-width) !important;
        margin-left: var(--wb-photo-margin) !important;
        margin-right: var(--wb-photo-margin) !important;
    }
    body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-columns:has(> .wp-block-column > :not(.wp-block-image)):not(.wildbirds-image-row, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]):not(.is-not-stacked-on-mobile) > .wp-block-column:not(.no-image-bleed, [data-no-image-bleed]) > .wp-block-image:not(.alignleft, .alignright, .size-thumbnail, .no-image-bleed, [data-no-image-bleed]):not(:has(img.alignleft, img.alignright, img.size-thumbnail, img.emoji, img.avatar, img.wp-smiley, .no-image-bleed, [data-no-image-bleed])) figcaption {
        padding-left: 15px;
        padding-right: 15px;
    }
}

/* Gutenberg Media & Text uses its own 600px stacking breakpoint. */
@media (max-width: 600px) {
    body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-media-text:not(.is-image-fill, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]).is-stacked-on-mobile > .wp-block-media-text__media:has(img):not(.no-image-bleed, [data-no-image-bleed]):not(:has(img.size-thumbnail, .no-image-bleed, [data-no-image-bleed])) {
        width: var(--wb-photo-width) !important;
        margin-left: var(--wb-photo-margin) !important;
        margin-right: var(--wb-photo-margin) !important;
    }
    body.single :is(.wildbirds-edge-post, .wildbirds-edge-post .post-inner-wrapper) > .wp-block-media-text:not(.is-image-fill, .alignwide, .alignfull, .no-image-bleed, [data-no-image-bleed]).is-stacked-on-mobile > .wp-block-media-text__media:has(img):not(.no-image-bleed, [data-no-image-bleed]):not(:has(img.size-thumbnail, .no-image-bleed, [data-no-image-bleed])) figcaption {
        padding-left: 15px;
        padding-right: 15px;
    }
}
