@layer pages {
	.journal-cover {
		aspect-ratio: 3 / 4;
		margin: 0;
		overflow: clip;
		border: 1px solid rgb(255 255 255 / 24%);
		border-radius: 0.55rem;
		background: var(--color-surface-muted);
		/* Inset lips hint at a moulded plastic shell: the top edge catches
		   light, the bottom falls into the rim, and a hairline marks the wall. */
		box-shadow:
			inset 0 0 0 1px rgb(255 255 255 / 8%),
			inset 0 1px 0 rgb(255 255 255 / 22%),
			inset 0 -1px 0 rgb(8 12 24 / 20%),
			0 1.2rem 3rem rgb(0 0 0 / 28%);

		> :is(img, picture) {
			inline-size: 100%;
			block-size: 100%;
			object-fit: cover;
		}
	}

	/* The whole cover tilts toward a pointer or a touch drag; cover-drift.js eases the
	   custom properties each frame while this transform rests perfectly flat.
	   The fixed shadow keeps the plastic edge without repainting it each frame. */
	.journal-cover[data-cover-drift] {
		--tilt-x: 0deg;
		--tilt-y: 0deg;
		--sheen-x: 50%;

		position: relative;
		/* The cover owns its touches so scrolling cannot steal the drag. */
		touch-action: none;
		transform: perspective(46rem) rotateX(var(--tilt-x)) rotateY(var(--tilt-y));

		> img {
			/* Keep iOS from dragging the artwork out or offering its callout. */
			user-select: none;
			-webkit-user-drag: none;
			-webkit-touch-callout: none;
		}

		box-shadow:
			inset 0 0 0 1px rgb(255 255 255 / 8%),
			inset 0 1px 0 rgb(255 255 255 / 22%),
			inset 0 -1px 0 rgb(8 12 24 / 20%),
			1px 1px 0 0 rgb(8 12 24 / 50%),
			0 1.2rem 3rem rgb(0 0 0 / 28%);

		&::after {
			position: absolute;
			inset: 0;
			background: linear-gradient(
				105deg,
				transparent 32%,
				rgb(255 255 255 / 4%) 42%,
				rgb(255 255 255 / 15%) 50%,
				rgb(255 255 255 / 5%) 59%,
				transparent 68%
			);
			content: "";
			opacity: 0;
			pointer-events: none;
			transition: opacity 600ms ease;
			transform: translateX(calc(var(--sheen-x) - 50%));
		}

		&.is-drifting::after {
			opacity: 1;
		}
	}

}

/* CSS smoothing on top of the eased values cover-drift.js writes each frame; the
   long easing lets a hovering pointer settle with some weight, while a touch
   drag tracks the finger more directly. */
@media (prefers-reduced-motion: no-preference) {
	@layer pages {
		.journal-cover[data-cover-drift] {
			transition: transform 320ms cubic-bezier(0.2, 0.75, 0.25, 1);
		}

		.journal-cover[data-cover-drift].is-touch {
			transition-duration: 180ms;
		}
	}
}

@media (forced-colors: active) {
	.journal-cover[data-cover-drift]::after { display: none; }
}
