// ================================
// GLOBAL PAGE STYLES AND VARIABLES
// ================================

:root {
	--color-fog: #eeeeee;
	--color-parchment: #faefe2;
	--color-cloud: #d9e1e4;
	--color-mustard: #e5c299;
	--color-navy: #16323f;
	--color-walnut: #473a3a;
	--color-slate: #3a4047;
	--color-crimson: #803847;
	--color-lilac: #e5e0eb;
	// --color-lime: #c5e0af;
	--color-lemon: #efe2b2;
	--color-peach: #ebb29f;
	--color-ale: #cd8f7a;
	--color-flamingo: #d2697c;
	--color-seaside: #b0d6cb;
	// --color-cove: #83c0b9;
	// --color-sage: #91b99a;
	--color-storm: #495875;

	--max-width: 1200px;
	--max-width-plus-padding: calc(var(--max-width) + 40px * 2);
	--max-extended-width: 1600px;
	--max-width-reading-material: 800px;

	--variable-px: Min(1px, 0.15vw);
	--page-edge-padding: 40px;
	--border-thickness: 2px;
	--feature-box-padding: 80;
	--font-size-link: calc(1rem * 4 / 3);
}

html,
body {
	color: var(--color-navy);
	background: white;
	font-family: "Inter Variable", sans-serif;
	line-height: 1.5;
	font-weight: 500;
	font-size: 18px;
	tab-size: 4;
	width: 100%;
	height: 100%;
	margin: 0;
}

@media screen and (max-width: 780px) {
	:root {
		--font-size-link: calc(1rem * 4 / 3);
		--page-edge-padding: 28px;
		--border-thickness: 1px;
		--feature-box-padding: 40;
	}

	html,
	body {
		font-size: 16px;
	}
}

@media print, screen and (max-width: 500px) {
	:root {
		--page-edge-padding: 20px;
	}
}

// ==================
// GLOBAL PAGE LAYOUT
// ==================

