:root {
	--bg: #fff;
	--text: #2e2f30;
	--outline: #fff;
	--button-radius: 16px;
	--button-size: 32px;
	--icon-size: 16px;
	--icon-offset: 8px;
	--blur: 20px;
	--button-bg: rgba(255, 255, 255, .45);
	--button-bg-hover: rgba(255, 255, 255, .65);
	--button-bg-active: rgba(255, 255, 255, .5);
	--overlay-hover: rgba(0, 0, 0, .25);
	--overlay-active: rgba(0, 0, 0, .5);
	--nav-width: 80px;
	--link-offset: 24px;
	--font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
	--ease-bounce: cubic-bezier(.22, 1.07, .36, 1);
	--transition-duration: .3s;
	--grid-radius: 0;
	--text-size: 10pt;

	--icon-close: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpath fill='%23fff' d='M3.293 3.293a1 1 0 0 1 1.414 0L8 6.586l3.293-3.293a1 1 0 1 1 1.414 1.414L9.414 8l3.293 3.293a1 1 0 0 1-1.414 1.414L8 9.414l-3.293 3.293a1 1 0 0 1-1.414-1.414L6.586 8 3.293 4.707a1 1 0 0 1 0-1.414Z'/%3E%3C/svg%3E");
	--icon-info: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23fff'%3E%3Ccircle cx='8' cy='8' r='7' fill='none' stroke='currentColor' stroke-width='1.5'/%3E%3Cpath d='M8 11V8M8 5v.5' stroke='currentColor' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
	--icon-pin: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none'%3E%3Cpath d='M3 1.5h10l-1.5 8.5h-7z' stroke='%23fff' stroke-width='2.5' stroke-linejoin='round'/%3E%3Cline x1='8' y1='10.5' x2='8' y2='14.5' stroke='%23fff' stroke-width='2.5' stroke-linecap='round'/%3E%3C/svg%3E");
	--icon-pin-filled: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpath d='M3 1.5h10l-1.5 8.5h-7z' fill='%23000' stroke-linejoin='round'/%3E%3Cline x1='8' y1='10.5' x2='8' y2='14.5' stroke='%23000' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    --icon-download: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Cpath fill='%23fff' d='M8 12l4-4h-2.5V3h-3v5H4l4 4zm-6 2h12v2H2v-2z'/%3E%3C/svg%3E");

	@media (prefers-color-scheme: dark) {
		--bg: #000;
		--text: #eee;
		--outline: #000;
	}
}

* {
	padding: 0;
	margin: 0;
	list-style: none;
	font-size: 1em;
	box-sizing: border-box;
}

html, body {
	min-height: 100%;
	display: flex;
}

body {
	flex-grow: 1;
	font: 16px/24px var(--font-stack);
	background: var(--bg);
	color: var(--text);
}

/* PHOTO GRID — CSS columns masonry */

