/**
 * Ibtidah YouTube Videos — front-end styles.
 *
 * Design intent: inherit, do not impose. Colours, fonts and spacing are taken
 * from the active theme via `currentColor`, `inherit` and CSS custom
 * properties with conservative fallbacks. There are no fixed brand colours,
 * no font stacks, no theme class-name assumptions, no glassmorphism and no
 * decorative animation — the cards should read as ordinary site content
 * (requirements 10, 50).
 */

/* -------------------------------------------------------------------------
 * Tokens
 * ---------------------------------------------------------------------- */

.ibti-yt-grid,
.ibti-yt-carousel,
.ibti-yt-single,
.ibti-yt-archive {
	--ibti-yt-gap: clamp(1rem, 2.5vw, 2rem);
	--ibti-yt-radius: 4px;
	--ibti-yt-muted: color-mix(in srgb, currentColor 62%, transparent);
	--ibti-yt-line: color-mix(in srgb, currentColor 15%, transparent);
	--ibti-yt-surface: color-mix(in srgb, currentColor 6%, transparent);
}

/* Fallback for browsers without color-mix(). */
@supports not (color: color-mix(in srgb, red 50%, transparent)) {
	.ibti-yt-grid,
	.ibti-yt-carousel,
	.ibti-yt-single,
	.ibti-yt-archive {
		--ibti-yt-muted: inherit;
		--ibti-yt-line: rgba(128, 128, 128, 0.3);
		--ibti-yt-surface: rgba(128, 128, 128, 0.1);
	}
}

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

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

@media (max-width: 1024px) {
	.ibti-yt-grid {
		grid-template-columns: repeat(min(var(--ibti-yt-columns, 3), 2), minmax(0, 1fr));
	}
}

@media (max-width: 640px) {
	.ibti-yt-grid {
		grid-template-columns: minmax(0, 1fr);
	}
}

/* -------------------------------------------------------------------------
 * Card
 * ---------------------------------------------------------------------- */

.ibti-yt-card {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.ibti-yt-card__link {
	display: flex;
	flex-direction: column;
	gap: 0.75em;
	color: inherit;
	text-decoration: none;
}

/* Focus lands on the single anchor that wraps the whole card. */
.ibti-yt-card__link:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 3px;
	border-radius: var(--ibti-yt-radius);
}

.ibti-yt-card__media {
	position: relative;
	display: block;
	overflow: hidden;
	border-radius: var(--ibti-yt-radius);
	background: var(--ibti-yt-surface);
	/* Reserving the box prevents layout shift while images load. */
	aspect-ratio: 16 / 9;
}

