/* Theme follows the OS unless <html data-theme="light|dark"> is set by the toggle. */
:root {
	color-scheme: light;
	--bg: #f5f5f5;
	--fg: #1a1a1a;
	--error: #b00020;
	/* Logo art is black fill + white outline (built for dark), so light theme inverts it. */
	--logo-filter: invert(1);
	--show-if-light: block;
	--show-if-dark: none;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme='light']) {
		color-scheme: dark;
		--bg: #0d0d0d;
		--fg: #e0e0e0;
		--error: #ff6b6b;
		--logo-filter: none;
		--show-if-light: none;
		--show-if-dark: block;
	}
}

:root[data-theme='dark'] {
	color-scheme: dark;
	--bg: #0d0d0d;
	--fg: #e0e0e0;
	--error: #ff6b6b;
	--logo-filter: none;
	--show-if-light: none;
	--show-if-dark: block;
}

/* A classic scrollbar takes width from the page. Its gutter is kept on pages too short to scroll,
   so the navbar and centred content do not shift sideways between a page that scrolls and one that
   does not, which the cross-fade below would show as a jump (tests/e2e/scrollbar.spec.js). */
html {
	scrollbar-gutter: stable;
}

/* Page changes. A link swaps the next page's <main> in place (router.js) and cross-fades the two
   pages as the live elements they are; the outgoing one waits out its fade here, lifted out of the
   flow so the new page takes its place (router.js sets `top` to where it was on screen). */
main.leaving {
	position: fixed;
	left: 0;
	right: 0;
}

/* Without the Navigation API the router stays off and a link loads a whole page; that load
   cross-fades too, as a view transition (Safari 18.2+; between pages of one origin only).
   Chromium reads the new page's opt-in before it waits for this file, and aborts with an error if
   the file is still loading. Each page's first script comes right after the stylesheet link, and a
   script waits for the stylesheets before it, which holds the parser until this rule is known.
   Without scripting nothing holds it, so those visitors keep the plain load. */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
	@view-transition {
		navigation: auto;
	}
}

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

@font-face {
	font-family: 'Orbitron';
	src:
		url('fonts/orbitron-light-webfont.woff') format('woff'),
		url('fonts/orbitron-light-webfont.ttf') format('truetype');
	font-weight: 300;
	font-display: swap;
}

