/* PB Watermarks: background image and colour overlay for Group, Columns and Column.
   Variables are set per block (see pb-watermarks.php and editor.js):
   --pbw-img image, --pbw-pos focal point, --pbw-ov-c overlay colour, --pbw-ov-a strength (0 to 1). */

.pbw-has-image,
.pbw-has-overlay {
	position: relative;
	isolation: isolate; /* the overlay sits above the block's own background but below its content */
}

.pbw-has-image {
	background-image: var(--pbw-img);
	background-size: cover;
	background-position: var(--pbw-pos, 50% 50%);
	background-repeat: no-repeat;
}

.pbw-has-overlay::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	border-radius: inherit;
	pointer-events: none;
	--pbw-mix: color-mix(in srgb, var(--pbw-ov-c, #000) calc(var(--pbw-ov-a, 0.4) * 100%), transparent);
	background: var(--pbw-mix);
}
.pbw-has-overlay.pbw-ov-bottom::before { background: linear-gradient(to top, var(--pbw-mix), transparent); }
.pbw-has-overlay.pbw-ov-top::before { background: linear-gradient(to bottom, var(--pbw-mix), transparent); }

/* Image block: the overlay sits above the picture. It is left off when the image has a caption,
   because the layer would cover the caption as well. */
.wp-block-image.pbw-has-overlay::before { z-index: 1; }
.wp-block-image.pbw-has-overlay:has(figcaption)::before { display: none; }
.editor-styles-wrapper .wp-block-image.pbw-has-overlay:has(figcaption)::before { display: block; }

/* Watermark shapes (Group, Columns, Column). The shape sits above the overlay and below the content.
   --pbw-sh-c colour, --pbw-sh-a strength (0 to 1), --pbw-sh-size size as % of the block's height,
   --pbw-shape the SVG file (set per block), --pbw-word and --pbw-mark (set for the whole site). */
.pbw-has-shape {
	position: relative;
	isolation: isolate;
}
.pbw-has-shape::after {
	content: "";
	position: absolute;
	z-index: -1;
	pointer-events: none;
	top: 50%;
	height: calc(var(--pbw-sh-size, 80) * 1%);
	aspect-ratio: 1;
	max-width: 92%; /* the 4% side gap plus the same again keeps the shape inside the block */
	translate: 0 -50%;
	opacity: var(--pbw-sh-a, 0.12);
}
.pbw-has-shape.pbw-sh-right::after { right: 4%; }
.pbw-has-shape.pbw-sh-left::after { left: 4%; }
.pbw-has-shape.pbw-sh-center::after { left: 50%; translate: -50% -50%; }

.pbw-sh-svg::after {
	background-color: var(--pbw-sh-c, var(--wp--preset--color--accent, currentColor));
	-webkit-mask: var(--pbw-shape) center / contain no-repeat;
	mask: var(--pbw-shape) center / contain no-repeat;
}

/* The site logo is drawn as a one-colour silhouette in the shape colour, so a white logo (made for a dark header)
   still shows on a light section and colour variations restyle it. Logos are wide, so the box is wide, not square. */
.pbw-sh-mark::after {
	aspect-ratio: auto;
	width: calc(var(--pbw-sh-size, 80) * 0.7%);
	background-color: var(--pbw-sh-c, var(--wp--preset--color--accent, currentColor));
	-webkit-mask: var(--pbw-mark) center / contain no-repeat;
	mask: var(--pbw-mark) center / contain no-repeat;
}
.pbw-sh-mark.pbw-sh-right::after { -webkit-mask-position: right center; mask-position: right center; }
.pbw-sh-mark.pbw-sh-left::after { -webkit-mask-position: left center; mask-position: left center; }

.pbw-has-shape.pbw-sh-word { overflow: clip; }
.pbw-sh-word::after {
	content: var(--pbw-word, "");
	height: auto;
	aspect-ratio: auto;
	max-width: none;
	font-weight: 800;
	line-height: 1;
	letter-spacing: 0.02em;
	white-space: nowrap;
	font-size: clamp(3rem, calc(var(--pbw-sh-size, 80) * 0.09vw), 16rem);
	color: var(--pbw-sh-c, var(--wp--preset--color--accent, currentColor));
}

/* Site plan: a faint grid on the block's own background, plus building outlines drawn as a shape (the ::after layer),
   so Size and Position move the outlines and the grid squares follow Size too. The outlines are hidden on phones. */
.pbw-sh-plan {
	--pbw-grid: color-mix(in srgb, var(--pbw-sh-c, var(--wp--preset--color--accent, currentColor)) calc(var(--pbw-sh-a, 0.12) * 40%), transparent);
	background-image:
		linear-gradient(var(--pbw-grid) 1px, transparent 1px),
		linear-gradient(90deg, var(--pbw-grid) 1px, transparent 1px);
	background-size: calc(var(--pbw-sh-size, 80) * 0.6px) calc(var(--pbw-sh-size, 80) * 0.6px); /* size 80 = 48px squares */
}
.pbw-has-image.pbw-sh-plan {
	background-image:
		linear-gradient(var(--pbw-grid) 1px, transparent 1px),
		linear-gradient(90deg, var(--pbw-grid) 1px, transparent 1px),
		var(--pbw-img);
	background-size: calc(var(--pbw-sh-size, 80) * 0.6px) calc(var(--pbw-sh-size, 80) * 0.6px), calc(var(--pbw-sh-size, 80) * 0.6px) calc(var(--pbw-sh-size, 80) * 0.6px), cover;
}
.pbw-sh-plan::after {
	aspect-ratio: 600 / 360;
	width: calc(var(--pbw-sh-size, 80) * 0.7%);
	background-color: var(--pbw-sh-c, var(--wp--preset--color--accent, currentColor));
	-webkit-mask: url("shapes/general/plan.svg") center / contain no-repeat;
	mask: url("shapes/general/plan.svg") center / contain no-repeat;
}
@media (max-width: 781px) {
	.pbw-sh-plan::after { display: none; }
}

/* Alongside the band theme's "Watermark image" Group style: its colour layer sits at z-index 0, so the shape goes above it. */
.wp-block-group.is-style-watermark.pbw-has-shape::after { z-index: 0; }

/* ---------- Divider strips (0.4.0) ----------
   A thin, empty Group between two sections. The Group's own background colour is one section's colour; the shape
   (wave, zigzag, ...) is drawn over it in the other's. --pbw-st-h height in px, --pbw-st-c shape colour, --pbw-st the
   shape (an SVG address). The 1px negative margin hides hairline gaps between the strip and its neighbours. */
.pbw-strip {
	position: relative;
	height: calc(var(--pbw-st-h, 80) * 1px);
	min-height: 0;
	padding-block: 0 !important;
	margin-block: -1px !important;
	overflow: hidden;
}
.pbw-strip::after {
	content: "";
	position: absolute;
	inset: 0;
	pointer-events: none;
	background: var(--pbw-st-c, currentColor);
	-webkit-mask: var(--pbw-st) center / 100% 100% no-repeat;
	mask: var(--pbw-st) center / 100% 100% no-repeat;
}
@media (max-width: 781px) {
	.pbw-strip { height: calc(var(--pbw-st-h, 80) * 0.6px); }
}

/* ---------- Offset frame for Image blocks (0.4.0) ----------
   A block, outline or dashed outline the same size as the picture, shifted towards a corner and drawn behind it.
   --pbw-fr-x / --pbw-fr-y the shift, --pbw-fr-c colour, --pbw-fr-w outline width, --pbw-fr-r corner radius. */
.pbw-has-frame {
	position: relative;
	isolation: isolate;
}
.wp-block-image.pbw-has-frame:not(.alignfull):not(.alignwide) {
	width: fit-content;
	max-width: 100%;
}
.pbw-has-frame::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	pointer-events: none;
	box-sizing: border-box;
	translate: var(--pbw-fr-x, 20px) var(--pbw-fr-y, -20px);
	border-radius: var(--pbw-fr-r, 0);
	background: var(--pbw-fr-c, currentColor);
}
.pbw-fr-outline::after,
.pbw-fr-dashed::after {
	background: none;
	border: var(--pbw-fr-w, 4px) solid var(--pbw-fr-c, currentColor);
}
.pbw-fr-dashed::after { border-style: dashed; }
@media (max-width: 599px) {
	.pbw-has-frame::after { translate: calc(var(--pbw-fr-x, 20px) * 0.5) calc(var(--pbw-fr-y, -20px) * 0.5); }
}

