/*
 * Long-form content presentation: poetry, essays, samples.
 *
 * Loaded site-wide after style.css (see inc/enqueue.php, priority 23).
 *
 * Everything here is scoped to an `mts-` class that appears in page content,
 * so nothing in this sheet can affect a page that has not opted in.
 *
 * Colour rule for this sheet: Brass #a8712a is 3.78:1 on Cream and must never
 * carry text. Brass Dark #8a5c1f is 5.26:1 on Cream and 4.65:1 on Sand, and is
 * the only brass used for type. Ratios in comments are measured, not estimated.
 */

/* ======================================================================
 * 1. Poetry
 * ====================================================================== */

/*
 * A poem is not body copy. style.css puts a 68ch measure on paragraphs so
 * prose reads well, but a poem's line breaks are authored — the line ends
 * where the poet ended it, and a column that rewraps them destroys the work.
 *
 * `width: max-content` sizes the verse box to its own longest line, so no
 * line wraps until the viewport is genuinely narrower than the poem. The
 * `max-width: 100%` then keeps it inside the page on small screens.
 */

.mts-poem,
.wp-block-group.is-style-poem {
	margin-block: var(--wp--preset--spacing--50);
}

/*
 * The left margin is load-bearing, not cosmetic. WordPress's constrained layout
 * emits
 *
 *   .is-layout-constrained > :where(:not(.alignleft):not(.alignright)…) {
 *     margin-left: auto !important; margin-right: auto !important; }
 *
 * A max-content box obeys that and gets centred, so each stanza centres on its
 * own longest line and the poem ends up with a ragged left edge — the one thing
 * a poem cannot have. Because core marks it !important, no amount of
 * specificity wins; !important here is the only lever, and it is scoped to
 * three classes that exist solely for this purpose.
 */
.mts-poem__verse,
p.is-style-verse,
.mts-poem.mts-poem > .mts-poem__verse,
.wp-block-post-content > .mts-poem .mts-poem__verse {
	width: max-content;
	max-width: 100%;
	margin-left: 0 !important;
	margin-right: auto !important;
	font-size: clamp(1.0625rem, 1rem + 0.35vw, 1.1875rem);
	line-height: 1.75;
	font-weight: 400;
	letter-spacing: 0;
	overflow-wrap: break-word;
	margin-block: 0 1.45em;
}

/*
 * Deliberately no `text-wrap: nowrap`. With max-content sizing, a line longer
 * than the container would then overflow the page instead of wrapping, and one
 * of these poems does have a line of that length. Letting the capped box wrap
 * is the graceful failure: short poems never wrap at all, long lines wrap only
 * when the viewport genuinely cannot hold them.
 *
 * Below that point, shrink the type so that fewer lines wrap in the first place.
 */
/*
 * px, not rem. In a media query `rem` resolves against the browser's root font
 * size, not the page's — so at a 20px default these two became 920px and 960px
 * while every other breakpoint in the theme (600, 781, 782, 900) stayed put,
 * and the poem shrank at a width unrelated to when the layout actually stacks.
 * These were the only rem media queries in the project.
 *
 * Paired with the two-column index below at 768px: they were 736px and 768px,
 * leaving a 32px band where the poem was full size but the index was still one
 * column. Same breakpoint for both now.
 */
@media (max-width: 767px) {
	.mts-poem__verse,
	.wp-block-post-content > .mts-poem .mts-poem__verse {
		width: auto;
		font-size: 1rem;
	}
}

.mts-poem__verse:last-child,
p.is-style-verse:last-child {
	margin-block-end: 0;
}

/* The date each poem carries in Mark's own text, set as a colophon. */
.mts-poem__date,
p.is-style-colophon {
	margin-block-start: var(--wp--preset--spacing--30);
	font-family: var(--wp--preset--font-family--display);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 400;
	text-transform: uppercase;
	letter-spacing: 0.14em;
	color: var(--wp--preset--color--contrast-2); /* 7.41:1 on Cream */
}

/*
 * Asides that follow a poem — the "That's nice poetry, dear." exchanges.
 * These were marked up as h3 headings, which put a punchline into the
 * document outline and skipped a level. They are quotations, not headings.
 */
