/*
 * Global header/footer shell.
 * Final: desktop brand flip axis aligned to the visual center of lowercase "a".
 */

html,
body {
	min-height: 100%;
}

body {
	min-height: 100vh;
	min-height: 100dvh;
	display: flex;
	flex-direction: column;
}

.site-main {
	flex: 1 0 auto;
}

/*
 * Two-stage first paint without flashing fallback fonts.
 *
 * The tiny inline HTML font gate is retained byte-for-byte, including its
 * CSP SHA256. Its original whole-body opacity must be overridden ONLY AFTER
 * our blocking theme stylesheet is available; otherwise the shell could not
 * appear before page-specific content. Elements still start hidden below.
 */
html.fonts-pending body {
	opacity: 1 !important;
}

/* Header and footer are a single early shell, revealed together once the
 * critical Futura Medium face is available. Do NOT reveal either through the
 * main/content readiness class; heavy Home/Works sizing may continue. */
body:not(.thymotheus-shell-ready) > .site-header,
body:not(.thymotheus-shell-ready) > .site-footer,
body:not(.thymotheus-shell-ready) > #color-invert-toggle {
	opacity: 0;
	visibility: hidden;
	animation: thymotheus-page-ready-failsafe 0s linear 1.5s forwards;
}

body.thymotheus-shell-ready > .site-header,
body.thymotheus-shell-ready > .site-footer,
body.thymotheus-shell-ready > #color-invert-toggle {
	opacity: 1;
	visibility: visible;
	animation: none;
}

/* The main content stays black/hidden until all page-specific font, image and
 * geometry checks have finished. It is always revealed in a single frame. */
body:not(.thymotheus-page-ready) > .site-main {
	opacity: 0;
	visibility: hidden;
	animation: thymotheus-page-ready-failsafe 0s linear 1.5s forwards;
}

body.thymotheus-page-ready > .site-main {
	opacity: 1;
	visibility: visible;
	animation: none;
	transition: opacity 80ms linear;
}

@keyframes thymotheus-page-ready-failsafe {
	to {
		opacity: 1;
		visibility: visible;
	}
}

/* Header */

.site-header {
	flex: 0 0 auto;
	color: #b4b4b4;
}

.site-header__inner {
	width: 100%;
	max-width: 1100px;
	margin-inline: auto;
	margin-top: 30px;
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	align-items: center;
	row-gap: 34px;
}

.site-brand {
	min-width: 0;
	text-align: center;
	font-family: "Futura", Arial, sans-serif;
	font-size: 30px;
	font-weight: 500;
	line-height: 1.2;
	letter-spacing: 5px;
	color: #b4b4b4;
}

.site-brand__word {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 12px 16px;
	margin: -12px -16px;
	color: inherit;
	text-decoration: none;
}

.site-brand__label {
	display: inline-block;
	line-height: 1;
	transform: scaleY(1);
	transform-origin: 50% 19px;
	transition: transform 0.4s ease;
}

@media (min-width: 768px) {
	.site-brand__word:hover .site-brand__label,
	.site-brand__word:focus-visible .site-brand__label {
		transform: scaleY(-1);
	}
}

/* Menu toggle */

.site-menu {
	position: relative;
	grid-column: 1 / -1;
	display: flex;
	flex-direction: column;
	align-items: center;
	z-index: 9999;
}

.site-menu__toggle {
	width: 40px;
	height: 40px;
	padding: 5px;
	display: inline-flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 4px;
	border: 0;
	background: transparent;
	color: #b4b4b4;
	cursor: pointer;
}

.site-menu__toggle span {
	display: block;
	width: 30px;
	height: 4px;
	border-radius: 2px;
	background: currentColor;
	transform-origin: center;
	transition: transform 180ms ease, opacity 120ms ease;
}

.site-menu__toggle[aria-expanded="true"] span:nth-child(1) {
	transform: translateY(8px) rotate(45deg);
}

.site-menu__toggle[aria-expanded="true"] span:nth-child(2) {
	opacity: 0;
}

.site-menu__toggle[aria-expanded="true"] span:nth-child(3) {
	transform: translateY(-8px) rotate(-45deg);
}

/* Dropdown */

.site-navigation {
	position: absolute;
	top: 50px;
	left: 50%;
	width: min(1140px, calc(100vw - 40px));
	transform: translateX(-50%) translateY(-8px);
	z-index: 1000;
	background: #fff;

	opacity: 0;
	clip-path: inset(0 0 100% 0);
	visibility: hidden;
	pointer-events: none;

	/*
	 * Closed state doubles as the reverse animation.
	 * Visibility is delayed until the 420 ms retraction has finished.
	 */
	transition:
		clip-path 420ms cubic-bezier(0.4, 0, 0.2, 1),
		opacity 300ms ease,
		transform 420ms cubic-bezier(0.4, 0, 0.2, 1),
		visibility 0s linear 420ms;
}

