/* ============================================================================
   rr.co — main stylesheet

   Hand-edited plain CSS (native nesting, no SASS toolchain). Design tokens live
   as custom properties on :root; the rest is a baseline-grid layout sized in
   rem, with media queries stepping the root font size and the column layout.
   ============================================================================ */


/* ----------------------------------------------------------------------------
   Fonts: Founders Grotesk, Founders Grotesk Text, and Founders Grotesk Mono,
   licensed from Klim Type Foundry for rr.co. The WOFF2 files in static/fonts
   are served as delivered; README.md describes the license.
   ---------------------------------------------------------------------------- */

@font-face {
	font-family: "Founders Grotesk";
	src: url("/https/rr.co/fonts/founders-grotesk-regular.woff2") format("woff2");
	font-weight: 400;
	font-style: normal;
	font-display: swap;
}

@font-face {
	font-family: "Founders Grotesk";
	src: url("/https/rr.co/fonts/founders-grotesk-regular-italic.woff2") format("woff2");
	font-weight: 400;
	font-style: italic;
	font-display: swap;
}

@font-face {
	font-family: "Founders Grotesk";
	src: url("/https/rr.co/fonts/founders-grotesk-medium.woff2") format("woff2");
	font-weight: 500;
	font-style: normal;
	font-display: swap;
}

@font-face {
	font-family: "Founders Grotesk";
	src: url("/https/rr.co/fonts/founders-grotesk-medium-italic.woff2") format("woff2");
	font-weight: 500;
	font-style: italic;
	font-display: swap;
}

@font-face {
	font-family: "Founders Grotesk";
	src: url("/https/rr.co/fonts/founders-grotesk-semibold.woff2") format("woff2");
	font-weight: 600;
	font-style: normal;
	font-display: swap;
}

@font-face {
	font-family: "Founders Grotesk";
	src: url("/https/rr.co/fonts/founders-grotesk-semibold-italic.woff2") format("woff2");
	font-weight: 600;
	font-style: italic;
	font-display: swap;
}

@font-face {
	font-family: "Founders Grotesk Text";
	src: url("/https/rr.co/fonts/founders-grotesk-text-regular.woff2") format("woff2");
	font-weight: 400;
	font-style: normal;
	font-display: swap;
}

@font-face {
	font-family: "Founders Grotesk Text";
	src: url("/https/rr.co/fonts/founders-grotesk-text-regular-italic.woff2") format("woff2");
	font-weight: 400;
	font-style: italic;
	font-display: swap;
}

@font-face {
	font-family: "Founders Grotesk Text";
	src: url("/https/rr.co/fonts/founders-grotesk-text-medium.woff2") format("woff2");
	font-weight: 500;
	font-style: normal;
	font-display: swap;
}

@font-face {
	font-family: "Founders Grotesk Text";
	src: url("/https/rr.co/fonts/founders-grotesk-text-medium-italic.woff2") format("woff2");
	font-weight: 500;
	font-style: italic;
	font-display: swap;
}

@font-face {
	font-family: "Founders Grotesk Mono";
	src: url("/https/rr.co/fonts/founders-grotesk-mono-regular.woff2") format("woff2");
	font-weight: 400;
	font-style: normal;
	font-display: swap;
}

@font-face {
	font-family: "Founders Grotesk Mono";
	src: url("/https/rr.co/fonts/founders-grotesk-mono-medium.woff2") format("woff2");
	font-weight: 500;
	font-style: normal;
	font-display: swap;
}

/* ----------------------------------------------------------------------------
   Design tokens
   ---------------------------------------------------------------------------- */

