/* ==========================================================================
   just-me.dev - one hand-written stylesheet
   1. Theme variables     5. Home page          9. Media and figures
   2. Base                6. Post lists         10. Callouts, tables, misc
   3. Header and footer   7. Article            11. Lightbox
   4. The mark            8. Code blocks        12. Motion
   ========================================================================== */

/* 1. Theme variables ----------------------------------------------------- */

:root {
	--bg: #fbfaf8;
	--bg-soft: #f2f3f3;
	--surface: #ffffff;
	--border: #e3e5e6;
	--text: #16191c;
	--text-soft: #434a50;
	--muted: #737b82;
	--accent: #f38020;
	--accent-text: #b4530a;
	--accent-soft: rgb(243 128 32 / 0.12);
	--code-bg: #f4f5f6;

	--tok-comment: #858c92;
	--tok-string: #3f7d2c;
	--tok-keyword: #0b5e73;
	--tok-function: #8f5500;
	--tok-number: #b4501c;
	--tok-type: #a33d6e;
	--tok-attr: #845600;
	--tok-tag: #0b5e73;
	--tok-var: #1f6fa3;
	--tok-meta: #7348ad;

	--font-serif:
		"Iowan Old Style", "Palatino Linotype", Palatino, Charter, Georgia, serif;
	--font-sans:
		system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--font-mono:
		ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono",
		monospace;
	--measure: 38rem;
	--radius: 14px;
	--ease-out: cubic-bezier(0.16, 1, 0.3, 1);
	--ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

	color-scheme: light;
}

:root[data-theme="dark"] {
	--bg: #0f1215;
	--bg-soft: #171b1f;
	--surface: #1b2025;
	--border: #262c32;
	--text: #e6e9ec;
	--text-soft: #a9b1b8;
	--muted: #7a838b;
	--accent: #f38020;
	--accent-text: #faad3f;
	--accent-soft: rgb(243 128 32 / 0.18);
	--code-bg: #14181c;

	--tok-comment: #737c84;
	--tok-string: #b5d39b;
	--tok-keyword: #6cc7de;
	--tok-function: #ffc66d;
	--tok-number: #f6a06b;
	--tok-type: #ef9ac3;
	--tok-attr: #f2c27c;
	--tok-tag: #6cc7de;
	--tok-var: #8cc8ec;
	--tok-meta: #c9a3f0;

	color-scheme: dark;
}

/* 2. Base ---------------------------------------------------------------- */

*,
*::before,
*::after {
	box-sizing: border-box;
}

html {
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
	scroll-behavior: smooth;
	scroll-padding-top: 2rem;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 400 1.1875rem/1.7 var(--font-serif);
	-webkit-font-smoothing: antialiased;
	transition:
		background-color 0.4s ease,
		color 0.4s ease;
}

h1,
h2,
h3 {
	font-weight: 600;
	letter-spacing: -0.015em;
	text-wrap: balance;
}

p {
	text-wrap: pretty;
}

::selection {
	background: var(--accent-soft);
}

a {
	color: inherit;
	text-decoration: none;
	background:
		linear-gradient(var(--accent-soft), var(--accent-soft)) 0 100% / 100% 0 no-repeat,
		linear-gradient(var(--accent), var(--accent)) 0 100% / 100% 1.5px no-repeat;
	transition:
		background-size 0.35s var(--ease-out),
		color 0.2s;
}

a:hover {
	background-size:
		100% 100%,
		100% 1.5px;
}

:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 3px;
	border-radius: 4px;
}

img,
video,
svg {
	display: block;
	max-width: 100%;
}

button {
	font: inherit;
	color: inherit;
}

.nowrap {
	white-space: nowrap;
}

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

.wrap {
	width: 100%;
	max-width: calc(var(--measure) + 3rem);
	margin-inline: auto;
	padding-inline: 1.5rem;
}

/* 3. Header and footer --------------------------------------------------- */

