/**
 * YouTube Video Gallery — front-end styles.
 * Scoped under .ytg-wrap to avoid clashing with theme styles.
 */

.ytg-wrap {
	--ytg-radius: 10px;
	--ytg-gap: 20px;
	--ytg-card-bg: #fff;
	--ytg-card-border: #e6e6e6;
	--ytg-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
	--ytg-shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.16);
	--ytg-text: #1a1a1a;
	--ytg-muted: #6b7280;
	--ytg-accent: #cc0000;
	box-sizing: border-box;
	color: var(--ytg-text);
	max-width: 100%;
}

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

/* ---------- Grid ---------- */
.ytg-grid {
	display: grid;
	grid-template-columns: repeat(var(--ytg-cols, 3), minmax(0, 1fr));
	gap: var(--ytg-gap);
	margin: 0;
	padding: 0;
}

.ytg-cols-1 { --ytg-cols: 1; }
.ytg-cols-2 { --ytg-cols: 2; }
.ytg-cols-3 { --ytg-cols: 3; }
.ytg-cols-4 { --ytg-cols: 4; }
.ytg-cols-5 { --ytg-cols: 5; }
.ytg-cols-6 { --ytg-cols: 6; }

/* ---------- Cards ---------- */
.ytg-card {
	display: flex;
	flex-direction: column;
	background: var(--ytg-card-bg);
	border: 1px solid var(--ytg-card-border);
	border-radius: var(--ytg-radius);
	overflow: hidden;
	text-decoration: none;
	color: inherit;
	box-shadow: var(--ytg-shadow);
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.ytg-card:hover,
.ytg-card:focus {
	transform: translateY(-4px);
	box-shadow: var(--ytg-shadow-hover);
}

.ytg-card:focus-visible {
	outline: 2px solid var(--ytg-accent);
	outline-offset: 2px;
}

/* ---------- 16:9 thumbnail ---------- */
.ytg-ratio-16x9 {
	position: relative;
	width: 100%;
	aspect-ratio: 16 / 9;
	background: #111;
	overflow: hidden;
}

/* Fallback for browsers without aspect-ratio support. */
@supports not (aspect-ratio: 16 / 9) {
	.ytg-ratio-16x9::before {
		content: "";
		display: block;
		padding-top: 56.25%;
	}
}

.ytg-thumb img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	transition: transform 0.25s ease;
}

.ytg-card:hover .ytg-thumb img {
	transform: scale(1.04);
}

.ytg-thumb-placeholder {
	position: absolute;
	inset: 0;
	background: linear-gradient(135deg, #2b2b2b, #4b4b4b);
}

/* Play badge on video cards. */
.ytg-play-badge {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 56px;
	height: 56px;
	transform: translate(-50%, -50%);
	background: rgba(0, 0, 0, 0.6);
	border-radius: 50%;
	opacity: 0;
	z-index: 3;
	transition: opacity 0.2s ease;
}

.ytg-play-badge::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 54%;
	transform: translate(-50%, -50%);
	border-style: solid;
	border-width: 10px 0 10px 17px;
	border-color: transparent transparent transparent #fff;
}

.ytg-video-card:hover .ytg-play-badge {
	opacity: 1;
}

/* Overlay text rendered over a thumbnail. */
.ytg-overlay-text {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	/* Comfortable, responsive breathing room on every edge. */
	padding: clamp(10px, 6%, 26px);
	text-align: center;
	z-index: 2;
	background: linear-gradient(180deg, rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.45));
	pointer-events: none;
}

.ytg-overlay-inner {
	color: #fff;
	font-weight: 700;
	line-height: 1.25;
	letter-spacing: 0.01em;
	text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7), 0 0 2px rgba(0, 0, 0, 0.5);
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
	max-width: 100%;
}

