/*
 * Practice areas widget (inc/elementor/practice-areas-widget.php).
 * Without .is-ready (no JavaScript) the section is a plain nested list. With it, on wide screens,
 * the chapter names run down the left and the panel of the chapter in view stays beside them;
 * on tablets and phones the panels open under their names.
 * Colours come from tokens.css through data-theme. Selectors carry .kl-practice twice where the
 * Elementor Kit styles headings and links, so the section keeps its own colours.
 */

.kl-practice {
	--kl-rail: 40px;
	/* Width of the turn the thread makes into the button; the closing block is set in by as much */
	--kl-curve: 48px;
	--kl-delta: 104px;
	--kl-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
	--kl-panel-h: calc(100vh - var(--kl-header-h, 136px));
	position: relative;
	padding-block: var(--space-6);
	background: var(--bg-alt);
	color: var(--fg);
}

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

/* Lines. They may leave the section at the top, to cross into the section above. */
.kl-practice__thread,
.kl-practice__wires {
	display: none;
	overflow: visible;
	pointer-events: none;
}
.kl-practice.is-ready .kl-practice__thread {
	display: block;
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
}
.kl-practice__line {
	fill: none;
	stroke-width: 2;
}
.kl-practice__node {
	fill: var(--bg-alt);
	stroke: var(--rule);
	stroke-width: 1.5;
	transform-box: fill-box;
	transform-origin: center;
	transition: fill 0.4s linear, stroke 0.4s linear, transform 0.5s var(--kl-ease);
}
.kl-practice__node.is-passed { fill: var(--rule); }
.kl-practice__node.is-active {
	fill: var(--accent);
	stroke: var(--accent);
	transform: scale(1.5);
}
.kl-practice__tip { fill: var(--accent); }

.kl-practice__draw {
	fill: none;
	stroke-dasharray: 1;
	stroke-dashoffset: 1;
	transition: stroke-dashoffset 0.9s var(--kl-ease);
}
.kl-practice__draw.is-drawn { stroke-dashoffset: 0; }
.kl-practice__arcs,
.kl-practice__wire-set { transition: opacity 0.25s linear; }
.kl-practice__arcs.is-leaving,
.kl-practice__wire-set.is-leaving { opacity: 0; }
.kl-practice__arc {
	stroke: var(--eyebrow);
	stroke-width: 1;
}
.kl-practice__wire {
	stroke: var(--rule);
	stroke-width: 1.5;
}

/* Head */
.kl-practice__head { padding-left: var(--kl-rail); margin-bottom: var(--space-5); }
.kl-practice__closing { padding-left: calc(var(--kl-rail) + var(--kl-curve)); }

.kl-practice .kl-practice__eyebrow {
	margin: 0 0 var(--space-3);
	color: var(--eyebrow);
	font-size: var(--type-eyebrow-size);
	line-height: var(--type-eyebrow-line);
	font-weight: var(--type-eyebrow-weight);
	letter-spacing: var(--type-eyebrow-tracking);
	text-transform: uppercase;
}
.kl-practice .kl-practice__title {
	max-width: 18em;
	margin: 0;
	color: var(--heading);
	font-family: var(--font-serif);
}
.kl-practice .kl-practice__text {
	max-width: 34em;
	margin: var(--space-4) 0 0;
	color: var(--fg);
}

/* Chapter names */
.kl-practice__list {
	margin: 0;
	padding: 0;
	list-style: none;
}
.kl-practice__item { position: relative; }

.kl-practice .kl-practice__name {
	display: flex;
	align-items: center;
	min-height: 64px;
	margin: 0;
	padding: var(--space-3) 52px var(--space-3) var(--kl-rail);
	/* The hairline starts at the numeral, so the thread keeps its own space */
	border-top: 1px solid var(--border);
	border-image: linear-gradient(to right, transparent var(--kl-rail), var(--border) var(--kl-rail)) 1;
	font-family: var(--font-serif);
	font-size: var(--type-h3-mobile-size);
	line-height: var(--type-h3-mobile-line);
	font-weight: 500;
}
.kl-practice .kl-practice__name::after { content: none; }

.kl-practice .kl-practice__name a {
	display: grid;
	grid-template-columns: 2em minmax(0, 1fr);
	align-items: baseline;
	color: var(--fg);
	font: inherit;
	text-decoration: none;
	transition: color 0.4s linear;
}
.kl-practice .kl-practice__name a:hover { color: var(--heading); }

.kl-practice__num {
	color: var(--eyebrow);
	font-style: italic;
	font-weight: 400;
	/* The old-style 1 of EB Garamond reads as the letter I */
	font-variant-numeric: lining-nums;
}

