:root {
	--bg-gradient: linear-gradient(#eefeff, #fff);
	--bg-fallback: #fff;
	--main: #202020;
	--muted: #666;
	--border: #ddd;
	--code-bg: #dadce0;
	--input-bg: #f7f7f7;
	--input-border: #ccc;
	--input-focus: #7c9fff;
	--metadata-bg: #ebecee;
	--surface: #fafafa;
	--surface-hover: #efefef;
	--button: #183352;
	--button-bg: #dfeaf8;
	--button-bg-hover: #d1def0;
	--button-top-shadow: rgba(255, 255, 255, 0.45);
	--button-bottom-shadow: rgba(55, 82, 122, 0.12);
	--accent: #2f80fa;
	--accent-hover: #1b74fa;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg-gradient: linear-gradient(#16181d, #101010);
		--bg-fallback: #101010;
		--main: #e7e7e7;
		--muted: #999;
		--border: #2a2a2a;
		--code-bg: #222428;
		--input-bg: #222325;
		--input-border: #444;
		--input-focus: #284186;
		--metadata-bg: #18181a;
		--surface: #18181a;
		--surface-hover: #222428;
		--button: #ececec;
		--button-bg: #242424;
		--button-top-shadow: rgba(255, 255, 255, 0.1);
		--button-bottom-shadow: rgba(0, 0, 0, 0.1);
		--button-bg-hover: #303030;
	}
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

body {
	font-family: sans-serif, system-ui;
	font-size: 1rem;
	line-height: 1.6;
	color: var(--main);
	background: var(--bg-fallback) var(--bg-gradient) no-repeat;
	margin: 0;
	padding: 0;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
}

header {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 2.5rem 1rem 1.5rem;
	gap: 1rem;
}

header .logo {
	display: block;
}

header form {
	display: flex;
	width: 100%;
	max-width: 600px;
}

header form .search-container {
	position: relative;
	display: flex;
	width: 100%;
}

header form input[type="search"] {
	flex: 1;
	padding: 0.6rem 3.5rem 0.6rem 1.25rem;
	font-size: 0.95rem;
	color: var(--main);
	background: var(--input-bg);
	border: 1px solid var(--input-border);
	border-radius: 50px;
	outline: none;
	transition: border-color 0.15s;
}

header form input[type="search"]::placeholder {
	color: var(--muted);
}

header form input[type="search"]:focus {
	border-color: var(--input-focus);
}

header form button {
	position: absolute;
	right: 4px;
	top: 50%;
	transform: translateY(-50%);
	width: 34px;
	height: 34px;
	padding: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #fff;
	background: var(--accent);
	box-shadow: inset 0 0.1rem 0 rgba(255, 255, 255, 0.3), inset 0 -0.1rem 0 rgba(122, 122, 122, 0.1);
	border: none;
	border-radius: 50%;
	cursor: pointer;
	transition: all 0.15s;
}

header form button:hover {
	background: var(--accent-hover);
}

header form button svg {
	display: block;
}

main {
	flex: 1;
	width: 100%;
	max-width: 960px;
	margin: 0 auto;
	padding: 0 1.25rem 2rem;
}

.index-hero {
	text-align: center;
	margin: 0 0 1rem;
}

.index-actions {
	text-align: center;
	margin: 0 0 2rem;
}

code {
	font-size: 0.9em;
	background: var(--code-bg);
	padding: 0.15em 0.4em;
	border-radius: 4px;
}

pre {
	background: var(--code-bg);
	padding: 0.75rem 1rem;
	border-radius: 6px;
	overflow-x: auto;
	margin: 0.5rem 0;
}

pre code {
	background: none;
	padding: 0;
}

.search-results {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
	gap: 0.75rem;
}

@supports (display: grid-lanes) {
	.search-results {
		display: grid-lanes;
	}
}

@supports (grid-template-rows: masonry) {
	.search-results {
		grid-template-rows: masonry;
		align-items: start;
	}
}

.tile {
	position: relative;
	/* A grid without masonry stretches items to the row; the hover overlay
	   must stay at the bottom of the image */
	align-self: start;
}

.tile > a {
	display: block;
	overflow: hidden;
	line-height: 0;
}

.search-results img {
	width: 100%;
	height: auto;
	border-radius: 8px;
	background: var(--border);
}

/*
 * Tags and a download menu over the bottom of a GIF. Only for devices that
 * can hover; on others a tap opens the GIF's page, which has both.
 */
.tile-hover {
	display: none;
}

@media (hover: hover) {
	.tile:hover,
	.tile:focus-within {
		z-index: 5;
	}

	.tile:has(.tile-menu[open]) {
		z-index: 5;
	}

	.tile-hover {
		position: absolute;
		inset: auto 0 0;
		display: flex;
		align-items: flex-end;
		justify-content: space-between;
		gap: 0.5rem;
		padding: 1.75rem 0.5rem 0.5rem;
		border-radius: 0 0 8px 8px;
		background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
		opacity: 0;
		pointer-events: none;
		transition: opacity 0.15s;
	}

	.tile:hover .tile-hover,
	.tile:focus-within .tile-hover {
		opacity: 1;
	}

	.tile:has(.tile-menu[open]) .tile-hover {
		opacity: 1;
	}
}

/* One line of tags; those that do not fit wrap out of sight */
.tile-tags {
	display: flex;
	flex-wrap: wrap;
	flex: 1;
	gap: 0.25rem;
	min-width: 0;
	max-height: 1.5rem;
	margin: 0;
	padding: 0;
	overflow: hidden;
	list-style: none;
	line-height: 1.5rem;
}

.tile-tags li {
	display: block;
	min-width: 0;
	max-width: 100%;
}

.tile-tags a {
	display: block;
	padding: 0 0.5rem;
	overflow: hidden;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.22);
	color: #fff;
	font-size: 0.75rem;
	line-height: 1.5rem;
	text-decoration: none;
	text-overflow: ellipsis;
	white-space: nowrap;
	pointer-events: auto;
}

