/**
 * Inoforest Step Cards
 *
 * Contents
 * 1. Defaults (variables), icon styles
 * 2. List and steps
 * 3. Connector line
 * 4. Icon and number badge
 * 5. Title, text and link
 * 6. Editor hint, reduced motion, responsive
 *
 * Colours read the Design System (--inoforest-color-*) with fallbacks. The defaults sit in :where() blocks (no
 * specificity), so the Style tab controls, which set the same variables on the widget, always win.
 *
 * The Columns control also sets the layout switches (class.php, selectors_dictionary): --ino-sc-v is 1 when the steps
 * stack in one column (vertical connector, 50 px row gap, 460 px centred column, 20 px above and below each step) and
 * 0 otherwise (horizontal connector).
 */

/* 1. Defaults ------------------------------------------------------------------ */
:where(.inoforest-step-cards) {
	--ino-sc-columns: 3;
	--ino-sc-v: 0;
	--ino-sc-gap: 40px;
	--ino-sc-auto-row-gap: var(--ino-sc-gap);
	--ino-sc-max: none;
	--ino-sc-item-py: 0px;
	--ino-sc-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
	--ino-sc-primary: var(--inoforest-color-primary, #0b7a75);
	--ino-sc-accent: var(--inoforest-color-accent, #ff6a3d);
	--ino-sc-white: var(--inoforest-color-background, #fff);

	/* Alignment (centre). */
	--ino-sc-icon-x: 50%;
	--ino-sc-self: center;
	--ino-sc-text-ml: auto;
	--ino-sc-text-mr: auto;

	/* Icon circle: Outline (default style). */
	--ino-sc-icon-box: 110px;
	--ino-sc-icon-size: 42px;
	--ino-sc-icon-gap: 28px;
	--ino-sc-icon-border-width: 1px;
	--ino-sc-icon-color: var(--ino-sc-primary);
	--ino-sc-icon-bg: var(--ino-sc-white);
	--ino-sc-icon-border: var(--inoforest-color-border, #e5ebef);
	--ino-sc-icon-hover-color: #fff;
	--ino-sc-icon-hover-bg: var(--ino-sc-primary);
	--ino-sc-icon-hover-border: var(--ino-sc-icon-border);
	--ino-sc-icon-hover-y: -6px;

	/* Number badge. */
	--ino-sc-number-size: 38px;
	--ino-sc-number-color: #fff;
	--ino-sc-number-bg: var(--ino-sc-accent);
	--ino-sc-number-border-width: 3px;
	--ino-sc-number-border: var(--ino-sc-white);

	/* Connector. */
	--ino-sc-line-width: 2px;
	--ino-sc-line-style: dashed;
	--ino-sc-line-color: rgba(11, 122, 117, 0.28);
	--ino-sc-line-color: color-mix(in srgb, var(--ino-sc-primary) 28%, transparent);
	--ino-sc-line-offset: 0px;

	/* Text. */
	--ino-sc-title-color: var(--inoforest-color-heading, #0d1b2a);
	--ino-sc-text-color: var(--inoforest-color-text, #5a6a79);
	--ino-sc-text-max: 330px;
	--ino-sc-link-color: var(--ino-sc-primary);
	--ino-sc-link-hover-color: var(--ino-sc-accent);
	--ino-sc-link-gap: 18px;
}

/* Filled: a coloured circle with a white icon; accent on hover. */
:where(.inoforest-step-cards[data-icon-style="filled"]) {
	--ino-sc-icon-color: #fff;
	--ino-sc-icon-bg: var(--ino-sc-primary);
	--ino-sc-icon-border: var(--ino-sc-primary);
	--ino-sc-icon-hover-bg: var(--ino-sc-accent);
	--ino-sc-icon-hover-border: var(--ino-sc-accent);
}

/* 2. List and steps ------------------------------------------------------------------ */
.inoforest-step-cards .inoforest-step-cards__list {
	--ino-sc-rg: var(--ino-sc-row-gap, var(--ino-sc-auto-row-gap));
	display: grid;
	grid-template-columns: repeat(var(--ino-sc-columns), minmax(0, 1fr));
	gap: var(--ino-sc-rg) var(--ino-sc-gap);
	max-width: var(--ino-sc-max);
	margin: 0 auto;
	padding: 0;
	list-style: none;
}

.inoforest-step-cards__item {
	position: relative;
	display: var(--ino-sc-item-display, flex);
	flex-direction: column;
	grid-template-columns: var(--ino-sc-item-cols, none);
	align-content: var(--ino-sc-item-align, normal);
	column-gap: var(--ino-sc-icon-gap);
	min-width: 0;
	margin: 0;
	padding: var(--ino-sc-item-py) 0;
	color: var(--ino-sc-text-color);
	text-align: center;
	list-style: none;
}

/* 3. Connector line -------------------------------------------------------------------
   Drawn by each step towards the next one, so it needs no background behind the icons: across from circle edge to
   circle edge (horizontal), or through the row gap below the step (stacked). The last step of each row draws none:
   --ino-sc-kN is 0 on every Nth step when there are N columns. */
.inoforest-step-cards__item:nth-child(2n) { --ino-sc-k2: clamp(0, max(var(--ino-sc-columns) - 2, 2 - var(--ino-sc-columns)), 1); }
.inoforest-step-cards__item:nth-child(3n) { --ino-sc-k3: clamp(0, max(var(--ino-sc-columns) - 3, 3 - var(--ino-sc-columns)), 1); }
.inoforest-step-cards__item:nth-child(4n) { --ino-sc-k4: clamp(0, max(var(--ino-sc-columns) - 4, 4 - var(--ino-sc-columns)), 1); }
.inoforest-step-cards__item:nth-child(5n) { --ino-sc-k5: clamp(0, max(var(--ino-sc-columns) - 5, 5 - var(--ino-sc-columns)), 1); }
.inoforest-step-cards__item:nth-child(6n) { --ino-sc-k6: clamp(0, max(var(--ino-sc-columns) - 6, 6 - var(--ino-sc-columns)), 1); }

.inoforest-step-cards[data-connector="yes"] .inoforest-step-cards__item:not(:last-child)::after {
	--ino-sc-k: calc(var(--ino-sc-k2, 1) * var(--ino-sc-k3, 1) * var(--ino-sc-k4, 1) * var(--ino-sc-k5, 1) * var(--ino-sc-k6, 1));
	/* Three layouts, one of them 1: across (H), down between stacked steps (V), down behind icons beside the text (B). */
	--ino-sc-bb: var(--ino-sc-b, 0);
	--ino-sc-vv: calc(var(--ino-sc-v) * (1 - var(--ino-sc-bb)));
	--ino-sc-h: calc((1 - var(--ino-sc-v)) * (1 - var(--ino-sc-bb)));
	--ino-sc-on: var(--ino-sc-line-on, 1);
	position: absolute;
	top: calc(var(--ino-sc-vv) * (100% + var(--ino-sc-line-offset)) + var(--ino-sc-h) * (var(--ino-sc-pt, var(--ino-sc-item-py)) + var(--ino-sc-icon-box) / 2 - var(--ino-sc-line-width) / 2) + var(--ino-sc-bb) * 50%);
	left: calc((var(--ino-sc-vv) + var(--ino-sc-bb)) * (var(--ino-sc-icon-x) - var(--ino-sc-line-width) / 2) + var(--ino-sc-h) * (var(--ino-sc-icon-x) + var(--ino-sc-icon-box) / 2 + var(--ino-sc-line-offset)));
	width: calc(var(--ino-sc-on) * var(--ino-sc-h) * var(--ino-sc-k) * (100% + var(--ino-sc-gap) - var(--ino-sc-icon-box) - 2 * var(--ino-sc-line-offset)));
	height: calc(var(--ino-sc-on) * (var(--ino-sc-vv) * (var(--ino-sc-rg) - 2 * var(--ino-sc-line-offset)) + var(--ino-sc-bb) * (100% + var(--ino-sc-rg))));
	content: "";
	border: 0 var(--ino-sc-line-style) var(--ino-sc-line-color);
	border-top-width: calc(var(--ino-sc-on) * var(--ino-sc-h) * var(--ino-sc-line-width));
	border-left-width: calc(var(--ino-sc-on) * (var(--ino-sc-vv) + var(--ino-sc-bb)) * var(--ino-sc-line-width));
	pointer-events: none;
}

/* 4. Icon and number badge -------------------------------------------------------------- */
/* Icon beside the text (--ino-sc-b: 1): the icon spans the title, text and link rows of the second column. */
.inoforest-step-cards__item > :not(.inoforest-step-cards__icon) {
	grid-column: var(--ino-sc-body-col, auto);
}

.inoforest-step-cards__icon {
	position: relative;
	z-index: 1;
	grid-row: var(--ino-sc-icon-row, auto);
	display: grid;
	flex: none;
	place-items: center;
	align-self: var(--ino-sc-self);
	box-sizing: border-box;
	width: var(--ino-sc-icon-box);
	height: var(--ino-sc-icon-box);
	margin-bottom: var(--ino-sc-icon-mb, var(--ino-sc-icon-gap));
	font-size: var(--ino-sc-icon-size);
	line-height: 1;
	color: var(--ino-sc-icon-color);
	background-color: var(--ino-sc-icon-bg);
	border: var(--ino-sc-icon-border-width) solid var(--ino-sc-icon-border);
	border-radius: 50%;
	box-shadow: 0 6px 20px rgba(13, 27, 42, 0.07);
	transition: background-color 0.35s var(--ino-sc-ease), border-color 0.35s var(--ino-sc-ease), color 0.35s var(--ino-sc-ease), transform 0.35s var(--ino-sc-ease);
}

.inoforest-step-cards__icon > i {
	line-height: 1;
}

.inoforest-step-cards__icon > svg {
	width: 1em;
	height: 1em;
	fill: currentColor;
}

/* li + two pseudo-classes: above the Normal controls, below the Hover controls. */
li.inoforest-step-cards__item:hover .inoforest-step-cards__icon,
li.inoforest-step-cards__item:focus-within .inoforest-step-cards__icon {
	color: var(--ino-sc-icon-hover-color);
	background-color: var(--ino-sc-icon-hover-bg);
	border-color: var(--ino-sc-icon-hover-border);
	transform: translateY(var(--ino-sc-icon-hover-y));
}

.inoforest-step-cards__number {
	position: absolute;
	top: -4px;
	right: -4px;
	display: grid;
	place-items: center;
	box-sizing: border-box;
	width: var(--ino-sc-number-size);
	height: var(--ino-sc-number-size);
	background-color: var(--ino-sc-number-bg);
	border: var(--ino-sc-number-border-width) solid var(--ino-sc-number-border);
	border-radius: 50%;
}

.inoforest-step-cards .inoforest-step-cards__number {
	font-size: 0.85rem;
	font-weight: 800;
	line-height: 1;
	color: var(--ino-sc-number-color);
}

/* 5. Title, text and link ------------------------------------------------------------ */
.inoforest-step-cards .inoforest-step-cards__title {
	margin: 0 0 10px;
	font-size: 1.3rem;
	font-weight: 800;
	line-height: 1.2;
	letter-spacing: -0.02em;
	color: var(--ino-sc-title-color);
}

.inoforest-step-cards .inoforest-step-cards__text {
	max-width: var(--ino-sc-text-max);
	margin: 0 var(--ino-sc-text-mr) 0 var(--ino-sc-text-ml);
	font-size: 1rem;
	line-height: 1.75;
	color: inherit;
}

.inoforest-step-cards__footer {
	margin-top: auto;
	padding-top: var(--ino-sc-link-gap);
}

.inoforest-step-cards .inoforest-step-cards__link {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-weight: 700;
	line-height: 1.5;
	color: var(--ino-sc-link-color);
	text-decoration: none;
	transition: color 0.35s var(--ino-sc-ease), background-color 0.35s var(--ino-sc-ease), box-shadow 0.35s var(--ino-sc-ease);
}

.inoforest-step-cards__link i,
.inoforest-step-cards__link svg {
	font-size: 0.9em;
	transition: transform 0.35s var(--ino-sc-ease);
}

.inoforest-step-cards__link svg {
	width: 0.9em;
	height: 0.9em;
	fill: currentColor;
}

/* a + class: above the Normal colour control, below the Hover controls. */
.inoforest-step-cards a.inoforest-step-cards__link:hover,
.inoforest-step-cards a.inoforest-step-cards__link:focus-visible {
	color: var(--ino-sc-link-hover-color);
}

.inoforest-step-cards__link:hover i,
.inoforest-step-cards__link:hover svg,
.inoforest-step-cards__link:focus-visible i,
.inoforest-step-cards__link:focus-visible svg {
	transform: translateX(4px);
}

/* 6. Editor hint, reduced motion, responsive ------------------------------------------- */
.inoforest-step-cards__hint {
	margin: 0;
	padding: 16px;
	font-size: 0.85rem;
	text-align: center;
	border: 1px dashed currentColor;
	opacity: 0.7;
}

@media (prefers-reduced-motion: reduce) {
	.inoforest-step-cards__icon,
	.inoforest-step-cards .inoforest-step-cards__link,
	.inoforest-step-cards__link i,
	.inoforest-step-cards__link svg {
		transition: none;
	}
}

@media (max-width: 767px) {
	.inoforest-step-cards .inoforest-step-cards__text {
		font-size: 0.9375rem;
	}
}
