/* Timeline (docs/widgets/timeline.md), in the design language (spec §3.7): raised cards with their own colours,
   markers and labels in tints of the accent, and a quiet connector. The tokens come from design.css.

   One stylesheet draws every layout. The widget's Layout control writes a set of custom properties
   per breakpoint, for the columns and for which column and row each part takes. The connector's
   position and length are sums weighted by --hafe-timeline-x (1 when horizontal) and
   --hafe-timeline-at (where the line sits across the item: 0 start, 0.5 middle, 1 end). Without
   the control (no generated CSS yet), the fallbacks give the line-first layout, which fits any width. */

/* Lengths the connector is computed from, resolved once on the list, so a marker with its own font
   size still lines up with its connector. */
@property --hafe-timeline-m {
	syntax: "<length>";
	inherits: true;
	initial-value: 32px;
}

@property --hafe-timeline-g {
	syntax: "<length>";
	inherits: true;
	initial-value: 32px;
}

@property --hafe-timeline-lw {
	syntax: "<length>";
	inherits: true;
	initial-value: 2px;
}

@property --hafe-timeline-lg {
	syntax: "<length>";
	inherits: true;
	initial-value: 4px;
}

.hafe-timeline__items {
	--hafe-timeline-m: var(--hafe-timeline-marker-size, 2em);
	--hafe-timeline-g: var(--hafe-timeline-gap, 2em);
	--hafe-timeline-lw: var(--hafe-timeline-line-width, 2px);
	--hafe-timeline-lg: var(--hafe-timeline-line-gap, 0.25em);
	display: grid;
	grid-auto-columns: var(--hafe-timeline-auto, minmax(0, 1fr));
	grid-auto-flow: var(--hafe-timeline-flow, row);
	gap: var(--hafe-timeline-g);
	--hafe-timeline-room-now: calc(var(--hafe-timeline-x, 0) * var(--hafe-timeline-room, 1em));
	margin: 0;
	/* The bottom has more room: the cards' shadow falls downward. */
	padding: var(--hafe-timeline-room-now) var(--hafe-timeline-room-now) calc(2.25 * var(--hafe-timeline-room-now));
	scroll-padding-inline: var(--hafe-timeline-room-now);
	overflow-x: var(--hafe-timeline-overflow, visible);
	list-style: none;
	scroll-snap-type: var(--hafe-timeline-snap, none);
	scrollbar-width: thin;
}

.hafe-timeline__items > .hafe-timeline__item {
	position: relative;
	display: grid;
	grid-template-columns: var(--hafe-timeline-cols, auto minmax(0, 1fr));
	grid-template-rows: var(--hafe-timeline-rows, none);
	grid-auto-rows: auto;
	align-content: start;
	gap: 0.5em var(--hafe-timeline-marker-gap, 1em);
	min-width: 0;
	margin: 0;
	padding: 0;
	scroll-snap-align: start;
}

/* The connector runs from this marker to the next one. */
.hafe-timeline__items > .hafe-timeline__item:not(:last-child)::after {
	--hafe-timeline-x-now: var(--hafe-timeline-x, 0);
	--hafe-timeline-len: calc(100% + var(--hafe-timeline-g) - var(--hafe-timeline-m) - 2 * var(--hafe-timeline-lg));
	content: "";
	position: absolute;
	box-sizing: content-box;
	inset-block-start: calc((1 - var(--hafe-timeline-x-now)) * (var(--hafe-timeline-m) + var(--hafe-timeline-lg)) + var(--hafe-timeline-x-now) * (var(--hafe-timeline-m) - var(--hafe-timeline-lw)) / 2);
	inset-inline-start: calc(var(--hafe-timeline-x-now) * (var(--hafe-timeline-m) + var(--hafe-timeline-lg)) + (1 - var(--hafe-timeline-x-now)) * (var(--hafe-timeline-at, 0) * 100% + (1 - 2 * var(--hafe-timeline-at, 0)) * var(--hafe-timeline-m) / 2 - var(--hafe-timeline-lw) / 2));
	inline-size: calc(var(--hafe-timeline-x-now) * var(--hafe-timeline-len));
	block-size: calc((1 - var(--hafe-timeline-x-now)) * var(--hafe-timeline-len));
	border: 0 var(--hafe-timeline-line-style, solid) var(--hafe-timeline-item-color, var(--hafe-timeline-line-color, var(--hafe-line)));
	border-block-start-width: calc(var(--hafe-timeline-x-now) * var(--hafe-timeline-lw));
	border-inline-start-width: calc((1 - var(--hafe-timeline-x-now)) * var(--hafe-timeline-lw));
	pointer-events: none;
}