:root {
	--display-font-family: "Founders Grotesk", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
	--text-font-family: "Founders Grotesk Text", var(--display-font-family);
	--mono-font-family: "Founders Grotesk Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

	--background-color: #fff;
	--base-color: #222;
	--medium-color: #3c3c3c;                       /* lighten(#222, 10%) */
	--light-color: #a2a2a2;                        /* lighten(#222, 50%) */
	--link-color: #0e55c8;
	--link-active-color: #000;
	--link-hover-highlight: rgb(192 222 195 / 0.3);  /* sage green #c0dec3 at 30% */
	--heading-color: #000;
	--code-background-color: rgb(0 0 0 / 0.025);   /* light gray behind inline code */
	--code-keyword-color: #36783c;                 /* the sage hover hue, 126°, at 5.4:1 */
	--code-number-color: #995e00;                  /* amber, 37°, opposite the link blue, at 5.3:1 */
	--code-deletion-color: #c63b10;                /* red-orange, 14°, at 5.2:1 */

	--base-font-weight: 400;
	--strong-font-weight: 500;                     /* Founders Grotesk Medium */
	--heading-font-weight: 500;                    /* Founders Grotesk Medium */

	--root-font-size: 20px;
	--root-line-height: var(--major-grid);

	--major-grid: 1.5rem;
	--minor-grid: 0.75rem;                         /* major-grid * 0.5 */
	--indent: 2.25rem;                             /* major-grid * 1.5 */
	--main-column-width: 48rem;                    /* major-grid * 32 */
	--figure-width: 48rem;                         /* major-grid * 32 */

	--post-font-size: 1rem;                        /* post-body copy: the heading/nav base size */
}


/* ----------------------------------------------------------------------------
   Reset — the load-bearing subset of a normalize, for current browsers
   ---------------------------------------------------------------------------- */

html {
	-webkit-text-size-adjust: 100%;                /* iOS: no orientation-change text inflation */
}

body {
	margin: 0;
}

img {
	border: 0;
}

pre {
	overflow: auto;
	tab-size: 4;
}

sub, sup {
	font-size: 75%;
	line-height: 0;
	position: relative;
	vertical-align: baseline;
}
sup { top: -0.5em; }
sub { bottom: -0.25em; }

table {
	border-collapse: collapse;
	border-spacing: 0;
}
td, th { padding: 0; }

button, input, optgroup, select, textarea {
	color: inherit;
	font: inherit;
	margin: 0;
}


/* ----------------------------------------------------------------------------
   Desktop layout
   ---------------------------------------------------------------------------- */

html {
	font-family: var(--display-font-family);         /* at 20px the display cut sets close enough */
	font-size: var(--root-font-size);
	font-synthesis: none;                            /* no faux bold or oblique: a missing style falls back to the nearest real face */
	/* font-size-adjust: 0.5;  x-height 0.5 em: 10px at the 20px root size, 8px at 16px; Founders Grotesk is 0.437 em */
}

body {
	margin: 0;
	padding: var(--major-grid) 0 0;
	/* Chrome needs explicit font-size on <body> for rem units to work */
	font-size: var(--root-font-size);
	line-height: var(--root-line-height);
	/* sticky footer: body fills viewport, <main> absorbs the slack */
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	min-height: 100dvh; /* dvh accounts for mobile browser chrome */
}

main {
	flex: 1;
}

main footer,
body > header > nav,
body > footer > nav,
main > article > header,
main > article > section > * {
	margin-left: auto;
	margin-right: auto;
	max-width: var(--main-column-width);
}

main > article > section > figure {
	max-width: var(--figure-width);
}


/* ----------------------------------------------------------------------------
   Below the widest screens, narrow the content column from 48rem to 36rem
   breakpoint: 1.5 * 20px * 48 = 1440px
   ---------------------------------------------------------------------------- */

@media screen and (max-width: 1440px) {
	:root {
		--main-column-width: 36rem;                    /* major-grid * 24 */
		--figure-width: 36rem;                         /* major-grid * 24 */
	}
}


/* ----------------------------------------------------------------------------
   Tablet and below: drop the root font size to 16px
   breakpoint: 1.5 * 20px * 32 = 960px
   ---------------------------------------------------------------------------- */

@media screen and (max-width: 960px) {
	:root {
		--root-font-size: 16px;
		font-family: var(--text-font-family);           /* at 16px the display cut sets too tight */
	}
}


/* ----------------------------------------------------------------------------
   Mobile layout transitions to fluid layout
   breakpoint: 1.5 * 16px * (24 + 2) = 624px
   ---------------------------------------------------------------------------- */

@media screen and (max-width: 624px) {
	main footer,
	body > header > nav,
	body > footer > nav,
	main > article > header,
	main > article > section > * {
		max-width: 100vw;
		margin-left: var(--major-grid);
		margin-right: var(--major-grid);
	}

	main > article > section > figure {
		margin-left: auto;
		margin-right: auto;
	}
}


/* ----------------------------------------------------------------------------
   Common styles
   ---------------------------------------------------------------------------- */

