:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #6b7280;
  --border: #e5e7eb;
  --card: #f9fafb;
  --accent: #2563eb;
  --code-bg: #f6f8fa;
  --code-border: #eaeef2;
  --max-width: 1120px;
  --max-width-wide: 1600px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --fg: #e6e8eb;
    --muted: #9aa4b2;
    --border: #262b33;
    --card: #161a20;
    --accent: #6ea8fe;
    --code-bg: #161a20;
    --code-border: #262b33;
  }
}

@font-face {
  font-family: "STIX Two Math";
  src: url("/static/fonts/STIXTwoMath-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans CJK SC",
    "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  text-decoration: underline;
}

code,
pre {
  font-family:
    "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas,
    "Liberation Mono", monospace;
  font-size: 0.9em;
}

/* Header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--fg);
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 1rem;
  font-size: 0.92rem;
}

/* Layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 2.5rem;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  align-items: start;
}

.layout-single {
  grid-template-columns: minmax(0, 1fr);
}

.content {
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 4.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar-head {
  display: none;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgb(0 0 0 / 0.4);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    visibility 0.2s ease;
}

.sidebar-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.sidebar-toggle {
  display: none;
  flex: none;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
  cursor: pointer;
}

.sidebar-toggle,
.sidebar-close {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.sidebar-toggle-icon {
  display: block;
}

/* Breadcrumb */

.breadcrumb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.breadcrumb-row > .breadcrumb {
  flex: 1;
  min-width: 0;
  margin-bottom: 0;
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  row-gap: 0.35rem;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 0.88rem;
  color: var(--muted);
}

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

.concept-id-badge {
  appearance: none;
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 0.08rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-family:
    "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas,
    "Liberation Mono", monospace;
  font-size: 0.76rem;
  line-height: 1.5;
  cursor: pointer;
  overflow-wrap: anywhere;
  transition:
    border-color 0.15s ease,
    color 0.15s ease,
    background 0.15s ease;
}

.concept-id-badge:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  color: var(--accent);
}

.concept-id-badge:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.concept-id-badge.is-copied {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--card));
  color: var(--accent);
}

.concept-id-badge.is-copied::after {
  content: "✓";
  margin-left: 0.3rem;
  font-size: 0.85em;
}

/* Typst body */

.typst-body {
  font-size: 1rem;
}

/* Wrapper injected by Typst HTML export for paragraph source mapping. */
.kb-body {
  display: contents;
}

/* Ctrl/Cmd + hover: highlight the hovered paragraph and show its source. */
.kb-body [data-source] {
  border-radius: 4px;
  box-shadow: 0 0 0 0 transparent;
  transition:
    background-color 0.1s ease,
    box-shadow 0.1s ease;
}

body.kb-source-active [data-source]:hover {
  background-color: rgba(127, 127, 127, 0.12);
  box-shadow: 0 0 0 4px rgba(127, 127, 127, 0.12);
}

body.kb-long-press-active [data-source] {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

@media (prefers-reduced-motion: reduce) {
  .kb-body [data-source] {
    transition: none;
  }
}

.source-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: min(480px, calc(100vw - 24px));
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--fg);
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-line;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.12);
  overflow-wrap: anywhere;
  pointer-events: none;
}

.source-tooltip[hidden] {
  display: none;
}

.source-tooltip.is-copied {
  border-color: var(--accent);
  color: var(--accent);
}

/* Source detail modal */

body.kb-modal-open {
  overflow: hidden;
}