body {
	background: var(--bg);
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

main {
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

/* Logo + tagline scale as one unit with the window. The width knob: share of the
   window width, capped by height (logo is ~6.5:1) so short wide windows still fit. */
.brand {
	width: min(80vw, 140vh);
	container-type: inline-size;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 3cqi;
	/* The brand is a picture, not copy: no drag-select, no select-all. Prefix for older Safari. */
	-webkit-user-select: none;
	user-select: none;
}

.logo {
	width: 100%;
	height: auto;
	filter: var(--logo-filter);
}

.tagline {
	font-family: 'Orbitron', sans-serif;
	font-weight: 300;
	/* Proportional to the logo; the rem floor keeps it readable on phones and lets browser zoom enlarge it. */
	font-size: max(0.75rem, 2.4cqi);
	color: var(--fg);
	letter-spacing: 0.35em;
	margin-right: -0.35em; /* cancel trailing letter-spacing so the text centres under the logo */
	text-transform: uppercase;
}

/* Navbar: transparent and fixed over the page, so the brand stays centred in the window.
   Links on the left, theme toggle on the right. */
.navbar {
	position: fixed;
	inset: 0 0 auto;
	/* Above <main>: while a page fades (router.js) it is a stacking context, which would otherwise
	   paint over this bar (it comes later in the page) and take its clicks. */
	z-index: 1;
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 16px;
	padding: 16px;
}

.navbar nav {
	display: flex;
	gap: 16px;
}

/* Text button: the site's borderless button. The same look on <a href> (navigation, mailto:) and
   <button> (actions); pick the element by what it does. The underline is always drawn but
   transparent at rest, so its colour can fade in on hover and keyboard focus. */
.text-button {
	display: inline-flex;
	align-items: center;
	min-height: 40px;
	padding: 0 4px;
	background: none;
	border: 0;
	color: var(--fg);
	font-family: 'Orbitron', sans-serif;
	font-weight: 300;
	font-size: 0.875rem;
	letter-spacing: 0.2em;
	text-transform: uppercase;
	text-decoration: underline 1px transparent;
	text-underline-offset: 0.5em;
	opacity: 0.6;
	transition:
		opacity 0.2s,
		text-decoration-color 0.2s;
}

.text-button:hover,
.text-button:focus-visible {
	opacity: 1;
	text-decoration-color: currentColor;
}

/* The underline is the focus indicator. */
.text-button:focus-visible {
	outline: none;
}

/* An arrow before the label ("← Portal") is no glyph of Orbitron. As a box of its own in this flex
   container it would get a taller line than the label and be centred apart from it, and the
   underline would step down under the arrow: it shares the label's line instead. The arrow span
   only: an icon inside a button would lose its box, and with it its picture. */
.text-button > span[aria-hidden='true'] {
	display: contents;
}

/* Theme toggle */
.toggle {
	width: 40px;
	height: 40px;
	display: grid;
	place-items: center;
	background: none;
	border: 1px solid var(--fg);
	border-radius: 50%;
	color: var(--fg);
	opacity: 0.6;
	transition: opacity 0.2s;
}

.toggle:hover,
.toggle:focus-visible {
	opacity: 1;
}

.toggle:focus-visible {
	outline: 2px solid var(--fg);
	outline-offset: 3px;
}

.toggle svg {
	width: 18px;
	height: 18px;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.5;
	stroke-linecap: round;
	stroke-linejoin: round;
}

/* Show the theme you'd switch to. */
.toggle .moon {
	display: var(--show-if-light);
}

.toggle .sun {
	display: var(--show-if-dark);
}

/* Portal: the molecule menu (public/apex/portal/). Sizes are SVG user units, so it all scales with the
   viewBox; the width knob keeps it inside phones and short windows. */
.molecule {
	width: min(92vw, 80vh, 560px);
	-webkit-user-select: none;
	user-select: none;
}

.molecule svg {
	display: block;
	width: 100%;
	height: auto;
	/* A dragged atom's centre is kept inside the viewBox; its circle and label may reach past it. */
	overflow: visible;
}

/* portal.js blooms the atoms out of the hub. Module scripts run after the first paint can happen, so
   until it starts (data-state set) only the hub shows, else the finished layout flashes first. If the
   script never runs, the rest appears after 2s anyway. No JS or reduced motion: no animation, all
   shown at once. */
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
	.molecule svg:not([data-state]) :is(.bond, .atom:not(.hub)) {
		visibility: hidden;
		animation: reveal 0s 2s forwards;
	}
}

@keyframes reveal {
	to {
		visibility: visible;
	}
}

.bond {
	stroke: var(--fg);
	stroke-width: 1.5;
	opacity: 0.35;
}

/* portal.js lets a mouse or pen drag an atom; without this a pen would pan the page instead. Only the
   atoms opt out of panning (zoom stays), so touch scrolls from anywhere else; portal.js ignores touch
   drags, and a tap still follows the link. */
.atom {
	touch-action: pinch-zoom;
}

.atom circle {
	fill: var(--bg);
	stroke: var(--fg);
	stroke-width: 1.5;
	transition: stroke-width 0.2s;
}

.atom text {
	fill: var(--fg);
	font-family: 'Orbitron', sans-serif;
	font-weight: 300;
	text-anchor: middle;
	letter-spacing: 0.1em;
	text-transform: uppercase;
}

.atom .symbol {
	font-size: 16px;
	text-transform: none;
	dominant-baseline: central;
}

.atom.hub .symbol {
	font-size: 26px;
}

.atom .name {
	font-size: 14px;
}

.atom .note {
	font-size: 9px;
	opacity: 0.7;
}

/* Dim the ink only: the circle's fill stays opaque so the bonds still stop at its rim. */
.atom.soon circle {
	stroke-opacity: 0.45;
}

.atom.soon text {
	fill-opacity: 0.45;
}

/* A thicker rim marks hover; keyboard focus adds a dashed rim, as the outline doesn't follow the circle. */
a.atom {
	outline: none;
}

a.atom:hover circle,
a.atom:focus-visible circle {
	stroke-width: 3;
}

a.atom:focus-visible circle {
	stroke-dasharray: 5 3;
}

/* Blog, contact and privacy: plain reading column. The block padding keeps a long page clear of
   the fixed navbar. */
.prose {
	width: min(90vw, 40rem);
	padding-block: 5rem;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 1.5rem;
	color: var(--fg);
	/* A long address or word breaks instead of making a phone scroll sideways. */
	overflow-wrap: anywhere;
}

.prose h1 {
	font-family: 'Orbitron', sans-serif;
	font-weight: 300;
	font-size: 2rem;
	letter-spacing: 0.2em;
	text-transform: uppercase;
}

.prose p {
	line-height: 1.6;
}

.prose a:not(.text-button) {
	color: inherit;
}

/* Blog (blog/layout.html): the markup blogga renders, inside the .prose column. Class names are
   blogga's (src/render/index.ts, src/content/blocks.ts); never inline styles. */
.blogga {
	width: 100%;
	display: flex;
	flex-direction: column;
	gap: 1.5rem;
}

.blogga :is(h1, h2, h3) {
	font-family: 'Orbitron', sans-serif;
	font-weight: 300;
	letter-spacing: 0.1em;
	line-height: 1.3;
}

.blogga h1 {
	font-size: 2rem;
	letter-spacing: 0.2em;
	text-transform: uppercase;
}

.blogga h2 {
	font-size: 1.375rem;
}

.blogga h3 {
	font-size: 1.125rem;
}

.blogga a {
	color: inherit;
}

.blogga-description,
.blogga-excerpt {
	line-height: 1.6;
	opacity: 0.8;
}

.blogga-meta {
	font-size: 0.875rem;
	opacity: 0.7;
}

/* Blog navigation: the breadcrumb, a post's tags, the index's links and the pager speak the
   navbar's language (.text-button): Orbitron capitals, dimmed, an underline that fades in on hover
   and keyboard focus. Dimmed by colour, not opacity, so the separators dim with the links and a
   link can still brighten; 70% keeps text this small above 4.5:1 in both themes. */
.blogga-breadcrumb,
.blogga-kicker,
.blogga-tags,
.blogga-tag-list,
.blogga-links,
.blogga-pager {
	font-family: 'Orbitron', sans-serif;
	font-weight: 300;
	font-size: 0.75rem;
	letter-spacing: 0.2em;
	text-transform: uppercase;
	color: color-mix(in srgb, var(--fg) 70%, transparent);
}

.blogga :is(.blogga-breadcrumb, .blogga-kicker, .blogga-tags, .blogga-tag-list, .blogga-links, .blogga-pager) a {
	/* Padding on an inline box: a taller pointer target, and the line stays where it is. */
	padding-block: 0.75em;
	text-decoration: underline 1px transparent;
	text-underline-offset: 0.5em;
	transition:
		color 0.2s,
		text-decoration-color 0.2s;
}

.blogga :is(.blogga-breadcrumb, .blogga-kicker, .blogga-tags, .blogga-tag-list, .blogga-links, .blogga-pager) a:hover,
.blogga :is(.blogga-breadcrumb, .blogga-kicker, .blogga-tags, .blogga-tag-list, .blogga-links, .blogga-pager) a:focus-visible {
	color: var(--fg);
	text-decoration-color: currentColor;
}

/* The underline is the focus indicator, as on .text-button. */
.blogga :is(.blogga-breadcrumb, .blogga-kicker, .blogga-tags, .blogga-tag-list, .blogga-links, .blogga-pager) a:focus-visible {
	outline: none;
}

/* Post list: one card per post, separated by a hairline. */
.blogga-list {
	list-style: none;
	display: flex;
	flex-direction: column;
}

.blogga-card {
	padding-block: 1.5rem;
	border-top: 1px solid color-mix(in srgb, var(--fg) 20%, transparent);
}

.blogga-card article {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.blogga-card-title {
	font-size: 1.25rem;
}

.blogga-card-title a {
	text-decoration: none;
}

.blogga-card-title a:hover,
.blogga-card-title a:focus-visible {
	text-decoration: underline;
}

.blogga-card-img,
.blogga-hero img,
.blogga-body img {
	display: block;
	max-width: 100%;
	height: auto;
}

/* One line: the page's own name gives way first (it is the heading right below). */
.blogga-breadcrumb ol {
	list-style: none;
	display: flex;
	/* On the baseline: a character the display font lacks (the title's "·") makes its item taller. */
	align-items: baseline;
	gap: 0.5rem;
}

.blogga-breadcrumb li {
	flex: none;
}

.blogga-breadcrumb li + li::before {
	content: '/';
	margin-right: 0.5rem;
}

.blogga-breadcrumb [aria-current] {
	flex: 0 1 auto;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.blogga-post-header {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

/* The post body: Editor.js blocks (paragraph, header, list, quote, delimiter, image, gallery). */
.blogga-body {
	display: flex;
	flex-direction: column;
	gap: 1.25rem;
	line-height: 1.6;
}

.blogga-body :is(ul, ol) {
	padding-left: 1.5rem;
}

.blogga-body li + li,
.blogga-body li > :is(ul, ol) {
	margin-top: 0.25rem;
}

.blogga-body blockquote {
	padding-left: 1rem;
	border-left: 2px solid var(--fg);
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.blogga-body cite {
	font-size: 0.875rem;
	opacity: 0.7;
}

.blogga-body cite::before {
	content: '— ';
}

.blogga-body hr {
	width: 30%;
	margin-inline: auto;
	border: 0;
	border-top: 1px solid var(--fg);
	opacity: 0.4;
}

.blogga-body code {
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 0.9em;
}

.blogga figure {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.blogga figcaption {
	font-size: 0.875rem;
	opacity: 0.7;
}

/* Adjacent images: a grid that keeps two or more side by side on wide screens. */
.blogga-gallery {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
	gap: 1rem;
}

.blogga-tags,
.blogga-tag-list {
	list-style: none;
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem 1rem;
}

/* End of a post: its tags, then where else it was posted. Each copy is an icon link: the
   platform's name stays the link's text (its accessible name), moved out of sight, and the icon
   is a mask over the text colour, so it follows the theme. The icons (icons/, one file per
   platform blogga knows: tests/unit/blogga-icons.test.js) are Simple Icons' (simpleicons.org, CC0). */
.blogga-post-footer {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem 1.5rem;
}

.blogga-copies {
	list-style: none;
	display: flex;
	/* A 40px target around a 20px icon: the row is pulled out so the icons, not their targets,
	   line up with the column. */
	margin-inline: -10px;
}

.blogga-copy {
	position: relative;
	display: block;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	overflow: hidden;
	white-space: nowrap;
	/* Twice the box: at 100% the text's underline shows as a speck on the edge. */
	text-indent: 200%;
	opacity: 0.6;
	transition: opacity 0.2s;
}

.blogga-copy::before {
	content: '';
	position: absolute;
	inset: 0;
	background-color: currentColor;
	-webkit-mask: center / 20px no-repeat;
	mask: center / 20px no-repeat;
}

.blogga-copy:hover,
.blogga-copy:focus-visible {
	opacity: 1;
}

.blogga-copy:focus-visible {
	outline: 2px solid var(--fg);
	outline-offset: -4px;
}

.blogga-copy-telegram::before {
	-webkit-mask-image: url('icons/telegram.svg');
	mask-image: url('icons/telegram.svg');
}

.blogga-copy-mastodon::before {
	-webkit-mask-image: url('icons/mastodon.svg');
	mask-image: url('icons/mastodon.svg');
}

.blogga-copy-bluesky::before {
	-webkit-mask-image: url('icons/bluesky.svg');
	mask-image: url('icons/bluesky.svg');
}

.blogga-copy-instagram::before {
	-webkit-mask-image: url('icons/instagram.svg');
	mask-image: url('icons/instagram.svg');
}

.blogga-copy-threads::before {
	-webkit-mask-image: url('icons/threads.svg');
	mask-image: url('icons/threads.svg');
}

/* Forced colours repaint backgrounds, which would blank the mask: keep it, in a system colour and
   at full strength. */
@media (forced-colors: active) {
	.blogga-copy {
		opacity: 1;
	}

	.blogga-copy::before {
		forced-color-adjust: none;
		background-color: LinkText;
	}
}

.blogga-pager {
	display: flex;
	gap: 1rem;
	align-items: baseline;
}

.blog-footer {
	width: 100%;
}

/* Contact form (public/apex/contact/): one column, a visible label over each control. */
.contact-form {
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 0.5rem;
}

.contact-form label {
	margin-top: 1rem;
}

.contact-form input,
.contact-form textarea {
	width: 100%;
	padding: 0.5rem;
	border: 1px solid var(--fg);
	border-radius: 0;
	background: var(--bg);
	color: var(--fg);
	font: inherit;
}

.contact-form textarea {
	resize: vertical;
}

.contact-form :is(input, textarea, button):focus-visible {
	outline: 2px solid var(--fg);
	outline-offset: 2px;
}

/* Matches the focus rule's specificity and comes after it, so a focused invalid field stays marked. */
.contact-form :is(input, textarea)[aria-invalid='true'] {
	border-color: var(--error);
	outline: 2px solid var(--error);
	outline-offset: 2px;
}

.contact-form .hint {
	font-size: 0.875rem;
	opacity: 0.7;
}

.contact-form button {
	margin-top: 1rem;
	padding: 0.5rem 1.5rem;
	background: none;
	border: 1px solid var(--fg);
	color: var(--fg);
	font-family: 'Orbitron', sans-serif;
	font-weight: 300;
	font-size: 0.875rem;
	letter-spacing: 0.2em;
	text-transform: uppercase;
}

.contact-form button:disabled {
	opacity: 0.5;
}

.contact-status:focus {
	outline: none;
}

/* The honeypot: off-screen rather than display:none, which some bots skip. Out of the tab order and
   the accessibility tree by its markup. */
.contact-hp {
	position: absolute;
	left: -10000px;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

/* Cursor overlay (see main.js) */
.cursor {
	display: none;
	position: fixed;
	left: 0;
	top: 0;
	pointer-events: none;
	z-index: 2147483647;
	will-change: transform;
}

.cursor svg {
	display: block;
	width: 32px;
	height: 32px;
	animation: spin 1.2s linear infinite; /* one full turn per 1.2s; lower = faster */
}

/* Theme colours beat whatever an editor writes into the file (incl. inline styles).
   Filled with the page background so the outline stays legible over content. */
.cursor svg * {
	fill: var(--bg) !important;
	stroke: var(--fg) !important;
}

/* A transform, not the `rotate` property: on an SVG element Chrome runs only the former on the
   compositor, where it keeps turning while the page is busy (tests/e2e/cursor.spec.js). */
@keyframes spin {
	to {
		transform: rotate(-360deg);
	}
}

/* Particle overlay, created by main.js on the first button or link click; sits just under the cursor. */
.particles {
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	pointer-events: none;
	z-index: 2147483646;
}

html.custom-cursor .cursor {
	display: block;
}

html.custom-cursor,
html.custom-cursor *,
html.custom-cursor *::before,
html.custom-cursor *::after {
	cursor: none !important;
}
