/**
 * Viora Sticky Index widget.
 *
 * The left column pins and the right one scrolls past it. Entries are dimmed
 * until they are the one being read, which is what carries the structure —
 * there are no hairlines and no repeated section head here on purpose.
 */

.viora-sticky {
	--viora-sticky-entry-size: clamp(1.75rem, 3.61vw, 3.25rem);
	--viora-sticky-active: var(--viora-color-accent);

	position: relative;
	padding-block: clamp(3.5rem, 7.64vw, 6.875rem);
}

.viora-sticky__inner {
	width: min(1082px, 100% - 2 * var(--viora-layout-container-pad));
	margin-inline: auto;
}

.viora-sticky__layout {
	--viora-sticky-aside: 44%;

	display: grid;
	grid-template-columns: var(--viora-sticky-aside, 44%) minmax(0, 1fr);
	column-gap: clamp(2.5rem, 6.25vw, 5.625rem);
	align-items: start;
}

/* Pinned on the right: swap the columns, not the source order. */
.viora-sticky--pin-right .viora-sticky__layout {
	grid-template-columns: minmax(0, 1fr) var(--viora-sticky-aside, 44%);
}

.viora-sticky--pin-right .viora-sticky__aside {
	order: 2;
}

/* -------------------------------------------------- *
 * Pinned column
 * -------------------------------------------------- */

/*
 * Stretched on purpose, against the layout's `align-items: start`.
 *
 * A sticky element can only travel inside its own containing block. Left at
 * `start` this column collapsed to its content — exactly the height of the
 * pinned block inside it — so there was nowhere to travel and it never stuck.
 * Stretching it to the row gives the pin the entries column's full height to
 * work with. `align-self` rather than dropping `align-items`, so the entries
 * column keeps its own alignment.
 */
.viora-sticky__aside {
	min-width: 0;
	align-self: stretch;
}

.viora-sticky__pinned {
	position: sticky;
	/* Clears the sticky site header. */
	top: clamp(5rem, 9vw, 7rem);
	display: flex;
	flex-direction: column;
	align-items: flex-start;
}

.viora-sticky__kicker {
	color: var(--viora-color-accent);
}

.viora-sticky__title {
	margin: clamp(0.85rem, 1.4vw, 1.25rem) 0 0;
	color: var(--viora-ink, var(--viora-color-heading));
	font-family: var(--viora-font-display);
	font-size: clamp(2rem, 3.75vw, 3.375rem);
	font-weight: 400;
	line-height: 1;
	letter-spacing: -0.035em;
}

.viora-sticky__title em {
	font-style: italic;
}

/*
 * One frame, every plate stacked in it. Cross-fading in place is what makes
 * the column feel pinned rather than re-rendered.
 */
.viora-sticky__frame {
	position: relative;
	width: 100%;
	margin-top: clamp(1.5rem, 2.5vw, 2.25rem);
	aspect-ratio: 1.2;
	overflow: hidden;
	background-color: var(--viora-color-surface-alt);
}

.viora-sticky__plate {
	position: absolute;
	inset: 0;
	margin: 0;
	opacity: 0;
	transform: scale(1.04);
	transition:
		opacity 0.7s var(--viora-motion-easing),
		transform 1.2s var(--viora-motion-easing);
}

.viora-sticky__plate.is-current {
	opacity: 1;
	transform: none;
}

.viora-sticky__plate img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.viora-sticky__text {
	margin: clamp(1.25rem, 2vw, 1.75rem) 0 0;
	max-width: 34ch;
	color: var(--viora-ink-soft, var(--viora-color-heading-soft));
	font-family: var(--viora-font-ui);
	font-size: 0.9375rem;
	line-height: 1.7;
}

.viora-sticky__counter {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	margin: clamp(1.25rem, 2vw, 1.75rem) 0 0;
	color: var(--viora-ink-soft, var(--viora-color-heading-soft));
	font-family: var(--viora-font-ui);
	font-size: 0.75rem;
	font-weight: var(--viora-weight-medium);
	letter-spacing: 0.24em;
	font-variant-numeric: tabular-nums;
}

.viora-sticky__counter-now {
	color: var(--viora-ink, var(--viora-color-heading));
}

.viora-sticky__counter-rule {
	display: block;
	width: 2rem;
	height: 1px;
	background-color: currentColor;
	opacity: 0.4;
}

/* -------------------------------------------------- *
 * Entries
 * -------------------------------------------------- */

.viora-sticky__entries {
	margin: 0;
	padding: 0;
	list-style: none;
	min-width: 0;
}

.viora-sticky__entry {
	/* Tall enough that only one entry is ever the obvious subject. */
	padding-block: clamp(3rem, 7vw, 6rem);
}

