/* Shared article navigation; colors follow the site's light/dark theme. */
.post-body :is(h2, h3, h4),
.post-title {
  scroll-margin-top: calc(var(--site-header-height, 120px) + var(--post-nav-height, 46px) + 24px);
}

.post-toc {
  position: sticky;
  top: var(--site-header-height);
  z-index: 90;
  background: var(--bg);
  margin: 24px 0 32px;
  border-block: 1px solid var(--border-strong);
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 12px;
  line-height: 1.6;
}

.post-toc summary {
  padding: 12px 4px;
  cursor: pointer;
  color: var(--text-primary);
}

.post-toc-current {
  display: inline-block;
  max-width: calc(100% - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  color: var(--text-secondary);
  font-weight: 400;
}

.post-toc nav {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 20px rgb(0 0 0 / 8%);
  max-height: min(55dvh, calc(100dvh - var(--site-header-height) - 70px));
  overflow-y: auto;
  padding: 0 0 14px;
  overscroll-behavior: contain;
}

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

.post-toc ul ul {
  padding-left: 14px;
}

.post-toc a {
  display: block;
  padding: 6px 10px;
  border-left: 2px solid transparent;
  color: var(--text-secondary);
  text-decoration: none;
  overflow-wrap: anywhere;
  transition: color 150ms ease, border-color 150ms ease;
}

.post-toc a:hover {
  color: var(--text-primary);
  border-left-color: var(--border-strong);
}

.post-toc a[aria-current="location"] {
  color: var(--text-primary);
  border-left-color: var(--text-primary);
  background: var(--bg-card);
  font-weight: 700;
}

.post-toc a:focus-visible,
.post-toc summary:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

@media (min-width: 1280px) {
  :root { --post-nav-height: 0px; }
  .post-toc {
    position: fixed;
    top: calc(var(--site-header-height, 120px) + 24px);
    left: max(24px, calc(50% - 640px));
    width: 240px;
    margin: 0;
    border: 0;
    z-index: 10;
  }

  .post-toc summary {
    display: none;
  }

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

  .post-toc nav {
    position: static;
    background: transparent;
    border: 0;
    box-shadow: none;
    max-height: calc(100dvh - var(--site-header-height, 120px) - 88px);
    scrollbar-width: thin;
  }
}

@media (prefers-reduced-motion: no-preference) {
  html:has(.post-toc) { scroll-behavior: smooth; }
}

@media print {
  .post-toc { display: none; }
}
