/*
 * Global base styles that theme.json cannot express. Per-block CSS lives in
 * block styles (Task 4).
 */

/*
 * Brand colour as text. The brand taupe (primary, #BFB39B) is only 2.07:1 on
 * white, so text, links, outline buttons and focus rings use the darker
 * `primary-text` (WCAG AA on white, light, light-gray and gray-100). On dark
 * backgrounds the taupe itself is readable (5.53:1 on body-color) and stays;
 * on a taupe background brand text becomes gray-900. theme.json's link and
 * button colours and button.css read these variables (fallback: the
 * primary-text preset).
 */
body,
:where(
	.has-white-background-color,
	.has-light-background-color,
	.has-light-gray-background-color,
	.has-gray-100-background-color,
	.has-gray-400-background-color
) {
	--ragazzo-brand-text: var(--wp--preset--color--primary-text);
	--ragazzo-brand-text-hover: var(--wp--custom--color--primary-text-hover);
}

:where(
	.has-body-color-background-color,
	.has-secondary-background-color,
	.has-dark-background-color,
	.has-black-background-color,
	.has-medium-gray-background-color,
	.has-dark-gray-background-color,
	.has-gray-900-background-color,
	.has-primary-text-background-color,
	.wp-block-cover
) {
	--ragazzo-brand-text: var(--wp--preset--color--primary);
	--ragazzo-brand-text-hover: var(--wp--preset--color--primary);
}

:where(.has-primary-background-color, .has-brown-background-color) {
	--ragazzo-brand-text: var(--wp--preset--color--gray-900);
	--ragazzo-brand-text-hover: var(--wp--preset--color--gray-900);
}

/*
 * The editor's "Primary" / "Brown" text colour follows the same rule (core
 * prints the colour classes with !important).
 */
:is(.has-primary-color, .has-brown-color):not(.has-background) {
	color: var(--ragazzo-brand-text) !important;
}

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
	outline: 2px solid var(--ragazzo-brand-text, var(--wp--preset--color--primary-text));
	outline-offset: 2px;
}

/*
 * In-page anchors (e.g. the Certificazioni icons) scroll smoothly and stop
 * below the sticky header. Reduced motion turns the smoothing off below.
 */
html {
	scroll-behavior: smooth;
	scroll-padding-top: calc(var(--wp-admin--admin-bar--height, 0px) + var(--ragazzo-header-height, 75px) + var(--wp--preset--spacing--30));
}

@media (prefers-reduced-motion: reduce) {

	*,
	*::before,
	*::after {
		transition-duration: 0.01ms !important;
		animation-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}
}

/* The font ships 300 and 700 only: "bolder" from 300 would synthesize 400. */
:where(b, strong) {
	font-weight: 700;
}

/* Long unbroken strings (bare URLs in classic post content) wrap instead of overflowing on mobile. */
body {
	overflow-wrap: break-word;
}

/*
 * oEmbed iframes in classic (freeform) content, e.g. a bare YouTube URL in a post: WordPress
 * prints fixed width/height attributes. Scale them to the column at 16:9. Embed blocks keep
 * core's responsive wrapper (.wp-block-embed), so they are excluded.
 */
iframe {
	max-width: 100%;
}

:is(iframe[src*="youtube.com/embed"], iframe[src*="youtube-nocookie.com/embed"], iframe[src*="player.vimeo.com"]):not(.wp-block-embed iframe) {
	width: 100%;
	height: auto;
	aspect-ratio: 16 / 9;
}

/*
 * Edge rows (className `is-edge-tiles` on a full-width block): the content
 * runs edge to edge with no gaps, like the old site, capped at the shared
 * breakout width (theme.json custom.breakout) so very wide screens don't get
 * huge tiles. Every section that breaks out of the content width uses this
 * cap, so they all line up. The term-grid tiles apply the same cap.
 */
.alignfull.is-edge-tiles > * {
	max-width: var(--wp--custom--breakout, 1920px);
	margin-inline: auto;
	gap: 0;
}

/* Pagination under edge tiles: its own spacing, away from the tiles and the footer. */
.alignfull.is-edge-tiles > .wp-block-query-pagination {
	gap: 0.5rem;
	margin-block: var(--wp--preset--spacing--50) var(--wp--preset--spacing--section);
}

/* "Carica altri" under a post list (assets/js/load-more.js). */
.wp-block-buttons.ragazzo-load-more {
	margin-block: var(--wp--preset--spacing--50) var(--wp--preset--spacing--section);
}

.ragazzo-load-more.is-loading .wp-block-button__link {
	opacity: 0.6;
	pointer-events: none;
}

/*
 * Media & text with a taller image (className `has-tall-media`): with image
 * fill the image follows the text height, so give it a minimum of its own.
 */
@media (min-width: 600px) {

	.wp-block-media-text.has-tall-media .wp-block-media-text__media {
		min-height: clamp(400px, 50vw, 720px);
	}

	/*
	 * Vertical room around the text: the image fills the whole row, so it
	 * always stands taller than the text beside it, however long the text.
	 */
	.wp-block-media-text.has-tall-media > .wp-block-media-text__content {
		padding-block: clamp(2rem, 1rem + 4vw, 5rem);
	}

	/*
	 * More room between the text and the image (core: 8% on both sides);
	 * the outer side keeps core's 8%.
	 */
	.wp-block-media-text.has-media-on-the-right > .wp-block-media-text__content {
		padding-right: clamp(2rem, 7vw, 6rem);
	}

	.wp-block-media-text:not(.has-media-on-the-right) > .wp-block-media-text__content {
		padding-left: clamp(2rem, 7vw, 6rem);
	}
}