/* Panel of a chapter */
.kl-practice__panel-inner { padding-left: calc(var(--kl-rail) + var(--type-h3-mobile-size) * 2); }
/* Spacing as content, not padding: a closed panel has to collapse to nothing */
.kl-practice__panel-inner::after {
	content: "";
	display: block;
	height: var(--space-4);
}

.kl-practice__big-num { display: none; }

.kl-practice .kl-practice__headline {
	margin: 0 0 var(--space-3);
	color: var(--fg-muted);
	font-style: italic;
}

.kl-practice__pages {
	margin: 0 0 var(--space-3);
	padding: 0;
	list-style: none;
}
.kl-practice__pages li { margin: 0; }

.kl-practice .kl-practice__pages a {
	display: block;
	padding-block: 6px;
	color: var(--fg);
	font-size: var(--type-body-size);
	line-height: 1.35;
	text-decoration: none;
}
.kl-practice .kl-practice__pages a span {
	background: linear-gradient(currentColor, currentColor) no-repeat 0 100% / 0 1px;
	transition: background-size 0.45s var(--kl-ease);
}
.kl-practice .kl-practice__pages a:hover { color: var(--heading); }
.kl-practice .kl-practice__pages a:hover span { background-size: 100% 1px; }

.kl-practice .kl-practice__more {
	display: inline-flex;
	align-items: center;
	gap: var(--space-2);
	min-height: 44px;
	color: var(--accent);
	font-size: var(--type-button-size);
	font-weight: var(--type-button-weight);
	letter-spacing: var(--type-menu-tracking, 0.08em);
	text-transform: uppercase;
	text-decoration: none;
}
.kl-practice .kl-practice__more:hover { color: var(--accent-hover); }
.kl-practice .kl-practice__more svg { flex: none; transition: transform 0.4s var(--kl-ease); }
.kl-practice .kl-practice__more:hover svg { transform: translateX(4px); }

.kl-practice .kl-practice__related {
	margin: var(--space-3) 0 0;
	padding-top: var(--space-3);
	border-top: 1px solid var(--border);
	color: var(--fg-muted);
	font-size: var(--type-caption-size);
	line-height: 1.5;
}
.kl-practice__related-label { display: block; margin-bottom: var(--space-1); }
.kl-practice .kl-practice__related a {
	color: var(--accent);
	text-underline-offset: 3px;
}
.kl-practice .kl-practice__related a:hover { color: var(--accent-hover); }
.kl-practice .kl-practice__related a:not(:last-child)::after {
	content: " · ";
	color: var(--fg-muted);
	display: inline-block;
	white-space: pre;
}

/* Closing: where the thread ends */
.kl-practice__closing { margin-top: var(--space-5); }
.kl-practice .kl-practice__closing-text {
	max-width: 30em;
	margin: 0 0 var(--space-4);
	color: var(--fg);
	font-size: var(--type-lead-size);
	line-height: var(--type-lead-line);
}
/* The button is the shared .btn of base.css */

.kl-practice__toggle { display: none; }

/* Tablets and phones: the thread in the left gutter, panels open under their names */
@media (max-width: 1023px) {
	.kl-practice.is-ready .kl-practice__toggle {
		position: absolute;
		top: 10px;
		right: 0;
		display: block;
		width: 44px;
		height: 44px;
		padding: 0;
		border: 0;
		border-radius: var(--radius-none);
		background: none;
		color: var(--accent);
		cursor: pointer;
	}
	.kl-practice__toggle::before,
	.kl-practice__toggle::after {
		content: "";
		position: absolute;
		top: 21px;
		left: 14px;
		width: 16px;
		height: 1.5px;
		background: currentColor;
		transition: transform 0.4s var(--kl-ease);
	}
	.kl-practice__toggle::after { transform: rotate(90deg); }
	.kl-practice__item.is-open .kl-practice__toggle::after { transform: rotate(0deg); }

	.kl-practice.is-ready .kl-practice__panel {
		display: grid;
		grid-template-rows: 0fr;
		visibility: hidden;
		transition: grid-template-rows 0.45s var(--kl-ease), visibility 0s linear 0.45s;
	}
	.kl-practice.is-ready .kl-practice__item.is-open .kl-practice__panel {
		grid-template-rows: 1fr;
		visibility: visible;
		transition: grid-template-rows 0.45s var(--kl-ease), visibility 0s;
	}
	.kl-practice.is-ready .kl-practice__panel-inner { min-height: 0; overflow: hidden; }

	.kl-practice.is-ready .kl-practice__item.is-active .kl-practice__name a { color: var(--heading); }
}

