$radius-pill: 999px;
$card-radius: var(--border1);
$gap: 10px;

.mp-hero {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 16px;
	margin-bottom: 10px;

	h2 {
		margin: 0 0 2px;
		font-weight: 800;
		font-size: 20px;
	}

	.muted {
		font-size: 12px;
	}

	.mp-hero-actions {
		display: flex;
		gap: 8px;
	}
}

.mp-toolbar {
	display: grid;
	gap: $gap;
	padding: 12px;
	border-radius: $card-radius;
	border: 1px solid var(--transp-2);
	background: var(--background-900a);

	&-row {
		display: grid;
		grid-template-columns: 1fr auto;
		gap: $gap;
	}

	.mp-search {
		input[type="search"] {
			width: 100%;
		}
	}
}

.mp-clear {
	display: flex;
	align-items: center;
}

.mp-summary {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 2px;
}

.chip {
	border-radius: $radius-pill;
	padding: 2px 10px;
	font-size: var(--small);
	background: var(--transp-1);
	color: var(--text-600);

	&.success {
		color: var(--success);
		background: color-mix(in oklab, var(--success) 10%, transparent);
	}

	&.warning {
		color: var(--warning);
		background: color-mix(in oklab, var(--warning) 12%, transparent);
	}

	&.accent {
		color: var(--accent);
		background: color-mix(in oklab, var(--accent) 10%, transparent);
	}
}

.mp-controls {
	display: flex;
	flex-direction: column;
	gap: 8px;
	.align-end {
		align-self: flex-end;
	}
}

.segment {
	display: inline-flex;
	border: 1px solid var(--transp-2);
	background: var(--background-900a);
	border-radius: $radius-pill;
	padding: 2px;
	position: relative;
	box-shadow: inset 0 0 0 1px var(--background-800a);

	input[type="radio"] {
		position: absolute;
		opacity: 0;
		pointer-events: none;

		&:checked + label.seg {
			background: color-mix(in oklab, var(--accent) 10%, transparent);
			color: var(--accent);
		}
	}

	.seg {
		border: 0;
		background: transparent;
		color: var(--text-600);
		padding: 6px 10px;
		border-radius: $radius-pill;
		font-size: 12px;
		cursor: pointer;
		user-select: none;
		transition: background-color 0.15s ease, color 0.15s ease;

		&.active {
			background: color-mix(in oklab, var(--accent) 10%, transparent);
			color: var(--accent);
		}
	}
}

.chips-row {
	display: flex;
	gap: 6px;
	flex-wrap: wrap;

	&.scroll {
		overflow-x: auto;
		scrollbar-width: thin;
		padding-bottom: 2px;
	}

	.chip {
		cursor: pointer;

		&.active {
			outline: 1px solid var(--accent);
			color: var(--accent);
			background: color-mix(in oklab, var(--accent) 10%, transparent);
		}
	}
}

.mp-view-sort {
	display: grid;
	grid-template-columns: auto auto;
	align-items: end;
	gap: $gap;

	.view-toggle {
		align-self: start;
	}

	.sort-control {
		min-width: 160px;
	}
}

.mp-sort {
	display: flex;
	flex-direction: column;
	gap: 4px;
	align-items: flex-end;
	min-width: 160px;
}

.mp-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	clip-path: inset(50%);
}

.section-title {
	margin: 14px 0 8px;
	display: flex;
	justify-content: space-between;
	align-items: center;

	h3 {
		margin: 0;
		font-weight: 700;
		font-size: 16px;
	}

	&.with-sort {
		margin-top: 16px;
	}
}

.featured-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
	gap: 12px;
}

.marketplace-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
	gap: 12px;
	margin-top: 12px;
}

