/* Heading (docs/widgets/heading.md), in the design language (spec §3.7). This is Soft, the default:
   highlighted words in the accent, the text above in a pale tint, an accent separator. The title's
   size and font come from the theme, by its tag. heading-outline.css and heading-solid.css change
   only the --hafe-heading-d-* tokens below, so a Style control's own property always wins over the
   design. A highlight style chosen in the Style tab sets the span's properties itself, which beats
   every design. */
.hafe-heading {
	--hafe-heading-d-hl: var(--hafe-accent-ink);
	--hafe-heading-d-hl-bg: transparent;
	--hafe-heading-d-hl-ink: var(--hafe-accent-ink);
	--hafe-heading-d-hl-pad: 0;
	--hafe-heading-d-hl-deco: none;
	--hafe-heading-d-above: var(--hafe-tint);
	--hafe-heading-d-above-ink: var(--hafe-accent-ink);
	--hafe-heading-d-above-line: transparent;
	--hafe-heading-d-icon: var(--hafe-tint);
	--hafe-heading-d-icon-ink: var(--hafe-accent-ink);
	--hafe-heading-d-icon-line: transparent;
	--hafe-heading-d-sep: var(--hafe-accent);
	--hafe-heading-d-sep-thick: 3px;
	--hafe-heading-d-back: color-mix(in srgb, var(--hafe-accent) 10%, transparent);
	--hafe-heading-d-back-fill: currentColor;
	--hafe-heading-d-back-stroke: 0;
	position: relative;
	isolation: isolate;
	display: flex;
	flex-direction: column;
	align-items: var(--hafe-heading-items, flex-start);
	gap: var(--hafe-heading-gap, 0.75em);
	text-align: var(--hafe-heading-align, start);
}

.hafe-scheme-dark .hafe-heading {
	--hafe-heading-d-back: color-mix(in srgb, var(--hafe-accent) 18%, transparent);
}

.hafe-heading__head,
.hafe-heading__group {
	display: flex;
	flex-direction: column;
	align-items: inherit;
	gap: inherit;
	margin: 0;
}

.hafe-heading__head {
	position: relative;
	max-inline-size: 100%;
}

.hafe-heading .hafe-heading__title {
	margin: 0;
	color: var(--hafe-heading-title-color, var(--hafe-ink));
}

/* A title that isn't a heading has no size from the theme, so it gets one. */
.hafe-heading p.hafe-heading__title,
.hafe-heading div.hafe-heading__title {
	font-size: 1.75em;
	font-weight: 700;
	line-height: 1.2;
}

.hafe-heading__title a {
	color: inherit;
	text-decoration: none;
}

.hafe-heading__title a:hover {
	color: var(--hafe-heading-title-hover-color, inherit);
	text-decoration: underline;
	text-decoration-thickness: 0.06em;
	text-underline-offset: 0.15em;
}

/* Title fills, from the Style tab: a gradient or outlined letters. */
.hafe-heading-fill-gradient .hafe-heading__title {
	background: linear-gradient(var(--hafe-heading-g-angle, 90deg), var(--hafe-heading-g1, var(--hafe-accent)), var(--hafe-heading-g2, var(--hafe-ink)));
	-webkit-background-clip: text;
	background-clip: text;
	-webkit-text-fill-color: transparent;
}

.hafe-heading-fill-outline .hafe-heading__title {
	-webkit-text-fill-color: transparent;
	-webkit-text-stroke: var(--hafe-heading-stroke, 1px) var(--hafe-heading-title-color, var(--hafe-ink));
}

.hafe-heading__hl {
	padding-inline: var(--hafe-heading-d-hl-pad);
	border-radius: 0.15em;
	background: var(--hafe-heading-hl-bg, var(--hafe-heading-d-hl-bg));
	color: var(--hafe-heading-hl-color, var(--hafe-heading-d-hl-ink));
	-webkit-text-fill-color: currentColor;
	text-decoration: var(--hafe-heading-d-hl-deco) var(--hafe-heading-hl-line, var(--hafe-heading-d-hl));
	text-decoration-thickness: 0.1em;
	text-underline-offset: 0.12em;
	-webkit-box-decoration-break: clone;
	box-decoration-break: clone;
}

/* Highlight styles, from the Style tab. */
.hafe-heading-hl-color .hafe-heading__hl,
.hafe-heading-hl-underline .hafe-heading__hl,
.hafe-heading-hl-outline .hafe-heading__hl,
.hafe-heading-hl-gradient .hafe-heading__hl {
	padding-inline: 0;
	background: none;
	text-decoration: none;
}

.hafe-heading-hl-color .hafe-heading__hl {
	color: var(--hafe-heading-hl-color, var(--hafe-accent-ink));
}

.hafe-heading-hl-underline .hafe-heading__hl {
	color: var(--hafe-heading-hl-color, inherit);
	text-decoration: underline var(--hafe-heading-hl-line, var(--hafe-accent));
	text-decoration-thickness: 0.1em;
}

.hafe-heading-hl-band .hafe-heading__hl {
	padding-inline: 0.2em;
	background: var(--hafe-heading-hl-bg, var(--hafe-accent));
	color: var(--hafe-heading-hl-color, var(--hafe-on-accent));
	text-decoration: none;
}