.grid {
	columns: 200px;
	column-gap: 2px;
	width: 100vw;

	& .item {
		break-inside: avoid;
		margin-bottom: 2px;
		position: relative;
		line-height: 0;

		& img {
			width: 100%;
			height: auto;
			display: block;
			border-radius: var(--grid-radius);
		}

		& .open {
			position: absolute;
			inset: 0;
			border-radius: var(--grid-radius);
			text-indent: 150%;
			overflow: hidden;
			white-space: nowrap;
		}

		& .open {
			cursor: pointer;
			background-color: transparent;
			transition: background-color calc(var(--transition-duration) / 2) var(--ease-bounce);

			&:hover, &:focus {
				background-color: var(--overlay-hover);
			}

			&:active {
				background-color: var(--overlay-active);
			}
		}

		& .previous  { display: none; }
		& .next      { display: none; }
		& .actions   { display: none; }
		& .caption   { display: none; }

		/* PHOTO DETAIL — fullscreen overlay */

		&.target {
			position: fixed;
			inset: 0;
			width: 100vw;
			height: 100vh;
			height: 100dvh;
			z-index: 10;
			background: var(--bg);
			display: flex;
			align-items: center;
			justify-content: center;
			line-height: normal;

			& figure {
				width: 100%;
				height: 100%;
			}

			& img {
				width: 100%;
				height: 100%;
				object-fit: contain;
			}

			& .open  { display: none; }

			& .previous,
			& .next {
				display: flex;
				position: absolute;
				top: 0;
				bottom: 0;
				z-index: 20;
				width: 25vw;
				align-items: center;
				transition: background-color var(--transition-duration) var(--ease-bounce), opacity calc(var(--transition-duration) * 2) var(--ease-bounce);

				& .button {
					background-image: url(../img/icon-left.svg);
					pointer-events: none;
					transition: background-color var(--transition-duration) var(--ease-bounce), transform var(--transition-duration) var(--ease-bounce);
				}

				&:hover {
					background-color: rgba(0, 0, 0, .05);

					& .button {
						background-color: var(--button-bg-hover);
						transform: scale(1.1);
					}
				}
				&:active .button { background-color: var(--button-bg-active); }
			}

			& .previous {
				left: 0;
				cursor: pointer;
				justify-content: flex-start;
				padding-left: 24px;
			}

			& .next {
				right: 0;
				left: auto;
				cursor: pointer;
				justify-content: flex-end;
				padding-right: 24px;

				& .button {
					background-image: url(../img/icon-right.svg);
				}
			}

			& .previous.faded,
			& .next.faded {
				opacity: 0;
				pointer-events: none;
			}

			& .actions {
				display: flex;
				position: fixed;
				top: var(--link-offset);
				right: var(--link-offset);
				z-index: 21;
				gap: 8px;
				transition: opacity calc(var(--transition-duration) * 2) var(--ease-bounce);

				&.faded {
					opacity: 0;
					pointer-events: none;
				}

				& .button {
					transition: background-color calc(var(--transition-duration) / 3) var(--ease-bounce);
					cursor: pointer;
				}

				& .share { background-image: url(../img/icon-share.svg); }
			}

			/* CAPTION — lightbox metadata */
			& .caption {
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				gap: 4px;
				position: fixed;
				left: var(--link-offset);
				bottom: var(--link-offset);
				right: auto;
				top: auto;
				color: #fff;
				z-index: 21;
				transition: opacity calc(var(--transition-duration) * 2) var(--ease-bounce);
				pointer-events: none;
				margin: 6rem;

				&.faded {
					opacity: 0;
					pointer-events: none;
					& > * { animation: none; }
				}
			}

			& .caption-title,
			& .caption-desc,
			& .caption-exif,
			& .caption-tags {
				display: inline;
				background: rgba(0, 0, 0, .6);
				box-decoration-break: clone;
				-webkit-box-decoration-break: clone;
				padding: 4px 8px;
				animation: caption-in var(--transition-duration) var(--ease-bounce) both;
			}
			& .caption-title { font-size: calc(var(--text-size) * 2); font-weight: 900; line-height: 1.8; animation-delay: var(--transition-duration); }
			& .caption-desc { font-size: calc(var(--text-size) * 1.5); font-weight: 400; line-height: 1.8; animation-delay: calc(var(--transition-duration) * 4 / 3); }
			& .caption-exif { font-size: calc(var(--text-size) * 1); line-height: 1.8; opacity: .7; animation-delay: calc(var(--transition-duration) * 5 / 3); }
			& .caption-tags { font-size: calc(var(--text-size) * 1); line-height: 1.8; opacity: .5; animation-delay: calc(var(--transition-duration) * 2); }

			& .caption-pin {
				all: unset;
				display: inline-block;
				width: .7em;
				height: .7em;
				padding: 2px;
				margin-left: .4em;
				vertical-align: middle;
				cursor: pointer;
				border-radius: 50%;
				background: no-repeat center / 65%;
				background-image: var(--icon-pin);
				pointer-events: auto;
				animation: caption-in var(--transition-duration) var(--ease-bounce) both;
				animation-delay: calc(var(--transition-duration) * 7 / 3);
				opacity: .5;
				transition: opacity var(--transition-duration) var(--ease-bounce),
					background-color var(--transition-duration) var(--ease-bounce);

				&:hover { opacity: .8; }
				&.pinned {
					opacity: 1;
					background-color: #fff;
					background-image: var(--icon-pin-filled);
				}
				}

			& .caption a {
				color: inherit;
				pointer-events: auto;
			}
			& .caption code {
				background: rgba(255, 255, 255, .15);
				padding: 1px 4px;
				border-radius: 3px;
			}
		}
	}

	/* RESPONSIVE — single column on narrow portrait screens */

	@media (max-aspect-ratio: 1/1) and (max-width: 640px) {
		columns: 1;

		& .item.target {
			& .caption {
				left: 0;
				right: 0;
				bottom: 0;
				margin: 2rem 2rem 6rem 2rem;
				max-width: none;
			}
		}
	}
}

