@media (prefers-reduced-motion: no-preference) {
  html:has(.post-outline:not([hidden])) {
    scroll-behavior: smooth;
  }
}

.post-outline {
  --outline-gutter: 1.25rem;
  color: #929292;
}

.post-outline details {
  border-block: 1px solid #2b2b2b;
  padding: .7rem 0;
  margin-bottom: 1.75rem;
}

.post-outline summary {
  display: grid;
  grid-template-columns: var(--outline-gutter) minmax(0, 1fr);
  align-items: center;
  list-style: none;
  cursor: pointer;
  color: inherit;
  font-size: .9rem;
  font-weight: 600;
}

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

.post-outline summary::before {
  content: "";
  justify-self: center;
  inline-size: .6rem;
  block-size: .6rem;
  background: currentColor;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

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

.post-outline ul {
  list-style: none;
  border-inline-start: 1px solid #2b2b2b;
  margin: .65rem 0 0 calc(var(--outline-gutter) / 2);
}

.post-outline a {
  display: block;
  border-inline-start: 1px solid transparent;
  margin-inline-start: -1px;
  padding: .3rem .8rem;
  color: inherit;
  font-size: .9rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.post-outline li:not(.outline-subsection):not(:first-child) {
  margin-block-start: .65rem;
}

.post-outline .outline-subsection a {
  padding-inline-start: 1.65rem;
  font-size: .825rem;
}

.post-outline a:hover {
  color: #b0b0b0;
}

.post-outline a:focus-visible {
  outline: 2px solid #80bbff;
  outline-offset: -2px;
}

.post-outline a[aria-current="location"] {
  border-inline-start-color: #80bbff;
  color: #80bbff;
}

@media (width < 1400px) {
  .post-outline {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #181818;
  }

  .post-outline nav {
    max-height: 45vh;
    overflow: auto;
  }

  .post-content :is(h2, h3)[id] {
    scroll-margin-top: 4rem;
  }
}

.post-code-copy {
  position: relative;
}

.post-content pre:has(> code) {
  padding: 1rem 1.25rem;
}

.post-content pre.post-numbered-code {
  display: flex;
  gap: .85rem;
}

.post-content pre.post-numbered-code > code {
  width: auto;
  flex: 1 0 auto;
}

.post-content pre.post-numbered-code > .post-code-gutter {
  border-inline-end: 1px solid #2b2b2b;
  padding-inline-end: .85rem;
  color: #858585;
  flex: none;
  text-align: right;
  user-select: none;
}

.post-content .post-code-copy pre {
  padding-inline-end: 3.5rem;
}

.post-copy-button {
  display: grid;
  place-items: center;
  position: absolute;
  inset-block-start: .3rem;
  inset-inline-end: .4rem;
  padding: .3rem .55rem;
  color: #d8d8d8;
  background: rgb(34 34 34 / 40%);
  border: 1px solid #444;
  border-radius: 4px;
  cursor: pointer;
}

.post-copy-check,
[data-copy-state="copied"] .post-copy-icon {
  display: none;
}

[data-copy-state="copied"] .post-copy-check {
  display: block;
  color: #a6e3a1;
}

[data-copy-state="failed"] .post-copy-status {
  width: auto;
  height: auto;
  clip-path: none;
  position: absolute;
  inset-block-start: .3rem;
  inset-inline-end: 3.2rem;
  padding: .25rem .45rem;
  border-radius: 4px;
  background: #222;
  color: #d8d8d8;
  font-size: .875rem;
  pointer-events: none;
}

.post-copy-status {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
}

@media (hover: hover) and (pointer: fine) {
  .post-code-copy:not(:hover) .post-copy-button:not(:focus-visible) {
    opacity: 0;
  }
}

@media (min-width: 1400px) {
  .post {
    position: relative;
  }

  .post-outline {
    position: absolute;
    inset-block: 0;
    inset-inline-start: calc(100% + 2rem);
    width: 13rem;
  }

  .post-outline details {
    position: sticky;
    top: 1.25rem;
    max-height: calc(100vh - 2.5rem);
    overflow: auto;
    box-sizing: border-box;
    border: 0;
  }
}
