/**
 * Promo tile.
 *
 * Everything is scoped under .gc-promo and nothing reads a theme token, so the
 * tile looks the same on a stock storefront as it does on a custom theme. A
 * theme that wants it to match its own type and color sets the custom
 * properties below and changes nothing else.
 *
 * The breakpoint is 782px and is written out rather than kept in a custom
 * property, because a media query cannot read one. It matches the width the
 * markup's picture source uses, so the two move together only if both are
 * edited together.
 */

.gc-promo {
	--gc-promo-bar-bg: #1a1a1a;
	--gc-promo-bar-fg: #ffffff;
	--gc-promo-accent: #c00000;
	--gc-promo-overline-font: inherit;
	--gc-promo-heading-font: inherit;
	--gc-promo-radius: 0;

	list-style: none;
	position: relative;
}

/* The tile fills its grid row rather than sitting to its natural height, so a
   row of product cards and a promo line up along the bottom. */
.gc-promo,
.gc-promo .gc-promo__link {
	height: 100%;
}

.gc-promo .gc-promo__link {
	display: flex;
	flex-direction: column;
	text-decoration: none;
	color: var(--gc-promo-bar-fg);
	background: var(--gc-promo-bar-bg);
	border-radius: var(--gc-promo-radius);
	overflow: hidden;
}

.gc-promo .gc-promo__link:hover,
.gc-promo .gc-promo__link:focus {
	text-decoration: none;
	color: var(--gc-promo-bar-fg);
}

.gc-promo .gc-promo__link:focus-visible {
	outline: 2px solid var(--gc-promo-accent);
	outline-offset: 2px;
}

/*
 * The media box carries the aspect ratio so the slot has its full height
 * before any image loads and before the pool script runs. Without this the
 * grid would settle twice.
 *
 * 2 / 3 comes off the mockup rather than being chosen: the tile there is
 * 485 by 882 with a 143px bar, leaving a 485 by 739 image, which is 0.656
 * against 0.667 for a clean two to three. It is a ratio rather than a fixed
 * height so the tile still stretches to whatever height the theme's grid row
 * ends up being.
 */
.gc-promo .gc-promo__media {
	display: block;
	position: relative;
	width: 100%;
	aspect-ratio: 2 / 3;
	overflow: hidden;
	background: #e9e9e9;
	flex: 1 1 auto;
}

.gc-promo .gc-promo__media picture {
	display: block;
	height: 100%;
}

/*
 * The image is taken out of flow and pinned to the frame.
 *
 * This is structural rather than a specificity fight, because the fight is not
 * winnable by ordinary means: WooCommerce ships
 *   .woocommerce ul.products li.product a img { width: 100%; height: auto }
 * at three classes and four elements, and a promo tile is inside that exact
 * selector because it carries the product class to inherit the grid. A plain
 * .gc-promo .gc-promo__img loses on specificity, height falls back to auto,
 * and a landscape image renders at its own ratio with the frame showing
 * underneath it. A portrait image happens to overflow the frame instead, which
 * is why the bug hides until someone picks a wide photograph.
 *
 * Pinned with inset 0, height: auto no longer means anything: the top and
 * bottom offsets decide the height whatever the height property says, so the
 * theme rule can win and be harmless. object-fit then has a box to fill.
 *
 * The selector is still raised above WooCommerce's on class count as a second
 * line of defence, so width and object-fit are not relying on the same trick.
 */
.gc-promo.product .gc-promo__media .gc-promo__img {
	display: block;
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: cover;
	/* object-position is set inline from the promo's focal point. */
}

/*
 * The bar is 16.2% of the tile in the mockup (143px of 882) with 27px of side
 * padding on a 485px tile, which is 5.6%. At the 300px card the plugin is
 * built around that is 16px, so the padding is literal and the height is left
 * to the type inside it rather than being forced.
 */
.gc-promo .gc-promo__bar {
	display: block;
	padding: 12px 16px 16px;
	background: var(--gc-promo-bar-bg);
	color: var(--gc-promo-bar-fg);
	flex: 0 0 auto;
}

/*
 * Italic by default so a script or display face dropped in through
 * --gc-promo-overline-font sits correctly without needing a second rule to
 * turn the italic off again.
 */
.gc-promo .gc-promo__overline {
	display: block;
	font-family: var(--gc-promo-overline-font);
	font-size: .875rem;
	font-style: italic;
	letter-spacing: .06em;
	text-transform: uppercase;
	line-height: 1.25;
	margin: 0 0 2px;
	color: var(--gc-promo-accent);
}

.gc-promo .gc-promo__headline {
	display: block;
	font-family: var(--gc-promo-heading-font);
	font-size: 1.125rem;
	font-weight: 700;
	line-height: 1.2;
	margin: 0;
}

.gc-promo .gc-promo__chevron {
	display: inline-block;
	width: 8px;
	height: 13px;
	margin-left: .35em;
	vertical-align: baseline;
}

.gc-promo .gc-promo__subline {
	display: block;
	font-size: .8125rem;
	line-height: 1.35;
	margin: 4px 0 0;
	opacity: .85;
}

.gc-promo .gc-promo__overline[hidden],
.gc-promo .gc-promo__subline[hidden] {
	display: none;
}

/* The admin preview tile is the same markup without the product class, so it
   needs the pinning too. */
.gc-promo .gc-promo__media .gc-promo__img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	max-width: none;
	object-fit: cover;
}

