/**
 * Smart Slideshow Posts — frontend.
 *
 * Variáveis definidas inline por instância:
 *   --ssposts-spv-d / -t / -m    slides visíveis (desktop/tablet/mobile)
 *   --ssposts-ratio              proporção da imagem
 *   --ssposts-title-lines        limite de linhas do título (line-clamp)
 *   --ssposts-excerpt-lines      limite de linhas do resumo (line-clamp)
 *
 * Personalizáveis pelo tema: --ssposts-gap, --ssposts-radius, --ssposts-ui,
 * --ssposts-ui-contrast, --ssposts-overlay, --ssposts-duration.
 */

.ssposts {
	--ssposts-spv: var(--ssposts-spv-d, 1);
	--ssposts-gap: 16px;
	--ssposts-radius: 8px;
	--ssposts-ui: currentcolor;
	--ssposts-ui-contrast: #fff;
	--ssposts-overlay: linear-gradient(to top, rgba(0, 0, 0, 0.82) 0%, rgba(0, 0, 0, 0.45) 55%, rgba(0, 0, 0, 0) 100%);
	--ssposts-duration: 500ms;

	position: relative;
	box-sizing: border-box;
	width: 100%;
}

.ssposts *,
.ssposts *::before,
.ssposts *::after {
	box-sizing: inherit;
}

.ssposts [hidden] {
	display: none !important;
}

/* Tablet */
@media (max-width: 1024px) {

	.ssposts {
		--ssposts-spv: var(--ssposts-spv-t, 1);
	}
}

/* Mobile */
@media (max-width: 767px) {

	.ssposts {
		--ssposts-spv: var(--ssposts-spv-m, 1);
		--ssposts-gap: 12px;
	}
}

/* ---------- Trilho ---------- */

.ssposts__viewport {
	overflow: hidden;
	border-radius: var(--ssposts-radius);
	touch-action: pan-y; /* scroll vertical nativo; o swipe horizontal fica com o JS */
}

.ssposts__track {
	display: flex;
	gap: var(--ssposts-gap);
	margin: 0;
	padding: 0;
	list-style: none;
	transition: transform var(--ssposts-duration) cubic-bezier(0.25, 0.8, 0.25, 1);
	will-change: transform;
}

.ssposts.is-dragging .ssposts__track,
.ssposts.no-transition .ssposts__track {
	transition: none;
}

.ssposts.is-dragging .ssposts__viewport {
	cursor: grabbing;
	user-select: none;
}

.ssposts__slide {
	position: relative;
	display: flex;
	flex-direction: column;
	flex: 0 0 calc((100% - (var(--ssposts-spv) - 1) * var(--ssposts-gap)) / var(--ssposts-spv));
	min-width: 0;
	margin: 0;
	padding: 0;
	overflow: hidden;
	border-radius: var(--ssposts-radius);
	background: #111;

	/* O layout do texto depende da largura do slide, não da tela. */
	container: ssposts-slide / inline-size;
}

/* ---------- Imagem ---------- */

.ssposts__media {
	display: block;
	position: relative;
	aspect-ratio: var(--ssposts-ratio, 16 / 9);

	/* Telas largas: o quadro não passa de 80% da altura da tela. */
	max-height: var(--ssposts-max-h, 80vh);
	overflow: hidden;
	background: #222;
}

.ssposts__media img,
.ssposts__placeholder {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: cover;
	-webkit-user-drag: none;
}

.ssposts__placeholder {
	background: linear-gradient(135deg, #3a3f47 0%, #1d2026 100%);
}

/* ---------- Texto (sobreposto à imagem em telas largas) ---------- */

.ssposts__body {
	position: absolute;
	right: 0;
	bottom: 0;
	left: 0;
	padding: clamp(16px, 3vw, 32px);
	padding-top: clamp(48px, 8vw, 96px);
	color: #fff;
	background: var(--ssposts-overlay);
	pointer-events: none;
}

/* Só categoria/data: faixa escura mais baixa */
.ssposts__body:not(:has(.ssposts__title, .ssposts__excerpt)) {
	padding-top: clamp(32px, 4vw, 48px);
}

.ssposts__body a {
	pointer-events: auto;
	color: inherit;
	text-decoration: none;
}

.ssposts__body a:hover,
.ssposts__body a:focus-visible {
	text-decoration: underline;
}

.ssposts__meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px;
	margin-bottom: 8px;
	font-size: 0.8125rem;
	line-height: 1.4;
	opacity: 0.9;
}

.ssposts__term {
	font-weight: 600;
	letter-spacing: 0.02em;
	text-transform: uppercase;
}

.ssposts__title {
	margin: 0;
	font-size: clamp(1.125rem, 1rem + 1vw, 1.75rem);
	line-height: 1.25;
	color: inherit;
}

.ssposts__excerpt {
	margin: 8px 0 0;
	font-size: 0.9375rem;
	line-height: 1.5;
	opacity: 0.92;
}

