/**
 * Titula - reading engine.
 *
 * Loaded only when an article uses a reading profile. The Classic profile
 * (`none`) never requests this file, so a site upgraded from 1.x renders
 * exactly as before until it chooses a profile.
 *
 * WHAT THIS FILE DOES
 * -------------------
 * It sets the vertical rhythm between the blocks of an article: paragraphs,
 * lists, quotations, figures, tables and code, and the transitions where a
 * heading meets the block it introduces. That is all.
 *
 * WHAT IT DOES NOT DO
 * -------------------
 * - No font family, font size or line height is declared for Latin text. The
 *   theme's typography is inherited in every profile. The one exception is
 *   the Arabic Editorial profile, which raises line height because Arabic
 *   needs it and a Latin-designed theme cannot know that.
 * - Heading margins are left to the heading system (Headings screen), which
 *   already owns them. Only the gap between a heading and what immediately
 *   follows it is tightened here.
 * - Nothing outside `.acaart-pad-article__content` is selected, and only its
 *   direct children, so embeds, columns, galleries and other plugins' blocks
 *   nested inside keep their own spacing.
 * - Left, right and centre alignment are untouched: a floated or centred
 *   image keeps the theme's inline margins. Only the browser's default 40px
 *   indent on unaligned figures and quotations is removed, so they line up
 *   with the text column.
 */

.acaart-pad-article.has-reading-rhythm {
	/* The gap between reading blocks. Follows the Paragraph spacing setting. */
	--acaart-rhythm: 1;
	--acaart-flow: calc(var(--acaart-paragraph-gap, 1.15em) * var(--acaart-rhythm));

	/* Figures, tables and quotations are given a little more room than text. */
	--acaart-flow-media: 1.8em;

	/* A list item's gap to the next one. */
	--acaart-flow-item: 0.4em;
}

/* --------------------------------------------------------------------------
 * The flow
 * ----------------------------------------------------------------------- */

.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content > :is(p, ul, ol, dl, pre, .wp-block-list, .wp-block-code, .wp-block-preformatted, .wp-block-verse) {
	margin-block: 0 var(--acaart-flow);
}

.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content > :is(figure, blockquote, .wp-block-image, .wp-block-quote, .wp-block-pullquote, .wp-block-table, .acaart-pad-table-wrapper, .wp-caption, .wp-block-embed, .wp-block-video) {
	margin-block: var(--acaart-flow-media);
}

/*
 * Browsers indent <figure> and <blockquote> by 40px on each side unless told
 * otherwise, which leaves tables and images floating off the text column.
 */
.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content > :is(figure, blockquote):not(.alignleft):not(.alignright):not(.aligncenter):not(.alignwide):not(.alignfull) {
	margin-inline: 0;
}

.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content > hr {
	margin-block: var(--acaart-gap);
}

.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content > :first-child {
	margin-block-start: 0;
}

/*
 * Paragraphs follow the theme's alignment. Titula 1.x justified body text on
 * wide screens, which opens uneven gaps between words and does the most harm
 * in narrow columns and in Arabic. Profiles hand the decision back to the
 * theme.
 */
.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content > p {
	text-align: inherit;
	hyphens: manual;
}

/* --------------------------------------------------------------------------
 * Transitions
 * ----------------------------------------------------------------------- */

/*
 * A heading introduces what follows it. Without this, the larger margin a
 * figure or table carries opens a gap under the heading that detaches it from
 * its own content.
 */
.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content > :is(h2, h3, h4) + :is(figure, blockquote, ul, ol, pre, .wp-block-image, .wp-block-quote, .wp-block-table, .acaart-pad-table-wrapper, .wp-caption, .wp-block-list, .wp-block-code) {
	margin-block-start: var(--acaart-flow);
}

/* A subheading straight after its section heading belongs to it. */
.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content > h2 + h3,
.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content > h3 + h4 {
	margin-block-start: calc(var(--acaart-heading-space-after, 0.85em) * 1.4);
}

/* A Titula component placed by shortcode keeps its own, larger gap. */
.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content > .acaart-pad-module {
	margin-block: var(--acaart-gap);
}

/* --------------------------------------------------------------------------
 * Lists
 * ----------------------------------------------------------------------- */

.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content > :is(ul, ol) li {
	margin-block: 0;
}

.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content > :is(ul, ol) li + li {
	margin-block-start: var(--acaart-flow-item);
}

.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content > :is(ul, ol) :is(ul, ol) {
	margin-block: var(--acaart-flow-item) 0;
}

