/**
 * 3D-карусель портфолио — «веер» из центра.
 *
 * Карточки расположены горизонтально от центра, каждая со своим
 * translateX + translateZ + rotateY + scale, рассчитываемыми через JS
 * на основе относительного смещения от активного слайда.
 * Переключение закольцовано (infinite loop).
 */

.gallery-3d {
	position: relative;
	padding: clamp(3rem, 8vw, 6rem) 0;
	background: radial-gradient(ellipse at top, #181820 0%, #0c0c0e 70%);
	color: rgb(var(--color-primary));
	overflow: hidden;
}

.gallery-3d__head {
	text-align: center;
	margin-bottom: clamp(2rem, 5vw, 3.25rem);
}

.gallery-3d__title {
	font-family: var(--font-serif);
	font-weight: 300;
	font-size: clamp(1.75rem, 4vw, 2.75rem);
	line-height: 1.15;
	letter-spacing: -0.01em;
	margin: 0 0 0.75rem;
}

.gallery-3d__subtitle {
	font-size: 0.9375rem;
	color: rgb(var(--color-primary) / 0.7);
	margin: 0 auto;
	max-width: 56ch;
}

/* ---- КАРУСЕЛЬ ---- */
.gallery-3d__carousel {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.75rem;
	padding: 0 clamp(0.5rem, 2vw, 2rem);

	/* Управляющие CSS-переменные (переопределяются на mobile/tablet).
	 * Карточки вертикальные (9:16). */
	--card-w: 300px;
	--card-h: 500px;
	--stage-h: 640px;
	--perspective: 1800px;
	/* Шаг по X между соседями */
	--step-x: 210px;
	/* Уход в глубину */
	--step-z: 140px;
	/* Поворот боковых вокруг Y */
	--step-rot: 22deg;
	/* Уменьшение боковых */
	--step-scale: 0.1;
	/* Увеличение активной карточки (+20%) */
	--active-scale: 1.2;
}

.gallery-3d__stage {
	flex: 1;
	position: relative;
	height: var(--stage-h);
	perspective: var(--perspective);
	perspective-origin: 50% 50%;
	max-width: 1200px;
	user-select: none;
	cursor: grab;
	touch-action: pan-y;
}
.gallery-3d__stage.is-dragging { cursor: grabbing; }

.gallery-3d__ring {
	list-style: none;
	margin: 0;
	padding: 0;
	position: absolute;
	inset: 0;
	transform-style: preserve-3d;
}

.gallery-3d__slide {
	position: absolute;
	top: 50%;
	left: 50%;
	width: var(--card-w);
	height: var(--card-h);
	margin-left: calc(var(--card-w) / -2);
	margin-top: calc(var(--card-h) / -2);

	transform-style: preserve-3d;
	transform: var(--t, translate3d(0,0,0));
	transition: transform 600ms cubic-bezier(.22,.65,.22,1),
	            filter 500ms ease,
	            opacity 500ms ease;
	will-change: transform;
	filter: brightness(var(--b, 1));
	opacity: var(--o, 1);
	pointer-events: var(--pe, auto);
}

/* ---- КАРТОЧКА ---- */
.gallery-3d__card {
	display: block;
	position: relative;
	width: 100%;
	height: 100%;
	border-radius: 18px;
	overflow: hidden;
	text-decoration: none;
	color: inherit;
	background: #15151a;
	box-shadow: 0 30px 60px rgb(0 0 0 / 0.5), 0 0 0 1px rgb(255 255 255 / 0.06);
	transition: box-shadow 400ms ease;
}

.gallery-3d__slide[data-active="true"] .gallery-3d__card {
	box-shadow: 0 40px 90px rgb(0 0 0 / 0.65), 0 0 0 1px rgb(var(--color-accent) / 0.35);
}

.gallery-3d__media {
	position: absolute;
	inset: 0;
	overflow: hidden;
}

.gallery-3d__media img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
	pointer-events: none;
	-webkit-user-drag: none;
}

/* Градиент для читаемости подписи */
.gallery-3d__media::after {
	content: '';
	position: absolute;
	inset: 0;
	background: linear-gradient(180deg, rgba(0,0,0,0) 45%, rgba(0,0,0,0.55) 100%);
	pointer-events: none;
}

.gallery-3d__badge {
	position: absolute;
	top: 0.9rem;
	left: 0.9rem;
	z-index: 2;
	display: inline-flex;
	align-items: center;
	gap: 0.35em;
	font-size: 0.68rem;
	font-weight: 500;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: #fff;
	padding: 0.38em 0.8em 0.36em;
	border-radius: 999px;
	background: rgb(0 0 0 / 0.55);
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
	border: 1px solid rgb(255 255 255 / 0.18);
}
.gallery-3d__badge svg {
	opacity: 0.9;
}

