.grid,
.list {
  gap: 1rem;
  margin: 0;
  padding: 0;

  > * {
    display: flex;
    margin: 0;
    padding: 0;
    > * {
      flex: 1;
    }
  }
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
}

.list {
  display: flex;
  flex-direction: column;
}

section:has(.list),
section[name="labels"] {
  max-width: var(--max-line);
  margin-left: auto;
  margin-right: auto;
}

section[name="labels"] .grid {
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  grid-template-columns: repeat(3, 1fr);
  li a {
    flex: none;
  }
  @media (max-width: 800px) {
    grid-template-columns: repeat(2, 1fr);
  }
}

.card {
  background: var(--background-1);
  color: var(--foreground-2);
  border-radius: 6px;
  padding: 1rem;
  position: relative;
  outline: 2px solid transparent;
  transition: outline .1s ease-in-out;
  overflow: hidden;

  .grid & {
    /* stretch cards vertically across the grid cells */
    display: flex;
    flex-direction: column;
  }

  &:has(h3 a:hover),
  &:has(:focus-visible) {
    outline: 2px solid var(--orange-1);
  }

  h3 {
    color: var(--foreground-1);
    padding-top: 0;
    padding-right: 3.2em;
    margin-top: 0;
    margin-bottom: 2px;
    overflow-wrap: anywhere;

    + * {
      padding-top: 0;
      margin-top: 0;
      flex: 1; /* push other content to the end of the card */
    }
  }
  &:has(.stats .warning) h3 {
    padding-right: 4.8em;
  }

  h3 {
    color: var(--foreground-3);
  }

  h3 a,
  a[href*="q=author"] {
    color: var(--foreground-1);
    &:hover {
      color: var(--orange-1);
    }
  }

  p:last-child {
    margin-bottom: 0;
  }

  .stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 0;
    margin: 0;
    line-height: 1.6;
    position: absolute;
    top: 22px;
    right: 1rem;
    gap: 0;
    font-size: 12px;
    background: inherit;
    color: var(--foreground-3);
    svg {
      width: 12px;
      height: 12px;
    }
  }

  .labels {
    font-size: 12px;
    justify-content: flex-end;
    padding: 0;
    margin: 0;
  }

  .list & .labels {
    justify-content: flex-start;
    margin-top: 18px;  /* usually collapses with margin-bottom from .description */
  }

  .list & .stats {
    @media (min-width: 480px) {
      flex-direction: row-reverse;
      gap: 1em;
    }
  }

  .list & .description {
    font-size: 1rem;
    padding-top: 8px;
    max-width: calc(var(--max-line) * 5/6);
  }

  .button-group {
    line-height: 18px;
  }

  .button {
    background: var(--background-2);
    &:hover {
      background: var(--background-3);
    }
  }
}
