@import url('https://fonts.googleapis.com/css2?family=Fira+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400&family=Fira+Code:wght@300;400;500&display=swap');

:root {
  --surface: #0a0a0b;
  --surface-raised: #141416;
  --border: #3d3d3d;

  --text-primary: #f8f8f8;
  --text-heading: #ffffff;
  --text-muted: #c0c0c0;

  --accent: #a5b4fc;
  --accent-light: #c7d2fe;
  --accent-border: rgba(165, 180, 252, 0.35);
  --accent-tag-bg: rgba(165, 180, 252, 0.08);

  --nav-blur-bg: rgba(10, 10, 11, 0.85);
  --font: 'Fira Sans', system-ui, sans-serif;
}

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

html.theme-transitioning,
html.theme-transitioning *,
html.theme-transitioning *::before,
html.theme-transitioning *::after {
  transition: background-color 0.35s ease, color 0.35s ease,
    border-color 0.35s ease, box-shadow 0.35s ease !important;
}

html {
  font-family: var(--font);
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text-primary);
  font-weight: 300;
  line-height: 1.75;
}


/* ── Nav ── */
header.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  background-color: var(--nav-blur-bg);
  border-bottom: 1px solid var(--accent);
}

nav.site-nav {
  position: relative;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

nav.site-nav .nav-brand a {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: -0.02em;
  transition: opacity 0.2s;
}

nav.site-nav .nav-brand a:hover {
  opacity: 0.75;
}

nav.site-nav .nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

nav.site-nav .nav-links a {
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

nav.site-nav .nav-links a:hover {
  color: var(--text-primary);
}

.nav-end {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.theme-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.2em 0.35em;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s;
}

.theme-toggle:hover {
  color: var(--accent);
}

/* ── Hamburger ── */
.nav-menu-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 4px;
  width: 2rem;
  height: 2rem;
}

.nav-menu-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-muted);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.15s ease;
}

.nav-menu-btn.is-open span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.nav-menu-btn.is-open span:nth-child(2) {
  opacity: 0;
}

.nav-menu-btn.is-open span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ── Layout ── */
main {
  flex: 1;
}

.content-width {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ── Hero ── */
.hero {
  padding-top: 6rem;
  padding-bottom: 4rem;
}

.hero h1 {
  font-size: clamp(2.25rem, 5vw, 3rem);
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1.1;
  margin: 0 0 1.25rem;
  color: var(--accent);
}

.hero .hero-tagline {
  font-size: clamp(1.1rem, 2.5vw, 1.35rem);
  font-weight: 300;
  color: var(--text-muted);
  line-height: 1.55;
  margin: 0 0 1rem;
  max-width: 30rem;
}

.hero .hero-body {
  font-size: 0.95rem;
  font-weight: 300;
  color: var(--text-primary);
  line-height: 1.7;
  max-width: 36rem;
  margin: 0;
}

/* ── Section header ── */
.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
}

.section-label {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.section-link {
  font-size: 0.8rem;
  font-weight: 300;
  color: var(--accent);
  text-decoration: none;
  transition: opacity 0.15s;
}

.section-link:hover {
  opacity: 0.75;
  text-decoration: underline;
}

/* ── Index two-column layout ── */
.index-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4rem;
  align-items: start;
  padding-bottom: 6rem;
}

/* ── Post list ── */
.posts-section {}

.posts-list {
  display: flex;
  flex-direction: column;
}

/* ── Projects column (index) ── */
.projects-col {}

.projects-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.project-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  padding: 1rem;
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s, background-color 0.2s, box-shadow 0.2s;
}

.project-card:hover {
  border-color: var(--accent-border);
  box-shadow: 0 4px 16px rgba(129, 140, 248, 0.07);
}

.project-card h3 {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-heading);
  margin: 0 0 0.4rem;
  letter-spacing: -0.01em;
  transition: color 0.15s;
  line-height: 1.3;
}

.project-card:hover h3 {
  color: var(--accent-light);
}

.project-card .card-desc {
  font-size: 0.73rem;
  font-weight: 300;
  color: var(--text-muted);
  line-height: 1.5;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.6rem;
}

.project-card .card-tag {
  font-size: 0.62rem;
  font-weight: 300;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  padding: 0.12em 0.45em;
  border-radius: 3px;
}

/* ── Full projects page ── */
.projects-page-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
  margin-top: 2rem;
}

.project-card--full {
  aspect-ratio: 1;
  padding: 1.1rem;
}

.project-card--full h3 {
  font-size: 0.88rem;
}

.project-card--full .card-desc {
  font-size: 0.72rem;
  -webkit-line-clamp: 4;
}

.card-gh-link {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--accent);
  transition: color 0.15s;
}

.project-card:hover .card-gh-link {
  color: var(--accent-light);
}

.page-intro {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 300;
  margin: -0.5rem 0 0;
  max-width: 48rem;
}

.page-intro p {
  margin: 0;
}

.post-item {
  display: block;
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s;
}

