/* Nex books: the complete stylesheet for every book page.
 *
 *   1. base layout and components, merged from the books' former stylesheets
 *   2. per-book differences
 *   3. site look (tokens, header, headings, code windows, notes, navigation)
 *
 * Body text stays in a serif for long reading; chrome, headings and code
 * follow the main Nex site. book.js adds the theme toggle and home crumb.
 */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

/* ============ 1. base (folded from the old per-book stylesheets) ============ */
:root {
  --font-body: 'EB Garamond', Georgia, serif;
  --font-ui:   'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --text-xs: 0.72rem; --text-sm: 0.85rem; --text-base: 1.175rem; --text-md: 1.32rem;
  --text-lg: 1.65rem; --text-xl: 2rem; --text-2xl: 2.8rem; --lh-body: 1.76;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body { background: var(--paper); color: var(--ink); font-family: var(--font-body); font-size: var(--text-base); line-height: var(--lh-body); font-feature-settings: "kern" 1, "liga" 1, "onum" 1; }
.site-header { border-bottom: 1px solid var(--rule); padding: 1.1rem 2rem; position: sticky; top: 0; background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(8px); z-index: 10; }
.site-header-inner { max-width: 52rem; margin: 0 auto; display: flex; align-items: baseline; gap: 2rem; flex-wrap: wrap; }
a.book-title { font-family: var(--font-ui); font-size: var(--text-sm); font-weight: 500; letter-spacing: 0.01em; color: var(--ink-mid); text-decoration: none; transition: color 0.15s; }
a.book-title:hover { color: var(--ink); }
.book-nav { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-left: auto; }
.book-nav a { font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 400; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); text-decoration: none; transition: color 0.15s; }
.book-nav a:hover { color: var(--ink); }
.book-nav a.current { color: var(--ink); }
.book-nav a:hover, .book-nav a.active { color: var(--accent); }
.page { max-width: 52rem; margin: 0 auto; padding: 5rem 2rem 8rem; }
.toc-header { margin-bottom: 4rem; padding-bottom: 3rem; border-bottom: 1px solid var(--rule); }
.toc-eyebrow { display: block; font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 1rem; }
.toc-title { font-family: var(--font-body); font-size: var(--text-2xl); font-weight: 400; line-height: 1.08; letter-spacing: -0.01em; color: var(--ink); }
.toc-subtitle { margin-top: 1rem; font-size: var(--text-md); font-style: italic; color: var(--ink-mid); line-height: 1.45; max-width: 48ch; }
.index-columns { column-count: 2; column-gap: 3.5rem; }
.letter-group { break-inside: avoid; margin-bottom: 1.75rem; }
.letter-heading { font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); border-bottom: 1.5px solid var(--ink); padding-bottom: 0.35rem; margin-bottom: 0.6rem; }
.term { break-inside: avoid; padding: 0.28rem 0; }
.term-name { font-style: italic; color: var(--ink); }
.term-see { color: var(--ink-faint); font-style: italic; }
.locators { margin-left: 0; }
.locators a { font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: 0.02em; color: var(--ink-mid); text-decoration: none; border-bottom: 1px solid var(--rule); }
.locators a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.locators .sep { color: var(--ink-faint); font-size: var(--text-xs); }
.sub-term { margin-left: 1.1rem; padding: 0.2rem 0; font-size: 0.95rem; }
.sub-term .term-name { color: var(--ink-mid); }
a.toc-front { display: flex; justify-content: space-between; align-items: baseline; padding: 0.75rem 0; border-bottom: 1px solid var(--rule); gap: 1.5rem; text-decoration: none; color: inherit; }
a.toc-front:first-of-type { border-top: 1px solid var(--rule); }
a.toc-front:hover .front-title { color: var(--ink); }
.front-title { font-family: var(--font-body); font-size: var(--text-md); font-style: italic; color: var(--ink-mid); flex: 1; transition: color 0.15s; }
.front-label { font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); flex-shrink: 0; }
.section-block { margin-top: 3.5rem; }
.section-header { display: flex; align-items: baseline; gap: 1.25rem; margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1.5px solid var(--ink); }
.section-label { font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); flex-shrink: 0; }
.section-title-text { font-family: var(--font-body); font-size: var(--text-md); font-weight: 400; font-style: italic; color: var(--ink); }
a.chapter-entry { display: flex; align-items: baseline; padding: 0.75rem 0; border-bottom: 1px solid var(--rule); gap: 0; text-decoration: none; color: inherit; }
a.chapter-entry:hover .ch-title { color: var(--accent); }
.ch-num { font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 400; letter-spacing: 0.04em; color: var(--ink-faint); width: 5.5rem; flex-shrink: 0; }
.ch-body { flex: 1; min-width: 0; }
.ch-title { font-family: var(--font-body); font-size: var(--text-md); font-style: italic; color: var(--ink); line-height: 1.3; display: block; transition: color 0.15s; }
a.interlude-entry { display: flex; align-items: baseline; padding: 0.75rem 0; border-bottom: 1px solid var(--rule); gap: 0; text-decoration: none; color: inherit; background: linear-gradient(to right, rgba(30,125,122,0.04), transparent 60%); }
a.interlude-entry:hover .ch-title { color: var(--accent); }
.interlude-entry .ch-num { color: var(--accent); opacity: 0.65; }
.backmatter-block { margin-top: 3.5rem; }
.backmatter-header { display: flex; align-items: baseline; gap: 1.25rem; margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--rule); }
.backmatter-label { font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); }
.appendix-block { margin-top: 3.5rem; }
.appendix-header { display: flex; align-items: baseline; gap: 1.25rem; margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--rule); }
.appendix-label { font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); }
.opener { margin-bottom: 4rem; padding-bottom: 3rem; border-bottom: 1px solid var(--rule); }
.opener-label { display: block; font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); margin-bottom: 1.25rem; }
.opener-title { font-family: var(--font-body); font-size: var(--text-2xl); font-weight: 400; line-height: 1.08; letter-spacing: -0.01em; color: var(--ink); max-width: 26ch; }
.opener-lede { margin-top: 1.5rem; max-width: 60ch; font-size: var(--text-md); font-style: italic; color: var(--ink-mid); line-height: 1.5; }
.prose { max-width: 66ch; }
.prose section { display: block; }
.prose p { margin-top: 1.2em; }
.prose p:first-child { margin-top: 0; }
.prose p.signoff { margin-top: 2.5rem; font-family: var(--font-ui); font-style: normal; color: var(--ink-faint); }
.prose h2 { font-family: var(--font-body); font-size: var(--text-lg); font-weight: 400; line-height: 1.2; color: var(--ink); margin-top: 3rem; margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--rule); }
.prose h2 .secno { font-family: var(--font-mono); font-size: 0.66em; color: var(--accent); margin-right: 0.6em; }
.prose h3 { font-family: var(--font-body); font-size: var(--text-md); font-weight: 400; font-style: italic; color: var(--ink); margin-top: 2rem; margin-bottom: 0.75rem; }
.prose h3 .secno { font-family: var(--font-mono); font-style: normal; font-size: 0.62em; color: var(--ink-faint); margin-right: 0.6em; }
.prose h2 .header-section-number, .prose h3 .header-section-number { font-family: var(--font-mono); font-size: 0.66em; color: var(--accent); margin-right: 0.6em; }
.prose h4 { font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); margin-top: 1.5rem; margin-bottom: 0.5rem; }
.prose ul, .prose ol { padding-left: 1.5rem; margin-top: 1em; margin-bottom: 1em; }
.prose li { margin-top: 0.3em; }
.prose li p { margin-top: 0.3em; }
.prose strong { font-weight: 600; color: var(--ink); }
.prose em { font-style: italic; }
.prose a { color: var(--accent); text-decoration: underline; text-decoration-color: var(--rule2); text-underline-offset: 3px; transition: color 0.15s; }
.prose a:hover { color: var(--accent2); text-decoration-color: var(--accent); }
.prose blockquote { margin: 1.5em 0; padding: 0.75em 1.25em; border-left: 3px solid var(--rule2); color: var(--ink-mid); font-style: italic; }
.prose blockquote p { margin-top: 0.5em; }
.prose blockquote p:first-child { margin-top: 0; }
.prose hr { border: none; border-top: 1px solid var(--rule); margin: 2.5rem 0; }
.prose code { font-family: var(--font-mono); font-size: 0.8em; background: var(--code-bg); padding: 0.15em 0.4em; border-radius: 3px; }
.prose pre:not(.sourceCode) { background: #e9ebf2; border: 1px solid #c8cdd8; border-radius: 6px; padding: 1.1rem 1.25rem; overflow-x: auto; margin: 1.5rem 0; font-size: 0.78rem; line-height: 1.65; font-family: var(--font-mono); box-shadow: 0 1px 4px rgba(0,0,0,0.05); }
.prose pre:not(.sourceCode) code { background: none; padding: 0; border-radius: 0; font-size: inherit; }
.prose div.sourceCode { position: relative; margin: 1.5rem 0; border-radius: 6px; overflow: hidden; border: 1px solid #c8cdd8; box-shadow: 0 1px 4px rgba(0,0,0,0.05); }
.prose pre.sourceCode { background: #e9ebf2; padding: 1.1rem 1.25rem; overflow-x: auto; margin: 0; border-radius: 0; font-size: 0.78rem; line-height: 1.65; }
.prose pre.sourceCode code { background: none; padding: 0; border-radius: 0; font-size: inherit; font-family: var(--font-mono); }
.prose pre { background: var(--code-bg); border: 1px solid var(--rule2); border-radius: 6px; padding: 1.1rem 1.25rem; overflow-x: auto; margin: 1.5rem 0; font-size: 0.8rem; line-height: 1.7; font-family: var(--font-mono); }
.prose pre code { background: none; padding: 0; border-radius: 0; font-size: inherit; }
.codeblock { position: relative; }
.copy-btn { position: absolute; top: 0.5rem; right: 0.5rem; background: color-mix(in srgb, var(--paper) 80%, transparent); border: 1px solid var(--rule2); border-radius: 3px; padding: 0.2rem 0.5rem; font-family: var(--font-ui); font-size: 0.65rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-faint); cursor: pointer; transition: color 0.15s, background 0.15s; }
.copy-btn:hover { color: var(--ink); }
.prose figure { margin: 2rem 0; }
.prose figure img { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.prose figcaption { margin-top: 0.75rem; font-family: var(--font-ui); font-size: var(--text-xs); color: var(--ink-faint); text-align: center; line-height: 1.5; }
.prose figure p { margin: 0; }
.prose pre .kw { color: var(--accent2); }
.prose pre .ty { color: #2c6f6a; }
.prose pre .co { color: var(--ink-faint); font-style: italic; }
.prose pre .st { color: #7d5a00; }
.grammar { margin: 1.75rem 0; font-family: var(--font-mono); font-size: 0.82rem; line-height: 1.9; background: var(--rule-bg); border: 1px solid var(--rule); border-left: 3px solid var(--accent); border-radius: 4px; padding: 1.1rem 1.25rem; overflow-x: auto; }
.grammar table { border-collapse: collapse; width: auto; }
.grammar td { padding: 0.05rem 0.55rem 0.05rem 0; vertical-align: top; white-space: nowrap; }
.grammar .nt { color: var(--accent2); font-style: italic; }
.grammar .op { color: var(--ink-faint); }
.grammar .lit { color: var(--ink); font-weight: 500; }
.grammar .cmt { color: var(--ink-faint); font-style: italic; white-space: normal; }
.rule-block { margin: 1.75rem 0; overflow-x: auto; overflow-y: hidden; }
.rule-block a[id] { scroll-margin-top: 5rem; }
.rule { display: flex; align-items: center; justify-content: center; gap: 1.1rem; margin: 1.2rem 0; }
.rule .frac { text-align: center; }
.rule .frac .num { padding: 0 0.4rem 0.25rem; border-bottom: 1.3px solid var(--ink); display: block; }
.rule .frac .den { padding: 0.25rem 0.4rem 0; display: block; }
.rule .rno { font-family: var(--font-ui); font-size: var(--text-xs); color: var(--accent); white-space: nowrap; }
.rule .side { font-family: var(--font-ui); font-size: var(--text-xs); color: var(--ink-faint); }
mjx-container { font-size: 1.02em !important; }
mjx-container[display="true"] { margin: 1.1rem 0 !important; }
.note { margin: 1.6rem 0; padding: 0.85rem 1.15rem; background: var(--accent-tint); border-left: 3px solid var(--accent); border-radius: 4px; font-size: var(--text-sm); color: var(--ink-mid); }
.note .note-label { display: block; font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.35rem; }
.note p { margin-top: 0.6em; }
.note p:first-child { margin-top: 0; }
.note code { font-size: 0.82em; }
.thesis { margin: 2.25rem 0; padding: 1.4rem 1.6rem; border-left: 3px solid var(--accent); background: var(--rule-bg); font-family: var(--font-body); font-size: var(--text-md); font-style: italic; line-height: 1.5; color: var(--ink); }
.thesis strong { font-style: normal; font-weight: 600; }
.prose table { width: 100%; border-collapse: collapse; margin: 1.5rem 0; font-size: var(--text-sm); }
.prose th { font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1.5px solid var(--ink); }
.prose td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--rule); color: var(--ink-mid); vertical-align: top; }
.prose td code { font-size: 0.82em; }
.prose tr:last-child td { border-bottom: none; }
.prose ul.reflist { list-style: none; padding-left: 0; margin-top: 1.5rem; }
.prose ul.reflist li { padding-left: 1.8rem; text-indent: -1.8rem; margin-top: 1.05em; line-height: 1.55; }
.prose ul.reflist li code { font-size: 0.78em; }
.chapter-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 5rem; padding-top: 2rem; border-top: 1px solid var(--rule); }
.chapter-nav .prev a, .chapter-nav .next a { display: inline-block; font-family: var(--font-ui); font-size: var(--text-xs); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); text-decoration: none; transition: color 0.15s; }
.chapter-nav .next { text-align: right; }
.chapter-nav .next-title { display: block; font-family: var(--font-body); font-size: var(--text-base); font-style: italic; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--ink-mid); margin-top: 0.3rem; transition: color 0.15s; }
.chapter-nav .label { display: block; }
.chapter-nav .ttl { display: block; font-family: var(--font-body); font-size: var(--text-base); font-style: italic; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--ink-mid); margin-top: 0.3rem; transition: color 0.15s; }
.chapter-nav a:hover { color: var(--accent); }
.chapter-nav a:hover .next-title { color: var(--ink); }
.chapter-nav a:hover .ttl { color: var(--accent); }
.chapter-nav .next:only-child { grid-column: 2; }
.cover { max-width: 52rem; margin: 0 auto; padding: 7rem 2rem 6rem; }
.cover-eyebrow { font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.2em; text-transform: uppercase; color: var(--accent); margin-bottom: 2rem; }
.cover-title { font-family: var(--font-body); font-size: clamp(2.8rem, 7vw, 4.6rem); font-weight: 400; line-height: 1.02; letter-spacing: -0.02em; color: var(--ink); max-width: 18ch; }
.cover-sub { margin-top: 1.6rem; max-width: 36ch; font-size: var(--text-md); font-style: italic; color: var(--ink-mid); line-height: 1.5; }
.cover-rule { width: 4rem; height: 3px; background: var(--accent); margin: 2.5rem 0; }
.cover-meta { font-family: var(--font-ui); font-size: var(--text-sm); color: var(--ink-faint); line-height: 1.9; }
.cover-meta strong { color: var(--ink-mid); font-weight: 500; }
.part-head { font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); margin: 2.5rem 0 0; padding-top: 1.5rem; }
.part-head:first-of-type { border-top: none; }
.toc-list { list-style: none; padding: 0; margin: 3rem 0 0; border-top: 1px solid var(--rule); }
.toc-entry { display: grid; grid-template-columns: 3.5rem 1fr; gap: 1rem; padding: 1rem 0; border-bottom: 1px solid var(--rule); align-items: baseline; }
.toc-entry .tn { font-family: var(--font-ui); font-size: var(--text-sm); color: var(--ink-faint); }
.toc-entry a { font-family: var(--font-body); font-size: var(--text-md); color: var(--ink); text-decoration: none; }
.toc-entry a:hover { color: var(--accent); }
.toc-entry .desc { display: block; font-size: var(--text-sm); font-style: italic; color: var(--ink-faint); margin-top: 0.25rem; }
.toc-entry.todo a { color: var(--ink-faint); }
.toc-entry.todo .tn::after { content: " ·"; }
.colophon { margin-top: 2.5rem; padding-top: 1.25rem; border-top: 1px solid var(--rule); font-family: var(--font-ui); font-size: var(--text-xs); color: var(--ink-faint); }
.colophon a { color: var(--ink-faint); text-decoration: underline; text-underline-offset: 0.15em; transition: color 0.15s; }
.colophon a:hover { color: var(--ink); }
.prose a.xref { font-family: var(--font-body); font-style: italic; color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(30,125,122,0.3); transition: border-color 0.15s, color 0.15s; }
.prose a.xref:hover { color: var(--ink); border-bottom-color: var(--ink-faint); }
.prose .note-exercise { margin: 1.6em 0; padding: 1rem 1.4rem; border-left: 3px solid var(--accent); background: rgba(30,125,122,0.04); border-radius: 0 3px 3px 0; }
.prose .note-exercise > p:first-child { margin-top: 0; }
.prose .note-exercise > p:first-child strong { font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.prose .note-studio, .prose .note-lab { margin: 1.6em 0; padding: 1rem 1.4rem; border-left: 3px solid var(--accent); background: rgba(30,125,122,0.04); border-radius: 0 3px 3px 0; }
.prose .note-studio > p:first-child, .prose .note-lab > p:first-child { margin-top: 0; }
.prose .note-studio > p:first-child strong, .prose .note-lab > p:first-child strong { display: block; margin-bottom: 0.35rem; font-family: var(--font-ui); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.prose .note-takeaways { margin-top: 3rem; }
.prose .note-takeaways > p:first-child { font-family: var(--font-body); font-size: var(--text-lg); font-weight: 400; line-height: 1.2; color: var(--ink); margin-top: 0; margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--rule); }
.prose .note-takeaways > p:first-child strong { font-weight: 400; }
@media (max-width: 700px) {
  .index-columns { column-count: 1; }
}
@media (max-width: 640px) {
  .page { padding: 3rem 1.25rem 5rem; }
  .cover { padding: 4rem 1.25rem 4rem; }
  .site-header { padding: 1rem 1.25rem; }
  .book-nav { display: none; }
  .toc-title { font-size: var(--text-xl); }
  .opener-title { font-size: var(--text-xl); }
  .chapter-nav { grid-template-columns: 1fr; }
  .chapter-nav .next { text-align: left; }
  .toc-entry { grid-template-columns: 2.5rem 1fr; }
}

/* ============ 2. per-book differences ============ */
html[data-book="pwn"] .prose strong, html[data-book="bc"] .prose strong { font-weight: 500; }
html[data-book="tcoe"] .cover-sub { max-width: 40ch; }
html[data-book="tcoe"] .toc-list { margin: 1rem 0 0; }
html[data-book="design"] .colophon, html[data-book="bc"] .colophon { font-size: 0.62rem; }
html[data-book="pwn"] .prose td, html[data-book="bc"] .prose td { vertical-align: middle; }
.prose h2, .prose h3 { scroll-margin-top: 5rem; }
/* the book-index page (programming-with-nex/book-index.html): wider, with a denser type scale */
.page-index { max-width: 62rem; --text-base: 1.05rem; --lh-body: 1.6; font-size: var(--text-base); line-height: var(--lh-body); }
.page-index .toc-header { margin-bottom: 3rem; }

/* ============ 3. site look ============ */
/* per-book accent (matches the cards on the landing page) */
html[data-book="pwn"]    { --book-accent: #0b7d7c; --book-accent-dk: #33d1b0; }
html[data-book="bc"]     { --book-accent: #b45309; --book-accent-dk: #fbbf24; }
html[data-book="tcoe"]   { --book-accent: #6d28d9; --book-accent-dk: #a78bfa; }
html[data-book="don"]    { --book-accent: #be123c; --book-accent-dk: #fb7185; }
html[data-book="design"] { --book-accent: #1d4ed8; --book-accent-dk: #60a5fa; }

html[data-theme="light"] {
  --paper: #fafbfc; --paper2: #f1f4f8; --ink: #0f172a; --ink-mid: #334155; --ink-faint: #64748b;
  --rule: #e2e8f0; --rule2: #cbd5e1; --code-bg: #eef2f7; --rule-bg: #f1f4f8;
  --accent: var(--book-accent, #0b7d7c);
  --accent2: color-mix(in srgb, var(--accent) 75%, #000);
  --accent-tint: color-mix(in srgb, var(--accent) 8%, #fff);
  --win: #0f172a; --win-line: #1e293b; --shadow: 0 10px 30px -12px rgba(15,23,42,.25);
}
html[data-theme="dark"] {
  --paper: #0b1220; --paper2: #0f1a2e; --ink: #e8eefc; --ink-mid: #c3cfe6; --ink-faint: #93a4c0;
  --rule: #23324d; --rule2: #31456a; --code-bg: #111c31; --rule-bg: #0f1a2e;
  --accent: var(--book-accent-dk, #33d1b0);
  --accent2: color-mix(in srgb, var(--accent) 75%, #fff);
  --accent-tint: color-mix(in srgb, var(--accent) 14%, var(--paper));
  --win: #060c18; --win-line: #1e293b; --shadow: 0 10px 30px -12px rgba(0,0,0,.7);
}

/* logo in the header */
a.book-title::before { content: ""; flex: none; width: 26px; height: 26px; border-radius: 7px; background: url("../assets/logo/nex-logo-concept-7-orbit-n-light.svg") center / cover; }
html[data-theme="dark"] a.book-title::before { background-image: url("../assets/logo/nex-logo-concept-7-orbit-n-dark.svg"); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }


html[data-theme] body .site-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; height: 60px; padding: 0 1.5rem; background: color-mix(in srgb, var(--paper) 85%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--rule); }
html[data-theme] body .site-header-inner { width: 100%; max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; flex-wrap: nowrap; }
html[data-theme] body a.book-title { display: flex; align-items: center; gap: .55rem; min-width: 0; font: 700 .95rem "JetBrains Mono", monospace; letter-spacing: -.01em; color: var(--ink); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html[data-theme] body a.book-title:hover { color: var(--accent); }
html[data-theme] body .site-crumb { font: 500 .85rem "JetBrains Mono", monospace; color: var(--ink-faint); text-decoration: none; }
html[data-theme] body .site-crumb:hover { color: var(--accent); }
html[data-theme] body .site-sep { color: var(--rule2); font: 400 .9rem "JetBrains Mono", monospace; }
html[data-theme] body .book-nav { margin-left: auto; display: flex; gap: 1.1rem; flex-wrap: nowrap; }
html[data-theme] body .book-nav a { font: 500 .82rem Inter, system-ui, sans-serif; letter-spacing: 0; text-transform: none; color: var(--ink-faint); text-decoration: none; white-space: nowrap; }
html[data-theme] body .book-nav a:hover, html[data-theme] body .book-nav a.active { color: var(--accent); }
html[data-theme] body .theme-toggle { flex: none; width: 34px; height: 34px; border-radius: 999px; border: 1px solid var(--rule); background: var(--paper2); color: var(--ink); cursor: pointer; font-size: .95rem; line-height: 1; }
html[data-theme] body .theme-toggle:hover { border-color: var(--accent); }

html[data-theme] body .page { padding: 4rem 2rem 7rem; }
html[data-theme] body .opener { margin-bottom: 3rem; padding-bottom: 2.2rem; border-bottom: 1px solid var(--rule); }
html[data-theme] body .opener-label { font: 500 .78rem "JetBrains Mono", monospace; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
html[data-theme] body .opener-label:not(:empty)::before { content: "// "; }
html[data-theme] body .opener-title { font: 700 clamp(2rem, 4.6vw, 2.9rem)/1.12 "JetBrains Mono", monospace; letter-spacing: -.03em; color: var(--ink); max-width: 24ch; }
html[data-theme] body .opener-lede { color: var(--ink-mid); }

html[data-theme] body .prose h2 { font: 700 1.5rem/1.25 "JetBrains Mono", monospace; letter-spacing: -.02em; color: var(--ink); border-bottom: 0; border-top: 1px solid var(--rule); padding: 1.6rem 0 0; margin-top: 3rem; }
html[data-theme] body .prose h3 { font: 600 1.08rem/1.35 "JetBrains Mono", monospace; font-style: normal; letter-spacing: -.01em; color: var(--ink); margin-top: 2.2rem; }
html[data-theme] body .prose h4 { font: 600 .8rem "JetBrains Mono", monospace; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); }
html[data-theme] body .prose h2 .secno, html[data-theme] body .prose h2 .header-section-number, html[data-theme] body .prose h3 .secno, html[data-theme] body .prose h3 .header-section-number { font-family: "JetBrains Mono", monospace; color: var(--accent); }
html[data-theme] body .prose a { color: var(--accent); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 3px; border-bottom: 0; }
html[data-theme] body .prose a:hover { color: var(--accent2); text-decoration-color: currentColor; }
html[data-theme] body .prose a.xref { font-style: italic; text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
html[data-theme] body .prose li::marker { color: var(--accent); }
html[data-theme] body .prose blockquote { border-left: 3px solid var(--accent); background: var(--accent-tint); border-radius: 0 10px 10px 0; color: var(--ink-mid); }
html[data-theme] body .prose hr { border-top-color: var(--rule); }
html[data-theme] body .prose strong { color: var(--ink); }

html[data-theme] body .prose code { font-family: "JetBrains Mono", monospace; font-size: .8em; background: var(--code-bg); border: 1px solid var(--rule); border-radius: 6px; padding: .1em .38em; color: var(--ink); }
html[data-theme] body .prose pre, html[data-theme] body .prose pre:not(.sourceCode), html[data-theme] body .prose pre.sourceCode { background: var(--win); color: #e2e8f0; border: 1px solid var(--win-line); border-radius: 14px; padding: 1.1rem 1.3rem; margin: 1.5rem 0; font-family: "JetBrains Mono", monospace; font-size: .8rem; line-height: 1.7; box-shadow: var(--shadow); overflow-x: auto; }
html[data-theme] body .prose div.sourceCode { background: transparent; border: 0; margin: 0; }
html[data-theme] body .prose div.sourceCode pre { margin: 1.5rem 0; }
html[data-theme] body .prose pre code, html[data-theme] body .prose pre:not(.sourceCode) code, html[data-theme] body .prose pre.sourceCode code { background: none; border: 0; padding: 0; color: inherit; font-size: inherit; border-radius: 0; }
html[data-theme] body .prose pre code span, html[data-theme] body .prose pre span { color: inherit; }
html[data-theme] body .prose pre span.kw, html[data-theme] body .prose pre span.cf, html[data-theme] body .prose pre .kw { color: #f472b6; font-weight: 400; }
html[data-theme] body .prose pre span.st, html[data-theme] body .prose pre span.ss, html[data-theme] body .prose pre span.vs, html[data-theme] body .prose pre span.sc, html[data-theme] body .prose pre span.ch, html[data-theme] body .prose pre span.dv, html[data-theme] body .prose pre span.fl, html[data-theme] body .prose pre span.bn, html[data-theme] body .prose pre .st { color: #fcd34d; }
html[data-theme] body .prose pre span.dt, html[data-theme] body .prose pre span.bu, html[data-theme] body .prose pre span.fu, html[data-theme] body .prose pre span.ex, html[data-theme] body .prose pre span.cn, html[data-theme] body .prose pre .ty { color: #67e8f9; }
html[data-theme] body .prose pre span.co, html[data-theme] body .prose pre span.an, html[data-theme] body .prose pre span.do, html[data-theme] body .prose pre span.in, html[data-theme] body .prose pre .co { color: #64748b; font-style: italic; }
html[data-theme] body .prose pre span.er, html[data-theme] body .prose pre span.al, html[data-theme] body .prose pre span.wa { color: #fb7185; }
html[data-theme] body .codeblock { position: relative; }
html[data-theme] body .copy-btn { top: .55rem; right: .55rem; background: #1e293b; color: #cbd5e1; border: 0; border-radius: 8px; padding: .3rem .7rem; font: 500 .72rem "JetBrains Mono", monospace; letter-spacing: 0; text-transform: none; cursor: pointer; }
html[data-theme] body .copy-btn:hover { background: var(--accent); color: var(--paper); }

html[data-theme] body .note, html[data-theme] body .prose .note-exercise, html[data-theme] body .prose .note-studio, html[data-theme] body .prose .note-lab { margin: 1.6rem 0; padding: 1rem 1.3rem; background: var(--accent-tint); border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--rule)); border-left: 4px solid var(--accent); border-radius: 12px; }
html[data-theme] body .note { font-size: .98rem; color: var(--ink-mid); }
html[data-theme] body .note .note-label, html[data-theme] body .prose .note-exercise > p:first-child strong, html[data-theme] body .prose .note-studio > p:first-child strong, html[data-theme] body .prose .note-lab > p:first-child strong { font: 600 .74rem "JetBrains Mono", monospace; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
html[data-theme] body .prose .note-takeaways > p:first-child { font: 700 1.5rem/1.25 "JetBrains Mono", monospace; letter-spacing: -.02em; }
html[data-theme] body .prose .note-takeaways > p:first-child strong { font-weight: 700; }
html[data-theme] body .thesis { border-left: 4px solid #f59e0b; background: color-mix(in srgb, #f59e0b 12%, var(--paper)); border-radius: 12px; font-style: normal; font-weight: 500; color: var(--ink); }

html[data-theme] body .prose table { font-size: .95rem; }
html[data-theme] body .prose th { font: 600 .74rem "JetBrains Mono", monospace; letter-spacing: .06em; color: var(--ink-faint); border-bottom: 2px solid var(--ink); }
html[data-theme] body .prose td { border-bottom-color: var(--rule); }
html[data-theme] body .grammar { background: var(--code-bg); border-color: var(--rule); border-radius: 12px; }
html[data-theme] body .grammar .nt { color: var(--accent2); }

html[data-theme] body .chapter-nav { gap: 1rem; margin-top: 4rem; padding-top: 0; border-top: 0; }
html[data-theme] body .chapter-nav .prev a, html[data-theme] body .chapter-nav .next a { display: block; height: 100%; padding: 1rem 1.2rem; background: var(--paper2); border: 1px solid var(--rule); border-radius: 14px; font: 500 .72rem "JetBrains Mono", monospace; letter-spacing: .08em; color: var(--ink-faint); transition: border-color .15s, transform .15s, box-shadow .15s; }
html[data-theme] body .chapter-nav .prev a:hover, html[data-theme] body .chapter-nav .next a:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
html[data-theme] body .chapter-nav .ttl, html[data-theme] body .chapter-nav .next-title { display: block; margin-top: .3rem; font: 600 1.02rem/1.35 Inter, system-ui, sans-serif; font-style: normal; letter-spacing: 0; text-transform: none; color: var(--ink); }
html[data-theme] body .chapter-nav a:hover .ttl, html[data-theme] body .chapter-nav a:hover .next-title { color: var(--accent); }
html[data-theme] body .chapter-nav .next:empty { display: none; }

html[data-theme] body .part-head { font: 600 .78rem "JetBrains Mono", monospace; letter-spacing: .12em; color: var(--accent); }
html[data-theme] body .toc-entry .tn, html[data-theme] body .ch-num { font-family: "JetBrains Mono", monospace; color: var(--accent); }
html[data-theme] body .toc-entry a, html[data-theme] body .ch-title { color: var(--ink); }
html[data-theme] body .toc-entry a:hover, html[data-theme] body .ch-title:hover { color: var(--accent); }
html[data-theme] body .toc-entry .desc { color: var(--ink-faint); }
html[data-theme] body .colophon a:hover { color: var(--accent); }
html[data-theme] body .reflist li code { background: var(--code-bg); }
html[data-theme] body mjx-container { color: var(--ink); }

@media (max-width: 640px) {
  html[data-theme] body .site-header { padding: 0 1rem; }
  html[data-theme] body .site-crumb, html[data-theme] body .site-sep { display: none; }
  html[data-theme] body .page { padding: 2.5rem 1.25rem 5rem; }
  html[data-theme] body .book-nav { display: none; }
}
