/* style.css
 * Version 2.0
 */

@font-face {
	font-family: "Kalam";
	font-style: normal;
	font-weight: 400;
	font-display: swap;
	src: url("fonts/kalam-400-latin.woff2") format("woff2");
}
@font-face {
	font-family: "Kalam";
	font-style: normal;
	font-weight: 700;
	font-display: swap;
	src: url("fonts/kalam-700-latin.woff2") format("woff2");
}

*,
*::before,
*::after {
	box-sizing: border-box;
}
:root {
	/* Follows the system setting unless a theme has been picked (see theme.js) */
	color-scheme: light dark;

	/* Printed parts of the napkin */
	--paper: light-dark(#faf6ee, #1e1b17);
	--emboss: light-dark(rgba(120, 95, 50, 0.05), rgba(255, 245, 225, 0.03));
	--crease: light-dark(rgba(120, 95, 50, 0.06), rgba(255, 245, 225, 0.04));
	--foreground: light-dark(#24211c, #ece6db);
	--pencil: light-dark(#5e5850, #aaa398);
	--pencil-light: light-dark(#a59d92, #6d675e);

	/* What's been written on it */
	--ink: light-dark(#2346b0, #9db7ff);
	--red-pen: light-dark(#b3261e, #ff8f80);
	--highlighter: light-dark(rgba(255, 221, 0, 0.45), rgba(255, 214, 0, 0.22));

	/* Images can't use light-dark(), so the pen line swaps with the theme below */
	--pen-line-light: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 8' preserveAspectRatio='none'%3E%3Cpath d='M1 4.5C40 3 80 5.5 120 4S200 2.8 240 4.2 298 5 299 3.5' fill='none' stroke='%235e5850' stroke-width='1.5' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
	--pen-line-dark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 8' preserveAspectRatio='none'%3E%3Cpath d='M1 4.5C40 3 80 5.5 120 4S200 2.8 240 4.2 298 5 299 3.5' fill='none' stroke='%23aaa398' stroke-width='1.5' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
	--pen-line: var(--pen-line-light);

	--site-width: 840px;

	--space-small: 10px;
	--space-default: 20px;
	--space-large: 40px;

	--font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	--font-hand: "Kalam", "Segoe Print", "Bradley Hand", cursive;
	--font-size-small: 14px;
	--font-size-default: 20px;
	--font-size-hand: 22px; /* Keep inputs above 16px, or iOS Safari zooms in on focus */
	--font-size-large: 40px;
}
:root[data-theme="light"] {
	color-scheme: light;
}
:root[data-theme="dark"] {
	color-scheme: dark;
	--pen-line: var(--pen-line-dark);
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--pen-line: var(--pen-line-dark);
	}
}

/* The napkin: quilted emboss and a faint fold down the middle */
body {
	margin: 0;
	padding: var(--space-large) 0;
	background-color: var(--paper);
	background-image:
		linear-gradient(90deg, transparent calc(50% - 2px), var(--crease) 50%, transparent calc(50% + 2px)),
		repeating-linear-gradient(45deg, transparent 0 21px, var(--emboss) 21px 22px),
		repeating-linear-gradient(-45deg, transparent 0 21px, var(--emboss) 21px 22px);
	color: var(--foreground);
	font-family: var(--font-family);
}
a {
	color: inherit;
	text-decoration: underline;
	text-decoration-color: var(--pencil-light);
	text-decoration-style: wavy;
	text-underline-offset: 3px;
}
a:hover {
	text-decoration-color: var(--ink);
}
header, main, footer {
	margin-left: auto;
	margin-right: auto;
	max-width: var(--site-width);
	padding-left: var(--space-default);
	padding-right: var(--space-default);
}
main {
	margin-top: var(--space-large);
	margin-bottom: 0;
}
header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: var(--space-default);
}
.theme-toggle {
	display: grid;
	place-items: center;
	flex-shrink: 0;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: none;
	color: var(--pencil);
	cursor: pointer;
}
.theme-toggle:hover {
	color: var(--ink);
}
.theme-toggle:focus-visible {
	outline: none;
	background: var(--highlighter);
}
.theme-toggle svg {
	width: 24px;
	height: 24px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.8;
	stroke-linecap: round;
	stroke-linejoin: round;
}
/* Show the moon in light mode and the sun in dark mode */
.theme-toggle .icon-sun,
:root[data-theme="dark"] .theme-toggle .icon-moon {
	display: none;
}
:root[data-theme="dark"] .theme-toggle .icon-sun {
	display: block;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) .theme-toggle .icon-moon {
		display: none;
	}
	:root:not([data-theme="light"]) .theme-toggle .icon-sun {
		display: block;
	}
}
.logo-link {
	display: inline-block;
	text-decoration: none;
}
.site-logo {
	display: block;
	height: auto;
	width: 260px;
	overflow: visible;
}
.site-logo .print {
	fill: var(--foreground);
}
.site-logo .ink {
	fill: var(--ink);
}
.site-logo .ink-line {
	stroke: var(--ink);
}
h1, h2, h3, h4, h5, h6 {
	margin-top: var(--space-large);
	margin-bottom: 0;
	line-height: 1.25;
}
h1 {
	margin-top: 0;
	font-size: var(--font-size-large);
}
h2 {
	font-size: var(--font-size-default);
	font-weight: 900;
}
h3, h4, h5, h6 {
	border-bottom: 1px solid var(--pencil-light);
	color: var(--pencil);
	font-size: var(--font-size-small);
	letter-spacing: 3px;
	padding-bottom: 3px;
	text-transform: uppercase;
}
p {
	line-height: 1.5;
	font-size: var(--font-size-default);
}
[hidden] {
	display: none !important;
}

/* The disclaimer, added in red pen */
.note {
	margin: var(--space-large) 0 0;
	max-width: 34em;
	color: var(--red-pen);
	font-family: var(--font-hand);
	font-size: var(--font-size-default);
	line-height: 1.4;
	transform: rotate(-1deg);
	transform-origin: left center;
}
.note::before {
	content: "P.S. ";
	font-weight: 700;
}
.intro {
	margin-bottom: var(--space-large);
}

/* Form: printed labels, answers written on a pen line */
label {
	color: var(--pencil);
	font-size: var(--font-size-small);
}
.hint {
	color: var(--pencil);
	font-size: var(--font-size-small);
	line-height: 1.4;
}
input,
.select {
	width: 100%;
	min-height: 48px;
	padding: 2px 4px 4px;
	border: 0;
	border-radius: 0;
	background: var(--pen-line) left bottom / 100% 8px no-repeat;
	color: var(--ink);
	font-family: var(--font-hand);
	font-size: var(--font-size-hand);
	line-height: 1.2;
}
input::placeholder {
	color: var(--pencil-light);
	font-family: var(--font-family);
	font-size: 15px;
}
input:focus,
.select:focus-within {
	outline: none;
	background:
		var(--pen-line) left bottom / 100% 8px no-repeat,
		linear-gradient(transparent 25%, var(--highlighter) 25%, var(--highlighter) 85%, transparent 85%);
}
/* Hide the number spinners, they look out of place on paper */
input[type="number"] {
	-moz-appearance: textfield;
	appearance: textfield;
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}
select {
	appearance: none;
	background-color: transparent;
	border: none;
	padding: 0 1.2em 0 0;
	margin: 0;
	width: 100%;
	color: inherit;
	font-family: inherit;
	font-size: inherit;
	cursor: inherit;
	line-height: inherit;
	outline: none;
}
select option {
	color: CanvasText;
	background-color: Canvas;
	font-family: var(--font-family);
	font-size: 16px;
}
select::-ms-expand {
	display: none;
}
.select {
	display: grid;
	grid-template-areas: "select";
	align-items: center;
	cursor: pointer;
}
.select::after {
	content: "";
	width: 0.45em;
	height: 0.45em;
	margin: 0 6px 6px 0;
	border-right: 2px solid var(--pencil);
	border-bottom: 2px solid var(--pencil);
	transform: rotate(40deg);
	justify-self: end;
	pointer-events: none;
}
select,
.select::after {
	grid-area: select;
}

/* Layout */
form,
.results-table {
	display: flex;
	flex-direction: column;
	gap: var(--space-default);
}
.row, .column {
	display: flex;
	justify-content: space-between;
	width: 100%;
}
.row {
	flex-direction: row;
	gap: var(--space-large);
}
.column {
	flex-direction: column;
	justify-content: flex-start;
	gap: 6px;
}
@media screen and (min-width: 621px) {
	/* Keep form fields at half width, even when their neighbour is hidden */
	form .row > .column {
		flex: 1 1 0;
		max-width: calc(50% - var(--space-large) / 2);
	}
}

/* Results, framed in a wobbly pen line */
.results {
	margin-top: var(--space-large);
}
.results h2 {
	margin-bottom: var(--space-default);
}
.results-table {
	position: relative;
	padding: 28px;
	font-size: var(--font-size-default);
}
.results-table .frame {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	overflow: visible;
	fill: none;
	stroke: var(--ink);
	stroke-width: 2px;
	stroke-linecap: round;
	vector-effect: non-scaling-stroke;
	pointer-events: none;
}
.results-table .frame path {
	vector-effect: non-scaling-stroke;
}
.results-message {
	margin: 0;
	color: var(--pencil);
}
.results-table .row {
	align-items: baseline;
	padding-bottom: 6px;
	border-bottom: 1.5px dotted var(--pencil-light);
}
.results-table .row > :last-child {
	flex-shrink: 0;
	color: var(--ink);
	font-family: var(--font-hand);
	font-size: 24px;
	line-height: 1.1;
	text-align: right;
}
.results-table:not(.has-results) .row > :last-child {
	color: var(--pencil-light);
}
.results-table h3 {
	margin-top: var(--space-default);
}

/* The key answer gets circled */
.circled {
	position: relative;
	display: inline-block;
	margin-right: 8px;
}
.circled svg {
	position: absolute;
	inset: -10px -14px -8px;
	width: calc(100% + 28px);
	height: calc(100% + 18px);
	overflow: visible;
	fill: none;
	stroke: var(--ink);
	stroke-width: 2.5px;
	stroke-linecap: round;
	stroke-dasharray: 1;
	stroke-dashoffset: 1;
	vector-effect: non-scaling-stroke;
	pointer-events: none;
}
.has-results .circled svg {
	stroke-dashoffset: 0;
	transition: stroke-dashoffset 0.7s ease-out 0.15s;
}
@media (prefers-reduced-motion: reduce) {
	.has-results .circled svg {
		transition: none;
	}
}

/* Projection table */
.table-wrapper {
	overflow-x: auto;
}
.results-table table {
	border-collapse: collapse;
	width: 100%;
}
.results-table th,
.results-table td {
	padding: 4px var(--space-small);
	text-align: right;
	white-space: nowrap;
}
.results-table th:first-child,
.results-table td:first-child {
	padding-left: 0;
	text-align: left;
}
.results-table th:last-child,
.results-table td:last-child {
	padding-right: 0;
}
.results-table thead th {
	border-bottom: 1px solid var(--pencil-light);
	color: var(--pencil);
	font-size: var(--font-size-small);
	font-weight: 600;
}
.results-table td {
	color: var(--ink);
	font-family: var(--font-hand);
	font-size: 18px;
}

/* Footer, shared layout with other Bored Horse things */
.site-footer {
	margin-top: 64px;
	padding-top: var(--space-large);
	padding-bottom: var(--space-default);
	color: var(--pencil);
	font-size: var(--font-size-small);
	position: relative;
}
/* A hand-drawn squiggle instead of a border */
.site-footer::before {
	content: "";
	position: absolute;
	top: 0;
	left: var(--space-default);
	right: var(--space-default);
	height: 12px;
	background-color: var(--pencil-light);
	-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 12'%3E%3Cpath d='M0 6Q15 0 30 6T60 6' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3C/svg%3E") repeat-x left center / 60px 12px;
	mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 12'%3E%3Cpath d='M0 6Q15 0 30 6T60 6' fill='none' stroke='%23000' stroke-width='1.5'/%3E%3C/svg%3E") repeat-x left center / 60px 12px;
}
.site-footer p {
	margin: 0;
	font-size: inherit;
}
.site-footer a {
	text-decoration: none;
}
.site-footer a:hover {
	color: var(--foreground);
}
.footer-top {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: var(--space-default);
}
.footer-brand {
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.footer-brand p {
	max-width: 20rem;
}
.footer-name {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	color: var(--foreground);
	font-weight: 600;
}
.footer-name img {
	border-radius: 5px;
}
.footer-links {
	display: flex;
	flex-wrap: wrap;
	justify-content: flex-end;
	gap: 8px 20px;
}
.footer-x {
	display: inline-flex;
	align-items: center;
	gap: 6px;
}
.footer-bottom {
	margin-top: 32px !important;
	padding-top: var(--space-default);
	border-top: 1px solid var(--pencil-light);
	color: var(--pencil);
}
.site-footer .footer-bottom a {
	text-decoration: underline;
	text-decoration-color: var(--pencil-light);
	text-underline-offset: 2px;
}

@media screen and (max-width: 620px) {
	.footer-top {
		flex-direction: column;
	}
	.footer-links {
		justify-content: flex-start;
	}
	.row {
		flex-direction: column;
		gap: var(--space-default);
	}
	.results-table {
		padding: 32px var(--space-default) var(--space-default);
	}
	.results-table .row {
		gap: 4px;
	}
	.results-table .row > :last-child {
		text-align: left;
	}
	.circled {
		margin-left: 8px;
	}
}
/* 404 */
.not-found-title {
	margin-top: 0;
	font-size: var(--font-size-large);
}