/* BUTTON BASE — common styles for all button-like elements */

.button {
	display: block;
	border-radius: var(--button-radius);
	text-indent: 150%;
	overflow: hidden;
	white-space: nowrap;
	width: var(--button-size);
	height: var(--button-size);
	background: var(--button-bg) no-repeat var(--icon-offset) / var(--icon-size);
	backdrop-filter: blur(var(--blur));
	transition: background-color var(--transition-duration) var(--ease-bounce);

	&:hover { background-color: var(--button-bg-hover); }
	&:active { background-color: var(--button-bg-active); }

	&.large {
		--button-size-large: calc(2 * var(--button-size));
		--icon-size-large: calc(2 * var(--icon-size));
		--icon-offset-large: calc(2 * var(--icon-offset));

		width: var(--button-size-large);
		height: var(--button-size-large);
		background-size: var(--icon-size-large);
		background-position: var(--icon-offset-large);

		@media (max-aspect-ratio: 1/1) and (max-width: 640px) {
			width: var(--button-size);
			height: var(--button-size);
			background-size: var(--icon-size);
			background-position: var(--icon-offset);
		}
	}

	&.close {
		background-image: var(--icon-close);
		background-color: rgba(0, 0, 0, .6);
		outline: 2px solid rgba(255, 255, 255, .5);
		outline-offset: -2px;

		&:hover { background-color: rgba(0, 0, 0, .75); }
		&:active { background-color: rgba(0, 0, 0, .5); }
	}

	&.download {
		background-image: var(--icon-download);
		background-color: rgba(0, 0, 0, .6);
		outline: 2px solid rgba(255, 255, 255, .5);
		outline-offset: -2px;

		&:hover { background-color: rgba(0, 0, 0, .75); }
		&:active { background-color: rgba(0, 0, 0, .5); }
	}
}

/* SOCIAL LINKS */

.links {
	position: fixed;
	right: var(--link-offset);
	bottom: var(--link-offset);
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: 8px;
	z-index: 30;

	& .button {
		backdrop-filter: blur(var(--blur)) saturate(180%) contrast(120%);
		box-shadow: 0 0 0 0 var(--button-bg-hover);
		transition: background-color var(--transition-duration) var(--ease-bounce),
		            box-shadow var(--transition-duration) var(--ease-bounce);

		&:hover {
			background-color: var(--button-bg-hover);
			box-shadow: 0 0 0 6px var(--button-bg-hover);
		}
		&:active {
			background-color: var(--button-bg-active);
			box-shadow: 0 0 0 2px var(--button-bg-active);
			transition-duration: calc(var(--transition-duration) / 3);
		}
	}

	& .github a    { background-image: url(../img/icon-github.svg); }
	& .twitter a   { background-image: url(../img/icon-twitter.svg); }
	& .mastodon a  { background-image: url(../img/icon-mastodon.svg); }
	& .instagram a { background-image: url(../img/icon-instagram.svg); }
	& .pixelfed a  { background-image: url(../img/icon-pixelfed.svg); }
	& .rss {
		position: fixed;
		top: var(--link-offset);
		right: var(--link-offset);

		& a { background-image: url(../img/icon-rss.svg); }
	}

	& .link a {
		text-indent: 0;
		width: auto;
		font-size: 13px;
		line-height: var(--button-size);
		text-transform: uppercase;
		padding: 0 12px;
		color: rgba(0, 0, 0, .75);
		font-weight: 600;
		text-decoration: none;
	}

	& .avatar a {
		text-indent: 0;
		padding: 0;
		background: none;
		width: 48px;
		height: 48px;
		border-radius: 50%;

		& img {
			width: 100%;
			height: 100%;
			display: block;
			border-radius: 50%;
			border: 2px solid #fff;
			box-sizing: border-box;
		}
	}
}