body > .page {
	box-sizing: border-box;
	min-width: 320px;

	header {
		padding: 0 var(--page-edge-padding);
		color: var(--color-walnut);
		position: relative;
		z-index: 1000;

		nav {
			margin: auto;
			max-width: var(--max-width);

			.row {
				display: flex;
				justify-content: space-between;
				--nav-padding-above-below: 30px;
				padding-top: var(--nav-padding-above-below);
				padding-bottom: calc(var(--nav-padding-above-below) - 16px);
				margin-bottom: calc(var(--nav-padding-above-below) - 16px);
				// Covers up content that extends up underneath the header
				background: white;

				@media screen and (max-width: 780px) {
					--nav-padding-above-below: 24px;
				}

				.left,
				.right {
					z-index: 1;
					display: flex;
					align-items: center;
					gap: 40px;
					--height: 60px;
					--button-padding: 24px;
					--nav-font-size: 28px; // Keep up to date with `NAV_BUTTON_INITIAL_FONT_SIZE` in navbar.js

					a {
						font-family: "Bona Nova", Palatino, serif;
						font-feature-settings: "lnum";
						line-height: 1.25;
						font-weight: 700;
						text-decoration: none;
						font-size: var(--nav-font-size);

						&.button {
							min-height: 0;
							height: var(--height);
							padding-left: var(--button-padding);
							padding-right: var(--button-padding);
							line-height: calc(var(--height) - 2 * var(--border-thickness));
							font-size: var(--nav-font-size);

							&::before {
								content: none;
							}
						}

						&:not(.button) {
							color: inherit;
						}

						img {
							display: block;
							width: var(--height);
							height: var(--height);
						}
					}

					&.left img {
						// Don't show the alt text if the image doesn't load
						font-size: 0;
					}

					.heart.heart {
						// The same color is also used below in the SVG after the `%23` (URL-encoded `#`)
						color: #cc304f;
					}

					@media screen and (max-width: 1200px) {
						gap: 30px;
						--height: 50px;
						--button-padding: 16px;
						--nav-font-size: 24px;
					}

					@media screen and (max-width: 1000px) {
						gap: 30px;
						--button-padding: 14px;
						--nav-font-size: 20px;
					}

					@media print, screen and (max-width: 900px) {
						gap: 20px;
						--height: 40px;
						--button-padding: 13px;
						--nav-font-size: 18px;
					}

					@media print, screen and (max-width: 780px) {
						gap: 20px;
						--button-padding: 12px;
						--nav-font-size: 16px;
					}

					@media screen and (max-width: 680px) {
						gap: 16px;
						--height: 30px;
						--button-padding: 8px;
						--nav-font-size: 14px;
					}

					@media screen and (max-width: 580px) {
						gap: 12px;
						--height: 24px;
						--nav-font-size: 13px;
					}

					@media screen and (max-width: 520px) {
						gap: 10px;
						--height: 22px;
						--button-padding: 6px;
						--nav-font-size: 12px;
					}

					@media screen and (max-width: 460px) {
						gap: 8px;
						--height: 20px;
						--button-padding: 4px;
						--nav-font-size: 11px;
					}

					@media screen and (max-width: 420px) {
						gap: 6px;
						--nav-font-size: 10px;
					}

					@media screen and (max-width: 380px) {
						gap: 6px;
						--nav-font-size: 9px;
					}

					@media screen and (max-width: 350px) {
						gap: 6px;
						--nav-font-size: 8px;
					}
				}
			}
		}

		.ripple {
			display: block;
			background: none;
			// Total SVG height splits into space above the baseline (for raised bumps and wave crests) and space below (for wave troughs that dip into the page body)
			--ripple-height: 32px;
			--ripple-baseline-from-top: 16px;
			--ripple-taper-half-width: 40px;
			height: var(--ripple-height);
			margin-top: calc(-1 * var(--ripple-baseline-from-top) + var(--border-thickness));
			margin-bottom: calc(-1 * (var(--ripple-height) - var(--ripple-baseline-from-top)) - var(--border-thickness));
			// Allow taper polygons (apex at +/- 40px) and wave crests/troughs to spill outside the SVG box; the path's off-screen fill corners are still drawn within bounds since the line/mask are split
			overflow: visible;
			clip-path: inset(-100px calc(-1 * var(--ripple-taper-half-width)) -100px calc(-1 * var(--ripple-taper-half-width)));
			pointer-events: none;

			.ripple-mask {
				// Covers up content that extends up underneath the header
				fill: white;
				stroke: none;
			}

			.ripple-line {
				fill: none;
				stroke: currentColor;
				stroke-width: var(--border-thickness);
			}

			polygon {
				fill: currentColor;
				stroke: none;
			}
		}

		@media screen and (max-width: 1400px) {
			.ripple {
				width: calc(100% + (var(--page-edge-padding) * 2));
				margin-left: calc(-1 * var(--page-edge-padding));
				margin-right: calc(-1 * var(--page-edge-padding));
			}

			hr {
				display: none;
			}
		}
	}

	main {
		padding: calc(120 * var(--variable-px)) var(--page-edge-padding);

		> section {
			max-width: var(--max-width);
			margin-left: auto;
			margin-right: auto;
			// Puts the content in front of the hexagon decoration
			position: relative;
			z-index: 1;

			~ section {
				margin-top: calc(120 * var(--variable-px));
			}

			p img {
				max-width: 100%;
			}

			pre {
				box-sizing: border-box;
				overflow: auto;
			}

			details {
				width: 100%;

				summary {
					display: inline-block;
					position: relative;
					padding-left: calc(10px + 8px);
					font-weight: 800;

					&::before {
						content: "";
						background: url('data:image/svg+xml;utf8,\
							<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><polygon fill="%2316323f" points="4,0 1,0 6,5 1,10 4,10 9,5 4,0" /></svg>\
							');
						position: absolute;
						margin: auto;
						top: 0;
						bottom: 0;
						left: 0;
						width: 10px;
						height: 10px;
					}

					+ * {
						margin-top: 20px;
					}
				}
			}

			details[open] summary::before {
				transform: rotate(90deg);
			}
		}
	}

	footer {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 40px;
		padding-top: 0;
		color: var(--color-walnut);

		@media screen and (max-width: 1400px) {
			hr {
				width: 100%;

				&::before,
				&::after {
					border: none;
					background: currentColor;
					width: calc(var(--page-edge-padding) + 40px);
					height: var(--border-thickness);
				}
			}
		}

		nav {
			display: flex;
			flex-wrap: wrap;
			justify-content: center;
			gap: 8px 40px;
			margin-top: 40px;

			a {
				color: var(--color-walnut);
			}

			@media screen and (max-width: 900px) {
				max-width: 500px;
			}

			@media screen and (max-width: 780px) {
				max-width: 440px;
			}

			@media screen and (max-width: 400px) {
				gap: 6px 20px;
			}
		}

		span {
			text-align: center;
			margin-top: 40px;
		}
	}
}

// =====================
// ELEMENT SPACING RULES
// =====================

