/* Site-wide styles. build.py copies everything in static/ to the site root.

   Theme: SNES-RPG menu windows, in Lufia II's style. The window frame,
   dividers and background are 8x8-pixel tiles from the game, scaled up by
   --px with nearest-neighbour scaling so the pixels stay sharp:

     frame.png       window frame: corner, edge and fill tiles from border.png,
                     mirrored for the right and bottom sides like the SNES does
     divider*.png    the horizontal divider and the pieces that join it to
                     the left and right edges of the frame
     bricks.png      background tile from sprites.png
     crystal-*.png   the menu cursor (6 frames of a spinning crystal) and the
                     shimmering gem marking the selected item (5 frames),
                     from sprites.png */

:root {
	/* One SNES pixel. Everything drawn on the pixel grid scales by this. */
	--px: 3px;

	--bg: #302820;           /* a dark brick colour, shown until bricks.png loads */
	--window: #a89070;       /* the frame's fill tile */
	--ink: #261c12;
	--ink-shadow: #bba384;
	--ink-dim: #3e3e4c;      /* greyed-out menu text */
	--link: #142259;
	--link-visited: #3e1a46;
	--inset: #9c8466;        /* sunken panels */
	--bevel-dark: #604828;
	--bevel-light: #bba384;

	/* Fonts: --font-ui for menu-like text (nav, headings), --font-body for
	   everything else. --shadow is the drop-shadow offset under text.
	   Inconsolata is self-hosted (see @font-face below); the rest are
	   fallbacks if it doesn't load. */
	--font-body: Inconsolata, Consolas, Menlo, "DejaVu Sans Mono", ui-monospace, monospace;
	--font-ui: var(--font-body);
	--font-size: 20px;
	--shadow: 1px;

	/* Window frame: one 8-pixel tile wide on each side. The outer half is the
	   carved border, the inner half is window fill. */
	--frame: url("frame.png");
	--frame-width: calc(8 * var(--px));
	/* Space between the frame and the text, horizontally. */
	--window-padding: calc(2 * var(--px));

	/* A divider across a window, joined to the frame at both ends. */
	--divider:
		url("divider-left.png") left bottom / var(--frame-width) var(--frame-width) no-repeat,
		url("divider-right.png") right bottom / var(--frame-width) var(--frame-width) no-repeat,
		url("divider.png") left bottom / calc(16 * var(--px)) var(--frame-width) repeat-x;

	/* Menu markers, each a strip of animation frames: the spinning crystal
	   cursor (six 12x8 frames) and the selected gem (five 9x9 frames). */
	--cursor: url("crystal-cursor.png");
	--selected: url("crystal-selected.png");
}

/* Inconsolata 3.000 (SIL Open Font License, fonts/OFL.txt), from
   github.com/googlefonts/Inconsolata. Cut down from the variable font for
   the web: normal width only, weights 400-700, Latin, Latin-1, Latin
   Extended-A and general punctuation. Other characters fall back to the next
   font in --font-body. templates/page.html preloads it. */
@font-face {
	font-family: Inconsolata;
	src: url("fonts/Inconsolata.woff2") format("woff2");
	font-weight: 400 700;
	font-display: swap;
}

@media (max-width: 40rem) {
	:root {
		--px: 2px;
		--font-size: 17px;
	}
}

html {
	/* 32x32 brick tile, scaled up like everything else. */
	background: var(--bg) url("bricks.png") 0 0 / calc(32 * var(--px)) repeat;
	/* Nearest-neighbour scaling for the pixel art (inherited; photos and the
	   chess board opt back out below). */
	image-rendering: pixelated;
}

body {
	max-width: 46rem;
	margin: 0 auto;
	padding: calc(6 * var(--px)) calc(4 * var(--px));
	font: var(--font-size)/1.5 var(--font-body);
	color: var(--ink);
	text-shadow: var(--shadow) var(--shadow) 0 var(--ink-shadow);
}

/* The windows. The frame's edges repeat their tiles rather than stretching,
   so any window size keeps whole pixels. */
header,
main,
figure {
	border: var(--frame-width) solid transparent;
	border-image: var(--frame) 8 fill / var(--frame-width) repeat;
	padding: 0 var(--window-padding);
}

header,
main {
	margin-bottom: calc(4 * var(--px));
}

/* The nav is a menu. The current page is marked with the round gem; the
   spinning crystal cursor points at whatever you hover or tab to (and covers
   the gem when that's the current page). build.py puts the page's section
   (home, projects, blog, chess, cats) in <body class="...">. */
nav {
	display: flex;
	flex-wrap: wrap;
	column-gap: 0.75em;
}

nav a {
	position: relative;
	/* Room on the left for the marker. */
	margin-left: calc(14 * var(--px));
	color: var(--ink);
	font-family: var(--font-ui);
	text-decoration: none;
}

/* The marker. These two rules use :where() so they have no specificity and
   the cursor rule below always wins over them. */
:where(nav a)::before {
	content: "";
	position: absolute;
	right: calc(100% + 2 * var(--px));
	top: 50%;
	transform: translateY(-50%);
	visibility: hidden;
}