/* ---------- Zoom (0.7.0) ----------
   The picture is scaled inside its frame. Image: the picture is also clipped back to its own box (a transform alone would
   spill over the page, and clipping the figure would cut off an offset frame). The clip is worked out from the zoom
   point, so it stays exact for any point. Cover: the block already hides what spills over. */
.wp-block-image.pbw-has-zoom img {
	transform: scale(var(--pbw-zm, 1));
	transform-origin: var(--pbw-zx, 50%) var(--pbw-zy, 50%);
	border-radius: 0;
	clip-path: inset(
		calc(var(--pbw-zyn, 0.5) * var(--pbw-zk, 0) * 100%)
		calc((1 - var(--pbw-zxn, 0.5)) * var(--pbw-zk, 0) * 100%)
		calc((1 - var(--pbw-zyn, 0.5)) * var(--pbw-zk, 0) * 100%)
		calc(var(--pbw-zxn, 0.5) * var(--pbw-zk, 0) * 100%)
		round calc(var(--pbw-zr, 0px) / var(--pbw-zm, 1))
	);
}
.wp-block-cover.pbw-has-zoom .wp-block-cover__image-background {
	transform: scale(var(--pbw-zm, 1));
	transform-origin: var(--pbw-zx, 50%) var(--pbw-zy, 50%);
}

