/**
 * Video tiles (template-parts/videos/grid.php) and the video player
 * (assets/js/video-player.js), a modal built on the photo lightbox
 * (components/lightbox.css). Used by the Videos page and the homepage.
 *
 * Grid: 2 columns on phones, 3 on tablets, 4 on laptops and desktops.
 * .nscb-video-grid--three (homepage): a swipeable row on phones, then 3 columns.
 */

/* ---------- Grid ---------- */

.nscb-video-grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: var(--nscb-space-3);
	margin: 0;
	padding: 0;
	list-style: none;
}

@media (max-width: 47.99rem) {
	.nscb-video-grid--three {
		grid-template-columns: none;
		grid-auto-columns: 62%;
		grid-auto-flow: column;
		overflow-x: auto;
		overscroll-behavior-x: contain;
		scroll-snap-type: x mandatory;
		scrollbar-width: none;
	}

	.nscb-video-grid--three::-webkit-scrollbar {
		display: none;
	}

	.nscb-video-grid--three .nscb-video-grid__item {
		scroll-snap-align: start;
	}
}

.nscb-video-card {
	position: relative;
	display: flex;
	flex-direction: column;
	height: 100%;
	overflow: hidden;
	border: 1px solid var(--nscb-edge);
	border-radius: var(--nscb-radius-lg);
	background-color: var(--nscb-color-surface);
	box-shadow: var(--nscb-shadow-card);
	color: inherit;
	text-decoration: none;
}

/* The card clips its corners, so draw the focus ring inside. */
.nscb-video-card:focus-visible {
	outline-offset: -3px;
}

/* Reels are 9:16; 3:4 keeps the subject and fits more videos per screen. */
.nscb-video-card__media {
	position: relative;
	display: grid;
	aspect-ratio: 3 / 4;
	place-items: center;
	overflow: hidden;
	background-color: var(--nscb-surface-raised);
	color: var(--nscb-color-text-secondary);
}

.nscb-video-card__img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform var(--nscb-duration-slow) var(--nscb-ease-out);
}

.nscb-video-card__placeholder {
	width: 2.5rem;
	height: 2.5rem;
}

/* Darkens the lower edge so the play button reads on any thumbnail. */
.nscb-video-card__media::after {
	position: absolute;
	inset: 0;
	background: linear-gradient(to top, rgba(0, 0, 0, 0.45), transparent 45%);
	content: "";
	pointer-events: none;
}

.nscb-video-card__play {
	position: absolute;
	z-index: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 3.25rem;
	height: 3.25rem;
	border: 1px solid rgba(255, 255, 255, 0.35);
	border-radius: 50%;
	background-color: rgba(0, 0, 0, 0.45);
	color: #fff;
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
	transition: background-color var(--nscb-duration-fast) var(--nscb-ease-standard), color var(--nscb-duration-fast) var(--nscb-ease-standard), transform var(--nscb-duration-fast) var(--nscb-ease-standard);
}

.nscb-video-card__play .nscb-icon {
	width: 1.25rem;
	height: 1.25rem;
	margin-left: 0.15rem; /* Optical centre of the triangle. */
	fill: currentColor;
}

.nscb-video-card__body {
	display: grid;
	gap: var(--nscb-space-1);
	padding: var(--nscb-space-3);
}

.nscb-video-card__title {
	display: -webkit-box;
	overflow: hidden;
	font-size: var(--nscb-text-sm);
	font-weight: 600;
	line-height: 1.35;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	line-clamp: 2;
}

.nscb-video-card__date {
	color: var(--nscb-color-text-secondary);
	font-size: var(--nscb-text-xs);
}

@media (hover: hover) and (pointer: fine) {
	.nscb-video-card:hover .nscb-video-card__img {
		transform: scale(1.04);
	}

	.nscb-video-card:hover .nscb-video-card__play {
		background-color: var(--nscb-color-highlight);
		color: var(--nscb-color-highlight-text);
		transform: scale(1.06);
	}
}

@media (min-width: 48rem) {
	.nscb-video-grid {
		grid-template-columns: repeat(3, minmax(0, 1fr));
		gap: var(--nscb-space-4);
	}

	.nscb-video-card {
		border-radius: var(--nscb-radius-xl);
	}

	.nscb-video-card__body {
		padding: var(--nscb-space-4);
	}
}

@media (min-width: 64rem) {
	.nscb-video-grid:not(.nscb-video-grid--three) {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}

	.nscb-video-grid--three {
		gap: var(--nscb-space-6);
	}

	.nscb-video-grid--three .nscb-video-card__title {
		font-size: var(--nscb-text-md);
	}

	.nscb-video-grid--three .nscb-video-card__play {
		width: 4rem;
		height: 4rem;
	}
}

/* ---------- Player ---------- */

.nscb-video-player__figure {
	display: grid;
	width: 100%;
	height: 100%;
	place-items: center;
	align-content: center;
	gap: var(--nscb-space-3);
	margin: 0;
}

/* Portrait (reels): as tall as the screen allows at 9:16. */
.nscb-video-player__frame {
	overflow: hidden;
	width: min(100%, calc((100dvh - 10rem) * 9 / 16));
	aspect-ratio: 9 / 16;
	border-radius: var(--nscb-radius-md);
	background-color: #000;
}

.nscb-video-player--landscape .nscb-video-player__frame {
	width: min(100%, calc((100dvh - 10rem) * 16 / 9), 64rem);
	aspect-ratio: 16 / 9;
}

.nscb-video-player__iframe {
	display: block;
	width: 100%;
	height: 100%;
	border: 0;
}

.nscb-video-player__caption {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: center;
	gap: var(--nscb-space-1) var(--nscb-space-4);
	max-width: 40rem;
	text-align: center;
}

.nscb-video-player__title {
	font-weight: 600;
}

.nscb-video-player__source {
	color: var(--nscb-color-text-secondary);
	font-size: var(--nscb-text-sm);
	text-decoration: underline;
	text-underline-offset: 0.2em;
}

.nscb-video-player__source:hover {
	color: var(--nscb-color-text);
}

/* Phones and tablets: previous / next sit below the player, clear of its controls. */
@media (max-width: 63.99rem) {
	.nscb-video-player .nscb-lightbox__prev,
	.nscb-video-player .nscb-lightbox__next {
		top: auto;
		bottom: max(var(--nscb-space-3), env(safe-area-inset-bottom));
		transform: none;
	}

	.nscb-video-player__caption {
		padding-inline: 3.5rem;
	}
}

@media (min-width: 64rem) {
	.nscb-video-player__frame {
		width: min(100%, calc((100dvh - 2 * var(--nscb-space-8) - 3rem) * 9 / 16));
	}

	.nscb-video-player--landscape .nscb-video-player__frame {
		width: min(100%, calc((100dvh - 2 * var(--nscb-space-8) - 3rem) * 16 / 9), 64rem);
	}
}

@media (prefers-reduced-motion: reduce) {
	.nscb-video-card__img,
	.nscb-video-card__play {
		transition: none;
	}
}
