/* Webkit Scrollbar Customize */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
    background: $scrollbar-background;
}

::-webkit-scrollbar-thumb {
    background: #888;

    &:hover {
        background: $scrollbar-color;
    }
}

html {
    box-sizing: border-box;
    letter-spacing: 0.06em;
    scroll-behavior: smooth;
}

*,
*:before,
*:after {
    box-sizing: inherit;
    overflow-wrap: anywhere;
    word-break: break-word;
}

body {
    margin: 0;
    padding: 0;
    font-family: "Inter UI", -apple-system, BlinkMacSystemFont, "Roboto",
        "Segoe UI", Helvetica, Arial, sans-serif;
    font-display: auto;
    font-size: 1rem;
    line-height: 1.54;
    background-color: $light-background;
    color: $light-color;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "liga", "tnum", "case", "calt", "zero", "ss01",
        "locl";
    -webkit-overflow-scrolling: touch;
    -webkit-text-size-adjust: 100%;

    display: flex;
    min-height: 100vh;
    flex-direction: column;

    @media #{$media-size-phone} {
        font-size: 1rem;
    }

    &.dark-theme {
        background-color: $dark-background;
        color: $dark-color;
    }
}

h2,
h3,
h4,
h5,
h6 {
    display: flex;
    align-items: center;
    line-height: 1.3;
}

h1 {
    font-size: 2.625rem;
}

h2 {
    font-size: 1.625rem;
}

h3 {
    font-size: 1.375rem;
}

h4 {
    font-size: 1.125rem;
}

h5 {
    font-size: 1.075rem;
    margin: 1em 0;
}

h6 {
    font-size: 1rem;
    margin: 1em 0;
}

@media #{$media-size-phone} {
    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.4rem;
    }

    h3 {
        font-size: 1.15rem;
    }

    h4 {
        font-size: 1.125rem;
    }

    h5 {
        font-size: 1.075rem;
    }

    h6 {
        font-size: 1rem;
    }
}

a {
    color: inherit;
}

img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;

    &.left {
        margin-right: auto;
    }

    &.center {
        margin-left: auto;
        margin-right: auto;
    }

    &.right {
        margin-left: auto;
    }

    &.circle {
        border-radius: 50%;
        max-width: 25%;
        margin: auto;
    }
}

figure {
    display: table;
    max-width: 100%;
    margin: 1em 0;

    img {
        border-radius: 8px;
        padding: 5px;

        .dark-theme & {
            background-color: $dark-image-border;
        }
    }

    picture {
        max-height: 100%;
        max-width: 100%;
    }

    &.left {
        margin-right: auto;
    }

    &.left-floated {
        margin-right: auto;
        float: left;

        img {
            margin: 20px 20px 20px 0;
        }
    }

    &.center {
        margin-left: auto;
        margin-right: auto;
    }

    &.right {
        margin-left: auto;
    }

    &.right-floated {
        margin-left: auto;
        float: right;

        img {
            margin: 20px 0 20px 20px;
        }
    }

    &.rounded {
        img {
            border-radius: 50%;
        }
    }

    figcaption {
        font-size: 1.125rem;
        line-height: 1.3;
        margin-top: 0.4em;
        opacity: 0.8;
        vertical-align: middle;

        span {
            vertical-align: middle;
        }

        &.left {
            text-align: left;
        }

        &.center {
            text-align: center;
        }

        &.right {
            text-align: right;
        }

        .figcaption {
            &__title {
                font-weight: bold;
            }

            &__attr {
                font-size: 0.7em;

                svg {
                    margin-right: 0.3em;
                }
            }
        }
    }

    &.small {
        max-width: 300px;
        width: 90%;
        margin: 5px 0;
    }

    &.inline {
        display: inline-table;
    }

    &.floated-focus {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        max-width: unset;
        height: 100vh;
        padding: 3rem;
        margin: 0;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        background-color: transparentize(darken($dark-background, 5%), 0.08);
        z-index: 10000;

        picture {
            max-height: 90%;
        }

        figcaption {
            color: $dark-color;
            font-size: 1.5rem;
        }

        &:after {
            content: "Close";
            margin-top: 1rem;
            text-decoration: underline;
            cursor: pointer;
            display: block;
            color: transparentize($dark-color, 0.43);
        }
    }
}

code {
    font-family: Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace;
    font-display: auto;
    font-feature-settings: normal;
    background: $light-background-secondary;
    padding: 1px 6px;
    margin: 0 2px;
    border-radius: 5px;
    font-size: 0.95rem;
    word-wrap: break-word;

    .dark-theme & {
        background: $dark-background-secondary;
    }
}