/* --------------------------------------------------------------------------
 * Figures and captions
 * ----------------------------------------------------------------------- */

.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content :is(figcaption, .wp-caption-text) {
	margin-block: 0.6em 0;
	font-size: 0.85em;
	line-height: 1.5;
	color: var(--acaart-muted);
	text-align: start;
}

/*
 * A classic-editor caption carries an inline width from the shortcode. On a
 * phone that width is wider than the screen; capping it keeps the image and
 * its caption inside the column without changing it anywhere else.
 */
.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content .wp-caption {
	max-inline-size: 100%;
}

/*
 * Space is reserved from the width and height attributes, which the browser
 * turns into an aspect ratio. `height: auto` is what lets that ratio apply
 * once the width is constrained, and it is already set by the base layer; it
 * is repeated here for images a theme has given a fixed height.
 */
.acaart-pad-article.has-reading-rhythm .acaart-pad-article__content img[width][height] {
	height: auto;
}

/* --------------------------------------------------------------------------
 * Profiles
 * ----------------------------------------------------------------------- */

/* Travel: more air around photographs and between blocks. */
.acaart-pad-article.acaart-pad-profile--travel {
	--acaart-rhythm: 1.1;
	--acaart-flow-media: 2.1em;
}

/* Technology: tighter, with code and lists held close to their text. */
.acaart-pad-article.acaart-pad-profile--technology {
	--acaart-rhythm: 0.9;
	--acaart-flow-media: 1.5em;
	--acaart-flow-item: 0.3em;
}

/*
 * Code needs a surface to be read as code. Declared at zero specificity with
 * :where(), so any theme that already styles `pre` keeps its own treatment.
 */
:where(.acaart-pad-profile--technology) :where(.acaart-pad-article__content) > :where(pre, .wp-block-code) {
	padding: 0.9em 1em;
	overflow-x: auto;
	border-radius: var(--acaart-radius, 4px);
	background: var(--acaart-surface-muted, rgba(0, 0, 0, 0.03));
	font-size: 0.9em;
	line-height: 1.55;
}

/* Knowledge: structured reference reading, lists easy to scan. */
.acaart-pad-article.acaart-pad-profile--knowledge {
	--acaart-flow-media: 1.7em;
	--acaart-flow-item: 0.5em;
}

.acaart-pad-article.acaart-pad-profile--knowledge .acaart-pad-article__content > dl dt {
	font-weight: 600;
}

.acaart-pad-article.acaart-pad-profile--knowledge .acaart-pad-article__content > dl dd {
	margin-block: 0.2em var(--acaart-flow-item);
	margin-inline-start: 0;
}

/*
 * Arabic Editorial.
 *
 * Applied whatever the detected language, because a site that chose it is
 * telling us its articles are in Arabic. Taller lines for the script's
 * ascenders, descenders and diacritics; letter spacing always normal, since
 * spacing joined letters apart breaks the words; no justification, which in
 * Arabic without kashida stretches the gaps between words instead of the
 * letters.
 */
.acaart-pad-article.acaart-pad-profile--arabic {
	--acaart-rhythm: 1.2;
	--acaart-flow-media: 2em;

	line-height: var(--acaart-line-height-ar, 1.9);
	word-spacing: var(--acaart-word-spacing-ar, normal);
}

.acaart-pad-article.acaart-pad-profile--arabic :is(p, li, h2, h3, h4, blockquote, figcaption) {
	letter-spacing: normal;
	text-transform: none;
}

.acaart-pad-article.acaart-pad-profile--arabic .acaart-pad-article__content > p {
	text-align: start;
}

.acaart-pad-article.acaart-pad-profile--arabic :is(h2, h3) {
	line-height: 1.45;
}

/* Minimal: spacing only. Colour and markers go back to the theme. */
.acaart-pad-article.acaart-pad-profile--minimal .acaart-pad-article__content li::marker {
	color: inherit;
}

.acaart-pad-article.acaart-pad-profile--minimal .acaart-pad-article__content :is(strong, b) {
	color: inherit;
}

.acaart-pad-article.acaart-pad-profile--minimal .acaart-pad-article__content > blockquote {
	border-inline-start-color: var(--acaart-border);
	color: inherit;
}

/* --------------------------------------------------------------------------
 * Small screens
 * ----------------------------------------------------------------------- */

@media (max-width: 640px) {
	.acaart-pad-article.has-reading-rhythm {
		--acaart-flow-media: 1.5em;
	}
}
