/*
 * Post body typography, on the site (.entry-content) and in the block editor (.is-root-container),
 * so the editor looks like the published post.
 *
 * Most of the archive is classic-editor HTML from 2004 onwards; the second half of this file
 * makes that markup behave: floats, captions, wide images, tables, inline styles, embeds.
 */

:is(.entry-content, .is-root-container) {
	max-width: var(--acw-measure);
	font-family: var(--acw-serif);
	font-size: var(--acw-fs-body);
	line-height: var(--acw-lh-body);
	color: var(--acw-ink);
	overflow-wrap: break-word;
}

/* Rhythm: one blank line between blocks. */
:is(.entry-content, .is-root-container) > * {
	margin-block: 0 1.1em;
}

:is(.entry-content, .is-root-container) > :last-child {
	margin-bottom: 0;
}

:is(.entry-content, .is-root-container) p {
	margin-block: 0 1.1em;
}

:is(.entry-content, .is-root-container) :is(h1, h2, h3, h4, h5, h6) :is(strong, b) {
	font-weight: inherit;
}

:is(.entry-content, .is-root-container) :is(h2, h3, h4, h5, h6) {
	margin: 1.8em 0 0.6em;
	font-family: var(--acw-serif);
	font-weight: 500;
	line-height: var(--acw-lh-hed);
	letter-spacing: var(--acw-tracking-hed);
	text-wrap: balance;
}

/* A stray <h1> in a post body shouldn't compete with the page title. */
:is(.entry-content, .is-root-container) h1,
:is(.entry-content, .is-root-container) h2 {
	font-size: 1.6em;
}

:is(.entry-content, .is-root-container) h3 {
	font-size: 1.3em;
}

:is(.entry-content, .is-root-container) :is(h4, h5, h6) {
	font-size: 1.1em;
}

:is(.entry-content, .is-root-container) h1 {
	margin: 1.8em 0 0.6em;
	font-weight: 500;
	line-height: var(--acw-lh-hed);
}

:is(.entry-content, .is-root-container) a {
	color: var(--acw-accent);
	text-decoration-thickness: 1px;
	text-underline-offset: 0.15em;
}

:is(.entry-content, .is-root-container) a:hover {
	color: var(--acw-ink);
}

/* Long unbroken URLs used as link text. */
:is(.entry-content, .is-root-container) a {
	overflow-wrap: anywhere;
}

:is(.entry-content, .is-root-container) :is(strong, b) {
	font-weight: 600;
}

:is(.entry-content, .is-root-container) :is(ul, ol) {
	padding-left: 1.4em;
}

:is(.entry-content, .is-root-container) li {
	margin-bottom: 0.4em;
}

:is(.entry-content, .is-root-container) li > :is(ul, ol) {
	margin-top: 0.4em;
}

/* Superscripts (footnote marks, "21st") without stretching the line. */
:is(.entry-content, .is-root-container) :is(sup, sub) {
	font-size: 0.7em;
	line-height: 0;
}

:is(.entry-content, .is-root-container) hr {
	width: 100%;
	margin: 2em 0;
	border: 0;
	border-top: var(--acw-rule-hair);
}

:is(.entry-content, .is-root-container) :is(code, kbd, samp) {
	font-family: var(--acw-mono);
	font-size: 0.85em;
}

:is(.entry-content, .is-root-container) pre {
	max-width: 100%;
	overflow-x: auto;
	padding: var(--acw-space-4);
	background: var(--acw-surface);
	border-radius: var(--acw-radius-sm);
	font-family: var(--acw-mono);
	font-size: 0.8em;
	line-height: 1.5;
	white-space: pre;
}

:is(.entry-content, .is-root-container) mark {
	background: var(--acw-mark);
	color: inherit;
}

/* A highlight the author coloured in the editor (bright green, yellow…) keeps dark text, or
   the night theme's light text vanishes on it. */
:is(.entry-content, .is-root-container) mark[style*="background-color"] {
	color: #16181d;
}

/*
 * Quotations. Authors quote documents and statements at length (blockquote is used in 2,000+
 * posts), so a quote reads like body text, set off by a rule, rather than as a big italic
 * pull quote. The pull-quote look is kept for the core Pullquote block.
 */
:is(.entry-content, .is-root-container) blockquote {
	margin: 1.4em 0;
	padding: 0 0 0 1.1em;
	border-left: 3px solid var(--acw-hairline);
	color: var(--acw-text-2);
}