.post-item:last-child {
  border-bottom: none;
}

.post-item:hover {
  border-bottom-color: var(--accent-border);
}

.post-item .post-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.72rem;
  font-weight: 300;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.post-item .sep {
  color: var(--border);
}

.post-item h3 {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text-heading);
  margin: 0 0 0.4rem;
  letter-spacing: -0.02em;
  line-height: 1.3;
  transition: color 0.15s;
}

.post-item:hover h3 {
  color: var(--accent-light);
}

.post-item .post-desc {
  font-size: 0.85rem;
  font-weight: 300;
  color: var(--text-muted);
  margin: 0 0 0.65rem;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag {
  font-size: 0.68rem;
  font-weight: 300;
  color: var(--text-muted);
  background: var(--accent-tag-bg);
  border: 1px solid var(--border);
  padding: 0.15em 0.55em;
  border-radius: 4px;
}

.post-item .tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.post-item .tag {
  font-size: 0.68rem;
  font-weight: 300;
  color: var(--text-muted);
  background: var(--accent-tag-bg);
  border: 1px solid var(--border);
  padding: 0.15em 0.55em;
  border-radius: 4px;
}

/* ── Post three-column layout (toc | body | margin) ── */
.post-layout {
  display: grid;
  grid-template-columns: 240px 1fr minmax(0, 200px);
  gap: 0 4rem;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem;
  justify-content: center;
}

.post-wrap {
  min-width: 0;
  padding: 4rem 0 7rem;
  align-self: start;
}

/* ── TOC drawer toggle (mobile) ── */
.toc-toggle {
  display: none;
  position: fixed;
  bottom: 2rem;
  left: 1.25rem;
  z-index: 41;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-family: var(--font);
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  letter-spacing: 0.04em;
  transition: color 0.15s, border-color 0.15s;
}

.toc-toggle:hover {
  color: var(--accent);
  border-color: var(--accent-border);
}

/* ── Post aside column (empty grid slot) ── */
.post-asides {
  min-width: 0;
}

/* ── Aside inline reference marker ── */
.aside-ref {
  font-size: 0.65em;
  font-weight: 500;
  color: var(--accent);
  vertical-align: super;
  line-height: 0;
  margin-left: 0.1em;
}

/* ── Sticky TOC sidebar ── */
.post-toc {
  padding-top: 4rem;
}

.toc-inner {
  position: sticky;
  top: 5.5rem;
}

.toc-label {
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

.toc-inner .toc {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
}

.toc-inner .toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-inner .toc>ul>li {
  margin-bottom: 0.2rem;
}

.toc-inner .toc li {
  margin: 0;
}

.toc-inner .toc ul ul {
  padding-left: 0.85rem;
  border-left: 1px solid var(--border);
  margin-top: 0.2rem;
  margin-bottom: 0.2rem;
}

.toc-inner .toc a {
  display: block;
  font-size: 0.75rem;
  font-weight: 300;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.2rem 0;
  line-height: 1.4;
  transition: color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-inner .toc a:hover {
  color: var(--accent-light);
}

.toc-inner .toc a.toc-active {
  color: var(--accent-light);
  font-weight: 400;
}

/* ── Post header ── */
.post-header {
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.post-header h1 {
  font-size: clamp(1.7rem, 3.5vw, 2.3rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.12;
  color: var(--text-heading);
  margin: 0 0 0.75rem;
}

.post-header .subtitle {
  font-size: 1rem;
  font-weight: 300;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
  line-height: 1.5;
}

.post-header .byline {
  font-size: 0.75rem;
  font-weight: 300;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.post-header .sep {
  color: var(--border);
}

.post-header .tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.post-header .tag {
  font-size: 0.68rem;
  font-weight: 300;
  color: var(--text-muted);
  background: var(--accent-tag-bg);
  border: 1px solid var(--border);
  padding: 0.15em 0.55em;
  border-radius: 4px;
}

code,
pre,
.codehilite {
  border-color: #4a4a4a;
}

pre code {
  border: none;
}

/* ── Post body ── */
.post-body {
  font-size: 0.95rem;
  font-weight: 300;
  line-height: 1.75;
  text-align: justify;
  hyphens: auto;
}

/* ── Aside / margin note ── */
.post-body .aside-note {
  float: right;
  clear: right;
  /* push aside past the body column into the third grid column.
     negative margin-right cancels the width, so body text doesn't wrap around it. */
  width: 200px;
  margin-right: calc(-200px - 4rem);
  margin-top: 0rem;
  margin-bottom: 1rem;
  font-size: 0.72rem;
  font-weight: 300;
  color: var(--text-muted);
  border-left: 2px solid var(--border);
  padding: 0.35rem 0 0.35rem 0.75rem;
  line-height: 1.55;
}

.aside-num {
  font-size: 0.7em;
  font-weight: 500;
  color: var(--accent);
  vertical-align: super;
  line-height: 0;
  margin-right: 0.25em;
}

.post-body .aside-note p {
  margin: 0 0 0.4rem;
}

.post-body .aside-note p:last-child {
  margin: 0;
}

.post-body h1,
.post-body h2,
.post-body h3 {
  scroll-margin-top: 6rem;
}


.post-body p {
  margin-bottom: 1.5rem;
}

.post-body h1 {
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text-heading);
  margin: 2.5rem 0 1rem;
  line-height: 1.2;
}

.post-body h2 {
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text-heading);
  margin: 2rem 0 0.75rem;
  line-height: 1.2;
}

.post-body h3 {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-heading);
  margin: 1.75rem 0 0.5rem;
}

/* ── Typography ── */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text-heading);
  line-height: 1.2;
}

a {
  color: var(--accent-light);
  text-decoration: none;
  transition: color 0.15s;
}

a:hover {
  color: var(--text-heading);
}

.post-body a {
  color: var(--accent-light);
  border-bottom: 1px solid var(--border);
  transition: color 0.15s, border-color 0.15s;
}

.post-body a:hover {
  color: var(--text-heading);
  border-bottom-color: var(--border);
}

strong {
  font-weight: 500;
  color: var(--text-heading);
}

em {
  font-style: italic;
}

hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 3rem 0;
}

