/* YT Video Gallery — frontend styles
   Everything is driven by CSS variables so you can retheme in one place.
   Colours intentionally neutral so the gallery inherits the host theme. */

.ytvg-gallery {
	--ytvg-cols: 4;
	--ytvg-gap: 20px;
	--ytvg-radius: 10px;
	--ytvg-accent: #6F6189;          /* active filter bg + play hover */
	--ytvg-accent-dark: #5b5070;     /* hover shade (PHP overrides this when accent is customised) */
	--ytvg-text: inherit;
	--ytvg-muted: #6b7177;
	/* The variables below are overridden from the Look & Feel page when set. */
	--ytvg-filter-text: var(--ytvg-muted);
	--ytvg-filter-border: currentColor;
	--ytvg-filter-active-text: #fff;
	--ytvg-title-color: inherit;
	--ytvg-play-bg: rgba(0, 0, 0, .55);
	--ytvg-play-icon: #fff;
	font-family: inherit;
	color: var(--ytvg-text);
	box-sizing: border-box;
	max-width: 100%;
}

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

/* -------- Filter (desktop buttons) -------- */
.ytvg-filter {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	justify-content: center;   /* centre the buttons across the full-width row */
	width: 100%;
	margin-bottom: 24px;
}

.ytvg-filter__btn {
	appearance: none;
	border: 1px solid var(--ytvg-filter-border);
	background: transparent;
	color: var(--ytvg-filter-text);
	border-radius: 999px;
	padding: 8px 18px;
	font: inherit;
	font-size: 14px;
	line-height: 1;
	cursor: pointer;
	transition: background .18s ease, color .18s ease, border-color .18s ease;
}

.ytvg-filter__btn:hover {
	background: var(--ytvg-accent-dark);
	border-color: var(--ytvg-accent-dark);
	color: #fff;
}

.ytvg-filter__btn.is-active {
	background: var(--ytvg-accent);
	border-color: var(--ytvg-accent);
	color: var(--ytvg-filter-active-text);
}

.ytvg-filter__btn.is-active:hover {
	background: var(--ytvg-accent-dark);
	border-color: var(--ytvg-accent-dark);
	color: #fff;
}

/* Same theme insulation for the filter buttons: drop the theme's focus
   box-shadow, but provide our own keyboard focus ring for accessibility. */
.ytvg-gallery .ytvg-filter__btn:focus {
	box-shadow: none !important;
	outline: none !important;
}

.ytvg-gallery .ytvg-filter__btn:focus-visible {
	outline: 2px solid var(--ytvg-accent) !important;
	outline-offset: 2px;
}

/* -------- Filter (mobile dropdown) -------- */
.ytvg-filter-mobile {
	display: none;
	margin-bottom: 22px;
}

.ytvg-filter-select {
	width: 100%;
	padding: 12px 14px;
	font: inherit;
	font-size: 16px;            /* 16px stops iOS zoom-on-focus */
	border: 1px solid var(--ytvg-muted);
	border-radius: 8px;
	background: transparent;
	color: var(--ytvg-text);
}

/* -------- Grid -------- */
.ytvg-grid-front {
	display: grid;
	grid-template-columns: repeat(var(--ytvg-cols), 1fr);
	gap: var(--ytvg-gap);
}

/* Each tile is a div with role="button" (keyboard handled in JS). Using a div
   rather than a <button> avoids inheriting the theme's button styling. */
.ytvg-tile {
	appearance: none;
	border: 0;
	background: none;
	padding: 0;
	margin: 0;
	text-align: left;
	cursor: pointer;
	font: inherit;
	color: inherit;
	display: flex;
	flex-direction: column;
	gap: 8px;
	white-space: normal;
	min-width: 0;   /* lets the 1fr columns shrink + stay equal (the overflow/uneven-size fix) */
}

.ytvg-tile.is-hidden {
	display: none;
}

/* Insulate the tile from theme styling. Now that the tile is a div (not a
   <button>) most theme button rules no longer reach it, but we keep this
   reset as defence-in-depth and to suppress the default focus outline — the
   accessible focus indicator lives on .ytvg-tile__thumb (below). */
.ytvg-gallery .ytvg-tile,
.ytvg-gallery .ytvg-tile:hover,
.ytvg-gallery .ytvg-tile:focus,
.ytvg-gallery .ytvg-tile:active,
.ytvg-gallery .ytvg-tile:focus-visible,
.ytvg-gallery .ytvg-tile:focus-within {
	background: transparent !important;
	box-shadow: none !important;
	outline: none !important;
	border: 0 !important;
	-webkit-tap-highlight-color: transparent;
}

.ytvg-tile__thumb {
	position: relative;
	display: block;
	width: 100%;
	flex-shrink: 0;
	aspect-ratio: 16 / 9;
	border-radius: var(--ytvg-radius);
	overflow: hidden;
	background: rgba(0, 0, 0, .06);
}

.ytvg-tile__thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	transition: transform .35s ease;
}

.ytvg-tile:hover .ytvg-tile__thumb img,
.ytvg-tile:focus-visible .ytvg-tile__thumb img {
	transform: scale(1.04);
}

.ytvg-tile:focus-visible .ytvg-tile__thumb {
	outline: 3px solid var(--ytvg-accent);
	outline-offset: 2px;
}

/* Pure-CSS play overlay. To use your own art instead, set a background-image
   on .ytvg-tile__play, remove the ::before triangle, and size to taste. */
