/* Reusable HTML5 / iframe advertising display components.
   Ads render at their real intended pixel dimensions — never stretched. */

/**
 * A real <iframe> can't be told to "fit" a container the way an image
 * can — it has hard pixel width/height. So the frame renders at true
 * size by default, and where the outer .ad-frame is narrower than the
 * ad's native width (a 970×250 billboard on a 390px viewport, say),
 * assets/js/main.js measures the available space and applies a CSS
 * transform: scale() to the whole native-sized ad, then resizes this
 * wrapper to the resulting scaled footprint so layout doesn't overflow.
 * --ad-scale defaults to 1 (full size) until JS runs.
 */
.ad-frame {
	--ad-w: 300px;
	--ad-h: 250px;
	--ad-ratio: 300 / 250;
	--ad-scale: 1;
	display: inline-block;
	width: var(--ad-w);
	max-width: 100%;
	background: var(--ad-bg, #1a1a1a);
}

.ad-frame__inner {
	width: 100%;
	/* The format's proportions, so the wrapper matches the creative's scaled
	   footprint rather than its unscaled native height.

	   --ad-ratio is a plain unitless ratio written by the PHP component.
	   --ad-w/--ad-h cannot serve here: they carry px units (needed for the
	   width/height/transform math below) and `calc(var(--ad-w) / 1px)` —
	   dividing a length by a length — is not supported, so that form computed
	   to `auto` and reserved nothing. An iframe hid the problem, having hard
	   pixel width and height of its own; the wrapper then took that unscaled
	   height, clipping the creative wherever --ad-scale was above 1 and leaving
	   a dead-space gap wherever it was below (a 970×250 on mobile, say). */
	aspect-ratio: var(--ad-ratio);
	overflow: hidden;
	position: relative;
}

.ad-frame iframe {
	width: var(--ad-w);
	height: var(--ad-h);
	border: 0;
	display: block;
	transform: scale(var(--ad-scale));
	transform-origin: top left;
}

/* An HTML5 example can be a recording of the creative instead of the live
   creative. It is the same example in the same box — a 300x250 shown as video
   still occupies a 300x250 — so it takes no geometry of its own and simply
   fills .ad-frame__inner, whose --ad-ratio has already reserved the format's
   exact proportions before any video byte is fetched. Nothing shifts as the
   file loads.

   object-fit: cover keeps the format's proportions if a recording is slightly
   off the nominal ratio; the box never changes shape to suit the file. No
   --ad-scale here: unlike an iframe, which has hard pixel dimensions and must
   be transformed, a video scales on its own. */
.ad-frame__video {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
	border: 0;
	background: var(--ad-bg, #1a1a1a);
}

.ad-frame__label {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: var(--space-2xs);
	padding: var(--space-2xs) 0.1em;
	font-size: var(--size-small);
	color: var(--color-fg-dim);
}

.ad-frame__label span:first-child {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.ad-grid {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-md);
	align-items: flex-start;
	justify-content: center;
}

/* Below the site's mobile breakpoint, oversized banner formats (a
   970×250 billboard, say) shrink to fit the viewport instead of
   forcing horizontal scroll — main.js computes --ad-scale so the
   fixed-size iframe inside is visually scaled to match, never
   stretched or cropped. Desktop always renders ads at true size. */
@media (max-width: 899px) {
	.ad-frame {
		width: 100%;
		max-width: var(--ad-w);
	}
}

/* A still of the creative, behind the live one.
   The frame only gets a real src while it is on screen, and none at all
   without JavaScript, so a poster is what stands in for it in the meantime.
   It is covered the instant the creative loads — hence the stacking order
   rather than a swap, which would need a load handler and could flicker. */
.ad-frame__poster {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
}

.ad-frame iframe {
	position: relative;
	z-index: 1;
}

/* Replay. Added by main.js and hidden until it is, so a control that cannot
   work never reaches the page — see the [data-ad-replay] block there. */
.ad-frame__controls {
	display: flex;
	justify-content: flex-end;
	padding-top: var(--space-2xs);
}

.ad-frame__replay {
	appearance: none;
	background: none;
	border: 1px solid var(--color-line);
	border-radius: var(--radius-pill);
	color: var(--color-fg-dim);
	font: inherit;
	font-size: var(--size-label);
	letter-spacing: 0;
	text-transform: none; /* Direction C: no capitals */
	padding: 0.35em 1em;
	cursor: pointer;
	transition: color var(--duration-fast) var(--ease-out),
		border-color var(--duration-fast) var(--ease-out);
}

.ad-frame__replay:hover,
.ad-frame__replay:focus-visible {
	color: var(--color-fg);
	border-color: var(--color-fg-faint);
}