.site-navigation.is-open {
	transform: translateX(-50%) translateY(0);
	opacity: 1;
	clip-path: inset(0 0 0 0);
	visibility: visible;
	pointer-events: auto;

	/* Opening stays quick. */
	transition:
		clip-path 180ms ease,
		opacity 120ms ease,
		transform 180ms ease,
		visibility 0s linear 0s;
}

.site-navigation[hidden] {
	display: none;
}

.site-navigation__list {
	margin: 0;
	padding: 0;
	list-style: none;
	background: #fff;
	text-align: center;
}

.site-navigation__list li {
	margin: 0;
	padding: 0;
}

.site-navigation .site-navigation__list a {
	height: 40px;
	padding: 0 20px;
	display: flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	font-family: "Futura", Arial, sans-serif;
	font-size: 21px;
	font-weight: 500;
	line-height: 1;
	color: #111;
	background: #fff;
	text-decoration: none;
}

.site-navigation .site-navigation__list a:hover,
.site-navigation .site-navigation__list a:focus-visible {
	background: #3f444b;
	color: #fff;
}

/*
 * Current page is NOT permanently highlighted. It uses the same black text
 * on white as every other closed-state menu entry.
 */
.site-navigation .site-navigation__list .current-menu-item > a,
.site-navigation .site-navigation__list .current_page_item > a,
.site-navigation .site-navigation__list a[aria-current="page"] {
	background: #3f444b !important;
	color: #fff !important;
}

@media (prefers-reduced-motion: reduce) {
	.site-footer .social-links a {
		transition: none;
	}

	.site-navigation,
	.site-navigation.is-open {
		transition: none;
		transform: translateX(-50%);
	}
}

/* Footer */

.site-footer {
	flex: 0 0 auto;
	margin-top: auto;
	/*
	 * Keep the social icons on the same bottom baseline as the homepage
	 * whenever the page is shorter than the viewport.
	 */
	padding: 72px 20px 24px;
	color: #fff;
}

.social-links {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 48px;
}

.site-footer .social-links a,
.site-footer .social-links a:visited {
	width: 54px;
	height: 54px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	color: #fff !important;
	text-decoration: none;
	transform: scale(1);
	opacity: 1;
	filter: none;
	transition: transform 180ms ease;
}

.site-footer .social-links a:hover,
.site-footer .social-links a:focus-visible,
.site-footer .social-links a:active {
	color: #fff !important;
	opacity: 1;
	filter: none;
}

@media (hover: hover) and (pointer: fine) {
	.site-footer .social-links a:hover,
	.site-footer .social-links a:focus-visible {
		transform: scale(1.18);
	}
}

/*
 * Touch feedback on phones/tablets: same enlargement as desktop hover,
 * visible while the finger/stylus is pressing the icon.
 */
@media (hover: none), (pointer: coarse) {
	.site-footer .social-links a:active {
		transform: scale(1.18);
	}
}

.social-icon {
	display: block;
	width: 46px;
	height: 46px;
	overflow: visible;
}

.social-icon--instagram {
	width: 40px;
}

.social-icon--youtube {
	width: 52px;
}

/* Mobile */

@media (max-width: 767px) and (hover: none) and (pointer: coarse) {
	.site-header__inner {
		max-width: none;
		margin-top: 0;
		padding: 0 10px;
		box-sizing: border-box;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		column-gap: 5px;
		row-gap: 11px;
	}

	.site-brand {
		font-size: 30px;
		letter-spacing: 5px;
	}

	.site-brand--tymoteusz {
		grid-column: 1 / -1;
		padding-top: 0;
	}

	.site-brand--karas {
		grid-column: 1;
		padding-top: 0;
	}

	.site-brand--tecza {
		grid-column: 2;
		padding-top: 0;
	}

	.site-brand__label,
	.site-brand__word:hover .site-brand__label,
	.site-brand__word:focus-visible .site-brand__label {
		transform: none;
		transition: none;
	}

	.site-menu {
		grid-column: 1 / -1;
		margin-top: 0;
	}

	.site-navigation {
		top: 48px;
		width: calc(100vw - 20px);
	}

	.site-navigation .site-navigation__list a {
		height: 40px;
		font-size: 21px;
	}

	/*
	 * Mobile footer stays in normal document flow.
	 *
	 * On short pages the flex column pushes it to the bottom of 100dvh,
	 * so the icons always have the same bottom baseline. On long pages
	 * it follows the content instead of overlaying it.
	 */
	.site-footer {
		position: static;
		z-index: auto;
		margin-top: auto;
		padding:
			36px
			20px
			max(10px, env(safe-area-inset-bottom));
	}

	.social-links {
		gap: 38px;
	}

	.site-footer .social-links a {
		width: 38px;
		height: 38px;
	}

	.social-icon {
		width: 28px;
		height: 28px;
	}

	.social-icon--instagram {
		width: 25px;
	}

	.social-icon--youtube {
		width: 32px;
	}
}