:is(.entry-content, .is-root-container) blockquote blockquote {
	margin: 1em 0;
}

:is(.entry-content, .is-root-container) blockquote > :last-child {
	margin-bottom: 0;
}

:is(.entry-content, .is-root-container) blockquote cite {
	display: block;
	margin-top: 0.6em;
	font-family: var(--acw-sans);
	font-size: var(--acw-fs-caption);
	font-style: normal;
	color: var(--acw-muted);
}

:is(.entry-content, .is-root-container) .wp-block-pullquote {
	margin: 1.6em 0;
	padding: 0;
	border: 0;
	text-align: left;
}

:is(.entry-content, .is-root-container) .wp-block-pullquote blockquote {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: var(--acw-fs-quote);
	font-style: italic;
	line-height: 1.35;
	color: var(--acw-ink);
}

/* Embedded tweets, shown as the quote fallback (X's script is not loaded). */
:is(.entry-content, .is-root-container) blockquote.twitter-tweet {
	max-width: 520px;
	padding: var(--acw-space-4) var(--acw-space-5);
	border: 1px solid var(--acw-hairline);
	border-radius: var(--acw-radius-lg);
	font-family: var(--acw-sans);
	font-size: var(--acw-fs-ui-sm);
	line-height: var(--acw-lh-ui);
	color: var(--acw-ink);
}

:is(.entry-content, .is-root-container) blockquote.twitter-tweet p {
	margin-bottom: 0.6em;
	font-size: var(--acw-fs-ui);
}

:is(.entry-content, .is-root-container) blockquote.twitter-tweet > a:last-child {
	font-size: var(--acw-fs-caption);
	color: var(--acw-muted);
}

/* ---------- Images and captions ---------- */

:is(.entry-content, .is-root-container) img {
	max-width: 100%;
	height: auto;
	border-radius: var(--acw-radius-sm);
}

/* Night theme: charts and maps are often transparent PNGs with black text; give them a page. */
.entry-content img:not(.emoji, .wp-smiley) {
	background: var(--acw-img-backdrop);
}

/* Inline icons and emoji in old posts shouldn't get rounded corners or become blocks. */
:is(.entry-content, .is-root-container) img[width][height]:is([width="1"], [height="1"]) {
	display: none;
}

:is(.entry-content, .is-root-container) :is(figure, .wp-caption) {
	max-width: 100%;
	margin: 1.6em 0;
}

/* [caption] sets an inline width; never let it overflow the column. */
:is(.entry-content, .is-root-container) .wp-caption {
	width: auto !important;
}

:is(.entry-content, .is-root-container) :is(figcaption, .wp-caption-text, .wp-element-caption, .gallery-caption) {
	margin-top: var(--acw-space-3);
	font-family: var(--acw-sans);
	font-size: var(--acw-fs-caption);
	line-height: 1.5;
	color: var(--acw-muted);
	text-align: left;
}

:is(.entry-content, .is-root-container) :is(.aligncenter, .wp-block-image.aligncenter) {
	display: block;
	margin-inline: auto;
}

:is(.entry-content, .is-root-container) img.aligncenter {
	margin-block: 1.6em;
}

/* Images wider than the column (tagged .is-wide by the theme) break out to the right, up to 1000px. */
.entry-content img.is-wide {
	display: block;
	max-width: min(var(--acw-wide), 100cqi);
}

.entry-content :is(figure, .wp-caption, p):has(img.is-wide) {
	max-width: min(var(--acw-wide), 100cqi);
}

.entry-content :is(figure, .wp-caption):has(img.is-wide) :is(figcaption, .wp-caption-text) {
	max-width: var(--acw-measure);
}

/* Floats only where there's room; on phones floated images sit full width in the flow. */
:is(.entry-content, .is-root-container) :is(.alignleft, .alignright, [style*="float"]) {
	float: none !important;
	display: block;
	margin: 1.6em auto !important;
}

@media (min-width: 700px) {
	:is(.entry-content, .is-root-container) :is(.alignleft, [style*="float: left"], [style*="float:left"]) {
		float: left !important;
		max-width: 50%;
		margin: 0.3em 1.5em 1em 0 !important;
	}

	:is(.entry-content, .is-root-container) :is(.alignright, [style*="float: right"], [style*="float:right"]) {
		float: right !important;
		max-width: 50%;
		margin: 0.3em 0 1em 1.5em !important;
	}
}

/* Keep floats from poking into the next section, author box, etc. */
.entry-content::after {
	content: "";
	display: table;
	clear: both;
}

