/*
 * A — news: indexed rows from the blog snapshot. A row comes in two shapes, with an excerpt or
 * without one (most blog posts have none), and every row of a shape has one height whatever the
 * post holds: the title keeps exactly two lines (clamped, reserved when short), an excerpt two
 * more; a row without one reserves nothing for it. On wide screens such a row gives the excerpt's
 * columns to the title. Long unbroken strings wrap anywhere, the category ends in an ellipsis,
 * and the whole row is the link's target.
 */

.news-list {
  display: grid;
  grid-template-columns: subgrid;
  margin-top: 3rem;
  border-top: 1px solid var(--rule);
  counter-reset: news;
}

.news-list > li {
  grid-column: 1 / -1;
}

/* Without the Worker the list holds one fallback link. */
.news-list > li:not(.news-card) {
  padding: 16px var(--pad);
}

.news-card {
  --title-fs: 1.0625rem;
  --title-lh: calc(1.4 * var(--title-fs));
  --excerpt-fs: 0.875rem;
  --excerpt-lh: calc(1.6 * var(--excerpt-fs));
  position: relative;
  display: grid;
  grid-template-columns: subgrid;
  /* Meta, then the title's two lines (and the excerpt's two, when there is one). */
  grid-template-rows: auto calc(2 * var(--title-lh));
  row-gap: 8px;
  padding: 14px 0 18px;
  border-bottom: 1px solid var(--hair);
  counter-increment: news;
}

.news-card:has(.news-excerpt) {
  grid-template-rows: auto calc(2 * var(--title-lh)) calc(2 * var(--excerpt-lh));
}

.news-card > * {
  min-width: 0;
}

.news-card::before {
  content: counter(news, decimal-leading-zero);
  grid-column: 1;
  grid-row: 1;
  padding-left: var(--pad);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
  color: var(--fg-mute);
}

.news-category {
  grid-column: 2 / 5;
  grid-row: 1;
  overflow: hidden;
  padding-left: var(--pad);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.news-card time {
  grid-column: 5 / -1;
  grid-row: 1;
  justify-self: end;
  padding-right: var(--pad);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--fg-mute);
  white-space: nowrap;
}

/* The title sits on the bottom line of its two: a short one leaves the room above it, under the
   meta, not a gap where text seems to be missing. */
.news-card a {
  grid-column: 1 / -1;
  grid-row: 2;
  align-self: end;
  display: block;
  padding: 0 var(--pad);
  text-decoration: none;
}

/* The row is the link. */
.news-card a::after {
  content: "";
  position: absolute;
  inset: 0;
}

.news-title,
.news-excerpt {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.news-title {
  font-size: var(--title-fs);
  font-weight: 700;
  line-height: var(--title-lh);
  letter-spacing: -0.02em;
}

.news-card:hover .news-title {
  text-decoration: underline;
  text-decoration-thickness: 1px;
}

.news-excerpt {
  grid-column: 1 / -1;
  grid-row: 3;
  height: calc(2 * var(--excerpt-lh));
  padding: 0 var(--pad);
  font-size: var(--excerpt-fs);
  line-height: var(--excerpt-lh);
  color: var(--fg-mute);
}

.news__all {
  margin-top: 1.5rem;
  padding: 0 var(--pad);
  font-size: 0.9375rem;
  font-weight: 600;
}

@media (min-width: 768px) {
  .news-list {
    margin-top: 4rem;
  }

  /* One line of the table: index, category over date, title, excerpt. */
  .news-card,
  .news-card:has(.news-excerpt) {
    --title-fs: 1.25rem;
    grid-template-rows: auto 1fr;
    row-gap: 4px;
    padding: 18px 0 20px;
  }

  .news-category {
    grid-column: 2 / 4;
  }

  .news-card time {
    grid-column: 2 / 4;
    grid-row: 2;
    justify-self: start;
    padding: 0 0 0 var(--pad);
  }

  /* Without an excerpt the title runs on through the excerpt's columns. */
  .news-card a {
    grid-column: 4 / -1;
    grid-row: 1 / 3;
    align-self: start;
  }

  .news-card:has(.news-excerpt) a {
    grid-column: 4 / 9;
  }

  .news-excerpt {
    grid-column: 9 / -1;
    grid-row: 1 / 3;
  }
}