.hafe-timeline__marker {
	--hafe-timeline-marker-now: var(--hafe-timeline-item-color, var(--hafe-timeline-marker-color, var(--hafe-accent)));
	box-sizing: border-box;
	display: flex;
	grid-column: var(--hafe-timeline-marker-col, 1);
	grid-row: var(--hafe-timeline-marker-row, 1 / span 2);
	align-items: center;
	justify-content: center;
	align-self: start;
	inline-size: var(--hafe-timeline-m);
	block-size: var(--hafe-timeline-m);
	overflow: hidden;
	border: var(--hafe-timeline-marker-border-width, 0) solid var(--hafe-timeline-marker-now);
	border-radius: var(--hafe-timeline-marker-radius, 50%);
	background: var(--hafe-timeline-marker-bg, color-mix(in srgb, var(--hafe-timeline-marker-now) 14%, transparent));
	color: var(--hafe-timeline-marker-now);
	font-weight: 700;
	line-height: 1;
	transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}

.hafe-timeline__item:hover .hafe-timeline__marker,
.hafe-timeline__item:focus-within .hafe-timeline__marker {
	--hafe-timeline-marker-now: var(--hafe-timeline-marker-hover-color, var(--hafe-timeline-item-color, var(--hafe-timeline-marker-color, var(--hafe-accent))));
	background: var(--hafe-timeline-marker-hover-bg, var(--hafe-timeline-marker-bg, color-mix(in srgb, var(--hafe-timeline-marker-now) 24%, transparent)));
}

/* The dot is the marker's middle, so its box stays the same size as the others and lines still meet. */
.hafe-timeline__marker--dot {
	border-color: transparent;
}

.hafe-timeline__marker--dot::before {
	content: "";
	inline-size: 42%;
	block-size: 42%;
	border-radius: inherit;
	background: currentColor;
}

.hafe-timeline__marker svg {
	width: var(--hafe-timeline-icon-size, 1em);
	height: var(--hafe-timeline-icon-size, 1em);
	fill: currentColor;
}

.hafe-timeline__marker i {
	font-size: var(--hafe-timeline-icon-size, 1em);
}

/* The first line of a label is centred on its marker. */
.hafe-timeline .hafe-timeline__label {
	grid-column: var(--hafe-timeline-label-odd, 2);
	grid-row: var(--hafe-timeline-label-row, 1);
	min-block-size: calc((1 - var(--hafe-timeline-x, 0)) * var(--hafe-timeline-m));
	margin: 0;
	padding-block-start: max(0px, calc((1 - var(--hafe-timeline-x, 0)) * (var(--hafe-timeline-m) - 1lh - 0.6em) / 2));
	color: var(--hafe-timeline-item-color, var(--hafe-timeline-label-color, var(--hafe-accent-ink)));
	font-weight: 600;
	text-align: var(--hafe-timeline-align-odd, start);
}

/* The label is a pill in a tint of its own colour. */
.hafe-timeline__tag {
	display: inline-block;
	padding: 0.3em 0.9em;
	border-radius: var(--hafe-pill);
	background: color-mix(in srgb, currentColor 12%, var(--hafe-surface));
}

.hafe-timeline__sublabel {
	display: block;
	margin-block-start: 0.35em;
	color: var(--hafe-timeline-sublabel-color, var(--hafe-ink-soft));
	font-size: 0.85em;
	font-weight: 400;
}

.hafe-timeline__item:nth-child(even) .hafe-timeline__label {
	grid-column: var(--hafe-timeline-label-even, 2);
	text-align: var(--hafe-timeline-align-even, start);
}

.hafe-timeline__card {
	box-sizing: border-box;
	grid-column: var(--hafe-timeline-odd, 2);
	grid-row: var(--hafe-timeline-card-row, 2);
	min-width: 0;
	padding: var(--hafe-timeline-card-padding, 1.5em);
	border: var(--hafe-timeline-card-border-width, 1px) solid var(--hafe-timeline-card-border, var(--hafe-line));
	border-radius: var(--hafe-timeline-card-radius, var(--hafe-radius));
	background: var(--hafe-timeline-card-bg, var(--hafe-surface));
	color: var(--hafe-ink);
	box-shadow: var(--hafe-shadow);
	text-align: var(--hafe-timeline-card-align, start);
}

.hafe-timeline__item:nth-child(even) .hafe-timeline__card {
	grid-column: var(--hafe-timeline-even, 2);
}

.hafe-timeline .hafe-timeline__image {
	display: block;
	width: var(--hafe-timeline-image-width, auto);
	max-width: 100%;
	height: auto;
	margin-block-end: var(--hafe-timeline-image-gap, 0.75em);
	margin-inline: var(--hafe-timeline-image-start, 0) var(--hafe-timeline-image-end, auto);
	--hafe-img-radius: var(--hafe-timeline-image-radius, var(--hafe-radius-sm));
}

