.modal[role="dialog"].open {
	grid-template: minmax(0, 1fr) / minmax(0, 1fr);
	padding-block: clamp(76px, 6vw, 112px);
}

.modal[role="dialog"].modal-gallery {
	padding-inline: max(68px, 6vw);
}

.modal .modal-figure {
	display: flex;
	flex-direction: column;
	align-items: center;
	align-self: safe center;
	max-height: 100%;
	min-height: 0;
	margin: 0 0 15px;
}

.modal .modal-figure img {
	min-height: 0;
}

.modal-gallery .modal-figure img {
	touch-action: pan-y pinch-zoom;
}

.modal .modal-figure figcaption {
	flex: none;
	width: 100%;
	max-height: min(26svh, 6em);
	overflow-y: auto;
	overflow-wrap: anywhere;
}

.modal .modal-figure figcaption:empty {
	display: none;
}

.modal .modal-figure figcaption:focus-visible,
.modal :is(.modal-close, .modal-nav):focus-visible {
	outline: 2px solid white;
	outline-offset: 3px;
}

.modal-nav {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	border: 1px solid #d9c3b7;
	border-radius: 50%;
	background: #291a16;
	color: white;
	cursor: pointer;
}

.modal-nav::before {
	content: "";
	width: 9px;
	height: 9px;
	border: solid currentColor;
	border-width: 0 2px 2px 0;
}

.modal-prev {
	inset-inline-start: 12px;
}

.modal-prev::before {
	transform: translateX(2px) rotate(135deg);
}

.modal-next {
	inset-inline-end: 12px;
}

.modal-next::before {
	transform: translateX(-2px) rotate(-45deg);
}

.modal-nav:hover {
	background: #49332d;
}

.modal-nav[hidden],
.modal-counter[hidden] {
	display: none;
}

.modal-counter {
	position: absolute;
	inset-inline: 64px;
	bottom: 18px;
	margin: 0;
	color: white;
	font: 400 14px/24px var(--sans);
	text-align: center;
	font-variant-numeric: tabular-nums;
}

.modal-image-error {
	margin: 0;
	color: white;
	font-family: var(--sans);
	text-align: center;
}

.modal-image-failed .modal-figure img {
	display: none;
}

.modal-image-loading .modal-figure img {
	visibility: hidden;
}

@media (max-width: 780px), (max-height: 480px) {
	.modal[role="dialog"].open {
		padding: 76px 6vw 16px;
	}

	.modal[role="dialog"].open.modal-gallery {
		padding-bottom: 64px;
	}

	.modal .modal-figure {
		max-height: calc(100% - 15px);
	}

	.modal .modal-figure figcaption {
		font-size: clamp(20px, 4.5vw, 31px);
	}

	.modal-nav {
		top: auto;
		bottom: 12px;
		transform: none;
	}

	.modal-counter {
		bottom: 22px;
	}
}

@media (max-height: 480px) {
	.modal .modal-close {
		top: 8px;
		right: 12px;
	}

	.modal[role="dialog"].open {
		padding-top: 66px;
	}
}
