/* Simple clean starter stylesheet — make it yours. */

/* ET Book (MIT License, see LICENSE in this folder) — the typeface of the original site. */
@font-face {
	font-family: et-book;
	src: url("/font/et-book/et-book-roman-line-figures/et-book-roman-line-figures.woff") format("woff");
	font-weight: normal;
	font-style: normal;
	font-display: swap;
}

@font-face {
	font-family: et-book;
	src: url("/font/et-book/et-book-display-italic-old-style-figures/et-book-display-italic-old-style-figures.woff") format("woff");
	font-weight: normal;
	font-style: italic;
	font-display: swap;
}

@font-face {
	font-family: et-book;
	src: url("/font/et-book/et-book-bold-line-figures/et-book-bold-line-figures.woff") format("woff");
	font-weight: bold;
	font-style: normal;
	font-display: swap;
}

:root {
    --text:   #383633;
    --muted:  #6b7280;
    --heading: #292724;
	--accent: #0066CC;
	--accent-hover: #0066CC;
    --border: #e2e2e2;
    --code-bg: #f5f5f5;
    --bg: #FAF9F7;
    --inline-code-bg: #eef3f7;
    --inline-code-text: #2b5377;
    --inline-code-border: #d8e3ec;
    --syntax-comment: #57524a;
    --syntax-keyword: #b32200;
    --syntax-string: #00663a;
    --syntax-number: #8c4200;
    --syntax-function: #0b4f8a;
    --syntax-type: #5c118c;
    --syntax-operator: #4f3b2a;
    --syntax-punctuation: #5c574f;
    color-scheme: light;
}
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; font-size: 18px; }

body {
	margin: 0 auto;
	max-width: 44rem;
	padding: 0 1.25rem;
	font: 1.06rem/1.65 et-book, Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
	color: var(--text);
	background: var(--bg);
}

/* Pages WITHOUT margin notes stay as the centered 44rem column above.
   Pages WITH sidenotes keep the centered 72rem page area, but the whole
   content (nav, text, notes, footer) shifts toward its right edge: the
   spare room collects on the left, leaving a small gap before the right. */
@media (min-width: 1152px) {
	body:has(.sidenote) {
		max-width: 72rem;
		padding: 0 1.25rem 0 6rem; /* extra left padding pushes content right */
	}
}

/* reading column: content stays 44rem wide, leaving a margin on the right
   for sidenotes (like the original site's layout) */
main,
body > p,
body > h1, body > h2, body > h3,
body > ul.articles {
	max-width: 44rem;
}

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

header nav {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: .5rem;
	max-width: 44rem; /* align with the reading column, even on widened pages */
	padding: 1.6rem 0 1.2rem;
	border-bottom: 1px solid var(--border);
}

#logo {
	margin: 0;
	font-size: 1.35rem;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

.menu {
	margin: 0;
	padding: 0;
	list-style: none;
	display: flex;
	flex-wrap: wrap;
	gap: .6rem 1.2rem;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: .95rem;
}

.menu a { color: var(--muted); text-decoration: none; }
.menu a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: .16em; }

.theme-toggle {
	background: none;
	border: 0;
	padding: 0;
	margin: 0;
	font: inherit;
	font-size: 1.2rem;
	line-height: 1;
	color: var(--muted);
	cursor: pointer;
	min-width: 1.2rem;
}

.theme-toggle:hover { color: var(--accent-hover); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.font-toggle {
	background: none;
	border: 0;
	padding: 0;
	margin: 0;
	font: inherit;
	font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
	font-size: .95rem;
	line-height: 1;
	color: var(--muted);
	cursor: pointer;
	min-width: 1.2rem;
}

.font-toggle:hover { color: var(--accent-hover); }
.font-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

:root[data-code-font="cascadia"] .font-toggle {
	font-family: "Cascadia Mono", Consolas, "Liberation Mono", Menlo, Courier, monospace;
}

/* ---- articles ---- */

.article-meta > header { padding-bottom: .4rem; }

.article-meta h1 { font-size: 2rem; line-height: 1.25; margin: 1.6rem 0 .4rem; }
.article-meta h1 a { color: inherit; text-decoration: none; }
.article-meta h1 a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: .16em; }

.article-meta > header > h2 {
	font-size: 1.15rem;
	font-weight: normal;
	color: var(--muted);
	margin: 0 0 .8rem;
}