/* line-clamp: altura fixa por linhas para não desalinhar o carrossel */
.ssposts--clamp .ssposts__title,
.ssposts--clamp .ssposts__excerpt {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.ssposts--clamp .ssposts__title {
	-webkit-line-clamp: var(--ssposts-title-lines, 2);
	line-clamp: var(--ssposts-title-lines, 2);
}

.ssposts--clamp .ssposts__excerpt {
	-webkit-line-clamp: var(--ssposts-excerpt-lines, 3);
	line-clamp: var(--ssposts-excerpt-lines, 3);
}

/* Vários slides lado a lado no desktop: texto mais compacto */
@media (min-width: 1025px) {

	.ssposts--multi .ssposts__title {
		font-size: 1.125rem;
	}
}

/*
 * Slide estreito (celular, ou vários slides lado a lado numa coluna): texto
 * abaixo da imagem, com altura reservada para manter todos os slides iguais.
 */
@container ssposts-slide (max-width: 560px) {

	.ssposts__body {
		position: static;
		flex: 1;
		padding: 16px;
		background: #111;
	}

	.ssposts__title {
		font-size: 1.0625rem;
	}

	.ssposts__excerpt {
		font-size: 0.875rem;
	}

	.ssposts--clamp .ssposts__title {
		min-height: calc(var(--ssposts-title-lines, 2) * 1.25em);
	}

	.ssposts--clamp .ssposts__excerpt {
		min-height: calc(var(--ssposts-excerpt-lines, 3) * 1.5em);
	}
}

/*
 * Imagem inteira, sem cortes (padrão). Sobra espaço nas laterais ou em
 * cima/embaixo quando a proporção da imagem é diferente da do quadro; esse
 * espaço mostra o fundo do site (ou --ssposts-contain-bg). O texto fica abaixo
 * da imagem para não cobrir nada dela.
 */
.ssposts--contain .ssposts__slide,
.ssposts--contain .ssposts__media {
	background: var(--ssposts-contain-bg, transparent);
}

.ssposts--contain .ssposts__media img {
	object-fit: contain;
}

.ssposts--contain .ssposts__body {
	position: static;
	padding: 10px 2px 0;
	color: inherit;
	text-align: center;
	background: none;
}

.ssposts--contain .ssposts__meta {
	justify-content: center;
}

/* ---------- Setas ---------- */

.ssposts__arrow {
	position: absolute;
	top: calc(var(--ssposts-media-h, 100%) / 2);
	z-index: 2;
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	color: #111;
	background: rgba(255, 255, 255, 0.9);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
	cursor: pointer;
	transform: translateY(-50%);
	transition: background-color 0.2s, opacity 0.2s;
}

.ssposts__arrow:hover {
	background: #fff;
}

.ssposts__arrow svg {
	width: 24px;
	height: 24px;
	fill: currentcolor;
}

.ssposts__arrow--prev {
	left: 12px;
}

.ssposts__arrow--next {
	right: 12px;
}

/* Dispositivos de toque usam swipe */
@media (hover: none) and (pointer: coarse) and (max-width: 1024px) {

	.ssposts__arrow {
		display: none;
	}
}

/* ---------- Bullets e play/pause ---------- */

.ssposts__controls {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 4px;
	min-height: 44px;
	margin-top: 4px;
	color: var(--ssposts-ui);
}

/* Celular: sem bullets/pausa; a imagem fica com o espaço (navega por swipe). */
@media (max-width: 767px) {

	.ssposts__controls {
		display: none;
	}

	/*
	 * Margens laterais definidas no bloco (Estilos → Dimensões) fazem sentido
	 * no desktop, mas no celular espremem o slider. O !important é necessário
	 * porque o WordPress grava essas margens como estilo inline.
	 */
	.wp-block-ssposts-slider {
		margin-right: 0 !important;
		margin-left: 0 !important;
	}

	/* Proporção fixa escolhida para o celular. */
	.ssposts__media {
		aspect-ratio: var(--ssposts-ratio-m, var(--ssposts-ratio, 16 / 9));
	}

	/*
	 * Proporção automática: o quadro acompanha a imagem mais alta, usando toda
	 * a largura da tela (cartazes verticais não ficam espremidos). Limitado a
	 * 75% da altura da tela para o slider caber inteiro.
	 */
	.ssposts--m-auto .ssposts__media {
		display: flex;
		flex: 1 1 auto;
		align-items: center;
		justify-content: center;
		aspect-ratio: auto;
	}

	.ssposts--m-auto .ssposts__media img {
		width: 100%;
		height: auto;
		max-height: 75vh;
	}

	.ssposts--m-auto .ssposts__placeholder {
		height: auto;
		aspect-ratio: 16 / 9;
	}
}

.ssposts__bullets {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
}

.ssposts__bullet,
.ssposts__toggle {
	display: grid;
	place-items: center;
	width: 32px;
	height: 44px;
	margin: 0;
	padding: 0;
	border: 0;
	color: inherit;
	background: none;
	cursor: pointer;
}

.ssposts__bullet::before {
	content: "";
	display: block;
	width: 10px;
	height: 10px;
	border-radius: 999px;
	background: currentcolor;
	opacity: 0.35;
	transition: width 0.3s, opacity 0.3s;
}

.ssposts__bullet:hover::before {
	opacity: 0.65;
}

.ssposts__bullet[aria-current="true"]::before {
	width: 22px;
	opacity: 1;
}

.ssposts__bullet[aria-current="true"] {
	width: 40px;
}

.ssposts__toggle svg {
	width: 20px;
	height: 20px;
	fill: currentcolor;
}

.ssposts__icon-play,
.ssposts.is-paused .ssposts__icon-pause {
	display: none;
}

.ssposts.is-paused .ssposts__icon-play {
	display: block;
}

.ssposts__arrow:focus-visible,
.ssposts__bullet:focus-visible,
.ssposts__toggle:focus-visible,
.ssposts__body a:focus-visible {
	outline: 2px solid currentcolor;
	outline-offset: 2px;
}

.ssposts__arrow:focus-visible {
	outline-color: #fff;
	box-shadow: 0 0 0 4px #111;
}

/* ---------- Acessibilidade de movimento ---------- */

@media (prefers-reduced-motion: reduce) {

	.ssposts__track,
	.ssposts__bullet::before {
		transition: none;
	}
}

.ssposts-empty {
	padding: 12px 16px;
	border: 1px dashed currentcolor;
	opacity: 0.7;
}