.ibti-yt-card__image {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.ibti-yt-card__image--missing {
	display: block;
	width: 100%;
	height: 100%;
}

/* Play indicator */
.ibti-yt-card__play {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	pointer-events: none;
}

.ibti-yt-card__play svg {
	width: 3.25em;
	height: auto;
}

.ibti-yt-card__play-bg {
	fill: #212121;
	fill-opacity: 0.8;
}

.ibti-yt-card__play-arrow {
	fill: #fff;
}

.ibti-yt-card__link:hover .ibti-yt-card__play-bg,
.ibti-yt-card__link:focus-visible .ibti-yt-card__play-bg {
	fill: #f00;
	fill-opacity: 1;
}

.ibti-yt-card__duration {
	position: absolute;
	right: 0.5em;
	bottom: 0.5em;
	padding: 0.15em 0.4em;
	border-radius: 3px;
	background: rgba(0, 0, 0, 0.8);
	color: #fff;
	font-size: 0.8em;
	line-height: 1.4;
	font-variant-numeric: tabular-nums;
}

.ibti-yt-card__title {
	margin: 0;
	font-size: 1.05em;
	line-height: 1.35;
	/* Long YouTube titles must not blow out the column. */
	overflow-wrap: anywhere;
}

.ibti-yt-card__link:hover .ibti-yt-card__title,
.ibti-yt-card__link:focus-visible .ibti-yt-card__title {
	text-decoration: underline;
}

.ibti-yt-card__meta {
	margin: 0.4em 0 0;
	font-size: 0.85em;
	color: var(--ibti-yt-muted);
}

/* -------------------------------------------------------------------------
 * Carousel
 *
 * The track is a real scroll container, not a JavaScript-positioned strip,
 * so touch, trackpad and keyboard scrolling all work before — and without —
 * the script. The buttons and dots are hidden until the script marks the
 * carousel ready and confirms there is actually something to scroll to.
 * ---------------------------------------------------------------------- */

.ibti-yt-carousel {
	/* Cards visible at once, per breakpoint. Set inline by the renderer. */
	--ibti-yt-visible: 3;
	--ibti-yt-visible-md: 2;
	--ibti-yt-per-view: var(--ibti-yt-visible, 3);
	margin: 0 0 var(--ibti-yt-gap);
}

.ibti-yt-carousel__header {
	display: flex;
	align-items: center;
	gap: 1em;
	margin: 0 0 0.85em;
}

.ibti-yt-carousel__title {
	margin: 0;
	/* Sized relative to the theme's own type scale, not a fixed value. */
	font-size: 1.4em;
	line-height: 1.25;
	overflow-wrap: anywhere;
}

/*
 * An auto margin rather than justify-content, so the buttons sit at the end
 * whether or not a heading was configured.
 */
.ibti-yt-carousel__nav {
	display: none;
	flex: 0 0 auto;
	gap: 0.4em;
	margin-inline-start: auto;
}

.ibti-yt-carousel.is-ready .ibti-yt-carousel__nav {
	display: flex;
}

.ibti-yt-carousel__button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.4em;
	height: 2.4em;
	padding: 0;
	border: 1px solid var(--ibti-yt-line);
	border-radius: 50%;
	background: transparent;
	color: inherit;
	font: inherit;
	cursor: pointer;
}

.ibti-yt-carousel__button:hover:not([disabled]) {
	border-color: currentColor;
	background: var(--ibti-yt-surface);
}

.ibti-yt-carousel__button:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.ibti-yt-carousel__button[disabled] {
	opacity: 0.35;
	cursor: default;
}

.ibti-yt-carousel__icon {
	display: block;
	width: 1.1em;
	height: 1.1em;
}

.ibti-yt-carousel__track {
	display: flex;
	gap: var(--ibti-yt-gap);
	margin: 0;
	padding: 0;
	list-style: none;
	overflow-x: auto;
	overflow-y: hidden;
	/* Keeps a horizontal swipe from turning into a page-level back gesture. */
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scroll-behavior: smooth;
	/* The arrows and dots are the visible affordance; the bar is noise. */
	scrollbar-width: none;
	-ms-overflow-style: none;
}

.ibti-yt-carousel__track::-webkit-scrollbar {
	display: none;
}

.ibti-yt-carousel__track:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 4px;
	border-radius: var(--ibti-yt-radius);
}

.ibti-yt-carousel__slide {
	flex: 0 0 calc(
		(100% - var(--ibti-yt-gap) * (var(--ibti-yt-per-view) - 1)) / var(--ibti-yt-per-view)
	);
	min-width: 0;
	scroll-snap-align: start;
}

.ibti-yt-carousel__dots {
	display: none;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0.25em;
	margin: 1em 0 0;
}

.ibti-yt-carousel.is-ready .ibti-yt-carousel__dots {
	display: flex;
}

/* Specific enough to beat the .is-ready rule above. */
.ibti-yt-carousel.is-ready .ibti-yt-carousel__dots[hidden] {
	display: none;
}

/* A 24px target around a small dot, so the control is tappable. */
.ibti-yt-carousel__dot {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
	cursor: pointer;
}

.ibti-yt-carousel__dot::before {
	content: "";
	width: 0.55em;
	height: 0.55em;
	border: 1px solid currentColor;
	border-radius: 50%;
	opacity: 0.55;
}