:is(h1, h2, h3, h4, article > :first-child, details > summary) ~ :is(p, ul, ol, ol li p, img, details, a:has(> img:only-child)),
:is(h1, h2, h3, h4, article > :first-child) ~ :is(ul, ol) li p + img,
:is(h1, h2, h3, h4, p) ~ .feature-icons,
p ~ :is(h1, h2, h3, h4, details summary, blockquote, .image-comparison, .video-background, .youtube-embed),
.youtube-embed + :is(p, .link, .button),
p + p > .button,
p + :is(.link, section, details),
table td p ~ p,
img + .link,
article {
	margin-top: 20px;
}

* {
	min-width: 0;
	min-height: 0;
}

// ==================================
// HEADER AND TEXT ELEMENT TAG STYLES
// ==================================

h1 {
	font-size: calc(1rem * 8 / 3);
	font-family: "Bona Nova", Palatino, serif;
	font-feature-settings: "lnum";
	line-height: 1.25;
	font-weight: 700;
	display: inline-block;
	margin: 0;

	~ h2 {
		margin-top: 40px;
	}

	~ hr {
		margin-top: 40px;
		margin-bottom: 20px;
	}
}

h2,
h3,
h4,
h5,
h6 {
	font-family: "Inter Variable", sans-serif;
	line-height: 1.5;
	font-weight: 800;
	display: inline-block;
	margin: 0;
}

h2 {
	font-size: 1.75rem;
	font-weight: 700;
}

h3 {
	font-size: 1.25rem;
}

h4,
h5,
h6 {
	font-size: 1rem;
}

p {
	margin: 0;
	text-align: justify;
	text-justify: inter-character; // Only supported in Firefox
	hyphens: auto;

	code {
		text-justify: auto;
	}
}

h1,
h2,
h3,
h4,
h5,
h6,
p {
	~ img,
	~ iframe,
	~ a > img:only-child {
		width: 100%;
		height: auto;
	}
}

a {
	color: var(--color-crimson);
}

// ========================
// OTHER ELEMENT TAG STYLES
// ========================

img {
	vertical-align: top;
}

table {
	margin: 40px -10px;
	width: calc(100% + 20px);
	font-size: 16px;
	border-collapse: collapse;

	th,
	td {
		border: solid var(--color-fog);
		border-width: 1px 0;
		vertical-align: top;
		margin: 0;
		padding: 20px;

		p {
			text-align: left;
		}

		&:first-child {
			padding-left: 10px;
		}

		&:last-child {
			padding-right: 10px;
		}

		&:not(:first-child) img {
			max-width: 100%;
		}
	}

	thead:not(:has(tr th:not(:empty))) {
		th {
			padding: 0;
		}

		+ tbody tr:first-child td {
			border: none;
		}
	}

	tr th,
	tr:last-child td {
		border: none;
	}

	:is(h1, h2, h3, h4, h5, h6) + & {
		margin-top: 0;
	}
}

ul,
ol {
	margin: 0;

	+ p {
		margin-top: 0;
	}

	li {
		margin-top: 0.5em;
	}
}

hr {
	// Reset Firefox user agent style that is overriding `currentColor` that we set
	color: unset;
}

code {
	color: black;
	background: var(--color-fog);
	padding: 0 4px;
	overflow-wrap: anywhere;
	hyphens: none;

	a & {
		color: var(--color-crimson);
	}
}

kbd {
	outline: calc(var(--border-thickness) / 2) solid var(--color-navy);
	padding: 0 8px;
	margin: 0 4px;
	color: inherit;
	font-family: inherit;
}

summary {
	cursor: pointer;
}

hr {
	overflow: visible;
}

hr,
.ripple {
	width: calc(100% - 32px * 2);
	height: var(--border-thickness);
	margin: 0 32px;
	background: currentColor;
	position: relative;
	border: none;

	&::before {
		left: -40px;
		border-width: 0 0 var(--border-thickness) 40px;
	}

	&::after {
		right: -40px;
		border-width: 0 40px var(--border-thickness) 0;
	}

	&::before,
	&::after {
		content: "";
		display: block;
		width: 0;
		height: 0;
		position: absolute;
		border-color: transparent transparent currentColor transparent;
		border-style: solid;
	}
}

// ========================
// COMMON SIMPLE COMPONENTS
// ========================

.block {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	width: 100%;

	&.centered {
		align-items: center;
	}

	:not(.diptych, .triptych) > .block + & {
		margin-top: calc(120 * var(--variable-px));
	}
}

