@layer resets, defaults, layouts, components;

@layer resets {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html {
    -moz-text-size-adjust: none;
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
  }

  body,
  h1,
  h2,
  h3,
  h4,
  p {
    margin: 0;
  }

  ul {
    list-style: none;
    padding-inline-start: 0;
    margin: 0;
  }

  body {
    min-height: 100vh;
    line-height: 1.5;
    display: grid;
    grid-template-rows: auto 1fr auto;
  }

  h1,
  h2,
  h3,
  h4,
  button,
  input,
  label {
    line-height: 1.1;
  }

  h1,
  h2,
  h3,
  h4 {
    text-wrap: balance;
  }

  a:not([class]) {
    text-decoration-skip-ink: auto;
    color: currentColor;
  }

  img,
  picture {
    max-width: 100%;
    display: block;
  }

  input,
  button,
  textarea,
  select {
    font-family: inherit;
    font-size: inherit;
  }
}

@layer defaults {
  @font-face {
    font-family: "Inconsolata";
    src: url("../fonts/inconsolata.woff2") format("woff2");
    font-display: swap;
  }

  :root {
    --gutter: 1rem;
    --full-bleed: 1 / -1;
    --with-gutter: 2 / 3;
    --max-content-width: 55em;
    --gradient-1: linear-gradient(
      90deg in oklab,
      oklch(70% 0.5 0) -27% -27%,
      oklch(80% 0.3 238) 50%,
      oklch(80% 0.3 161) 115% 115%
    );
    font-family: "Inconsolata", monospace;
    font-weight: 400;
    font-style: normal;
    color-scheme: light dark;
  }

  body {
    display: grid;
    grid-template-columns:
      minmax(var(--gutter), 1fr)
      minmax(0, var(--max-content-width))
      minmax(var(--gutter), 1fr);
    row-gap: clamp(1rem, 5vw, 2rem);
    margin-block: 1rem;
  }

  header,
  footer {
    grid-column: var(--with-gutter);
  }

  main {
    display: grid;
    grid-column: var(--full-bleed);
    grid-template-columns: subgrid;
  }

  h1 {
    font-weight: bolder;
    font-size: clamp(2rem, 5vw, 3rem);
  }

  h2 {
    font-weight: bold;
  }
}

@layer layouts {
  .article-list {
    display: grid;
    grid-column: var(--with-gutter);
    grid-auto-flow: dense;
    grid-template-columns: repeat(3, 1fr);
    container-type: inline-size;
    gap: 2rem;
  }

  .article-detail {
    display: grid;
    grid-column: var(--full-bleed);
    grid-template-columns: subgrid;
    grid-auto-rows: max-content;
    * {
      grid-column: var(--with-gutter);
    }
    h2 {
      font-size: clamp(2rem, 5vw, 3rem);
      margin-block-end: 1.5rem;
    }
    img {
      grid-column: var(--full-bleed);
      aspect-ratio: 16 / 9;
      object-fit: cover;
      width: 100%;
      margin-block-end: clamp(1.5rem, 5vw, 3rem);
    }

    .author::before {
      content: "";
      display: block;
      height: 2px;
      background: var(--gradient-1);
      margin-block-end: 1.5rem;
    }

    .category {
      padding-block-end: 1rem;
      margin-block-end: 1rem;
    }

    @media (width > 50em) {
      grid-template-columns: repeat(3, 1fr);
      grid-column: var(--with-gutter);
      grid-auto-flow: dense;
      column-gap: 2rem;
      img {
        grid-column: span 2;
        grid-row: span 5;
      }
      h2,
      time,
      .category,
      .author {
        grid-column-start: 3;
      }
      p {
        grid-column: span 3;
        white-space: pre-wrap;
      }
    }
  }
}

@layer components {
  .article-card {
    grid-column: 1 / -1;
    container-type: inline-size;
    a {
      text-decoration: none;
      color: currentColor;
    }
    img {
      width: 100%;
      object-fit: cover;
      margin-block-end: 0.5rem;
      aspect-ratio: 16 / 9;
    }
    p {
      display: flex;
      justify-content: space-between;
    }
    span {
      display: block;
      line-height: 115%;
    }
    h2 {
      font-size: clamp(1.5rem, 5cqw, 2rem);
      margin-block-end: 0.5rem;
    }
  }

  @media (width > 50em) {
    .article-card--small {
      grid-area: span 1 / span 1;
      img {
        aspect-ratio: 3 / 2;
      }
    }

    .article-card--medium {
      grid-area: span 2 / span 2;
      img {
        aspect-ratio: 5 / 4;
      }
    }

    .article-card--large {
      grid-area: span 2 / span 3;
      img {
        aspect-ratio: 16 / 9;
      }
    }
  }
}
