/**
 * @file
 * Video matrix: grid of videos <-> player with a strip, in one bordered box.
 *
 * The list is laid out as a grid by default and as a horizontal strip once the
 * root has .is-playing (set by video-matrix.js).
 */

.rn-video-matrix {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin: 0 0 1.75rem;
  padding: 20px;
  border: 1px solid #dedede;
}

.rn-video-matrix.is-playing {
  gap: 16px;
}

.rn-video-matrix__heading {
  margin: 0;
  font-size: 1.125rem;
  line-height: 1.3;
}

/*
 * State change (video-matrix.js): content fades out, the state swaps, then the
 * box animates between its two measured heights while the content fades in.
 * Durations are mirrored in the script.
 */
.rn-video-matrix {
  transition: height 380ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* With a fixed height the flex children must keep their size, not squash. */
.rn-video-matrix > * {
  flex-shrink: 0;
  transition: opacity 280ms ease;
}

.rn-video-matrix.is-animating {
  overflow: hidden;
}

.rn-video-matrix.is-switching > * {
  opacity: 0;
  transition-duration: 160ms;
}

/* Player ---------------------------------------------------------------- */

.rn-video-matrix__stage {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  background: #000;
  overflow: hidden;
}

.rn-video-matrix__stage iframe,
.rn-video-matrix__stage .plyr {
  width: 100%;
  height: 100%;
  border: 0;
}

/* Matrix (grid) --------------------------------------------------------- */

.rn-video-matrix__items {
  display: grid;
  grid-template-columns: repeat(var(--rn-video-matrix-columns, 3), minmax(0, 1fr));
  gap: 20px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rn-video-matrix__item {
  min-width: 0;
  margin: 0;
  padding: 0;
}

.rn-video-matrix__item::before {
  content: none;
}

.rn-video-matrix__tile {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  color: inherit;
  cursor: pointer;
}

.rn-video-matrix__tile:focus-visible {
  outline: 2px solid #1585fe;
  outline-offset: 2px;
}

.rn-video-matrix__thumb {
  position: relative;
  display: block;
}

.rn-video-matrix__title {
  font-family: Poppins, sans-serif;
  font-size: 16px;
  line-height: 20px;
  font-weight: 600;
  color: #1a1a1a;
  word-break: break-word;
}

/* "Now playing" tag on the active tile. */
.rn-video-matrix__badge {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  height: 20px;
  padding: 0 10px;
  background: #1585fe;
  font-family: Poppins, sans-serif;
  font-size: 12px;
  line-height: 14px;
  font-weight: 500;
  text-transform: uppercase;
  white-space: nowrap;
  color: #fff;
}

/* Playing: the same list as a strip ------------------------------------- */

.rn-video-matrix.is-playing .rn-video-matrix__items {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  /* Room for the focus ring and the scrollbar without clipping tiles. */
  padding: 2px 2px 6px;
  scroll-snap-type: x proximity;
}

/* Five across, as in the design; more than five scroll sideways. */
.rn-video-matrix.is-playing .rn-video-matrix__item {
  flex: 0 0 calc((100% - 48px) / 5);
  scroll-snap-align: start;
}

.rn-video-matrix.is-playing .rn-video-matrix__title {
  font-size: 14px;
  line-height: 16px;
  font-weight: 500;
}

.rn-video-matrix__back {
  align-self: center;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font-family: Poppins, sans-serif;
  font-size: 14px;
  line-height: 16px;
  font-weight: 600;
  color: #8f8f8f;
  cursor: pointer;
  /* Opacity is the state-change fade, shared with the box's other children. */
  transition: color 150ms ease, opacity 280ms ease;
}

.rn-video-matrix__back:hover,
.rn-video-matrix__back:focus-visible {
  color: #1585fe;
  text-decoration: underline;
}

/* Narrow ---------------------------------------------------------------- */

@media (max-width: 700px) {
  .rn-video-matrix__items {
    grid-template-columns: repeat(min(var(--rn-video-matrix-columns, 3), 2), minmax(0, 1fr));
    gap: 16px;
  }

  .rn-video-matrix.is-playing .rn-video-matrix__item {
    flex-basis: calc((100% - 24px) / 3);
  }
}

/*
 * Phones: the matrix is a row to swipe through. Each tile is a little
 * narrower than the box, so part of the next one always shows -- that sliver
 * is what tells the viewer there are more videos.
 */
@media (max-width: 600px) {
  .rn-video-matrix {
    padding: 16px;
  }

  .rn-video-matrix__items {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    /* Room for the focus ring; the scrollbar is hidden, the peek does its job. */
    padding: 2px;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .rn-video-matrix__items::-webkit-scrollbar {
    display: none;
  }

  .rn-video-matrix__item {
    flex: 0 0 82%;
    scroll-snap-align: start;
  }

  /* While playing, the strip keeps its smaller tiles. */
  .rn-video-matrix.is-playing .rn-video-matrix__items {
    scroll-snap-type: x proximity;
  }

  .rn-video-matrix.is-playing .rn-video-matrix__item {
    flex-basis: 42%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rn-video-matrix,
  .rn-video-matrix > *,
  .rn-video-matrix__back {
    transition: none;
  }
}
