/*
Theme Name: sirre.al
Author: Jon Surrell
Description: Semantic HTML on browser defaults, with optional era styles picked from a style dot.
Version: 0.1.1
Requires at least: 6.9
Requires PHP: 7.4
License: GPL-2.0-or-later
Text Domain: sirreal
*/

/*
 * Base style: "Prof. Dr.". This is the whole stylesheet for the default page.
 * Everything else is the browser's own defaults: Times, Canvas, CanvasText,
 * default form controls. The era stylesheet, eras.css, restyles the same
 * markup when a visitor picks an era from the style dot.
 */

:root {
	color-scheme: light dark;
	--hue: 195; /* the one per-site value: blog 195, Live DOM Viewer 319, Encoding 264 */
	--link: light-dark(oklch(0.45 0.14 var(--hue)), oklch(0.8 0.11 var(--hue)));
	--sunk: color-mix(in oklch, CanvasText 6%, Canvas);
	accent-color: var(--link);
}

body {
	margin: 0;
	padding: 8px 1rem;
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 0 2rem;
}

main { overflow-wrap: break-word; }

a { color: var(--link); }
a:visited { color: color-mix(in oklch, var(--link) 65%, CanvasText); }

h1, h2 { text-wrap: balance; }
p, li, dd { text-wrap: pretty; }

:not(pre) > code { background: var(--sunk); padding: 0 0.2em; overflow-wrap: anywhere; }

/*
 * Code blocks. WordPress.com renders a highlighted code block as a
 * div.wp-block-code around .cm-editor > .cm-scroller > pre > code > .cm-line,
 * with .tok-* spans, and its stylesheet removes the inner pre's box with
 * !important. The box is therefore .wp-block-code, or a pre outside one.
 * Each era sets the --code-* box values and the --tok-* token colors; a token
 * with no color set takes the text color.
 */
:is(.wp-block-code, pre):not(.wp-block-code *) {
	margin-block: 1em;
	padding: var(--code-padding, 1em);
	overflow-x: auto;
	border: var(--code-border, none);
	border-radius: var(--code-radius, 0);
	box-shadow: var(--code-shadow, none);
	font-family: var(--code-font, monospace);
	font-size: var(--code-size);
}
/* The Solarized block styles set their own background and text colors. */
:is(.wp-block-code, pre):not(.wp-block-code *, .is-style-solarized-light, .is-style-solarized-dark) {
	background: var(--code-bg, var(--sunk));
	color: var(--code-fg, inherit);
	text-shadow: var(--code-glow, none);
}
:is(.wp-block-code, pre) :is(pre, code) { font: inherit; }
.wp-block-code:has(> .cm-editor) { overflow: visible; }
/* WordPress.com's flex layout is for its div; an unhighlighted pre.wp-block-code stays a block. */
pre.wp-block-code { display: block; }
.wp-block-code .cm-line { padding: 0; }

/* WordPress.com's stylesheet colors these eleven token groups from these properties. */
:root {
	--wp--custom--core-code--comment: var(--tok-comment, currentColor);
	--wp--custom--core-code--keyword: var(--tok-keyword, currentColor);
	--wp--custom--core-code--boolean: var(--tok-boolean, currentColor);
	--wp--custom--core-code--literal: var(--tok-literal, currentColor);
	--wp--custom--core-code--string: var(--tok-string, currentColor);
	--wp--custom--core-code--special-string: var(--tok-special-string, currentColor);
	--wp--custom--core-code--macro-name: var(--tok-macro-name, currentColor);
	--wp--custom--core-code--variable-definition: var(--tok-definition, currentColor);
	--wp--custom--core-code--type-name: var(--tok-type-name, currentColor);
	--wp--custom--core-code--class-name: var(--tok-class-name, currentColor);
	--wp--custom--core-code--invalid: var(--tok-invalid, currentColor);
}

/* It leaves these tokens uncolored. The block styles with their own palette keep them uncolored. */
.wp-block-code:not(.is-style-no-highlight, .is-style-solarized-light, .is-style-solarized-dark) {
	& .tok-number { color: var(--tok-number, currentColor); }
	& .tok-meta { color: var(--tok-meta, currentColor); }
	& .tok-operator { color: var(--tok-operator, currentColor); }
	& .tok-punctuation { color: var(--tok-punctuation, currentColor); }
	& .tok-propertyName:not(.tok-definition) { color: var(--tok-property, currentColor); }
}

/*
 * Prof. Dr.: a green phosphor terminal. One color at three intensities, as on a
 * monochrome display: bold and bright for keywords and names, dim for comments,
 * reverse video for invalid tokens and the header line.
 */