pre {
    // background: #212020;
    padding: 10px 10px 10px 20px;
    border-radius: 8px;
    font-size: 0.95rem;
    overflow: auto;

    @media #{$media-size-phone} {
        white-space: pre-wrap;
        word-wrap: break-word;
    }

    code {
        background: none !important;
        color: #ccc;
        margin: 0;
        padding: 0;
        font-size: inherit;

        .dark-theme & {
            color: inherit;
        }
    }
}

blockquote {
    position: relative;
    border-left: 2px solid;
    margin: 20px 40px;
    padding: 10px 20px;

    @media #{$media-size-phone} {
        margin: 10px 10px 10px 25px;
        padding: 10px;
    }

    &:before {
        content: "”";
        // font-family: Georgia, serif;
        font-display: auto;
        font-size: 3.875rem;
        position: absolute;
        left: -40px;
        top: -13px;

        @media #{$media-size-phone} {
            left: -27.5px;
            top: -7px;
            font-size: 3.075rem;
        }
    }

    p:first-of-type {
        margin-top: 0;
    }

    p:last-of-type {
        margin-bottom: 0;
    }
}

ul,
ol {
    margin-left: 40px;
    padding: 0;

    @media #{$media-size-phone} {
        margin-left: 20px;
    }
}

ol ol {
    list-style-type: lower-alpha;
}

.container {
    flex: 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
}

.content {
    display: flex;
    flex-direction: column;
    flex: 1 auto;
    align-items: center;
    justify-content: center;
    margin: 0;

    @media #{$media-size-phone} {
        margin-top: 0;
    }

    &-list {
        display: block;
    }
}

hr {
    width: 100%;
    border: none;
    background: $light-border-color;
    height: 1px;

    .dark-theme & {
        background: $dark-border-color;
    }
}

svg {
    height: 1em;
}

.hidden {
    display: none !important;
}

.hide-on-phone {
    @media #{$media-size-phone} {
        display: none;
    }
}

.hide-on-tablet {
    @media #{$media-size-tablet} {
        display: none;
    }
}

// Accessibility
.screen-reader-text {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute !important;
    width: 1px;
    word-wrap: normal !important;
}

.screen-reader-text:focus {
    background-color: $screen-reader-text-background;
    border-radius: 3px;
    box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.6);
    clip: auto !important;
    clip-path: none;
    color: $screen-reader-text-color;
    display: block;
    font-size: 14px;
    font-size: 0.875rem;
    font-weight: bold;
    height: auto;
    width: auto;
    top: 5px;
    left: 5px;
    line-height: normal;
    padding: 15px 23px 14px;
    text-decoration: none;
    z-index: 100000;
}

// Custom
.socials {
    user-select: none;

    svg {
        font-size: 1.5rem;
    }
}

table {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    font-size: 0.95rem;
    background: $light-background-secondary;

    th {
        padding: 8px 8px;

        word-break: normal;
        overflow-wrap: normal;
    }

    td {
        padding: 6px 8px;

        border-top: 1px solid $light-color-secondary;
    }

    .dark-theme & {
        background: $dark-background-secondary;

        td {
            border-top-color: $dark-color-secondary;
        }
    }
}

.feather {
    display: inline-block;
    vertical-align: -0.125em;
    width: 1em;
    height: 1em;
}

.nostyle {
    text-decoration: none;
}

.breadcrumbs {
    display: inline;

    ol {
        list-style-type: none;
        margin: 0;
        display: inline;

        li {
            display: inline;

            &::after {
                content: " > ";
            }
        }
    }
}

.article-heading {
    a {
        position: relative;
        text-decoration: none;

        @mixin link-image($color) {
            $color: "rgb(" + red($color) + "," + green($color) + "," +
                blue($color) + ")";

            --background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#{$color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>');
        }

        @include link-image($light-color);

        .dark-theme & {
            @include link-image($dark-color);
        }

        &.current-heading {
            --background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="rgb(0, 128, 0)" stroke-width="4" stroke-linecap="round" stroke-linejoin="round" class="feather feather-check"><polyline points="20 6 9 17 4 12"></polyline></svg>');
        }

        &:hover {
            &::before {
                content: " ";
                display: inline-block;
                position: absolute;
                top: 50%;
                transform: translateY(-50%);
                height: 100%;

                background-image: var(--background-image);
                background-repeat: no-repeat;
                background-position: center;
                background-size: auto 50%;
            }
        }

        @media #{$media-size-tablet-min} {
            &:hover {
                &::before {
                    right: 100%;
                    width: 1.5em;
                }
            }
        }

        @media #{$media-size-tablet} {
            &:hover {
                &::before {
                    left: 100%;
                    width: 1.2em;
                }
            }
        }
    }
}

