/*
 * jmm/youtube-playlist. Every rule is scoped to .jmm-ytpl.
 *
 * A dark box, like the old Nyttiflempan column: #222, white text, compact rows with
 * 16:9 thumbnails 120 px wide. The block is its own container, so it lays itself out by
 * its own width and not the window's: stacked in a narrow column, the list beside the
 * player when there is room. Theme.json presets are used where they exist (the font
 * sizes, the accent colour for focus and for the playing item), with the dark look as
 * the fallback.
 */
.jmm-ytpl {
	--jmm-ytpl-bg: #222;
	--jmm-ytpl-fg: #fff;
	--jmm-ytpl-muted: #bdbdbd;
	--jmm-ytpl-hover: #2f2f2f;
	--jmm-ytpl-current: #383838;
	--jmm-ytpl-accent: var(--wp--preset--color--accent-1, #ffee58);

	container: jmm-ytpl / inline-size;
	box-sizing: border-box;
	padding: 0.75rem;
	background: var(--jmm-ytpl-bg);
	color: var(--jmm-ytpl-fg);
	font-size: var(--wp--preset--font-size--small, 0.875rem);
	line-height: 1.35;
}

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

.jmm-ytpl a {
	color: inherit;
}

.jmm-ytpl__heading {
	margin: 0 0 0.625rem;
	color: inherit;
	font-size: var(--wp--preset--font-size--medium, 1rem);
	font-weight: 700;
	line-height: 1.25;
}

.jmm-ytpl__notice {
	margin: 0;
}

.jmm-ytpl__inner {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 0.75rem;
}

@container jmm-ytpl (min-width: 32rem) {
	.jmm-ytpl--auto .jmm-ytpl__inner {
		grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
		align-items: start;
	}
}

/* The player */
.jmm-ytpl__stage {
	position: relative;
	aspect-ratio: 16 / 9;
	background: #000;
	overflow: hidden;
}

.jmm-ytpl__facade {
	position: absolute;
	inset: 0;
	display: block;
}

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

.jmm-ytpl__play {
	position: absolute;
	top: 50%;
	left: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 3.5rem;
	height: 2.5rem;
	transform: translate(-50%, -50%);
	border-radius: 0.5rem;
	background: rgba(34, 34, 34, 0.85);
	color: #fff;
}

.jmm-ytpl__play svg {
	width: 1.75rem;
	height: 1.75rem;
	fill: currentcolor;
}

.jmm-ytpl__facade:hover .jmm-ytpl__play,
.jmm-ytpl__facade:focus-visible .jmm-ytpl__play {
	background: #c00;
}

.jmm-ytpl__frame {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	border: 0;
}

.jmm-ytpl__now {
	margin: 0.5rem 0 0;
	font-weight: 600;
	overflow-wrap: anywhere;
}

/* The list */
.jmm-ytpl__list {
	display: grid;
	gap: 0.25rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.jmm-ytpl__item {
	margin: 0;
	padding: 0;
}

.jmm-ytpl__link {
	display: grid;
	grid-template-columns: 120px minmax(0, 1fr);
	gap: 0.625rem;
	align-items: start;
	padding: 0.25rem;
	border-left: 3px solid transparent;
	border-radius: 0.25rem;
	text-decoration: none;
}

.jmm-ytpl__link:hover {
	background: var(--jmm-ytpl-hover);
}

.jmm-ytpl__link[aria-current="true"] {
	border-left-color: var(--jmm-ytpl-accent);
	background: var(--jmm-ytpl-current);
}

.jmm-ytpl__link:hover .jmm-ytpl__title,
.jmm-ytpl__link:focus-visible .jmm-ytpl__title {
	text-decoration: underline;
}

.jmm-ytpl__thumb {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: 16 / 9;
	object-fit: cover;
	background: #000;
}

.jmm-ytpl__text {
	display: block;
	min-width: 0;
}

.jmm-ytpl__title {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	line-clamp: 3;
	overflow: hidden;
	font-weight: 600;
	overflow-wrap: anywhere;
}

.jmm-ytpl__date {
	display: block;
	margin-top: 0.2rem;
	color: var(--jmm-ytpl-muted);
	font-size: 0.85em;
}

.jmm-ytpl__more {
	margin: 0.75rem 0 0;
}

.jmm-ytpl--fallback .jmm-ytpl__more {
	margin: 0;
}

/* Keyboard focus is always visible. */
.jmm-ytpl a:focus-visible,
.jmm-ytpl__frame:focus-visible {
	outline: 2px solid var(--jmm-ytpl-accent);
	outline-offset: 2px;
}

/* Narrowest columns: a smaller thumbnail leaves the title room. */
@container jmm-ytpl (max-width: 15rem) {
	.jmm-ytpl__link {
		grid-template-columns: 96px minmax(0, 1fr);
		gap: 0.5rem;
	}
}

.jmm-ytpl__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

/* Colour changes are only animated for those who have not asked for less motion. */
@media (prefers-reduced-motion: no-preference) {
	.jmm-ytpl__link,
	.jmm-ytpl__play {
		transition: background-color 0.15s ease;
	}
}
