/**
 * Portfolio Gallery — carousel (3D book) layout.
 *
 * Cover frame is always portrait 2:3. Rotation is driven by JS
 * (inline transform) with a CSS transition of 0.7s.
 */

.portfolio-gallery--carousel {
	--portfolio-gallery-book-height: 400px;
	--portfolio-gallery-book-width: calc(var(--portfolio-gallery-book-height) * 2 / 3);
	--portfolio-gallery-book-spine: 15px;
	--portfolio-gallery-book-gap: 1.5rem;
	--portfolio-gallery-book-motion: 0.7s ease;
	--portfolio-gallery-book-info-width: min(320px, 36vw);
	/* Soft silhouette under/around the cover (San Rocco-like). */
	--portfolio-gallery-book-shadow:
		0 1px 2px rgba(0, 0, 0, 0.08),
		0 6px 14px -4px rgba(0, 0, 0, 0.22),
		0 10px 20px -8px rgba(0, 0, 0, 0.14);
	--portfolio-gallery-book-shadow-hover:
		0 2px 3px rgba(0, 0, 0, 0.1),
		0 8px 18px -4px rgba(0, 0, 0, 0.26),
		0 14px 28px -10px rgba(0, 0, 0, 0.16);
	background-color: var(--portfolio-gallery-bg, transparent);
}

.portfolio-gallery--carousel.portfolio-gallery--size-small {
	--portfolio-gallery-book-height: 320px;
}

.portfolio-gallery--carousel.portfolio-gallery--size-medium {
	--portfolio-gallery-book-height: 400px;
}

.portfolio-gallery--carousel.portfolio-gallery--size-large {
	--portfolio-gallery-book-height: 520px;
}

.portfolio-gallery--carousel.portfolio-gallery--size-full {
	/* Full-bleed row: tall covers relative to viewport, not the old ~medium cap. */
	--portfolio-gallery-book-height: clamp(480px, 68vh, 760px);
	--portfolio-gallery-book-info-width: min(360px, 32vw);
}

.portfolio-gallery--carousel.portfolio-gallery--size-custom {
	--portfolio-gallery-book-height: clamp(
		280px,
		calc(var(--portfolio-gallery-item-max) * 0.75),
		720px
	);
}

.portfolio-gallery--carousel .portfolio-gallery__track {
	display: flex;
	flex-wrap: nowrap;
	align-items: flex-end;
	justify-content: center;
	justify-content: safe center;
	gap: var(--portfolio-gallery-book-gap);
	width: 100%;
	overflow-x: auto;
	overflow-y: visible;
	padding: 1.75rem 0.75rem 2rem;
	margin: 0;
	background: transparent;
	-webkit-overflow-scrolling: touch;
	scrollbar-width: thin;
	cursor: grab;
	box-sizing: border-box;
}

.portfolio-gallery--carousel .portfolio-gallery__track:active {
	cursor: grabbing;
}

.portfolio-gallery--carousel .portfolio-gallery__track:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 4px;
}

.portfolio-gallery--carousel .portfolio-gallery__book {
	position: relative;
	flex: 0 0 auto;
	width: var(--portfolio-gallery-book-width);
	height: var(--portfolio-gallery-book-height);
	aspect-ratio: 2 / 3;
	margin: 0;
	perspective: 1600px;
	perspective-origin: left center;
	transition: width var(--portfolio-gallery-book-motion);
}

.portfolio-gallery--carousel .portfolio-gallery__book-scene {
	position: relative;
	width: 100%;
	height: 100%;
	transform-style: preserve-3d;
}

.portfolio-gallery--carousel .portfolio-gallery__book-content {
	position: absolute;
	top: 0;
	left: 0;
	width: var(--portfolio-gallery-book-width);
	height: 100%;
	transform-style: preserve-3d;
	transform-origin: left center;
	/* Inline transform from JS; this is the fallback / initial. */
	transform: rotateY(0deg);
	transition: transform 0.7s ease, box-shadow 0.7s ease;
	box-shadow: var(--portfolio-gallery-book-shadow);
	background: #fff;
	z-index: 1;
	will-change: transform;
}

.portfolio-gallery--carousel .portfolio-gallery__book-cover {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center center;
	backface-visibility: hidden;
	user-select: none;
	-webkit-user-drag: none;
	background: #fff;
	/* Grayscale on the image, not the 3D node (filter flattens transform). */
	filter: grayscale(1);
	transition: filter 0.2s ease;
}

.portfolio-gallery--carousel .portfolio-gallery__book.is-hot .portfolio-gallery__book-cover,
.portfolio-gallery--carousel .portfolio-gallery__book.is-open .portfolio-gallery__book-cover {
	filter: none;
}

