@use '../core' as *;

$vertical-padding: $spacing-size-2;
$blog-code-selector: '.post-full pre[class*="language-"]';

pre.code,
#{$blog-code-selector},
pre.code code,
#{$blog-code-selector} code {
    color: black;
    background: none;
    text-align: left;
    white-space: pre;
    word-spacing: normal;
    word-break: normal;
    word-wrap: normal;
    line-height: 1.5;

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

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

    #{$selector-darkmode} & {
        -webkit-font-smoothing: antialiased;

        color: var(--color-fg-primary);
    }
}

pre.code,
#{$blog-code-selector} {
    position: relative;
    margin-top: $spacing-size-5;
    margin-bottom: $spacing-size-5;
    padding: 0;
    border: 1px solid color-mix(in srgb, var(--color-border-secondary), var(--color-border-primary));
    background-color: var(--color-code-background);
    overflow: hidden;

    #{$selector-darkmode} & {
        color-scheme: dark;
    }
}

pre.code > code,
#{$blog-code-selector} > code {
    display: block;
    width: 100%;
    padding: $vertical-padding + 2px $spacing-size-4 $vertical-padding;
    border: none;
    font-size: 15px;
    overflow: hidden;
    overflow-x: auto;
    font-weight: 400;
}

pre.code > .language-bash,
#{$blog-code-selector} > .language-bash {
    color: var(--color-code-function);
}

pre.code.line-numbers.line-numbers code,
#{$blog-code-selector}.line-numbers.line-numbers code {
    padding-left: 3.8em;
}

pre.code.line-numbers.line-numbers .line-numbers-rows,
#{$blog-code-selector}.line-numbers.line-numbers .line-numbers-rows {
    left: 0;
}

pre.code[data-line],
#{$blog-code-selector}[data-line] {
    padding-top: 0;
    padding-bottom: 0;
    padding-left: 0;
}

pre[data-line] code,
#{$blog-code-selector}[data-line] code {
    position: relative;
    padding-left: 4em;
}

pre.code .line-highlight,
#{$blog-code-selector} .line-highlight {
    margin-top: 0;
}

pre.code.line-numbers,
#{$blog-code-selector}.line-numbers {
    position: relative;
    counter-reset: linenumber;
}

pre.code.line-numbers > code,
#{$blog-code-selector}.line-numbers > code {
    position: relative;
    white-space: inherit;
    height: 100%;
    overflow: auto;
}

.line-numbers .line-numbers-rows {
    position: absolute;
    pointer-events: none;
    top: 0;
    min-height: 100%;
    padding-top: $vertical-padding;
    font-size: 100%;
    left: -3.8em;
    width: 3em;
    letter-spacing: -1px;

    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.line-numbers-rows > span {
    display: block;
    counter-increment: linenumber;
}

.line-numbers-rows > span:before {
    content: counter(linenumber);
    display: block;
    padding-right: 0.8em;
    text-align: right;
}

.copy-to-clipboard {
    overflow: hidden;

    > code {
        max-width: 100%;
    }
}

// Theme colors
// ============
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
    color: var(--color-code-comment);
    font-style: italic;
}

.token.namespace {
    opacity: 0.7;
}

.token.string {
    color: var(--color-code-string);
}

.token.punctuation,
.token.operator {
    color: var(--color-code-punctuation);
}

.token.url,
.token.symbol,
.token.number,
.token.boolean,
.token.variable,
.token.constant,
.token.inserted {
    color: var(--color-code-symbol);
}

.token.atrule,
.token.keyword,
.token.attr-value,
.language-autohotkey .token.selector,
.language-json .token.boolean,
.language-json .token.number,
code[class*='language-css'] {
    color: var(--color-code-keyword);
}

.token.function {
    color: var(--color-code-function);
}

.token.deleted,
.language-autohotkey .token.tag {
    color: var(--color-code-deleted);
}

.token.important {
    color: var(--color-code-important);
}

.token.important,
.token.bold {
    font-weight: bold;
}

.token.italic {
    font-style: italic;
}

.token.class-name,
.token.builtin,
.language-json .token.property {
    color: var(--color-code-class-name);
}

.token.tag {
    color: var(--color-code-tag);
}

.token.selector {
    color: var(--color-code-selector);
}

.token.attr-name,
.token.property,
.token.regex,
.token.entity {
    color: var(--color-code-property);
}

.language-css .token.property {
    color: var(--color-code-tag);
}

.language-bash {
    .token.function {
        color: var(--color-fg-primary);
        font-weight: 600;
    }
}

.token.atrule,
.token.attr-name,
.token.attr-value,
.token.boolean,
.token.builtin,
.token.cdata,
.token.class-name,
.token.comment,
.token.constant,
.token.deleted,
.token.doctype,
.token.entity,
.token.inserted,
.token.keyword,
.token.namespace,
.token.number,
.token.operator,
.token.prolog,
.token.property,
.token.regex,
.token.selector,
.token.string,
.token.symbol,
.token.tag,
.token.url,
.token.variable {
    #{$selector-darkmode} & {
        -webkit-font-smoothing: subpixel-antialiased;
    }
}

.line-numbers .line-numbers-rows {
    border-right: 1px solid var(--color-util-brand-100);

    #{$selector-darkmode} & {
        border-right-color: var(--color-border-secondary);
    }
}

.line-numbers-rows > span:before {
    color: var(--color-util-brand-500);
    opacity: 0.33;

    #{$selector-darkmode} & {
        color: var(--color-fg-primary);
    }
}

.code-block-homepage {
    pre {
        background-color: #111a4a;
    }
    .line-numbers-rows {
        border-right: none;
    }
    .line-numbers-rows > span:before {
        color: rgba(255, 255, 255, 0.9);
    }

    code {
        color: rgba(255, 255, 255, 0.9) !important;
    }

    .token.tag {
        // var(--color-code-tag) //
        color: rgba(255, 255, 255, 0.9);
    }

    .token.comment,
    .token.prolog,
    .token.doctype,
    .token.cdata {
        // var(--token-comment) //
        color: rgba(255, 255, 255, 0.417);
        font-style: italic;
    }

    .token.url,
    .token.symbol,
    .token.number,
    .token.boolean,
    .token.variable,
    .token.constant,
    .token.inserted {
        // var(--color-code-symbol) //
        color: #7dd3fc;
    }

    .token.attr-name,
    .token.property,
    .token.regex,
    .token.entity {
        // var(--token-property) //
        color: #a2a6ba;
    }

    .token.deleted,
    .language-autohotkey .token.tag {
        // var(--color-code-deleted) //
        color: #81869f;
    }

    .token.class-name,
    .token.builtin,
    .language-json .token.property {
        // var(--class-name-color //
        color: #f472b6;
    }

    .token.atrule,
    .token.keyword,
    .token.attr-value,
    .language-autohotkey .token.selector,
    .language-json .token.boolean,
    .language-json .token.number,
    code[class*='language-css'] {
        // var(--color-code-keyword) //
        color: #f472b6;
    }

    .token.punctuation,
    .token.operator {
        // var(--color-code-punctuation) //
        color: #81869f;
    }

    .token.string {
        // var(--color-code-string) //
        color: #7dd3fc;
    }
}