:root:not([data-style]) {
	--code-bg: #050f07;
	--code-fg: #41e070;
	--code-glow: 0 0 3px rgb(65 224 112 / 0.45);
	--tok-keyword: #b8ffcb;
	--tok-boolean: #b8ffcb;
	--tok-definition: #b8ffcb;
	--tok-type-name: #b8ffcb;
	--tok-class-name: #b8ffcb;
	--tok-macro-name: #b8ffcb;
	--tok-comment: #2fa553;
	--tok-meta: #2fa553;
	--tok-invalid: #050f07;

	& .wp-block-code {
		& .tok-keyword { font-weight: bold; }
		& .tok-invalid { background: #41e070; text-shadow: none; }
	}
	& .a8c\/code__header {
		min-height: 0;
		margin: -1em -1em 0;
		padding: 0 1em;
		background: #41e070;
		color: #050f07;
		text-shadow: none;
	}
	& .a8c\/code__btn-copy {
		padding: 0;
		border: 0;
		background: none;
		color: inherit;
		font: inherit;
		cursor: pointer;
	}
	& .a8c\/code__btn-copy::before { content: "["; }
	& .a8c\/code__btn-copy::after { content: "]"; }
}

img { max-width: 100%; height: auto; }
:is(input, textarea, select) { box-sizing: border-box; max-width: 100%; }

/*
 * Background presets used in post content. WordPress's generated preset styles
 * are not loaded, so each one is defined here against Canvas and follows the
 * light or dark scheme of the page and of each era.
 */
.has-accent-1-background-color,
.has-accent-2-background-color { background-color: var(--sunk); }
.has-light-green-cyan-background-color { background-color: color-mix(in oklch, #7bdcb5 30%, Canvas); }

/* Site frame. DOM order is header, main, aside, footer. */

/* The light, dark and system scheme picker exists only in the dark era (eras.css). */
.scheme-picker { display: none; }

/* Profile link icons show only in the flat and dark eras (eras.css). */
.profile-icon { display: none; }

/* The feed icon is beside the link text; the flat and dark eras show the icon alone (eras.css). */
.feed-icon {
	width: 1em;
	height: 1em;
	margin-right: 0.3em;
	vertical-align: -0.125em;
}

/* The WordPress mark follows the WordPress link text in the footer. */
.wordpress-mark {
	width: 1em;
	height: 1em;
	margin-left: 0.25em;
	vertical-align: -0.125em;
}

/* The site name and About lead the header; the tools links follow at its end, smaller. */
body > header nav {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: baseline;
	column-gap: 2em;
}
body > header .tools { font-size: smaller; }

body > header ul {
	display: flex;
	flex-wrap: wrap;
	margin: 0;
	padding: 0;
	list-style: none;
}

/* Header links are at least 24px tall (WCAG 2.2 target size). */
body > header a {
	display: inline-block;
	box-sizing: border-box;
	min-height: 24px;
	padding-block: 0.25em;
}

body > header li + li::before {
	content: "|";
	content: "|" / "";
	margin: 0 0.5em;
}

main > *,
main > article > *,
body > footer {
	max-width: 65ch;
}

/* Wide content (diagrams) uses the whole column; the text beside it keeps its measure. */
main > article { max-width: none; }
main > article > :is(.alignwide, .alignfull) { max-width: none; }
main > article > hr { margin-inline: 0; }

body > aside { overflow-wrap: anywhere; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 0.5rem; top: 0.5rem; z-index: 20; padding: 0.5em 1em; background: Canvas; }

/* Wide screens: the aside moves to a left column. On phones it stays below the content. */
@media (min-width: 48rem) {
	body { grid-template-columns: 11rem minmax(0, 1fr); }
	body > header { grid-column: 1 / -1; }
	body > aside { grid-column: 1; grid-row: 2 / span 2; }
	body > main { grid-column: 2; grid-row: 2; }
	body > footer { grid-column: 2; grid-row: 3; }
	body > aside > hr { display: none; }
}

/*
 * Style dot. Fixed to the corner and styled with system colors only, so no era
 * moves or restyles it. Its button shows the current era's icon from icons/,
 * chosen by the root's data-style. The panel is a modal dialog with a
 * transparent backdrop, so the page behind it shows the chosen style. Its size
 * is in px because the eras change the root font size.
 */

.style-dot {
	position: fixed;
	right: 12px;
	bottom: 12px;
	z-index: 10;
}

.style-dot > button {
	width: 48px;
	height: 48px;
	padding: 0;
	border: 0;
	background: url(icons/prof.gif) center / 48px 48px no-repeat;
	cursor: pointer;
	color-scheme: light dark;
}

[data-style="home-page"] .style-dot > button { background-image: url(icons/home-page.gif); }
[data-style="blog"] .style-dot > button { background-image: url(icons/blog.svg); }
[data-style="skeuo"] .style-dot > button { background-image: url(icons/skeuo.png); }
[data-style="flat"] .style-dot > button { background-image: url(icons/flat.svg); }
[data-style="dark"] .style-dot > button { background-image: url(icons/dark.svg); }
[data-style="markdown"] .style-dot > button { background-image: url(icons/markdown.svg); }

/* The pixel-art GIFs scale with hard edges. */
:root:not([data-style]) .style-dot > button,
[data-style="home-page"] .style-dot > button { image-rendering: pixelated; }

/* Reduced motion shows the first frame of the animated GIFs. */
@media (prefers-reduced-motion: reduce) {
	.style-dot > button { background-image: url(icons/prof-still.gif); }
	[data-style="home-page"] .style-dot > button { background-image: url(icons/home-page-still.gif); }
}

#style-pop {
	color-scheme: light dark;
	inset: auto 12px 64px auto;
	box-sizing: border-box;
	width: 288px;
	max-width: calc(100% - 24px);
	max-height: none;
	margin: 0;
	padding: 8px 12px;
	border: 1px solid CanvasText;
	background: Canvas;
	color: CanvasText;
	font: 14px/1.4 system-ui, sans-serif;
	text-shadow: none;
}

#style-pop::backdrop { background: transparent; }
#style-pop .head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#style-pop form { margin: 0; }
#style-pop .head button { min-height: 24px; font: inherit; }
#style-pop .row { display: flex; align-items: center; gap: 8px; }
#style-pop input { flex: 1; min-width: 0; min-height: 44px; margin: 0; }
#style-pop output { font-weight: 700; }