:where(body.home nav .home,
       body.projects nav .projects,
       body.blog nav .blog,
       body.chess nav .chess,
       body.cats nav .cats)::before {
	visibility: visible;
	width: calc(9 * var(--px));
	height: calc(9 * var(--px));
	background: var(--selected) 0 0 / calc(45 * var(--px)) 100%;
}

nav a:hover::before,
nav a:focus-visible::before {
	visibility: visible;
	width: calc(12 * var(--px));
	height: calc(8 * var(--px));
	background: var(--cursor) 0 0 / calc(72 * var(--px)) 100%;
}

@media (prefers-reduced-motion: no-preference) {
	:where(body.home nav .home,
	       body.projects nav .projects,
	       body.blog nav .blog,
	       body.chess nav .chess,
	       body.cats nav .cats)::before {
		animation: gem-shimmer 1.6s step-end infinite;
	}

	nav a:hover::before,
	nav a:focus-visible::before {
		animation: crystal-spin 0.6s steps(6) infinite;
	}
}

/* Over the 1.6s loop, the gem rests on its first frame for 1.2 seconds, then
   the highlight runs round it: four frames at a tenth of a second (6.25%)
   each. step-end holds each frame until the next keyframe. */
@keyframes gem-shimmer {
	0% {
		background-position-x: 0;
	}
	75% {
		background-position-x: calc(-9 * var(--px));
	}
	81.25% {
		background-position-x: calc(-18 * var(--px));
	}
	87.5% {
		background-position-x: calc(-27 * var(--px));
	}
	93.75% {
		background-position-x: calc(-36 * var(--px));
	}
}

@keyframes crystal-spin {
	to {
		background-position-x: calc(-72 * var(--px));
	}
}

/* The cursor shows keyboard focus in the nav, so it doesn't need an outline. */
nav a:focus-visible {
	outline: none;
}

body.home nav .home,
body.projects nav .projects,
body.blog nav .blog,
body.chess nav .chess,
body.cats nav .cats {
	font-weight: 600;
}

/* Text inside the windows. */
h1,
h2,
h3 {
	font-family: var(--font-ui);
	font-weight: 600;
	line-height: 1.2;
	letter-spacing: 0.03em;
}

/* The page title sits in its own section at the top of the window, with a
   divider under it that joins the frame on both sides. It reaches out over
   the frame so the divider's end pieces land on the frame's edges. */
h1 {
	margin: 0 calc(-1 * (var(--frame-width) + var(--window-padding)));
	padding: calc(2 * var(--px)) calc(var(--frame-width) + var(--window-padding)) calc(var(--frame-width) + 2 * var(--px));
	font-size: 1.6em;
	background: var(--divider);
}

hr {
	height: var(--frame-width);
	margin-inline: calc(-1 * (var(--frame-width) + var(--window-padding)));
	border: 0;
	background: var(--divider);
}

a {
	color: var(--link);
	text-decoration-thickness: 2px;
	text-underline-offset: 3px;
}

a:visited {
	color: var(--link-visited);
}

time,
.date {
	color: var(--ink-dim);
}

.page-list {
	list-style: none;
	padding: 0;
}

.page-list li {
	margin-bottom: 0.75em;
}

.page-list p {
	margin: 0.25em 0 0;
}

/* Sunken panels for code and quotes. */
pre,
code,
blockquote {
	background: var(--inset);
}

pre,
blockquote {
	margin-inline: 0;
	padding: calc(3 * var(--px)) calc(4 * var(--px));
	box-shadow:
		inset var(--px) var(--px) 0 var(--bevel-dark),
		inset calc(-1 * var(--px)) calc(-1 * var(--px)) 0 var(--bevel-light);
}

code {
	padding: 0 0.2em;
	/* Same font as the text around it; the sunken background marks it out. */
	font-family: inherit;
	font-size: inherit;
	text-shadow: none;
}

pre code {
	padding: 0;
}

/* Long lines in code blocks (e.g. PGN move lists) wrap instead of scrolling. */
pre {
	white-space: pre-wrap;
}

/* Superscripts and subscripts don't push their line away from its
   neighbours. */
sup,
sub {
	line-height: 0;
}

/* Footnotes. Pandoc turns [^1] into a superscript link to the note
   (a.footnote-ref) and collects the notes at the end of the page in
   section.footnotes: a divider (its <hr>), then a numbered list where each
   note ends in a link back (a.footnote-back). Following a reference makes
   its note :target, which gets the selected gem. On pages with notes inside
   notes, footnotes.lua writes the same markup itself. */
a.footnote-ref,
a.footnote-back {
	/* Jumps within the page; whether you've followed one before doesn't
	   matter. */
	color: var(--link);
	text-decoration: none;
}

a.footnote-ref:hover,
a.footnote-back:hover {
	text-decoration: underline;
}

.footnote-ref {
	/* Coming back, leave the lines you'd just read in view above it. */
	scroll-margin-top: 30vh;
}

