/* -- Article Header (website) ---------------------------------------
   Presents an article: category, the title (h1), a subtitle, the byline
   (Avatar, author link, date, read time) and an optional lead image with
   its caption. Centered, or as a cover - the copy over the image. */

@layer components {
  .mk-article-header {
    container: mk-article-header / inline-size;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    box-sizing: border-box;
    width: 100%;
    max-width: 52rem;
    margin-inline: auto;
    padding-inline: 1.25rem;
  }

  .mk-article-header-category {
    color: var(--primary);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;

    &:hover {
      text-decoration: underline;
      text-underline-offset: 0.2em;
    }
    &:focus-visible {
      outline: 2px solid var(--ring);
      outline-offset: 2px;
      border-radius: var(--radius-sm);
    }
  }

  .mk-article-header-title {
    margin: 0;
    font-size: 2.25rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.03em;
    text-wrap: balance;
  }

  .mk-article-header-subtitle {
    margin: 0;
    color: var(--muted-foreground);
    font-size: 1.1875rem;
    line-height: 1.5;
    text-wrap: pretty;
  }

  .mk-article-header-byline {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-block-start: 0.5rem;
    font-size: 0.875rem;
  }

  .mk-article-header-author {
    color: var(--foreground);
    font-weight: 600;
    text-decoration: none;

    &:hover {
      text-decoration: underline;
      text-underline-offset: 0.2em;
    }
    &:focus-visible {
      outline: 2px solid var(--ring);
      outline-offset: 2px;
      border-radius: var(--radius-sm);
    }
  }

  /* date · read time · … - dots between the parts */
  .mk-article-header-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0 0.5rem;
    color: var(--muted-foreground);

    & > * + *::before {
      content: "·";
      margin-inline-end: 0.5rem;
    }
  }

  .mk-article-header-media {
    width: 100%;
    margin: 1rem 0 0;

    & img {
      display: block;
      width: 100%;
      aspect-ratio: 16 / 9;
      object-fit: cover;
      border-radius: var(--radius-lg);
      background: var(--muted);
    }
    & figcaption {
      margin-block-start: 0.5rem;
      color: var(--muted-foreground);
      font-size: 0.8125rem;
    }
  }

  /* tags (Badges) and actions (listen, save, share) - each a row */
  .mk-article-header-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
  }
  .mk-article-header-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    margin-inline-start: auto;
  }
  /* the byline grows to hold actions at its end */
  .mk-article-header-byline:has(.mk-article-header-actions) {
    align-self: stretch;
    flex-wrap: wrap;
  }

  /* a series line: "Part 2 of 4" + a Progress bar */
  .mk-article-header-series {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    color: var(--muted-foreground);
    font-size: 0.8125rem;

    & .progress {
      width: 8rem;
    }
    & strong {
      color: var(--foreground);
      font-weight: 600;
    }
  }

  @container mk-article-header (min-width: 40rem) {
    .mk-article-header-title {
      font-size: 3rem;
    }
  }

  /* split: the copy beside the image (wraps under it when narrow) */
  .mk-article-header[data-variant="split"] {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
    align-items: center;
    gap: 1rem 2.5rem;
    max-width: 80rem;

    & > :not(.mk-article-header-media) {
      grid-column: 1;
    }
    & .mk-article-header-media {
      grid-column: -2;
      grid-row: 1 / span 6;
      margin: 0;
    }
    & .mk-article-header-media img {
      aspect-ratio: 4 / 5;
    }
  }

  /* one column: the image follows the copy */
  @container mk-article-header (max-width: 47rem) {
    .mk-article-header[data-variant="split"] .mk-article-header-media {
      grid-row: auto;
    }
  }

  /* editorial: serif, centered, an ornament and an italic subtitle */
  .mk-article-header[data-variant="editorial"] {
    align-items: center;
    text-align: center;

    & .mk-article-header-category {
      color: var(--muted-foreground);
      font-size: 0.75rem;
      letter-spacing: 0.2em;
      text-transform: uppercase;
    }
    & .mk-article-header-title {
      font-family: var(--font-serif);
      font-weight: 700;
      letter-spacing: -0.015em;
    }
    & .mk-article-header-subtitle {
      font-family: var(--font-serif);
      font-style: italic;
    }
    & .mk-article-header-byline::before,
    & .mk-article-header-byline::after {
      content: "";
      width: 2rem;
      height: 1px;
      background: var(--border);
    }
  }

  .mk-article-header[data-align="center"] {
    align-items: center;
    text-align: center;
  }

  /* cover: the image fills the header, the copy sits on it */
  .mk-article-header[data-variant="cover"] {
    justify-content: flex-end;
    max-width: 80rem;
    min-height: 26rem;
    padding: 2rem 1.5rem;
    overflow: hidden;
    border-radius: var(--radius-xl);
    background: #0b0b0f;
    color: #fff;

    & .mk-article-header-media {
      position: absolute;
      inset: 0;
      margin: 0;

      & img {
        height: 100%;
        aspect-ratio: auto;
        border-radius: 0;
      }
      & figcaption {
        position: absolute;
        inset-block-start: 0.75rem;
        inset-inline-end: 1rem;
        margin: 0;
        color: rgb(255 255 255 / 0.75);
        font-size: 0.75rem;
      }
      &::after {
        content: "";
        position: absolute;
        inset: 0;
        background: linear-gradient(to top, rgb(0 0 0 / 0.85), rgb(0 0 0 / 0.3) 60%, rgb(0 0 0 / 0.15));
      }
    }
    & > :not(.mk-article-header-media) {
      position: relative;
      z-index: 1;
      max-width: 44rem;
    }
    & :is(.mk-article-header-subtitle, .mk-article-header-meta) {
      color: rgb(255 255 255 / 0.82);
    }
    & :is(.mk-article-header-category, .mk-article-header-author) {
      color: #fff;
    }
  }

  /* -- Accessibility ------------------------------------------- */
  @media (prefers-contrast: more) {
    .mk-article-header-subtitle,
    .mk-article-header-meta {
      color: var(--foreground);
    }
  }

  @media (forced-colors: active) {
    .mk-article-header[data-variant="cover"] {
      border: 1px solid CanvasText;
    }
    .mk-article-header-media::after {
      display: none;
    }
  }
}