.tile-tags a:hover,
.tile-tags a:focus-visible {
	background: var(--accent);
}

.tile-hover > .tile-download,
.tile-menu {
	flex: none;
	margin-left: auto;
	pointer-events: auto;
}

.tile-menu {
	position: relative;
}

.tile-download {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 1.75rem;
	height: 1.75rem;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.92);
	color: #1a1a1a;
	cursor: pointer;
	list-style: none;
	line-height: 1;
	user-select: none;
	transition: background-color 0.15s, transform 0.15s;
}

.tile-download::-webkit-details-marker {
	display: none;
}

.tile-download::before {
	--download-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 4v11m0 0l-4.5-4.5M12 15l4.5-4.5M5 20h14'/%3E%3C/svg%3E");
	content: "";
	width: 1rem;
	height: 1rem;
	background: currentColor;
	-webkit-mask: var(--download-icon) center / contain no-repeat;
	mask: var(--download-icon) center / contain no-repeat;
}

.tile-download:hover,
.tile-download:focus-visible {
	background: #fff;
}

.tile-download:active {
	transform: scale(0.92);
}

.tile-menu ul {
	position: absolute;
	z-index: 10;
	bottom: calc(100% + 0.35rem);
	right: 0;
	margin: 0;
	padding: 4px;
	list-style: none;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 12px;
	box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
	line-height: 1.4;
}

.tile-menu li a {
	display: block;
	padding: 4px 12px;
	border-radius: 8px;
	color: var(--main);
	font-size: 0.85rem;
	text-decoration: none;
	white-space: nowrap;
	transition: background-color 0.15s;
}

.tile-menu li a:hover,
.tile-menu li a:focus-visible {
	background: var(--surface-hover);
}

@media (prefers-reduced-motion: reduce) {
	.tile-hover,
	.tile-download,
	.tile-menu li a {
		transition: none;
	}
}

