/* Twirola front end. Structure and sensible looks only: colours, type, gaps and
 * radii are CSS variables, so the Elementor widget (or a theme) can restyle them. */

.twirola {
	--twirola-gap: 16px;
	--twirola-radius: 14px;
	--twirola-ratio: 1 / 1;
	--twirola-meta-color: #fff;
	--twirola-play-size: 54px;
	--twirola-play-color: #fff;
	--twirola-play-bg: rgba(0, 0, 0, .45);
	--twirola-arrow-size: 44px;
	--twirola-arrow-color: #111;
	--twirola-arrow-bg: #fff;
	position: relative;
	box-sizing: border-box;
}
.twirola *, .twirola *::before, .twirola *::after { box-sizing: border-box; }

/* ---------- columns ----------
 * Three inputs (desktop, tablet, mobile) feed one working variable, --twirola-cols.
 * Presets set the inputs by class; a saved design or a shortcode sets them inline;
 * the Elementor widget may set --twirola-cols itself, which wins over all of this. */
.twirola { --twirola-cols-d: 3; --twirola-cols-t: 3; --twirola-cols-m: 2; --twirola-cols: var(--twirola-cols-d); }
.twirola--p-grid8   { --twirola-cols-d: 4; --twirola-cols-t: 4; }
.twirola--p-grid10  { --twirola-cols-d: 5; --twirola-cols-t: 5; }
.twirola--p-grid12  { --twirola-cols-d: 6; --twirola-cols-t: 4; }
.twirola--p-slider  { --twirola-cols-t: 2.5; --twirola-cols-m: 1.35; }
.twirola--p-slider4 { --twirola-cols-d: 4; --twirola-cols-m: 1.35; }
.twirola--slider { --twirola-ratio: 9 / 16; }
@media (max-width: 1024px) {
	.twirola { --twirola-cols: var(--twirola-cols-t); }
}
@media (max-width: 767px) {
	.twirola { --twirola-cols: var(--twirola-cols-m); }
}

.twirola--r-1-1  { --twirola-ratio: 1 / 1; }
.twirola--r-9-16 { --twirola-ratio: 9 / 16; }
.twirola--r-3-4  { --twirola-ratio: 3 / 4; }
.twirola--r-4-5  { --twirola-ratio: 4 / 5; }

.twirola--grid .twirola__track {
	display: grid;
	grid-template-columns: repeat(var(--twirola-cols), minmax(0, 1fr));
	gap: var(--twirola-gap);
}

.twirola--slider .twirola__track {
	display: flex;
	gap: var(--twirola-gap);
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scroll-behavior: auto; /* position corrections of the endless slider must be instant, whatever the theme sets */
	scrollbar-width: none;
	-webkit-overflow-scrolling: touch;
	outline-offset: 4px;
}
.twirola--slider .twirola__track::-webkit-scrollbar { display: none; }
.twirola--slider .twirola__item {
	flex: 0 0 calc((100% - (var(--twirola-cols) - 1) * var(--twirola-gap)) / var(--twirola-cols));
	scroll-snap-align: start;
}

/* ---------- tile ---------- */
.twirola__item { position: relative; min-width: 0; }

.twirola .twirola__media {
	position: relative;
	display: block;
	width: 100%;
	aspect-ratio: var(--twirola-ratio);
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: var(--twirola-radius);
	overflow: hidden;
	background: #16161a;
	color: var(--twirola-meta-color);
	font: inherit;
	line-height: 1.35;
	text-align: start;
	text-decoration: none;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
	isolation: isolate;
}
.twirola .twirola__media:focus { outline: none; }
.twirola .twirola__media:focus-visible,
.twirola .twirola__arrow:focus-visible {
	outline: 3px solid #37b8bb;
	outline-offset: 3px;
}

/* The image carries the tile's shape itself (its own aspect-ratio plus object-fit), instead of
 * stretching to "100% of the button". Some browsers do not give an image inside a <button>
 * a height to take a percentage of, and then the picture keeps its own proportions and
 * leaves a dark band under it. */
