/**
 * Scroll Story widget.
 *
 * Wide screens: the photo frame stays pinned while the steps scroll past;
 * the step being read is full strength, the others recede, and its photo
 * opens with the roller-door reveal used by the hero. A rail beside the
 * steps fills as the story progresses.
 *
 * Phones (and no JavaScript): a plain list, each step with its own photo.
 */

.dw-story {
	--dw-story-progress: 0;
	display: grid;
	gap: var(--dw-space-7);
}

.dw-story__media {
	display: none;
}

.dw-story__steps {
	display: grid;
	gap: var(--dw-space-7);
	margin: 0;
	padding: 0;
	list-style: none;
}

.dw-story__inline-media {
	margin-block-end: var(--dw-space-5);
	overflow: hidden;
	aspect-ratio: 16 / 10;
	background: var(--dw-color-light);
}

.dw-story .dw-story__inline-img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.dw-story__inline-media:empty {
	display: none;
}

.dw-story__index {
	display: block;
	margin-block-end: var(--dw-space-2);
	color: var(--dw-color-primary);
	font-family: var(--dw-font-heading);
	font-size: var(--dw-fs-sm);
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	letter-spacing: 0.08em;
}

.dw-story__title {
	margin-block-end: var(--dw-space-3);
	font-size: var(--dw-fs-display-sm);
	font-weight: 700;
	line-height: 1.02;
}

.dw-story__text {
	max-width: 40ch;
	margin: 0;
	font-size: var(--dw-fs-md);
	line-height: 1.65;
}

/* ------------------------------------------------------- Wide screens */

@media (min-width: 1025px) {
	.dw-story {
		grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr);
		gap: clamp(3rem, 6vw, 7rem);
		align-items: start;
	}

	.dw-story--media-end .dw-story__media {
		order: 2;
	}

	.dw-story__media {
		position: sticky;
		top: 7.5rem;
		display: block;
	}

	.dw-story__frame {
		position: relative;
		overflow: hidden;
		height: min(calc(100svh - 10rem), 640px);
		background: var(--dw-color-secondary-dark);
	}

	.dw-story__slide {
		position: absolute;
		inset: 0;
		visibility: hidden;
	}

	.dw-story__slide.is-active {
		z-index: 2;
		visibility: visible;
	}

	.dw-story__slide.is-leaving {
		z-index: 1;
		visibility: visible;
	}

	.dw-story .dw-story__img {
		width: 100%;
		height: 100%;
		object-fit: cover;
		transition: opacity 1s var(--dw-ease-in-out), transform 6s linear;
	}

	.dw-story__slide.is-active .dw-story__img {
		transform: scale(1.04);
	}

	/* The covered photo dims as the next one rises over it. */
	.dw-story__slide.is-leaving .dw-story__img {
		opacity: 0.45;
	}

	.dw-story__slide.is-entering {
		animation: dw-story-door 1s var(--dw-ease-in-out) both;
	}

	@keyframes dw-story-door {
		from {
			clip-path: inset(100% 0 0 0);
		}

		to {
			clip-path: inset(0 0 0 0);
		}
	}

	/* Step counter on the photo. */
	.dw-story__counter {
		position: absolute;
		inset-inline-start: var(--dw-space-5);
		bottom: var(--dw-space-5);
		z-index: 3;
		padding: 0.375rem 0.75rem;
		background: rgba(20, 25, 32, 0.72);
		color: rgba(255, 255, 255, 0.75);
		font-family: var(--dw-font-heading);
		font-size: var(--dw-fs-xs);
		font-weight: 600;
		font-variant-numeric: tabular-nums;
		letter-spacing: 0.08em;
	}

	.dw-story__counter-current {
		color: var(--dw-color-white);
	}

	/* Steps: each gets most of a screen, so the reader dwells on it. */
	.dw-story__steps {
		position: relative;
		gap: 0;
		padding-inline-start: var(--dw-space-7);
	}

	.dw-story__step {
		display: flex;
		flex-direction: column;
		justify-content: center;
		min-height: min(42svh, 400px);
	}

	.dw-story__step:first-child {
		min-height: min(calc(100svh - 10rem), 640px);
		justify-content: flex-start;
		padding-block-start: var(--dw-space-5);
	}

	.dw-story__inline-media {
		display: none;
	}

	/* Progress rail. */
	.dw-story__steps::before,
	.dw-story__steps::after {
		content: "";
		position: absolute;
		inset-block: 0;
		inset-inline-start: 0;
		width: 2px;
	}

	.dw-story__steps::before {
		background: var(--dw-color-border);
	}

	.dw-story__steps::after {
		background: var(--dw-color-primary);
		transform: scaleY(var(--dw-story-progress));
		transform-origin: top;
		transition: transform 0.6s var(--dw-ease-out);
	}

	/* Only once the script runs: the steps not being read recede through
	   colour, never below readable contrast (muted grey is 5:1 on white). */
	.dw-story.is-enhanced .dw-story__title,
	.dw-story.is-enhanced .dw-story__text,
	.dw-story.is-enhanced .dw-story__index {
		color: var(--dw-color-muted);
		transition: color 0.5s var(--dw-ease-out);
	}

	/* Titles are large text (3:1 is enough), so they can recede further. */
	.dw-story.is-enhanced .dw-story__title {
		color: #8b8f97;
	}

	.dw-story.is-enhanced .dw-story__step.is-active .dw-story__title {
		color: var(--dw-color-heading);
	}

	.dw-story.is-enhanced .dw-story__step.is-active .dw-story__text {
		color: var(--dw-color-text);
	}

	.dw-story.is-enhanced .dw-story__step.is-active .dw-story__index {
		color: var(--dw-color-primary);
	}
}

@media (prefers-reduced-motion: reduce) {
	.dw-story__slide.is-entering {
		animation: none;
	}

	.dw-story .dw-story__img {
		transition: none;
		transform: none !important;
	}
}