/* Если есть и бейдж, и номер — номер сдвигаем в правый верхний угол */
.gallery-3d__badge ~ .gallery-3d__num {
	left: auto;
	right: 0.9rem;
}

.gallery-3d__num {
	position: absolute;
	top: 0.9rem;
	left: 0.9rem;
	z-index: 2;
	font-family: var(--font-serif);
	font-weight: 300;
	font-size: 0.95rem;
	letter-spacing: 0.1em;
	color: rgb(255 255 255 / 0.95);
	padding: 0.25em 0.7em;
	border: 1px solid rgb(255 255 255 / 0.45);
	border-radius: 999px;
	background: rgb(0 0 0 / 0.3);
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
}

.gallery-3d__caption {
	position: absolute;
	left: 1.1rem;
	right: 1.1rem;
	bottom: 1rem;
	z-index: 2;
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
}

.gallery-3d__city {
	font-family: var(--font-serif);
	font-weight: 400;
	font-size: 1.35rem;
	line-height: 1.15;
	color: #fff;
	text-shadow: 0 2px 10px rgb(0 0 0 / 0.5);
}

.gallery-3d__sub {
	font-size: 0.85rem;
	color: rgb(255 255 255 / 0.82);
	text-shadow: 0 1px 6px rgb(0 0 0 / 0.45);
}

.gallery-3d__cta {
	font-size: 0.7rem;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: rgb(255 255 255 / 0.8);
	opacity: 0;
	transform: translateY(4px);
	transition: opacity 300ms ease, transform 300ms ease;
}

.gallery-3d__slide[data-active="true"] .gallery-3d__cta {
	opacity: 1;
	transform: translateY(0);
}

/* ---- СТРЕЛКИ ---- */
.gallery-3d__nav {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 52px;
	height: 52px;
	padding: 0;
	border-radius: 50%;
	border: 1px solid rgb(255 255 255 / 0.16);
	background: rgb(255 255 255 / 0.06);
	color: rgb(var(--color-primary));
	cursor: pointer;
	z-index: 3;
	transition: background 240ms ease, border-color 240ms ease, transform 240ms ease;
}
.gallery-3d__nav:hover {
	background: rgb(var(--color-accent) / 0.22);
	border-color: rgb(var(--color-accent) / 0.55);
	transform: scale(1.05);
}
.gallery-3d__nav:focus-visible {
	outline: 2px solid rgb(var(--color-accent));
	outline-offset: 3px;
}

/* ---- ПАГИНАЦИЯ ---- */
.gallery-3d__dots {
	position: absolute;
	left: 50%;
	bottom: -0.75rem;
	transform: translateX(-50%);
	display: flex;
	gap: 0.45rem;
	z-index: 3;
}

.gallery-3d__dot {
	width: 22px;
	height: 4px;
	padding: 0;
	border: 0;
	border-radius: 2px;
	background: rgb(255 255 255 / 0.22);
	cursor: pointer;
	transition: background 240ms ease, width 240ms ease;
}
.gallery-3d__dot.is-active {
	background: rgb(var(--color-accent));
	width: 34px;
}
.gallery-3d__dot:focus-visible {
	outline: 2px solid rgb(var(--color-accent));
	outline-offset: 2px;
}

.gallery-3d__footer {
	text-align: center;
	margin-top: 3rem;
}

.gallery-3d__portfolio-link {
	display: inline-block;
	font-size: 0.875rem;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: rgb(var(--color-primary));
	text-decoration: none;
	padding: 0.875rem 2rem;
	border: 1px solid rgb(var(--color-accent) / 0.5);
	border-radius: 999px;
	transition: background 240ms ease, border-color 240ms ease;
}
.gallery-3d__portfolio-link:hover {
	background: rgb(var(--color-accent) / 0.18);
	border-color: rgb(var(--color-accent));
}

/* ---- TABLET ---- */
@media (min-width: 768px) and (max-width: 1023px) {
	.gallery-3d__carousel {
		--card-w: 260px;
		--card-h: 430px;
		--stage-h: 560px;
		--step-x: 170px;
		--step-z: 120px;
	}
}

/* ---- MOBILE ---- */
@media (max-width: 767px) {
	.gallery-3d {
		padding: clamp(2.5rem, 7vw, 3.5rem) 0;
	}
	.gallery-3d__carousel {
		--card-w: 220px;
		--card-h: 370px;
		--stage-h: 500px;
		--perspective: 1200px;
		--step-x: 130px;
		--step-z: 90px;
		--step-rot: 16deg;
		--step-scale: 0.11;
		--active-scale: 1.2;
		gap: 0;
		padding: 0;
	}
	.gallery-3d__nav { display: none; }

	.gallery-3d__num { font-size: 0.8125rem; }
	.gallery-3d__city { font-size: 1.1rem; }
	.gallery-3d__cta  { font-size: 0.65rem; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
	.gallery-3d__slide { transition: none; }
}
