/* Blog styles. Tokens, type and motion are taken from pi.brain's web workspace
 * (packages/brain/web/src/styles): layered neutral surfaces, hairline borders,
 * a single blue accent, and light-dark() pairs resolved by color-scheme. */

:root {
	color-scheme: light dark;

	--bg: light-dark(#f5f5f7, #0e0e11);
	--bg-raised: light-dark(#ffffff, #1a1a1e);
	--bg-inset: light-dark(#f2f2f5, #0a0a0c);
	--surface-hover: light-dark(rgba(0, 0, 0, 0.045), rgba(255, 255, 255, 0.06));

	--fg: light-dark(#1d1d1f, #f2f2f4);
	--fg-muted: light-dark(#5f5f66, #b0b0b6);
	--fg-faint: light-dark(#767680, #8b8b92);

	--accent: light-dark(#0071e3, #0a84ff);
	--accent-hover: light-dark(#0077ed, #3a9aff);
	--accent-fg: #ffffff;
	--accent-muted: light-dark(rgba(0, 113, 227, 0.1), rgba(10, 132, 255, 0.16));

	--border: light-dark(rgba(0, 0, 0, 0.08), rgba(255, 255, 255, 0.1));
	--border-strong: light-dark(rgba(0, 0, 0, 0.15), rgba(255, 255, 255, 0.19));
	--ring: light-dark(rgba(0, 113, 227, 0.45), rgba(10, 132, 255, 0.6));
	--shadow-card: light-dark(0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.35));

	--font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
	--font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;

	--radius-sm: 6px;
	--radius: 8px;
	--radius-lg: 12px;

	--ease: cubic-bezier(0.22, 1, 0.36, 1);
	--dur-fast: 0.14s;
	--dur: 0.22s;

	--hl-keyword: light-dark(#a626a4, #c792ea);
	--hl-string: light-dark(#2f7d32, #8bd49c);
	--hl-number: light-dark(#b25000, #f2a65a);
	--hl-title: light-dark(#0b5fc4, #6cb2ff);
	--hl-attr: light-dark(#8a5a00, #e5c07b);
	--hl-builtin: light-dark(#0f7a85, #5fd0d8);
	--hl-comment: light-dark(#8a8a92, #7a7a84);
	--hl-meta: light-dark(#7a52b8, #b79af0);

	--measure: 680px;
}

[data-theme="light"] { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }

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

html {
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
	background: var(--bg);
	scroll-padding-top: 72px;
}

body {
	display: flex;
	flex-direction: column;
	min-height: 100dvh;
	font: 400 16px / 1.6 var(--font-ui);
	background: var(--bg);
	color: var(--fg);
	-webkit-font-smoothing: antialiased;
	text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

button { appearance: none; margin: 0; padding: 0; background: none; border: 0; font: inherit; color: inherit; cursor: pointer; }

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

:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: var(--radius-sm); }
::selection { background: var(--accent); color: var(--accent-fg); }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

.wrap {
	width: 100%;
	max-width: calc(var(--measure) + 48px);
	margin-inline: auto;
	padding-inline: 24px;
}

/* ---------- header ---------- */

.site-head {
	position: sticky;
	top: 0;
	z-index: 10;
	background: color-mix(in srgb, var(--bg) 82%, transparent);
	-webkit-backdrop-filter: saturate(1.6) blur(14px);
	backdrop-filter: saturate(1.6) blur(14px);
	border-bottom: 1px solid transparent;
	transition: border-color var(--dur) var(--ease);
}
.site-head.is-stuck { border-bottom-color: var(--border); }

.site-head .wrap {
	display: flex;
	align-items: center;
	gap: 20px;
	height: 56px;
}

.brand {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	margin-right: auto;
	color: var(--fg);
	font-weight: 600;
	font-size: 15px;
	letter-spacing: -0.01em;
}
.brand:hover { color: var(--fg); }

.mark {
	display: grid;
	place-items: center;
	width: 24px;
	height: 24px;
	border-radius: 7px;
	background: var(--accent);
	color: var(--accent-fg);
	font-size: 14px;
	font-weight: 600;
	line-height: 1;
	padding-bottom: 1px;
}

.nav { display: flex; gap: 2px; }
.nav a {
	padding: 5px 10px;
	border-radius: var(--radius);
	color: var(--fg-muted);
	font-size: 14px;
	transition: background var(--dur-fast) ease, color var(--dur-fast) ease;
}
.nav a:hover { background: var(--surface-hover); color: var(--fg); }
.nav a[aria-current="page"] { color: var(--fg); background: var(--surface-hover); }

.theme-btn {
	display: grid;
	place-items: center;
	width: 30px;
	height: 30px;
	border-radius: var(--radius);
	color: var(--fg-muted);
	transition: background var(--dur-fast) ease, color var(--dur-fast) ease;
}
.theme-btn:hover { background: var(--surface-hover); color: var(--fg); }
.theme-btn svg { width: 16px; height: 16px; }
.theme-btn .i-sun { display: none; }
/* The icon shows the theme you would switch to. */
html[data-resolved="dark"] .theme-btn .i-sun { display: block; }
html[data-resolved="dark"] .theme-btn .i-moon { display: none; }

/* ---------- main ---------- */

main { flex: 1; padding-block: 56px 80px; }

.intro { margin-bottom: 48px; }
.intro h1 {
	font-size: 28px;
	line-height: 1.2;
	font-weight: 600;
	letter-spacing: -0.022em;
	margin-bottom: 12px;
}
.intro p { color: var(--fg-muted); font-size: 17px; line-height: 1.55; max-width: 34em; }

.year {
	display: flex;
	align-items: baseline;
	gap: 12px;
	margin: 36px 0 4px;
	color: var(--fg-faint);
	font-size: 12.5px;
	font-weight: 500;
	letter-spacing: 0.02em;
	font-variant-numeric: tabular-nums;
}
.year::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.posts { list-style: none; padding: 0; }
.posts li { margin-inline: -12px; }

.post-row {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 2px 24px;
	padding: 14px 12px;
	border-radius: var(--radius-lg);
	color: var(--fg);
	transition: background var(--dur-fast) ease;
}
.post-row:hover { background: var(--surface-hover); color: var(--fg); }
.post-row h2 { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.4; }
.post-row time {
	grid-row: 1;
	grid-column: 2;
	color: var(--fg-faint);
	font-size: 13px;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
	padding-top: 1px;
}
.post-row p { grid-column: 1; color: var(--fg-muted); font-size: 14.5px; line-height: 1.5; }

/* ---------- article ---------- */

.article-head { margin-bottom: 40px; }
.article-head h1 {
	font-size: clamp(28px, 5vw, 36px);
	line-height: 1.15;
	font-weight: 650;
	letter-spacing: -0.028em;
	text-wrap: balance;
	margin-bottom: 14px;
}
.meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px 10px;
	color: var(--fg-faint);
	font-size: 13px;
	font-variant-numeric: tabular-nums;
}
.meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--border-strong); }
.tag {
	padding: 1px 8px;
	border-radius: 999px;
	background: var(--accent-muted);
	color: var(--accent);
	font-size: 12px;
	font-weight: 500;
}

.prose { font-size: 17px; line-height: 1.72; }

/* Chinese: a CJK-first stack, a little more leading, and no first-line text-wrap tricks. */
.post-zh, :lang(zh) { --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif; }
article:lang(zh) .prose { font-size: 17.5px; line-height: 1.85; text-align: justify; text-justify: inter-ideograph; }
article:lang(zh) .prose p { text-wrap: wrap; }
article:lang(zh) h1 { font-family: var(--font-ui); line-height: 1.35; letter-spacing: 0; }
article:lang(zh) .prose h2 { letter-spacing: 0; line-height: 1.45; }
article:lang(zh) .prose h2 .anchor { letter-spacing: 0; }

.source { margin-top: 14px; color: var(--fg-faint); font-size: 13px; }
.post-row:lang(zh) h2 { letter-spacing: 0; line-height: 1.45; }
.prose > * + * { margin-top: 1.3em; }
.prose p { text-wrap: pretty; }
.prose h2, .prose h3 { line-height: 1.3; letter-spacing: -0.018em; font-weight: 600; position: relative; }
.prose h2 { font-size: 22px; margin-top: 2.2em; }
.prose h3 { font-size: 18px; margin-top: 1.8em; }
.prose h2 + *, .prose h3 + * { margin-top: 0.7em; }
.prose h2 .anchor, .prose h3 .anchor {
	position: absolute;
	left: -22px;
	color: var(--fg-faint);
	font-weight: 400;
	opacity: 0;
	transition: opacity var(--dur-fast) ease;
}
.prose h2:hover .anchor, .prose h3:hover .anchor, .prose .anchor:focus-visible { opacity: 1; }
.prose a {
	text-decoration: underline;
	text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
	text-underline-offset: 3px;
	text-decoration-thickness: 1px;
}
.prose a:hover { text-decoration-color: currentColor; }
.prose strong { font-weight: 600; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: 0.35em; }
.prose li::marker { color: var(--fg-faint); }
.prose hr { border: 0; height: 1px; background: var(--border); margin-block: 2.4em; }

.prose blockquote {
	padding-left: 18px;
	border-left: 2px solid var(--border-strong);
	color: var(--fg-muted);
}

.prose :not(pre) > code {
	padding: 0.12em 0.4em;
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--bg-raised);
	font-size: 0.86em;
}

.prose pre {
	overflow-x: auto;
	padding: 16px 18px;
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	background: var(--bg-inset);
	font-size: 13.5px;
	line-height: 1.6;
	tab-size: 2;
}
.prose pre code { font-size: inherit; }
.prose figcaption { margin-top: 8px; color: var(--fg-faint); font-size: 13px; }

.prose table { width: 100%; border-collapse: collapse; font-size: 15px; }
.prose th, .prose td { padding: 8px 12px 8px 0; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.prose th { color: var(--fg-faint); font-size: 12.5px; font-weight: 500; }

.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-type { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition { color: var(--hl-string); }
.hljs-number, .hljs-symbol, .hljs-bullet { color: var(--hl-number); }
.hljs-title, .hljs-section, .hljs-selector-id, .hljs-selector-class { color: var(--hl-title); }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable { color: var(--hl-attr); }
.hljs-built_in, .hljs-name { color: var(--hl-builtin); }
.hljs-comment, .hljs-quote, .hljs-deletion { color: var(--hl-comment); font-style: italic; }
.hljs-meta, .hljs-doctag { color: var(--hl-meta); }

.article-foot {
	display: flex;
	justify-content: space-between;
	gap: 16px;
	margin-top: 64px;
	padding-top: 20px;
	border-top: 1px solid var(--border);
	font-size: 14px;
}
.article-foot a { color: var(--fg-muted); }
.article-foot a:hover { color: var(--accent); }
.article-foot .next { margin-left: auto; text-align: right; }
.article-foot small { display: block; color: var(--fg-faint); font-size: 12px; margin-bottom: 2px; }

/* ---------- 404 ---------- */

.lost { padding-top: 12vh; }
.lost .code { color: var(--fg-faint); font: 500 13px var(--font-mono); margin-bottom: 12px; }
.lost h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.022em; margin-bottom: 10px; }
.lost p { color: var(--fg-muted); }

/* ---------- footer ---------- */

.site-foot { border-top: 1px solid var(--border); }
.site-foot .wrap {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: 8px 20px;
	padding-block: 22px;
	color: var(--fg-faint);
	font-size: 13px;
}
.site-foot a { color: var(--fg-muted); }
.site-foot a:hover { color: var(--accent); }
.site-foot nav { display: flex; gap: 16px; }

/* ---------- motion ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
main > * { animation: rise 0.4s var(--ease) both; }

:root[data-theme-switch="true"]::view-transition-old(root),
:root[data-theme-switch="true"]::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
:root[data-theme-switch="true"]::view-transition-new(root) { animation: theme-reveal 0.52s var(--ease); }
@keyframes theme-reveal {
	from { clip-path: circle(0 at var(--theme-x, 50%) var(--theme-y, 50%)); }
	to { clip-path: circle(150vmax at var(--theme-x, 50%) var(--theme-y, 50%)); }
}

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

@media (max-width: 640px) {
	main { padding-block: 36px 56px; }
	.prose { font-size: 16.5px; }
	.prose h2 .anchor, .prose h3 .anchor { display: none; }
	.post-row { grid-template-columns: 1fr; }
	.post-row time { grid-row: 1; grid-column: 1; padding: 0; font-size: 12.5px; }
	.post-row h2 { grid-row: 2; }
	.post-row p { grid-row: 3; }
}

@media print {
	.site-head, .site-foot, .theme-btn { display: none; }
	body { background: #fff; color: #000; }
}