.site-header {
	display: flex;
	justify-content: flex-end;
	padding: 1.25rem 1.5rem 0;
}

.site-footer a {
	background: linear-gradient(var(--accent), var(--accent)) 0 100% / 0 1.5px no-repeat;
	transition:
		background-size 0.35s var(--ease-out),
		color 0.2s;
}

.site-footer a:hover {
	background-size: 100% 1.5px;
}

.theme-toggle {
	display: grid;
	place-items: center;
	width: 2rem;
	height: 2rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: none;
	color: var(--text-soft);
	cursor: pointer;
	transition:
		color 0.2s,
		background-color 0.2s;
}

.theme-toggle:hover {
	background: var(--bg-soft);
	color: var(--accent-text);
}

.theme-toggle svg {
	grid-area: 1 / 1;
	width: 1.1rem;
	height: 1.1rem;
	transition:
		transform 0.6s var(--ease-spring),
		opacity 0.3s;
}

.icon-moon,
:root[data-theme="dark"] .icon-sun {
	opacity: 0;
	transform: rotate(-90deg) scale(0.5);
}

:root[data-theme="dark"] .icon-moon {
	opacity: 1;
	transform: none;
}

/* The footer mirrors the header: the feed link sits in the lower right corner */
.site-footer {
	display: flex;
	justify-content: flex-end;
	margin-top: 7rem;
	padding: 2rem 1.5rem 1.5rem;
	color: var(--muted);
	font: 0.85rem var(--font-sans);
}

.site-footer a {
	color: var(--text-soft);
}

/*
 * The path to the current page. It sits in the lower left corner, below the
 * sphere, and mirrors the feed link on the right.
 */
.crumbs {
	position: fixed;
	bottom: 1.5rem;
	left: 1.5rem;
	max-width: calc(36vw - 3rem);
	margin-right: auto;
}

.crumbs ol {
	display: flex;
	margin: 0;
	padding: 0;
	list-style: none;
	white-space: nowrap;
}

.crumbs li + li::before {
	content: "/";
	margin-inline: 0.45rem;
	color: var(--muted);
}

.crumbs [aria-current] {
	overflow: hidden;
	text-overflow: ellipsis;
}