.info { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
.info p { margin: .2rem 0; font-size: .9rem; color: var(--muted); }
.info .date { color: var(--muted); }
.info .series { color: var(--accent); }
.info a { color: var(--accent); text-decoration: none; }
.info a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: .16em; }

/* ---- headings ---- */

h1, h2, h3, h4 { line-height: 1.3; color: var(--heading); }

h1 { font-size: 1.7rem;  margin: 1.2rem 0 .3rem;  }
h2 { font-size: 1.4rem;  margin: 1.1rem 0 .25rem; }
h3 { font-size: 1.15rem; margin: 1rem 0 .2rem;   }

/* keep content snug under its heading */
h1 + p,  h2 + p,  h3 + p,
h1 + ul, h2 + ul, h3 + ul,
h1 + ol, h2 + ol, h3 + ol { margin-top: .15rem; }

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

ul.articles {
	margin: .1rem 0 1.25rem;
	padding: 0;
	list-style: none;
}

ul.articles li { padding: .45rem 0; }

ul.articles a {
	font-size: 1.2rem;
	color: var(--accent);
	text-decoration: none;
}
ul.articles a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: .16em; }

ul.articles .description {
	margin: .25rem 0 0;
	color: var(--muted);
	font-size: .95rem;
}

ul.articles .date {
	margin: .15rem 0 0;
	color: var(--muted);
	font-size: .82rem;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---- content bits ---- */

:where(.article-meta p, .article-meta li, .article-meta blockquote) a {
	color: var(--accent);
	text-decoration: none;
	text-underline-offset: .16em;
}

:where(.article-meta p, .article-meta li, .article-meta blockquote) a:hover {
	color: var(--accent-hover);
	text-decoration: underline;
}

.article-meta h2 a,
.article-meta h3 a,
.article-meta h4 a { color: inherit; text-decoration: none; }

.article-meta h2 a:hover,
.article-meta h3 a:hover,
.article-meta h4 a:hover {
	color: var(--accent-hover);
	text-decoration: underline;
	text-underline-offset: .16em;
}

blockquote {
	margin: 1.2rem 0;
	padding: .1rem 1rem;
	border-left: 4px solid var(--border);
	color: var(--muted);
}

hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

code, pre { font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; }

:root[data-code-font="cascadia"] body {
	font-family: "Cascadia Mono", Consolas, "Liberation Mono", Menlo, Courier, monospace;
	font-size: 0.85em;
}

:root[data-code-font="cascadia"] code,
:root[data-code-font="cascadia"] pre {
	font-family: "Cascadia Mono", Consolas, "Liberation Mono", Menlo, Courier, monospace;
}

/* code keeps its normal size even while the surrounding body text shrinks */
:root[data-code-font="cascadia"] pre { font-size: .90rem; }
:root[data-code-font="cascadia"] code { font-size: .80rem; }
:root[data-code-font="cascadia"] pre code { font-size: .95em; }

/* math keeps its normal size even while the surrounding body text shrinks
   (body goes 1.06rem -> 0.85em, so scale .katex by 1.06/0.85 on top of its 1.21em base) */
:root[data-code-font="cascadia"] .katex { font-size: 1.51em; }

code {
	background: var(--inline-code-bg);
	color: var(--inline-code-text);
	border: 1px solid var(--inline-code-border);
	padding: .1em .32em;
	border-radius: 3px;
	font-size: .80rem;
}

pre {
	position: relative;
	background: var(--code-bg);
	border: 1px solid var(--border);
	border-radius: 4px;
	padding: .9rem 1.1rem;
	overflow-x: auto;
	font-size: .90rem;
	line-height: 1.5;
}

/* language tag in the top-left corner of fenced code blocks */
pre[data-lang] { padding-top: 2.4rem; }

pre[data-lang]::before {
	content: attr(data-lang);
	position: absolute;
	top: .55rem;
	left: .7rem;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: .68rem;
	font-weight: 600;
	line-height: 1.2;
	letter-spacing: .08em;
	text-transform: capitalize;
	color: var(--muted);
	border: 1px solid var(--border);
	border-radius: 3px;
	padding: .14rem .45rem;
}

pre code { background: none; border: 0; color: inherit; padding: 0; font-size: .95em; }

/* ---- syntax highlighting (Prism) ---- */

.token.comment { color: var(--syntax-comment); font-style: italic; }

.token.keyword,
.token.directive,
.token.macro { color: var(--syntax-keyword); font-weight: 600; }

.token.string,
.token.char { color: var(--syntax-string); }

.token.number,
.token.boolean { color: var(--syntax-number); }

.token.function { color: var(--syntax-function); font-weight: 600; }

.token.type,
.token.class-name { color: var(--syntax-type); font-weight: 600; }

.token.operator { color: var(--syntax-operator); }

.token.punctuation { color: var(--syntax-punctuation); }

img { max-width: 100%; height: auto; }

article.article-meta img {
	display: block;
	max-width: 100%;
	margin: 1.4rem auto;
	border: 1px solid var(--border);
	border-radius: 4px;
}

article.article-meta img[src*="emission-order"] { max-width: min(24rem, 100%); }
article.article-meta img[src*="allocator-benchmark"] { max-width: min(30rem, 100%); }

article video {
	display: block;
	max-width: 100%;
	margin: 1.4rem auto;
	border: 1px solid var(--border);
	border-radius: 4px;
}

/* ---- sidenotes / margin notes ---- */

input.margin-toggle { display: none; }
label.margin-toggle:not(.sidenote-number) { display: none; }

/* the superscript reference number in the text */
label.sidenote-number { display: inline; }

label.sidenote-number sup {
	font-size: .9em;
	font-weight: 700;
	color: var(--accent);
	line-height: 0;
	padding: 0 .12em;
	cursor: pointer;
}

/* float the note text into the right-hand margin, Tufte style.
   Snug against the text, with a slightly smaller gap before the
   page area's right edge. */
.sidenote {
	float: right;
	clear: right;
	width: 40%;                      /* 17.6rem of the 44rem column */
	margin: .2rem -44% .6rem 1rem;   /* 19.4rem out: ~1.8rem gap from text, ~1.4rem to page edge */
	color: var(--muted);
	font-size: .95em;
	line-height: 1.5;
	text-align: left;
	overflow-wrap: anywhere;
}

/* the matching number at the top-left of the note */
.sidenote-mark {
	font-size: .9em;
	font-weight: 700;
	color: var(--accent);
	vertical-align: super;
	margin-right: .15em;
}

/* not enough room for the side margin: turn notes into tap-to-open footnotes */
@media (max-width: 1151px) {
	.sidenote { display: none; }

	input.margin-toggle:checked + .sidenote {
		display: block;
		float: none;
		width: auto;
		margin: .5rem 0 1rem;
		padding: .35rem .8rem;
		border-left: 3px solid var(--border);
	}
}

/* ---- tables ---- */

table { border-collapse: collapse; margin: 1.2rem 0; }

th, td {
	border: 1px solid var(--border);
	padding: .35rem .75rem;
	text-align: left;
}

th { background: var(--code-bg); }

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

footer {
	max-width: 44rem;
	margin: 3.5rem 0 1.5rem;
	padding-top: 1rem;
	border-top: 1px solid var(--border);
	color: var(--muted);
	font-size: .9rem;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---- dark mode ---- */

:root[data-theme="dark"] {
	color-scheme: dark;
	--text:   #D0CABE;
	--muted:  #99a3ad;
	--heading: #DEDAD5;
	--accent: #79abdc;
	--accent-hover: #99CCFF;
	--border: #2e2e2e;
	--code-bg: #1f1f1f;
	--bg:     #191919;
	--inline-code-bg: #242424;
	--inline-code-text: #aacdec;
	--inline-code-border: #333333;
	--syntax-comment: #8f887d;
	--syntax-keyword: #ffa76c;
	--syntax-string: #9ed4b0;
	--syntax-number: #ecc27d;
	--syntax-function: #8cc3ee;
	--syntax-type: #cbb0ef;
	--syntax-operator: #c9b7a4;
	--syntax-punctuation: #9b968f;
}

@font-face {
    font-family: "Cascadia Mono";
    src: url("/font/CascadiaMono.woff2") format("woff2");
    font-weight: 200 700;
    font-style: normal;
    font-display: swap;
}

.contact-table {
    border-collapse: collapse;
    margin: .5rem 0 1.5rem;
}

.contact-table th,
.contact-table td {
    border: 0;
    background: none;
    padding: .25rem 1.25rem .25rem 0;
}

.contact-table th {
    color: var(--muted);
    font-weight: normal;
}

.contact-table a {
    color: var(--accent);
    text-decoration: none;
    text-underline-offset: .16em;
}

.contact-table a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.tinybin-note a {
    color: var(--accent);
    text-decoration: none;
    text-underline-offset: .16em;
}

.tinybin-note a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}