/*** CMP-POSTCARD.CSS v4.1
- Shared "Post" card + grid component.
- Used by: the `cmp-postcard.html` include (Work / Agent / Agent-XT / Show /
  Label detail pages — "Articles & Episodes", "Mentioned In", authored post
  grids) and directly by the editorial-masthead post/show archives.
- Visual: 1px-framed card with a bleeding feature image, editorial serif
  title, sans meta strip, optional serif excerpt.
- Grid: 3 across ≥ 800px, stacking below. The composition modifier
  `cmp-posts-grid--featured-first` promotes the first card to a full-row
  two-column masthead.
##########################
***/

/* #region SECTION WRAPPER ############################################ */

.cmp-posts-grid-section {
  margin-top: 0;
}

.cmp-posts-grid-title {
  padding: 0 0 0.25rem 0;
  margin: 0 0 1.5rem 0;
  border-bottom: 1px solid var(--color-shade);
}

/* #endregion */

/* #region GRID ####################################################### */

.cmp-posts-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-column-gap: var(--space-md);
  grid-row-gap: var(--space-md);
}

/* Mirror grid.css narrow-viewport reduction. A 12-track template
   reserves (N − 1) × column-gap of intrinsic width regardless of how
   items span; at 2rem gap that's 352px, which exceeds the iPhone SE
   content area (≈ 311px) and pushes cards past the viewport. Shrinking
   the gap to 1rem here keeps the reserved width at 176px, well inside
   any modern phone viewport. */
@media (max-width: 540px) {
  .cmp-posts-grid { grid-column-gap: var(--space-sm); }
}

.cmp-posts-grid .column { grid-column: span 12; min-width: 0; }

@media (min-width: 800px) {
  .cmp-posts-grid .column { grid-column: span 4; }
}

/* #endregion */

/* #region CARD BASE ################################################## */

.cmp-postcard {
  position: relative;
  height: 100%;
  /* Contain the card inside its grid track. Without this, any inner child
     whose intrinsic width exceeds the track (meta flex that doesn't wrap,
     a long title, an image hover-transform) visually paints past the
     card's right edge — hiding the right border and spilling into (or
     past) the next card. */
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--color-black);
  background-color: var(--color-theme-alpha);
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* The link is an <a> (inline by default). Without an explicit block-level
   display, the inner grid has no determined width, 1fr collapses to
   min-content, and a long title blows the card past the viewport on
   narrow screens. Force block so the grid sizes to the card. */
.cmp-postcard-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.cmp-postcard-link:hover {
  text-decoration: none;
  cursor: pointer;
}

.cmp-postcard-link > .d-content {
  display: grid;
  /* minmax(0, 1fr) — without the 0-min, grid columns default to min-content,
     which lets long unbroken titles blow out the card on narrow viewports. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto;
  padding: var(--space-sm);
  gap: 0.75rem;
}

.cmp-postcard-title {
  grid-row: 3;
  font-weight: 700;
  color: inherit;
}

.cmp-postcard-title span {
  background-image: linear-gradient(180deg,
      transparent 50%,
      var(--color-high) 50% 80%,
      transparent 80%);
  background-size: 0% 100%;
  background-repeat: no-repeat;
  transition: background-size 0.5s ease;
}

.cmp-postcard-title span:hover {
  background-size: 100% 100%;
}

.cmp-postcard-meta {
  grid-row: 2;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  column-gap: var(--space-sm);
  min-width: 0;
}

.cmp-postcard-meta-alpha,
.cmp-postcard-meta-beta {
  min-width: 0;
}

.cmp-postcard-meta-alpha {
  color: var(--color-shade);
}

/* Keep the right-hand meta (date) aligned to the right edge even when
   its text wraps to multiple lines. */
.cmp-postcard-meta-beta {
  text-align: right;
}

.cmp-postcard-excerpt {
  grid-row: 4;
  color: inherit;
}

.cmp-postcard-figure {
  grid-row: 1;
  position: relative;
  overflow: hidden;
  margin: -var(--space-sm) -var(--space-sm) 0 -var(--space-sm); /* bleed to card edges, inside the var(--space-sm) d-content padding */
  width: auto;
  height: 240px;
  border-bottom: 1px solid var(--color-black);
}

.cmp-postcard-figure-image__wrapper {
  position: absolute;
  width: 100%;
  height: 100%;
}

.cmp-postcard-figure-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transition: transform 0.5s ease;
}

.cmp-postcard-figure-image:hover {
  transform: scale(1.05);
}

/* #endregion */

/* #region GRID-CONTEXT CHROME (editorial treatment when card sits in a
   .cmp-posts-grid — serif title, sans caps meta, serif excerpt) ########### */

.cmp-posts-grid .cmp-postcard-meta-beta {
  color: var(--color-black);
  font-variant-numeric: tabular-nums lining-nums;
}

.cmp-posts-grid .cmp-postcard-title {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 400;
  font-style: normal;
  font-size: var(--type-lg);
  line-height: 1.2em;
  letter-spacing: -0.005em;
  color: var(--color-black);
}

.cmp-posts-grid .cmp-postcard-title span {
  background: none;
}

.cmp-posts-grid .cmp-postcard-excerpt {
  margin: 0;
  font-family: var(--font-serif);
  font-size: var(--type-sm);
  line-height: 1.5em;
  color: var(--color-night);
  text-wrap: pretty;
}

/* #endregion */

/* #region FEATURED-FIRST VARIANT ##################################
   Promotes the first card into a full-row "masthead" with figure on
   the left and meta/title/excerpt on the right. Mirrors the gamma
   archive masthead from mp-archive.css, but lives here so any page
   using cmp-posts-grid can opt in by adding `cmp-posts-grid--featured-first`.
   Below 800px the featured card collapses back to the default --alpha
   layout so it reads identically to its siblings on phones/tablets. */

@media (min-width: 800px) {
  .cmp-posts-grid--featured-first > .column:first-child {
    grid-column: span 12;
  }

  .cmp-posts-grid--featured-first > .column:first-child .cmp-postcard > .cmp-postcard-link > .d-content {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    column-gap: var(--space-md);
    row-gap: 0.75rem;
    padding: 1.5rem;
    align-content: start;
  }

  .cmp-posts-grid--featured-first > .column:first-child .cmp-postcard-figure {
    grid-column: 1;
    grid-row: 1 / -1;
    margin: -1.5rem 0 -1.5rem -1.5rem;
    height: auto;
    min-height: 420px;
    border-bottom: none;
    border-right: 1px solid var(--color-black);
  }

  .cmp-posts-grid--featured-first > .column:first-child .cmp-postcard-meta,
  .cmp-posts-grid--featured-first > .column:first-child .cmp-postcard-title,
  .cmp-posts-grid--featured-first > .column:first-child .cmp-postcard-excerpt {
    grid-column: 2;
  }

  .cmp-posts-grid--featured-first > .column:first-child .cmp-postcard-meta { grid-row: 1; }
  .cmp-posts-grid--featured-first > .column:first-child .cmp-postcard-title {
    grid-row: 2;
    font-size: 2.5em;
    line-height: 1.1em;
  }
  .cmp-posts-grid--featured-first > .column:first-child .cmp-postcard-excerpt {
    grid-row: 3;
    font-size: var(--type-md);
    line-height: 1.45em;
    max-width: 56ch;
  }
}

/* #endregion */

