/**
 * SEBERD — микроанимации страницы записи (single).
 * Desktop (≥768px): каскад, линия под «Содержание», stagger пунктов TOC.
 * Mobile: короткий вход, без stagger по nth-child; hover-сдвиг только при hover: hover.
 */

/* Якоря: фиксированная шапка не перекрывает заголовки при переходе из оглавления */
body.single .entry-content h2,
body.single .entry-content h3 {
	scroll-margin-top: calc(var(--hdr, 58px) + 20px);
}

/* Safe area на узких экранах (после legacy-стилей) */
@media (max-width: 767.98px) {
	body.single .site-content .content-area,
	body.single .site-main .inside-article {
		padding-left: max(14px, env(safe-area-inset-left, 0px)) !important;
		padding-right: max(14px, env(safe-area-inset-right, 0px)) !important;
	}

	body.single .inside-right-sidebar {
		padding-left: max(0px, env(safe-area-inset-left, 0px));
		padding-right: max(0px, env(safe-area-inset-right, 0px));
	}
}

@media (prefers-reduced-motion: no-preference) {
	@keyframes sbrd-rise {
		from {
			opacity: 0;
			transform: translateY(16px);
		}
		to {
			opacity: 1;
			transform: translateY(0);
		}
	}

	@keyframes sbrd-rise-tight {
		from {
			opacity: 0;
			transform: translateY(10px) scale(0.992);
		}
		to {
			opacity: 1;
			transform: translateY(0) scale(1);
		}
	}

	@keyframes sbrd-toc-row {
		from {
			opacity: 0;
			transform: translateX(-10px);
		}
		to {
			opacity: 1;
			transform: translateX(0);
		}
	}

	@keyframes sbrd-line-grow {
		from {
			transform: scaleX(0);
			opacity: 0.6;
		}
		to {
			transform: scaleX(1);
			opacity: 1;
		}
	}

	/* ——— Mobile: короткий вход, TOC одним блоком ——— */
	@media (max-width: 767.98px) {
		body.single .inside-article > .entry-header {
			animation: sbrd-rise-tight 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
		}

		body.single .inside-article > .entry-content {
			animation: sbrd-rise 0.48s cubic-bezier(0.22, 1, 0.36, 1) both;
			animation-delay: 0.04s;
		}

		body.single .inside-article > .sbrd-related-wrap {
			animation: sbrd-rise 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
			animation-delay: 0.08s;
		}

		body.single .inside-right-sidebar {
			animation: sbrd-rise 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
			animation-delay: 0.04s;
		}

		body.single .sbrd-post-toc-widget .sbrd-post-toc-list {
			animation: sbrd-rise 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
			animation-delay: 0.06s;
		}

		body.single .sbrd-post-toc-widget .sbrd-post-toc-item a {
			transition: background 0.18s ease, color 0.18s ease;
		}
	}

	/* ——— Desktop: полный каскад, линия, stagger TOC ——— */
	@media (min-width: 768px) {
		body.single .inside-article > .entry-header {
			animation: sbrd-rise-tight 0.58s cubic-bezier(0.22, 1, 0.36, 1) both;
			animation-delay: 0.04s;
		}

		body.single .inside-article > .entry-content {
			animation: sbrd-rise 0.62s cubic-bezier(0.22, 1, 0.36, 1) both;
			animation-delay: 0.1s;
		}

		body.single .inside-article > .sbrd-related-wrap {
			animation: sbrd-rise 0.58s cubic-bezier(0.22, 1, 0.36, 1) both;
			animation-delay: 0.2s;
		}

		body.single .inside-right-sidebar {
			animation: sbrd-rise 0.52s cubic-bezier(0.22, 1, 0.36, 1) both;
			animation-delay: 0.06s;
		}

		body.single .sbrd-post-toc-widget .widget-title {
			position: relative;
			border-bottom: none !important;
		}

		body.single .sbrd-post-toc-widget .widget-title::after {
			content: "";
			position: absolute;
			left: 0;
			bottom: 0;
			width: 100%;
			height: 2px;
			transform-origin: left center;
			background: linear-gradient(90deg, var(--accent) 0%, rgba(255, 102, 0, 0.15) 72%, transparent 100%);
			border-radius: 1px;
			animation: sbrd-line-grow 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
			animation-delay: 0.28s;
		}

		body.single .sbrd-post-toc-widget .sbrd-post-toc-item {
			animation: sbrd-toc-row 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
		}

		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(1) {
			animation-delay: 0.14s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(2) {
			animation-delay: 0.17s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(3) {
			animation-delay: 0.2s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(4) {
			animation-delay: 0.23s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(5) {
			animation-delay: 0.26s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(6) {
			animation-delay: 0.29s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(7) {
			animation-delay: 0.32s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(8) {
			animation-delay: 0.35s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(9) {
			animation-delay: 0.38s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(10) {
			animation-delay: 0.41s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(11) {
			animation-delay: 0.44s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(12) {
			animation-delay: 0.47s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(13) {
			animation-delay: 0.5s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(14) {
			animation-delay: 0.53s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(15) {
			animation-delay: 0.56s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(16) {
			animation-delay: 0.59s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(17) {
			animation-delay: 0.62s;
		}
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item:nth-child(18) {
			animation-delay: 0.65s;
		}

		body.single .sbrd-post-toc-widget .sbrd-post-toc-item a {
			transition:
				transform 0.22s cubic-bezier(0.22, 1, 0.36, 1),
				background 0.22s ease,
				color 0.18s ease;
		}

		body.single .sbrd-post-toc-widget .sbrd-post-toc-item a:active {
			transform: translateX(1px) scale(0.99);
		}
	}

	@media (min-width: 768px) and (hover: hover) {
		body.single .sbrd-post-toc-widget .sbrd-post-toc-item a:hover {
			transform: translateX(2px);
		}
	}

	body.single .entry-content a:focus-visible {
		transition: outline-offset 0.15s ease;
		outline-offset: 3px;
	}
}

@media (prefers-reduced-motion: reduce) {
	body.single .inside-article > .entry-header,
	body.single .inside-article > .entry-content,
	body.single .inside-article > .sbrd-related-wrap,
	body.single .inside-right-sidebar,
	body.single .sbrd-post-toc-widget .sbrd-post-toc-list,
	body.single .sbrd-post-toc-widget .sbrd-post-toc-item,
	body.single .sbrd-post-toc-widget .widget-title::after {
		animation: none !important;
	}

	body.single .sbrd-post-toc-widget .widget-title {
		border-bottom: 1px solid var(--border) !important;
	}

	body.single .sbrd-post-toc-widget .widget-title::after {
		display: none;
	}

	body.single .sbrd-post-toc-widget .sbrd-post-toc-item a:hover,
	body.single .sbrd-post-toc-widget .sbrd-post-toc-item a:active {
		transform: none;
	}
}