.twirola .twirola__cover {
	position: relative;
	display: block;
	width: 100%;
	height: auto;
	max-width: none;
	aspect-ratio: var(--twirola-ratio);
	object-fit: cover;
	transition: transform .35s ease;
}
.twirola .twirola__cover--empty { background: linear-gradient(135deg, #25f4ee22, #fe2c5522), #16161a; }
.twirola__media:hover .twirola__cover { transform: scale(1.04); }

.twirola__play {
	position: absolute;
	top: 50%;
	left: 50%;
	display: grid;
	place-items: center;
	width: var(--twirola-play-size);
	height: var(--twirola-play-size);
	border-radius: 50%;
	background: var(--twirola-play-bg);
	color: var(--twirola-play-color);
	transform: translate(-50%, -50%);
	-webkit-backdrop-filter: blur(6px);
	backdrop-filter: blur(6px);
	transition: transform .2s ease;
	pointer-events: none;
}
.twirola__play svg { width: 46%; height: 46%; margin-left: 6%; }
.twirola__media:hover .twirola__play { transform: translate(-50%, -50%) scale(1.08); }

.twirola .twirola__media--live { cursor: default; }
.twirola__media--live iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---------- author, likes, caption ---------- */
.twirola__info {
	position: absolute;
	inset-inline: 0;
	bottom: 0;
	display: flex;
	flex-direction: column;
	gap: 4px;
	padding: 34px 12px 10px;
	background: linear-gradient(to top, rgba(0, 0, 0, .78), rgba(0, 0, 0, 0));
	color: var(--twirola-meta-color);
	font-size: 13px;
	pointer-events: none;
}
.twirola__meta {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	min-width: 0;
}
.twirola__author {
	direction: ltr; /* handles are Latin: cut the end, not the start, when space is short */
	min-width: 0;
	overflow: hidden;
	font-weight: 600;
	text-overflow: ellipsis;
	white-space: nowrap;
	color: inherit;
	text-decoration: none;
}
.twirola__stats { display: inline-flex; flex: none; align-items: center; gap: 10px; margin-inline-start: auto; }
.twirola__stat { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; direction: ltr; }
.twirola__stat svg { flex: none; }
.twirola__caption {
	display: -webkit-box;
	overflow: hidden;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	font-size: .93em;
	opacity: .95;
}

.twirola__info--below {
	position: static;
	padding: 8px 2px 0;
	background: none;
	--twirola-meta-color: inherit;
	color: inherit;
	pointer-events: auto;
}
.twirola__info--below .twirola__author:hover { text-decoration: underline; }

/* ---------- playing inside the tile ---------- */
.twirola__item.is-playing > iframe {
	position: absolute;
	top: 0;
	inset-inline: 0;
	z-index: 2;
	width: 100%;
	aspect-ratio: var(--twirola-ratio);
	border: 0;
	border-radius: var(--twirola-radius);
	background: #000;
}

/* ---------- slider arrows ---------- */
.twirola .twirola__arrow {
	position: absolute;
	top: 50%;
	z-index: 2;
	display: grid;
	place-items: center;
	width: var(--twirola-arrow-size);
	height: var(--twirola-arrow-size);
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: var(--twirola-arrow-radius, 50%);
	background: var(--twirola-arrow-bg);
	color: var(--twirola-arrow-color);
	box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
	transform: translateY(-50%);
	cursor: pointer;
	transition: opacity .2s ease, background-color .15s ease, color .15s ease;
}
/* the theme's own button colours (hover, focus, pressed) never reach the arrows */
.twirola .twirola__arrow:hover,
.twirola .twirola__arrow:focus,
.twirola .twirola__arrow:active {
	border: 0;
	background: var(--twirola-arrow-bg-hover, var(--twirola-arrow-bg));
	color: var(--twirola-arrow-color-hover, var(--twirola-arrow-color));
	box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
	text-decoration: none;
}
@media (hover: none) {
	.twirola .twirola__arrow:hover,
	.twirola .twirola__arrow:focus { background: var(--twirola-arrow-bg); color: var(--twirola-arrow-color); }
}
.twirola .twirola__arrow:focus { outline: none; }
.twirola__arrow--prev { inset-inline-start: calc(var(--twirola-arrow-size) / -2); }
.twirola__arrow--next { inset-inline-end: calc(var(--twirola-arrow-size) / -2); }
/* The chevron is drawn pointing right. data-dir is the page direction, printed by the plugin,
 * so the arrows never depend on what surrounds the slider. */
.twirola__arrow--prev svg { transform: scaleX(-1); }
.twirola[data-dir="rtl"] .twirola__arrow--prev svg { transform: none; }
.twirola[data-dir="rtl"] .twirola__arrow--next svg { transform: scaleX(-1); }
/* pages cached before data-dir existed */
[dir="rtl"] .twirola:not([data-dir]) .twirola__arrow--prev svg { transform: none; }
[dir="rtl"] .twirola:not([data-dir]) .twirola__arrow--next svg { transform: scaleX(-1); }
.twirola .twirola__arrow[disabled] { opacity: 0; pointer-events: none; }
@media (max-width: 767px) {
	.twirola__arrow--prev { inset-inline-start: 6px; }
	.twirola__arrow--next { inset-inline-end: 6px; }
}

/* shape */
.twirola--nav-rounded { --twirola-arrow-radius: 12px; }
.twirola--nav-square { --twirola-arrow-radius: 0; }

/* above or below the videos: the two arrows stand outside the slider, in a row of their own */
.twirola--nav-top { padding-top: calc(var(--twirola-arrow-size) + 14px); }
.twirola--nav-bottom { padding-bottom: calc(var(--twirola-arrow-size) + 14px); }
.twirola--nav-top .twirola__arrow { top: 0; transform: none; }
.twirola--nav-bottom .twirola__arrow { top: auto; bottom: 0; transform: none; }
:is(.twirola--nav-top, .twirola--nav-bottom) .twirola__arrow--prev { inset-inline: 0 auto; }
:is(.twirola--nav-top, .twirola--nav-bottom) .twirola__arrow--next { inset-inline: auto 0; }
.twirola--nav-a-start .twirola__arrow--next { inset-inline: calc(var(--twirola-arrow-size) + 8px) auto; }
.twirola--nav-a-end .twirola__arrow--prev { inset-inline: auto calc(var(--twirola-arrow-size) + 8px); }
.twirola--nav-a-center .twirola__arrow--prev { inset-inline: calc(50% - var(--twirola-arrow-size) - 4px) auto; }
.twirola--nav-a-center .twirola__arrow--next { inset-inline: calc(50% + 4px) auto; }
/* in a row of their own an arrow that has nowhere to go stays in place, dimmed */
:is(.twirola--nav-top, .twirola--nav-bottom) .twirola__arrow[disabled] { opacity: .35; }

/* manual: height in % of the slider, distance in px from its edge (negative = outside) */
.twirola--nav-custom .twirola__arrow { top: var(--twirola-arrow-y, 50%); }
.twirola--nav-custom .twirola__arrow--prev { inset-inline-start: var(--twirola-arrow-x, 0px); }
.twirola--nav-custom .twirola__arrow--next { inset-inline-end: var(--twirola-arrow-x, 0px); }
@media (max-width: 767px) {
	.twirola--nav-custom .twirola__arrow--prev { inset-inline-start: max(var(--twirola-arrow-x, 0px), 6px); }
	.twirola--nav-custom .twirola__arrow--next { inset-inline-end: max(var(--twirola-arrow-x, 0px), 6px); }
}

/* ---------- slider on a phone: which side the next video peeks from ----------
 * By nature the next video comes from the left on a right-to-left page and from the right
 * on a left-to-right page. "m-flip" turns the slider the other way round on phones only:
 * the first video sits on the opposite side and the next one peeks from the other edge.
 * Texts inside each tile keep the page direction. "m-center" keeps the direction and puts
 * the current video in the middle, with a peek on both sides. */
@media (max-width: 767px) {
	.twirola--slider.twirola--m-flip[data-dir="rtl"] { direction: ltr; }
	.twirola--slider.twirola--m-flip[data-dir="ltr"] { direction: rtl; }
	.twirola--m-flip[data-dir="rtl"] .twirola__item { direction: rtl; }
	.twirola--m-flip[data-dir="ltr"] .twirola__item { direction: ltr; }
	.twirola--m-flip[data-dir="rtl"] .twirola__arrow--prev svg { transform: scaleX(-1); }
	.twirola--m-flip[data-dir="rtl"] .twirola__arrow--next svg { transform: none; }
	.twirola--m-flip[data-dir="ltr"] .twirola__arrow--prev svg { transform: none; }
	.twirola--m-flip[data-dir="ltr"] .twirola__arrow--next svg { transform: scaleX(-1); }

	.twirola--slider.twirola--m-center .twirola__item { scroll-snap-align: center; }
	/* empty room before the first and after the last video, so they too can stand in the middle */
	.twirola--slider.twirola--m-center .twirola__track::before,
	.twirola--slider.twirola--m-center .twirola__track::after {
		content: "";
		flex: 0 0 calc((100% - (100% - (var(--twirola-cols) - 1) * var(--twirola-gap)) / var(--twirola-cols)) / 2 - var(--twirola-gap));
	}
}


/* ---------- stopping a video that plays in its tile ---------- */
.twirola .twirola__stop {
	position: absolute;
	top: 8px;
	inset-inline-end: 8px;
	z-index: 3;
	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(14, 14, 16, .78);
	color: #fff;
	cursor: pointer;
}
.twirola .twirola__stop svg { width: 20px; height: 20px; }
.twirola .twirola__stop:focus-visible { outline: 3px solid #37b8bb; outline-offset: 2px; }

/* ---------- grid paging ---------- */
.twirola .twirola__item.is-off { display: none; }
.twirola__pager { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: calc(var(--twirola-gap) + 6px); }
.twirola .twirola__pager button {
	min-width: 40px;
	min-height: 40px;
	padding: 8px 18px;
	border: 1px solid rgba(127, 127, 127, .35);
	border-radius: 999px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 14px;
	line-height: 1.2;
	cursor: pointer;
}
.twirola .twirola__pager button.is-on { border-color: currentColor; font-weight: 600; }
.twirola .twirola__pager button:focus-visible { outline: 3px solid #37b8bb; outline-offset: 2px; }

/* ---------- phones: the grid becomes a swipe view ----------
 * Rows stay rows; the grid flows sideways, and the script orders each "page" row by row.
 * The next column peeks in, from the side picked in the design (or from both sides). */
.twirola__dots { display: none; }
@media (max-width: 767px) {
	.twirola--grid.twirola--cv .twirola__track {
		grid-template-columns: none;
		grid-template-rows: repeat(var(--twirola-rows-m, 2), auto);
		grid-auto-flow: column;
		grid-auto-columns: calc((100% - var(--twirola-cols) * var(--twirola-gap)) / (var(--twirola-cols) + .35));
		overflow-x: auto;
		overscroll-behavior-x: contain;
		scroll-snap-type: x mandatory;
		scrollbar-width: none;
		-webkit-overflow-scrolling: touch;
	}
	.twirola--grid.twirola--cv .twirola__track::-webkit-scrollbar { display: none; }
	.twirola--grid.twirola--cv .twirola__item { scroll-snap-align: start; }

	.twirola--grid.twirola--m-flip[data-dir="rtl"] .twirola__track { direction: ltr; }
	.twirola--grid.twirola--m-flip[data-dir="ltr"] .twirola__track { direction: rtl; }
	.twirola--grid.twirola--m-flip[data-dir="rtl"] .twirola__item { direction: rtl; }
	.twirola--grid.twirola--m-flip[data-dir="ltr"] .twirola__item { direction: ltr; }

	.twirola__dots { display: flex; justify-content: center; gap: 6px; margin-top: 12px; }
	.twirola__dots i { width: 7px; height: 7px; border-radius: 999px; background: rgba(127, 127, 127, .35); transition: width .2s, background-color .2s; }
	.twirola__dots i.is-on { width: 20px; background: #37b8bb; }
}

/* ---------- lightbox ---------- */
.twirola-lightbox {
	width: 100vw;
	max-width: 100vw;
	height: 100dvh;
	max-height: 100dvh;
	margin: 0;
	padding: 0;
	border: 0;
	background: rgba(0, 0, 0, .88);
	overflow: hidden;
}
.twirola-lightbox::backdrop { background: transparent; }
.twirola-lightbox__stage {
	display: grid;
	place-items: center;
	width: 100%;
	height: 100%;
	padding: 16px;
}
.twirola-lightbox__frame {
	position: relative;
	width: min(92vw, calc((100dvh - 32px) * 9 / 16), 480px);
	aspect-ratio: 9 / 16;
	max-height: calc(100dvh - 32px);
	border-radius: 16px;
	overflow: hidden;
	background: #000;
}
.twirola-lightbox__frame::before,
.twirola__media--live::before {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 34px;
	height: 34px;
	margin: -17px 0 0 -17px;
	border: 3px solid rgba(255, 255, 255, .25);
	border-top-color: #fff;
	border-radius: 50%;
	animation: twirola-spin .8s linear infinite;
}
@keyframes twirola-spin { to { transform: rotate(360deg); } }
.twirola-lightbox__frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.twirola-lightbox button {
	position: absolute;
	z-index: 2;
	display: grid;
	place-items: center;
	width: 46px;
	height: 46px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, .16);
	color: #fff;
	cursor: pointer;
}
.twirola-lightbox button:hover { background: rgba(255, 255, 255, .28); }
.twirola-lightbox button:focus { outline: none; }
.twirola-lightbox button:focus-visible { outline: 3px solid #37b8bb; outline-offset: 2px; }
.twirola-lightbox__close { top: 14px; inset-inline-end: 14px; }
.twirola-lightbox__prev, .twirola-lightbox__next { top: 50%; transform: translateY(-50%); }
.twirola-lightbox__prev { inset-inline-start: 14px; }
.twirola-lightbox__next { inset-inline-end: 14px; }
.twirola-lightbox__prev svg { transform: scaleX(-1); }
[dir="rtl"] .twirola-lightbox__prev svg { transform: none; }
[dir="rtl"] .twirola-lightbox__next svg { transform: scaleX(-1); }
.twirola-lightbox button[hidden] { display: none; }
@media (max-width: 600px) {
	.twirola-lightbox__prev, .twirola-lightbox__next { top: auto; bottom: 14px; transform: none; }
}

.twirola-empty {
	padding: 18px;
	border: 1px dashed currentColor;
	border-radius: 12px;
	text-align: center;
	opacity: .75;
}

@media (prefers-reduced-motion: reduce) {
	.twirola__cover, .twirola__play, .twirola__arrow { transition: none; }
	.twirola-lightbox__frame::before, .twirola__media--live::before { animation-duration: 2.4s; }
	.twirola__media:hover .twirola__cover { transform: none; }
}