.ornament {
  text-align: center;
  margin: 3rem 0;
  color: var(--accent);
  opacity: 0.4;
  font-size: 0.9rem;
  letter-spacing: 0.4em;
}

.ornament::before {
  content: '~  *  ~';
}

/* ── Code ── */
code {
  font-family: 'Fira Code', ui-monospace, monospace;
  font-size: 0.75em;
  font-weight: 400;
  background: var(--surface-raised);
  color: var(--accent-light);
  padding: 0.15em 0.45em;
  border-radius: 3px;
  border: 1px solid var(--border);
  white-space: pre-wrap;
}

pre {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  margin: 2rem 0;
  border-radius: 8px;
}

pre code {
  background: transparent;
  color: var(--text-primary);
  padding: 0;
  border: none;
  font-size: 0.75rem;
  font-weight: 300;
  line-height: 1.0;
  white-space: pre;
}

.codehilite {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  margin: 2rem 0;
  border-radius: 8px;
  overflow: hidden;
}

.codehilite pre {
  margin: 0;
  border: none;
  background: transparent;
  border-radius: 0;
  font-weight: 300;
}

.codehilite .hll {
  background: rgba(129, 140, 248, 0.1);
}

.codehilite .k,
.codehilite .kw {
  color: #c7d2fe;
  font-weight: 500;
}

.codehilite .kn,
.codehilite .kp,
.codehilite .kr,
.codehilite .kt {
  color: #c7d2fe;
}

.codehilite .cf {
  color: #c7d2fe;
  font-weight: 500;
}

.codehilite .pp {
  color: #c7d2fe;
}

.codehilite .ot {
  color: #c7d2fe;
}

.codehilite .dt {
  color: #67e8f9;
}

.codehilite .dv,
.codehilite .mi,
.codehilite .mf,
.codehilite .mo,
.codehilite .bn,
.codehilite .fl {
  color: #86efac;
}

.codehilite .s,
.codehilite .s1,
.codehilite .s2,
.codehilite .sb,
.codehilite .sc,
.codehilite .se,
.codehilite .si,
.codehilite .sl,
.codehilite .ss,
.codehilite .sx {
  color: #fdba74;
}

.codehilite .c,
.codehilite .c1,
.codehilite .cm,
.codehilite .cs,
.codehilite .cp {
  color: #52525b;
  font-style: italic;
}

.codehilite .nd {
  color: #67e8f9;
}

.codehilite .nf,
.codehilite .fm {
  color: #93c5fd;
}

.codehilite .nc {
  color: #67e8f9;
}

.codehilite .ne {
  color: #fca5a5;
}

.codehilite .nb {
  color: var(--text-muted);
}

.codehilite .o,
.codehilite .ow {
  color: #71717a;
}

.codehilite .err {
  color: #fca5a5;
  font-weight: 500;
}

.codehilite .nv,
.codehilite .vi {
  color: var(--text-primary);
}

/* ── Blockquote ── */
blockquote {
  background: var(--surface-raised);
  border-left: 3px solid var(--accent);
  padding: 1.1rem 1.5rem;
  margin: 2rem 0;
  font-style: italic;
  font-weight: 300;
  color: var(--text-muted);
  border-radius: 0 6px 6px 0;
  position: relative;
}

blockquote::before {
  content: '\201C';
  font-size: 2.5rem;
  color: var(--accent);
  opacity: 0.2;
  position: absolute;
  top: -0.2rem;
  left: 0.45rem;
  line-height: 1;
}

/* ── Tables ── */
table {
  border-collapse: collapse;
  width: 100%;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  margin: 2rem 0;
  font-size: 0.85rem;
  border-radius: 8px;
  overflow: hidden;
}