/* The home page has two views, each with its own path */
body:not(:has(#writing:target)) .crumbs[data-view="writing"],
body:has(#writing:target) .crumbs[data-view="intro"] {
	display: none;
}

/* 4. The mark ---------------------------------------------------------- */

:root {
	--sphere-from: #e2650c;
	--sphere-to: #f8a03a;
}

:root[data-theme="dark"] {
	--sphere-from: #f38020;
	--sphere-to: #fbbf5a;
}

.mark {
	display: block;
	width: 100%;
	aspect-ratio: 1;
}

/*
 * On every page a huge sphere stays fixed on the left. Its centre sits
 * off screen, so only its right arc shows, inside the left 30% of the window.
 * The sphere fills 0.34 of its canvas, so the canvas is the radius / 0.34.
 * It sits a little above the middle, so its wobble and glow never reach the
 * path in the lower left corner.
 */
.side-mark {
	--radius: 38vh;
	--center: calc(50vh - 2rem);
	--size: calc(var(--radius) / 0.34);
	position: fixed;
	top: calc(var(--center) - var(--size) / 2);
	left: calc(27vw - var(--radius) - var(--size) / 2);
	z-index: -1;
	width: var(--size);
	height: var(--size);
	pointer-events: none;
}

/* The content sits on the right, next to the sphere */
.side-mark ~ .wrap {
	width: auto;
	margin-left: 36vw;
}

/* Centre short pages in the window, between the theme switch and the footer */
.centered {
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	min-height: 100dvh;
}

.centered main {
	display: flex;
	flex: 1;
	flex-direction: column;
	justify-content: center;
}

.centered .hero,
.centered .page-header,
.centered .not-found {
	padding-top: 0;
}

/*
 * Post lists with the author filter start at a fixed height instead, so the
 * header stays put when the filter makes the list shorter or longer
 */
.centered main:has(> .page-header > .author-filter),
.centered main:has(> .view:target > .page-header > .author-filter) {
	justify-content: flex-start;
	padding-top: 14vh;
}

.centered .site-footer {
	margin-top: 2rem;
}

/* 5. Home page ----------------------------------------------------------- */

.hero {
	padding-block: 4.5rem 2rem;
}

.hero h1 {
	margin: 0 0 1.25rem;
	font-size: clamp(2.6rem, 7vw, 3.8rem);
	font-weight: 500;
	line-height: 1.05;
	letter-spacing: -0.03em;
}

.hero em {
	color: var(--accent);
}

.hero p {
	margin: 0;
	color: var(--text-soft);
	font-size: 1.25rem;
	line-height: 1.6;
}

/*
 * The landing page has two views: the intro and the writing.
 * The links switch them through the URL hash, so the sphere keeps running
 * and the back button works. Without a hash the intro shows.
 */
.view {
	display: none;
	scroll-margin-top: 100vh;
}

.view:target,
main:not(:has(.view:target)) > .view:first-child {
	display: block;
}

.view:target > * {
	animation: rise 0.9s var(--ease-out) both;
}

.view:target > :nth-child(2) {
	animation-delay: 0.08s;
}

.view:target > :nth-child(n + 3) {
	animation-delay: 0.16s;
}

.hero-links {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem 1.75rem;
	margin: 2.5rem 0 0;
	padding: 0;
	list-style: none;
	font: 0.95rem var(--font-sans);
}

.hero-links a {
	color: var(--text-soft);
	background: linear-gradient(var(--accent), var(--accent)) 0 100% / 0 1.5px no-repeat;
	transition:
		background-size 0.35s var(--ease-out),
		color 0.2s;
}

.hero-links a:hover {
	color: var(--text);
	background-size: 100% 1.5px;
}

.year-head {
	margin: 0;
	color: var(--muted);
	font: 500 0.9rem var(--font-sans);
	letter-spacing: 0;
}

.tags {
	display: inline-flex;
	flex-wrap: wrap;
	gap: 0 0.5rem;
	margin: 0;
	padding: 0;
	list-style: none;
}

.tag::before {
	content: "#";
	color: var(--accent);
}

/* 6. Post lists ---------------------------------------------------------- */

.post-list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.post-item a {
	display: grid;
	grid-template-columns: 1fr auto;
	align-items: baseline;
	gap: 0.15rem 1.5rem;
	margin-inline: -1rem;
	padding: 0.9rem 1rem;
	border-radius: var(--radius);
	background: none;
	transition:
		background-color 0.3s,
		transform 0.4s var(--ease-out);
}

.post-item a:hover {
	background: var(--bg-soft);
}

.post-title {
	font-size: 1.35rem;
	font-weight: 600;
	line-height: 1.3;
	letter-spacing: -0.015em;
	transition: color 0.2s;
}

.post-item a:hover .post-title {
	color: var(--accent-text);
}

.post-date {
	grid-row: 1;
	grid-column: 2;
	color: var(--muted);
	font: 0.85rem var(--font-sans);
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

.post-excerpt {
	grid-column: 1 / -1;
	color: var(--text-soft);
	font-size: 1.02rem;
	line-height: 1.55;
}

.year-head {
	margin: 3rem 0 0.5rem;
}

.post-author {
	color: var(--text-soft);
	font-weight: 500;
}

/*
 * The author filter: three radio buttons styled as a small segmented switch.
 * It works with CSS alone, so it needs no script and also works from disk.
 */
.author-filter {
	display: inline-flex;
	gap: 0.15rem;
	margin: 1.75rem 0 0;
	padding: 0.2rem;
	border: 1px solid var(--border);
	border-radius: 999px;
	font: 0.85rem var(--font-sans);
}

.author-filter label {
	padding: 0.2rem 0.8rem;
	border-radius: 999px;
	color: var(--muted);
	cursor: pointer;
	transition:
		color 0.2s,
		background-color 0.2s;
}

.author-filter label:hover {
	color: var(--text);
}

.author-filter :checked + label {
	background: var(--accent-soft);
	color: var(--accent-text);
}

.author-filter :focus-visible + label {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

/*
 * Hide the posts of the other author, and years left without any post. The
 * build lists the authors of each year in data-authors, as :has() cannot nest.
 */
:has(> .page-header #author-pi:checked) .post-item:not([data-author="pi"]),
:has(> .page-header #author-jm:checked) .post-item:not([data-author="jm"]),
:has(> .page-header #author-pi:checked) > :not([data-authors~="pi"])[data-authors],
:has(> .page-header #author-jm:checked) > :not([data-authors~="jm"])[data-authors] {
	display: none;
}

/* Say so when an author has no posts at all */
.filter-empty {
	display: none;
	margin-top: 3rem;
}

:has(> .page-header #author-pi:checked):not(:has([data-author="pi"])) > .filter-empty,
:has(> .page-header #author-jm:checked):not(:has([data-author="jm"])) > .filter-empty {
	display: block;
}

/* 7. Article ------------------------------------------------------------- */

.progress {
	position: fixed;
	inset: 0 0 auto;
	z-index: 10;
	height: 2px;
	background: var(--accent);
	transform: scaleX(0);
	transform-origin: 0 50%;
}

.post-header,
.page-header {
	padding-block: 3.5rem 2.5rem;
}

.post-header h1,
.page-header h1 {
	margin: 0 0 1rem;
	font-size: clamp(2.3rem, 6vw, 3.2rem);
	font-weight: 500;
	line-height: 1.1;
	letter-spacing: -0.03em;
}

.post-lead {
	margin: 0;
	color: var(--text-soft);
	font-size: 1.3rem;
	font-style: italic;
	line-height: 1.5;
}

.post-meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.25rem 0.5rem;
	margin-top: 1.5rem;
	color: var(--muted);
	font: 0.88rem var(--font-sans);
}

.post-meta > * + *::before {
	content: "·";
	margin-right: 0.5rem;
}

.post-meta .tags::before {
	margin-right: 0;
}

.prose > * + * {
	margin-top: 1.3em;
}

.prose p,
.prose ul,
.prose ol {
	margin-bottom: 0;
}

.prose h2,
.prose h3 {
	position: relative;
	line-height: 1.25;
}

.prose h2 {
	margin: 2.4em 0 0;
	font-size: 1.75rem;
}

.prose h3 {
	margin: 2em 0 0;
	font-size: 1.3rem;
}

.prose h2 + *,
.prose h3 + * {
	margin-top: 0.6em;
}

.anchor {
	margin-left: 0.35em;
	color: var(--muted);
	font-weight: 400;
	background: none;
	opacity: 0;
	transition: opacity 0.2s;
}

.prose h2:hover .anchor,
.prose h3:hover .anchor,
.anchor:focus-visible {
	opacity: 1;
}

.prose ul,
.prose ol {
	padding-left: 1.4em;
}

.prose li + li {
	margin-top: 0.4em;
}

.prose li::marker {
	color: var(--accent);
}

.prose blockquote {
	margin-inline: 0;
	padding-left: 1.5rem;
	border-left: 2px solid var(--accent);
	color: var(--text);
	font-size: 1.3rem;
	font-style: italic;
	line-height: 1.55;
}

.prose blockquote p {
	margin: 0;
}

.prose hr {
	margin-block: 3.5rem;
	border: 0;
	text-align: center;
}

.prose hr::before {
	content: "⁂";
	color: var(--accent);
	font-size: 1.3rem;
}

/* 8. Code blocks --------------------------------------------------------- */

code,
kbd,
pre {
	font-family: var(--font-mono);
}

:not(pre) > code {
	padding: 0.12em 0.4em;
	border-radius: 6px;
	background: var(--bg-soft);
	font-size: 0.8em;
}

pre {
	margin: 0;
	padding: 1.1rem 1.25rem;
	overflow-x: auto;
	font-size: 0.84rem;
	line-height: 1.7;
	tab-size: 4;
}

.code {
	overflow: hidden;
	border-radius: var(--radius);
	background: var(--code-bg);
	box-shadow: inset 0 0 0 1px var(--border);
}

.code-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.55rem 0.6rem 0 1.25rem;
	color: var(--muted);
	font: 0.78rem var(--font-sans);
}

.code-title {
	flex: 1;
}

.code-copy {
	padding: 0.2rem 0.65rem;
	border: 0;
	border-radius: 999px;
	background: none;
	color: var(--muted);
	font: inherit;
	cursor: pointer;
	transition:
		background-color 0.2s,
		color 0.2s;
}

.code-copy:hover {
	background: var(--bg-soft);
	color: var(--text);
}

.tok-comment {
	color: var(--tok-comment);
	font-style: italic;
}
.tok-string {
	color: var(--tok-string);
}
.tok-keyword {
	color: var(--tok-keyword);
}
.tok-function {
	color: var(--tok-function);
}
.tok-number {
	color: var(--tok-number);
}
.tok-type {
	color: var(--tok-type);
}
.tok-attr {
	color: var(--tok-attr);
}
.tok-tag {
	color: var(--tok-tag);
}
.tok-var {
	color: var(--tok-var);
}
.tok-meta {
	color: var(--tok-meta);
}

/* 9. Media and figures --------------------------------------------------- */

.prose figure {
	margin: 2.5rem 0;
}

.prose figure img,
.prose figure video {
	width: 100%;
	height: auto;
	border-radius: var(--radius);
	background: var(--bg-soft);
}

.prose figcaption {
	margin-top: 0.75rem;
	color: var(--muted);
	font: 0.85rem/1.5 var(--font-sans);
	text-align: center;
}

.is-zoomable {
	cursor: zoom-in;
	transition: transform 0.5s var(--ease-out);
}

.is-zoomable:hover {
	transform: scale(1.01);
}

.embed {
	position: relative;
	aspect-ratio: 16 / 9;
	overflow: hidden;
	border-radius: var(--radius);
}

.embed iframe {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	border: 0;
}

.stage {
	display: grid;
	place-items: center;
	min-height: 12rem;
	padding: 2rem;
	overflow: hidden;
	border-radius: var(--radius);
	background: var(--bg-soft);
}

/* 10. Callouts, tables, misc --------------------------------------------- */

.callout {
	position: relative;
	padding: 1.1rem 1.35rem;
	border-radius: var(--radius);
	background: var(--bg-soft);
	font-size: 1.05rem;
}

.callout::before {
	content: attr(data-title);
	display: block;
	margin-bottom: 0.2rem;
	color: var(--accent-text);
	font: 600 0.85rem var(--font-sans);
}

.callout p {
	margin: 0;
}

.callout > * + * {
	margin-top: 0.75em;
}

.callout.warn::before {
	color: #e0a100;
}

.table-wrap {
	overflow-x: auto;
}

.prose table {
	width: 100%;
	border-collapse: collapse;
	font: 0.92rem/1.5 var(--font-sans);
}

.prose th {
	padding: 0.5rem 0.75rem 0.5rem 0;
	border-bottom: 1px solid var(--border);
	color: var(--muted);
	font-weight: 500;
	text-align: left;
}

.prose td {
	padding: 0.6rem 0.75rem 0.6rem 0;
	border-bottom: 1px solid var(--border);
}

.prose tr:last-child td {
	border-bottom: 0;
}

kbd {
	padding: 0.1em 0.45em;
	border-radius: 6px;
	background: var(--bg-soft);
	box-shadow: inset 0 -1px 0 var(--border);
	font-size: 0.8em;
}

mark {
	padding: 0 0.15em;
	border-radius: 4px;
	background: var(--accent-soft);
	color: inherit;
}

.not-found {
	padding-block: 7rem 2rem;
}

.not-found h1 {
	margin: 0 0 1rem;
	font-size: clamp(2.4rem, 6vw, 3.4rem);
	font-weight: 500;
	letter-spacing: -0.03em;
}

.not-found p {
	margin: 0 0 0.5rem;
	color: var(--text-soft);
}

.draft-banner {
	margin: 0;
	padding: 0.45rem 1rem;
	background: var(--accent-soft);
	color: var(--accent-text);
	font: 500 0.85rem var(--font-sans);
	text-align: center;
}

/* 11. Lightbox ----------------------------------------------------------- */

.lightbox {
	max-width: 94vw;
	max-height: 94vh;
	padding: 0;
	border: 0;
	background: none;
	cursor: zoom-out;
}

.lightbox[open] {
	animation: rise 0.4s var(--ease-out);
}

.lightbox::backdrop {
	background: rgb(15 18 21 / 0.85);
	backdrop-filter: blur(6px);
}

.lightbox img {
	max-width: 94vw;
	max-height: 94vh;
	border-radius: var(--radius);
}

/* 12. Motion ------------------------------------------------------------- */

@keyframes rise {
	from {
		opacity: 0;
		transform: translateY(14px);
	}
}

.hero > *,
.post-header > *,
.page-header > *,
.not-found > *,
main > .year-head,
main > .post-list,
.prose {
	animation: rise 0.9s var(--ease-out) both;
}

.hero > :nth-child(2),
.post-header > :nth-child(2),
.page-header > :nth-child(2),
.not-found > :nth-child(2) {
	animation-delay: 0.08s;
}

.hero > :nth-child(3),
.post-header > :nth-child(3),
.page-header > :nth-child(3),
.not-found > :nth-child(3),
main > .year-head {
	animation-delay: 0.16s;
}

main > .post-list {
	animation-delay: 0.24s;
}

.prose {
	animation-delay: 0.3s;
}

.reveal {
	opacity: 0;
	transform: translateY(18px);
	transition:
		opacity 0.8s ease,
		transform 0.9s var(--ease-out);
}

.reveal.is-revealed {
	opacity: 1;
	transform: none;
}

/*
 * On narrow screens the sphere hangs from the top edge instead. Its centre
 * sits above the page, so only its lower arc shows, like a horizon above the
 * content. The band scrolls away with the page and clips the huge canvas, so
 * the sphere never sits behind the text. It leaves room for the wobble.
 */
@media (max-width: 48rem) {
	.side-mark {
		--radius: min(120vw, 36rem);
		--arc: 7rem;
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: calc(var(--arc) + var(--radius) * 0.12 + 1rem);
		overflow: hidden;
	}

	.side-mark .mark {
		position: absolute;
		top: calc(var(--arc) - var(--radius) - var(--size) / 2);
		left: calc(50% - var(--size) / 2);
		width: var(--size);
	}

	/* The theme switch stays above the arc */
	.site-header {
		position: relative;
		z-index: 1;
	}

	/* The content starts below the arc */
	.side-mark ~ .wrap {
		margin-top: 4rem;
		margin-left: auto;
	}

	.crumbs {
		position: static;
		max-width: 70%;
	}
}

@media (max-width: 36rem) {
	.hero {
		padding-top: 2.5rem;
	}

	.post-item a {
		grid-template-columns: 1fr;
	}

	.post-date {
		grid-row: auto;
		grid-column: 1;
	}
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation: none !important;
		transition: none !important;
		scroll-behavior: auto !important;
	}
}
