/* Layout primitives: container, section, grid, stack, cluster. */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.container--narrow {
  max-width: var(--container-narrow);
}

.container--wide {
  max-width: var(--container-wide);
}

.section {
  padding-block: var(--space-section);
}

.section--tight {
  padding-block: calc(var(--space-section) * 0.6);
}

/* Slate on mist is only 4.22:1, so muted text turns charcoal here. */
.section--mist {
  --color-text-muted: var(--pg-charcoal);
  background: var(--color-surface-alt);
}

.section--white {
  background: var(--color-surface);
}

.section--dark {
  background: var(--color-inverse-bg);
  color: var(--color-inverse-text);
}

.section + .section:not([class*='section--']) {
  border-top: var(--hairline) solid var(--color-line);
}

/* Auto-fitting grid: columns are at least --grid-min wide and there are never more
   than --grid-cols of them (so 6 cards are 3 + 3, never 4 + 2). */
.grid {
  --grid-gap: var(--space-l);
  --grid-cols: 6;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, max(var(--grid-min, 18rem), (100% - (var(--grid-cols) - 1) * var(--grid-gap)) / var(--grid-cols))), 1fr));
  gap: var(--grid-gap);
}

.grid--2 {
  --grid-min: 22rem;
  --grid-cols: 2;
}

.grid--3 {
  --grid-min: 16rem;
  --grid-cols: 3;
}

/* Exactly three items: one column until all three fit side by side (never 2 + 1). */
@media (max-width: 58rem) {
  .grid--3:has(> :nth-child(3):last-child) {
    --grid-cols: 1;
  }
}

.grid--4 {
  --grid-min: 13rem;
  --grid-cols: 4;
}

/* Exactly four items: at most two columns until all four fit (never 3 + 1). */
@media (max-width: 64rem) {
  .grid--4:has(> :nth-child(4):last-child) {
    --grid-cols: 2;
  }
}

/* Vertical rhythm for flowing content. */
.stack > * + * {
  margin-top: var(--stack-space, var(--space-m));
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--cluster-gap, var(--space-s));
}

/* A list used for layout (grids of items), not as a bulleted list. */
.list-plain {
  list-style: none;
}

.prose {
  max-width: var(--measure);
}

.prose > * + * {
  margin-top: var(--space-s);
}