th {
  background: rgba(129, 140, 248, 0.05);
  font-weight: 400;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-light);
  padding: 0.75rem 1rem;
  text-align: left;
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 300;
  color: var(--text-primary);
}

tr:last-child td {
  border-bottom: none;
}

/* ── Images ── */
img {
  max-width: 100%;
  display: block;
  margin: 2rem auto;
}

figcaption,
.img-caption {
  text-align: center;
  font-style: italic;
  font-weight: 300;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: -1.25rem;
  margin-bottom: 2rem;
}

/* ── Figures (block images + inlined SVG diagrams) ── */
.post-body figure {
  margin: 2rem 0;
  text-align: center;
}

.post-body figure img,
.post-body figure svg {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.post-body figure figcaption {
  margin: 0.85rem 0 0;
}

/* ── Callout blocks ── */
.theorem,
.proof,
.definition,
.remark,
.example,
.lemma,
.corollary {
  padding: 1.5rem 1.75rem 1.25rem;
  margin: 2rem 0;
  border-left: 3px solid;
  border-radius: 0 6px 6px 0;
  position: relative;
  font-weight: 300;
}

.theorem::before,
.proof::before,
.definition::before,
.remark::before,
.example::before,
.lemma::before,
.corollary::before {
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  position: absolute;
  top: 0.5rem;
  left: 1.5rem;
}

.theorem {
  background: rgba(129, 140, 248, 0.05);
  border-color: var(--accent);
}

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

.lemma {
  background: rgba(129, 140, 248, 0.05);
  border-color: #6366f1;
}

.lemma::before {
  content: "lemma";
  color: #6366f1;
}

.corollary {
  background: rgba(129, 140, 248, 0.05);
  border-color: #6366f1;
}

.corollary::before {
  content: "corollary";
  color: #6366f1;
}

.proof {
  background: var(--surface-raised);
  border-color: var(--border);
}

.proof::before {
  content: "proof";
  color: var(--text-muted);
  font-style: italic;
}

.definition {
  background: var(--surface-raised);
  border-color: var(--border);
}

.definition::before {
  content: "definition";
  color: var(--text-muted);
}

.remark {
  background: var(--surface-raised);
  border-color: var(--border);
}

.remark::before {
  content: "remark";
  color: var(--text-muted);
}

.example {
  background: var(--surface-raised);
  border-color: var(--border);
}

.example::before {
  content: "example";
  color: var(--text-muted);
}

/* ── Collapsible details ── */
.post-body details {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  margin: 2rem 0;
}

.post-body details summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s;
}

.post-body details summary::-webkit-details-marker {
  display: none;
}

.post-body details summary::before {
  content: '▸';
  font-size: 0.75em;
  display: inline-block;
  transition: transform 0.2s ease;
}

.post-body details[open] summary::before {
  transform: rotate(90deg);
}

.post-body details summary:hover {
  opacity: 0.75;
}

.post-body details[open] summary {
  border-bottom: 1px solid var(--border);
}

.post-body .details-body {
  padding: 1rem 1.25rem;
  font-size: 0.88rem;
  font-weight: 300;
  color: var(--text-muted);
  line-height: 1.7;
}

.post-body .details-body>*:first-child {
  margin-top: 0;
}

.post-body .details-body>*:last-child {
  margin-bottom: 0;
}

/* ── Post prev/next nav ── */
.post-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.post-nav-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  text-decoration: none;
  color: inherit;
  max-width: 46%;
  transition: opacity 0.15s;
}

.post-nav-newer {
  margin-left: auto;
  text-align: right;
}

.post-nav-label {
  font-size: 0.68rem;
  font-weight: 300;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.post-nav-title {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-heading);
  line-height: 1.3;
  transition: color 0.15s;
}

.post-nav-item:hover .post-nav-title {
  color: var(--accent-light);
}

/* ── Page (non-post) ── */
.page-wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 4rem 1.5rem 7rem;
  font-weight: 300;
}

.page-wrap--wide {
  max-width: 1080px;
}

.page-title {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin: 0 0 2rem;
  color: var(--text-heading);
}

/* ── Footer ── */
footer.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 6rem;
}

.footer-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.78rem;
  font-weight: 300;
  color: var(--text-muted);
}

.footer-links {
  display: flex;
  gap: 1.5rem;
}

.footer-links a,
.footer-inner a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.footer-links a:hover,
.footer-inner a:hover {
  color: var(--accent-light);
}

/* ── Selection ── */
::selection {
  background: rgba(129, 140, 248, 0.2);
  color: var(--text-heading);
}

::-moz-selection {
  background: rgba(129, 140, 248, 0.2);
  color: var(--text-heading);
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: var(--surface);
}

