//
// Figures
//
img {
  box-sizing: border-box;
  max-width: 100%;
  height: auto;
}

article {
  .figure {
    border-radius: 0.2rem;

    padding: 0.5rem;
    :last-child {
      margin-bottom: 0;
    }
  }
  .align-left {
    float: left;
    clear: left;
    margin: 0 1rem 1rem;
  }
  .align-right {
    float: right;
    clear: right;
    margin: 0 1rem 1rem;
  }
  .align-center {
    text-align: center;
    margin-left: 50%;
    transform: translate(-50%);
  }

  .figure.align-default,
  .legend .align-default {
    @extend .align-center;
  }
}

//
// Blockquote
//
blockquote {
  border-left: 1px solid var(--color-foreground-border);
  font-style: italic;
  margin-left: 0.5rem;
  margin-right: 0.5rem;
  padding: 0.5rem 1rem;
}

//
// Code and Literal Blocks
//
// Inspired by mkdocs-material's design.
$code-spacing-vertical: 0.625rem;
$code-spacing-horizontal: 0.875rem;

article {
  // Wraps every literal block + line numbers.
  div[class*=" highlight-"],
  div[class^="highlight-"] {
    margin: 1em 0;
    display: flex;
  }
}

pre {
  margin: 0;
  padding: 0;

  // Needed to have more specificity than pygments' "pre" selector. :(
  article & {
    line-height: 1.5;
  }

  &.literal-block,
  .highlight & {
    font-size: var(--code-font-size);
    padding: $code-spacing-vertical $code-spacing-horizontal;
  }
  // Make it look like all the other blocks.
  &.literal-block {
    overflow: auto;

    margin-top: 1rem;
    margin-bottom: 1rem;

    border-radius: 0.2rem;
    background-color: var(--color-code-background);
    color: var(--color-code-foreground);
  }
}

// All code is always contained in a pre
.highlight {
  flex-grow: 1;
  border-radius: 0.2rem;
  overflow: auto;
}
// Added when there's line numbers associated with a literal block.
.highlighttable {
  width: 100%;
  display: block;
  tbody {
    display: block;
  }
  tr {
    display: flex;
  }
  // Line numbers
  td.linenos {
    background-color: var(--color-code-background);
    color: var(--color-code-foreground);
    padding: $code-spacing-vertical $code-spacing-horizontal;
    padding-right: 0;
    border-top-left-radius: 0.2rem;
    border-bottom-left-radius: 0.2rem;
  }
  .linenodiv {
    font-size: var(--code-font-size);

    padding-right: 0.5rem;
    box-shadow: -0.0625rem 0 var(--color-code-foreground) inset;
    opacity: 0.5; // I hate myself.
  }
  // Actual code
  td.code {
    padding: 0;
    display: block;
    flex: 1;
    overflow: hidden;

    .highlight {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
    }
  }
}

.field-list,
.option-list,
dl.simple,
dl.footnote,
dl.glossary {
  dt {
    display: inline-block;
    margin-top: 0.25rem;
    font-weight: 500;

    .classifier::before {
      content: ":";
      margin-left: 0.2rem;
      margin-right: 0.2rem;
    }
  }

  dd {
    > p:first-child,
    ul {
      margin-top: 0.125rem;
    }
    ul {
      margin-bottom: 0.125rem;
    }
  }
}

// Footnotes
dl.footnote {
  font-size: var(--font-size--small);
  color: var(--color-foreground-secondary);

  display: grid;
  grid-template-columns: max-content auto;
  dt {
    margin: 0;
    > .fn-backref {
      margin-left: 0.25rem;
    }

    &:after {
      content: ":";
    }
    .brackets {
      &:before {
        content: "[";
      }
      &:after {
        content: "]";
      }
    }
  }
}
