@import (reference) './variables.less';

.markdown {
  color: @c-text;
  font-size: 14px;
  line-height: 1.8;

  [data-prefers-color='dark'] & {
    color: @c-secondary-dark;
  }

  &:not(:first-child):empty {
    min-height: 32px;
  }

  // titles
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    margin-top: calc(3em - 30px);
    margin-bottom: 18px;
    color: @c-heading;
    font-weight: 500;
    line-height: 1.40625;
    position: relative;

    [data-prefers-color='dark'] & {
      color: @c-heading-dark;
    }

    // anchor link
    &:hover > a[aria-hidden] {
      float: left;
      margin-left: -1.3em;
      width: 0.8em;
      padding-left: 0.5em;
      line-height: 1.15;
      box-sizing: border-box;

      @media @mobile {
        width: 14px;
        margin-left: -14px;
      }

      &::after {
        content: '#';
        display: inline-block;
        vertical-align: middle;
        width: 1em;
      }

      span {
        display: none;
      }
    }

    + h1,
    + h2,
    + h3,
    + h4,
    + h5,
    + h6 {
      margin-top: 16px;
    }
  }

  h1 {
    margin-top: 32px;
    margin-bottom: 32px;
    font-size: 30px;
  }

  h2 {
    font-size: 24px;
    padding-bottom: 6px;
  }

  h3 {
    font-size: 18px;
  }

  h4 {
    font-size: 16px;
  }

  h5 {
    font-size: 15px;
  }

  h6 {
    font-size: 14px;
  }

  // paragraph
  p {
    margin: 16px 0;
  }

  strong {
    border-bottom: solid #ffe7b2 4px;
    font-weight: 600;
  }

  // inline code
  *:not(pre) code {
    padding: 2px 5px;
    color: @c-text;
    background: @c-light-bg;
    border-radius: 4px;

    [data-prefers-color='dark'] & {
      color: #ff7875;
      background: @c-light-bg-dark;
    }
  }

  code {
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas,
      'Liberation Mono', monospace;
    font-size: 14px;
  }

  // code block
  pre {
    font-size: 14px;
    background: @c-light-bg;

    &:not([class^='language-']) {
      padding: 1em;
    }
  }

  // horizontal line
  hr {
    margin: 16px 0;
    border: 0;
    border-top: 1px solid var(--doc-border-color);
  }

  // blockquote
  blockquote {
    margin: 16px 0;
    padding: 0 24px;
    color: fadeout(@c-text, 30%);
    border-left: 4px solid var(--doc-border-color);
    overflow: hidden;

    [data-prefers-color='dark'] & {
      color: fadeout(@c-text-dark, 30%);
    }
  }

  // list
  ul,
  ol {
    margin: 8px 0 8px 32px;
    padding: 0;

    li {
      margin-bottom: 4px;
    }
  }

  .__dumi-default-table-content {
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--doc-border-color);
  }

  // table
  table {
    width: 100%;
    border-collapse: collapse;
    [data-prefers-color='dark'] & {
      border: 1px solid #3b434b;
    }

    th,
    td {
      padding: 10px 24px;
      border: 1px solid @c-border-inner;

      [data-prefers-color='dark'] & {
        border: 1px solid #3b434b;
      }
    }

    th {
      font-weight: 600;
      background: @c-light-bg;

      [data-prefers-color='dark'] & {
        background: @c-light-bg-dark;
      }
    }

    td:first-child {
      font-weight: 500;
    }
    thead th {
      border-top: none;
    }
    tr:last-child td {
      border-bottom: none;
    }
    tr td:first-child,
    tr th:first-child {
      border-left: none;
    }
    tr td:last-child,
    tr th:last-child {
      border-right: none;
    }
  }

  // links
  a {
    color: @c-link;
    text-decoration: none;
    transition: opacity 0.2s;
    outline: none;

    [data-prefers-color='dark'] & {
      color: @c-primary-dark;
    }

    &:hover {
      opacity: 0.7;
      text-decoration: underline;
    }

    &:active {
      opacity: 0.9;
    }
  }

  // images
  img {
    max-width: 100%;
  }
}

.@{prefix} {
  &-external-link-icon {
    vertical-align: -0.155em;
    margin-left: 2px;
  }
}

// For demo
[data-prefers-color='dark'] {
  h1,
  h2,
  h3,
  h4 {
    color: @c-heading-dark;
  }
}