.ytvg-tile__play {
	position: absolute;
	top: 50%;
	left: 50%;
	width: var(--ytvg-play-size, 64px);
	height: var(--ytvg-play-size, 64px);
	transform: translate(-50%, -50%);
	border-radius: 50%;
	background: var(--ytvg-play-bg);
	backdrop-filter: blur(2px);
	transition: background .2s ease, transform .2s ease;
}

.ytvg-tile__play::before {
	content: "";
	position: absolute;
	top: 50%;
	left: 54%;
	transform: translate(-50%, -50%);
	border-style: solid;
	/* triangle scales with the circle: ~0.17 tall, ~0.28 wide */
	border-width: calc(var(--ytvg-play-size, 64px) * 0.17) 0 calc(var(--ytvg-play-size, 64px) * 0.17) calc(var(--ytvg-play-size, 64px) * 0.28);
	border-color: transparent transparent transparent var(--ytvg-play-icon);
}

.ytvg-tile:hover .ytvg-tile__play,
.ytvg-tile:focus-visible .ytvg-tile__play {
	background: var(--ytvg-accent);
	transform: translate(-50%, -50%) scale(1.06);
}

/* Text block: stretches to the bottom so every tile in a row matches height. */
.ytvg-tile__text {
	flex: 1 1 auto;
	min-width: 0;        /* allow the text block to shrink within the column */
	display: flex;
	flex-direction: column;
	gap: 5px;
	padding: 12px 7px;
}

.ytvg-tile__title {
	font-size: 15px;
	font-weight: 600;
	line-height: 1.35;
	color: var(--ytvg-title-color);
	min-width: 0;
	white-space: normal;        /* override any inherited nowrap from theme button styles */
	overflow-wrap: break-word;  /* break over-long words instead of overflowing */
	display: -webkit-box;
	-webkit-line-clamp: 2;       /* hard two-line clamp */
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.ytvg-tile__desc {
	font-size: 13px;
	line-height: 1.4;
	color: var(--ytvg-muted);
	min-width: 0;
	white-space: normal;
	overflow-wrap: break-word;
	display: -webkit-box;
	-webkit-line-clamp: 2;       /* two lines of description */
	-webkit-box-orient: vertical;
	overflow: hidden;
}

/* -------- Responsive columns --------
   Desktop uses the count from the Look & Feel page (--ytvg-cols).
   Tablet (<=1024px) drops to 3, phones (<=600px) to a single column. */
@media (max-width: 1024px) {
	.ytvg-grid-front { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
	.ytvg-filter { display: none; }
	.ytvg-filter-mobile { display: block; }
}

@media (max-width: 600px) {
	.ytvg-grid-front { grid-template-columns: 1fr; gap: 16px; }
}

/* -------- Lightbox -------- */
.ytvg-lightbox {
	position: fixed;
	inset: 0;
	z-index: 99999;
	display: none;
	align-items: center;
	justify-content: center;
	padding: 24px;
}

.ytvg-lightbox.is-open {
	display: flex;
}

.ytvg-lightbox__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, .85);
	animation: ytvg-fade .2s ease;
}

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

.ytvg-lightbox__inner {
	position: relative;
	z-index: 1;
	width: min(960px, 92vw);
	animation: ytvg-pop .22s ease;
}

@keyframes ytvg-pop {
	from { opacity: 0; transform: scale(.97); }
	to   { opacity: 1; transform: scale(1); }
}

.ytvg-lightbox__frame {
	position: relative;
	aspect-ratio: 16 / 9;
	width: 100%;
	background: #000;
	border-radius: 10px;
	overflow: hidden;
}

.ytvg-lightbox__frame iframe {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	border: 0;
}

.ytvg-lightbox__meta {
	color: #fff;
	margin-top: 14px;
	text-align: center;
}

.ytvg-lightbox__title {
	margin: 0 0 6px;
	font-size: 18px;
	font-weight: 600;
}

.ytvg-lightbox__desc {
	margin: 0;
	font-size: 14px;
	line-height: 1.5;
	color: #cfd2d6;
}

/* Close + nav controls */
.ytvg-lightbox__close {
	position: absolute;
	top: 16px;
	right: 20px;
	z-index: 2;
	width: 44px;
	height: 44px;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, .12);
	color: #fff;
	font-size: 26px;
	line-height: 1;
	cursor: pointer;
	transition: background .18s ease;
}

.ytvg-lightbox__close:hover {
	background: rgba(255, 255, 255, .25);
}

.ytvg-lightbox__nav {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	z-index: 2;
	width: 52px;
	height: 52px;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, .12);
	color: #fff;
	font-style: normal;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: background .18s ease;
}

.ytvg-lightbox__nav svg {
	width: 22px;
	height: 22px;
	display: block;
}

.ytvg-lightbox__nav:hover {
	background: rgba(255, 255, 255, .25);
}

.ytvg-lightbox__nav.is-hidden {
	display: none;
}

.ytvg-lightbox__prev { left: 16px; }
.ytvg-lightbox__next { right: 16px; }

@media (max-width: 768px) {
	.ytvg-lightbox { padding: 12px; }
	.ytvg-lightbox__nav {
		top: auto;
		bottom: 14px;
		transform: none;
		width: 46px;
		height: 46px;
	}
	.ytvg-lightbox__prev { left: 18px; }
	.ytvg-lightbox__next { right: 18px; }
	.ytvg-lightbox__meta { margin-bottom: 56px; }
}
