/* ============================================================================
   YEMMA CORE — the legal documents            handle: yemma-legal-page

   Almost nothing, and that is the test this file has to pass. The theme already
   draws every part of these pages: `.legal`, `.legal__toc`, `.legal__doc`,
   `.lsec`, `.plain`, `.lnote`, `.ltable`, `.ldocs`, `.ldoc__meta`, `.ldoc__end`
   and `.lrel` are all in its own `legal.css`, and `.phead`, `.crumbs`,
   `.sec-head`, `.btn` and `.wrap` are in the sheets beside it. The section
   numbering is a CSS counter over there and stays there.

   So what is left for this file is the one thing the theme could not know: how
   many cards the related-documents grid is actually handed. The theme's sheet
   was written against a set of five documents where every page shows four
   others; the plugin makes the number of documents a thing a shop decides, and
   a stylesheet cannot count what a template prints. `:has()` can.

   The handle carries the `-page` suffix for the reason `story.css` carries
   its own — and NOT for `usp.css`'s reason, which is the opposite one: that
   sheet shares the bare `yemma-usp` handle with the theme deliberately. Here
   the theme's own sheet is enqueued as `yemma-legal`,
   and a plugin handle that collided with it would silently unregister one of
   the two — leaving a page that is missing either every rule below or every
   rule above.

   ## Why both rules are inside a media query

   **The plugin's sheet prints BEFORE the theme's chain.** The plugin boots on
   `plugins_loaded` and the theme on `after_setup_theme`, both at priority 10,
   and this sheet declares no dependency on the theme's — so it lands first and
   source order is working against every rule in it. `assets/public/css/story.css`
   documents that at length and it is why nothing here relies on coming later.

   Specificity is what carries a rule instead, and that is exactly the hazard.
   The theme's `.lrel { grid-template-columns: repeat(3, ...) }` scores 0-1-0, and
   so does its `@media (max-width: 1000px) { .lrel { grid-template-columns: 1fr } }`
   — the one-column collapse that makes these cards readable on a phone. A
   selector like `.lrel:has(> a:nth-child(4):last-child)` scores 0-3-1, because
   `:has()` takes the specificity of its own argument. Specificity beats source
   order and it beats a media query's position in the cascade, so an unguarded
   rule here would put two columns on a 375px phone and win.

   That is not a hypothetical: `usp.css` shipped without its media queries and
   was wrong on every phone, silently, from the day it landed. The fix is not
   `!important` and it is not reordering. It is saying where each rule applies.
   The 1000px below is read off the theme's `legal.css:141`; it is the theme's
   number, not this file's, and if it moves there it moves here.
   ========================================================================== */

@media (min-width: 1001px) {

	/*
	 * FOUR CARDS — the case every page shows today.
	 *
	 * Five documents means every one of the five pages hands this grid four
	 * cards, and four in a three-column grid is three across and then one alone
	 * on a second row, two thirds of the width empty beside it. It reads as a
	 * card that failed to load. This is visible on all five pages right now.
	 *
	 * **2x2 rather than four across, and the card's own measure is what decides
	 * it.** The theme drew this grid at three across: inside a 1560px `.wrap`
	 * with its 3.6rem gutters and a 1.4rem gap, that is a card about 467px wide,
	 * of which roughly 410px is text after the card's own
	 * `clamp(1.2rem, 2vw, 1.7rem)` of padding — a little over sixty characters a
	 * line, which is a measure somebody chose.
	 *
	 * Four across at the same width gives about 345px, or 45 characters. That is
	 * still fine. The problem is the bottom of this rule's own range, and a rule
	 * has to be right across all of it: at 1001px, four across gives each card
	 * about 214px with roughly 174px of text — under thirty characters a line,
	 * with the 1.3rem serif `<h4>` "Shipping & returns" wrapping onto two lines
	 * and the 9.5px `.2em`-tracked kicker above it wrapping too. Laptops sit in
	 * the 1024-1280 band where that is the shape they would get.
	 *
	 * 2x2 at 1001px gives about 449px a card, which is within twenty pixels of
	 * the measure the design was drawn at. At the widest wrap it over-runs the
	 * other way, to roughly 95 characters — loose, and worth naming, but a long
	 * line is readable and a wrapped heading in a 214px box is not.
	 */
	.lrel:has(> a:nth-child(4):last-child) {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}

	/*
	 * FEWER THAN THREE — a shop that has not published five documents.
	 *
	 * This one is not hypothetical either. Trashing a page is the documented way
	 * to switch a legal document off, and the grid lists every document except
	 * the one being read: a shop with three documents shows two cards, and a shop
	 * with two shows one. One card in a three-column grid is a card sitting in
	 * the left third with two thirds of a bone band empty beside it, which looks
	 * like the page stopped loading rather than like a shop with two documents.
	 *
	 * Two across for two, and full width for one — the same answer `usp.css`
	 * reached for the same question, and for the same reason: a single item in a
	 * multi-column grid should fill the band it is in, because a band is what it
	 * is now the only thing in.
	 *
	 * Three needs no rule. It is already the default and it is already right.
	 *
	 * Five or more cards — a shop that adds a sixth document — falls back to the
	 * theme's three across, which for five is three and then two. That is left
	 * alone deliberately: it is a shape nobody has yet, and a third counting rule
	 * bought against a hypothetical shop is how a file like this stops being
	 * almost nothing.
	 */
	.lrel:has(> a:nth-child(1):last-child) {
		grid-template-columns: minmax(0, 1fr);
	}

	.lrel:has(> a:nth-child(2):last-child) {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

/*
 * Below 1001px the theme is already one column and there is nothing to count.
 *
 * A browser without `:has()` gets the three-column grid it always got, with the
 * gap it always had. That is the honest fallback: the band still reads, every
 * card is still a link to a document, and nothing about it is worse than it was
 * before this file existed.
 */
