/* ==========================================================================
   Timeline Block
   ==========================================================================

   Structure
   ---------
   .timeline               — Outer wrapper.
   .timeline__title        — Centered section heading.
   .timeline__list         — 2-column grid (left items / right items).
   .timeline__spine        — The vertical center line. A real grid item
                              (grid-column: 1 / -1, centered via
                              justify-self), not an absolutely-positioned
                              overlay — spanning `1 / -1` for *columns* is
                              safe because grid-template-columns declares
                              them explicitly. Its `grid-row` (inline style,
                              set in template.php) ends at the start of the
                              last item's row rather than `-1`/the container
                              bottom, so it stops at the last milestone
                              instead of running through that item's own
                              description text; `height` then overflows a
                              small fixed amount past that row boundary to
                              reach the last dot exactly.
   .timeline__item         — One milestone; modifier sets which side it's on.
                              Each item gets an explicit inline `grid-row`
                              (set in template.php) so consecutive milestones
                              stack in DOM order down the spine — without it,
                              grid auto-placement packs two items into the
                              same row whenever a same-row cell is free,
                              pairing left/right instead of interleaving them.
   .timeline__header       — Date badge + connector line/dot, one row.
   .timeline__connector    — Bleeds out of the item's column into the gutter
                              so its line always reaches the spine, however
                              long or short that gap needs to be.
   .timeline__date         — The highlighter-style date badge.
   .timeline__dot          — White circle with a colored ring, sits next to
                              the date at the connector's inner end.
   .timeline__description  — Body copy under the header.
   ========================================================================== */

.timeline {
	/* 9.375rem (150px) total gap between the two item columns, split evenly
	   by the spine sitting in the middle — 75px of clear space from the
	   spine to each item, enough room for a visible connector line. */
	--timeline-gutter: 9.375rem;
	--timeline-line-width: 4px;
	--timeline-min-stagger: 5.625rem; /* 90px — static minimum, not scaled */
	/* How far the spine overflows past the start of the last item's row to
	   reach that item's dot — the row-gap plus roughly half the date
	   badge's height (badge height is what sets a header's height, and is
	   effectively constant regardless of description length). */
	--timeline-spine-overhang: 3.81rem;
	/* How far down the first row the spine starts, so it begins at the first
	   item's connector (half the date badge's height, less half the line's
	   thickness so the spine's top meets the connector's top edge rather
	   than leaving a gap above the corner). */
	--timeline-spine-start: calc( 2.2rem - ( var( --timeline-line-width ) / 2 ) );
}

.timeline__title {
	margin: 0 0 3.5rem;
	font-family: var( --wp--preset--font-family--gotham );
	font-size: clamp( 1.75rem, 1.2rem + 2vw, 2.75rem );
	font-weight: 800;
	text-transform: uppercase;
	text-align: center;
	color: var( --wp--preset--color--dark-green );
}

.is-style-dark .timeline__title,
.is-style-circle-dark-green .timeline__title {
	color: var( --wp--preset--color--white );
}

/* ── Grid + spine ──────────────────────────────────────────────────────── */

.timeline__list {
	display: grid;
	grid-template-columns: 1fr 1fr;
	column-gap: var( --timeline-gutter );
	row-gap: 1.5rem;
	/* Each milestone occupies its own explicit row (see template.php), so
	   this is really "minimum height per milestone" — the static, unscaled
	   vertical stagger between consecutive points on the spine. */
	grid-auto-rows: minmax( var( --timeline-min-stagger ), auto );
}

.timeline__spine {
	grid-column: 1 / -1;
	justify-self: center;
	width: var( --timeline-line-width );
	/* Overflows past its own grid area on purpose — see the note above. */
	margin-top: var( --timeline-spine-start );
	height: calc( 100% + var( --timeline-spine-overhang ) - var( --timeline-spine-start ) );
	background: var( --wp--preset--color--dark-green );
}

.is-style-dark .timeline__spine {
	background: var( --wp--preset--color--lime-green );
}

/* ── Items ─────────────────────────────────────────────────────────────── */

.timeline__item {
	min-width: 0;
}

.timeline__item--left {
	grid-column: 1;
}

.timeline__item--right {
	grid-column: 2;
}