.mts-poem-aside {
	margin-block-start: var(--wp--preset--spacing--50);
	padding-inline-start: var(--wp--preset--spacing--30);
	border-inline-start: 3px solid var(--wp--preset--color--primary);
	font-family: var(--wp--preset--font-family--display);
	font-size: var(--wp--preset--font-size--large);
	font-weight: 300;
	line-height: 1.35;
	color: var(--wp--preset--color--contrast); /* 16.35:1 on Cream */
}

/* Facsimile of a poem that also appears as text on the page. */
.mts-manuscript {
	margin-block: var(--wp--preset--spacing--50);
}

.mts-manuscript img {
	max-width: min(100%, 34rem);
	height: auto;
}

.mts-manuscript figcaption {
	font-size: var(--wp--preset--font-size--small);
	color: var(--wp--preset--color--contrast-2); /* 7.41:1 on Cream */
}

/* ----- Poem-to-poem navigation ---------------------------------------- */

.mts-poem-nav {
	margin-block-start: var(--wp--preset--spacing--60);
	padding-block-start: var(--wp--preset--spacing--30);
	border-block-start: 1px solid var(--wp--preset--color--base-2);
	display: flex;
	flex-wrap: wrap;
	gap: var(--wp--preset--spacing--30);
	align-items: baseline;
	justify-content: space-between;
	font-family: var(--wp--preset--font-family--display);
	font-size: var(--wp--preset--font-size--small);
	text-transform: uppercase;
	letter-spacing: 0.08em;
}

.mts-poem-nav a {
	color: var(--wp--preset--color--secondary); /* 10.58:1 on Cream */
}

.mts-poem-nav__next {
	margin-inline-start: auto;
	text-align: end;
}

/* ======================================================================
 * 2. Index of pieces — poems, essays, reports
 * ====================================================================== */

.mts-index,
.wp-block-group.is-style-index {
	display: grid;
	gap: var(--wp--preset--spacing--30);
	margin-block: var(--wp--preset--spacing--40);
	padding: 0;
	list-style: none;
}

/*
 * WordPress's flow layout puts `margin-block-start: <block-gap>` on every child
 * except the first. On a grid that offsets the second card in each row downward,
 * so the cards in a row no longer share a top edge. Gap already spaces them.
 * Class repeated to outrank core's `:where(.is-layout-flow) > *`.
 */
.mts-index.mts-index > *,
.is-style-index.is-style-index > * {
	margin-block: 0;
}

