/*
 * AutoPix front-end styles.
 *
 * Sizing model: every figure gets two inline custom properties
 *   --apx-w : the width we WANT (percentage of the content column)
 *   --apx-r : the displayed aspect ratio (width / height)
 * and the width actually used is  min(wanted, maxHeight * ratio).
 * That single rule keeps tall portrait photos from ever exceeding the max height,
 * while landscape photos use the full wanted width. Works in any theme column width.
 */

figure.apx-fig {
	--apx-w: 100%;
	--apx-r: 1.5;
	display: block;
	position: relative;
	box-sizing: border-box;
	max-width: 100%;
	width: min(var(--apx-w), calc(var(--apx-maxh, 520px) * var(--apx-r)));
	margin: 1.8em auto;
	padding: 0;
	clear: both;
}

figure.apx-fig img.apx-img {
	display: block;
	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
	height: auto;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: var(--apx-radius, 8px);
	box-shadow: var(--apx-shadow, none);
	object-fit: cover;
	background-color: #e8e8e8; /* overridden inline with the photo's dominant colour */
}

/* Wrapped text flow */
figure.apx-fig.apx-left {
	float: left;
	margin: 0.4em 1.7em 1em 0;
}

figure.apx-fig.apx-right {
	float: right;
	margin: 0.4em 0 1em 1.7em;
}

figure.apx-fig.apx-center {
	margin: 1.9em auto;
}

figure.apx-fig.apx-wide {
	margin: 2.1em auto;
}

/* Headings always start below a floated photo */
figure.apx-fig.apx-left ~ h2,
figure.apx-fig.apx-left ~ h3,
figure.apx-fig.apx-left ~ h4,
figure.apx-fig.apx-right ~ h2,
figure.apx-fig.apx-right ~ h3,
figure.apx-fig.apx-right ~ h4 {
	clear: both;
}

/* Credit */
figure.apx-fig figcaption.apx-cap {
	margin: 0.55em 0 0;
	padding: 0;
	font-size: 0.78em;
	line-height: 1.4;
	font-style: normal;
	font-weight: 400;
	color: inherit;
	text-align: left;
	opacity: 0.68;
}

figure.apx-fig figcaption.apx-cap a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
}

figure.apx-fig.apx-credit-overlay figcaption.apx-cap {
	position: absolute;
	left: 8px;
	bottom: 8px;
	margin: 0;
	padding: 3px 10px;
	max-width: calc(100% - 16px);
	border-radius: 999px;
	background: rgba(0, 0, 0, 0.58);
	color: #fff;
	font-size: 11px;
	line-height: 1.5;
	opacity: 1;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	-webkit-backdrop-filter: blur(4px);
	backdrop-filter: blur(4px);
}

figure.apx-fig.apx-credit-overlay figcaption.apx-cap a {
	color: #fff;
}

/* Small screens: no wrapping, one clean centered column (still capped in height) */
@media (max-width: 640px) {
	figure.apx-fig,
	figure.apx-fig.apx-left,
	figure.apx-fig.apx-right,
	figure.apx-fig.apx-center,
	figure.apx-fig.apx-wide {
		float: none;
		--apx-w: 100% !important;
		width: min(100%, calc(min(var(--apx-maxh, 520px), 72vh) * var(--apx-r)));
		margin: 1.5em auto;
	}
}

@media print {
	figure.apx-fig {
		break-inside: avoid;
	}
}