.viora-sticky__entry:first-child {
	padding-top: 0;
}

.viora-sticky__entry-inner {
	display: block;
	color: inherit;
	text-decoration: none;
}

.viora-sticky__entry-index {
	display: block;
	color: var(--viora-ink-soft, var(--viora-color-heading-soft));
	font-family: var(--viora-font-ui);
	font-size: 0.6875rem;
	font-weight: var(--viora-weight-medium);
	line-height: 1.8;
	letter-spacing: 0.28em;
	transition: color var(--viora-motion-base) var(--viora-motion-easing);
}

.viora-sticky__entry.is-current .viora-sticky__entry-index {
	color: var(--viora-sticky-active);
}

.viora-sticky__entry-title {
	margin: clamp(0.5rem, 0.9vw, 0.85rem) 0 0;
	color: var(--viora-ink, var(--viora-color-heading));
	font-family: var(--viora-font-display);
	font-size: var(--viora-sticky-entry-size);
	font-weight: 400;
	line-height: 1.04;
	letter-spacing: -0.035em;
	/*
	 * Dimmed until it is the entry being read. Opacity rather than colour, so
	 * it works on every scheme without a second variable.
	 */
	opacity: 0.35;
	transition: opacity var(--viora-motion-slow) var(--viora-motion-easing);
}

.viora-sticky__entry.is-current .viora-sticky__entry-title {
	opacity: 1;
}

.viora-sticky__entry-inner:hover .viora-sticky__entry-title {
	opacity: 1;
}

.viora-sticky__entry-text {
	margin: clamp(0.75rem, 1.25vw, 1.125rem) 0 0;
	max-width: 40ch;
	color: var(--viora-ink-soft, var(--viora-color-heading-soft));
	font-family: var(--viora-font-ui);
	font-size: clamp(0.9375rem, 1.11vw, 1rem);
	line-height: 1.7;
	opacity: 0.55;
	transition: opacity var(--viora-motion-slow) var(--viora-motion-easing);
}

.viora-sticky__entry.is-current .viora-sticky__entry-text {
	opacity: 1;
}

.viora-sticky__entry-meta {
	margin: clamp(0.85rem, 1.25vw, 1.125rem) 0 0;
	color: var(--viora-color-accent);
	font-family: var(--viora-font-ui);
	font-size: 0.6875rem;
	font-weight: var(--viora-weight-medium);
	line-height: 1.7;
	letter-spacing: 0.24em;
	text-transform: uppercase;
}

/* -------------------------------------------------- *
 * Reveal
 * -------------------------------------------------- */

.viora-sticky.is-animated .viora-sticky__pinned,
.viora-sticky.is-animated .viora-sticky__entry {
	opacity: 0;
	transform: translateY(24px);
}

.viora-sticky.is-animated .viora-sticky__pinned.is-in,
.viora-sticky.is-animated .viora-sticky__entry.is-in {
	opacity: 1;
	transform: none;
	transition:
		opacity 0.9s var(--viora-motion-easing),
		transform 0.9s var(--viora-motion-easing);
}

/* -------------------------------------------------- *
 * Tablet — the pin has nothing to scroll against once stacked
 * -------------------------------------------------- */

@media (max-width: 1024px) {
	.viora-sticky {
		padding-block: clamp(3rem, 6vw, 4.5rem);
	}

	.viora-sticky__layout,
	.viora-sticky--pin-right .viora-sticky__layout {
		grid-template-columns: minmax(0, 1fr);
		row-gap: clamp(2rem, 4vw, 3rem);
	}

	.viora-sticky--pin-right .viora-sticky__aside {
		order: 0;
	}

	.viora-sticky__pinned {
		position: static;
	}

	.viora-sticky__frame {
		aspect-ratio: 1.7;
	}

	.viora-sticky__entry {
		padding-block: clamp(1.75rem, 4vw, 2.5rem);
		border-top: 1px solid var(--viora-hairline, rgba(17, 17, 17, 0.14));
	}

	.viora-sticky__entry:first-child {
		padding-top: clamp(1.75rem, 4vw, 2.5rem);
	}

	/* Nothing is "current" without a scroll to track, so nothing is dimmed. */
	.viora-sticky__entry-title,
	.viora-sticky__entry-text {
		opacity: 1;
	}

	.viora-sticky__counter {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.viora-sticky.is-animated .viora-sticky__pinned,
	.viora-sticky.is-animated .viora-sticky__entry {
		opacity: 1;
		transform: none;
		transition: none;
	}

	.viora-sticky__plate {
		transition: none;
	}
}