::-webkit-scrollbar-thumb {
  background: #2a2a2a;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* ── Page transition ── */
@property --reveal {
  syntax: '<percentage>';
  inherits: false;
  initial-value: -60%;
}

@keyframes pageFadeIn {
  from {
    --reveal: -60%;
  }

  to {
    --reveal: 160%;
  }
}

main {
  mask-image: linear-gradient(135deg,
      black calc(var(--reveal) - 50%),
      transparent calc(var(--reveal) + 50%));
  -webkit-mask-image: linear-gradient(135deg,
      black calc(var(--reveal) - 50%),
      transparent calc(var(--reveal) + 50%));
  animation: pageFadeIn 2s cubic-bezier(0.16, 1, 0.3, 1) both;
}

body[data-page="index"] main {
  animation-duration: 10s;
}

/* ── Responsive ── */
@media (max-width: 860px) {
  .post-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  /* TOC becomes a slide-in drawer */
  .post-toc {
    display: block;
    position: fixed;
    top: 4rem;
    left: 0;
    bottom: 0;
    width: 260px;
    z-index: 40;
    overflow-y: auto;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.5rem;
    padding-top: 2rem;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .post-toc.is-open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.25);
  }

  .toc-inner {
    position: static;
  }

  .toc-toggle {
    display: block;
  }

  .post-body .aside-note {
    float: none;
    width: auto;
    margin: 1rem 0;
    margin-right: 0;
  }

  .index-grid {
    grid-template-columns: 1fr;
  }

  .projects-page-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 560px) {
  nav.site-nav {
    padding: 0 1rem;
  }

  .nav-menu-btn {
    display: flex;
  }

  nav.site-nav .nav-links {
    display: flex;
    position: absolute;
    top: 100%;
    left: -1rem;
    right: -1rem;
    flex-direction: column;
    gap: 0;
    align-items: stretch;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.25rem 0;
    opacity: 0;
    transform: translateY(-6px);
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.35s ease, transform 0.35s ease, visibility 0s linear 0.35s;
  }

  nav.site-nav .nav-links.is-open {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.35s ease, transform 0.35s ease, visibility 0s linear 0s;
  }

  nav.site-nav .nav-links li {
    padding: 0;
  }

  nav.site-nav .nav-links a {
    display: block;
    padding: 0.75rem 2.25rem;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
  }

  nav.site-nav .nav-links li:last-child a {
    border-bottom: none;
  }

  .content-width {
    padding: 0 1rem;
  }

  .page-wrap {
    padding: 2.5rem 1rem 5rem;
  }

  .hero {
    padding-top: 3rem;
    padding-bottom: 2rem;
  }

  .projects-page-grid {
    grid-template-columns: 1fr;
  }

  .footer-inner {
    flex-direction: column;
    text-align: center;
  }
}

/* ── Light mode (system preference) ── */
@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) {
    --surface: #f1f2f5;
    --surface-raised: #fafbfd;
    --border: #e0e2e7;
    --text-primary: #0f172a;
    --text-heading: #020617;
    --text-muted: #475569;
    --accent: #6366f1;
    --accent-light: #4f46e5;
    --accent-border: rgba(99, 102, 241, 0.3);
    --accent-tag-bg: rgba(99, 102, 241, 0.06);
    --nav-blur-bg: rgba(241, 242, 245, 0.90);
  }

  html:not([data-theme="dark"]) .project-card {
    background: #e8eaef;
    border-color: #c7cad3;
  }

  html:not([data-theme="dark"]) .post-header {
    border-bottom-color: #b2b2b8;
  }

  html:not([data-theme="dark"]) code,
  html:not([data-theme="dark"]) pre,
  html:not([data-theme="dark"]) .codehilite {
    background: #e8eaef;
    border-color: #d5d8df;
  }

  html:not([data-theme="dark"]) pre code {
    background: transparent;
    border: none;
  }

  html:not([data-theme="dark"]) .project-card:hover {
    box-shadow: none;
  }

  html:not([data-theme="dark"]) header.site-header {
    border-bottom: 1px solid var(--accent);
  }

  html:not([data-theme="dark"]) ::-webkit-scrollbar-thumb {
    background: #d2d2d6;
  }

  html:not([data-theme="dark"]) ::selection {
    background: rgba(99, 102, 241, 0.12);
    color: var(--text-heading);
  }

  html:not([data-theme="dark"]) ::-moz-selection {
    background: rgba(99, 102, 241, 0.12);
    color: var(--text-heading);
  }

  html:not([data-theme="dark"]) .codehilite .k,
  html:not([data-theme="dark"]) .codehilite .kw,
  html:not([data-theme="dark"]) .codehilite .kn,
  html:not([data-theme="dark"]) .codehilite .kp,
  html:not([data-theme="dark"]) .codehilite .kr,
  html:not([data-theme="dark"]) .codehilite .kt,
  html:not([data-theme="dark"]) .codehilite .cf,
  html:not([data-theme="dark"]) .codehilite .pp,
  html:not([data-theme="dark"]) .codehilite .ot {
    color: #4f46e5;
  }

  html:not([data-theme="dark"]) .codehilite .dv,
  html:not([data-theme="dark"]) .codehilite .mi,
  html:not([data-theme="dark"]) .codehilite .mf,
  html:not([data-theme="dark"]) .codehilite .mo,
  html:not([data-theme="dark"]) .codehilite .bn,
  html:not([data-theme="dark"]) .codehilite .fl {
    color: #15803d;
  }

  html:not([data-theme="dark"]) .codehilite .s,
  html:not([data-theme="dark"]) .codehilite .s1,
  html:not([data-theme="dark"]) .codehilite .s2,
  html:not([data-theme="dark"]) .codehilite .sb,
  html:not([data-theme="dark"]) .codehilite .sc,
  html:not([data-theme="dark"]) .codehilite .se,
  html:not([data-theme="dark"]) .codehilite .si,
  html:not([data-theme="dark"]) .codehilite .sl,
  html:not([data-theme="dark"]) .codehilite .ss,
  html:not([data-theme="dark"]) .codehilite .sx {
    color: #0f766e;
  }

  html:not([data-theme="dark"]) .codehilite .c,
  html:not([data-theme="dark"]) .codehilite .c1,
  html:not([data-theme="dark"]) .codehilite .cm,
  html:not([data-theme="dark"]) .codehilite .cs,
  html:not([data-theme="dark"]) .codehilite .cp {
    color: #71717a;
  }

  html:not([data-theme="dark"]) .codehilite .nf,
  html:not([data-theme="dark"]) .codehilite .fm {
    color: #1d4ed8;
  }

  html:not([data-theme="dark"]) .codehilite .nc,
  html:not([data-theme="dark"]) .codehilite .dt,
  html:not([data-theme="dark"]) .codehilite .nd {
    color: #0e7490;
  }

  html:not([data-theme="dark"]) .codehilite .ne {
    color: #dc2626;
  }

  html:not([data-theme="dark"]) .codehilite .o,
  html:not([data-theme="dark"]) .codehilite .ow {
    color: #525252;
  }

  html:not([data-theme="dark"]) .codehilite .hll {
    background: rgba(99, 102, 241, 0.08);
  }
}

