*:not(pre) > code {
  font-family: var(--site-code-fontFamily);
  font-size: 0.9em;
  line-height: 1.25em;
  padding: 0.1rem 0.25rem;
  background-color: var(--site-inset-bgColor-translucent);
  border: 1px solid var(--site-inset-borderColor);
  border-radius: 0.25rem;
  word-wrap: break-word;
  white-space: nowrap;
}

pre {
  margin: 0 0 1rem;
  font-size: 0.9375rem;
  font-weight: 400;
  padding: 1.25rem;

  code {
    white-space: pre;
    font-family: var(--site-code-fontFamily);
  }

  a {
    font-family: inherit;
    font-weight: inherit;
  }

  .highlight {
    background: var(--site-code-highlight-bgColor);
    padding: 0.1em;
  }

  .highlight-diagnostics & {
    .highlight {
      border-bottom: 2px #F44336 dashed;
      background: inherit;
      padding: 0;
    }
  }

  &:focus {
    outline: none;
  }

  span.line {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
    width: 100%;
    display: inline-block;
    min-width: 100%;
    border-left: 2px solid rgba(0, 0, 0, 0);

    &.highlighted-line {
      background: var(--site-primary-color-highlight);
      border-left-color: var(--site-primary-color);
      min-width: 100%;
    }
  }

  &.show-line-numbers code {
    span.line {
      padding-left: 0.5rem;

      &[data-line]::before {
        display: inline-block;
        content: attr(data-line) "";
        width: 2em;
        margin-right: 0.5rem;
        text-align: right;
        color: var(--site-base-fgColor-alt);
      }
    }
  }
}

.code-copy-button {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 10;

  width: 2rem;
  height: 2rem;
  padding: 0;

  font: 24px / 1 var(--site-icon-fontFamily);

  appearance: none;
  border: none;
  color: var(--site-base-fgColor-alt);
  background: none;
  opacity: 0;
  transition: opacity 0.4s;

  &:hover, &:focus {
    color: var(--site-link-fgColor);
    opacity: 1;
    outline: none;
  }

  &:active {
    color: var(--site-link-fgColor-active);
  }
}

.code-block-language {
  font-family: var(--site-code-fontFamily);
  user-select: none;
  font-size: 0.8125rem;
  color: var(--site-base-fgColor-alt);
  opacity: 1;
  transition: opacity 0.25s;

  position: absolute;
  top: 3px;
  right: 6px;
  z-index: 5;

  .highlight-languages .language-dart & {
    color: var(--site-primary-color);
  }

  .highlight-languages .language-js & {
    color: #f1a85a;
  }

  .highlight-languages .language-swift & {
    color: #f05137;
  }

  .highlight-languages :not(.has-tag) & {
    font-size: 0.875rem;
    left: 6px;
    right: unset;
  }
}

.code-block-tag {
  font-family: var(--site-code-fontFamily);
  font-size: 0.8125rem;
  font-weight: 500;
  position: absolute;
  top: 3px;
  left: 6px;

  .tag-good &, .tag-passes-sa &, .tag-runtime-success & {
    color: var(--site-alert-tip-color);
  }

  .tag-bad &, .tag-fails-sa &, .tag-runtime-fail & {
    color: var(--site-alert-error-color);
  }
}

.code-block-wrapper {
  margin-block-start: 1rem;
  margin-block-end: 1rem;
  border: 1px solid var(--site-inset-borderColor);
  background-color: var(--site-inset-bgColor);

  .code-block-header {
    background-color: var(--site-raised-bgColor);
    border-bottom: 1px solid var(--site-inset-borderColor);
    font-size: 0.9375rem;
    font-weight: 500;
    padding: 0.75rem 0.5rem 0.67rem 1rem;
  }

  .code-block-body {
    position: relative;
    background: none;

    &:hover, &:focus-within {
      .code-block-language {
        opacity: 0;
      }

      .code-copy-button {
        opacity: 1;
      }
    }

    // TODO(parlough): Consider bringing some background highlighting back.
    //&.tag-good, &.tag-passes-sa, &.tag-runtime-success {
    //  background-color: #f1fbf9;
    //}
    //
    //&.tag-bad, &.tag-fails-sa, &.tag-runtime-fail {
    //  background-color: #fef3f6;
    //}
  }

  &:has(:focus-visible) {
    border-color: var(--site-primary-color);
  }

  pre {
    margin-bottom: 0;
    padding-right: 0;
    padding-left: 0;
    overflow-x: scroll;

    &:not([lang="console"]) {
      line-height: 1.8;
    }

    code {
      display: block;
      min-width: fit-content;
      width: 100%;
    }
  }
}

// Border and resizability for dartpad
iframe[src^="https://dartpad"]:not(#try-dart-pad) {
  border: 1px solid var(--site-inset-borderColor);
  margin: 0;
  min-height: 400px;
  resize: vertical;
  width: 100%;
}
