/* WPST Video Slider — CSS scroll-snap slider สำหรับธีม RetroTube / WP-Script */

.wpstvs {
	--vs-per: var(--vs-per-d, 5);
	--vs-gap: 10px;
	position: relative;
	margin: 0 0 30px;
	clear: both;
}

/* ---------- หัวข้อ ---------- */

.wpstvs-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin: 0 0 12px;
}

.wpstvs-title {
	margin: 0;
	font-size: 18px;
	line-height: 1.3;
	font-weight: 700;
}

.wpstvs-more {
	flex: none;
	font-size: 13px;
	text-decoration: none;
	opacity: .8;
}

.wpstvs-more:hover {
	opacity: 1;
}

/* ---------- ราง ---------- */

.wpstvs-viewport {
	position: relative;
}

.wpstvs-track {
	display: flex;
	flex-wrap: nowrap;
	gap: var(--vs-gap);
	overflow-x: auto;
	overflow-y: hidden;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior-x: contain;
	scrollbar-width: none;          /* Firefox */
	-ms-overflow-style: none;       /* IE/Edge เก่า */
	padding: 0 0 2px;
	margin: 0;
	list-style: none;
}

.wpstvs-track::-webkit-scrollbar {
	display: none;                  /* Chrome / Safari */
}

/*
 * กล่องวิดีโอ — ต้อง !important เพื่อทับ grid ของธีม
 * (.thumb-block ในธีมกำหนด width เป็น % + float ไว้)
 */
.wpstvs .wpstvs-track > article {
	flex: 0 0 220px !important; /* fallback ถ้าเบราว์เซอร์ไม่รองรับ calc() หารด้วยตัวแปร */
	flex: 0 0 calc((100% - (var(--vs-per) - 1) * var(--vs-gap)) / var(--vs-per)) !important;
	width: auto !important;
	max-width: none !important;
	min-width: 0;
	margin: 0 !important;
	padding: 0 !important;
	float: none !important;
	position: relative;
	scroll-snap-align: start;
}

/* รูปในกล่องให้เต็มความกว้างกล่องเสมอ */
.wpstvs .wpstvs-track > article img {
	width: 100%;
	height: auto;
	display: block;
	border-radius: 12px;
}

/* ให้ overlay / ป้ายต่าง ๆ ที่ธีมวางทับรูป โค้งตามไปด้วย ไม่ล้นมุม */
.wpstvs .wpstvs-track > article .post-thumbnail,
.wpstvs .wpstvs-track > article .post-thumbnail-container {
	border-radius: 12px;
	overflow: hidden;
}

/* ---------- เลขอันดับ (rank="on") ---------- */

.wpstvs-rank .wpstvs-track {
	counter-reset: wpstvs-rank;
}

.wpstvs-rank .wpstvs-track > article {
	counter-increment: wpstvs-rank;
}

.wpstvs-rank .wpstvs-track > article::before {
	content: counter(wpstvs-rank);
	position: absolute;
	top: 0;
	left: 0;
	z-index: 4;
	min-width: 26px;
	height: 24px;
	padding: 0 7px;
	display: flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	background: rgba(0, 0, 0, .75);
	color: #fff;
	font-size: 13px;
	font-weight: 700;
	line-height: 1;
	border-radius: 12px 0 10px 0;  /* มุมซ้ายบนโค้งเท่ารูป จะได้ไม่ล้นออกนอกกรอบ */
	pointer-events: none;
}

/* สามอันดับแรกให้เด่นกว่าเพื่อน */
.wpstvs-rank .wpstvs-track > article:nth-child(1)::before { background: #e10600; }
.wpstvs-rank .wpstvs-track > article:nth-child(2)::before { background: #ff6a00; }
.wpstvs-rank .wpstvs-track > article:nth-child(3)::before { background: #ffa800; color: #1a1a1a; }

/* ---------- สไลด์ top view ที่แทรกบนสุดของ <main> ---------- */

.wpstvs-top {
	margin-top: 0;
}

/* ธีมเว้นระยะหัวข้อ .page-header ไว้แล้ว ตัวสไลด์เลยเว้นแค่ด้านล่าง */
.wpstvs-top + .page-header,
.wpstvs-top + .widget {
	margin-top: 6px;
}

/* ---------- ปุ่มลูกศร ---------- */

.wpstvs-btn {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	z-index: 5;
	width: 38px;
	height: 60px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 0;
	border-radius: 4px;
	cursor: pointer;
	background: rgba(0, 0, 0, .65);
	color: #fff;
	font-size: 18px;
	line-height: 1;
	opacity: 0;
	transition: opacity .2s ease, background .2s ease;
}

.wpstvs-viewport:hover .wpstvs-btn {
	opacity: 1;
}

.wpstvs-btn:hover {
	background: rgba(0, 0, 0, .85);
}

.wpstvs-btn:focus-visible {
	opacity: 1;
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.wpstvs-btn[hidden] {
	display: none;
}

.wpstvs-prev { left: 0; }
.wpstvs-next { right: 0; }

/* ---------- responsive ---------- */

@media (max-width: 1200px) {
	.wpstvs { --vs-per: min(var(--vs-per-d, 5), 4); }
}

@media (max-width: 900px) {
	.wpstvs { --vs-per: min(var(--vs-per-d, 5), 3); }
}

@media (max-width: 600px) {
	.wpstvs { --vs-per: var(--vs-per-m, 1.5); }

	.wpstvs-title { font-size: 16px; }

	/* บนมือถือใช้นิ้วปัดพอ ไม่ต้องมีปุ่ม */
	.wpstvs-btn { display: none; }
}

/* เครื่องที่ตั้งค่าลดการเคลื่อนไหว */
@media (prefers-reduced-motion: reduce) {
	.wpstvs-track { scroll-behavior: auto; }
}