/* ---------- Zoom for background pictures and Media & Text (0.8.0) ----------
   Group, Columns, Column: the picture is taken out of the block's own CSS background and drawn in a layer (.pbw-bg) that
   sits behind the content and behind the overlay. The outer box clips; the inner picture is scaled from the zoom point.
   (The block's background colour stays where it was. A site-plan grid on the same block is not drawn while the zoom is on.) */
.pbw-has-zoombg {
	position: relative;
	isolation: isolate;
	background-image: none !important;
}
.pbw-bg {
	position: absolute;
	inset: 0;
	z-index: -2;
	overflow: hidden;
	border-radius: inherit;
	pointer-events: none;
}
.pbw-bg__pic {
	position: absolute;
	inset: 0;
	background-repeat: no-repeat;
	background-size: cover;
	transform: scale(var(--pbw-zm, 1));
	transform-origin: var(--pbw-zx, 50%) var(--pbw-zy, 50%);
}

/* Media & Text: the picture is scaled inside its own column. */
.wp-block-media-text.pbw-has-zoom .wp-block-media-text__media {
	overflow: hidden;
}
.wp-block-media-text.pbw-has-zoom .wp-block-media-text__media img {
	transform: scale(var(--pbw-zm, 1));
	transform-origin: var(--pbw-zx, 50%) var(--pbw-zy, 50%);
}
/* older crop-to-fill markup: the layer replaces the figure's background (the img is hidden by WordPress) */
.wp-block-media-text.pbw-zoom-fig .wp-block-media-text__media {
	position: relative;
	isolation: isolate;
}
.wp-block-media-text.pbw-zoom-fig .wp-block-media-text__media .pbw-bg {
	z-index: 0;
}

/* Editor preview for a zoomed background (Group, Columns, Column). The front end uses a real layer (.pbw-bg); in the editor
   the block's ::before draws the zoomed picture, so a colour overlay on the same block moves to ::after while the zoom is on
   (a watermark shape on the same block is not previewed). */
