/*
 * Author note: a tutorial's own credit, in its author's words.
 *
 * Two sources share these rules: the Group style "Author note" (pattern
 * pst/author-note) and the older Custom HTML credits, `<div class="authorcomment">`,
 * which stay as they were saved. inc/authors.php marks a credit heading
 * directly before an old credit with .pst-author-note__heading, so the
 * heading and the credit show as one panel.
 */
.authorcomment,
.is-style-author-note {
	display: flow-root;
	padding: 1.25rem 1.5rem;
	border-radius: var(--wp--preset--border-radius--xl);
	background: var(--wp--preset--color--surface);
	font-size: var(--wp--preset--font-size--medium);
	line-height: 1.65;
	overflow-wrap: anywhere;
}

.pst-author-note__heading:has(+ .authorcomment) {
	margin-block-end: 0;
	padding: 1.25rem 1.5rem 0.75rem;
	border-start-start-radius: var(--wp--preset--border-radius--xl);
	border-start-end-radius: var(--wp--preset--border-radius--xl);
	background: var(--wp--preset--color--surface);
	font-size: var(--wp--preset--font-size--x-large);
}

.pst-author-note__heading + .authorcomment {
	margin-block-start: 0;
	padding-block-start: 0;
	border-start-start-radius: 0;
	border-start-end-radius: 0;
}

.authorcomment > :is(h2, h3, h4),
.is-style-author-note > .wp-block-heading {
	margin: 0 0 0.75rem;
	font-size: var(--wp--preset--font-size--x-large);
}

/* Old credits saved the photo at 103 to 250 px, inline before the words. */
.authorcomment figure {
	margin: 0;
}

.authorcomment img {
	height: auto;
	border-radius: var(--wp--preset--border-radius--lg);
}

/*
 * inc/authors.php marks the portrait by its saved size. The photo hangs in a
 * left gutter, so the words, the sign-off and the "More tutorials" link start
 * on one text line, also when the text is longer than the photo. The float's
 * margin box has no width (-5rem + 4rem + 1rem), so no text wraps under it.
 */
.authorcomment:has(img.pst-author-note__photo) {
	padding-inline-start: calc(1.5rem + var(--pst-author-note-gutter, 5rem));
}

.authorcomment:has(img.pst-author-note__photo) > :is(h2, h3, h4) {
	margin-inline-start: calc(-1 * var(--pst-author-note-gutter, 5rem));
}

.authorcomment img.pst-author-note__photo {
	float: left;
	width: calc(var(--pst-author-note-gutter, 5rem) - 1rem);
	height: calc(var(--pst-author-note-gutter, 5rem) - 1rem);
	margin: 0.25rem 1rem 0.5rem calc(-1 * var(--pst-author-note-gutter, 5rem));
	border-radius: var(--wp--preset--border-radius--full);
	object-fit: cover;
}

.authorcomment p {
	margin: 0 0 0.5rem;
}

.authorcomment p:empty {
	display: none;
}

.authorcomment > :last-child,
.is-style-author-note > :last-child {
	margin-block-end: 0;
}

/* The profile Avatar, or the author's own photo as an Image block. */
.is-style-author-note :is(.wp-block-avatar, .wp-block-image) {
	flex: 0 0 auto;
	margin: 0;
}

/* .wp-block-group: beats `.pst-prose .wp-block-image img` in the tutorial body. */
.wp-block-group.is-style-author-note :is(.wp-block-avatar, .wp-block-image) img {
	width: 4rem;
	height: 4rem;
	border-radius: var(--wp--preset--border-radius--full);
	object-fit: cover;
}

.pst-author-note__body {
	min-width: 0;
}

.pst-author-note__body > * {
	margin: 0;
}

/*
 * Added at render from the post author, never saved in the post. It is the
 * last line of the text column: no divider, no clear past the photo.
 */
.pst-author-note__more {
	margin: 0.5rem 0 0;
	font-weight: 600;
}

.authorcomment > .pst-author-note__more,
.is-style-author-note .pst-author-note__more {
	margin-block-start: 0.5rem;
}

.pst-author-note__more a {
	text-decoration: none;
}

.pst-author-note__more a:hover,
.pst-author-note__more a:focus-visible {
	text-decoration: underline;
}

/* The panel already separates the credit; old posts add one or two lines. */
.wp-block-separator:has(+ .authorcomment),
.wp-block-separator:has(+ .wp-block-separator + .authorcomment),
.wp-block-separator:has(+ .pst-author-note__heading + .authorcomment),
.wp-block-separator:has(+ .wp-block-separator + .pst-author-note__heading + .authorcomment),
.wp-block-separator:has(+ .is-style-author-note),
.authorcomment + .wp-block-separator,
.is-style-author-note + .wp-block-separator {
	display: none;
}

/* Phones: a 3 rem photo and less padding keep the text column near 250 px. */
@media (max-width: 600px) {
	.authorcomment,
	.is-style-author-note {
		--pst-author-note-gutter: 4rem;
		padding-inline: 1rem;
	}

	.pst-author-note__heading:has(+ .authorcomment) {
		padding-inline: 1rem;
	}

	.authorcomment:has(img.pst-author-note__photo) {
		padding-inline-start: calc(1rem + var(--pst-author-note-gutter));
	}

	.wp-block-group.is-style-author-note :is(.wp-block-avatar, .wp-block-image) img {
		width: 3rem;
		height: 3rem;
	}
}