/* Galleries ([gallery] and the gallery block). */
:is(.entry-content, .is-root-container) .gallery {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
	gap: var(--acw-space-3);
	margin: 1.6em 0;
}

:is(.entry-content, .is-root-container) .gallery-item {
	min-width: 0;
	margin: 0;
}

/* A full-size image in a gallery cell stays in its cell (.is-wide would size it to the column). */
.entry-content .gallery img.is-wide {
	max-width: 100%;
}

:is(.entry-content, .is-root-container) .gallery br {
	display: none;
}

/* ---------- Tables ---------- */

/* Edge shadows appear only when there is more table to scroll to (background-attachment: local). */
.entry-content .table-scroll {
	max-width: 100%;
	margin: 1.6em 0;
	overflow-x: auto;
	background:
		linear-gradient(to right, var(--acw-bg) 30%, transparent) left / 32px 100% no-repeat local,
		linear-gradient(to left, var(--acw-bg) 30%, transparent) right / 32px 100% no-repeat local,
		radial-gradient(farthest-side at 0 50%, var(--acw-shadow), transparent) left / 12px 100% no-repeat scroll,
		radial-gradient(farthest-side at 100% 50%, var(--acw-shadow), transparent) right / 12px 100% no-repeat scroll;
}

.entry-content .table-scroll:focus-visible {
	outline-offset: 4px;
}

:is(.entry-content, .is-root-container) table {
	width: auto;
	min-width: 50%;
	border-collapse: collapse;
	font-family: var(--acw-sans);
	font-size: var(--acw-fs-ui-sm);
	line-height: 1.45;
}

:is(.entry-content, .is-root-container) .table-scroll table {
	margin: 0;
}

:is(.entry-content, .is-root-container) :is(th, td) {
	padding: var(--acw-space-2) var(--acw-space-3);
	border-bottom: var(--acw-rule-hair);
	text-align: left;
	vertical-align: top;
}

:is(.entry-content, .is-root-container) th {
	font-weight: 600;
	border-bottom: 1px solid var(--acw-ink);
}

:is(.entry-content, .is-root-container) :is(th, td) p {
	margin: 0 0 0.4em;
}

/* ---------- Legacy inline styling ---------- */

/*
 * Pasted Word/web HTML carries its own fonts, sizes and colours. Neutralise those so every post
 * reads in the site's type, but leave bold, italic, alignment and links alone.
 */
:is(.entry-content, .is-root-container) :is([style*="font-family"], [style*="font-size"], [style*="line-height"]) {
	font-family: inherit !important;
	font-size: inherit !important;
	line-height: inherit !important;
}

:is(.entry-content, .is-root-container) table * {
	font-family: inherit !important;
}

/* The editor's "Stripes" table style: core paints #f0f0f0 rows, which night text can't sit on. */
:is(.entry-content, .is-root-container) .wp-block-table.is-style-stripes tbody tr:nth-child(odd) {
	background-color: var(--acw-surface);
}

:is(.entry-content, .is-root-container) .wp-block-table.is-style-stripes {
	border-bottom-color: var(--acw-hairline);
}

/* Night: cells shaded by hand (Word, old HTML) are light; use the theme's shade. The two
   selectors match the two night blocks in tokens.css. */
@media screen and (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) .entry-content :is(table, tr, th, td):is([style*="background" i], [bgcolor]) {
		background: var(--acw-surface) !important;
	}
}

@media screen {
	:root[data-theme="dark"] .entry-content :is(table, tr, th, td):is([style*="background" i], [bgcolor]) {
		background: var(--acw-surface) !important;
	}
}

/* Word tables paint every cell white, which would hide the scroll shadows. */
:is(.entry-content, .is-root-container) :is(table, tr, th, td):is([style*="#ffffff" i], [style*="#fff;" i], [style*="white" i]) {
	background: transparent !important;
}

:is(.entry-content, .is-root-container) :is(p, span, div, li, font, td, th)[style*="color"] {
	color: inherit !important;
}

:is(.entry-content, .is-root-container) :is(p, span, li, font)[style*="background"] {
	background: none !important;
}

:is(.entry-content, .is-root-container) font {
	font-family: inherit;
	font-size: inherit;
	color: inherit;
}

/* ---------- Embeds ---------- */

:is(.entry-content, .is-root-container) iframe {
	max-width: 100%;
	border: 0;
}

