@layer pages {
	.cv {
		margin-inline: auto;
		max-width: 68rem;
		padding-bottom: 1rem;
	}

	.cv-intro {
		align-items: stretch;
		border-bottom: 1px solid var(--color-secondary);
		column-gap: 2.5rem;
		display: grid;
		grid-template-columns: auto 1fr;
		padding-block: 1rem 3rem;
		row-gap: 1.5rem;

		img {
			border: 1px solid var(--color-secondary);
			height: 100%;
			object-fit: cover;
			width: 12rem;
		}

		h1 {
			font-size: clamp(2.5rem, 6vw, 4.25rem);
			line-height: 1.1;
			text-transform: capitalize;
		}

		.cv-role {
			color: var(--color-tertiary);
			font-family:
				"Neue Montreal",
				system-ui,
				-apple-system,
				BlinkMacSystemFont,
				sans-serif;
			font-size: clamp(1.25rem, 3vw, 1.75rem);
			font-weight: 500;
			line-height: 1.2;
			margin-top: 0.25rem;
		}

		@media (max-width: 768px) {
			align-items: start;
			gap: 1.5rem;
			grid-template-columns: 1fr;
			padding-block: 2.5rem 2rem;

			img {
				display: none;
			}
		}
	}

	.cv-intro-body {
		align-items: flex-start;
		display: flex;
		flex-direction: column;
	}

	.cv-back-link {
		color: var(--color-tertiary);
		font-size: 0.8rem;
		grid-column: 1 / -1;
		justify-self: start;
		letter-spacing: 0.2em;
		text-transform: uppercase;

		&:hover {
			color: color-mix(
				in oklch,
				var(--color-tertiary),
				var(--color-secondary) 35%
			);
		}

		@media (max-width: 768px) {
			display: none;
		}
	}

	.cv-email {
		margin-top: 1rem;

		a {
			color: var(--color-secondary);
			text-decoration: underline;
			text-decoration-color: var(--color-tertiary);
			text-underline-offset: 0.2em;
			transition: color 150ms ease;

			&:hover {
				color: color-mix(
					in oklch,
					var(--color-secondary),
					var(--color-tertiary) 35%
				);
			}
		}
	}

	/* Contact details only appear on the printed CV, with icons. */
	.print-contact {
		display: none;
	}

	/* Download and print actions */
	.cv-actions {
		display: flex;
		flex-wrap: wrap;
		gap: 0.75rem;
		margin-top: auto;
		padding-top: 1.5rem;

		.outline-btn {
			color: var(--color-secondary);
			gap: 0.5rem;
			height: auto;
			padding-block: 0.55rem;
			padding-inline: 0.9rem;

			svg {
				height: 18px;
				width: 18px;
			}
		}
	}

	.cv-section {
		border-bottom: 1px solid var(--color-secondary);
		display: flex;
		flex-direction: column;
		gap: 1.5rem;
		padding-block: 2.5rem;

		> h2 {
			font-size: 2rem;
		}
	}

	/* Roles, education and skill groups share the document's two-column rhythm */
	.cv-entry,
	.skill-group {
		column-gap: 2.5rem;
		display: grid;
		grid-template-columns: 13rem 1fr;
	}

	.cv-entry {
		row-gap: 0.75rem;

		header {
			align-self: start;
		}

		h3 {
			font-size: 1.15rem;
			line-height: 1.3;
		}

		.cv-meta {
			color: var(--color-tertiary);
		}

		.cv-dates {
			color: var(--color-tertiary);
			font-size: 0.85rem;
		}

		ul {
			margin: 0;
			padding-left: 1.1rem;
		}

		li {
			margin-bottom: 0.6rem;

			&::marker {
				color: var(--color-tertiary);
			}

			&:last-child {
				margin-bottom: 0;
			}
		}

		@media (max-width: 768px) {
			grid-template-columns: 1fr;
			row-gap: 0.5rem;
		}
	}

	.cv-entry-body {
		display: flex;
		flex-direction: column;
		gap: 1rem;

		p {
			margin: 0;
		}
	}

	/* Named client engagements within one employer */
	.engagement {
		h4 {
			font-size: 1rem;
			line-height: 1.3;
		}

		p {
			margin-top: 0.25rem;
		}
	}

	.cv-skills {
		display: flex;
		flex-direction: column;
		gap: 1rem;
		margin: 0;

		dt {
			color: var(--color-tertiary);
			font-size: 0.8rem;
			letter-spacing: 0.08em;
			text-transform: uppercase;
		}

		dd {
			margin: 0;
		}

		@media (max-width: 768px) {
			.skill-group {
				grid-template-columns: 1fr;
				row-gap: 0.2rem;
			}
		}
	}

	/* Extracurricular */
	.cv-list {
		margin: 0;
		padding-left: 1.1rem;

		li {
			margin-bottom: 0.75rem;

			&::marker {
				color: var(--color-tertiary);
			}

			&:last-child {
				margin-bottom: 0;
			}
		}
	}

	/* Print: keep the HTML as the source of truth for the downloadable document */
	@media print {
		@page {
			margin: 14mm;
			size: A4;
		}

		html,
		body {
			background: #fff;
			color: #000;
			font-family: "Neue Montreal", system-ui, sans-serif;
			font-size: 10pt;
			line-height: 1.45;
		}

		body > header,
		.cv-actions,
		.cv-back-link,
		.cv-email,
		footer {
			display: none;
		}

		main {
			padding: 0;
		}

		.cv {
			max-width: none;
			padding: 0;
		}

		a {
			color: #000;
			text-decoration: underline;

			/* The external-link arrow is meaningless on paper. */
			&[target="_blank"]::after {
				content: none;
			}
		}

		.cv-intro {
			align-items: center;
			gap: 1.5rem;
			grid-template-columns: auto 1fr;
			padding-block: 0 1rem;

			img {
				border-color: #000;
				display: block;
				height: auto;
				width: 5.5rem;
			}

			.cv-role {
				color: #333;
				font-size: 1.1rem;
			}

			h1 {
				font-size: 2.25rem;
			}
		}

		.print-contact {
			display: flex;
			flex-direction: column;
			font-size: 8.5pt;
			gap: 0.1rem;
			list-style: none;
			margin: 0.5rem 0 0;
			padding: 0;

			li {
				align-items: center;
				display: flex;
				gap: 0.35rem;
			}

			svg {
				height: 10px;
				width: 10px;
			}

			a {
				text-decoration: none;
			}
		}

		.cv-section {
			border-bottom-color: #999;
			gap: 0.6rem;
			padding-block: 1rem;

			> h2 {
				break-after: avoid;
				font-size: 1.35rem;
			}
		}

		.cv-entry {
			column-gap: 1.5rem;
			grid-template-columns: 8.5rem 1fr;
			row-gap: 0.3rem;

			header {
				break-after: avoid;
			}

			h3 {
				font-size: 9.5pt;
			}

			.cv-meta,
			.cv-dates {
				color: #333;
			}

			ul {
				padding-left: 0.9rem;
			}

			li {
				break-inside: avoid;
				margin-bottom: 0.25rem;
			}
		}

		.cv-entry-body {
			gap: 0.5rem;
		}

		.engagement h4 {
			break-after: avoid;
			font-size: 9.5pt;
		}

		.cv-skills {
			gap: 0.4rem;

			dt {
				color: #333;
				font-size: 7.5pt;
			}

			.skill-group {
				column-gap: 1.5rem;
				grid-template-columns: 8.5rem 1fr;
			}
		}

		.cv-list li {
			break-inside: avoid;
			margin-bottom: 0.4rem;
		}

		p,
		li {
			orphans: 3;
			widows: 3;
		}
	}
}