.hafe-heading-hl-outline .hafe-heading__hl {
	-webkit-text-fill-color: transparent;
	-webkit-text-stroke: max(1px, 0.03em) var(--hafe-heading-hl-color, var(--hafe-accent-ink));
}

.hafe-heading-hl-gradient .hafe-heading__hl {
	background: linear-gradient(var(--hafe-heading-hl-g-angle, 90deg), var(--hafe-heading-hl-g1, var(--hafe-accent)), var(--hafe-heading-hl-g2, var(--hafe-accent-ink)));
	-webkit-background-clip: text;
	background-clip: text;
	-webkit-text-fill-color: transparent;
}

.hafe-heading .hafe-heading__above {
	margin: 0;
	padding: 0.25em 0.8em;
	border: 1px solid var(--hafe-heading-above-line, var(--hafe-heading-d-above-line));
	border-radius: var(--hafe-pill);
	background: var(--hafe-heading-above-bg, var(--hafe-heading-d-above));
	color: var(--hafe-heading-above-color, var(--hafe-heading-d-above-ink));
	font-size: 0.85em;
	font-weight: 600;
	line-height: 1.4;
}

.hafe-heading-above-plain .hafe-heading__above {
	padding: 0;
	border: 0;
	background: none;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.hafe-heading__icon {
	display: flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	inline-size: calc(var(--hafe-heading-icon-size, 1.5em) * 2);
	block-size: calc(var(--hafe-heading-icon-size, 1.5em) * 2);
	border: 1px solid var(--hafe-heading-d-icon-line);
	border-radius: var(--hafe-radius-sm);
	background: var(--hafe-heading-icon-bg, var(--hafe-heading-d-icon));
	color: var(--hafe-heading-icon-color, var(--hafe-heading-d-icon-ink));
	font-size: var(--hafe-heading-icon-size, 1.5em);
	line-height: 1;
}

.hafe-heading__icon svg,
.hafe-heading__sep-icon svg {
	width: 1em;
	height: 1em;
	fill: currentColor;
}

.hafe-heading__sep {
	display: flex;
	align-items: center;
	gap: 0.6em;
	inline-size: var(--hafe-heading-sep-width, 3em);
	max-inline-size: 100%;
	color: var(--hafe-heading-sep-color, var(--hafe-heading-d-sep));
}

.hafe-heading__sep::before,
.hafe-heading__sep--icon::after {
	content: "";
	flex: 1;
	border-block-start: var(--hafe-heading-sep-thick, var(--hafe-heading-d-sep-thick)) var(--hafe-heading-sep-style, solid);
}

.hafe-heading__sep--icon {
	inline-size: var(--hafe-heading-sep-width, 9em);
}

/* A line beside the text above and the title: a border on their head. */
.hafe-heading--side .hafe-heading__head {
	padding-inline-start: 0.75em;
	border-inline-start: var(--hafe-heading-sep-thick, var(--hafe-heading-d-sep-thick)) var(--hafe-heading-sep-style, solid) var(--hafe-heading-sep-color, var(--hafe-heading-d-sep));
}

.hafe-heading__sep-icon {
	display: flex;
	color: var(--hafe-heading-sep-icon-color, inherit);
	font-size: var(--hafe-heading-sep-icon, 1em);
	line-height: 1;
}

.hafe-heading__text {
	max-inline-size: var(--hafe-heading-text-width, 40em);
	color: var(--hafe-heading-text-color, var(--hafe-ink-soft));
}

.hafe-heading__text a {
	text-decoration: underline;
}

.hafe-heading__text > :first-child {
	margin-block-start: 0;
}

.hafe-heading__text > :last-child {
	margin-block-end: 0;
}

/* Decoration behind the text above and the title, centred on them and cut at the widget's
   sides, so a long word never makes the page scroll sideways. */
.hafe-heading--back {
	overflow-x: clip;
	overflow-clip-margin: 0.5em;
}

.hafe-heading__back {
	position: absolute;
	z-index: -1;
	inset-block-start: 50%;
	inset-inline: 0;
	display: flex;
	justify-content: var(--hafe-heading-items, flex-start);
	color: var(--hafe-heading-back-color, var(--hafe-heading-d-back));
	-webkit-text-fill-color: var(--hafe-heading-d-back-fill);
	-webkit-text-stroke: var(--hafe-heading-d-back-stroke) currentColor;
	font-size: 5em;
	font-weight: 800;
	line-height: 1;
	white-space: nowrap;
	transform: translateY(-50%);
	pointer-events: none;
	user-select: none;
}

.hafe-empty {
	margin: 0;
	padding: 1em;
	border: 1px dashed currentColor;
	opacity: 0.7;
}

/* Windows high contrast: every letter in the system's text colour, with no fill tricks. */
@media (forced-colors: active) {
	.hafe-heading__title,
	.hafe-heading__hl {
		background: none;
		-webkit-text-fill-color: currentColor;
		-webkit-text-stroke: 0;
	}

	.hafe-heading__back {
		display: none;
	}
}