.hafe-timeline .hafe-timeline__image:last-child {
	margin-block-end: 0;
}

/* The tag says what a title is to the page, and themes size tags very differently, so the title's
   size follows the text around it until the Style tab says otherwise. */
.hafe-timeline .hafe-timeline__title {
	margin: 0 0 var(--hafe-timeline-title-gap, 0.35em);
	color: var(--hafe-timeline-title-color, inherit);
	font-size: 1.15em;
	font-weight: 600;
}

.hafe-timeline__title:last-child {
	--hafe-timeline-title-gap: 0;
}

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

.hafe-timeline__title a:hover {
	color: var(--hafe-timeline-title-hover-color, inherit);
	text-decoration: underline;
}

.hafe-timeline__title a:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.hafe-timeline__text {
	color: var(--hafe-timeline-text-color, var(--hafe-ink-soft));
}

/* Links in a description stand out by more than colour (WCAG 1.4.1), whatever the theme does. */
.hafe-timeline__text a {
	text-decoration: underline;
}

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

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

/* The horizontal layout's arrows. The script shows them when there's something to scroll. */
.hafe-timeline__nav {
	display: flex;
	justify-content: flex-end;
	gap: 0.5em;
	margin-block-end: 0.75em;
}

.hafe-timeline__nav[hidden] {
	display: none;
}

.hafe-timeline .hafe-timeline__arrow,
.hafe-timeline .hafe-timeline__arrow:is(:hover, :focus) {
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: center;
	inline-size: var(--hafe-timeline-arrow-size, 2.75rem);
	block-size: var(--hafe-timeline-arrow-size, 2.75rem);
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--hafe-timeline-arrow-bg, var(--hafe-surface));
	color: var(--hafe-timeline-arrow-color, var(--hafe-ink));
	box-shadow: var(--hafe-ring);
	cursor: pointer;
}

.hafe-timeline .hafe-timeline__arrow:hover {
	background: var(--hafe-timeline-arrow-hover-bg, var(--hafe-tint));
	color: var(--hafe-timeline-arrow-hover-color, var(--hafe-accent-ink));
}

.hafe-timeline .hafe-timeline__arrow:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.hafe-timeline .hafe-timeline__arrow[aria-disabled="true"] {
	opacity: 0.4;
	cursor: default;
}

.hafe-timeline__arrow svg {
	width: 1.25em;
	height: 1.25em;
}

.hafe-timeline__arrow:dir(rtl) svg {
	transform: scaleX(-1);
}

.hafe-timeline__items:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

/* The reveal. Only the script adds this class, so without it nothing is ever hidden. */
.hafe-timeline.is-revealing .hafe-timeline__item {
	transition: opacity 0.5s ease, transform 0.5s ease;
}

.hafe-timeline.is-revealing .hafe-timeline__item:not(.is-seen) {
	opacity: 0;
}

.hafe-timeline.is-revealing[data-reveal="slide"] .hafe-timeline__item:not(.is-seen) {
	transform: translateY(1.5em);
}

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

@media (prefers-reduced-motion: reduce) {
	.hafe-timeline__marker {
		transition: none;
	}
}

/* Paper can't scroll, and needs every item: the line-first layout, whatever the screen shows. */
@media print {
	.hafe-timeline {
		--hafe-timeline-x: 0;
		--hafe-timeline-flow: row;
		--hafe-timeline-auto: minmax(0, 1fr);
		--hafe-timeline-overflow: visible;
		--hafe-timeline-snap: none;
		--hafe-timeline-rows: none;
		--hafe-timeline-at: 0;
		--hafe-timeline-cols: auto minmax(0, 1fr);
		--hafe-timeline-marker-col: 1;
		--hafe-timeline-marker-row: 1 / span 2;
		--hafe-timeline-odd: 2;
		--hafe-timeline-even: 2;
		--hafe-timeline-label-odd: 2;
		--hafe-timeline-label-even: 2;
		--hafe-timeline-label-row: 1;
		--hafe-timeline-card-row: 2;
		--hafe-timeline-align-odd: var(--hafe-timeline-card-align, start);
		--hafe-timeline-align-even: var(--hafe-timeline-card-align, start);
	}

	.hafe-timeline__nav {
		display: none;
	}

	.hafe-timeline__items > .hafe-timeline__item {
		break-inside: avoid;
	}

	.hafe-timeline.is-revealing .hafe-timeline__item:not(.is-seen) {
		opacity: 1;
		transform: none;
	}
}
