.toc {
  display: block;
  margin: var(--spacing) 0;
  background-color: var(--lightest);
  border-radius: var(--border-radius);
  border: 1px solid var(--light);
  contain: content;
}

.toc:not([open]) {
  width: fit-content;
}

.toc:not([open]):hover {
  border-color: var(--primary);
}

.toc:not([open]):hover summary {
  color: var(--primary);
}

.toc summary {
  padding: .75em;
  color: var(--dark);
}

.toc summary:hover {
  cursor: pointer;
}

.toc[open] summary .hide,
.toc summary .show {
  display: inline;
}

.toc summary .hide,
.toc[open] summary .show {
  display: none;
}

.intoc {
  padding: 0 1em 1em;
  margin: 0;
  list-style-type: none;
}

.intoc ul {
  margin-left: 1em;
}

.intoc > li {
  margin-bottom: .75em;
}

.intoc ul > li {
  margin-left: 1em;
  padding-left: .5em;
}

.intoc > li > a {
  font-weight: 600;
  margin-bottom: .75em;
}

.intoc a {
  text-wrap: balance;
}

.intoc ul > li::marker {
  content: "\22A2";
  color: var(--medium);
}

.intoc ul > li:has(ul) > a {
  font-weight: 500;
}

@keyframes downarrow {
  0% {
    transform: translateY(0);
    opacity: 0.3;
  }

  100% {
    transform: translateY(0.2em);
    opacity: 1;
  }
}

@media (pointer: fine) {
  .toc a::after {
    content: "\2193";
    display: inline-block;
    margin-left: 0.66em;
    transform-origin: 50% 50%;
    animation: downarrow 0.6s infinite alternate ease-in-out;
    visibility: hidden;
    color: var(--primary);
  }

  .toc a:hover::after {
    visibility: visible;
  }
}