:is(.entry-content, .is-root-container) .video-iframe,
:is(.entry-content, .is-root-container) .video-embed iframe {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: 16 / 9;
	border-radius: var(--acw-radius-sm);
}

:is(.entry-content, .is-root-container) .video-embed {
	display: block;
	margin: 1.6em 0;
}

:is(.entry-content, .is-root-container) .wp-block-embed {
	margin: 1.6em 0;
}

:is(.entry-content, .is-root-container) .wp-block-embed.wp-has-aspect-ratio iframe {
	border-radius: var(--acw-radius-sm);
}

/* Dead embeds (Flash) collapse to one quiet line. */
:is(.entry-content, .is-root-container) .embed-gone {
	display: block;
	margin: 1.2em 0;
	padding: var(--acw-space-3) var(--acw-space-4);
	background: var(--acw-surface);
	border-radius: var(--acw-radius-md);
	font-family: var(--acw-sans);
	font-size: var(--acw-fs-caption);
	color: var(--acw-muted);
}

.entry-content .page-links {
	margin-top: 2em;
	font-family: var(--acw-sans);
	font-size: var(--acw-fs-ui-sm);
}

/* ---------- Sidenotes (copies made by article.js; wide screens only) ---------- */

.entry-content .sidenote {
	display: none;
}

@media (min-width: 1100px) {
	.entry-content.has-sidenotes .sidenote {
		display: block;
		float: right;
		clear: right;
		width: 240px;
		margin: 0.35em -288px 1em 0;
		padding-top: var(--acw-space-2);
		border-top: var(--acw-rule-hair);
		font-family: var(--acw-sans);
		font-size: var(--acw-fs-caption);
		font-style: normal;
		font-weight: 400;
		line-height: 1.5;
		text-align: left;
		color: var(--acw-muted);
		overflow-wrap: anywhere;
	}

	.entry-content .sidenote a {
		color: inherit;
	}
}

.sidenote__num {
	font-family: var(--acw-mono);
	font-weight: 500;
	color: var(--acw-accent);
}

/* ---------- Image zoom ---------- */

.entry-content .zoomable {
	position: relative;
	display: block;
	width: fit-content;
	max-width: 100%;
}

.entry-content .zoomable--center {
	margin-inline: auto;
}

.entry-content .zoomable:has(img.is-wide) {
	max-width: min(var(--acw-wide), 100cqi);
}

.zoom-button {
	position: absolute;
	right: 12px;
	bottom: 12px;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 36px;
	padding: 0 14px;
	border: 0;
	border-radius: var(--acw-radius-pill);
	background: var(--acw-bg);
	background: color-mix(in srgb, var(--acw-bg) 92%, transparent);
	color: var(--acw-ink);
	font: 500 13px / 1 var(--acw-sans);
	box-shadow: 0 1px 4px var(--acw-shadow);
	cursor: zoom-in;
}

.zoom-button:hover {
	background: var(--acw-bg);
}

.zoom {
	width: 100vw;
	max-width: none;
	height: 100vh;
	height: 100dvh;
	max-height: none;
	margin: 0;
	padding: 0;
	border: 0;
	overflow: auto;
	background: #0d0e11;
	color: #fff;
}

.zoom::backdrop {
	background: rgb(13 14 17 / 0.9);
}

.zoom__bar {
	position: sticky;
	top: 0;
	z-index: 1;
	display: flex;
	justify-content: flex-end;
	gap: var(--acw-space-2);
	padding: var(--acw-space-2) var(--acw-space-3);
	background: rgb(13 14 17 / 0.85);
}

.zoom__orig,
.zoom__close {
	display: inline-flex;
	align-items: center;
	min-height: var(--acw-tap);
	padding: 0 var(--acw-space-4);
	border: 1px solid #3b3f48;
	border-radius: var(--acw-radius-pill);
	background: none;
	color: #fff;
	font: 500 var(--acw-fs-caption) / 1 var(--acw-sans);
	text-decoration: none;
	cursor: pointer;
}

.zoom__close {
	background: #fff;
	color: #16181d; /* the zoom dialog is dark in both themes */
}

.zoom__scroll {
	display: grid;
	place-items: center;
	min-height: calc(100% - 60px);
	overflow: auto;
}

.zoom__scroll img {
	max-width: 100%;
	max-height: calc(100dvh - 60px);
	object-fit: contain;
	cursor: zoom-in;
}

.zoom__scroll img.is-actual {
	max-width: none;
	max-height: none;
	cursor: zoom-out;
}
