/* ub/device: a laptop or phone drawn in CSS around one core/image (no image files). Sizes follow the
   block's width (container units), so it works from about 200 to 900 px wide; give it a width with
   the block's Width setting or its parent. The editor and the site share this DOM:
   .wp-block-ub-device > figure.wp-block-image > (a >) img.
   Settings: [data-frame="laptop"|"phone"], [data-scroll="true"], [data-shadow="true"].
   Theme hooks: --ub-device-bezel, --ub-device-rim (laptop), --ub-device-body (laptop base),
   --ub-device-metal, --ub-device-key, --ub-device-screen (phone, below), --ub-scroll-time;
   .ub-device-host on any ancestor (a portfolio card) starts the scroll when that is hovered or focused. */

.wp-block-ub-device {
	--ub-bezel-color: var(--ub-device-bezel, #10141b);
	--ub-rim-color: var(--ub-device-rim, #3b4452);
	container: ub-device / inline-size;
	position: relative;
	box-sizing: border-box;
	max-inline-size: 100%;
}

/* The screen: the image block's figure, with the bezel as its border */
.wp-block-ub-device > .wp-block-image {
	position: relative;
	box-sizing: border-box;
	margin: 0 auto;
	overflow: hidden;
	border: var(--ub-bezel, 1.6cqi) solid var(--ub-bezel-color);
	border-radius: var(--ub-radius, 2cqi);
	background: var(--ub-bezel-color);
	box-shadow: 0 0 0 max(1px, 0.35cqi) var(--ub-rim-color);
}
.wp-block-ub-device img,
.wp-block-ub-device .components-resizable-box__container {
	display: block;
	inline-size: 100% !important;
	max-inline-size: none !important;
	block-size: auto !important;
}
.wp-block-ub-device img {
	aspect-ratio: var(--ub-screen-ratio) !important; /* the screen; the image keeps its width/height attributes */
	object-fit: cover !important;
	object-position: 50% 0;
	border: 0 !important;
	border-radius: 0 !important;
	box-shadow: none !important;
}
/* A caption would sit inside the bezel: kept for screen readers only */
.wp-block-ub-device figcaption {
	position: absolute !important; inline-size: 1px; block-size: 1px; margin: -1px; padding: 0;
	overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
/* A linked screenshot: the focus ring inside the screen (outside, the bezel's overflow cuts it) */
.wp-block-ub-device a:focus-visible { outline-offset: -4px !important; }

/* Laptop: a 16:10 screen with a thin bezel and a camera, on a base as wide as the block */
.wp-block-ub-device[data-frame="laptop"] {
	--ub-screen-ratio: 16 / 10;
	--ub-radius: 2.2cqi 2.2cqi 0.8cqi 0.8cqi;
}
.wp-block-ub-device[data-frame="laptop"] > .wp-block-image {
	inline-size: 86%;
	border-width: 1.5cqi 1.3cqi 2.2cqi;
}
.wp-block-ub-device[data-frame="laptop"]::before { /* the camera */
	content: "";
	position: absolute;
	z-index: 1;
	inset-block-start: 0.45cqi;
	inset-inline-start: 50%;
	inline-size: 0.6cqi;
	block-size: 0.6cqi;
	border-radius: 50%;
	background: #2b3442;
	translate: -50% 0;
}
.wp-block-ub-device[data-frame="laptop"]::after { /* the base, with the opening's notch */
	content: "";
	display: block;
	block-size: 2.4cqi;
	border-radius: 0.3cqi 0.3cqi 2cqi 2cqi / 0.3cqi 0.3cqi 1.6cqi 1.6cqi;
	background:
		linear-gradient(#8e96a2, #aab1bb) 50% 0 / 13% 0.9cqi no-repeat,
		linear-gradient(var(--ub-device-body, #d5d9df), #b3bac4 55%, #8f97a3);
}

/* Phone, after the reference Paul liked (2026-11-02, exports/tmp/phone-mockup-zip/preview.png): a thin
   graphite rim with a light-to-dark edge, the black bezel, the side buttons (action and two volume buttons
   on the left, power on the right) and, with `shadow`, a soft floor shadow. Proportions measured on the
   reference, as shares of the phone's width (cqi): rim 2, bezel 3, corner 14.5. The rim is the figure's
   border (a gradient under a transparent border), the bezel its padding; the screen is the image, rounded,
   the site's page starting right at the screen's top edge (Tomi, 2026-11-03: "imaginea cu site-ul până în
   rama de sus a telefonului"; QA round 1 had given it a dark status bar of its own). No camera island
   (Tomi, 2026-11-03, through Paul: "they're not real phones anyway"): nothing covers the page's top.
   Theme hooks: --ub-device-metal and --ub-device-key (images, e.g. a linear-gradient: the rim and the
   buttons), --ub-device-screen (a colour: the status bar). */
.wp-block-ub-device[data-frame="phone"] {
	--ub-screen-ratio: 9 / 19.5;
	--ub-rim: max(1.5px, 2cqi);
	--ub-bezel: 3cqi;
	--ub-radius: 14.5cqi;
	--ub-key: max(1.5px, 0.75cqi); /* how far the side buttons stand out */
	--ub-key-color: var(--ub-device-key, linear-gradient(90deg, #454b53, #868d96 55%, #5a6169));
	--ub-metal: var(--ub-device-metal, linear-gradient(155deg, #c5cad1 0%, #737a83 16%, #3b4047 42%, #2f343a 62%, #6a7179 86%, #a9afb7 100%));
	isolation: isolate; /* the buttons and the floor shadow sit behind the body, in front of the page */
}
.wp-block-ub-device[data-frame="phone"] > .wp-block-image {
	padding: var(--ub-bezel);
	border: var(--ub-rim) solid transparent;
	border-radius: var(--ub-radius);
	background: linear-gradient(var(--ub-bezel-color) 0 0) padding-box, var(--ub-metal) border-box;
	/* a dark hairline outside the rim, a faint light one inside it: the rim's bevel */
	box-shadow: 0 0 0 max(0.5px, 0.2cqi) rgb(0 0 0 / 0.5), inset 0 0 0 max(0.5px, 0.3cqi) rgb(255 255 255 / 0.1);
}
.wp-block-ub-device[data-frame="phone"] img {
	box-sizing: border-box;
	border-radius: calc(var(--ub-radius) - var(--ub-rim) - var(--ub-bezel)) !important;
	background: var(--ub-device-screen, #1d2128);
}
.wp-block-ub-device[data-frame="phone"]::after { /* the side buttons; with `shadow`, the floor shadow */
	--ub-key-w: calc(var(--ub-key) + 1cqi); /* 1cqi tucked under the rim */
	content: "";
	position: absolute;
	z-index: -1;
	inset-block: 0 calc(-1 * var(--ub-floor-room, 0px));
	inset-inline: calc(-1 * var(--ub-key));
	pointer-events: none;
	background:
		var(--ub-floor, none) 50% 100% / 104% 5cqi no-repeat,
		var(--ub-key-color) 0 32.3cqi / var(--ub-key-w) 7.8cqi no-repeat,
		var(--ub-key-color) 0 46.9cqi / var(--ub-key-w) 15.6cqi no-repeat,
		var(--ub-key-color) 0 66.7cqi / var(--ub-key-w) 15.6cqi no-repeat,
		var(--ub-key-color) 100% 52.4cqi / var(--ub-key-w) 24.5cqi no-repeat;
}

/* Shadow (the theme's "lifted" shadow when it has one) */
.wp-block-ub-device[data-shadow="true"] > .wp-block-image {
	box-shadow: 0 0 0 max(1px, 0.35cqi) var(--ub-rim-color), var(--wp--preset--shadow--lifted, 0 1.5rem 3rem -1rem rgb(0 20 45 / 0.35));
}
.wp-block-ub-device[data-shadow="true"][data-frame="laptop"]::after {
	box-shadow: 0 1.2cqi 2.4cqi -0.6cqi rgb(0 20 45 / 0.35);
}

/* The phone's shadow: soft and close under the body, and a floor shadow a little below it */
.wp-block-ub-device[data-frame="phone"][data-shadow="true"] {
	--ub-floor: radial-gradient(closest-side, rgb(0 20 45 / 0.42), rgb(0 20 45 / 0.16) 55%, rgb(0 20 45 / 0));
	--ub-floor-room: 9cqi;
}
.wp-block-ub-device[data-frame="phone"][data-shadow="true"] > .wp-block-image {
	box-shadow: 0 0 0 max(0.5px, 0.2cqi) rgb(0 0 0 / 0.5), inset 0 0 0 max(0.5px, 0.3cqi) rgb(255 255 255 / 0.1), 0 2cqi 6cqi -2cqi rgb(0 20 45 / 0.35);
}

/* The page scrolls inside the screen while the pointer is over it (or focus is inside): only with a
   mouse or trackpad, only when motion is allowed. Back to the top on leave. */
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
	html:not([data-ub-motion="off"]) .wp-block-ub-device[data-scroll="true"] img {
		transition: object-position 1.2s ease-in-out;
	}
	html:not([data-ub-motion="off"]) .wp-block-ub-device[data-scroll="true"]:is(:hover, :focus-within) img,
	html:not([data-ub-motion="off"]) .ub-device-host:is(:hover, :focus-within) .wp-block-ub-device[data-scroll="true"] img {
		object-position: 50% 100%;
		transition-duration: var(--ub-scroll-time, 6s);
	}
}