.footnote-ref sup {
	padding: 0 0.15em;
	font-weight: 600;
}

.footnote-back {
	margin-left: 0.5ch;
}

.footnotes {
	font-size: 0.9em;
}

.footnotes ol {
	/* Room on the left for the gem, then numbers up to "99. ". */
	padding-left: calc(14 * var(--px) + 4ch);
}

.footnotes li {
	position: relative;
	scroll-margin-top: calc(4 * var(--px));
}

.footnotes li p {
	margin: 0.5em 0;
}

/* The gem sits at the left of the list, level with the note's first line.
   Coming back from a note inside a note, the reference you return to is the
   target, so the note it's in gets the gem. */
.footnotes li:target::before,
.footnotes li:has(.footnote-ref:target)::before {
	content: "";
	position: absolute;
	left: calc(-14 * var(--px) - 4ch);
	top: 0.5lh;
	transform: translateY(-50%);
	width: calc(9 * var(--px));
	height: calc(9 * var(--px));
	background: var(--selected) 0 0 / calc(45 * var(--px)) 100%;
}

@media (prefers-reduced-motion: no-preference) {
	.footnotes li:target::before,
	.footnotes li:has(.footnote-ref:target)::before {
		animation: gem-shimmer 1.6s step-end infinite;
	}
}

/* Images shrink to fit the page; height follows to keep the aspect ratio. */
img {
	max-width: 100%;
	height: auto;
	image-rendering: auto;
}

/* Pandoc puts an image on its own line in a <figure> with a caption; that
   becomes a small window around the picture. */
figure {
	box-sizing: border-box;
	width: fit-content;
	max-width: 100%;
	margin: 1em auto;
}

figure img {
	display: block;
}

figcaption {
	padding: var(--px) 0;
	text-align: center;
}

/* Interactive chess boards made by pgn.js, framed like a window. The viewer's
   colours are CSS variables: --board-color, --c-lpv-bg, --c-lpv-font, ... */
.pgn-board {
	max-width: 40rem;
	margin-bottom: 2em;
	border: var(--frame-width) solid transparent;
	border-image: var(--frame) 8 / var(--frame-width) repeat;
	text-shadow: none;

	/* A dark sub-window in the background's browns. */
	--board-color: #886f46;
	--c-lpv-bg: #3a2d20;
	--c-lpv-bg-controls: #30251a;
	--c-lpv-bg-movelist: #3a2d20;
	--c-lpv-bg-player: #30251a;
	--c-lpv-bg-variation: #33271b;
	--c-lpv-bg-pane: #2a2016;
	--c-lpv-border: #54421a;
	--c-lpv-side-border: #271d13;
	--c-lpv-font: #d8c6a4;
	--c-lpv-past-moves: #b8a68a;
	--c-lpv-font-shy: #8c7a5c;
	--c-lpv-font-bg: #6a5a44;
	--c-lpv-accent: #3e5aa8;
	--c-lpv-current-move: #3e5aa8;
}

/* The frame stays pixelated; the board inside scales smoothly. */
.pgn-board > * {
	image-rendering: auto;
}

/* The Mondrian automaton (projects/mondrian/mondrian.js): a window with the
   picture in a sunken panel, a divider, then a row of controls. */
.mondrian {
	margin: 1em 0;
	padding: calc(2 * var(--px)) var(--window-padding);
	border: var(--frame-width) solid transparent;
	border-image: var(--frame) 8 fill / var(--frame-width) repeat;
}

.mondrian canvas {
	display: block;
	box-sizing: border-box;
	width: 100%;
	/* Overrides the canvas's own width:height, which mondrian.js sets to
	   match this. */
	aspect-ratio: 4 / 3;
	border: var(--px) solid;
	border-color: var(--bevel-dark) var(--bevel-light) var(--bevel-light) var(--bevel-dark);
	background: #fff;
}

.mondrian hr {
	margin-block: calc(2 * var(--px));
}

.mondrian-controls {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: calc(2 * var(--px)) 0.75em;
}

/* Raised buttons that press in, and a sunken text box, in the window's
   bevel colours. */
.mondrian button,
.mondrian input {
	font: inherit;
	color: inherit;
	text-shadow: inherit;
	border: var(--px) solid;
	border-radius: 0;
}

.mondrian button {
	padding: 0 0.5em;
	background: var(--window);
	border-color: var(--bevel-light) var(--bevel-dark) var(--bevel-dark) var(--bevel-light);
	cursor: pointer;
}

.mondrian button:hover {
	background: var(--ink-shadow);
}

.mondrian button:active {
	background: var(--inset);
	border-color: var(--bevel-dark) var(--bevel-light) var(--bevel-light) var(--bevel-dark);
}

.mondrian input {
	width: 10ch;
	padding: 0 0.25em;
	background: var(--inset);
	border-color: var(--bevel-dark) var(--bevel-light) var(--bevel-light) var(--bevel-dark);
}

.mondrian-status {
	margin-left: auto;
	color: var(--ink-dim);
}