/* ── Explicit light mode (manual toggle) ── */
html[data-theme="light"] {
  --surface: #f1f2f5;
  --surface-raised: #fafbfd;
  --border: #e0e2e7;
  --text-primary: #0f172a;
  --text-heading: #020617;
  --text-muted: #475569;
  --accent: #6366f1;
  --accent-light: #4f46e5;
  --accent-border: rgba(99, 102, 241, 0.3);
  --accent-tag-bg: rgba(99, 102, 241, 0.06);
  --nav-blur-bg: rgba(241, 242, 245, 0.90);
}

html[data-theme="light"] .project-card {
  background: #e8eaef;
  border-color: #c7cad3;
}

html[data-theme="light"] .post-header {
  border-bottom-color: #b2b2b8;
}

html[data-theme="light"] code,
html[data-theme="light"] pre,
html[data-theme="light"] .codehilite {
  background: #e8eaef;
  border-color: #d5d8df;
}

html[data-theme="light"] pre code {
  background: transparent;
  border: none;
}

html[data-theme="light"] .project-card:hover {
  box-shadow: none;
}

html[data-theme="light"] header.site-header {
  border-bottom: 1px solid var(--accent);
}

html[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: #d2d2d6;
}

html[data-theme="light"] ::selection {
  background: rgba(99, 102, 241, 0.12);
  color: var(--text-heading);
}

html[data-theme="light"] ::-moz-selection {
  background: rgba(99, 102, 241, 0.12);
  color: var(--text-heading);
}

html[data-theme="light"] .codehilite .k,
html[data-theme="light"] .codehilite .kw,
html[data-theme="light"] .codehilite .kn,
html[data-theme="light"] .codehilite .kp,
html[data-theme="light"] .codehilite .kr,
html[data-theme="light"] .codehilite .kt,
html[data-theme="light"] .codehilite .cf,
html[data-theme="light"] .codehilite .pp,
html[data-theme="light"] .codehilite .ot {
  color: #4f46e5;
}

html[data-theme="light"] .codehilite .dv,
html[data-theme="light"] .codehilite .mi,
html[data-theme="light"] .codehilite .mf,
html[data-theme="light"] .codehilite .mo,
html[data-theme="light"] .codehilite .bn,
html[data-theme="light"] .codehilite .fl {
  color: #15803d;
}

html[data-theme="light"] .codehilite .s,
html[data-theme="light"] .codehilite .s1,
html[data-theme="light"] .codehilite .s2,
html[data-theme="light"] .codehilite .sb,
html[data-theme="light"] .codehilite .sc,
html[data-theme="light"] .codehilite .se,
html[data-theme="light"] .codehilite .si,
html[data-theme="light"] .codehilite .sl,
html[data-theme="light"] .codehilite .ss,
html[data-theme="light"] .codehilite .sx {
  color: #0f766e;
}

html[data-theme="light"] .codehilite .c,
html[data-theme="light"] .codehilite .c1,
html[data-theme="light"] .codehilite .cm,
html[data-theme="light"] .codehilite .cs,
html[data-theme="light"] .codehilite .cp {
  color: #71717a;
}