.portfolio-gallery--carousel .portfolio-gallery__book-cover--placeholder {
	background: var(--portfolio-gallery-placeholder, #d0d0d0);
}

.portfolio-gallery--carousel .portfolio-gallery__book-frase {
	position: absolute;
	inset: 0;
	z-index: 1;
	overflow: hidden;
	pointer-events: none;
	backface-visibility: hidden;
	opacity: 0;
	background: linear-gradient(
		to bottom,
		transparent 28%,
		rgba(0, 0, 0, 0.2) 55%,
		rgba(0, 0, 0, 0.5) 100%
	);
	transition: opacity 0.35s ease;
}

.portfolio-gallery--carousel .portfolio-gallery__book.is-hot .portfolio-gallery__book-frase,
.portfolio-gallery--carousel .portfolio-gallery__book.is-open .portfolio-gallery__book-frase {
	opacity: 1;
}

.portfolio-gallery--carousel .portfolio-gallery__book-frase-block {
	position: absolute;
	left: 7%;
	right: 7%;
	top: 50%;
	transform: translateY(-50%);
	margin: 0;
	padding: 0.15em 0 0.2em;
	width: auto;
	max-width: none;
	box-sizing: border-box;
	color: #fff;
	text-align: left;
	text-shadow:
		0 0 1px rgba(0, 0, 0, 0.83),
		0 1px 3px rgba(0, 0, 0, 0.9),
		0 4px 16px rgba(0, 0, 0, 0.75),
		0 10px 32px rgba(0, 0, 0, 0.6);
}

.portfolio-gallery--carousel .portfolio-gallery__book-frase-title {
	margin: 0 0 0.5em;
	padding: 0;
	font-family: var(
		--wp--preset--font-family--heading,
		var(--wp--preset--font-family--headings, Georgia, "Times New Roman", serif)
	);
	font-size: calc(var(--portfolio-gallery-frase-size, 1.5rem) * 1.73);
	font-weight: 700;
	line-height: 1.08;
	letter-spacing: 0.005em;
	text-wrap: pretty;
}

.portfolio-gallery--carousel .portfolio-gallery__book-frase-text {
	margin: 0;
	padding: 0;
	font-family: var(
		--wp--preset--font-family--body,
		var(--wp--preset--font-family--text, system-ui, sans-serif)
	);
	font-size: calc(var(--portfolio-gallery-frase-size, 1.5rem) * 1.08);
	font-weight: 400;
	line-height: 1.4;
	letter-spacing: 0.01em;
	text-wrap: pretty;
}

.portfolio-gallery--carousel .portfolio-gallery__book-spine {
	position: absolute;
	top: 0;
	left: 0;
	width: var(--portfolio-gallery-book-spine);
	height: 100%;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	align-items: center;
	padding: 0.75rem 0;
	box-sizing: border-box;
	background: #fff;
	color: #111;
	box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.06);
	transform: rotateY(-90deg) translateZ(0.5px);
	transform-origin: left center;
	transform-style: preserve-3d;
	backface-visibility: hidden;
}

.portfolio-gallery--carousel .portfolio-gallery__spine-architect,
.portfolio-gallery--carousel .portfolio-gallery__spine-title {
	display: block;
	writing-mode: vertical-rl;
	text-orientation: mixed;
	font-size: 0.62rem;
	line-height: 1.2;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-height: 45%;
}

.portfolio-gallery--carousel .portfolio-gallery__spine-architect {
	order: 1;
}

.portfolio-gallery--carousel .portfolio-gallery__spine-title {
	order: 2;
	font-weight: 500;
}

.portfolio-gallery--carousel .portfolio-gallery__book-info {
	position: absolute;
	top: 0;
	left: calc(var(--portfolio-gallery-book-spine) + 3rem);
	z-index: 2;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: stretch;
	width: var(--portfolio-gallery-book-info-width);
	height: 100%;
	padding: 0.5rem 0.35rem 0.5rem 1rem;
	box-sizing: border-box;
	background: transparent;
	color: inherit;
	box-shadow: none;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transform: translateX(0.5rem);
	transition:
		opacity 0.7s ease,
		visibility 0.7s ease,
		transform 0.7s ease;
}

.portfolio-gallery--carousel .portfolio-gallery__book-info[hidden] {
	display: flex !important;
}

.portfolio-gallery--carousel .portfolio-gallery__book-info-body {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 0.75rem;
	width: 100%;
	max-height: 100%;
	padding-top: 2rem;
	box-sizing: border-box;
}

.portfolio-gallery--carousel .portfolio-gallery__book-close {
	position: absolute;
	top: 0;
	right: 0;
	appearance: none;
	margin: 0;
	padding: 0;
	width: 2rem;
	height: 2rem;
	border: 0;
	border-radius: 0;
	background: transparent !important;
	background-color: transparent !important;
	box-shadow: none !important;
	color: inherit !important;
	font-size: 1.5rem;
	line-height: 1;
	cursor: pointer;
}