/* px for the same reason as the poem query above, and the same breakpoint. */
@media (min-width: 768px) {
	.mts-index--two {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

.mts-index__item {
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
	padding: var(--wp--preset--spacing--30);
	background: #fff;
	border: 1px solid var(--wp--preset--color--base-2);
	border-inline-start: 3px solid var(--wp--preset--color--primary);
	border-radius: 3px;
	transition: box-shadow var(--wp--custom--transition--base, 180ms ease),
		border-color var(--wp--custom--transition--base, 180ms ease);
}

.mts-index__item:hover {
	box-shadow: var(--wp--preset--shadow--soft);
	border-inline-start-color: var(--wp--preset--color--primary-dark);
}

/*
 * The heading is the only link in the card. A whole-card click target was
 * rejected: it makes the poem's opening lines unselectable and gives screen
 * reader users one enormous link label instead of a title.
 */
.mts-index__item h3 {
	margin: 0;
	font-size: var(--wp--preset--font-size--large);
	line-height: 1.2;
}

.mts-index__item h3 a {
	color: var(--wp--preset--color--contrast); /* 16.35:1 on Cream */
	text-decoration: none;
}

.mts-index__item h3 a:hover,
.mts-index__item h3 a:focus-visible {
	color: var(--mts-brass-text, #8a5c1f); /* 5.26:1 on Cream */
	text-decoration: underline;
	text-underline-offset: 0.18em;
}

/* Opening lines of a poem, quoted verbatim as a preview. */
.mts-index__opening {
	margin: 0;
	max-width: none;
	font-size: var(--wp--preset--font-size--medium);
	line-height: 1.5;
	color: var(--wp--preset--color--contrast-2); /* 7.41:1 on Cream */
}

/* Length / date line. */
.mts-index__meta {
	margin: 0;
	font-family: var(--wp--preset--font-family--display);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 400;
	text-transform: uppercase;
	letter-spacing: 0.1em;
	color: var(--wp--preset--color--contrast-2); /* 7.41:1 on Cream */
}

.mts-index__meta b {
	font-weight: 500;
	color: var(--mts-brass-text, #8a5c1f); /* 5.26:1 on Cream */
}

/* ======================================================================
 * 3. Work-sample galleries — ad copy, humour
 * ====================================================================== */

/*
 * These pages are screenshots of Mark's published ads and posts. Presented as
 * a run of full-width images they read as a camera roll; grouped into numbered
 * samples with a caption they read as a portfolio.
 */

.mts-sample,
.wp-block-group.is-style-sample {
	margin-block: var(--wp--preset--spacing--60);
	padding-block-start: var(--wp--preset--spacing--30);
	border-block-start: 2px solid var(--wp--preset--color--base-2);
}

.mts-sample__kicker {
	margin: 0 0 var(--wp--preset--spacing--20);
	font-family: var(--wp--preset--font-family--display);
	font-size: var(--wp--preset--font-size--small);
	font-weight: 500;
	text-transform: uppercase;
	letter-spacing: 0.16em;
	color: var(--mts-brass-text, #8a5c1f); /* 5.26:1 on Cream */
}

.mts-sample__title {
	margin-block: 0 var(--wp--preset--spacing--20);
}

/*
 * As with the poem verse: a max-width inside a constrained layout is centred by
 * core's !important auto margins. See the note in section 1.
 */
.mts-sample__note.mts-sample__note {
	max-width: 68ch;
	margin-left: 0 !important;
	margin-right: auto !important;
	color: var(--wp--preset--color--contrast-2); /* 7.41:1 on Cream */
}

/*
 * The screenshots are tall phone captures (roughly 461x1024). Left at full
 * content width they are enormous. A grid of fixed-width columns shows them at
 * the size they were actually taken.
 */
.mts-shots,
.wp-block-group.is-style-shots {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
	gap: var(--wp--preset--spacing--30);
	margin-block: var(--wp--preset--spacing--30);
	padding: 0;
	list-style: none;
}

.mts-shots .wp-block-image,
.mts-shots figure {
	margin: 0;
}

.mts-shots img {
	display: block;
	width: 100%;
	height: auto;
	background: var(--wp--preset--color--base-2);
	border: 1px solid var(--wp--preset--color--base-2);
	border-radius: 2px;
	box-shadow: var(--wp--preset--shadow--soft);
}

.mts-shots figcaption {
	margin-block-start: 0.5rem;
	font-size: var(--wp--preset--font-size--small);
	line-height: 1.4;
	color: var(--wp--preset--color--contrast-2); /* 7.41:1 on Cream */
}

/* A single wide screenshot that should not be forced into a narrow column. */
.mts-shots--wide {
	grid-template-columns: minmax(0, 32rem);
}

/* ======================================================================
 * 4. Shared
 * ====================================================================== */

/* Section intro used at the top of each writing index. See section 1 on why
 * these two margins are !important. */
.mts-section-intro.mts-section-intro {
	max-width: 60ch;
	margin-left: 0 !important;
	margin-right: auto !important;
}

/*
 * Focus visibility. style.css sets the site-wide ring; these are the elements
 * this sheet introduces that need it restated because they change colour on
 * hover and must not rely on colour alone (WCAG 1.4.1).
 */
.mts-index__item h3 a:focus-visible,
.mts-poem-nav a:focus-visible {
	outline: var(--wp--custom--focus-ring--width, 3px) solid
		var(--wp--preset--color--secondary);
	outline-offset: var(--wp--custom--focus-ring--offset, 2px);
	border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
	.mts-index__item {
		transition: none;
	}
}

/* ----- Print ----------------------------------------------------------- */

@media print {
	.mts-poem-nav {
		display: none;
	}

	.mts-poem__verse {
		width: auto;
		text-wrap: wrap;
		font-size: 11pt;
	}

	.mts-index__item {
		border: 1px solid #000;
		box-shadow: none;
		break-inside: avoid;
	}

	.mts-shots {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}
