/* Branch Wale RC11 — adaptive homepage story grid.
 * Keeps the established card design but prevents orphan cards at any story count.
 */
@media (min-width:901px){
  .bw-home-stories{
    grid-template-columns:repeat(6,minmax(0,1fr));
    gap:22px;
  }
  .bw-home-stories>.bw-story-card{grid-column:span 2;}
  .bw-home-stories>.bw-story-card--lead{grid-column:span 4;}

  /* One card left in the final three-column row: make it an intentional,
     centred two-column feature instead of leaving two empty card tracks. */
  .bw-home-stories.bw-home-story-rem-1>.bw-story-card:last-child{
    grid-column:2 / span 4;
  }

  /* Two cards left: split the row into two equal halves. */
  .bw-home-stories.bw-home-story-rem-2>.bw-story-card:nth-last-child(2),
  .bw-home-stories.bw-home-story-rem-2>.bw-story-card:last-child{
    grid-column:span 3;
  }

  /* If the site has only one story, let the lead story own the row. */
  .bw-home-stories.bw-home-story-count-1>.bw-story-card--lead{
    grid-column:1 / -1;
  }
}

/* Tablet: two balanced columns, with a single final card spanning the row. */
@media (min-width:701px) and (max-width:900px){
  .bw-home-stories{grid-template-columns:repeat(2,minmax(0,1fr));gap:20px;}
  .bw-home-stories>.bw-story-card{grid-column:span 1!important;}
  .bw-home-stories>.bw-story-card--lead{grid-column:1 / -1!important;}
  .bw-home-stories>.bw-story-card:last-child:nth-child(odd):not(.bw-story-card--lead){
    grid-column:1 / -1!important;
  }
}

/* Phones retain the existing single-column reading rhythm. */
@media (max-width:700px){
  .bw-home-stories{grid-template-columns:1fr;}
  .bw-home-stories>.bw-story-card,
  .bw-home-stories>.bw-story-card--lead{grid-column:auto!important;}
}


/* RC12 — archive/category grids use the same count-aware balancing philosophy.
 * No lead card is used on archives, so the normal desktop rhythm is three cards.
 * The final incomplete row is deliberately rebalanced instead of leaving a lonely
 * card at the far left. This applies to category, bank, RRB, topic, search and other
 * archive templates rendered through archive.php. */
@media (min-width:901px){
  .bw-archive-stories{
    grid-template-columns:repeat(6,minmax(0,1fr));
    gap:22px;
  }
  .bw-archive-stories>.bw-story-card{grid-column:span 2;}

  /* One card remains after complete rows: centre it and give it useful width. */
  .bw-archive-stories.bw-archive-story-rem-1>.bw-story-card:last-child{
    grid-column:2 / span 4;
  }

  /* Two cards remain: make them equal halves instead of leaving a blank third. */
  .bw-archive-stories.bw-archive-story-rem-2>.bw-story-card:nth-last-child(2),
  .bw-archive-stories.bw-archive-story-rem-2>.bw-story-card:last-child{
    grid-column:span 3;
  }
}

/* Tablet: two columns, with an odd final card spanning the row intentionally. */
@media (min-width:701px) and (max-width:900px){
  .bw-archive-stories{grid-template-columns:repeat(2,minmax(0,1fr));gap:20px;}
  .bw-archive-stories>.bw-story-card{grid-column:span 1!important;}
  .bw-archive-stories>.bw-story-card:last-child:nth-child(odd){
    grid-column:1 / -1!important;
  }
}

/* Phones: one-column feed, no special balancing needed. */
@media (max-width:700px){
  .bw-archive-stories{grid-template-columns:1fr;}
  .bw-archive-stories>.bw-story-card{grid-column:auto!important;}
}
