/* =============================================================
   barrio_npm_prototype — related-videos grid (shared component)

   Content-type-neutral. Any content type with field_related_videos renders
   the grid via templates/content/_video-grid.html.twig (data from
   Video\RelatedVideosBuilder) inside its own <section> + heading, and emits
   the shared #np-video-modal (_video-modal.html.twig + barrioNpmVideoModal
   JS). The section wrapper + heading are owned per-content-type; the grid +
   cards + count behaviour live here so they stay consistent everywhere.

   `data-count` sits on the grid, so the single/double sizing applies
   regardless of the wrapper:
     · 1 video  → 50% width + 16:9 poster (full width + 4:3 at phone)
     · 2 videos → forced 2 columns
     · 3+ videos → auto-fit grid
   ============================================================= */

.np-videos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.np-video-card {
  /* Strip UA <button> chrome and lay out as image-then-title column. */
  appearance: none;
  border: 0;
  padding: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: #2c2c2b;
}
.np-video-card:focus-visible {
  outline: 3px solid var(--hue);
  outline-offset: 2px;
  border-radius: 8px;
}
.np-video-card-thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: #f1ece1;
  display: block;
}
.np-video-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Play button — centered SVG triangle in a circular Pātai-hued background.
   Slightly translucent so the thumbnail is still readable beneath it.
   Stronger contrast + scale on hover/focus. */
.np-video-card-play {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 60px; height: 60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .92);
  color: var(--hue-dk);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
  transition: transform .15s, background .15s;
  pointer-events: none;
}
.np-video-card-play svg {
  margin-left: 4px; /* optical centring — triangle tip pulls right */
}
.np-video-card:hover .np-video-card-play,
.np-video-card:focus-visible .np-video-card-play {
  transform: translate(-50%, -50%) scale(1.08);
  background: #fff;
}
/* Title under the thumbnail. Clamps to two lines so cards in the same
   grid row stay roughly the same height. */
.np-video-card-title {
  font-size: 13.5px;
  line-height: 1.35;
  font-weight: 600;
  color: #2c2c2b;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Count-based sizing — on the grid, so every content type inherits it.
   1 video: capped at 50% (was a fixed 480px on the project wrapper) with a
   16:9 poster; 2 videos: forced 2-col; 3+ videos: the auto-fit grid above. */
.np-videos-grid[data-count="1"] {
  grid-template-columns: minmax(0, 50%);
}
.np-videos-grid[data-count="1"] .np-video-card-thumb {
  aspect-ratio: 16 / 9;
}
.np-videos-grid[data-count="2"] {
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 575.98px) {
  /* Smaller play button at phone width so it doesn't dominate the
     thumbnail when the grid drops to a single column. */
  .np-video-card-play {
    width: 48px;
    height: 48px;
  }
  /* A lone video goes full width with a 4:3 poster at phone width. */
  .np-videos-grid[data-count="1"] {
    grid-template-columns: 1fr;
  }
  .np-videos-grid[data-count="1"] .np-video-card-thumb {
    aspect-ratio: 4 / 3;
  }
}

/* ---------- Rail variant ----------
   Opt-in via templates/content/_video-grid.html.twig's `variant: 'rail'`
   arg (adds .np-videos-grid--rail). Added 2026-10-15 for the
   embedded-video detail page's right-rail scroll area — see
   documentation/embedded-video-detail-related-rail-plan.md D-R3.

   Desktop: compact vertical stack with thumb-left + title-right rows.
   Mobile (<880px): horizontal scroll strip with vertical cards per
   D-R4, so the rail doesn't make the mobile page extremely tall. */

.np-videos-grid--rail {
  /* Defeats the grid-template-columns + auto-fit from the default
     grid — flex-column stack for the rail form factor. The data-count
     sizing rules above don't apply here because they target the grid
     model specifically. */
  display: flex;
  flex-direction: column;
  grid-template-columns: none;
  gap: 14px;
}
.np-videos-grid--rail .np-video-card {
  /* Horizontal: thumb on the left, title on the right. `display: flex`
     is redeclared here because video-listing.css carries a
     `.np-video-card { display: block; }` rule at identical specificity
     that loads AFTER video-grid.css and overrides its default
     `display: flex`. Without redeclaring, flex-direction has no effect. */
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: start;
}
.np-videos-grid--rail .np-video-card-thumb {
  /* Fixed small landscape thumb. flex-basis holds the width so the
     title column takes the remainder. 120px is a bump from the initial
     100px — the brand-banner-heavy video thumbnails on this site
     needed a touch more pixel area to be distinguishable. */
  flex: 0 0 120px;
  width: 120px;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
}
.np-videos-grid--rail .np-video-card-play {
  /* Scale down the play button to match the smaller thumb. */
  width: 32px;
  height: 32px;
}
.np-videos-grid--rail .np-video-card-play svg {
  width: 18px;
  height: 18px;
}
.np-videos-grid--rail .np-video-card-title {
  /* Title takes the remaining row width; clamp to 3 lines (one more
     than default) because the thumb is small so a bit more title
     real-estate reads better. */
  flex: 1 1 0;
  font-size: 13px;
  line-height: 1.3;
  -webkit-line-clamp: 3;
  align-self: center;
}

/* Mobile: horizontal strip (D-R4). Each card returns to the default
   vertical shape but gets a fixed width + the row scroll-snaps. */
@media (max-width: 880px) {
  .np-videos-grid--rail {
    flex-direction: row;
    overflow-x: auto;
    gap: 12px;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(
      to right, black 0, black calc(100% - 1.5rem), transparent 100%
    );
            mask-image: linear-gradient(
      to right, black 0, black calc(100% - 1.5rem), transparent 100%
    );
  }
  .np-videos-grid--rail::-webkit-scrollbar {
    display: none;
  }
  .np-videos-grid--rail .np-video-card {
    /* Revert to vertical card inside the strip, fixed width. Same
       display:flex redeclaration reason as above (video-listing.css
       overrides). */
    display: flex;
    flex-direction: column;
    flex: 0 0 180px;
    scroll-snap-align: start;
  }
  .np-videos-grid--rail .np-video-card-thumb {
    flex: 0 0 auto;
    width: 180px;
    aspect-ratio: 16 / 9;
  }
  .np-videos-grid--rail .np-video-card-play {
    width: 44px;
    height: 44px;
  }
  .np-videos-grid--rail .np-video-card-title {
    font-size: 13px;
    -webkit-line-clamp: 2;
    align-self: auto;
  }
}