/*
 * Optical left alignment of the big titles: at display sizes the condensed
 * font's left side bearing (about 0.04-0.06em: 4-6px at 92px) pushes the
 * letters visibly right of the breadcrumb and text below. Shift them back:
 * assets/js/header.js measures the first letter's bearing and sets
 * --ragazzo-optical-left (it varies by letter: P, N ~6px, C ~4px, A ~0);
 * -0.04em until then. Relative offset: constrained layouts force the margins.
 */
:is(
	.archive-intro > h1,
	.is-style-display-1,
	.is-style-display-2,
	.has-display-1-font-size,
	.has-display-2-font-size
):not(.has-text-align-center, .has-text-align-right) {
	position: relative;
	left: var(--ragazzo-optical-left, -0.04em);
}

/*
 * Image lightbox (core/image "enlarge on click", galleries with previous /
 * next), like the old site: dark backdrop, white close button and large thin
 * arrows, image title in a black bar along the bottom
 * (Theme::lightbox_caption_end). Core sets the colours inline from the
 * global styles, hence !important.
 */
.wp-lightbox-overlay .scrim {
	background-color: rgb(0 0 0 / 82%) !important;
}

.wp-lightbox-overlay :is(.wp-lightbox-close-button, .wp-lightbox-navigation-button) {
	color: var(--wp--preset--color--white);
	fill: var(--wp--preset--color--white) !important;
}

.wp-lightbox-overlay :is(.wp-lightbox-close-button, .wp-lightbox-navigation-button):is(:hover, :focus-visible) {
	opacity: 0.75;
}

.wp-lightbox-overlay .wp-lightbox-close-button svg {
	width: 32px;
	height: 32px;
}

.wp-lightbox-overlay .wp-lightbox-navigation-button svg {
	width: 56px;
	height: 56px;
}

.ragazzo-lightbox-caption {
	position: absolute;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: 3000000;
	padding: 0.6rem var(--wp--style--root--padding-right);
	background-color: var(--wp--preset--color--black, #000);
	color: var(--wp--preset--color--white);
	font-size: 1.125rem;
	font-weight: 700;
	line-height: 1.4;
	text-align: center;
	pointer-events: none;
}

.ragazzo-lightbox-caption:empty,
.wp-lightbox-overlay:not(.active) .ragazzo-lightbox-caption {
	display: none;
}

/*
 * Lightbox opens and closes with a simple fade (no zoom from the image's
 * place on the page), and the clicked image stays visible on the page
 * (core hides it while open and for 0.4s after closing, which leaves
 * an empty white square).
 */
.wp-lightbox-overlay.zoom.active {
	animation: both turn-on-visibility 0.25s;
}

.wp-lightbox-overlay.zoom.show-closing-animation:not(.active) {
	animation: both turn-off-visibility 0.25s;
}

.wp-lightbox-overlay.zoom.active .lightbox-image-container,
.wp-lightbox-overlay.zoom.show-closing-animation:not(.active) .lightbox-image-container {
	animation: none;
}

.wp-block-image img:is(.hide, .show) {
	visibility: visible;
	animation: none;
}

/*
 * Round swatches: the material cards (term-grid "cards": homepage, case
 * studies) and the finish swatches (group style "Campioni") share one look:
 * the circle, the name below it and the hover. Like the old site, a light shadow at
 * rest; on hover the circle grows by a seventh (old: scale 0.7 to 0.8) and
 * the shadow deepens. No ancestor clips it, so it stays a whole circle.
 */
:is(.is-style-swatches .wp-block-image img, .is-variant-cards .ragazzo-term-grid__image) {
	width: min(11rem, 100%);
	height: auto;
	aspect-ratio: 1;
	object-fit: cover;
	border-radius: 50%;
	box-shadow: 0 0.125rem 0.25rem rgb(0 0 0 / 7.5%);
	transition: transform 0.2s linear, box-shadow 0.2s linear;
}

/* Room between the intro text above and the circles. */
* + :is(.wp-block-group.is-style-swatches, .ragazzo-term-grid.is-variant-cards) {
	margin-block-start: var(--wp--preset--spacing--60);
}

:is(.is-style-swatches :is(h1, h2, h3, h4, h5, h6), .is-variant-cards .ragazzo-term-grid__title) {
	margin-block: 1.5rem 0;
	color: inherit;
	font-size: var(--wp--preset--font-size--h-3);
	font-weight: 700;
	text-transform: uppercase;
}

@media (hover: hover) and (prefers-reduced-motion: no-preference) {

	:is(.is-style-swatches > :hover .wp-block-image img, .is-variant-cards .ragazzo-term-grid__item:hover .ragazzo-term-grid__image) {
		transform: scale(1.14);
		box-shadow: 0 0.5rem 1rem rgb(0 0 0 / 15%);
	}
}

/*
 * A full-width coloured section joins the full-width sections next to it
 * (e.g. the dark title band and the dark intro below it, the homepage
 * materials band under the category tiles, the tiles under the Per la tua
 * casa band) instead of leaving a strip of page background between them:
 * the sections' own padding gives the room.
 */
.wp-block-post-content > .alignfull + .alignfull.has-background,
.wp-block-post-content > .alignfull.has-background + .alignfull {
	margin-block-start: 0;
}

/*
 * Coloured title band with the breadcrumbs inside (className `is-page-hero` on
 * a full-width group, e.g. the Essenze e finiture pages, on the "Pagina senza
 * titolo" template): breadcrumbs first, then the title, spaced like the page
 * hero cover (blocks/cover.css).
 */
.wp-block-group.is-page-hero > .wp-block-breadcrumbs + * {
	margin-top: var(--wp--preset--spacing--section);
}
