/* The feed page (feeds/index, _batch, _card, _rate and feed_controller.js).
   Cards sit in one grid whatever batch frame they arrived in: every batch
   frame is display: contents, so Turbo can nest them freely while the grid
   only ever sees cards. Every animation is a one-shot entrance with the
   reduced-motion fallback at the bottom. */

/* One column at every width, so the stream reads top to bottom. */
.feed-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem;
}

.feed-batch { display: contents; }
/* A frame still waiting to load needs a box of its own, or Turbo's
   IntersectionObserver never sees it scroll into view. Once complete it
   becomes display: contents like the rest and its cards join the grid. */
.feed-batch[loading="lazy"]:not([complete]) {
  display: block;
  grid-column: 1 / -1;
}

.feed-card,
.feed-slot {
  min-width: 0;
  animation: fade-up-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}
/* Even padding: for a visitor the card starts on its content (the label row
   is admin-only), and the rate row's stars carry their own hit padding at
   the bottom, so the same inset top and bottom reads as balanced. */
.feed-card {
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface-elevated);
  /* What an excerpt's "See more" fades into: the card's own background. */
  --excerpt-fade: var(--surface-elevated);
  padding: 1rem 1.25rem;
  box-shadow: var(--card-shadow);
}
/* A gentle stagger as a batch lands, capped so a late card never waits long. */
.feed-card:nth-child(2) { animation-delay: 0.05s; }
.feed-card:nth-child(3) { animation-delay: 0.1s; }
.feed-card:nth-child(4) { animation-delay: 0.15s; }
.feed-card:nth-child(n + 5) { animation-delay: 0.2s; }

/* Admin-only: the kind on the left, the time on the right. */
.feed-card__label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.feed-card__time { margin-left: auto; }
.feed-card__kind {
  display: inline-flex;
  align-items: center;
  border-radius: 9999px;
  background: var(--surface);
  padding: 0.125rem 0.625rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.feed-card__kind--new {
  background: var(--pill-green-bg);
  color: var(--pill-green-text);
}
.feed-card__kind--featured {
  background: var(--pill-amber-bg);
  color: var(--pill-amber-text);
}

/* The card bodies reuse the listing, patron and review partials, which carry
   their own list margins; inside a card those collapse to the card's padding. */
.feed-card__body > * { margin-top: 0; margin-bottom: 0; }

/* The rate row: stars always, the rest once a star is picked. */
.feed-rate {
  margin-top: 0.75rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}
.feed-rate__more { display: none; margin-top: 0.5rem; }
.feed-rate:has(input[type="radio"]:checked) .feed-rate__more { display: block; }

/* Load more (no-JavaScript fallback inside the lazy frame) and the end note
   span the whole grid. */
.feed-load-more,
.feed-end {
  grid-column: 1 / -1;
  text-align: center;
  padding: 1.5rem 0;
  color: var(--text-muted);
}
.feed-end { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }

/* The "N new items" pill: sticky under the header, shown by feed_controller.js. */
.feed-pill-holder {
  position: sticky;
  top: 1.25rem;
  z-index: 20;
  display: flex;
  justify-content: center;
  height: 0;
}
.feed-pill {
  transform: translateY(-50%);
  border: 1px solid var(--cta-border);
  border-radius: 9999px;
  background: var(--cta-bg);
  color: var(--cta-text);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: var(--card-shadow);
  cursor: pointer;
  animation: feed-pill-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.feed-pill:hover { background: var(--cta-hover); }
@keyframes feed-pill-in {
  from { opacity: 0; transform: translateY(-50%) scale(0.85); }
  to { opacity: 1; transform: translateY(-50%) scale(1); }
}

/* The blog cover sits in a <picture>; it must not become a box between the
   media frame and its image. */
.feed-media picture { display: contents; }

/* Phones (iPhone 13 up to the Pro Max, 390 to 440 CSS px): the feed reads
   like Instagram's. Posts run edge to edge, split by a hairline instead of
   boxed cards; a listing or patron opens with a round avatar beside a bold
   name; blog and news pictures go full width above their text; and the rate
   row becomes the action bar under the post, stars only. Tablet and desktop
   keep the boxed cards above. */
@media (max-width: 480px) {
  /* The layout's <main> pads 1rem each side; the feed bleeds through it. */
  #feed {
    width: calc(100% + 2rem);
    max-width: none;
    margin-inline: -1rem;
    padding: 0;
  }
  .feed-grid { gap: 0; }

  .feed-card {
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
    --excerpt-fade: var(--page-bg);
    box-shadow: none;
    padding: 0.75rem 0 0.25rem;
  }
  .feed-card__label { padding-inline: 0.75rem; }
  .feed-card__body { padding-inline: 0.75rem; }

  /* Listing and patron: avatar + name on one line, tagline and pills under. */
  .feed-card__body > div[itemtype$="SoftwareApplication"] { gap: 0.75rem; }
  .feed-card__body > div[itemtype$="SoftwareApplication"] > div:first-child {
    width: 2.75rem;
    min-width: 2.75rem;
    height: 2.75rem;
    border-radius: 9999px;
    background: var(--surface);
  }
  .feed-card__body > div[itemtype$="SoftwareApplication"] > div:first-child:not(.relative) { overflow: hidden; }
  .feed-card__body > div[itemtype$="SoftwareApplication"] > div:first-child img {
    width: 100%;
    height: 100%;
    border-radius: 9999px;
    object-fit: cover;
  }
  .feed-card__body > div[itemtype$="SoftwareApplication"] h3 {
    padding-bottom: 0.125rem;
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.3;
  }
  .feed-card__body > div[itemtype$="SoftwareApplication"] p[itemprop="headline"] {
    font-size: 0.875rem;
    line-height: 1.35;
  }
  /* Rating and pills sit flush left under the tagline, not centred. */
  .feed-card__body > div[itemtype$="SoftwareApplication"] a > div.justify-center { justify-content: flex-start; }
  /* The patron's sparkle sat on the corner of a 6rem logo; on the avatar it
     stays inside a smaller corner. */
  .feed-card__body > div[itemtype$="SoftwareApplication"] > div.relative > span { font-size: 1rem; }

  /* Reviews: the avatar line and stars read as the post's caption. */
  .feed-card__body > div[itemtype$="Review"] { margin-block: 0; }

  /* Blog and news: the picture is the post's media, full width and square,
     with the text under it like a caption. */
  .feed-card__body article > a,
  .feed-card__body article > a.flex { flex-direction: column; gap: 0.625rem; }
  .feed-media {
    width: auto;
    height: auto;
    aspect-ratio: 1 / 1;
    margin-inline: -0.75rem;
    border-radius: 0;
  }

  /* The rate row is the action bar: no divider, no label, bigger stars. */
  .feed-rate {
    margin-top: 0.5rem;
    border-top: 0;
    padding: 0 0.5rem 0.25rem;
  }
  .feed-rate form > div:first-of-type > span { display: none; }
  .feed-rate .star-icon { width: 1.75rem; height: 1.75rem; }
  .feed-rate label { padding: 0.25rem; }

  /* House cards and prompts keep a card look but sit inside the gutters. */
  .feed-slot { padding: 0.75rem; border-bottom: 1px solid var(--border); }
  .feed-load-more, .feed-end { padding: 1.25rem 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  .feed-card,
  .feed-slot,
  .feed-pill { animation: none; }
}
