/**
 * Component: prose, the editor content of the single templates (blog post,
 * case study, FAQ post intro). Works on block and classic (imported) HTML
 * alike: it styles plain elements; block styles only add enhancements.
 *
 * Measured from design/subpages/blog-single.png at 1920 (TODO: verify in
 * Figma): 17px grey body text, H2 in the .t-h4 style, H3 about 17px medium,
 * dark underlined links, a pull quote with an orange-to-blue start border
 * and a "— name, role" attribution,
 * tables with hairlines and a column divider. Captions and embeds are not in
 * the frames: proposals, TODO.
 *
 * Logical properties only (RTL follows the active language). Tokens used only
 * here are local to the component.
 *
 * @package cartrack
 */

.prose {
	--prose-text: var(--color-text-muted);
	--prose-strong: var(--color-text);
	--prose-gap: 1rem;
	--prose-h2-space: 3rem;
	--prose-h3-space: 1.75rem;
	--prose-list-indent: 1.25rem;
	--prose-rule: var(--color-border);
	--prose-figure-space: 2.5rem;
	--prose-caption-size: var(--t-small-size);   /* Proposal (no caption in the frame). */
	--prose-quote-size: 1.125rem;                /* ~18px */
	--prose-quote-font: var(--t-body-family);    /* Roboto 500 (case study frame); the blog post sets Montserrat. TODO: verify. */
	--prose-quote-weight: var(--font-weight-medium);
	--prose-quote-border: 3px;
	--prose-quote-from: var(--color-primary);
	--prose-quote-to: var(--color-secondary);
	--prose-cell-padding: 0.75rem;
	--prose-table-min: 32rem;                    /* Narrower screens scroll the table. */

	color: var(--prose-text);
	font-family: var(--t-body-family);
	font-size: var(--t-body-size);
	line-height: var(--t-body-line-height);
	overflow-wrap: anywhere; /* Long words and URLs never widen the page. */
}

.prose > * {
	margin-block: 0 var(--prose-gap);
}

.prose > :last-child {
	margin-block-end: 0;
}

/* ---------- Headings ---------- */

.prose h2,
.prose h3,
.prose h4 {
	color: var(--prose-strong);
	overflow-wrap: break-word;
}

.prose h2 {
	margin-block: var(--prose-h2-space) var(--prose-gap);
	font-family: var(--t-h4-family);
	font-size: var(--t-h4-size);
	font-weight: var(--t-h4-weight);
	line-height: var(--t-h4-line-height);
	letter-spacing: var(--t-h4-tracking);
}

.prose h3,
.prose h4 {
	margin-block: var(--prose-h3-space) calc(var(--prose-gap) / 2);
	font-family: var(--t-body-bold-family);
	font-size: var(--t-body-bold-size);
	font-weight: var(--t-body-bold-weight);
	line-height: var(--t-body-bold-line-height);
}

.prose > :first-child {
	margin-block-start: 0;
}

/* Scroll targets clear the sticky header. */
.prose [id] {
	scroll-margin-block-start: calc(var(--header-height) + var(--space-md));
}

/* ---------- Text ---------- */

.prose strong,
.prose b {
	color: var(--prose-strong);
	font-weight: var(--font-weight-medium);
}

.prose a {
	color: var(--prose-strong);
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 0.2em;
}

.prose a:focus-visible {
	outline: 2px solid var(--color-focus-dark);
	outline-offset: 2px;
}

/* TODO: verify hover state in Figma (no hover frame supplied). */
@media (hover: hover) {
	.prose a:hover {
		color: var(--color-primary);
	}
}

.prose ul,
.prose ol {
	padding-inline-start: var(--prose-list-indent);
}

.prose li + li {
	margin-block-start: calc(var(--prose-gap) / 2);
}

.prose hr {
	margin-block: var(--prose-h2-space);
	border: 0;
	border-block-start: 1px solid var(--prose-rule);
}

/* ---------- Media ---------- */

.prose img,
.prose video,
.prose iframe {
	max-inline-size: 100%;
	block-size: auto;
}

.prose figure {
	margin-block: var(--prose-figure-space);
	margin-inline: 0;
}

.prose figure img {
	display: block;
	inline-size: 100%;
}

.prose figcaption {
	margin-block-start: calc(var(--prose-gap) / 2);
	color: var(--color-text-muted);
	font-size: var(--prose-caption-size);
	line-height: var(--t-small-line-height);
}

/* Classic embeds without the block wrapper keep a 16:9 frame (proposal). */
.prose > iframe,
.prose p > iframe {
	display: block;
	inline-size: 100%;
	aspect-ratio: 16 / 9;
}

/* ---------- Quote ---------- */

/*
 * Every quote (blocks and imported classic HTML) has the frames'
 * orange-to-blue start border, about 18px: Roboto 500 by default (case
 * study), Montserrat on the blog post (--prose-quote-font). TODO: verify.
 */
.prose blockquote {
	margin-block: var(--prose-figure-space);
	margin-inline: 0;
	padding-inline-start: var(--space-lg);
	border-inline-start: var(--prose-quote-border) solid;
	border-image: linear-gradient(to bottom, var(--prose-quote-from), var(--prose-quote-to)) 1;
	color: var(--prose-strong);
	font-family: var(--prose-quote-font);
	font-size: var(--prose-quote-size);
	font-weight: var(--prose-quote-weight);
	line-height: var(--line-height-body);
}

.prose blockquote p {
	margin-block: 0 var(--prose-gap);
}

.prose blockquote cite,
.prose blockquote footer {
	display: block;
	color: var(--color-text-muted);
	font-family: var(--t-body-family);
	font-size: var(--t-body-size);
	font-style: normal;
	font-weight: var(--font-weight-medium);
}

/*
 * "— " before the attribution: CSS only and decorative (the empty
 * alternative text keeps it out of the accessibility tree; browsers without
 * that syntax use the first declaration). As ::before it sits at the
 * inline start, so it is on the right in RTL. Only direct children: a
 * <cite> inside a paragraph is a work's title, not an attribution. A dash typed by the editor is
 * removed by cartrack_single_content(), so it never doubles.
 */
.prose blockquote > cite::before,
.prose blockquote > footer::before {
	content: "\2014\00a0";
	content: "\2014\00a0" / "";
}

/* ---------- Tables (wrapped by cartrack_wrap_tables()) ---------- */

.prose__table {
	margin-block: var(--prose-figure-space);
	overflow-x: auto;
}

.prose__table:focus-visible {
	outline: 2px solid var(--color-focus-dark);
	outline-offset: 2px;
}

.prose table {
	inline-size: 100%;
	min-inline-size: var(--prose-table-min);
	border-collapse: collapse;
}

.prose th,
.prose td {
	padding: var(--prose-cell-padding);
	border-block-end: 1px solid var(--prose-rule);
	text-align: start;
	vertical-align: top;
}

.prose th + th,
.prose td + td {
	border-inline-start: 1px solid var(--prose-rule);
}

.prose th {
	color: var(--prose-strong);
	font-weight: var(--font-weight-medium);
}

.prose caption {
	caption-side: bottom;
	padding-block-start: calc(var(--prose-gap) / 2);
	color: var(--color-text-muted);
	font-size: var(--prose-caption-size);
	text-align: start;
}

/* Core table block wrapper: no extra margin around the scroll box. */
.prose .wp-block-table {
	margin-block: var(--prose-figure-space);
}

.prose .wp-block-table .prose__table {
	margin-block: 0;
}
