/**
 * Image credit: a © badge in the bottom right corner of the image. Hover, focus or a tap on the
 * badge reveals "Foto: Name"; until then the text is only visually hidden (screen readers read it).
 * Escape hides it again (`is-dismissed`, WCAG 1.4.13, see ImageCredits::DISMISS).
 * Uses the caption type size.
 */

.cr-image-credit {
	position: absolute;
	z-index: 2;
	right: 6px;
	bottom: 6px;
	display: flex;
	align-items: center;
	max-width: calc(100% - 12px);
	min-height: 20px;
	border-radius: 10px;
	background-color: rgb(255 255 255 / 85%);
	color: var(--wp--preset--color--black);
	font-size: var(--wp--preset--font-size--body-2);
	font-weight: 400;
	line-height: 1.35;
	text-align: start;
	cursor: default;

	&:focus-visible {
		outline: 2px solid var(--wp--preset--color--signal);
		outline-offset: 1px;
	}

	& a {
		color: inherit;
		text-decoration: underline;
	}
}

.cr-image-credit__icon {
	flex: none;
	width: 14px;
	height: 14px;
	margin: 3px;
}

/* Visually hidden until revealed. */
.cr-image-credit__text {
	position: absolute;
	overflow: hidden;
	width: 1px;
	height: 1px;
	clip-path: inset(50%);
	white-space: nowrap;
}

.cr-image-credit:is(:hover, :focus-within):not(.is-dismissed) {
	padding-block: 2px;
	border-radius: 2px;

	& .cr-image-credit__text {
		position: static;
		overflow: visible;
		order: -1;
		width: auto;
		height: auto;
		padding-inline-start: 8px;
		clip-path: none;
		white-space: normal;
	}
}

/* Positioned on the image, not on the whole figure. */
:is(.wp-block-cover, .wp-block-media-text__media, .wp-block-post-featured-image, .wp-block-image) {
	position: relative;
}

/*
 * Image blocks: image and badge share the first grid cell, so the badge sits on the image (not
 * on the caption, not beside a narrower image). The column is as wide as the image. Gallery
 * images keep the gallery layout; there the image fills the figure.
 */
.wp-block-image:has(> .cr-image-credit):not(.wp-block-gallery .wp-block-image) {
	display: grid;
	grid-template-columns: fit-content(100%);

	&.aligncenter {
		justify-content: center;
	}

	& > :not(figcaption) {
		grid-area: 1 / 1 / 2 / 2;
	}
}
