/**
 * TVC YouTube Shorts Frontend Stylesheet
 * Strictly isolated CSS with tvc-youtube-shorts- namespace
 *
 * @package TVC_YouTube_Shorts
 */

/* ==========================================================================
   1. CSS Reset & Variables
   ========================================================================== */
.tvc-youtube-shorts-wrapper {
	--tvc-cols-desktop: 4;
	--tvc-cols-tablet: 2;
	--tvc-cols-mobile: 1;
	--tvc-gap: 16px;
	--tvc-radius: 12px;
	--tvc-aspect-ratio: 9 / 16;
	--tvc-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
	--tvc-shadow-hover: 0 10px 25px rgba(0, 0, 0, 0.2);
	--tvc-primary: #ff0000;

	position: relative;
	width: 100%;
	max-width: 100%;
	margin: 24px 0;
	box-sizing: border-box;
}

.tvc-youtube-shorts-wrapper *,
.tvc-youtube-shorts-wrapper *::before,
.tvc-youtube-shorts-wrapper *::after {
	box-sizing: border-box;
}

/* ==========================================================================
   2. Grid Layout
   ========================================================================== */
.tvc-youtube-shorts-mode-grid .tvc-youtube-shorts-grid-track {
	display: grid;
	grid-template-columns: repeat(var(--tvc-cols-desktop, 4), minmax(0, 1fr));
	gap: var(--tvc-gap, 16px);
	width: 100%;
}

/* Tablet (<= 1024px) */
@media (max-width: 1024px) {
	.tvc-youtube-shorts-mode-grid .tvc-youtube-shorts-grid-track {
		grid-template-columns: repeat(var(--tvc-cols-tablet, 2), minmax(0, 1fr));
	}
}

/* Mobile (<= 640px): Grid automatically becomes a swipeable snap carousel,
   matching the native carousel behavior on phones — regardless of mode.
   Cards are ~78% of the viewport so a slice of the next video always peeks
   in from the right, making it obvious there is more to swipe. */
@media (max-width: 640px) {
	.tvc-youtube-shorts-mode-grid {
		padding-left: 0;
		padding-right: 0;
	}

	.tvc-youtube-shorts-mode-grid .tvc-youtube-shorts-grid-track {
		display: flex;
		flex-wrap: nowrap;
		gap: var(--tvc-gap, 16px);
		overflow-x: auto;
		scroll-snap-type: x mandatory;
		scroll-behavior: smooth;
		-webkit-overflow-scrolling: touch;
		scrollbar-width: none; /* Firefox */
		-ms-overflow-style: none; /* IE/Edge */
		user-select: none;
		overscroll-behavior-x: contain;
		padding: 8px 12px 14px 12px;
	}

	.tvc-youtube-shorts-mode-grid .tvc-youtube-shorts-grid-track::-webkit-scrollbar {
		display: none; /* Chrome, Safari, Opera */
	}

	.tvc-youtube-shorts-mode-grid .tvc-youtube-shorts-card {
		flex: 0 0 78%;
		width: 78%;
		max-width: 78%;
		min-width: 0;
		scroll-snap-align: start;
		scroll-snap-stop: always;
	}
}

/* ==========================================================================
   3. Carousel Layout
   ========================================================================== */
.tvc-youtube-shorts-mode-carousel {
	position: relative;
	display: flex;
	align-items: center;
}

.tvc-youtube-shorts-carousel-viewport {
	width: 100%;
	overflow: hidden;
	position: relative;
}

.tvc-youtube-shorts-carousel-track {
	display: flex;
	gap: var(--tvc-gap, 16px);
	overflow-x: auto;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: none; /* Firefox */
	-ms-overflow-style: none; /* IE/Edge */
	padding: 8px 2px 14px 2px;
	user-select: none;
}

.tvc-youtube-shorts-carousel-track::-webkit-scrollbar {
	display: none; /* Chrome, Safari, Opera */
}

.tvc-youtube-shorts-carousel-track.tvc-youtube-shorts-is-dragging {
	scroll-snap-type: none;
	scroll-behavior: auto;
	cursor: grabbing;
}

.tvc-youtube-shorts-mode-carousel .tvc-youtube-shorts-card {
	flex: 0 0 calc((100% - (var(--tvc-cols-desktop, 4) - 1) * var(--tvc-gap, 16px)) / var(--tvc-cols-desktop, 4));
	min-width: 0;
	scroll-snap-align: start;
}

@media (max-width: 1024px) {
	.tvc-youtube-shorts-mode-carousel .tvc-youtube-shorts-card {
		flex: 0 0 calc((100% - (var(--tvc-cols-tablet, 2) - 1) * var(--tvc-gap, 16px)) / var(--tvc-cols-tablet, 2));
	}
}

@media (max-width: 640px) {
	.tvc-youtube-shorts-mode-carousel .tvc-youtube-shorts-card {
		flex: 0 0 78%;
		width: 78%;
		max-width: 78%;
		scroll-snap-align: start;
		scroll-snap-stop: always;
	}
}

/* Carousel Navigation Buttons */
.tvc-youtube-shorts-nav-btn {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	z-index: 10;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.9);
	color: #1a202c;
	border: 1px solid rgba(0, 0, 0, 0.08);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
	padding: 0;
}

