/* Preserve complete uploaded artwork without stretching its text panel. */
body.legacy-mode .cards-grid .archive-card,
body.legacy-mode .cards-grid .archive-card:first-child {
  display: flex;
  flex-direction: column;
  align-self: start;
  width: 100%;
  min-width: 0;
  height: auto;
  min-height: 0 !important;
  gap: 0;
}

body.legacy-mode .cards-grid .archive-card .card-media,
body.legacy-mode .cards-grid .archive-card.featured-card .card-media {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  height: auto;
  min-height: 0;
  aspect-ratio: var(--media-ratio, 16 / 10);
}

body.legacy-mode .cards-grid .archive-card .card-media img {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: auto;
  min-height: 0;
  max-height: none;
  object-fit: contain;
  object-position: center;
}

body.legacy-mode .cards-grid .archive-card .card-body {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  height: auto;
  min-height: 0;
  align-content: start;
}

body.legacy-mode .cards-grid .archive-card .card-footer {
  margin-top: 0;
}

/* Sparse results have no measured spans, so their rows must contain the full
   cards. Pixel tracks are reserved for the measured layout below. */
body.legacy-mode .cards-grid:not(.balanced-cards-grid),
body.legacy-mode .reels-grid:not(.balanced-cards-grid) {
  grid-auto-rows: auto !important;
  grid-auto-flow: row;
}

/* Measured cover heights balance the masonry columns at the pager. The media
   stays contained, and text panels always use their real content height. */
body.legacy-mode .cards-grid.balanced-cards-grid,
body.legacy-mode .reels-grid.balanced-cards-grid {
  grid-auto-rows: 1px !important;
  row-gap: 0 !important;
  grid-auto-flow: row;
}

body.legacy-mode .cards-grid.balanced-cards-grid .archive-card .card-media,
body.legacy-mode .cards-grid.balanced-cards-grid .archive-card.featured-card .card-media {
  height: var(--balanced-media-height, auto) !important;
  min-height: 0;
  aspect-ratio: var(--media-ratio, 16 / 10);
  background: #100c0f;
}

body.legacy-mode .cards-grid.balanced-cards-grid .archive-card.reel-archive-card .card-media,
body.legacy-mode .reels-grid.balanced-cards-grid .reel-media {
  height: var(--balanced-media-height, var(--reel-media-height, 300px)) !important;
  min-height: 0;
  aspect-ratio: auto;
  background: #100c0f;
}

body.legacy-mode .reels-grid.balanced-cards-grid .reel-media {
  height: var(--balanced-media-height, var(--reel-preview-height, 400px)) !important;
}

body.legacy-mode .cards-grid.balanced-cards-grid .archive-card .card-media img {
  width: 100%;
  height: 100% !important;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
}

/* Reel covers retain every edge within a compact preview instead of making a
   portrait upload determine the entire column's height. Other cards stay natural. */
body.legacy-mode .cards-grid .archive-card.reel-archive-card .card-media {
  height: var(--reel-media-height, 320px) !important;
  min-height: 0;
  max-height: 320px;
  aspect-ratio: auto;
  background: #100c0f;
}

body.legacy-mode .cards-grid .archive-card.reel-archive-card .card-media img {
  width: 100%;
  height: 100% !important;
  max-height: 100%;
  object-fit: contain;
  background: #100c0f;
}

@media (max-width: 600px) {
  body.legacy-mode .cards-grid .archive-card.reel-archive-card .card-media {
    height: var(--reel-media-height, 280px) !important;
    max-height: 300px;
  }
}

/* Grid items otherwise retain the poster's intrinsic minimum width and clip its sides. */
@media (min-width: 981px) {
  body.legacy-mode.route-home .slider-frame {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    min-width: 0;
    min-height: 0;
    padding: 17px;
  }

  body.legacy-mode.route-home .slider-frame img {
    display: block;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: center;
  }

  body.legacy-mode.route-home .slider-is-reel.slider-tall .slider-frame {
    height: 440px !important;
    max-height: 440px;
  }

  body.legacy-mode.route-home .post-for-you-carousel.showing-reel {
    height: 328px;
    min-height: 0;
  }

  body.legacy-mode.route-home .reel-feature-slide .post-for-you-copy {
    padding: 22px 26px;
  }

  body.legacy-mode.route-home .reel-feature-slide .post-for-you-copy h2 {
    font-size: clamp(24px, 2.1vw, 30px);
    -webkit-line-clamp: 2;
  }

  body.legacy-mode.route-home .reel-feature-slide .post-for-you-copy p {
    -webkit-line-clamp: 3;
  }

  body.legacy-mode .main-nav {
    min-width: 0;
  }

  body.legacy-mode .main-nav button,
  body.legacy-mode:not(.header-is-scrolled) .main-nav button {
    padding-inline: clamp(8px, .85vw, 16px);
    font-size: clamp(11px, .8vw, 13.44px);
  }
}

@media (max-width: 980px) {
  body.legacy-mode.route-home .reel-feature-slide .post-for-you-media {
    height: min(280px, 44svh);
    min-height: 0;
    aspect-ratio: auto;
  }
}

@media (min-width: 981px) and (max-width: 1200px) {
  body.legacy-mode .brand,
  body.legacy-mode:not(.header-is-scrolled) .brand {
    min-width: 190px;
  }
}
