/*
 * Коллекции DanaBaby — сетка и карточка.
 * Все классы с префиксом dbc-, чтобы не пересекаться с WoodMart/Elementor.
 * Размеры подписи задаются в долях ширины карточки (container query units, cqw)
 * с запасным вариантом через vw для старых браузеров.
 */

.dbc-grid {
	--dbc-font: "VAG World", "Evolventa", sans-serif;
	--dbc-text: #f7f2d6;
	--dbc-plate: rgba(205, 110, 109, 0.85); /* #CD6E6D, непрозрачность 85% — текст остаётся 100% */
	--dbc-radius: 12px;
	--dbc-gap: 22px;
	--dbc-cols: 4;
	--dbc-duration: 400ms;
	--dbc-ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
	--dbc-focus: #cd6e6d;

	display: grid;
	grid-template-columns: repeat(var(--dbc-cols), minmax(0, 1fr));
	gap: var(--dbc-gap);
	width: 100%;
	max-width: 100%;
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

.dbc-grid *,
.dbc-grid *::before,
.dbc-grid *::after {
	box-sizing: border-box;
}

/*
 * Elementor (контейнеры e-con): на телефоне контейнер переводится в flex-wrap, и в многострочной
 * flex-колонке высота виджета считается по «естественной» ширине содержимого. У сетки квадратных
 * карточек она нулевая, и виджет схлопывается — следующий блок наезжает на карточки.
 * Растягиваем на всю ширину только те обёртки Elementor, внутри которых стоит наша сетка.
 */
.elementor-widget:has(> .elementor-widget-container > .elementor-shortcode > .dbc-grid),
.elementor-widget:has(> .elementor-widget-container > .dbc-grid),
.elementor-widget:has(> .elementor-shortcode > .dbc-grid),
.elementor-widget:has(> .dbc-grid) {
	width: 100%;
	max-width: 100%;
}

@media (max-width: 1023px) {
	.dbc-grid {
		--dbc-cols: 2;
		--dbc-gap: 16px;
	}
}

@media (max-width: 767px) {
	.dbc-grid {
		--dbc-gap: 10px;
		--dbc-radius: 8px;
	}
}

/* Карточка — одна ссылка, квадрат 1:1 */
.dbc-grid .dbc-card {
	position: relative;
	display: block;
	width: 100%;
	aspect-ratio: 1 / 1;
	overflow: hidden;
	border-radius: var(--dbc-radius);
	text-decoration: none;
	color: var(--dbc-text);
	background: #f3efe6;
	isolation: isolate;
	container-type: inline-size;
	-webkit-tap-highlight-color: transparent;
}

/* Запасной вариант для браузеров без aspect-ratio */
@supports not (aspect-ratio: 1 / 1) {
	.dbc-grid .dbc-card {
		height: 0;
		padding-bottom: 100%;
	}
}

.dbc-grid .dbc-card:hover,
.dbc-grid .dbc-card:focus,
.dbc-grid .dbc-card:active {
	text-decoration: none;
	color: var(--dbc-text);
}

.dbc-grid a.dbc-card.dbc-card:focus {
	outline: none;
}

/* !important — чтобы стили фокуса темы (в т.ч. прозрачная обводка) не прятали индикатор клавиатуры */
.dbc-grid a.dbc-card.dbc-card:focus-visible {
	outline: 3px solid var(--dbc-focus) !important;
	outline-offset: 3px !important;
	box-shadow: none;
	text-decoration: none;
}

.dbc-grid .dbc-card__media {
	position: absolute;
	inset: 0;
	display: block;
	overflow: hidden;
	border-radius: inherit;
}

/* !important у размеров: темы и оптимизаторы (например, Twenty Twenty-One) дописывают
   в <img> инлайновые width/height, из-за которых фото не заполняет квадрат. */
.dbc-grid .dbc-card__img {
	display: block;
	width: 100% !important;
	height: 100% !important;
	max-width: none !important;
	max-height: none !important;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	object-fit: cover !important;
	object-position: var(--dbc-fx, 50%) var(--dbc-fy, 50%) !important;
	transform: scale(1);
	transform-origin: center center;
	transition: transform var(--dbc-duration) var(--dbc-ease);
	will-change: transform;
}

.dbc-grid .dbc-card__img[hidden] {
	display: none !important;
}

/* Hover zoom: двигается только фото. Только для устройств с настоящим hover,
   поэтому на телефоне карточка открывается с первого касания. */
@media (hover: hover) and (pointer: fine) {
	.dbc-grid .dbc-card:hover .dbc-card__img {
		transform: scale(1.04);
	}
}

.dbc-grid .dbc-card:focus-visible .dbc-card__img {
	transform: scale(1.04);
}

/* Плашка с названием */
.dbc-grid .dbc-card__label {
	position: absolute;
	left: 50%;
	bottom: 9%;
	z-index: 1;
	display: block;
	width: max-content;
	max-width: 88%;
	transform: translateX(-50%);
	padding: 0.18em 0.47em 0.2em;
	border-radius: 3vw;
	border-radius: 3cqw;
	background: var(--dbc-plate);
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.1);
	font-family: var(--dbc-font);
	font-weight: 400;
	font-style: normal;
	font-size: 2.1vw;
	font-size: 8.5cqw;
	line-height: 1.12;
	letter-spacing: normal;
	text-transform: none;
	text-align: center;
	color: var(--dbc-text);
	white-space: normal;
	overflow-wrap: break-word;
	word-break: normal;
	hyphens: manual;
	pointer-events: none;
}

.dbc-grid .dbc-card__text {
	display: block;
	font: inherit;
	color: inherit;
	opacity: 1;
	overflow-wrap: anywhere;
}

/* Адаптивное уменьшение длинных названий — для каждой карточки отдельно */
.dbc-grid .dbc-card__label--s1 { font-size: 1.75vw; font-size: 7cqw; }
.dbc-grid .dbc-card__label--s2 { font-size: 1.45vw; font-size: 5.8cqw; }
.dbc-grid .dbc-card__label--s3 { font-size: 1.2vw;  font-size: 4.8cqw; }

@media (max-width: 1023px) {
	.dbc-grid .dbc-card__label         { font-size: 4.1vw; font-size: 8.5cqw; border-radius: 6vw; border-radius: 3cqw; }
	.dbc-grid .dbc-card__label--s1     { font-size: 3.4vw; font-size: 7cqw; }
	.dbc-grid .dbc-card__label--s2     { font-size: 2.8vw; font-size: 5.8cqw; }
	.dbc-grid .dbc-card__label--s3     { font-size: 2.3vw; font-size: 4.8cqw; }
}

/* Минимальная читаемость на узких экранах (360 px → карточка ~165 px) */
@media (max-width: 767px) {
	.dbc-grid .dbc-card__label {
		bottom: 8%;
		max-width: 92%;
		padding: 0.2em 0.5em 0.22em;
		font-size: max(13px, 8.5cqw);
	}
	.dbc-grid .dbc-card__label--s1 { font-size: max(12px, 7cqw); }
	.dbc-grid .dbc-card__label--s2 { font-size: max(11.5px, 5.8cqw); }
	.dbc-grid .dbc-card__label--s3 { font-size: max(11px, 4.8cqw); }
}

@media (prefers-reduced-motion: reduce) {
	.dbc-grid .dbc-card__img,
	.dbc-grid .dbc-card:hover .dbc-card__img,
	.dbc-grid .dbc-card:focus-visible .dbc-card__img {
		transition: none;
		transform: none;
		will-change: auto;
	}
}