.trends ul {
	list-style: none;
	padding: 0;
	margin: 0 0 1.5rem;
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.trends a {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.25rem 0.9rem;
	background: var(--bg-fallback);
	border: 1px solid var(--border);
	border-radius: 999px;
	font-size: 0.9rem;
	color: var(--main);
	text-decoration: none;
	transition: all 0.2s ease;
}

.trends a:hover {
	background: var(--accent);
	color: #fff;
	border-color: var(--accent);
}

.trends img {
	width: 32px;
	height: 32px;
	margin-left: -0.65rem;
	border-radius: 50%;
	object-fit: cover;
	background: var(--border);
}

.view-page {
	display: flex;
	flex-wrap: wrap;
	gap: 2rem;
	align-items: flex-start;
	justify-content: center;
}

.view-media {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.75rem;
	max-width: 100%;
	flex-shrink: 0;
	align-self: flex-start;
}

.view-media img,
.view-media video {
	max-width: 100%;
	max-height: 80vh;
	border-radius: 10px;
}

.view-controls {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	align-items: center;
	gap: 0.5rem;
	max-width: 100%;
}

.tabs {
	display: inline-flex;
	gap: 2px;
	padding: 3px;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 999px;
	white-space: nowrap;
	max-width: 100%;
	overflow-x: auto;
	overflow-y: hidden;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: thin;
}

.tabs .tab {
	display: inline-block;
	padding: 5px 14px;
	border-radius: 999px;
	color: var(--muted);
	text-decoration: none;
}

.tabs .tab:hover {
	background: var(--surface-hover);
	color: var(--main);
}

.tabs .tab.selected {
	background: var(--button-bg);
	color: var(--main);
	box-shadow: inset 0 0.1rem 0 var(--button-top-shadow), inset 0 -0.1rem 0 var(--button-bottom-shadow);
}

.download-menu {
	position: relative;
}

.download-button {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	padding: 8px 16px;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: var(--button-bg);
	color: var(--button);
	text-decoration: none;
	cursor: pointer;
	list-style: none;
	user-select: none;
	box-shadow: inset 0 0.1rem 0 var(--button-top-shadow), inset 0 -0.1rem 0 var(--button-bottom-shadow);
	transition: background-color 0.2s, transform 0.2s;
}

.download-button::-webkit-details-marker {
	display: none;
}

.download-button:hover {
	background: var(--button-bg-hover);
}

.download-button:active {
	transform: scale(0.94);
}

.download-menu summary::after,
.related summary::after {
	content: "";
	width: 0.4em;
	height: 0.4em;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: translateY(-0.15em) rotate(45deg);
	transition: transform 0.2s;
}

.download-menu[open] summary::after,
.related[open] summary::after {
	transform: translateY(0.1em) rotate(-135deg);
}

.download-menu ul {
	position: absolute;
	z-index: 10;
	top: calc(100% + 0.35rem);
	right: 0;
	min-width: 100%;
	margin: 0;
	padding: 4px;
	list-style: none;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 12px;
	box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
	transform-origin: top right;
}

.download-menu li a {
	display: block;
	padding: 6px 14px;
	border-radius: 8px;
	color: var(--main);
	text-decoration: none;
	white-space: nowrap;
	transition: background-color 0.15s;
}

.download-menu li a:hover,
.download-menu li a:focus-visible {
	background: var(--surface-hover);
}

@media (prefers-reduced-motion: reduce) {
	.download-button,
	.download-menu summary::after,
	.related summary::after,
	.download-menu li a {
		transition: none;
	}
}

.related {
	margin-top: 2rem;
	border-top: 1px solid var(--border);
}

.related summary {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	padding: 1rem 0;
	font-size: 1.15rem;
	font-weight: bold;
	cursor: pointer;
	list-style: none;
	user-select: none;
}

.related summary::-webkit-details-marker {
	display: none;
}

.related summary:hover {
	color: var(--accent);
}

.error-page {
	text-align: center;
	max-width: 620px;
	margin: 0 auto;
	padding: 4rem 0;
}

.error-page h1 {
	font-size: 4rem;
	margin: 0 0 0.5rem;
}

.error-page h2 {
	font-size: 1.6rem;
	margin: 0 0 0.75rem;
}

.error-page p {
	color: var(--muted);
	font-size: 1.1rem;
	margin: 0.5rem 0;
}

.error-actions {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0.75rem;
	margin: 1.75rem 0 0;
}

footer {
	text-align: center;
	padding: 1.5rem 1rem;
	font-size: 0.85rem;
	color: var(--muted);
}

footer a {
	color: var(--muted);
	text-decoration: none;
}

footer a:hover {
	color: var(--main);
	text-decoration: underline;
}

footer p {
	margin: 0.25rem 0;
}

a {
	color: var(--main);
}

@media (max-width: 600px) {
	header {
		padding: 1.5rem 1rem 1rem;
	}

	header form {
		max-width: 100%;
	}

	.search-results {
		grid-template-columns: repeat(2, 1fr);
		gap: 0.5rem;
	}

	.view-page h1 {
		font-size: 1.25rem;
	}

	main {
		padding: 0 0.75rem 1.5rem;
	}

	.profile-info {
		padding: 1rem;
	}

	.profile-avatar,
	.profile-avatar-placeholder {
		width: 56px;
		height: 56px;
		font-size: 1.4rem;
	}

	.profile-details h1 {
		font-size: 1.15rem;
	}
}

.metadata {
	margin: 0;
	padding: 1.5rem;
	background: var(--metadata-bg);
	border: 1px solid var(--border);
	border-radius: 12px;
	text-align: left;
	flex: 1;
	min-width: min(100%, 280px);
	max-width: 600px;
}

.metadata h1 {
	font-size: 1.5rem;
	margin: 0 0 1.5rem;
	line-height: 1.2;
	text-align: left;
}

.author-section {
	display: flex;
	align-items: center;
	gap: 1rem;
	margin-bottom: 1.5rem;
}

.author-section .avatar {
	width: 48px;
	height: 48px;
	border-radius: 50%;
	background: var(--border);
	object-fit: cover;
}

.author-section .avatar-placeholder {
	background: linear-gradient(135deg, #2f80fa, #7c9fff);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.2rem;
	font-weight: 700;
	flex-shrink: 0;
	text-transform: uppercase;
}

.author-section .author-info {
	display: flex;
	flex-direction: column;
	gap: 0.2rem;
}

.author-section .author-name {
	margin: 0;
	font-weight: 600;
	color: var(--main);
}

.author-section .upload-date {
	margin: 0;
	font-size: 0.85rem;
	color: var(--muted);
}

.gif-description {
	border-top: 1px solid var(--border);
	padding-top: 1.25rem;
	margin-bottom: 1.25rem;
}

.gif-description p {
	margin: 0.3rem 0 0;
	color: var(--main);
	font-size: 0.95rem;
	line-height: 1.55;
}

.gif-details-grid {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 0.75rem 1rem;
	margin-bottom: 1.5rem;
}

.detail-item {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
}

.gif-description .label,
.detail-item .label {
	font-size: 0.75rem;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--muted);
	font-weight: 600;
}

.detail-item .value {
	font-size: 0.95rem;
	color: var(--main);
}

@media (max-width: 600px) {
	.gif-details-grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

.metadata .tags {
	margin-top: 1.5rem;
	border-top: 1px solid var(--border);
	padding-top: 1rem;
}

.metadata .tags strong {
	display: block;
	margin-bottom: 0.5rem;
	font-size: 0.9rem;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--muted);
}

.metadata .tags ul {
	list-style: none;
	padding: 0;
	margin: 0;
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.metadata .tags li a {
	display: inline-block;
	background: var(--bg-fallback);
	border: 1px solid var(--border);
	padding: 0.35rem 0.8rem;
	border-radius: 20px;
	font-size: 0.85rem;
	color: var(--main);
	transition: all 0.2s ease;
	text-decoration: none;
	box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.metadata .tags li a:hover {
	background: var(--accent);
	color: #fff;
	border-color: var(--accent);
	box-shadow: 0 3px 5px rgba(0,0,0,0.1);
}

.pagination {
	display: flex;
	justify-content: center;
	padding: 2rem 0 1rem;
	gap: 1rem;
}

.button {
	color: var(--button);
	background-color: var(--button-bg);
	border-radius: 24px;
	padding: 10px 24px;
	text-align: center;
	text-decoration: none;
	display: inline-block;
	border: none;
	cursor: pointer;
	transition: 0.2s;
	font: 500 18px sans-serif, system-ui;
	box-shadow: inset 0 0.1rem 0 var(--button-top-shadow), inset 0 -0.1rem 0 var(--button-bottom-shadow);
}

.button.primary {
	color: #ffffff;
	background-color: var(--accent);
}

.button.secondary {
	color: var(--button);
	background-color: var(--button-bg);
}

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

.button.primary:hover {
	background-color: var(--accent-hover);
}

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

.button:active {
	transform: scale(0.94);
}

.profile-page h2 {
	font-size: 1.15rem;
	margin: 1.5rem 0 0.75rem;
}

.profile-section-header {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 1rem;
	margin: 1.5rem 0 0.75rem;
}

.profile-page .profile-section-header h2 {
	margin: 0;
}

.profile-section-header a {
	color: var(--accent);
	text-decoration: none;
	font-size: 0.95rem;
}

.profile-section-header a:hover {
	text-decoration: underline;
}

/* A single row that scrolls sideways, like the carousels on Tenor */
.profile-row {
	display: grid;
	grid-auto-flow: column;
	grid-auto-columns: 160px;
	gap: 0.75rem;
	overflow-x: auto;
	scroll-snap-type: x proximity;
	padding-bottom: 0.5rem;
}

.profile-row .tile {
	aspect-ratio: 1;
	scroll-snap-align: start;
	border-radius: 8px;
	background: var(--border);
}

.profile-row .tile > a {
	height: 100%;
	border-radius: 8px;
}

.profile-row img {
	width: 100%;
	height: 100%;
	object-fit: contain;
}

.profile-header {
	background: var(--metadata-bg);
	border: 1px solid var(--border);
	border-radius: 12px;
	overflow: hidden;
}

.profile-banner img {
	width: 100%;
	aspect-ratio: 1110 / 400;
	object-fit: cover;
	display: block;
}

.profile-info {
	display: flex;
	align-items: center;
	gap: 1rem;
	padding: 1.25rem 1.5rem;
}

.profile-avatar {
	width: 72px;
	height: 72px;
	border-radius: 50%;
	object-fit: cover;
	background: var(--border);
	flex-shrink: 0;
}

.profile-avatar-placeholder {
	width: 72px;
	height: 72px;
	border-radius: 50%;
	background: linear-gradient(135deg, #2f80fa, #7c9fff);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.75rem;
	font-weight: 700;
	flex-shrink: 0;
	text-transform: uppercase;
}

.profile-details h1 {
	font-size: 1.4rem;
	margin: 0;
	line-height: 1.3;
}

.badge {
	font-size: 0.7rem;
	background: var(--accent);
	color: #fff;
	padding: 0.15em 0.5em;
	border-radius: 4px;
	vertical-align: middle;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

.profile-tagline {
	margin: 0.25rem 0 0;
	color: var(--muted);
	font-size: 0.95rem;
}

.profile-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.75rem;
	justify-content: space-between;
	padding: 0 1.5rem 1.25rem;
}

.profile-social-links {
	display: flex;
	flex: 1 1 auto;
	flex-wrap: wrap;
	gap: 0.5rem;
	min-width: 0;
}

.profile-social-links a {
	display: inline-block;
	background: var(--bg-fallback);
	border: 1px solid var(--border);
	padding: 0.3rem 0.7rem;
	border-radius: 20px;
	font-size: 0.8rem;
	color: var(--main);
	text-decoration: none;
	transition: all 0.2s ease;
}

.profile-social-links a:hover {
	background: var(--accent);
	color: #fff;
	border-color: var(--accent);
}

.profile-cta {
	flex: 0 0 auto;
	margin-left: auto;
}

@media (max-width: 600px) {
	.profile-actions {
		justify-content: center;
		padding: 0 1rem 1.25rem;
	}

	.profile-social-links {
		flex-basis: 100%;
		justify-content: center;
	}

	.profile-cta {
		flex-basis: 100%;
		margin-left: 0;
		text-align: center;
	}
}

.profile-empty {
	text-align: center;
	padding: 3rem 1rem;
	color: var(--muted);
	font-size: 1.05rem;
}