.highlight {
    position: relative;
    border-radius: 8px;
    margin: 0.95em 0;
    overflow: hidden;

    pre {
        padding-left: 0;
        padding-right: 0;
        margin: 0;

        .line {
            padding-left: 20px;
            padding-right: 40px;
        }
    }

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

    table {
        width: 100% !important;
        display: block;
        background: inherit;
        position: relative;
        border-radius: 0;
        font-size: inherit;

        tbody {
            display: block;

            tr {
                display: flex;
                flex-direction: row;

                td {
                    overflow-wrap: anywhere;
                    word-break: normal;
                    width: 1px; // flex will override

                    pre {
                        margin: 0;

                        @media #{$media-size-phone} {
                            white-space: pre;
                        }
                    }

                    &:first-of-type {
                        // line numbers
                        flex: 0 0 max-content;

                        .lnt {
                            padding-left: 14px;
                            padding-right: 14px;
                            margin-right: 0;
                        }
                    }

                    &:last-of-type {
                        // code
                        flex: 1 1 auto;

                        pre {
                            padding-left: 0px;
                        }
                    }
                }
            }
        }
    }

    .codeblock-copy {
        @mixin code-copy-background($color) {
            $color: "rgb(" + red($color) + "," + green($color) + "," +
                blue($color) + ")";

            background-image: url('data:image/svg+xml;utf8, <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#{$color}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-copy"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>');
        }

        position: absolute;
        top: 10px;
        right: 10px;
        display: block;
        width: 26px;
        height: 26px;
        border: none;
        padding: 0;
        margin: 0;
        border-radius: 6px;
        background: none;
        background-color: inherit;

        @include code-copy-background(#adadad);

        background-repeat: no-repeat;
        background-position: center;
        background-size: auto 65%;

        &.current-code {
            --selected-code-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="rgb(52, 184, 0)" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" class="feather feather-check"><polyline points="20 6 9 17 4 12"></polyline></svg>');

            background-image: var(--selected-code-image);

            &:hover {
                background-image: var(--selected-code-image);
            }
        }

        &:hover {
            @include code-copy-background(#ffffff);
        }
    }
}

#toc {
    &.desktop-only {
        display: none;
    }

    .toc-title {
        display: flex;
        align-items: center;
        font-weight: bold;
        font-size: 1.625rem;
        line-height: 1.3;
        margin: 0.83em 0;
    }

    ul,
    ol {
        li::marker {
            content: "- ";
        }
    }

    @media (min-width: 1840px) {
        display: block !important;
        position: absolute;
        top: 100vh;
        height: calc(100% - 100vh - 380px);

        .toc-content {
            position: sticky;
            top: 10vh;
            height: 70vh;
            margin-bottom: -2em;
            margin-left: calc(-300px - 100px);
            display: flex !important;
            flex-direction: column;
            width: 300px;
            right: calc(100% + 100px);

            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
                background: darken($light-background, 10%);
                border-radius: 8px;
            }

            ::-webkit-scrollbar-thumb {
                background: darken($light-background, 25%);
                border-radius: 8px;

                &:hover {
                    background: darken($light-background, 40%);
                }
            }

            .dark-theme & {
                ::-webkit-scrollbar {
                    background: lighten($dark-background, 10%);
                }

                ::-webkit-scrollbar-thumb {
                    background: lighten($dark-background, 25%);

                    &:hover {
                        background: lighten($dark-background, 40%);
                    }
                }
            }

            .toc-title {
                font-size: 1.375rem;
                min-height: calc(1.625rem * 1.3);
                margin: 0;
            }

            nav {
                overflow-y: auto;
                margin-top: 1em;
            }

            a {
                display: block;
                text-decoration: none;
                padding: 5px;
                border-radius: 8px;

                &:hover {
                    background: darken($light-background, 10%);

                    .dark-theme & {
                        background: lighten($dark-background, 10%);
                    }
                }

                &.current-toc {
                    background: darken($light-background, 10%);

                    .dark-theme & {
                        background: lighten($dark-background, 10%);
                    }
                }

                &::before {
                    content: "- ";
                }
            }

            ul,
            ol {
                margin: 0;
                padding: 0;

                li::marker {
                    content: "";
                }

                li a {
                    padding-left: 20px;
                }
                li li a {
                    padding-left: 40px;
                }
                li li li a {
                    padding-left: 60px;
                }
            }
        }
    }
}