body {
	background: var(--background-color);
	color: var(--base-color);
	font-weight: var(--base-font-weight);
}

a {
	color: var(--link-color);
	text-decoration: none;

	&:hover {
		color: var(--link-color);
		/* an underline, not a border: it skips the inline-block arrows */
		text-decoration: underline 1.5px color-mix(in srgb, currentColor 30%, transparent);
		text-underline-offset: 0.2em;

		&:active {
			color: var(--link-active-color);
		}
	}
}

strong, b {
	font-weight: var(--strong-font-weight);
}

p, pre, address, blockquote, fieldset, ul, ol, dl {
	margin: 0 0 var(--major-grid) 0;
	font-size: inherit;
	line-height: inherit;
}

h1, h2, h3, h4, h5, h6 {
	margin: 0;
	font-weight: var(--heading-font-weight);
	font-size: inherit;
	line-height: inherit;
	color: var(--heading-color);

	a {
		color: inherit;

		&:hover {
			color: var(--link-color);

			&:active {
				color: var(--link-active-color);
			}
		}
	}
}

/* heading sizes are in rem, so a heading keeps one size inside and outside
   a post section, where the copy is 0.9rem: h3 to h1 step by 1.25 */

h1 {
	margin-bottom: var(--minor-grid);
	font-family: var(--display-font-family);
	font-size: 1.75rem;
	font-weight: 600;                              /* Founders Grotesk Semibold */
	letter-spacing: -0.01em;
	line-height: calc(var(--minor-grid) * 3);      /* three minor grid lines, plus the margin: two major lines for one line of title */
}

h2 {
	margin-bottom: var(--minor-grid);
	font-family: var(--display-font-family);
	font-size: 1.375rem;
	line-height: calc(var(--minor-grid) * 3);      /* three minor grid lines: about the h1 and copy ratio */
}

h3 {
	margin-bottom: var(--minor-grid);
	font-size: 1.125rem;
	line-height: inherit;
}

h4, h5, h6 {
	margin-bottom: var(--minor-grid);
	color: var(--medium-color);
	font-size: var(--post-font-size);      /* the post copy size, set apart by uppercase */
	line-height: inherit;
	text-transform: uppercase;
}

pre, code {
	font-family: var(--mono-font-family);
	font-synthesis-style: auto;  /* Founders Grotesk Mono has no italic, so allow an oblique here */
	/* font-size: 90%;  Founders Grotesk Mono shares the 0.437 em x-height of the text cuts, so code runs at 100% */
	line-height: inherit;
}

/* inline code: gray pill */
code {
	background: var(--code-background-color);
	border-radius: 0.2em;
	padding: 0.1em 0.3em;  /* slightly more horizontal than vertical */
	line-height: 1;        /* the mono baseline sits higher than the body baseline, so a full-height inline box would push the line off the grid */
}

/* code blocks are already a block; no pill chrome. The <code> inside takes the
   <pre> font size rather than scaling it again. */
pre code {
	background: none;
	border-radius: 0;
	padding: 0;
	font-size: inherit;
	line-height: inherit;
}

/* a code block takes the inline code gray. Half a line of padding above and
   below keeps it on the grid. */
pre {
	background: var(--code-background-color);
	border-radius: 0.2em;
	padding: var(--minor-grid);
}

/* syntax highlighting: Hugo marks fenced code with Chroma classes
   (markup.highlight.noClasses = false in hugo.toml). The palette adds three
   hues to the site blue and pink: amber (37°) across the color wheel from the
   blue, a green at the sage hover hue (126°) near the pink complement, and a
   red-orange (14°) for deletions. Pink marks only function and class names,
   which Chroma tags where they are declared and, in some lexers such as Go,
   where they are called. Each text color clears 4.5:1 on white, except
   comments in --light-color. Operators, punctuation, and other names keep
   the text color. */