.mp-card {
	display: flex;
	flex-direction: column;
	border-radius: $card-radius;
	overflow: hidden;
	border: 1px solid var(--transp-2);
	background: var(--background-900a);
	transition: box-shadow 0.2s ease, transform 0.2s ease;
	position: relative;
	height: 300px;

	&:hover {
		.body {
			backdrop-filter: blur(10px);
			background-color: rgba(0, 0, 0, 0.5);
		}
	}

	.cover {
		display: block;
		position: relative;
		height: 100%;
		background: var(--background-900);

		img {
			width: 100%;
			height: 100%;
			object-fit: cover;
			display: block;
		}

		.placeholder {
			width: 100%;
			height: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			color: var(--text-600);
		}

		.flag {
			position: absolute;
			top: 8px;
			left: 8px;
			font-size: 10px;
			padding: 2px 8px;
			border-radius: $radius-pill;
			background: var(--transp-1);
			color: var(--text-600);
			backdrop-filter: blur(4px);

			&.success {
				color: var(--success);
				background: color-mix(
					in oklab,
					var(--success) 12%,
					transparent
				);
			}

			&.warning {
				color: var(--warning);
				background: color-mix(
					in oklab,
					var(--warning) 14%,
					transparent
				);
			}
		}
	}

	.body {
		padding: var(--space-sm) var(--space-md);
		backdrop-filter: blur(5px);
		background-color: rgba(0, 0, 0, 0.3);
		transition: backdrop-filter 0.2s ease, background-color 0.2s ease;
		display: flex;
		flex-direction: column;
		position: absolute;
		bottom: 0;
		z-index: 1;
		width: 100%;
		justify-content: flex-end;
		flex-direction: column;
	}

	.top {
		display: flex;
		justify-content: space-between;
		align-items: flex-start;
		gap: 8px;
	}

	.title {
		font-weight: 700;
		color: #fff;
		text-decoration: none;

		&:hover {
			text-decoration: underline;
		}
	}

	.badges {
		display: flex;
		gap: 6px;
	}

	.meta {
		display: flex;
		align-items: center;
		gap: 8px;
		font-size: 12px;
		color: var(--text-600);

		.dot {
			width: 4px;
			height: 4px;
			border-radius: 50%;
			background: var(--transp-3);
			display: inline-block;
		}
	}

	.actions {
		display: grid;
		grid-template-columns: 1fr 1fr;
		gap: 5px;
		position: absolute;
		z-index: 1;
		width: 100%;
		display: flex;
		justify-content: flex-end;
		gap: 5px;
		top: 8px;
		right: 8px;

		.mp-install-button,
		.mp-details-button {
			background: var(--accent);
			color: var(--accent-900);
			border: 0;
			width: 40px;
			height: 40px;
			font-size: var(--h6);
			border-radius: 25px;
			display: inline-flex;
			align-items: center;
			justify-content: center;
			cursor: pointer;
			transition: background-color 0.2s ease, color 0.2s ease;

			&:hover {
				background-color: color-mix(
					in oklab,
					var(--accent) 80%,
					transparent
				);
			}
		}

		.mp-details-button {
			@extend .blur-bg;

			background: var(--transp-1);
			color: var(--text-600);

			&:hover {
				background: var(--transp-2);
				color: var(--text-200);
			}
		}
	}

	&.paid {
		border: 2px solid transparent !important;
		background: linear-gradient(
					var(--background-900),
					var(--background-900)
				)
				padding-box,
			linear-gradient(
					45deg,
					color-mix(in oklab, var(--accent) 60%, transparent),
					color-mix(in oklab, #ff6a00 40%, transparent),
					color-mix(in oklab, #fd50a3 40%, transparent),
					color-mix(in oklab, #00c6ff 40%, transparent),
					color-mix(in oklab, var(--accent) 60%, transparent)
				)
				border-box;
		background-size: 400% 400%;
		animation: borderShine 6s ease-in-out infinite;

		&::before {
			content: "";
			position: absolute;
			left: 0;
			right: 0;
			top: 0;
			height: 3px;
			background: linear-gradient(
				90deg,
				color-mix(in oklab, var(--accent) 40%, transparent),
				transparent
			);
		}
	}
}

.version-list {
	list-style: none;
	margin: 0;
	padding: 0;

	li {
		display: flex;
		justify-content: space-between;
		padding: 8px 0;
		border-bottom: 1px dashed var(--transp-2);

		&:last-child {
			border-bottom: 0;
		}
	}

	.ver {
		font-weight: 600;
	}
}

@keyframes borderShine {
	0%,
	100% {
		background-position: 0% 50%;
	}
	50% {
		background-position: 100% 50%;
	}
}

.marketplace-details {
	display: grid;
	gap: 20px;

	.details-header {
		display: grid;
		grid-template-columns: 300px 1fr;
		gap: 24px;
		padding: var(--space-md);
		border-radius: $card-radius;
		overflow: hidden;
		border: 1px solid var(--transp-2);
		background: var(--background-900a);

		&.paid {
			position: relative;
			border: 2px solid transparent !important;
			background: linear-gradient(
						var(--background-900),
						var(--background-900)
					)
					padding-box,
				linear-gradient(
						45deg,
						color-mix(in oklab, var(--accent) 60%, transparent),
						color-mix(in oklab, #ff6a00 40%, transparent),
						color-mix(in oklab, #fd50a3 40%, transparent),
						color-mix(in oklab, #00c6ff 40%, transparent),
						color-mix(in oklab, var(--accent) 60%, transparent)
					)
					border-box;
		}

		.cover {
			position: relative;
			width: 100%;
			aspect-ratio: 1/1;
			border-radius: var(--border1);
			overflow: hidden;
			background: var(--background-900a);

			img {
				width: 100%;
				height: 100%;
				object-fit: cover;
				display: block;
			}

			.placeholder-icon {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 100%;
				height: 100%;
				color: var(--text-600);
				font-size: 48px;
			}
		}

		.info {
			display: flex;
			flex-direction: column;
			gap: 12px;

			.title {
				margin: 0;
				font-size: 28px;
				font-weight: 800;
			}

			.labels {
				display: flex;
				flex-wrap: wrap;
				gap: 6px;
			}

			.meta-grid {
				display: grid;
				grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
				gap: 16px;
				margin-top: 12px;
				padding-top: 12px;
				border-top: 1px dashed var(--transp-2);
			}

			.meta-item {
				display: flex;
				flex-direction: column;
				gap: 2px;
				.label {
					font-size: 12px;
					color: var(--text-600);
				}
				.value {
					font-weight: 600;
				}
			}

			.actions {
				display: flex;
				gap: 8px;
                margin-top: var(--space-md);
			}
		}
	}

	.details-body {
		.tabs {
			border-radius: $card-radius;
			overflow: clip;
			border: 1px solid var(--transp-2);
			background: var(--background-900);
			padding: var(--space-md);
			padding-top: var(--space-sm);

			input[type="radio"] {
				position: absolute;
				opacity: 0;
				pointer-events: none;
			}

			label {
				display: inline-block;
				padding: 10px 12px;
				font-size: 13px;
				cursor: pointer;
				color: var(--text-600);
			}

			&:has(#tab-overview:checked) label[for="tab-overview"],
			&:has(#tab-versions:checked) label[for="tab-versions"] {
				color: var(--accent);
				border-bottom: 2px solid var(--accent);
			}

			.tab-content {
				margin-top: var(--space-md);

				.tab {
					display: none;
				}
			}

			/* Fallback for browsers without :has */
			#tab-overview:checked ~ .tab-content .t-overview {
				display: block;
			}
			#tab-versions:checked ~ .tab-content .t-versions {
				display: block;
			}
		}
	}

	@media (max-width: 992px) {
		.details-header {
			grid-template-columns: 1fr;
			padding: 16px;
			gap: 16px;

			.cover {
				aspect-ratio: 16/9;
			}
		}
	}
}

.markdown-content {
	h1,
	h2,
	h3,
	h4,
	h5,
	h6 {
		margin-top: 1.5em;
		margin-bottom: 0.5em;
		font-weight: 700;
		color: var(--text-200);

		&:first-child {
			margin-top: 0;
		}
	}

	h1 {
		font-size: 1.8em;
	}
	h2 {
		font-size: 1.6em;
	}
	h3 {
		font-size: 1.4em;
	}
	h4 {
		font-size: 1.2em;
	}

	p {
		line-height: 1.6;
		margin-bottom: 1em;
		color: var(--text-300);
	}

	a {
		color: var(--accent);
		text-decoration: none;
		&:hover {
			text-decoration: underline;
		}
	}

	ul,
	ol {
		padding-left: 20px;
		margin-bottom: 1em;
		color: var(--text-200);
	}

	li {
		margin-bottom: 0.5em;
	}

	strong {
		font-weight: 700;
		color: var(--text-200);
	}

	pre {
		background: var(--background-800);
		border: 1px solid var(--transp-2);
		border-radius: var(--border1);
		padding: 1em;
		overflow-x: auto;
		font-family: var(--font-mono);
	}

	code {
		font-family: var(--font-mono);
		background: var(--transp-1);
		padding: 0.2em 0.4em;
		border-radius: 3px;
		font-size: 85%;
		color: var(--text-200);
	}

	pre > code {
		padding: 0;
		background: none;
		font-size: inherit;
	}

	blockquote {
		border-left: 4px solid var(--transp-2);
		padding-left: 1em;
		margin-left: 0;
		color: var(--text-600);
	}

	hr {
		border: 0;
		border-top: 1px solid var(--transp-2);
		margin: 2em 0;
	}
}
