/*
 * Useful links widget (inc/elementor/useful-links-widget.php): a grid of logos on hairlines.
 * Without .is-ready (no JavaScript) every cell is simply there. With it, cells come up one after the
 * other once, and the pointer carries a glow inside the cell it is over.
 * Colours come from tokens.css through data-theme; --kl-ground is the section's own ground.
 * Selectors carry .kl-links twice where the Elementor Kit styles headings and links.
 */

.kl-links {
	--kl-ground: var(--bg);
	--kl-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
	padding-block: var(--space-7);
	background: var(--kl-ground);
	color: var(--fg);
}
.kl-links--tint[data-theme] { --kl-ground: var(--bg-alt); background: var(--kl-ground); }

.kl-links__inner { max-width: var(--wrap-max); margin-inline: auto; padding-inline: var(--gutter); }

.kl-links__head { display: grid; gap: var(--space-3); margin-bottom: var(--space-5); }
.kl-links .kl-links__title { max-width: 18em; margin: 0; color: var(--heading); font-family: var(--font-serif); }
.kl-links .kl-links__text { max-width: 34em; margin: 0; color: var(--fg); }

/* Hairlines are the gaps between cells, over a ground of their own colour */
.kl-links__grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 1px;
	margin: 0;
	padding: 0;
	border: 1px solid var(--border);
	background: var(--border);
	list-style: none;
}

.kl-links__cell { display: block; background: var(--kl-ground); }

.kl-links.kl-links .kl-links__link {
	position: relative;
	display: grid;
	grid-template-rows: 1fr auto;
	justify-items: center;
	gap: var(--space-3);
	height: 100%;
	min-height: 160px;
	padding: var(--space-5) var(--space-3) var(--space-4);
	overflow: hidden;
	color: var(--fg-muted);
	text-decoration: none;
	isolation: isolate;
	transition: color 0.4s ease;
}

/* The pointer's glow, inside the cell */
.kl-links__link::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	background: radial-gradient(circle 160px at var(--mx, 50%) var(--my, 50%), color-mix(in srgb, var(--accent) 20%, transparent), transparent);
	opacity: 0;
	transition: opacity 0.5s ease;
}
/* The double frame of the shield, rising when the cell is looked at */
.kl-links__link::after {
	content: "";
	position: absolute;
	inset: 10px;
	border: 1px solid var(--accent);
	opacity: 0;
	transform: scale(1.06);
	transition: opacity 0.4s ease, transform 0.6s var(--kl-ease);
	pointer-events: none;
}
.kl-links a.kl-links__link:hover,
.kl-links a.kl-links__link:focus-visible { color: var(--fg); }
.kl-links a.kl-links__link:hover::before,
.kl-links a.kl-links__link:focus-visible::before { opacity: 1; }
.kl-links a.kl-links__link:hover::after,
.kl-links a.kl-links__link:focus-visible::after { opacity: 0.7; transform: none; }

/* The logo: a stamp in the colour of the ground, tones kept; a band of the accent crosses it on hover */
.kl-links__mark {
	align-self: center;
	width: min(100%, calc(76px * var(--kl-r, 1)));
	max-width: 84%;
	aspect-ratio: var(--kl-r, 1);
	background: linear-gradient(105deg, var(--fg) 0 40%, var(--accent) 50%, var(--fg) 60% 100%) 100% 0 / 280% 100%;
	opacity: 0.7;
	-webkit-mask: var(--kl-logo) center / contain no-repeat;
	mask: var(--kl-logo) center / contain no-repeat;
	-webkit-mask-source-type: luminance;
	mask-mode: luminance;
	transition: background-position 1s var(--kl-ease), opacity 0.4s ease;
}
.kl-links a.kl-links__link:hover .kl-links__mark,
.kl-links a.kl-links__link:focus-visible .kl-links__mark { background-position: 0 0; opacity: 1; }

/* Not a cut-out: the logo as it is, on a white plate */
.kl-links__mark--plate { max-width: 84%; padding: var(--space-1); background: var(--white); opacity: 0.85; -webkit-mask: none; mask: none; }
.kl-links__mark--plate img { display: block; width: 100%; height: auto; }

.kl-links .kl-links__name {
	max-width: 14em;
	font-size: 13px;
	line-height: 1.35;
	letter-spacing: 0.08em;
	text-align: center;
	text-transform: uppercase;
}

.kl-links__arrow {
	position: absolute;
	top: var(--space-3);
	right: var(--space-3);
	color: var(--accent);
	opacity: 0;
	transform: translate(-6px, 6px);
	transition: opacity 0.3s ease, transform 0.4s var(--kl-ease);
}
.kl-links a.kl-links__link:hover .kl-links__arrow,
.kl-links a.kl-links__link:focus-visible .kl-links__arrow { opacity: 1; transform: none; }

/* Cells come up one after the other, once */
.kl-links.is-ready .kl-links__cell { opacity: 0; transform: translateY(18px); }
.kl-links.is-ready.is-in .kl-links__cell {
	opacity: 1;
	transform: none;
	transition: opacity 0.8s ease calc(var(--i) * 80ms), transform 0.9s var(--kl-ease) calc(var(--i) * 80ms);
}

@media (min-width: 768px) {
	.kl-links__grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
	.kl-links__link { min-height: 190px; }
}
@media (min-width: 1024px) {
	.kl-links { padding-block: var(--space-8); }
	.kl-links__head { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: end; margin-bottom: var(--space-6); }
}

@media (prefers-reduced-motion: reduce) {
	.kl-links *, .kl-links *::before, .kl-links *::after { transition-duration: 0.01ms !important; transition-delay: 0s !important; }
}