/* Wide screens: the panel stays in view while the names pass it */
@media (min-width: 1024px) {
	.kl-practice {
		--kl-rail: 72px;
		--kl-curve: 96px;
		padding-block: var(--space-8) 0;
	}

	.kl-practice:not(.is-ready) { padding-bottom: var(--space-8); }

	.kl-practice .kl-practice__name {
		min-height: clamp(84px, 11vh, 120px);
		padding-right: var(--space-5);
		font-size: var(--type-h2-size);
		line-height: var(--type-h2-line);
	}

	.kl-practice.is-ready .kl-practice__grid {
		display: grid;
		grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
		grid-template-rows: auto repeat(var(--kl-count), auto) auto;
	}
	.kl-practice.is-ready .kl-practice__head {
		grid-column: 1;
		grid-row: 1;
		margin-bottom: var(--space-6);
	}
	.kl-practice.is-ready .kl-practice__list,
	.kl-practice.is-ready .kl-practice__item { display: contents; }
	.kl-practice.is-ready .kl-practice__name {
		grid-column: 1;
		grid-row: var(--kl-row);
	}

	.kl-practice.is-ready .kl-practice__name a { color: var(--fg-muted); }
	.kl-practice.is-ready .kl-practice__item.is-passed .kl-practice__name a { color: var(--fg); }
	.kl-practice.is-ready .kl-practice__item.is-active .kl-practice__name a,
	.kl-practice.is-ready .kl-practice__name a:hover { color: var(--heading); }
	.kl-practice.is-ready .kl-practice__item.is-related .kl-practice__num { color: var(--heading); font-weight: 600; }

	.kl-practice.is-ready .kl-practice__panel,
	.kl-practice.is-ready .kl-practice__wires {
		grid-column: 2;
		grid-row: 1 / -1;
		position: sticky;
		top: var(--kl-header-h, 136px);
		align-self: start;
		height: var(--kl-panel-h);
	}
	.kl-practice.is-ready .kl-practice__wires {
		display: block;
		width: 100%;
	}

	.kl-practice.is-ready .kl-practice__panel {
		display: flex;
		align-items: center;
		visibility: hidden;
		padding-left: var(--kl-delta);
		pointer-events: none;
		transition: visibility 0s linear 0.25s;
	}
	.kl-practice.is-ready .kl-practice__item.is-shown .kl-practice__panel {
		visibility: visible;
		transition: visibility 0s;
	}
	.kl-practice.is-ready .kl-practice__panel-inner {
		width: 100%;
		padding: 0;
		pointer-events: auto;
	}
	.kl-practice.is-ready .kl-practice__panel-inner::after { content: none; }

	.kl-practice.is-ready .kl-practice__big-num {
		display: block;
		margin: 0 0 var(--space-2);
		color: var(--eyebrow);
		font-size: 72px;
		line-height: 1;
		font-style: italic;
		font-variant-numeric: lining-nums;
	}
	.kl-practice.is-ready .kl-practice__headline {
		margin-bottom: var(--space-4);
		font-size: var(--type-lead-size);
		line-height: 1.35;
	}

	/* Everything in the panel arrives one after the other, and leaves together */
	.kl-practice.is-ready .kl-practice__panel [style*="--i"] {
		opacity: 0;
		transform: translate3d(0, 10px, 0);
		transition: opacity 0.2s linear, transform 0s linear 0.2s;
	}
	.kl-practice.is-ready .kl-practice__item.is-shown .kl-practice__panel [style*="--i"] {
		opacity: 1;
		transform: none;
		transition:
			opacity 0.6s var(--kl-ease) calc(var(--i) * 45ms + 0.12s),
			transform 0.6s var(--kl-ease) calc(var(--i) * 45ms + 0.12s);
	}

	/* The rest of the height lets the last name reach the middle of the screen beside the panel */
	.kl-practice.is-ready .kl-practice__closing {
		grid-column: 1;
		grid-row: -2 / -1;
		min-height: calc(var(--kl-panel-h) / 2);
		margin: 0;
		padding-block: var(--space-6);
		border-top: 1px solid transparent;
		border-image: linear-gradient(to right, transparent var(--kl-rail), var(--border) var(--kl-rail)) 1;
	}
}

@media (min-width: 1024px) and (max-height: 760px) {
	.kl-practice.is-ready .kl-practice__big-num { display: none; }
}

@media (prefers-reduced-motion: reduce) {
	.kl-practice *,
	.kl-practice .kl-practice__panel [style*="--i"] {
		transition: none !important;
	}
}