.source-modal {
  width: min(760px, calc(100vw - 2rem));
  max-height: min(82vh, 920px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  opacity: 0;
  box-shadow: 0 24px 80px rgb(0 0 0 / 0.35);
  overflow: hidden;
  transition: opacity 0.1s ease;
}

.source-modal.is-open {
  opacity: 1;
}

.source-modal.is-closing {
  opacity: 0;
}

.source-modal:focus {
  outline: none;
}

.source-modal::backdrop {
  background: rgb(0 0 0 / 0.55);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.1s ease;
}

.source-modal.is-open::backdrop {
  opacity: 1;
}

.source-modal.is-closing::backdrop {
  opacity: 0;
}

.source-modal-card {
  display: flex;
  flex-direction: column;
  max-height: inherit;
}

.source-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

.source-modal-heading {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.source-modal-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.source-modal-path {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.82rem;
}

.source-modal-close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.source-modal-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 1.1rem;
  border-bottom: 1px solid var(--border);
}

.source-modal-tab {
  appearance: none;
  margin-bottom: -1px;
  padding: 0.7rem 0.35rem 0.6rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.source-modal-tab[aria-selected="true"] {
  border-bottom-color: var(--accent);
  color: var(--fg);
}

.source-modal-tab:focus-visible,
.source-modal-close:focus-visible,
.source-modal-action:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 2px;
}

.source-modal-panel {
  min-height: 0;
  padding: 0.9rem 1.1rem 1.1rem;
  overflow: auto;
}

.source-modal-panel[hidden] {
  display: none;
}

.source-modal-code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 2rem;
  margin-bottom: 0.6rem;
}

.source-modal-status {
  min-width: 0;
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.source-modal-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.4rem;
}