.timeline__header {
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

/* Left items: date starts at the column's outer edge; the connector is
   flex:1 so it stretches to fill whatever's left of the column, then
   bleeds past the column edge into the gutter to touch the spine (which
   sits exactly in the middle of the gap between the two equal columns). */
.timeline__item--left .timeline__header {
	width: calc( 100% + ( var( --timeline-gutter ) / 2 ) );
}

.timeline__item--left .timeline__connector {
	flex: 1 1 auto;
}

/* Right items: the connector is a fixed-width bridge from the spine to the
   date, and the header only bleeds left by that same fixed amount — the
   date itself sits close to the spine rather than at the column's far edge. */
.timeline__item--right .timeline__header {
	width: fit-content;
	margin-left: calc( -1 * ( var( --timeline-gutter ) / 2 ) );
}

.timeline__item--right .timeline__connector {
	flex: 0 0 auto;
	width: calc( var( --timeline-gutter ) / 2 );
}

.timeline__connector {
	display: flex;
	align-items: center;
}

.timeline__line {
	flex: 1 1 auto;
	height: var( --timeline-line-width );
	background: var( --wp--preset--color--dark-green );
}

.is-style-dark .timeline__line {
	background: var( --wp--preset--color--lime-green );
}

.timeline__dot {
	flex: 0 0 auto;
	width: 16px;
	height: 16px;
	box-sizing: border-box;
	border: 4px solid var( --wp--preset--color--dark-green );
	border-radius: 50%;
	background: var( --wp--preset--color--white );
}

.is-style-dark .timeline__dot {
	border-color: var( --wp--preset--color--lime-green );
}

/* ── Date badge ────────────────────────────────────────────────────────── */

.timeline__date {
	flex: 0 0 auto;
	display: inline-block;
	padding: 0.15em 0.4em;
	font-family: var( --wp--preset--font-family--gotham );
	font-size: 3.125rem; /* 50px */
	font-weight: 800;
	line-height: 1.1;
	color: var( --wp--preset--color--white );
	background: var( --wp--preset--color--dark-green );
}

.is-style-dark .timeline__date,
.is-style-circle-dark-green .timeline__date {
	background: var( --wp--preset--color--lime-green );
	color: var( --wp--preset--color--dark-green );
}

/* ── Description ───────────────────────────────────────────────────────── */

.timeline__description {
	margin: 1rem 0 0;
	font-size: 1.125rem; /* 18px */
	color: var( --wp--preset--color--black );
}

.is-style-dark .timeline__description,
.is-style-circle-dark-green .timeline__description {
	color: var( --wp--preset--color--white );
}

/* ── Mobile: collapse to a single left-anchored column ────────────────── */

@media ( max-width: 781px ) {
	.timeline {
		/* Recalculated for the smaller mobile row-gap and badge font-size
		   set below (see the desktop --timeline-spine-overhang comment). */
		--timeline-spine-overhang: 4.2rem;
		--timeline-spine-start: calc( 1.575rem - ( var( --timeline-line-width ) / 2 ) );
	}

	.timeline {
		--timeline-mobile-gap: 1.25rem;
	}

	.timeline__list {
		grid-template-columns: var( --timeline-line-width ) 1fr;
		column-gap: var( --timeline-mobile-gap );
		/* Single column is already sequential — no minimum stagger needed. */
		grid-auto-rows: auto;
		row-gap: 2.5rem;
	}

	.timeline__spine {
		grid-column: 1;
		justify-self: stretch;
	}

	.timeline__item--left,
	.timeline__item--right {
		grid-column: 2;
	}

	/* Both sides render as "connector, then date" so the line always reads
	   from the spine (now on the left) outward to the date. Right items
	   already have that DOM order; left items are visually reordered
	   (via `order`, not row-reverse, so they still pack against the left
	   edge instead of the right) to match, including their connector's
	   internal dot/line order. The header bleeds left by the column-gap
	   (same bleed technique as the desktop connectors) so the connector
	   actually reaches the spine instead of stopping at its own column's
	   edge, leaving a visible break across the gap. */
	.timeline__item--left .timeline__header,
	.timeline__item--right .timeline__header {
		width: calc( 100% + var( --timeline-mobile-gap ) );
		margin-left: calc( -1 * var( --timeline-mobile-gap ) );
	}

	.timeline__item--left .timeline__connector,
	.timeline__item--right .timeline__connector {
		flex: 0 0 auto;
		width: var( --timeline-mobile-gap );
	}

	.timeline__item--left .timeline__connector {
		order: -1;
	}

	.timeline__item--left .timeline__connector .timeline__dot {
		order: 1;
	}

	/* Badges can be much wider than a phone screen at 50px font size
	   ("1948–1965"), so let them shrink and wrap instead of overflowing. */
	.timeline__date {
		flex: 0 1 auto;
		min-width: 0;
		overflow-wrap: break-word;
		font-size: 2.25rem; /* smaller badge on narrow screens */
	}
}