.link {
	display: inline-block;
	font-size: var(--font-size-link);
	font-weight: 800;
	text-decoration: none;
	color: var(--color-crimson);
	white-space: nowrap;

	&:not(.not-uppercase) {
		text-transform: uppercase;
	}
}

.button {
	display: inline-block;
	border: var(--border-thickness) solid currentColor;
	min-height: calc(var(--font-size-link) * 2);
	font-size: var(--font-size-link);
	padding: 0 var(--font-size-link);
	box-sizing: border-box;
	text-align: left;
	text-decoration: none;
	font-weight: 800;
	color: var(--color-crimson);

	&::before {
		content: "";
		line-height: calc(var(--font-size-link) * 2 - 2 * var(--border-thickness));
	}

	img {
		height: calc(var(--font-size-link) * 1.5);
		margin-right: calc(var(--font-size-link) / 2);
	}

	img,
	span {
		vertical-align: middle;
	}
}

.arrow::after {
	content: " »";
	font-family: "Inter Variable", sans-serif;
}

.video-background {
	position: relative;
	font-size: 0;

	video {
		max-width: Min(100%, 1280px);
	}

	// Uses a white border over the video to cover up the edges of the video which, due to a Chrome rendering bug, displays black edges sometimes when scrolling
	&::after {
		content: "";
		position: absolute;
		inset: 0;
		border: 2px solid white;
		pointer-events: none;
	}
}

.heart::after {
	content: "";
	background-image: url('data:image/svg+xml;utf8,\
		<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M8,15C5.12471,9.753694 0.5,8.795225 0.5,4.736524 C0.5,-0.507473 7.468734,0 8,4.967381 C8.531266,0 15.5,-0.507473 15.5,4.736524 C15.5,8.795225 10.87529,9.753694 8,15z" fill="%23cc304f" /></svg>\
		');
	display: inline-block;
	width: 0.75em;
	height: 0.75em;
	margin-left: 0.25em;
	margin-bottom: -0.1em;
	vertical-align: baseline;
}

// blockquote {
// 	padding: 32px 80px;
// 	background: rgba(0, 0, 0, 0.0625);
// 	position: relative;
// 	border-left: 4px solid var(--color-navy);

// 	&::before,
// 	&::after {
// 		content: "";
// 		position: absolute;
// 		width: 52px;
// 		height: 40px;
// 		background-image: url('data:image/svg+xml;utf8,\
// 			<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 40"><path fill="rgba(22, 50, 63, 0.25)" d="M51.8,2.4c0,.5-.2.9-.6,1.2s-1,.5-1.8.7c-2.2.5-4.3,1.3-6.4,2.5-2.1,1.2-3.7,2.8-5,4.8-1.3,2-1.9,4.4-1.9,7.4s.6,2.7,1.7,4,2.5,2.1,4,2.4c2,.3,3.6,1,4.8,2.2,1.2,1.2,1.8,2.7,1.8,4.5s-.9,3.9-2.7,5.3c-1.8,1.4-3.8,2.2-6,2.2-3.8,0-7-1.3-9.4-4-2.4-2.7-3.6-6.1-3.6-10.4s.7-7,2.2-10c1.4-3,3.3-5.6,5.5-7.8,2.3-2.2,4.7-3.9,7.2-5,2.5-1.2,4.9-1.7,7.1-1.7s3,.6,3,1.9ZM22.2.5c-2.2,0-4.6.6-7.1,1.7-2.5,1.2-4.9,2.8-7.2,5-2.3,2.2-4.2,4.8-5.6,7.8C.9,18.1.2,21.5.2,25.1s1.2,7.7,3.7,10.4c2.4,2.7,5.5,4,9.3,4s4.3-.7,6-2.2c1.7-1.4,2.6-3.2,2.6-5.3s-.6-3.3-1.8-4.5c-1.2-1.2-2.8-1.9-4.7-2.2-1.5-.3-2.9-1.1-4-2.4s-1.7-2.6-1.7-4c0-3,.6-5.4,1.9-7.4,1.2-2,2.9-3.6,5-4.8,2.1-1.2,4.2-2,6.4-2.5.8-.2,1.4-.4,1.8-.7.4-.3.6-.7.6-1.2,0-1.2-1-1.9-3-1.9Z" /></svg>\
// 			');
// 	}

// 	&::before {
// 		top: 16px;
// 		left: 16px;
// 	}

// 	&::after {
// 		transform: rotate(180deg);
// 		bottom: 16px;
// 		right: 16px;
// 	}
// }