body:has(.item.target) .links :is(.rss, .info) { display: none; }

/* APERTURE BADGE */

.aperture-badge {
	display: inline-block;
	font-size: calc(var(--text-size) * .9);
	font-weight: 600;
	padding: 2px 6px;
	background: rgba(255, 255, 255, .5);
	color: rgba(0, 0, 0, .85);
	border-radius: 4px;
	line-height: 1.3;
	margin: 0 2px;
}

/* INFO BUTTON & STATS MODAL */

.links {
	& .info {
		position: fixed;
		top: var(--link-offset);
		right: calc(var(--link-offset) + 48px);

		& a {
			background-image: var(--icon-info);
		}
	}
}

.stats-modal {
	position: fixed;
	inset: 0;
	z-index: 100;
	display: grid;
	place-items: center;

	@media (max-width: 640px) {
		align-items: stretch;
	}
}

.stats-overlay {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, .85);
	cursor: pointer;
}

.stats-content {
	position: relative;
	max-width: 800px;
	max-height: 90vh;
	width: calc(100% - 48px);
	background: rgba(255, 255, 255, .1);
	backdrop-filter: blur(20px);
	border-radius: 16px;
	border: 1px solid rgba(255, 255, 255, .2);
	color: #fff;
	overflow: hidden;
	display: flex;
	flex-direction: column;

	@media (max-width: 640px) {
		width: 100%;
		height: 100%;
		max-height: none;
		border-radius: 0;
		align-self: stretch;
	}
}

.stats-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 24px;
	border-bottom: 1px solid rgba(255, 255, 255, .1);

	& h2 {
		font-size: 24px;
		font-weight: 700;
		margin: 0;
	}

	@media (max-width: 640px) {
		padding: 16px;
	}
}

.stats-body {
	padding: 24px;
	overflow-y: auto;

	@media (max-width: 640px) {
		padding: 16px;
	}
}

.stats-hero {
	text-align: center;
	margin-bottom: 32px;

	& .stat-big {
		font-size: 48px;
		font-weight: 900;
		line-height: 1.2;

		@media (max-width: 640px) {
			font-size: 36px;
		}
	}

	& .stat-subtitle {
		font-size: 16px;
		opacity: .7;
		margin-top: 8px;
	}
}

.stats-section {
	margin-bottom: 32px;

	& h3 {
		font-size: 18px;
		font-weight: 700;
		margin: 0 0 16px 0;
		opacity: .9;
	}
}

.stats-footer {
	font-size: 13px;
	opacity: .5;
	text-align: center;
	margin: 0;
	padding-top: 8px;
	border-top: 1px solid rgba(255, 255, 255, .1);

	& a {
		color: inherit;
		text-decoration: underline;
		text-underline-offset: 2px;

		&:hover { opacity: 1; }
	}
}

.stats-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 24px;
	margin-bottom: 32px;

	@media (max-width: 640px) {
		grid-template-columns: 1fr;
		gap: 16px;
	}
}

.stat-text {
	font-size: 15px;
	opacity: .85;
	line-height: 1.6;
}

.stat-badges {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
}

.stat-badge {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 4px 6px;
	align-items: center;
	font-size: 14px;
	padding: 8px 12px;
	background: rgba(255, 255, 255, .15);
	border-radius: 8px;
	opacity: .85;

	& .stat-label {
		display: flex;
		align-items: center;
		gap: 6px;
	}

	&.top .stat-label {
		font-weight: 700;
	}

	& .stat-pct {
		text-align: right;
		opacity: .7;
	}

	& .stat-bar {
		grid-column: 1 / -1;
	}

	& svg {
		flex-shrink: 0;
		opacity: .7;
	}
}

