/* The story listing pages: Featured, Archive, Contributors, Index and a tag's
   stories. Values follow the wireframes' 04-pages-stories.css. */

/* A story's image with its headline and byline over it on hover. */
.story-card {
  position: relative;
  display: block;
  aspect-ratio: 3 / 2;
  color: var(--color-white);

  .card-image {
    width: 100%;
    height: 100%;
    overflow: hidden;

    img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform 0.75s var(--motion-ease-standard);
    }
  }

  .card-text {
    position: absolute;
    inset: 0;
    padding: 24px;
    background-color: rgba(0, 0, 0, 0.75);
    opacity: 0;
    transition: opacity 0.75s var(--motion-ease-standard);
  }

  .card-title {
    margin-bottom: 2px;
    font-size: 24px;
    line-height: 1;
  }

  .card-byline {
    margin-bottom: 9px;
    font-size: 14px;
  }

  &:hover,
  &:focus-visible {
    .card-image img {
      transform: scale(1.1);
    }

    .card-text {
      opacity: 1;
    }
  }
}

.stories {
  .page-title {
    margin-top: 72px;
    font-size: 18px;
    line-height: 36px;
    color: var(--color-primary);

    a {
      color: inherit;
    }
  }

  /* Featured, the Archive and a tag's stories, three across. */
  .story-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
}

/* The featured set as a carousel, then each set as its title over its
   stories. */
.stories.featured {
  padding-top: 80px;

  .featured-carousel {
    margin-bottom: 80px;

    .overlay {
      position: absolute;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      padding: 36px 48px 48px;
      color: var(--color-white);
      background-color: rgba(0, 0, 0, 0.1875);
      opacity: 0;
      transition: opacity 0.25s ease;
      pointer-events: none;
    }

    .slide.is-active .overlay {
      opacity: 1;
    }

    .overlay-title {
      margin: 0;
      font-family: "Cormorant Garamond", serif;
      font-size: 48px;
      font-weight: 400;
      line-height: 1.25;
      text-wrap: balance;
    }

    .overlay-byline {
      margin: 0;
      font-size: 18px;
    }
  }

  .story-set {
    margin-bottom: 80px;
  }

  .set-title {
    margin-bottom: 24px;
    font-size: 24px;
  }

  /* A square pick with the guest editor's commentary filling the row. */
  .guest-editor {
    .set-title {
      margin-bottom: 8px;
    }

    .set-description {
      width: 50%;
      margin-bottom: 16px;
      font-size: 16px;
      line-height: 24px;
      text-wrap: pretty;
    }

    .story-card.square {
      aspect-ratio: 1;
    }

    .commentary {
      grid-column: span 2;
      padding: 0 8px;

      p {
        margin-bottom: 16px;
        font-size: 16px;
        font-style: italic;
        line-height: 1.45;
      }
    }
  }
}

.stories.archive,
.stories.tag {
  .sorting-wrapper {
    margin-bottom: 12px;
  }

  .story-grid {
    margin-bottom: 300px;
  }

  .list-title {
    font-size: 24px;
  }
}

/* The filters are <details>, so they open without script; opening one closes
   the others (they share a name). */
.stories.archive {
  .sorting-wrapper {
    align-items: flex-start;
    margin: 24px 0 16px;
    padding-top: 12px;
    border-top: 0.625px solid var(--color-black);

    .pagination-inline {
      margin-top: 4px;
    }
  }

  .filters {
    display: flex;
    gap: 20px;
  }

  .sort-trigger {
    cursor: pointer;
    list-style: none;

    &::-webkit-details-marker {
      display: none;
    }
  }

  .sort-trigger-label {
    padding: 6px 0;
    font-size: 16px;
    line-height: 24px;
  }

  .sort-dropdown[open] .sort-panel {
    display: block;
  }

  .sort-panel {
    top: 100%;
    left: -24px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 12px 0;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.15);

    li + li {
      border-top: 0;
    }

    .sort-option {
      min-width: 180px;
      padding: 8px 24px 6px;
      color: var(--color-black);
      white-space: nowrap;

      &:hover,
      &.active {
        color: var(--color-primary);
      }
    }

    .more {
      margin-top: 12px;
    }
  }

  .no-results {
    margin-bottom: 300px;
  }
}

/* Contributors and the Index: an A–Z bar that stays in view beside the list. */
.stories.contributors,
.stories.tags {
  .letter-index {
    display: flex;
    align-items: flex-start;
    margin-top: 24px;
  }

  .letter-bar {
    position: sticky;
    top: calc(var(--layout-header-height) + 2rem);
    flex: 0 0 25%;

    &::before {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      width: calc(100% - 24px);
      border-top: 0.625px solid var(--color-black);
    }

    .letters {
      display: flex;
      justify-content: space-between;
      width: 66%;
      padding: 16px 0;
    }

    li {
      padding-bottom: 12px;
      font-size: 16px;
      line-height: 24px;
    }

    a:hover,
    a.active {
      color: var(--color-primary);
    }

    .top {
      display: inline-block;
      width: 18px;
      height: 18px;
      fill: none;
      stroke: var(--color-black);
      stroke-width: 1.5px;
      stroke-linecap: round;
      stroke-linejoin: round;
      transform: translateX(-4px);

      &:hover {
        stroke: var(--color-primary);
      }
    }

    .disabled {
      color: var(--color-gray-12);
    }
  }

  .letter-list {
    flex: 0 0 74%;
    margin-left: auto;
    margin-bottom: 300px;
  }

  .letter-group {
    scroll-margin-top: calc(var(--layout-header-height) + 2rem);

    .letter {
      margin-bottom: 16px;
      padding-top: 16px;
      border-top: 0.625px solid var(--color-black);
      font-size: 16px;
      line-height: 24px;
    }

    ul {
      columns: 2;
      column-gap: 0;
      width: 80%;
      margin-bottom: 24px;
    }

    li {
      break-inside: avoid;
    }

    a {
      font-size: 16px;
      line-height: 1.275;
      text-wrap: pretty;

      &:hover {
        color: var(--color-primary);
      }
    }
  }
}

.stories.tags .letter-group {
  ul {
    columns: 4;
    width: 98%;
  }

  /* Padding, not margin: a margin at a column break carries over to the top of the next column. */
  li {
    padding: 0 16px 16px 0;
  }
}

/* A story on the shared product card, under a story and on product pages. */
.card.related-story {
  .images-wrapper {
    overflow: hidden;
  }

  .detail-image {
    transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .story-author {
    font-weight: 400;
  }

  &:hover {
    .detail-image {
      transform: scale(1.1);
    }

    .product-name {
      color: var(--color-primary);
    }
  }
}

/* Four related stories under a story. */
.related-stories {
  margin: 64px 0 80px;

  .section-inner {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
  }
}

@media (max-width: 768px) {
  .stories.archive .filters {
    flex-wrap: wrap;
    gap: 4px 20px;
  }

  .stories.archive .sorting-wrapper {
    flex-wrap: wrap;
    height: auto;
  }

  .stories .story-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stories.featured .guest-editor .set-description {
    width: 100%;
  }

  .related-stories .section-inner {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stories.contributors,
  .stories.tags {
    .letter-bar {
      display: none;
    }

    .letter-list {
      flex-basis: 100%;
    }

    .letter-group ul {
      columns: 1;
      width: 100%;
    }
  }
}