.editor-styles-wrapper .pbw-edit-zoom {
	position: relative;
	isolation: isolate;
	overflow: clip;
	background-image: none !important;
}
.editor-styles-wrapper .pbw-edit-zoom::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -2;
	pointer-events: none;
	background-image: var(--pbw-zimg);
	background-position: var(--pbw-zpos, 50% 50%);
	background-size: cover;
	background-repeat: no-repeat;
	transform: scale(var(--pbw-zm, 1));
	transform-origin: var(--pbw-zx, 50%) var(--pbw-zy, 50%);
}
.editor-styles-wrapper .pbw-edit-zoom.pbw-has-overlay::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	border-radius: inherit;
	pointer-events: none;
	background: var(--pbw-mix);
}
.editor-styles-wrapper .pbw-edit-zoom.pbw-has-overlay {
	--pbw-mix: color-mix(in srgb, var(--pbw-ov-c, #000) calc(var(--pbw-ov-a, 0.4) * 100%), transparent);
}
.editor-styles-wrapper .pbw-edit-zoom.pbw-ov-bottom::after { background: linear-gradient(to top, var(--pbw-mix), transparent); }
.editor-styles-wrapper .pbw-edit-zoom.pbw-ov-top::after { background: linear-gradient(to bottom, var(--pbw-mix), transparent); }
/* The theme's "Watermark image" Group style lays the block's colour over the picture with its own ::before. While the zoom
   preview uses ::before for the picture, that colour layer is drawn on ::after instead. */
.editor-styles-wrapper .pbw-edit-zoom.is-style-watermark::before {
	background-color: transparent;
	opacity: 1;
}
.editor-styles-wrapper .pbw-edit-zoom.is-style-watermark::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 0;
	pointer-events: none;
	background: none;
	background-color: inherit;
	opacity: var(--pbb-wm, 0.85);
}

/* ---------- Divider on a Group that has content (0.8.2) ----------
   The same shapes, laid over the top or bottom edge of the Group instead of making it a thin strip. The Group keeps its own
   height, padding and margins. The shape sits above the content, so give the Group some padding at that edge. --pbw-st-h the
   height in px, --pbw-st-c the colour (usually the next section's), --pbw-st the shape. A watermark shape on the same Group
   also uses ::after, so use one or the other. */
.pbw-edge {
	position: relative;
	isolation: isolate;
}
.pbw-edge::after {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	z-index: 2;
	height: calc(var(--pbw-st-h, 80) * 1px + 1px);
	pointer-events: none;
	background: var(--pbw-st-c, currentColor);
	-webkit-mask: var(--pbw-st) center / 100% 100% no-repeat;
	mask: var(--pbw-st) center / 100% 100% no-repeat;
}
.pbw-edge-top::after { top: -1px; }
.pbw-edge-bottom::after { bottom: -1px; }
@media (max-width: 781px) {
	.pbw-edge::after { height: calc(var(--pbw-st-h, 80) * 0.6px + 1px); }
}

/* ---------- Overlap (0.8.3) ----------
   The block is pulled up over the one above it by --pbw-pull px (a negative top margin) and lifted above it. Does nothing
   on the first block of a container. Scaled down on phones. */
.pbw-overlap {
	position: relative;
	z-index: 1;
	margin-block-start: calc(var(--pbw-pull, 0) * -1px) !important;
}
@media (max-width: 781px) {
	.pbw-overlap { margin-block-start: calc(var(--pbw-pull, 0) * -0.6px) !important; }
}

/* ---------- Icon (0.9.0) ----------
   A small drawing in front of a Group's content. On the page it is a real <span><svg> (see pbw_render_icon). In the editor
   the same look is drawn on ::before (a picture in the colour chosen). Size --pbw-ic-s, colour --pbw-ic-c. */
.pbw-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: var(--pbw-ic-s, 28px);
	height: var(--pbw-ic-s, 28px);
	box-sizing: content-box;
	color: var(--pbw-ic-c, currentColor);
	margin-block: 0 var(--wp--preset--spacing--30, 0.75rem) !important;
	flex: none;
}
.pbw-icon svg { width: 100%; height: 100%; display: block; }
.pbw-icon--start { margin-inline: 0 auto !important; }
.pbw-icon--center { margin-inline: auto !important; }
.pbw-icon--soft-round,
.pbw-icon--soft-square,
.pbw-icon--solid-round,
.pbw-icon--solid-square { padding: calc(var(--pbw-ic-s, 28px) * 0.4); }
.pbw-icon--soft-round, .pbw-icon--solid-round { border-radius: 50%; }
.pbw-icon--soft-square, .pbw-icon--solid-square { border-radius: calc(var(--pbw-ic-s, 28px) * 0.3); }
.pbw-icon--soft-round, .pbw-icon--soft-square { background: color-mix(in srgb, var(--pbw-ic-c, currentColor) 14%, transparent); }
.pbw-icon--solid-round, .pbw-icon--solid-square { background: var(--pbw-ic-c, currentColor); color: var(--wp--preset--color--on-accent, #fff); }
.pbw-has-icon.has-text-align-center > .pbw-icon--start { margin-inline: auto !important; }

/* Editor preview */
.editor-styles-wrapper .pbw-edit-icon::before {
	content: "";
	display: block;
	width: var(--pbw-ic-s, 28px);
	height: var(--pbw-ic-s, 28px);
	box-sizing: content-box;
	margin: 0 0 var(--wp--preset--spacing--30, 0.75rem);
	background: var(--pbw-ic-url) center / var(--pbw-ic-fit, 100%) no-repeat var(--pbw-ic-bg, transparent);
	background-origin: content-box;
	padding: var(--pbw-ic-pad, 0);
	border-radius: var(--pbw-ic-r, 0);
}
.editor-styles-wrapper .pbw-edit-icon.pbw-edit-icon--center::before { margin-inline: auto; }
