/* The text flow: the text style of each element in running text, and the space between
   them. For an article, a fact sheet, legal text or an FAQ answer.
   Made by scripts/build.mjs. Change tokens/ or fonts/ and run npm run build, not this file.

   Link it after css/tokens.css, or import it after css/shadcn-theme.css, and put class="text-flow"
   on the element around the text:

       <article class="text-flow">
           <h1>A title</h1>
           <p class="text-flow-intro">The intro.</p>
           <h2>A heading</h2>
           <p>Text.</p>
       </article>

   A date line under the title ("Last updated: ...") is a paragraph with class="text-flow-meta".
   The elements are the article's children, not nested deeper. Images, tables, quotes and code
   are blocks; give anything else that should stand apart class="text-flow-block".

   The rules are in the components layer, as Tailwind's are, so a utility class or the page's
   own CSS still wins. A page that resets margins (* { margin: 0 }) must do it in the base layer,
   or the reset wins too. */
@layer base, components;

:root {
    --flow-title-gap: 0.5rem; /* Between the title and the intro or the date line */
    --flow-intro-space-after: var(--flow-block-gap); /* Between the intro, the date line or a title without them, and a heading, a list or a block */
    --flow-intro-to-paragraph: 1.5rem; /* Between the intro or the date line and a paragraph right under it */
    --flow-h2-space-before: 2.5rem; /* Above an H2, from the text before it */
    --flow-h2-space-after: 0.5rem; /* Between an H2 and its text */
    --flow-h3-space-before: 2.5rem; /* Above an H3 */
    --flow-h3-space-after: 0.5rem; /* Between an H3 and its text */
    --flow-h4-space-before: 2.5rem; /* Above an H4, H5 or H6 */
    --flow-h4-space-after: 0.5rem; /* Between an H4, H5 or H6 and its text */
    --flow-heading-to-heading: 1rem; /* A heading right after another heading with no text between, like an H3 under its H2 */
    --flow-heading-to-list: 0.75rem; /* Between a heading and a list that starts its text */
    --flow-paragraph-gap: 1.5rem; /* Between paragraphs */
    --flow-list-space-before: 0.5rem; /* Between a paragraph and the list it introduces */
    --flow-list-space-after: 1.875rem; /* Between a list and the paragraph after it */
    --flow-list-item-gap: 0.75rem; /* Between the items of a list */
    --flow-list-indent: 1.25rem; /* From the text's left edge to a list's text; the bullet sits in it */
    --flow-block-gap: 2.5rem; /* Above and below a block: an image, a table, a quote, a callout */

    /* The colours. On a coloured surface, set these two on the element with text-flow. */
    --flow-heading-color: var(--color-text-neutral, var(--foreground)); /* text/neutral */
    --flow-text-color: var(--color-text-secondary-neutral, var(--foreground-secondary)); /* text/secondary/neutral */
    --flow-meta-color: var(--color-text-tertiary-neutral, var(--muted-foreground)); /* text/tertiary/neutral */
    --flow-link-color: var(--color-link, var(--link)); /* link */
}

/* Phones have less room between sections and blocks */
@media (width < 48rem) {
    :root {
        --flow-h2-space-before: 2rem;
        --flow-h3-space-before: 2rem;
        --flow-h4-space-before: 2rem;
        --flow-block-gap: 2rem;
    }
}