.chroma {
	/* comments */
	:is(.c, .c1, .ch, .cm, .cp, .cpf, .cs) { color: var(--light-color); }

	/* keywords, builtins, and markup tags */
	:is(.k, .kd, .kn, .kp, .kr, .kt, .nb, .bp, .nt) { color: var(--code-keyword-color); }

	/* strings */
	:is(.s, .s1, .s2, .sa, .sb, .sc, .sd, .se, .sh, .si, .sr, .ss, .sx, .dl) { color: var(--link-color); }

	/* numbers and constants such as true and null */
	:is(.m, .mb, .mf, .mh, .mi, .mo, .il, .kc) { color: var(--code-number-color); }

	/* function and class names: the header pink */
	:is(.nf, .fm, .nc) { color: rgb(227 28 121); }

	/* diffs */
	.gi { color: var(--code-keyword-color); }
	.gd { color: var(--code-deletion-color); }
	:is(.gh, .gu) { color: var(--light-color); }
}

ul, ol {
	padding: 0;

	& > li {
		margin-left: var(--indent);
	}
}

img {
	margin: 0;
	border: 0;
	vertical-align: bottom;
}

figure {
	display: block;
	position: relative;
	margin: 0 0 var(--major-grid) 0;
	padding: 0;
}

small {
	/* smaller-text */
	font-size: 80%;
	font-family: var(--text-font-family);  /* small type at every width */
	line-height: inherit;
}


/* ----------------------------------------------------------------------------
   Common layout
   ---------------------------------------------------------------------------- */

body > header {
	margin-bottom: var(--minor-grid);

	h1 {
		display: inline;
		font-family: inherit;
		font-size: inherit;
		line-height: inherit;
	}
}

body > header,
body > footer {
	/* smaller-text */
	font-size: 80%;
	font-family: var(--text-font-family);  /* small type at every width */
	line-height: inherit;

	h3 {
		font-size: inherit;                    /* a header or footer heading takes the smaller-text size */
	}

	.copyright {
		font-weight: var(--base-font-weight);
		opacity: 0.3;                          /* the header arrow alpha: dims the heading color and blends with the footer background */
	}

	nav {
		ul {
			margin: 0 0 calc(var(--major-grid) * 2) 0;
			padding: 0;

			li {
				display: inline-block;
				margin: 0 0.66em 0 0;

				a.home {
					font-weight: var(--strong-font-weight);
				}
			}
		}
	}
}

body > header {
	a {
		color: rgb(227 28 121); /* Pantone 213: https://www.pantone.com/color-finder/213-c */
		&:hover {
			color: rgb(227 28 121); /* stay pink on hover, not the global blue */

			&:active {
				color: var(--link-active-color);
			}
		}
	}
}

body > footer {
	padding-top: calc(var(--major-grid) * 2);
	padding-bottom: calc(var(--major-grid) * 2);
	background: var(--link-hover-highlight);
}

