:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #666666;
  --border: #dddddd;
  --code-bg: #f4f4f4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --fg: #eeeeee;
    --muted: #999999;
    --border: #333333;
    --code-bg: #1c1c1c;
  }
}

:root[data-theme="dark"] {
  --bg: #111111;
  --fg: #eeeeee;
  --muted: #999999;
  --border: #333333;
  --code-bg: #1c1c1c;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #666666;
  --border: #dddddd;
  --code-bg: #f4f4f4;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  font-size: 112.5%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.65;
  max-width: 1180px;
  margin: 0 auto;
  padding: 3rem 1.5rem 5rem;
}

a {
  color: var(--fg);
}

a:not(:hover) {
  text-decoration-color: var(--border);
}

header.site-header {
  margin-bottom: 2.5rem;
}

.site-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

header.site-header .site-title {
  font-size: 1.4rem;
  font-weight: 700;
  text-decoration: none;
}

.theme-toggle {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--code-bg);
}

.theme-toggle svg {
  display: block;
}

.toc-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
}

.toc-toggle:hover {
  background: var(--code-bg);
}

.layout {
  display: flex;
  align-items: flex-start;
  gap: 2.5rem;
}

.toc-sidebar {
  flex: 0 0 230px;
  width: 230px;
  position: sticky;
  top: 1.5rem;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  font-size: 0.85rem;
}

.toc-heading {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--fg);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

.toc-section {
  margin-bottom: 1.25rem;
}

.toc-section-title {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-left: 1px solid var(--border);
}

.toc-list li a {
  display: block;
  padding: 0.3rem 0 0.3rem 0.75rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  text-decoration: none;
  color: var(--muted);
}

.toc-list li a:hover {
  color: var(--fg);
}

.toc-list li a.active {
  color: var(--fg);
  font-weight: 600;
  border-left-color: var(--fg);
}

.page-content {
  flex: 1;
  min-width: 0;
}

@media (max-width: 860px) {
  .toc-toggle {
    display: inline-flex;
  }

  .layout {
    display: block;
  }

  .toc-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    max-height: none;
    width: 260px;
    background: var(--bg);
    border-right: 1px solid var(--border);
    padding: 4rem 1.25rem 2rem;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 60;
  }

  .toc-sidebar.open {
    transform: translateX(0);
  }

  .toc-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 55;
  }

  .toc-overlay.open {
    display: block;
  }
}

header.site-header .site-subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

nav.crumbs {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 2rem;
}

nav.crumbs a {
  color: var(--muted);
}

h1, h2, h3 {
  line-height: 1.3;
}

h1 {
  font-size: 1.8rem;
  margin-bottom: 0.25rem;
}

.post-meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.5rem 0 1.5rem;
}

.tag-filter button {
  font: inherit;
  font-size: 0.8rem;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  cursor: pointer;
}

.tag-filter button:hover {
  background: var(--code-bg);
}

.tag-filter button.active {
  color: var(--fg);
  border-color: var(--fg);
  font-weight: 600;
}

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

.post-list li {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.post-list a {
  text-decoration: none;
  font-weight: 600;
}

.post-list a:hover {
  text-decoration: underline;
}

.post-list li {
  flex-wrap: wrap;
}

.post-list li[hidden] {
  display: none;
}

.post-list .title-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.35rem;
}

.post-meta .tags {
  margin-top: 0.5rem;
}

.tag {
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
}

pre, code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
}

pre {
  background: var(--code-bg);
  padding: 1rem;
  overflow-x: auto;
  border-radius: 4px;
}

code {
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

pre code {
  background: none;
  padding: 0;
}

.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
}

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

.example-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--muted);
  margin: 1.25rem 0 0.35rem;
}

.intuition {
  color: var(--muted);
  font-style: italic;
  margin: 0.5rem 0 1.25rem;
}

.cite-box {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}

.cite-box h2 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.cite-box .cite-text {
  margin-bottom: 1rem;
}

.cite-box pre {
  position: relative;
}

.cite-box button.copy-btn {
  font-family: inherit;
  font-size: 0.8rem;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  margin-bottom: 0.5rem;
}

.cite-box button.copy-btn:hover {
  background: var(--code-bg);
}

footer.site-footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.figure {
  margin: 1.5rem 0;
}

.figure svg {
  display: block;
  width: 100%;
  max-width: 640px;
  height: auto;
  margin: 0 auto;
  color: var(--fg);
}

.figure figcaption {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  margin-top: 0.5rem;
}

.figure .pt {
  fill: currentColor;
}

.figure .origin {
  fill: var(--bg);
  stroke: currentColor;
  stroke-width: 1.5;
}

.figure .axis {
  stroke: currentColor;
  stroke-width: 1.5;
}

.figure .faint {
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}

.figure .lbl {
  fill: currentColor;
  font-size: 13px;
  font-family: inherit;
}

.figure .lbl.muted {
  fill: var(--muted);
}