html[data-theme="light"] .codehilite .nf,
html[data-theme="light"] .codehilite .fm {
  color: #1d4ed8;
}

html[data-theme="light"] .codehilite .nc,
html[data-theme="light"] .codehilite .dt,
html[data-theme="light"] .codehilite .nd {
  color: #0e7490;
}

html[data-theme="light"] .codehilite .ne {
  color: #dc2626;
}

html[data-theme="light"] .codehilite .o,
html[data-theme="light"] .codehilite .ow {
  color: #525252;
}

html[data-theme="light"] .codehilite .hll {
  background: rgba(99, 102, 241, 0.08);
}

/* ── Explicit dark mode (manual toggle overrides system light preference) ── */
html[data-theme="dark"] {
  --surface: #0a0a0b;
  --surface-raised: #141416;
  --border: #3d3d3d;
  --text-primary: #f8f8f8;
  --text-heading: #ffffff;
  --text-muted: #c0c0c0;
  --accent: #a5b4fc;
  --accent-light: #c7d2fe;
  --accent-border: rgba(165, 180, 252, 0.35);
  --accent-tag-bg: rgba(165, 180, 252, 0.08);
  --nav-blur-bg: rgba(10, 10, 11, 0.85);
}

html[data-theme="dark"] .post-header {
  border-bottom-color: #606060;
}

html[data-theme="dark"] code,
html[data-theme="dark"] pre,
html[data-theme="dark"] .codehilite {
  border-color: #4a4a4a;
}

html[data-theme="dark"] pre code {
  border: none;
}

html[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: #2a2a2a;
}

html[data-theme="dark"] ::selection {
  background: rgba(129, 140, 248, 0.2);
  color: var(--text-heading);
}

html[data-theme="dark"] ::-moz-selection {
  background: rgba(129, 140, 248, 0.2);
  color: var(--text-heading);
}

html[data-theme="dark"] .codehilite .k,
html[data-theme="dark"] .codehilite .kw,
html[data-theme="dark"] .codehilite .kn,
html[data-theme="dark"] .codehilite .kp,
html[data-theme="dark"] .codehilite .kr,
html[data-theme="dark"] .codehilite .kt,
html[data-theme="dark"] .codehilite .cf,
html[data-theme="dark"] .codehilite .pp,
html[data-theme="dark"] .codehilite .ot {
  color: #c7d2fe;
  font-weight: 500;
}

html[data-theme="dark"] .codehilite .dv,
html[data-theme="dark"] .codehilite .mi,
html[data-theme="dark"] .codehilite .mf,
html[data-theme="dark"] .codehilite .mo,
html[data-theme="dark"] .codehilite .bn,
html[data-theme="dark"] .codehilite .fl {
  color: #86efac;
}

html[data-theme="dark"] .codehilite .s,
html[data-theme="dark"] .codehilite .s1,
html[data-theme="dark"] .codehilite .s2,
html[data-theme="dark"] .codehilite .sb,
html[data-theme="dark"] .codehilite .sc,
html[data-theme="dark"] .codehilite .se,
html[data-theme="dark"] .codehilite .si,
html[data-theme="dark"] .codehilite .sl,
html[data-theme="dark"] .codehilite .ss,
html[data-theme="dark"] .codehilite .sx {
  color: #fdba74;
}

html[data-theme="dark"] .codehilite .c,
html[data-theme="dark"] .codehilite .c1,
html[data-theme="dark"] .codehilite .cm,
html[data-theme="dark"] .codehilite .cs,
html[data-theme="dark"] .codehilite .cp {
  color: #52525b;
  font-style: italic;
}

html[data-theme="dark"] .codehilite .nf,
html[data-theme="dark"] .codehilite .fm {
  color: #93c5fd;
}

html[data-theme="dark"] .codehilite .nc,
html[data-theme="dark"] .codehilite .dt,
html[data-theme="dark"] .codehilite .nd {
  color: #67e8f9;
}

html[data-theme="dark"] .codehilite .ne {
  color: #fca5a5;
}

html[data-theme="dark"] .codehilite .o,
html[data-theme="dark"] .codehilite .ow {
  color: #71717a;
}

html[data-theme="dark"] .codehilite .hll {
  background: rgba(129, 140, 248, 0.1);
}

/* ── Post images: invert dark-mode diagrams for light mode ── */
@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) .post-body img {
    filter: invert(1) hue-rotate(180deg);
    border-color: transparent;
  }
}

html[data-theme="light"] .post-body img {
  filter: invert(1) hue-rotate(180deg);
  border-color: transparent;
}

/* ── Inlined SVG diagrams: dark-first palette lives in the SVG; recolour for
   light mode here so they track the manual toggle (no invert filter). ── */
