/* Hide a card only when its sole child is a pending placement marker.
   Replacing that marker with the loaded creative releases the card. */
.gsra-marker[hidden],
:where(div, section, aside, li, p, figure):has(> .gsra-marker:only-child),
:where(.widget, .widget_block):has(> :only-child > .gsra-marker:only-child) {
    display: none !important;
}

/* The desktop sticky stop was calibrated with an ad at the bottom.
   Trim the Trending tail by 12px only while hidden slots follow it. */
@media screen and (min-width: 1024px) {
    body:is(.home, .blog) #page #secondary
    .widget:has(+ .gsra-marker[hidden]:last-child, + .gsra-marker[hidden] + .gsra-marker[hidden]:last-child)
    .gsr-trending {
        margin-bottom: 8px;
    }
}

/* Each boundary between a visible sponsor and its neighbor gets one gap. */
.widget-area { --gsra-placement-gap: 30px; }

.widget-area .widget:not(.widget_gsr-trending-news):has(+ .gsra-live-ad) {
    margin-bottom: var(--gsra-placement-gap) !important;
}
.gsra-live-ad:has(+ .widget_gsr-trending-news) {
    margin-bottom: var(--gsra-placement-gap, 30px);
}

/* Let the loaded lower placement own the gap after the final Trending card. */
.widget_gsr-trending-news:has(~ .gsra-live-ad) .gsr-trending,
#page .widget_gsr-trending-news:has(~ .gsra-live-ad) .gsr-trending__cards > article:last-child .card-blog-post {
    margin-bottom: 0 !important;
}

.widget_gsr-trending-news ~ .gsra-live-ad {
    padding-top: var(--gsra-placement-gap, 30px);
}

/* Fairy supplies a float clearfix. As a grid child it creates an empty
   final row with its own 20px gutter above the lower sponsor. */
.widget_gsr-trending-news:has(~ .gsra-live-ad) .gsr-trending__cards::after {
    content: none;
    display: none;
}

/* The category sticky columns stop at their content boxes. When the listing
   ends with cards, make the last card row the actual end of that box. */
@media screen and (min-width: 1024px) {
    #page .gsr-category-page .gsr-category__latest-section:has(> .gsr-category__grid:last-child),
    #page .gsr-category-page .gsr-category__latest-section > .gsr-category__grid:last-child {
        margin-bottom: 0 !important;
    }

    #page .gsr-category-page .gsr-category__grid:last-child::after {
        content: none;
        display: none;
    }
}

/* If only collapsed placements follow Trending on a desktop article, its
   last card is the sticky column's visible bottom. */
@media screen and (min-width: 1001px) {
    .gsr-article-layout__sidebar .widget_gsr-trending-news:has(~ .gsra-marker[hidden]):not(:has(~ .gsra-live-ad, ~ .widget)) .gsr-trending {
        margin-bottom: 0;
    }

    .gsr-article-layout__sidebar .widget_gsr-trending-news:has(~ .gsra-marker[hidden]):not(:has(~ .gsra-live-ad, ~ .widget)) .gsr-trending__cards::after {
        content: none;
        display: none;
    }
}

/* A terminal newsletter panel defines the weekly edition's visible baseline. */
@media screen and (min-width: 1001px) {
    body.gsr-article-layout-active #gsr-article-layout.gsr-weekly main > .gsr-weekly__newsletter:last-child {
        margin-bottom: 0;
    }
}