/*
 * Desktop browser zoom correction for the footer.
 *
 * On desktop Chrome/Edge, browser zoom reduces the CSS viewport width while
 * enlarging every fixed px value. The homepage content now avoids double-
 * scaling, but the footer icons were still fixed at 54/46/40/52px and thus
 * became enormous at high zoom.
 *
 * For fine-pointer devices only, size the footer from vw with the accepted
 * desktop dimensions as MAX values. When browser zoom halves the CSS
 * viewport width, these CSS dimensions halve too, approximately cancelling
 * the browser's physical magnification.
 *
 * Touch devices are intentionally excluded, so iPhone/iPad retain the
 * accepted mobile/tablet icon sizes and touch feedback.
 */
@media (pointer: fine) {
	.social-links {
		gap: min(48px, 3.87097vw);
	}

	.site-footer .social-links a,
	.site-footer .social-links a:visited {
		width: min(54px, 4.35484vw);
		height: min(54px, 4.35484vw);
	}

	.social-icon {
		width: min(46px, 3.70968vw);
		height: min(46px, 3.70968vw);
	}

	.social-icon--instagram {
		width: min(40px, 3.22581vw);
	}

	.social-icon--youtube {
		width: min(52px, 4.19355vw);
	}
}


/*
 * Viewport-only landings: scale the chrome when height, not width, is scarce.
 * Scope tightly to Home and the Polish Works index; all content pages retain
 * their usual flowing header/footer. Browser zoom/pinch gestures stay native.
 * The page-specific fit scripts provide --viewport-shell-scale.
 */
body.home .site-footer,
body.page-template-page-pl-works .site-header,
body.page-template-page-pl-works .site-footer,
body.home #color-invert-toggle,
body.page-template-page-pl-works #color-invert-toggle {
	zoom: var(--viewport-shell-scale, 1);
}

/* The 72px upper footer pad is redundant when the centre panel flexes. The
 * bottom icon baseline remains unchanged on normal-height displays. */
body.page-template-page-pl-works .site-footer {
	padding-top: 0;
}

/* The flyout must never force the one-screen Works page to scroll. Only the
 * flyout itself may scroll when a short landscape viewport cannot fit menu. */
body.page-template-page-pl-works .site-navigation {
	max-height: min(65dvh, 420px);
	overflow-y: auto;
	overscroll-behavior: contain;
}

/*
 * True mobile landscape (touch/coarse pointer): preserve the shared brand
 * on one horizontal line. This is orientation-specific, not a desktop-width
 * breakpoint; ordinary desktops at short heights stay unchanged.
 */
@media (orientation: landscape) and (max-height: 600px) and (max-width: 1024px) and (hover: none) and (pointer: coarse) {
	.site-header__inner {
		width: 100%;
		max-width: 1100px;
		margin-top: 7px;
		padding-inline: 10px;
		box-sizing: border-box;
		grid-template-columns: repeat(3, minmax(0, 1fr));
		column-gap: 0;
		row-gap: 3px;
	}

	.site-brand--tymoteusz,
	.site-brand--karas,
	.site-brand--tecza {
		grid-column: auto;
		padding-top: 0;
	}

	.site-brand {
		font-size: clamp(16px, 2.6vw, 24px);
		letter-spacing: clamp(1.5px, 0.40vw, 4px);
	}

	.site-menu {
		grid-column: 1 / -1;
		margin-top: 0;
	}

	.site-menu__toggle {
		width: 32px;
		height: 30px;
		padding: 3px;
		gap: 3px;
	}

	.site-menu__toggle span {
		width: 25px;
		height: 3px;
	}

	.site-menu__toggle[aria-expanded="true"] span:nth-child(1) {
		transform: translateY(6px) rotate(45deg);
	}

	.site-menu__toggle[aria-expanded="true"] span:nth-child(3) {
		transform: translateY(-6px) rotate(-45deg);
	}

	.site-navigation {
		top: 36px;
		width: calc(100vw - 20px);
	}

	.site-footer {
		padding-top: 16px;
		padding-bottom: max(6px, env(safe-area-inset-bottom));
	}
}