.source-modal-action {
  flex: none;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.source-modal-action.is-primary {
  border-color: var(--accent);
  color: var(--accent);
}

.source-modal-action:disabled {
  opacity: 0.55;
  cursor: default;
}

.source-modal-action.is-copied {
  border-color: var(--accent);
  color: var(--accent);
}

.source-modal-action.is-error {
  border-color: #dc2626;
  color: #dc2626;
}

.source-modal-code,
.source-modal-editor {
  max-height: min(52vh, 560px);
  margin: 0;
  padding: 0.9rem 1rem;
  overflow: auto;
  border: 1px solid var(--code-border);
  border-radius: 8px;
  background: var(--code-bg);
  font-family:
    "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas,
    "Liberation Mono", monospace;
  font-size: 0.82rem;
  line-height: 1.55;
  tab-size: 2;
}

.source-modal-code[hidden],
.source-modal-editor[hidden] {
  display: none;
}

.source-modal-code {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-content: start;
  align-items: start;
  column-gap: 0.75rem;
}

.source-modal-code code,
.source-modal-editor code {
  font-size: inherit;
}

.source-modal-editor {
  position: relative;
}

.source-modal-editor:focus-within {
  border-color: var(--accent);
}

.source-editor-highlight {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-content: start;
  align-items: start;
  column-gap: 0.75rem;
  pointer-events: none;
}

.source-editor-input {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: var(--fg);
  font: inherit;
  line-height: inherit;
  letter-spacing: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
  resize: none;
  overflow: hidden;
  outline: none;
  -webkit-text-fill-color: transparent;
}

.source-editor-input::selection {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
}

.source-line-number {
  color: var(--muted);
  text-align: right;
  user-select: none;
  font-variant-numeric: tabular-nums;
}

.source-line-text {
  display: block;
  min-height: 1.55em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
  .source-modal,
  .source-modal::backdrop {
    transition: none;
  }
}

.source-modal-commits {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.source-modal-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.source-commit-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.source-commit {
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}

.source-commit-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.86rem;
}

.source-commit-badge {
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
}

.source-commit-meta {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.25rem 0.75rem;
  margin: 0;
  font-size: 0.8rem;
}

.source-commit-meta dt {
  color: var(--muted);
}

.source-commit-meta dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.source-commit-meta code {
  font-size: 0.9em;
}

.source-commit-link {
  display: inline-block;
  margin-top: 0.55rem;
  font-size: 0.78rem;
}

@media (hover: hover) and (pointer: fine) {
  .source-modal-close:hover,
  .source-modal-action:not(:disabled):hover {
    border-color: var(--accent);
    color: var(--accent);
  }
}

@media (max-width: 640px) {
  .source-modal {
    width: calc(100vw - 1rem);
    max-height: calc(100vh - 1rem);
  }

  .source-modal-header {
    padding: 0.85rem;
  }

  .source-modal-tabs {
    padding: 0 0.85rem;
  }

  .source-modal-panel {
    padding: 0.8rem 0.85rem 0.9rem;
  }

  .source-modal-code {
    max-height: 45vh;
  }
}

.typst-body h2 {
  margin: 0 0 0.4rem;
  font-size: 2rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.typst-body h3 {
  margin: 2rem 0 0.6rem;
  padding-bottom: 0.35rem;
  font-size: 1.3rem;
  line-height: 1.3;
  border-bottom: 1px solid var(--border);
}

.typst-body h4 {
  margin: 1.5rem 0 0.4rem;
  font-size: 1.08rem;
}

.typst-body :is(h2, h3, h4, h5) {
  scroll-margin-top: 5.5rem;
}

.typst-body > em:first-of-type {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-style: normal;
  font-size: 1.05rem;
}

.typst-body p {
  margin: 0.8rem 0;
}

.typst-body ul,
.typst-body ol {
  padding-left: 1.4rem;
}

.typst-body li {
  margin: 0.3rem 0;
}

.typst-body code {
  padding: 0.12em 0.35em;
  border: 1px solid var(--code-border);
  border-radius: 4px;
  background: var(--code-bg);
}

.typst-body pre {
  margin: 1rem 0;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  border: 1px solid var(--code-border);
  border-radius: 10px;
  background: var(--code-bg);
  line-height: 1.55;
}

.typst-body pre code {
  padding: 0;
  border: 0;
  background: none;
  font-size: 0.88rem;
}

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

.typst-body table {
  width: 100%;
  margin: 1rem 0;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.typst-body th,
.typst-body td {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  text-align: left;
}

.typst-body th {
  background: var(--card);
}

.typst-body math {
  font-family: "STIX Two Math", "Latin Modern Math", "Cambria Math", "Noto Sans Math", math;
  font-size: 1.05em;
}

.typst-body math[display="block"] {
  margin: 1rem 0;
  text-align: center;
}

/* Sidebar cards */

.card {
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}

.card h2 {
  margin: 0 0 0.7rem;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 0.8rem;
  margin: 0 0 0.8rem;
  font-size: 0.9rem;
}

.meta dt {
  color: var(--muted);
}

.meta dd {
  margin: 0;
}

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

.tag {
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.8rem;
}

.tag:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.toc {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
}

.toc li {
  margin: 0.32rem 0;
}

.toc-level-4 {
  padding-left: 0.9rem;
}

.toc-level-5 {
  padding-left: 1.8rem;
}

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

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

.link-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.link-list li {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  gap: 0.6rem;
  padding: 0.3rem 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.9rem;
}

.link-list li:last-child {
  border-bottom: 0;
}

.link-list .badge {
  flex: none;
  white-space: nowrap;
}

.kind {
  flex: none;
  margin-left: auto;
  color: var(--muted);
  font-size: 0.75rem;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

/* Error page */

.error-page {
  padding: 2rem 0;
}

.error-code {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.error-page h1 {
  margin: 0.2rem 0 0.8rem;
  font-size: 1.8rem;
}

.error-detail {
  margin-top: 1.2rem;
  padding: 1rem;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--code-bg);
  font-size: 0.85rem;
  white-space: pre-wrap;
}

/* Footer */

.site-footer {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
}

/* Index / tag / search pages */

.hero {
  padding: 0.5rem 0 1.2rem;
}

.hero h1 {
  margin: 0 0 0.3rem;
  font-size: 2.1rem;
  letter-spacing: -0.01em;
}

.hero p {
  margin: 0 0 1.1rem;
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-width: 640px;
}

.search-form input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.95rem;
}

.search-form button {
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.95rem;
  cursor: pointer;
}

.search-form select {
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.9rem;
}

@media (max-width: 600px) {
  .search-form-advanced input[type="search"] {
    flex-basis: 100%;
  }

  .search-form-advanced select {
    flex: 1 1 0;
    min-width: 0;
  }
}

.search-form button:hover {
  filter: brightness(1.05);
}

.hero-home .search-form {
  width: 100%;
  max-width: none;
  gap: 0.65rem;
}

.hero-home .search-form input,
.hero-home .search-form button {
  border-radius: 10px;
}

.hero-home .search-form input {
  padding: 0.8rem 1rem;
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  box-shadow:
    0 1px 2px rgb(0 0 0 / 6%),
    0 0 0 3px color-mix(in srgb, var(--accent) 7%, transparent);
  font-size: 1.02rem;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.hero-home .search-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.hero-home .search-form button {
  padding: 0.8rem 1.6rem;
  font-size: 1rem;
  font-weight: 600;
}

/* Graph page */

.graph-section {
  margin-top: 2rem;
}

.graph-overview-wrap {
  overflow-x: auto;
}

.graph-overview {
  display: block;
  width: 100%;
  max-width: 640px;
  height: auto;
  margin: 0 auto;
}

.graph-overview-edge {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
}

.graph-overview-edge-label-bg {
  fill: var(--bg);
  stroke: var(--border);
  stroke-width: 1;
}

.graph-overview-edge-label {
  fill: var(--muted);
  font-size: 11px;
}

.graph-overview-topic-circle {
  fill: var(--card);
  stroke: var(--accent);
  stroke-width: 1.8;
}

.graph-overview-topic-problem .graph-overview-topic-circle {
  stroke: #d97706;
}

.graph-overview-topic-title {
  fill: var(--fg);
  font-size: 13px;
  font-weight: 600;
}

.graph-overview-topic-meta {
  fill: var(--muted);
  font-size: 10px;
}

.graph-overview-topic:hover .graph-overview-topic-circle {
  stroke-width: 3;
}

.graph-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 1rem;
}

.graph-detail-card {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}

.graph-detail-card h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.graph-detail-meta {
  margin: 0 0 0.6rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.graph-detail {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
}

.graph-detail-edge {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.35;
}

.graph-arrow-head {
  fill: var(--accent);
}

.graph-detail-node rect {
  fill: var(--bg);
  stroke: var(--accent);
  stroke-width: 1.5;
}

.graph-detail-node-algorithm rect {
  stroke: #16a34a;
}

.graph-detail-node-technique rect {
  stroke: #d97706;
}

.graph-detail-node-problem-model rect {
  stroke: #8b5cf6;
}

.graph-detail-node text {
  fill: var(--fg);
  font-size: 12px;
  text-anchor: middle;
}

.graph-detail-node:hover rect {
  stroke-width: 2.5;
}

.graph-matrix-wrap {
  overflow-x: auto;
}

.graph-matrix {
  border-collapse: collapse;
  width: 100%;
  max-width: 760px;
  font-size: 0.8rem;
}

.graph-matrix th,
.graph-matrix td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.4rem;
  text-align: center;
  white-space: nowrap;
}

.graph-matrix thead th {
  color: var(--muted);
  font-weight: 500;
}

.graph-matrix tbody th {
  text-align: left;
  color: var(--fg);
  font-weight: 500;
}

.graph-matrix td {
  min-width: 2rem;
  color: var(--fg);
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.8rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.legend::before {
  content: "";
  display: inline-block;
  width: 1rem;
  height: 0.2rem;
  margin-right: 0.35rem;
  vertical-align: middle;
}

.legend-edge::before {
  background: var(--accent);
}

.legend-concept::before {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: var(--accent);
}

.legend-algorithm::before {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: #16a34a;
}

.legend-technique::before {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: #d97706;
}

.legend-model::before {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: #8b5cf6;
}

.legend-problem-node::before {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: #d97706;
}

@media (max-width: 900px) {
  .graph-detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .graph-overview {
    min-width: 520px;
  }

  .graph-detail-card {
    overflow-x: auto;
  }

  .graph-detail-large {
    min-width: 520px;
  }
}

.panel {
  margin-top: 2rem;
}

.panel > h2 {
  margin: 0 0 0.8rem;
  font-size: 1.15rem;
}

.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.8rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.concept-card {
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}

.concept-card-head {
  display: block;
}

.concept-card-head > .badge {
  margin-right: 0.25rem;
}

.concept-title {
  overflow-wrap: anywhere;
  font-weight: 600;
  font-size: 1.02rem;
}

.concept-summary {
  margin: 0.4rem 0 0.7rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.search-snippet {
  overflow-wrap: anywhere;
}

.search-snippet mark {
  padding: 0 0.08em;
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: inherit;
}

.search-match {
  color: var(--muted);
  font-size: 0.75rem;
}

.concept-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.concept-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.concept-updated {
  margin-top: 0.4rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.badge {
  display: inline-block;
  line-height: 1.65;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--border);
  /* 35% of the computed badge height: line-height + vertical padding + border. */
  border-radius: calc((1.65em + 0.2rem + 2px) * 0.35);
  background: var(--bg);
  color: var(--muted);
  font-size: 0.75rem;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag-count {
  margin-left: 0.35rem;
  color: var(--muted);
  font-size: 0.72rem;
}

/* Responsive */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem;
  }

  .breadcrumb-row {
    align-items: flex-start;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 30;
    width: min(22rem, 88vw);
    height: 100vh;
    height: 100dvh;
    max-width: 100%;
    padding: 0 1.1rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg);
    border-left: 1px solid var(--border);
    box-shadow: -12px 0 32px rgb(0 0 0 / 0.18);
    transform: translateX(100%);
    visibility: hidden;
    pointer-events: none;
    transition:
      transform 0.2s ease,
      visibility 0.2s ease;
    order: 0;
  }

  .sidebar.is-open {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }

  .sidebar-head {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0 -1.1rem;
    padding: 0.75rem 1.1rem;
    background: var(--bg);
  }

  .sidebar-title {
    font-weight: 600;
    font-size: 0.95rem;
  }

  .sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card);
    color: var(--muted);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .typst-body h2 {
    font-size: 1.65rem;
  }
}

.sidebar-toggle:focus-visible,
.sidebar-close:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .sidebar-toggle:hover,
  .sidebar-close:hover {
    border-color: var(--accent);
    color: var(--accent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar-backdrop {
    transition: none;
  }
}

/* Outlines */

.outline-layout {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 2rem;
  align-items: start;
}

.outline-script {
  position: sticky;
  top: 4.5rem;
  max-height: calc(100vh - 6.5rem);
  overflow: auto;
  padding-right: 0.35rem;
}

.outline-header {
  margin-bottom: 1rem;
}

.outline-header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 0.9rem;
}

.outline-header-meta .muted {
  margin: 0;
}

.outline-handout-link {
  flex: none;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
}

.outline-handout-link:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

.outline-header h1 {
  margin: 0 0 0.45rem;
  font-size: 1.9rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.outline-summary {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.outline-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.outline-list-item {
  position: relative;
  padding: 0.8rem 0;
  border-top: 1px solid var(--border);
}

.outline-list-item:last-child {
  border-bottom: 1px solid var(--border);
}

.outline-item-button {
  display: flex;
  width: 100%;
  gap: 0.7rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--fg);
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.outline-item-button:hover .outline-item-title,
.outline-item-button.is-active .outline-item-title {
  color: var(--accent);
}

.outline-item-button.is-active .outline-item-title .badge {
  border-color: var(--accent);
  color: var(--accent);
}

.outline-item-button.is-active .outline-item-index {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.outline-item-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

.outline-item-index {
  flex: none;
  min-width: 1.8rem;
  height: 1.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.7rem;
  text-align: center;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.outline-item-main {
  display: block;
  min-width: 0;
}

.outline-item-title {
  display: block;
  font-weight: 600;
  line-height: 1.4;
  transition: color 0.15s ease;
}

.outline-item-title .badge {
  margin-right: 0.35rem;
}

.outline-item-summary,
.outline-item-id {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.outline-item-id {
  font-family: "JetBrains Mono", "Cascadia Code", monospace;
}

.outline-item-disabled {
  display: flex;
  gap: 0.7rem;
  opacity: 0.65;
}

.outline-notes {
  margin: 0.55rem 0 0 2.5rem;
  padding-left: 0.65rem;
  border-left: 2px solid var(--border);
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.55;
}

.outline-notes > :first-child {
  margin-top: 0;
}

.outline-notes > :last-child {
  margin-bottom: 0;
}

.outline-notes p {
  margin: 0.35rem 0;
}

.outline-notes ul,
.outline-notes ol {
  margin: 0.35rem 0;
  padding-left: 1.2rem;
}

.outline-notes li {
  margin: 0.15rem 0;
}

.outline-notes h3,
.outline-notes h4 {
  margin: 0.7rem 0 0.25rem;
  color: var(--fg);
  font-size: 0.92rem;
}

.outline-notes math {
  font-family: "STIX Two Math", "Latin Modern Math", "Cambria Math", "Noto Sans Math", math;
}

.outline-item-link {
  display: inline-block;
  margin: 0.35rem 0 0 2.5rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.outline-item-link:hover {
  color: var(--accent);
}

.outline-viewer {
  min-width: 0;
  min-height: 60vh;
  padding: 1.2rem 1.3rem 2rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
}

.outline-viewer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.outline-viewer-head h2 {
  margin: 0.1rem 0 0;
  font-size: 1.35rem;
  line-height: 1.3;
}

.outline-viewer-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
}

.outline-nav-button {
  flex: none;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}

.outline-nav-button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.outline-nav-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.outline-viewer-kicker {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.outline-open-link {
  flex: none;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
}

.outline-open-link:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.outline-content {
  scroll-margin-top: 5rem;
}

.outline-content > h2:first-child,
.outline-content > em:first-of-type {
  display: none;
}

.outline-content[aria-busy="true"] {
  opacity: 0.65;
}

@media (max-width: 900px) {
  .outline-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .outline-script {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .outline-viewer {
    min-height: 40vh;
  }
}

.outline-notes code {
  padding: 0.08em 0.28em;
  border: 1px solid var(--code-border);
  border-radius: 4px;
  background: var(--code-bg);
}

.outline-notes pre {
  margin: 0.5rem 0;
  padding: 0.6rem 0.7rem;
  overflow-x: auto;
  border: 1px solid var(--code-border);
  border-radius: 8px;
  background: var(--code-bg);
  line-height: 1.5;
}

.outline-notes pre code {
  padding: 0;
  border: 0;
  background: none;
}

.outline-notes math[display="block"] {
  margin: 0.5rem 0;
  text-align: center;
}


/* Wider workspace for outline pages */

.layout-wide,
body.page-wide .site-header,
body.page-wide .site-footer {
  max-width: min(var(--max-width-wide), calc(100vw - 2.5rem));
}

@media (max-width: 900px) {
  .layout-wide,
  body.page-wide .site-header,
  body.page-wide .site-footer {
    max-width: none;
  }
}

/* Content version history */

.commit-form {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 1rem;
}

.commit-form label {
  font-weight: 600;
}

.commit-form textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  line-height: 1.55;
  resize: vertical;
}

.commit-form textarea:disabled {
  opacity: 0.6;
}

.commit-form button {
  padding: 0.45rem 0.9rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.commit-form button:hover:not(:disabled) {
  filter: brightness(1.05);
}

.commit-form button:disabled {
  opacity: 0.45;
  cursor: default;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.form-error {
  padding: 0.65rem 0.8rem;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fef2f2;
  color: #991b1b;
}

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

.commit-row {
  position: relative;
  display: flex;
  gap: 1rem;
  justify-content: space-between;
  padding: 0.8rem 0 0.8rem 1.2rem;
  border-bottom: 1px solid var(--border);
}

.commit-row::before {
  position: absolute;
  top: 1.25rem;
  left: -5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
  content: "";
}

.commit-row.is-current::before {
  background: var(--accent);
}

.commit-row-main {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.25rem;
}

.commit-description {
  color: var(--fg);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.commit-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.commit-meta code {
  color: var(--muted);
}

.commit-stats {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.commit-open {
  flex: none;
  align-self: center;
  font-size: 0.85rem;
}

.badge-muted {
  opacity: 0.7;
}

.history-timeline {
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-entry {
  position: relative;
  margin-left: 0.25rem;
  padding-bottom: 0.75rem;
  padding-left: 1.1rem;
  border-left: 1px solid var(--border);
}

.history-entry:last-child {
  padding-bottom: 0;
  border-left-color: transparent;
}

.history-dot {
  position: absolute;
  top: 0.35rem;
  left: -5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
}

.history-entry.is-current .history-dot {
  background: var(--accent);
}

.history-entry-main {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.history-description {
  color: var(--fg);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.history-meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.history-current {
  margin-left: 0.35rem;
  color: var(--accent);
}

.diff-file-hint {
  margin: 0 0 0.6rem;
}

.diff-file-block {
  margin-bottom: 0.55rem;
  overflow: hidden;
  border: 1px solid var(--code-border);
  border-radius: 10px;
  background: var(--code-bg);
}

.diff-file-block > summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.diff-file-block > summary::-webkit-details-marker {
  display: none;
}

.diff-file-block > summary::before {
  flex: none;
  color: var(--muted);
  font-size: 0.8em;
  content: "▸";
  transition: transform 0.15s ease;
}

.diff-file-block[open] > summary::before {
  transform: rotate(90deg);
}

.diff-file-block > summary:hover {
  background: color-mix(in srgb, var(--fg) 4%, transparent);
}

.diff-file-block[open] > summary {
  border-bottom: 1px solid var(--code-border);
}

.diff-file-path {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family:
    "JetBrains Mono", "Cascadia Code", "SFMono-Regular", Consolas,
    "Liberation Mono", monospace;
  font-size: 0.85rem;
}

.diff-file-stats {
  flex: none;
  margin-left: auto;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.diff-add-count {
  color: #166534;
}

.diff-del-count {
  color: #991b1b;
}

.diff-file-block .commit-diff {
  margin: 0;
  border: 0;
  border-radius: 0;
}

.commit-diff {
  margin: 0;
  padding: 0.8rem 1rem;
  overflow-x: auto;
  border: 1px solid var(--code-border);
  border-radius: 10px;
  background: var(--code-bg);
  font-size: 0.82rem;
  line-height: 1.5;
}

.commit-diff span {
  display: block;
  white-space: pre;
}

.diff-add {
  background: rgba(34, 197, 94, 0.12);
  color: #166534;
}

.diff-del {
  background: rgba(239, 68, 68, 0.12);
  color: #991b1b;
}

.diff-file {
  color: var(--accent);
}

.diff-hunk {
  color: #7c3aed;
}

.diff-meta {
  color: var(--muted);
}

.code-block {
  padding: 0.7rem 0.8rem;
  overflow-x: auto;
  border: 1px solid var(--code-border);
  border-radius: 8px;
  background: var(--code-bg);
}

@media (prefers-color-scheme: dark) {
  .form-error {
    border-color: #7f1d1d;
    background: #2a1215;
    color: #fca5a5;
  }

  .diff-add {
    color: #86efac;
  }

  .diff-del {
    color: #fca5a5;
  }

  .diff-add-count {
    color: #86efac;
  }

  .diff-del-count {
    color: #fca5a5;
  }

  .diff-hunk {
    color: #c4b5fd;
  }
}

@media (max-width: 700px) {
  .commit-row {
    flex-direction: column;
    gap: 0.4rem;
  }

  .commit-open {
    align-self: flex-start;
  }
}

/* Keep the header navigation on one line on narrow screens. */
@media (max-width: 440px) {
  .site-header {
    gap: 0.5rem;
    padding: 0.75rem;
  }

  body.page-wide .site-header {
    max-width: none;
  }

  .brand {
    font-size: 1rem;
  }

  .site-nav {
    min-width: 0;
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 0.5rem;
    overflow-x: auto;
    font-size: 0.84rem;
    scrollbar-width: none;
  }

  .site-nav::-webkit-scrollbar {
    display: none;
  }

  .site-nav a {
    white-space: nowrap;
  }
}