.portfolio-gallery--carousel .portfolio-gallery__book-close:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.portfolio-gallery--carousel .portfolio-gallery__book-heading {
	margin: 0;
	font-size: clamp(0.8125rem, 0.75rem + 0.2vw, 0.9375rem);
	line-height: 1.35;
	font-weight: 300;
	letter-spacing: 0.01em;
	text-wrap: pretty;
}

.portfolio-gallery--carousel .portfolio-gallery__book-heading-title {
	font-weight: 400;
}

.portfolio-gallery--carousel .portfolio-gallery__book-heading-architect {
	font-weight: 300;
	opacity: 0.85;
}

.portfolio-gallery--carousel .portfolio-gallery__book-excerpt {
	margin: 0;
	flex: 0 1 auto;
	max-height: min(36vh, 12.5rem);
	font-size: clamp(0.75rem, 0.7rem + 0.15vw, 0.875rem);
	line-height: 1.5;
	font-weight: 300;
	overflow: auto;
	text-wrap: pretty;
}

.portfolio-gallery--carousel .portfolio-gallery__book-more {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	align-self: center;
	margin: 0.15rem 0 0;
	padding: 0.65rem 1rem;
	border-radius: 999px;
	background: #1a1a1a;
	color: #fff;
	text-decoration: none;
	font-size: 0.8125rem;
	font-weight: 500;
	letter-spacing: 0.03em;
	text-align: center;
}

.portfolio-gallery--carousel .portfolio-gallery__book-more:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 3px;
}

.portfolio-gallery--carousel .portfolio-gallery__book-hit {
	position: absolute;
	inset: 0;
	z-index: 3;
	appearance: none;
	margin: 0;
	padding: 0;
	border: 0 !important;
	border-radius: 0;
	background: transparent !important;
	background-color: transparent !important;
	box-shadow: none !important;
	color: transparent !important;
	font-size: 0;
	line-height: 0;
	cursor: pointer;
}

.portfolio-gallery--carousel .portfolio-gallery__book-hit:hover,
.portfolio-gallery--carousel .portfolio-gallery__book-hit:focus,
.portfolio-gallery--carousel .portfolio-gallery__book-hit:active {
	background: transparent !important;
	background-color: transparent !important;
	box-shadow: none !important;
	color: transparent !important;
	outline: none;
}

.portfolio-gallery--carousel .portfolio-gallery__book-hit:focus-visible {
	outline: 2px solid #111;
	outline-offset: 3px;
}

.portfolio-gallery--carousel .screen-reader-text {
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	width: 1px;
	word-wrap: normal !important;
}

.portfolio-gallery--carousel .portfolio-gallery__book.is-open .portfolio-gallery__book-hit {
	pointer-events: none;
}

.portfolio-gallery--carousel .portfolio-gallery__book.is-hot:not(.is-open) .portfolio-gallery__book-content,
.portfolio-gallery--carousel .portfolio-gallery__book.is-open .portfolio-gallery__book-content {
	box-shadow: var(--portfolio-gallery-book-shadow-hover);
}

.portfolio-gallery--carousel .portfolio-gallery__book.is-open {
	width: calc(
		var(--portfolio-gallery-book-spine) + 3rem + var(--portfolio-gallery-book-info-width)
	);
	height: var(--portfolio-gallery-book-height);
	aspect-ratio: auto;
}

.portfolio-gallery--carousel .portfolio-gallery__book.is-open .portfolio-gallery__book-info {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transform: translateX(0);
}

@media (hover: none), (pointer: coarse) {
	.portfolio-gallery--carousel .portfolio-gallery__book.is-open {
		width: min(
			calc(var(--portfolio-gallery-book-spine) + 3rem + 240px),
			92vw
		);
	}

	.portfolio-gallery--carousel .portfolio-gallery__book.is-open .portfolio-gallery__book-info {
		width: min(240px, calc(92vw - var(--portfolio-gallery-book-spine) - 3.25rem));
	}
}

@media (max-width: 600px) {
	.portfolio-gallery.portfolio-gallery--carousel {
		--portfolio-gallery-book-height: min(340px, 52vh);
		--portfolio-gallery-gap: 1rem;
	}

	.portfolio-gallery.portfolio-gallery--carousel.portfolio-gallery--size-full {
		--portfolio-gallery-book-height: min(420px, 62vh);
	}

	.portfolio-gallery--carousel .portfolio-gallery__track {
		padding: 1.25rem 0.35rem 1.5rem;
		gap: 1rem;
	}
}