/* The shortcode's own list, for a tile placed outside a product grid. */
.gc-promos-shortcode {
	margin: 0;
	padding: 0;
	list-style: none;
}

@media (max-width: 782px) {
	.gc-promo .gc-promo__bar {
		padding: 12px 12px 14px;
	}

	.gc-promo .gc-promo__headline {
		font-size: 1rem;
	}

	.gc-promo .gc-promo__subline {
		font-size: .75rem;
	}
}

/* ---------------------------------------------------------------- Per promo style
   A promo can set its own fonts, colors and type treatment from a palette the
   theme registers. Everything below is a fallback chain: the promo's own
   property first, then the tile level property the theme layer sets, then the
   plugin's plain default. A promo that sets nothing therefore renders exactly
   as it did before any of this existed.

   Every selector in this section carries .gc-promo on top of what it would
   otherwise need, which makes it three classes rather than two. A theme fills
   in the plugin's defaults with rules like .gc-promo .gc-promo__overline, and
   those are two classes loaded after this file, so at equal weight the theme
   won and a choice made on the promo itself did nothing. A theme default and
   an editor's explicit choice are not the same kind of statement, and they
   must not be settled by source order. The three carriers immediately below
   have no modifier class to compound with, so the root class is repeated to
   reach the same weight. */

.gc-promo.gc-promo .gc-promo__overline {
	font-family: var(--gc-promo-overline-font-own, var(--gc-promo-overline-font));
	color: var(--gc-promo-overline-color, var(--gc-promo-accent));
}

.gc-promo.gc-promo .gc-promo__headline {
	font-family: var(--gc-promo-headline-font-own, var(--gc-promo-heading-font));
	color: var(--gc-promo-headline-color, inherit);
}

.gc-promo.gc-promo .gc-promo__subline {
	font-family: var(--gc-promo-subline-font-own, inherit);
	color: var(--gc-promo-subline-color, inherit);
}

/* Size steps. Relative to the line's own default rather than absolute, so a
   theme that has already scaled its type keeps its proportions. */
.gc-promo.gc-promo--overline-s .gc-promo__overline { font-size: .75rem; }
.gc-promo.gc-promo--overline-m .gc-promo__overline { font-size: .875rem; }
.gc-promo.gc-promo--overline-l .gc-promo__overline { font-size: 1.125rem; }

.gc-promo.gc-promo--headline-s .gc-promo__headline { font-size: 1rem; }
.gc-promo.gc-promo--headline-m .gc-promo__headline { font-size: 1.125rem; }
.gc-promo.gc-promo--headline-l .gc-promo__headline { font-size: 1.5rem; }

.gc-promo.gc-promo--subline-s .gc-promo__subline { font-size: .75rem; }
.gc-promo.gc-promo--subline-m .gc-promo__subline { font-size: .8125rem; }
.gc-promo.gc-promo--subline-l .gc-promo__subline { font-size: 1rem; }

.gc-promo.gc-promo--overline-normal .gc-promo__overline { font-weight: 400; }
.gc-promo.gc-promo--overline-bold   .gc-promo__overline { font-weight: 700; }
.gc-promo.gc-promo--headline-normal .gc-promo__headline { font-weight: 400; }
.gc-promo.gc-promo--headline-bold   .gc-promo__headline { font-weight: 700; }
.gc-promo.gc-promo--subline-normal  .gc-promo__subline  { font-weight: 400; }
.gc-promo.gc-promo--subline-bold    .gc-promo__subline  { font-weight: 700; }

.gc-promo.gc-promo--overline-italic .gc-promo__overline { font-style: italic; }
.gc-promo.gc-promo--headline-italic .gc-promo__headline { font-style: italic; }
.gc-promo.gc-promo--subline-italic  .gc-promo__subline  { font-style: italic; }

/* The overline is uppercase by default, so its class has to be able to turn
   the transform off as well as on. The other two default to none. */
.gc-promo.gc-promo--overline-caps .gc-promo__overline { text-transform: uppercase; }
.gc-promo.gc-promo--headline-caps .gc-promo__headline { text-transform: uppercase; }
.gc-promo.gc-promo--subline-caps  .gc-promo__subline  { text-transform: uppercase; }

/* Overlay layout: the text sits over the bottom of the picture on a gradient
   rather than under it on a solid bar. The gradient is drawn from the bar
   color so a promo that changes one changes both. */
.gc-promo.gc-promo--overlay .gc-promo__link {
	position: relative;
	background: none;
}

.gc-promo.gc-promo--overlay .gc-promo__media {
	aspect-ratio: auto;
	height: 100%;
}

.gc-promo.gc-promo--overlay .gc-promo__bar {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	/* Solid behind the type and faded only across the padding above it, so
	   the overline holds the same contrast it has on the plain bar however
	   light the photograph is. The fade used to start at the bottom edge,
	   which left the top line of text on about 70%. */
	background: linear-gradient(
		to top,
		var(--gc-promo-bar-bg) 0%,
		var(--gc-promo-bar-bg) calc(100% - 36px),
		color-mix(in srgb, var(--gc-promo-bar-bg) 70%, transparent) calc(100% - 20px),
		transparent 100%
	);
	padding-top: 44px;
}

/* color-mix is recent. Where it is missing the gradient falls back to a flat
   wash of the bar color, which is less pretty and still readable. */
@supports not (background: color-mix(in srgb, #000 50%, transparent)) {
	.gc-promo.gc-promo--overlay .gc-promo__bar {
		background: var(--gc-promo-bar-bg);
		opacity: .92;
	}
}