.stats-table {
	width: 100%;
	border-collapse: collapse;

	& thead th {
		text-align: left;
		padding: 8px;
		border-bottom: 1px solid rgba(255, 255, 255, .2);
		font-size: 14px;
		font-weight: 600;
		opacity: .7;
	}

	& tbody td {
		padding: 8px;
		border-bottom: 1px solid rgba(255, 255, 255, .1);
		font-size: 14px;

		&:nth-child(1) {
			font-weight: 500;
		}

		&:nth-child(2) {
			text-align: right;
			opacity: .7;
			width: 60px;
		}

		&:nth-child(3) {
			width: 100px;
		}
	}
}

.stat-bar {
	height: 8px;
	background: rgba(255, 255, 255, .1);
	border-radius: 4px;
	overflow: hidden;
}

.stat-fill {
	height: 100%;
	background: rgba(255, 255, 255, .7);
	border-radius: 4px;
	transition: width var(--transition-duration) var(--ease-bounce);
}

.orientation-bars {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.orientation-row {
	display: grid;
	grid-template-columns: 100px 1fr 50px;
	gap: 12px;
	align-items: center;

	& span:first-child {
		font-size: 14px;
		font-weight: 500;
	}

	& span:last-child {
		text-align: right;
		font-size: 14px;
		opacity: .7;
	}

	@media (max-width: 640px) {
		grid-template-columns: 80px 1fr 40px;
		gap: 8px;
	}
}

/* 404 */

.four-oh-four {
	flex-grow: 1;
	display: flex;
	flex-direction: column;
	height: 100%;
	padding: 64px;
	align-items: center;
	justify-content: center;
	text-align: center;

	& h1 {
		font-size: 32px;
		line-height: 48px;
		font-weight: 700;
	}

	& p {
		margin-bottom: 32px;
	}

	& a {
		display: block;
		border-radius: var(--button-radius);
		backdrop-filter: blur(var(--blur));
		background-color: var(--button-bg);
		text-decoration: none;
		font-size: 13px;
		line-height: var(--button-size);
		text-transform: uppercase;
		padding: 0 12px;
		color: rgba(0, 0, 0, .75);
		font-weight: 600;

		&:hover { background-color: var(--button-bg-hover); }
	}
}

/* TOAST */

.toast {
	position: fixed;
	bottom: var(--link-offset);
	left: 50%;
	translate: -50% 0;
	z-index: 40;
	padding: 8px 16px;
	border-radius: var(--button-radius);
	background: var(--text);
	color: var(--bg);
	font: 13px/var(--button-size) var(--font-stack);
	white-space: nowrap;
	animation: toast calc(var(--transition-duration) * 7) var(--ease-bounce) forwards;
	pointer-events: none;
}

/* ANIMATIONS */

@keyframes caption-in {
	from { opacity: 0; translate: 0 -12px; }
	to   { opacity: 1; translate: 0 0; }
}

@keyframes fade-in {
	from { opacity: 0; }
	to   { opacity: 1; }
}

@keyframes slide-from-right {
	from { translate: 30% 0; opacity: 0; }
	to   { translate: 0 0; opacity: 1; }
}

@keyframes slide-from-left {
	from { translate: -30% 0; opacity: 0; }
	to   { translate: 0 0; opacity: 1; }
}

@keyframes toast {
	0%   { opacity: 0; translate: -50% 16px; }
	15%  { opacity: 1; translate: -50% 0; }
	85%  { opacity: 1; translate: -50% 0; }
	100% { opacity: 0; translate: -50% -8px; }
}

.slide-next figure { animation: slide-from-right var(--transition-duration) var(--ease-bounce); }
.slide-prev figure { animation: slide-from-left var(--transition-duration) var(--ease-bounce); }

