/*
 * Digitálka Instagram feed. Breakpoints and hover follow the Smash Balloon feed it replaces:
 * tablet up to 640 px, mobile up to 480 px. A theme can fix the tile height with
 * --dif-tile-height: the tile keeps its column width and the image is cropped to the centre,
 * as in Smash Balloon. Tiles are square otherwise.
 */

.dif-feed {
	--dif-gap: 0px;
	padding: 12px 0;
}

/* Doubled class selectors outrank theme list styles such as `.content ul li` when the
   shortcode sits in post content.
   A wrapping flex row rather than a grid: a tile is one column wide whatever the number of
   posts, and a row with fewer tiles (posts hidden, a short last row) stays centred. */
.dif-feed .dif-grid {
	--dif-columns: var(--dif-cols, 5);
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	margin: 0;
	padding: 0;
	list-style: none;
}

.dif-grid > .dif-item {
	position: static;
	box-sizing: border-box;
	flex: 0 0 calc(100% / var(--dif-columns));
	margin: 0;
	/* The gap is padding on the tiles (half of it also at the outer edges). A --dif-gap without
	   a unit (`0`, `4`) makes this declaration invalid, which only drops the gap — a gap inside
	   the width calc() would break the whole layout instead. */
	padding: calc(var(--dif-gap) / 2);
	min-width: 0;
}

.dif-grid > .dif-item::before,
.dif-grid > .dif-item::after {
	content: none;
}

.dif-tile {
	position: relative;
	display: block;
	overflow: hidden;
	/* Width comes from the column; aspect-ratio only applies while the height is auto. */
	width: 100%;
	aspect-ratio: 1;
	height: var(--dif-tile-height, auto);
	background: #f2f2f2;
	color: #fff;
}

.dif-tile .dif-img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: cover;
	object-position: center;
}

.dif-hover {
	position: absolute;
	inset: 0;
	background: rgba(255, 255, 255, 0.85);
	opacity: 0;
	transition: opacity 0.6s ease-in-out;
}

.dif-tile:hover .dif-hover,
.dif-tile:focus-visible .dif-hover {
	opacity: 1;
	transition-duration: 0.2s;
}

.dif-tile:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: -4px;
}

.dif-icon {
	position: absolute;
	color: #fff;
	opacity: 0.9;
	filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.4));
	pointer-events: none;
}

.dif-tile .dif-icon--play {
	top: 50%;
	left: 50%;
	width: 23px;
	height: 23px;
	transform: translate(-50%, -50%);
}

.dif-tile .dif-icon--carousel {
	top: 8px;
	right: 8px;
	width: 18px;
	height: 18px;
}

@media (max-width: 640px) {
	.dif-feed .dif-grid {
		--dif-columns: var(--dif-cols-tablet, 4);
	}
}

@media (max-width: 480px) {
	.dif-feed .dif-grid {
		--dif-columns: var(--dif-cols-mobile, 2);
	}

	.dif-grid > .dif-item--not-mobile {
		display: none;
	}
}

/* Lightbox */

.dif-lb-open {
	overflow: hidden;
}

.dif-lb {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px 64px;
	background: rgba(0, 0, 0, 0.9);
	color: #fff;
	font-size: 14px;
	line-height: 1.45;
}

.dif-lb[hidden] {
	display: none;
}

/* The lightbox hides its arrows and the avatar with the hidden attribute; a theme rule such
   as `button { display: inline-block }` would otherwise show them. */
.dif-lb [hidden] {
	display: none !important;
}

.dif-lb__box {
	position: relative;
	display: flex;
	flex-direction: column;
	width: fit-content;
	min-width: min(100%, 320px);
	max-width: min(100%, 900px);
	max-height: 100%;
	background: #000;
}

.dif-lb__media {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 0;
	background: #000;
}

.dif-lb__media img {
	display: block;
	max-width: 100%;
	max-height: calc(100vh - 230px);
	width: auto;
	height: auto;
}

.dif-lb__play {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #fff;
}

.dif-lb__play .dif-icon {
	position: static;
	width: 48px;
	height: 48px;
}

.dif-lb__dots {
	position: absolute;
	/* Keeps the dots' centre 14 px above the bottom edge, as with plain 8 px dots. */
	bottom: 2px;
	left: 0;
	right: 0;
	display: flex;
	justify-content: center;
}

/* The button is a 24 px hit target; the visible 8 px dot is drawn in its centre. The
   targets touch, so the dots sit 16 px apart. */
.dif-lb__dot {
	position: relative;
	width: 24px;
	height: 24px;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	cursor: pointer;
}

.dif-lb__dot::before {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 8px;
	height: 8px;
	margin: -4px 0 0 -4px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.5);
}

.dif-lb__dot[aria-current="true"]::before {
	background: #fff;
}

.dif-lb__meta {
	position: relative;
	/* Zero width + full min-width: the caption wraps to the image instead of widening the box. */
	width: 0;
	min-width: 100%;
	box-sizing: border-box;
	padding: 10px 12px 8px;
}

/* Only the caption scrolls, so the counter and the Instagram link stay in view. */
.dif-lb__caption {
	max-height: 104px;
	overflow: auto;
	overscroll-behavior: contain;
}

.dif-lb__user {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	margin-bottom: 6px;
	color: #fff;
	font-weight: 700;
	text-decoration: none;
}

.dif-lb__user:hover {
	color: #fff;
	text-decoration: underline;
}

.dif-lb__user img {
	width: 32px;
	height: 32px;
	border-radius: 50%;
}

.dif-lb__caption a,
.dif-lb__footer a {
	color: #fff;
	text-decoration: underline;
}

.dif-lb__footer {
	display: flex;
	justify-content: space-between;
	gap: 16px;
	margin-top: 8px;
	color: rgba(255, 255, 255, 0.7);
}

.dif-lb__close,
.dif-lb__nav {
	position: absolute;
	padding: 0;
	border: 0;
	background: none;
	color: #fff;
	cursor: pointer;
	opacity: 0.8;
}

.dif-lb__close:focus:not(:focus-visible),
.dif-lb__nav:focus:not(:focus-visible) {
	outline: none;
}

.dif-lb__close:hover,
.dif-lb__nav:hover,
.dif-lb__close:focus-visible,
.dif-lb__nav:focus-visible {
	opacity: 1;
}

.dif-lb__close {
	position: fixed;
	top: 12px;
	right: 16px;
	width: 36px;
	height: 36px;
	font-size: 36px;
	line-height: 1;
}

.dif-lb__nav {
	top: 50%;
	width: 48px;
	height: 72px;
	margin-top: -36px;
	font-size: 48px;
	line-height: 1;
}

.dif-lb__nav--prev {
	left: 8px;
}

.dif-lb__nav--next {
	right: 8px;
}

@media (max-width: 640px) {
	/* The arrows sit at the bottom of the screen; keep the box above them. */
	.dif-lb {
		padding: 12px 12px 64px;
	}

	.dif-lb__nav {
		top: auto;
		bottom: 8px;
		margin-top: 0;
		height: 48px;
		font-size: 36px;
	}
}