.ibti-yt-carousel__dot.is-active::before {
	background: currentColor;
	opacity: 1;
}

.ibti-yt-carousel__dot:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 1px;
	border-radius: 50%;
}

/* Match the grid's breakpoints so both layouts step down together. */
@media (max-width: 1024px) {
	.ibti-yt-carousel {
		--ibti-yt-per-view: var(--ibti-yt-visible-md, 2);
	}
}

@media (max-width: 640px) {
	.ibti-yt-carousel {
		--ibti-yt-per-view: 1;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ibti-yt-carousel__track {
		scroll-behavior: auto;
	}
}

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

.ibti-yt-player {
	margin: 0 0 1.5em;
}

.ibti-yt-player__frame {
	display: block;
	width: 100%;
	/* Keeps the 16:9 ratio without overflowing narrow viewports. */
	aspect-ratio: 16 / 9;
	height: auto;
	border: 0;
	border-radius: var(--ibti-yt-radius);
	background: #000;
}

.ibti-yt-player--blocked {
	padding: 1.25em;
	border: 1px solid var(--ibti-yt-line);
	border-radius: var(--ibti-yt-radius);
	background: var(--ibti-yt-surface);
}

.ibti-yt-player__notice {
	margin: 0 0 1em;
}

/* -------------------------------------------------------------------------
 * Single video
 * ---------------------------------------------------------------------- */

.ibti-yt-single__title {
	overflow-wrap: anywhere;
}

.ibti-yt-description {
	/* YouTube descriptions are newline-formatted plain text. */
	overflow-wrap: anywhere;
}

.ibti-yt-description a {
	overflow-wrap: anywhere;
}

.ibti-yt-actions {
	margin: 1.5em 0;
}

/*
 * The button inherits the theme's button styling where those classes exist.
 * These rules are a floor, not an override, so a theme that styles
 * .wp-block-button__link keeps full control.
 */
.ibti-yt-button {
	display: inline-block;
	padding: 0.7em 1.4em;
	border: 1px solid currentColor;
	border-radius: var(--ibti-yt-radius);
	text-decoration: none;
	line-height: 1.2;
}

.ibti-yt-button:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.ibti-yt-meta {
	margin: 1em 0 0;
	font-size: 0.9em;
	color: var(--ibti-yt-muted);
}

.ibti-yt-meta__item + .ibti-yt-meta__item::before {
	content: "·";
	margin: 0 0.5em;
}

/* -------------------------------------------------------------------------
 * Pagination
 * ---------------------------------------------------------------------- */

.ibti-yt-pagination {
	margin: var(--ibti-yt-gap) 0;
}

.ibti-yt-pagination__list {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4em;
	margin: 0;
	padding: 0;
	list-style: none;
	justify-content: center;
}

.ibti-yt-pagination__item .page-numbers {
	display: inline-block;
	padding: 0.45em 0.8em;
	border: 1px solid var(--ibti-yt-line);
	border-radius: var(--ibti-yt-radius);
	text-decoration: none;
	line-height: 1.2;
}

.ibti-yt-pagination__item .page-numbers.current {
	border-color: currentColor;
	font-weight: 600;
}

.ibti-yt-pagination__item .page-numbers:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

/* -------------------------------------------------------------------------
 * Empty state
 * ---------------------------------------------------------------------- */

.ibti-yt-empty {
	margin: 2em 0;
	padding: 1.5em;
	border: 1px dashed var(--ibti-yt-line);
	border-radius: var(--ibti-yt-radius);
	text-align: center;
	color: var(--ibti-yt-muted);
}

/* -------------------------------------------------------------------------
 * Screen reader utility
 *
 * Only defined if the theme has not already provided it.
 * ---------------------------------------------------------------------- */

.ibti-yt-card .screen-reader-text,
.ibti-yt-carousel .screen-reader-text,
.ibti-yt-single .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}
