/* components/tag-feed.css — the feed of tag.hbs, tag-news.hbs and
   tag-reviews.hbs beside the ad rail (the ad's own rules are in
   ad-slot.css), with the top-block templates' "More stories" /
   "Latest stories" header above. One column below --bp-lg. Also hides the
   tag label on tag-news.hbs's top row (.tag-top). With no rail beside it
   (author.hbs, none rendered, or Live and not yet filled), the feed runs
   full width. */

/* No row gap: the first card's padding already spaces it from the heading. */
.tag-feed {
  display: grid;
  column-gap: var(--space-10);
  margin-block: var(--space-16) var(--space-10);
}

/* No topic chip in the feed (every card would say the same tag). Sponsored
   posts keep theirs — it's a disclosure. An author's posts span sections,
   so theirs keep them all. */
.tag-feed:not([data-variant="author"]) .tag-feed__main .post-card:not(.tag-sponsored) .post-card__tag,
.tag-top .spotlight__label {
  display: none;
}

/* The card's own text–image gap assumes the text stops at its measure;
   beside the rail the feed narrows until the text runs up to the image. */
.tag-feed__main .post-card {
  column-gap: var(--space-6);
}

/* Author: the header's padding supplies the gap above the first card. */
.tag-feed[data-variant="author"] {
  margin-block-start: 0;
}

/* The archive header's rule is already above the top row. */
.tag-top {
  border-block-start: 0;
}

/* The ad rail (partials/ad-rail.hbs). min-width: 0 stops a creative wider
   than the column, before it's scaled, from widening the one-column grid. */
.tag-feed__rail {
  min-width: 0;
  margin-block-start: var(--space-10);
}

/* Live, ad-rail.hbs un-hides the rail once its slot fills. Needed because
   the sticky rail's display: flex below beats the browser's [hidden]. */
.tag-feed__rail[hidden] {
  display: none;
}

@media (width >= 64rem) {
  /* The rail is the width of its creative — 320px, default.hbs's rail size
     mapping; change them together — so the ad is never scaled down and
     only the feed gives way as the window narrows. */
  .tag-feed {
    grid-template-columns: minmax(0, 1fr) 320px;
    /* Columns end at different heights (the sticky rail stretches, below). */
    align-items: start;
  }

  /* Full width unless the rail is showing: author.hbs has none, paid members
     and ads Off get none, and Live it stays hidden until its slot fills. */
  .tag-feed__header,
  .tag-feed__main {
    grid-column: 1 / -1;
  }

  .tag-feed:has(> .tag-feed__rail:not([hidden])) :is(.tag-feed__header, .tag-feed__main) {
    grid-column: 1;
  }

  /* Row 1 is the header's; without one (tag.hbs) it collapses to nothing,
     so main and rail always share row 2. */
  .tag-feed__main {
    grid-row: 2;
  }

  .tag-feed__rail {
    grid-column: 2;
    grid-row: 2;
    /* Level with the first card's image. */
    margin-block-start: 0;
    padding-block-start: var(--space-6);
  }
}

/* Sticky rail — desktop, and only when the screen can hold the whole column.
   The rail fills the row; its ::after takes up to a screen off the end, so
   the ad has scrolled away before hyp-5 above the footer scrolls in. A flex
   basis of 0 keeps that screen out of the row's height (a short feed gains
   no blank space); the 1000 gives it the leftover before .tag-feed__rail-ad. */
@media (width >= 64rem) and (height >= 48rem) {
  .tag-feed__rail {
    align-self: stretch;
    display: flex;
    flex-direction: column;
  }

  .tag-feed__rail::after {
    content: "";
    flex: 1000 0 0px;
    max-block-size: 100vh;
  }

  .tag-feed__rail-ad {
    flex: 1 0 auto;
  }

  .tag-feed__rail-ad > :is(.ad-slot, .ad-preview) {
    position: sticky;
    top: var(--space-8);
  }
}
