@use 'sass:color';

@import '_variables';

// ===============================
// Forked and modified from prismjs/themes/prism-tomorrow.css

code[class*='language-'],
pre.shiki {
  background: none;
  font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
  text-align: left;
  white-space: pre;
  word-spacing: normal;
  word-break: normal;
  word-wrap: normal;
  line-height: 1.4;

  -moz-tab-size: 4;
  -o-tab-size: 4;
  tab-size: 4;

  -webkit-hyphens: none;
  -moz-hyphens: none;
  -ms-hyphens: none;
  hyphens: none;
}

/* Code blocks */
pre.shiki {
  padding: 2.2rem 1rem 1rem;
  margin: 0;
  vertical-align: middle;
  border-radius: 0.25rem;
  overflow: auto;

  code {
    padding: 0;
    background-color: transparent;
    border-radius: 0;
    -webkit-font-smoothing: auto;
    -moz-osx-font-smoothing: auto;
  }
}

/* Inline code */
:not(pre) > code[class*='language-'] {
  padding: 0.1em;
  border-radius: 0.3em;
  white-space: normal;
}

.line-number {
  font-family: var(--code-font-family);
}

div[class*='language-'] {
  display: flex;
  flex-direction: row-reverse;
  justify-content: left;
  position: relative;
  background-color: var(--block-code-bg-color);
  border-radius: 0.25rem;

  &::before {
    position: absolute;
    z-index: 3;
    top: 0.8em;
    right: 1em;
    font-size: 0.85rem;
  }

  &::after {
    content: '';
    position: absolute;
    top: 12px;
    left: 1rem;
    width: 12px;
    height: 12px;
    background: #f95c5b;
    border-radius: 100%;
    box-shadow: 0 0 0 1px #da3d42, 22px 0 0 0 #fabe3b, 22px 0 0 1px #ecb03e,
      44px 0 0 0 #38cd46, 44px 0 0 1px #2eae32;
    z-index: 10;
  }

  pre {
    // force override the background color to be compatible with shiki
    background: transparent !important;
    position: relative;
    z-index: 1;
  }

  .highlight-lines {
    user-select: none;
    position: absolute;
    top: 2.25rem;
    left: 0;
    width: 100%;
    line-height: 1.4;

    .highlight-line {
      background-color: var(--highlight-line-bg-color);
    }
  }

  &:not(.line-numbers-mode) {
    .line-numbers {
      display: none;
    }
  }

  &.line-numbers-mode {
    pre {
      padding-left: 0;
    }

    .highlight-lines .highlight-line {
      position: relative;

      &::before {
        content: ' ';
        position: absolute;
        z-index: 2;
        left: 0;
        top: 0;
        display: block;
        width: 2.6rem;
        height: 100%;
      }
    }

    .line-numbers {
      width: 2.6rem;
      text-align: center;
      color: #908f8f;
      padding: 2.2rem 0.5rem 1rem 0.5rem;
      line-height: 1.4;
      counter-reset: line-number;

      br {
        user-select: none;
      }

      .line-number {
        position: relative;
        z-index: 3;
        user-select: none;

        &::before {
          counter-increment: line-number;
          content: counter(line-number);
          font-size: 0.85em;
        }
      }
    }
  }
}

@each $lang in $codeLang {
  div[class*='language-'].ext-#{$lang} {
    &:before {
      content: '' + $lang;
      color: #6a6c6d;
    }
  }
}

// less than 576px
@media (max-width: ($portraitPhone - 0.02px)) {
  div[class*='language-'] {
    margin: 0.85rem -1rem;
    border-radius: 0;
  }
}