.tvc-youtube-shorts-nav-btn:hover {
	background: #ffffff;
	transform: translateY(-50%) scale(1.08);
	box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.tvc-youtube-shorts-nav-btn:focus-visible {
	outline: 2px solid #3b82f6;
	outline-offset: 2px;
}

.tvc-youtube-shorts-nav-btn.tvc-youtube-shorts-nav-disabled {
	opacity: 0;
	pointer-events: none;
	visibility: hidden;
}

.tvc-youtube-shorts-nav-prev {
	left: -20px;
}

.tvc-youtube-shorts-nav-next {
	right: -20px;
}

@media (max-width: 768px) {
	.tvc-youtube-shorts-nav-prev {
		left: 4px;
	}
	.tvc-youtube-shorts-nav-next {
		right: 4px;
	}
}

/* ==========================================================================
   4. Video Card Component (9:16 Aspect Ratio)
   ========================================================================== */
.tvc-youtube-shorts-card {
	position: relative;
	background: #000000;
	border-radius: var(--tvc-radius, 12px);
	overflow: hidden;
	box-shadow: var(--tvc-shadow);
	transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.28s cubic-bezier(0.4, 0, 0.2, 1);
	outline: none;
}

.tvc-youtube-shorts-card:hover {
	transform: translateY(-4px);
	box-shadow: var(--tvc-shadow-hover);
}

.tvc-youtube-shorts-card:focus-visible {
	box-shadow: 0 0 0 3px #3b82f6, var(--tvc-shadow-hover);
}

.tvc-youtube-shorts-media-container {
	position: relative;
	width: 100%;
	aspect-ratio: var(--tvc-aspect-ratio, 9 / 16);
	background: #09090b;
	overflow: hidden;
}

/* Fallback for browsers without aspect-ratio support */
@supports not (aspect-ratio: 9 / 16) {
	.tvc-youtube-shorts-media-container {
		height: 0;
		padding-top: 177.77%; /* 16 / 9 = 1.7777 */
	}
}

/* Poster Image */
.tvc-youtube-shorts-poster {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	z-index: 2;
	transition: opacity 0.4s ease;
	pointer-events: none;
}

.tvc-youtube-shorts-card.tvc-youtube-shorts-is-playing .tvc-youtube-shorts-poster {
	opacity: 0;
	pointer-events: none;
}

/* YouTube Iframe Player Mount */
.tvc-youtube-shorts-player-mount {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	z-index: 1;
	background: #000000;
}

.tvc-youtube-shorts-player-mount iframe {
	width: 100%;
	height: 100%;
	border: none;
	display: block;
	pointer-events: none; /* Let container handle touch/click */
}

/* Gradient Overlay for Titles */
.tvc-youtube-shorts-overlay {
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	height: 45%;
	background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.4) 50%, rgba(0, 0, 0, 0) 100%);
	z-index: 3;
	pointer-events: none;
}

/* Play / Pause Overlay Trigger */
.tvc-youtube-shorts-action-btn {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%) scale(0.9);
	z-index: 4;
	width: 54px;
	height: 54px;
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.55);
	color: #ffffff;
	border: 2px solid rgba(255, 255, 255, 0.3);
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	opacity: 0;
	visibility: hidden;
	transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
	padding: 0;
}

.tvc-youtube-shorts-card:hover .tvc-youtube-shorts-action-btn,
.tvc-youtube-shorts-card:focus-within .tvc-youtube-shorts-action-btn {
	opacity: 1;
	visibility: visible;
	transform: translate(-50%, -50%) scale(1);
}

.tvc-youtube-shorts-action-btn:hover {
	background: rgba(255, 0, 0, 0.85);
	border-color: rgba(255, 255, 255, 0.8);
	transform: translate(-50%, -50%) scale(1.1);
}

.tvc-youtube-shorts-card.tvc-youtube-shorts-is-playing .tvc-youtube-shorts-action-btn {
	opacity: 0;
	visibility: hidden;
}

.tvc-youtube-shorts-card.tvc-youtube-shorts-is-playing:hover .tvc-youtube-shorts-action-btn {
	opacity: 1;
	visibility: visible;
}

/* Mute / Unmute Button */
.tvc-youtube-shorts-mute-btn {
	position: absolute;
	top: 12px;
	right: 12px;
	z-index: 4;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.6);
	color: #ffffff;
	border: 1px solid rgba(255, 255, 255, 0.25);
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: all 0.2s ease;
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
	padding: 0;
}

.tvc-youtube-shorts-mute-btn:hover {
	background: rgba(0, 0, 0, 0.85);
	transform: scale(1.1);
}

.tvc-youtube-shorts-mute-btn:focus-visible {
	outline: 2px solid #3b82f6;
}

/* Card Caption / Title Bar */
.tvc-youtube-shorts-caption {
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	padding: 16px 14px 12px 14px;
	z-index: 3;
	pointer-events: none;
}

.tvc-youtube-shorts-title {
	color: #ffffff;
	font-size: 13px;
	font-weight: 600;
	line-height: 1.4;
	margin: 0;
	padding: 0;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	text-overflow: ellipsis;
	text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
	letter-spacing: -0.01em;
}

/* ==========================================================================
   5. Reduced Motion Preferences
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
	.tvc-youtube-shorts-wrapper,
	.tvc-youtube-shorts-carousel-track,
	.tvc-youtube-shorts-card,
	.tvc-youtube-shorts-poster,
	.tvc-youtube-shorts-action-btn,
	.tvc-youtube-shorts-nav-btn {
		transition: none !important;
		scroll-behavior: auto !important;
	}
}
