:where(table) {
  margin-block-start: var(--marx-flow);
  inline-size: 100%;
  font-variant-numeric: tabular-nums;
  /* separate + zero spacing so cell-borne row rules sit flush (append-safe) */
  border-collapse: separate;
  border-spacing: 0;
  /* marx keeps a top rule; typeset closes the bottom */
  border-block-start: 1px solid var(--marx-border);
  border-block-end: 1px solid var(--marx-border);
}

:where(caption) {
  caption-side: bottom;
  padding-block: var(--marx-space-sm);
  color: var(--marx-muted);
  font-size: var(--marx-text-sm);
}

/* No `white-space: nowrap` on headers — classless tables have no scroll
   wrapper, so wide tables must be allowed to wrap instead of overflow. */
:where(thead th) {
  text-align: start;
  /* stronger header rule, marx-style */
  border-block-end: 2px solid var(--marx-border);
}

:where(th, td) {
  padding-block: var(--marx-space-sm);
  padding-inline: var(--marx-space-md);
  text-align: start;
  vertical-align: top;
}

/* Row separators ride on cells, not tr/:last-child, so appended rows inherit them. */
:where(tbody, tfoot) :where(td, th) {
  border-block-start: 1px solid var(--marx-border);
}

/* First body row already sits under the table top rule (or thead's 2px rule),
   so drop its own top border to avoid a doubled line. */
:where(tbody:first-of-type tr:first-child) :where(td, th) {
  border-block-start: 0;
}

:where(tfoot td) {
  color: var(--marx-muted);
  font-size: var(--marx-text-sm);
}

/* Honour HTML alignment attributes, mapped to logical values. */
:where(th[align="center"], td[align="center"]) {
  text-align: center;
}
:where(th[align="right"], td[align="right"]) {
  text-align: end;
}
