article {
  --img-scale: 1.001;
  --title-color: black;
  --link-icon-translate: -20px;
  --link-icon-opacity: 0;
  position: relative;
  border-radius: 16px;
  box-shadow: none;
  height: 500px; /* Fixed height for all articles */
  background: #fff;
  transform-origin: center;
  transition: all 0.4s ease-in-out;
  overflow: hidden;
}

.title {
  margin-left: 100px;
}

article a::after {
  position: absolute;
  inset-block: 0;
  inset-inline: 0;
  cursor: pointer;
  content: "";
}

article h2 {
  margin: 0 0 18px 0;
  font-family: "Montserrat";
  font-size: 1rem;
  letter-spacing: 0.06em;
  color: var(--title-color);
  transition: color 0.3s ease-out;
}

article p {
  font-size: 1rem;
}

figure {
  margin: 0;
  padding: 0;
  aspect-ratio: 16/9;
  overflow: hidden;
}

article img {
  max-width: 100%;
  transform-origin: center;
  transform: scale(var(--img-scale));
  transition: transform 0.4s ease-in-out;
}

.article-body {
  max-height: 300px; /* Set a maximum height for content */
  padding: 24px;
  overflow-y: scroll; /* Enable vertical scrolling */
}

article a {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: #28666e;
}

article a:focus {
  outline: 1px dotted #28666e;
}

article a .icon {
  min-width: 24px;
  width: 24px;
  height: 24px;
  margin-left: 5px;
  transform: translateX(var(--link-icon-translate));
  opacity: var(--link-icon-opacity);
  transition: all 0.3s;
}

/* Generic layout settings */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #383838;
  font-family: "Montserrat", sans-serif;
  font-size: 1.2rem;
  line-height: 1.6rem;
  min-height: 100vh; /* Ensure the body is at least the viewport height */
}

.articles {
  display: grid;
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: 24px;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); /* Maintain a consistent grid layout */
  gap: 24px;
  margin-bottom: 50px;
}

/* using the has() relational pseudo selector to update our custom properties */
article:has(:hover, :focus) {
  --img-scale: 1.1;
  --title-color: #28666e;
  --link-icon-translate: 0;
  --link-icon-opacity: 1;
  box-shadow: rgba(0, 0, 0, 0.16) 0px 10px 36px 0px, rgba(0, 0, 0, 0.06) 0px 0px 0px 1px;
}

@media screen and (max-width: 960px) {
  article {
    height: 500px; /* Keep the same height on mobile screens */
  }

  .article-body {
    max-height: 250px; /* Maintain scroll behavior with a smaller max-height */
  }
}

@container card (min-width: 380px) {
  .article-wrapper {
    display: grid;
    grid-template-columns: 100px 1fr; /* Consistent two-column layout */
    gap: 16px;
  }

  .article-body {
    padding-left: 0;
  }

  figure {
    overflow: hidden; /* Prevent content overflow */
  }

  figure img {
    height: 100%;
    aspect-ratio: 1; /* Ensure the image maintains its aspect ratio */
    object-fit: cover; /* Ensure the image fills the container without distortion */
  }
}