main {
	margin-bottom: calc(var(--major-grid) * 2);

	article {
		margin-bottom: calc(var(--major-grid) * 4);

		& > header {
			position: relative;
		}

		& > footer {
			clear: both;
			/* smaller-text */
			font-size: 80%;
			font-family: var(--text-font-family);  /* small type at every width */
			line-height: inherit;

			/* the posted line follows the Continue link with no gap */
			& > p:has(> a.more) {
				margin-bottom: 0;
			}
		}

		& > section {
			margin: var(--minor-grid) 0;
			font-size: var(--post-font-size);
		}

		/* a category page with its own text lists its posts in a second
		   section, set two grid lines below the text */
		& > section + section {
			margin-top: calc(var(--major-grid) * 2);
		}

		/* figures display large images, video, iframes */
		figure > div {
			position: relative;
			overflow: hidden;
			height: 0;

			& > iframe {
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 100%;
				background: transparent;
				border: 0;
			}
		}

		/* table in a post: the reset above zeroes cell padding */
		table {
			width: 100%;
			margin-bottom: var(--root-line-height);

			& th, & td {
				padding-right: var(--minor-grid);
				vertical-align: top;
			}
		}

		/* full-bleed figure: width disabled (figures stay within column), centering kept */
		figure.full {
			text-align: center;

			& > img,
			& > a > img,
			& > video {
				width: 100%;
			}
		}

		/* 180px height for MixCloud player */
		figure.mixcloud > div { height: 180px; }

		/* 16:9 aspect ratio */
		figure.video > div { padding-top: 56.5%; }

		/* 4:3 ratio + 40px padding for controls */
		figure.slideshare > div {
			padding-top: 75%;
			padding-bottom: 40px;
		}

		figure.square > div { padding-top: 100%; }

		/* gallery of images */
		figure.gallery img {
			margin-bottom: var(--minor-grid);
		}

		img, iframe, embed, object, video {
			max-width: 100%;
			height: auto;

			&.full { width: 100%; }
			/* third: a third of the column, rounded to whole lines so the image
			   ends on the typographic grid, and at most 8 lines on either side.
			   It rounds to the nearest line, not down: a third of 720px comes
			   out a hair under 240px in layout units, and rounding down would
			   lose a whole line. A taller image is cropped rather than squeezed.
			   A browser without round() drops the width, and the image falls
			   back to its own size, capped at 8 lines. */
			&.third {
				width: round(nearest, calc(100% / 3), var(--root-line-height));
				max-width: calc(var(--root-line-height) * 8);
				max-height: calc(var(--root-line-height) * 8);
				object-fit: cover;
			}
		}

		blockquote {
			font-style: italic;

			& > * {
				margin-left: var(--major-grid);
			}
		}

		.left {
			float: left;
			margin: 0 var(--major-grid) var(--major-grid) 0;
		}

		.right {
			float: right;
			margin: 0 0 var(--major-grid) var(--major-grid);
		}

		/* pill: a radius larger than any box. The browser scales overlapping
		   radii down to half the shorter side, which makes a circle on a
		   square and a capsule on a rectangle. */
		.pill {
			border-radius: 100vmax;
		}

		/* A float directly in a post section, such as a bare <img class="right">
		   in an imported post, spans the full section width, and auto margins
		   do not center a float. Its outer margin is the distance from the
		   section edge to the column edge, or the mobile gutter. */
		& > section > .left {
			margin-left: max(var(--major-grid), calc((100% - var(--main-column-width)) / 2));
		}

		& > section > .right {
			margin-right: max(var(--major-grid), calc((100% - var(--main-column-width)) / 2));
		}

		/* title and the posted line or summary below it on an archive page: no
		   gap between the two, which keeps the pair on the grid and groups the
		   line with its title */
		& > section > h3:has(+ p:is(.meta, .summary)) {
			margin-bottom: 0;
		}

		& > section > p.meta {
			/* smaller-text */
			font-size: 80%;
			font-family: var(--text-font-family);  /* small type at every width */
			line-height: inherit;
		}

		/* the posted line follows a summary with no gap */
		& > section > p.summary:has(+ p.meta) {
			margin-bottom: 0;
		}

		/* one line on the grid: the text wraps at word boundaries, and the box
		   hides every line after the first, so the line ends on a whole word */
		& > section > p.summary {
			max-height: var(--major-grid);
			overflow: hidden;
		}

		p.import {
			/* smaller-text */
			font-size: 80%;
			font-family: var(--text-font-family);  /* small type at every width */
			line-height: inherit;
			font-style: italic;
			color: var(--light-color);
		}

		p.gallery {
			max-width: calc(var(--major-grid) * 19);

			img {
				float: left;
				margin: 0 var(--minor-grid) var(--minor-grid) 0;
			}
		}
	}
}

nav.pagination {
	/* smaller-text */
	font-size: 80%;
	font-family: var(--text-font-family);  /* small type at every width */
	line-height: inherit;
	font-weight: var(--strong-font-weight);

	a {
		margin-right: 1em;
	}

	/* the arrows live here, not in the link text */
	a.prev::before { content: "←"; display: inline-block; font-family: var(--mono-font-family); margin-right: 0.25em; }
	a.next::after { content: "→"; display: inline-block; font-family: var(--mono-font-family); margin-left: 0.25em; }
}

a.more {
	font-weight: var(--strong-font-weight);

	&::after { content: "→"; display: inline-block; font-family: var(--mono-font-family); margin-left: 0.25em; }
}

/* a header link to another site ends in ↗ (U+2197 north east arrow), in the
   same mono face as the pagination arrows, at 30% opacity, the alpha of
   --link-hover-highlight, so it takes a lighter tone of the link color. Links
   in posts carry no arrow. The :not() list holds rr.co and the dev server,
   whose absolute links start with http://localhost. The empty alt text keeps
   a screen reader from reading the arrow aloud. */
body > header a[href^="http"]:not([href^="https://rr.co"], [href^="http://localhost"])::after {
	content: "↗" / "";
	display: inline-block;
	font-family: var(--mono-font-family);
	margin-left: 0.1em;
	opacity: 0.3;
}