/* Fixed overlay sizes (set on .ytg-overlay-text by the shortcode). */
.ytg-overlay-sm .ytg-overlay-inner { font-size: clamp(12px, 1.6vw, 16px); }
.ytg-overlay-md .ytg-overlay-inner { font-size: clamp(15px, 2.4vw, 24px); }
.ytg-overlay-lg .ytg-overlay-inner { font-size: clamp(20px, 3.4vw, 34px); }

/*
 * Auto mode: the text is fit to the thumbnail width by frontend.js. We keep it
 * on a single line and disable the multi-line clamp; the medium size acts as a
 * sensible fallback before the script runs (or if JS is disabled).
 */
.ytg-overlay-auto .ytg-overlay-inner {
	font-size: clamp(15px, 2.4vw, 24px);
	white-space: nowrap;
	-webkit-line-clamp: none;
	display: block;
}

/* Duration pill. */
.ytg-duration {
	position: absolute;
	right: 8px;
	bottom: 8px;
	background: rgba(0, 0, 0, 0.8);
	color: #fff;
	font-size: 12px;
	line-height: 1;
	padding: 4px 6px;
	border-radius: 4px;
	z-index: 3;
	font-variant-numeric: tabular-nums;
}

/* ---------- Card body ---------- */
.ytg-card-body {
	padding: 12px 14px 14px;
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.ytg-card-title {
	font-weight: 600;
	font-size: 15px;
	line-height: 1.35;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.ytg-card-meta {
	font-size: 13px;
	color: var(--ytg-muted);
}

/* ---------- Headings & text ---------- */
.ytg-heading {
	margin: 0.2em 0 0.4em;
	font-size: 1.6em;
	line-height: 1.2;
}

.ytg-description {
	color: var(--ytg-muted);
	line-height: 1.6;
	margin-bottom: 1em;
	white-space: pre-line;
	word-break: break-word;
}

.ytg-description a {
	color: var(--ytg-accent);
}

.ytg-empty {
	padding: 2em;
	text-align: center;
	color: var(--ytg-muted);
	background: #f6f7f8;
	border-radius: var(--ytg-radius);
}

/* ---------- Navigation ---------- */
.ytg-nav {
	display: flex;
	flex-wrap: wrap;
	gap: 16px;
	align-items: center;
	margin: 0 0 16px;
}

.ytg-nav-bottom {
	margin: 24px 0 0;
}

.ytg-back-link {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	font-weight: 600;
	text-decoration: none;
	color: var(--ytg-accent);
}

.ytg-back-link:hover {
	text-decoration: underline;
}

.ytg-back-all {
	color: var(--ytg-muted);
}

/* ---------- Single video player ---------- */
.ytg-player {
	border-radius: var(--ytg-radius);
	overflow: hidden;
	box-shadow: var(--ytg-shadow);
	margin-bottom: 16px;
	background: #000;
}

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

/* ---------- Pagination ---------- */
.ytg-pagination {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 24px;
}

.ytg-page {
	min-width: 36px;
	text-align: center;
	padding: 6px 10px;
	border: 1px solid var(--ytg-card-border);
	border-radius: 6px;
	text-decoration: none;
	color: var(--ytg-text);
}

.ytg-page.current,
.ytg-page:hover {
	background: var(--ytg-accent);
	border-color: var(--ytg-accent);
	color: #fff;
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
	.ytg-cols-5,
	.ytg-cols-6 { --ytg-cols: 4; }
}

@media (max-width: 768px) {
	.ytg-grid { --ytg-cols: 2 !important; gap: 14px; }
}

@media (max-width: 480px) {
	.ytg-grid { --ytg-cols: 1 !important; }
	.ytg-heading { font-size: 1.35em; }
}

/* ---------- Dark theme friendliness ---------- */
@media (prefers-color-scheme: dark) {
	.ytg-wrap {
		--ytg-card-bg: #1f2227;
		--ytg-card-border: #33373d;
		--ytg-text: #e9eaec;
		--ytg-muted: #9aa0a6;
	}
	.ytg-empty { background: #1f2227; }
}