@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) .post-body svg .mv {
    fill: #5f5e5a;
  }

  html:not([data-theme="dark"]) .post-body svg .mvp {
    fill: #4f46e5;
  }

  html:not([data-theme="dark"]) .post-body svg .mvx,
  html:not([data-theme="dark"]) .post-body svg .pl {
    fill: #818cf8;
  }

  html:not([data-theme="dark"]) .post-body svg .edge {
    stroke: #afb5bf;
  }

  html:not([data-theme="dark"]) .post-body svg .edgep,
  html:not([data-theme="dark"]) .post-body svg .cut {
    stroke: #4f46e5;
  }

  html:not([data-theme="dark"]) .post-body svg .edgex {
    stroke: #818cf8;
  }

  html:not([data-theme="dark"]) .post-body svg .node {
    fill: #edf1f6;
    stroke: #828a94;
  }

  html:not([data-theme="dark"]) .post-body svg .nodep {
    fill: #eeedfe;
    stroke: #4f46e5;
  }

  html:not([data-theme="dark"]) .post-body svg .nodex {
    fill: #f4f2fd;
    stroke: #818cf8;
  }

  html:not([data-theme="dark"]) .post-body svg .nodenew,
  html:not([data-theme="dark"]) .post-body svg .net {
    fill: #f4f2fd;
    stroke: #818cf8;
  }

  html:not([data-theme="dark"]) .post-body svg .leaf {
    fill: #dcd9fb;
    stroke: #4f46e5;
  }

  html:not([data-theme="dark"]) .post-body svg .ring {
    stroke: #818cf8;
  }

  html:not([data-theme="dark"]) .post-body svg .edgeback {
    stroke: #6366f1;
  }

  html:not([data-theme="dark"]) .post-body svg .tag {
    fill: #6366f1;
  }

  html:not([data-theme="dark"]) .post-body svg .netd {
    fill: #4f46e5;
  }
}

html[data-theme="light"] .post-body svg .mv {
  fill: #5f5e5a;
}

html[data-theme="light"] .post-body svg .mvp {
  fill: #4f46e5;
}

html[data-theme="light"] .post-body svg .mvx,
html[data-theme="light"] .post-body svg .pl {
  fill: #818cf8;
}

html[data-theme="light"] .post-body svg .edge {
  stroke: #afb5bf;
}

html[data-theme="light"] .post-body svg .edgep,
html[data-theme="light"] .post-body svg .cut {
  stroke: #4f46e5;
}

html[data-theme="light"] .post-body svg .edgex {
  stroke: #818cf8;
}

html[data-theme="light"] .post-body svg .node {
  fill: #edf1f6;
  stroke: #828a94;
}

html[data-theme="light"] .post-body svg .nodep {
  fill: #eeedfe;
  stroke: #4f46e5;
}

html[data-theme="light"] .post-body svg .nodex {
  fill: #f4f2fd;
  stroke: #818cf8;
}

html[data-theme="light"] .post-body svg .nodenew,
html[data-theme="light"] .post-body svg .net {
  fill: #f4f2fd;
  stroke: #818cf8;
}

html[data-theme="light"] .post-body svg .leaf {
  fill: #dcd9fb;
  stroke: #4f46e5;
}

html[data-theme="light"] .post-body svg .ring {
  stroke: #818cf8;
}

html[data-theme="light"] .post-body svg .edgeback {
  stroke: #6366f1;
}

html[data-theme="light"] .post-body svg .tag {
  fill: #6366f1;
}

html[data-theme="light"] .post-body svg .netd {
  fill: #4f46e5;
}

/* ── LaTeX-generated diagrams (dpbusd post): box/line geometry stays in the SVG,
   labels are MathJax inside <foreignObject>. Recolour the grayscale strokes and
   purple highlight fills for light mode via attribute selectors. ── */
@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) .post-body svg [stroke="#c4c4c4"] {
    stroke: #9aa1ad;
  }

  html:not([data-theme="dark"]) .post-body svg [fill="#222540"] {
    fill: #c7d2fe;
  }

  html:not([data-theme="dark"]) .post-body svg [fill="#2b2f5e"] {
    fill: #a5b4fc;
  }
}

html[data-theme="light"] .post-body svg [stroke="#c4c4c4"] {
  stroke: #9aa1ad;
}

html[data-theme="light"] .post-body svg [fill="#222540"] {
  fill: #c7d2fe;
}

html[data-theme="light"] .post-body svg [fill="#2b2f5e"] {
  fill: #a5b4fc;
}

/* MathJax labels rendered into the diagrams' <foreignObject> cells. Colour is
   inherited from the theme, so they track light/dark automatically. */
.post-body svg foreignObject {
  overflow: visible;
}

.post-body svg .fo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--text-primary);
  line-height: 1;
  white-space: nowrap;
}

.post-body svg .fo.lbl {
  font-size: 11px;
}

.post-body svg .fo.res {
  font-size: 8.5px;
}

.post-body svg .fo.op {
  font-size: 17px;
}

.post-body svg .fo.dots {
  font-size: 13px;
}

.post-body svg .fo .MathJax {
  margin: 0 !important;
}