@layer components {
    /* The text styles: Title (H1) Title 1 Bold, Date line Footnote, Intro Lead, H2 Title 2 Bold, H3 Title 3 Bold, H4 Headline Bold, H5 Body Bold, H6 Footnote Bold, Paragraphs and lists Body */
    .text-flow {
        font-family: var(--type-body-font, var(--font-sans));
        font-size: var(--type-body-size, var(--text-base));
        line-height: var(--type-body-line-height, 1.45);
        letter-spacing: var(--type-body-letter-spacing, 0em);
        font-weight: 400;
        color: var(--flow-text-color);
    }
    .text-flow > :where(h1) {
        font-family: var(--type-title-1-font, var(--font-display));
        font-size: var(--type-title-1-size, var(--text-3xl));
        line-height: var(--type-title-1-line-height, 1.1);
        letter-spacing: var(--type-title-1-letter-spacing, 0em);
        font-weight: 600;
        color: var(--flow-heading-color);
    }
    .text-flow > :where(.text-flow-meta) {
        font-family: var(--type-footnote-font, var(--font-sans));
        font-size: var(--type-footnote-size, var(--text-sm));
        line-height: var(--type-footnote-line-height, 1.5);
        letter-spacing: var(--type-footnote-letter-spacing, 0em);
        font-weight: 400;
        color: var(--flow-meta-color);
    }
    .text-flow > :where(.text-flow-intro) {
        font-family: var(--type-lead-font, var(--font-display));
        font-size: var(--type-lead-size, var(--text-xl));
        line-height: var(--type-lead-line-height, 1.3);
        letter-spacing: var(--type-lead-letter-spacing, 0.02em);
        font-weight: 400;
        color: var(--flow-text-color);
    }
    .text-flow > :where(h2) {
        font-family: var(--type-title-2-font, var(--font-display));
        font-size: var(--type-title-2-size, var(--text-2xl));
        line-height: var(--type-title-2-line-height, 1.3);
        letter-spacing: var(--type-title-2-letter-spacing, 0.01em);
        font-weight: 600;
        color: var(--flow-heading-color);
    }
    .text-flow > :where(h3) {
        font-family: var(--type-title-3-font, var(--font-display));
        font-size: var(--type-title-3-size, var(--text-xl));
        line-height: var(--type-title-3-line-height, 1.3);
        letter-spacing: var(--type-title-3-letter-spacing, 0.02em);
        font-weight: 600;
        color: var(--flow-heading-color);
    }
    .text-flow > :where(h4) {
        font-family: var(--type-headline-font, var(--font-display));
        font-size: var(--type-headline-size, var(--text-lg));
        line-height: var(--type-headline-line-height, 1.3);
        letter-spacing: var(--type-headline-letter-spacing, 0.02em);
        font-weight: 600;
        color: var(--flow-heading-color);
    }
    .text-flow > :where(h5) {
        font-family: var(--type-body-font, var(--font-sans));
        font-size: var(--type-body-size, var(--text-base));
        line-height: var(--type-body-line-height, 1.45);
        letter-spacing: var(--type-body-letter-spacing, 0em);
        font-weight: 600;
        color: var(--flow-heading-color);
    }
    .text-flow > :where(h6) {
        font-family: var(--type-footnote-font, var(--font-sans));
        font-size: var(--type-footnote-size, var(--text-sm));
        line-height: var(--type-footnote-line-height, 1.5);
        letter-spacing: var(--type-footnote-letter-spacing, 0em);
        font-weight: 600;
        color: var(--flow-heading-color);
    }
    .text-flow :where(strong, b) {
        font-weight: 600;
    }
    .text-flow :where(a) {
        color: var(--flow-link-color);
        text-decoration: underline;
        text-underline-offset: 0.25rem;
    }

    /* Lists */
    .text-flow :where(ul, ol) {
        display: flex;
        flex-direction: column;
        gap: var(--flow-list-item-gap);
        margin-block: 0;
        padding-inline-start: var(--flow-list-indent);
    }
    .text-flow :where(ul) {
        list-style: disc;
    }
    .text-flow :where(ol) {
        list-style: decimal;
    }
    .text-flow :where(li) > :where(ul, ol) {
        margin-top: var(--flow-list-item-gap);
    }

    /* The space between the elements. Every rule weighs the same, so a later one wins. */
    .text-flow > * {
        margin-block: 0;
    }
    .text-flow > * + * {
        margin-top: var(--flow-paragraph-gap);
    }
    .text-flow > * + :where(ul, ol) {
        margin-top: var(--flow-list-space-before);
    }
    .text-flow > :where(ul, ol) + * {
        margin-top: var(--flow-list-space-after);
    }
    .text-flow > * + :where(figure, img, picture, video, table, blockquote, pre, hr, aside, .text-flow-block),
    .text-flow > :where(figure, img, picture, video, table, blockquote, pre, hr, aside, .text-flow-block) + * {
        margin-top: var(--flow-block-gap);
    }
    .text-flow > * + :where(h2) {
        margin-top: var(--flow-h2-space-before);
    }
    .text-flow > * + :where(h3) {
        margin-top: var(--flow-h3-space-before);
    }
    .text-flow > * + :where(h4, h5, h6) {
        margin-top: var(--flow-h4-space-before);
    }
    .text-flow > :where(h2) + * {
        margin-top: var(--flow-h2-space-after);
    }
    .text-flow > :where(h3) + * {
        margin-top: var(--flow-h3-space-after);
    }
    .text-flow > :where(h4, h5, h6) + * {
        margin-top: var(--flow-h4-space-after);
    }
    .text-flow > :where(h2, h3, h4, h5, h6) + :where(ul, ol) {
        margin-top: var(--flow-heading-to-list);
    }
    .text-flow > :where(h2, h3, h4, h5, h6) + :where(h2, h3, h4, h5, h6) {
        margin-top: var(--flow-heading-to-heading);
    }
    .text-flow > :where(h1, .text-flow-intro, .text-flow-meta) + * {
        margin-top: var(--flow-intro-space-after);
    }
    .text-flow > :where(.text-flow-intro, .text-flow-meta) + :where(p) {
        margin-top: var(--flow-intro-to-paragraph);
    }
    .text-flow > :where(h1) + :where(.text-flow-intro, .text-flow-meta) {
        margin-top: var(--flow-title-gap);
    }
}
