@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap');

:root {
    --surface-base-rgb:               18, 18, 18;
    --DEV_surface-base-rgb:     rgb(18, 18, 18);
    --surface-raised-rgb:             30, 30, 30;
    --DEV_surface-raised-rgb:   rgb(30, 30, 30);
    
    --text-primary-rgb:               224, 224, 224;
    --DEV_text-primary-rgb:     rgb(224, 224, 224);
    --text-secondary-rgb:             153, 153, 153;
    --DEV_text-secondary-rgb:   rgb(153, 153, 153);
    --text-bright-rgb:                255, 255, 255; 
    --DEV_text-bright-rgb:      rgb(255, 255, 255);

    --theme-accent-rgb:               230, 57, 70;
    --DEV_theme-accent-rgb:     rgb(230, 57, 70);
    
    --border-base-rgb:            42, 18, 21;
    --DEV_border-base-rgb:  rgb(42, 18, 21);
    --border-highlight-rgb:           230, 57, 71;
    --DEV_border-highlight-rgb: rgb(230, 57, 71);

    --code-surface-rgb:           26, 26, 26;
    --DEV_code-surface-rgb: rgb(26, 26, 26);
    --code-block-rgb:             12, 12, 12;
    --DEV_code-block-rgb:   rgb(12, 12, 12);
    
    --palette-table-head:   rgb(42, 42, 42);
    --palette-table-stripe: rgb(26, 25, 25);

    --bg-page:                rgb(var(--surface-base-rgb));
    --bg-sidebar:             rgb(var(--surface-raised-rgb));
    --bg-overlay:           rgba(0, 0, 0, 0.5);

    --font-main:              rgb(var(--text-primary-rgb));
    --font-muted:             rgb(var(--text-secondary-rgb));
    --font-heading:           rgb(var(--text-bright-rgb));

    --link-std:               var(--font-heading);
    --link-hover:             rgb(var(--theme-accent-rgb));
    --link-active-bg:         rgba(var(--theme-accent-rgb), 0.12);

    --scroll-track:           rgb(var(--surface-base-rgb));
    --scroll-thumb:           rgba(var(--theme-accent-rgb), 0.25);
    --scroll-thumb-hover:     rgba(var(--theme-accent-rgb), 1);

    --border-std:             rgb(var(--border-base-rgb));
    --border-focus:           rgba(var(--border-highlight-rgb), 0.83);
    
    --btn-hover-bg:           rgba(var(--text-bright-rgb), 0.08);
    --btn-active-bg:          rgba(var(--text-bright-rgb), 0.15);
    
    --code-inline-bg:         rgb(var(--code-surface-rgb));
    --pre-block-bg:           rgb(var(--code-block-rgb));
    --pre-border:           rgb(10, 10, 10);
    --pre-text-color:       rgb(230, 230, 230);

    --quote-bg: rgba(var(--theme-accent-rgb), 0.04);
    --highlight-flash: rgba(var(--theme-accent-rgb), 0.15);

    --table-head-bg: var(--palette-table-head);
    --table-stripe-bg: var(--palette-table-stripe);
    --table-border: var(--border-std);

    --radius-card: 12px;
    --font-stack: "JetBrains Mono", Consolas, Monaco, monospace;
    --gap-std: 8px;
    --sidebar-width: clamp(250px, 17vw, 400px);

    --text-inside-margin: 1rem;
    
    --z-header: 100;
    --z-overlay: 150;
    --z-sidebar: 200;
}

* {
    box-sizing: border-box;
}

@supports not selector(::-webkit-scrollbar) {
    * {
        scrollbar-width: thin;
        scrollbar-color: var(--scroll-thumb) var(--scroll-track);
    }
}

::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: var(--scroll-track);
}

::-webkit-scrollbar-thumb {
    background-color: var(--scroll-thumb);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--scroll-thumb-hover); 
}

html {
    min-width: 100%;
    min-height: 100%;
    font-size: 15px;
    overflow: hidden;

    @media (min-width: 1200px) {
        font-size: 17px;
    }
}

body {
    font-family: var(--font-stack);
    background: var(--bg-page);
    color: var(--font-main);
    gap: var(--gap-std);
    display: flex;
    margin: 0;
    height: 100dvh;
    overflow: hidden;

    @media (min-width: 1200px) {
        padding-top: 0;
    }

    &.sidebar-open {
        overflow: hidden;

        &::after {
            content: "";
            position: fixed;
            inset: 0;
            backdrop-filter: blur(2px) brightness(0.7);
            background: var(--bg-overlay);
            z-index: var(--z-overlay);
            animation: fadein .3s;

            @media (min-width: 1200px) {
                opacity: 0;
                pointer-events: none;
            }
        }
        
        main { transform: scale(0.94); }
    }
}

:focus-visible {
    outline: 2px solid var(--link-hover);
    outline-offset: 2px;
}

.hidden { display: none !important; }

@keyframes fadein {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes avatarGlow {
    0%   { box-shadow: 0 0 2px  2px var(--border-focus); }
    70%  { box-shadow: 0 0 15px 2px var(--border-focus); }
    100% { box-shadow: 0 0 2px  2px var(--border-focus); }
}

@keyframes skeleton-loading {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.skeleton-loader {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 2rem;
    width: 100%;
}

.toc-skeleton {
    margin-top: 0.5rem;
    gap: 0.8rem;
    
    .skeleton { height: 12px; }
}

.skeleton {
    background: linear-gradient(90deg, 
        var(--bg-sidebar) 0%, 
        var(--border-std) 50%, 
        var(--bg-sidebar) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-out infinite;
    border-radius: 4px;
}

.skeleton-h1 { height: 40px; width: 70%; margin-bottom: 1rem; }
.skeleton-text { height: 16px; width: 100%; }
.skeleton-text.extrashort { width: 20%; }
.skeleton-text.short { width: 40%; }
.skeleton-text.mid { width: 60%; }
.skeleton-text.large { width: 80%; }
.skeleton-img { height: 200px; width: 100%; border-radius: var(--radius-card); }


header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    background: var(--bg-page);
    z-index: var(--z-header);
    border-bottom: 1px solid var(--border-std);
    transition: transform 0.3s ease-in-out;

    &::after {
        content: "";
        position: absolute;

        top: 100%; 
        left: 0;

        height: 3px;
        width: var(--progress-width);
        background: var(--link-hover);
        
        transition: width 0.1s linear;
        z-index: 200;
        pointer-events: none;
    }

    &.header-hidden {
        transform: translateY(-100%);
    }

    button {
        background: none;
        border: none;
        color: var(--font-heading);
        font-size: 1.5rem;
        cursor: pointer;
        padding: 8px;
        border-radius: 6px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background-color .2s ease;

        &:hover {
            background-color: var(--btn-hover-bg);
        }

        &:active {
            background-color: var(--btn-active-bg);
        }
    }

    @media (min-width: 1200px) {
        display: none;
    }
}

.sidebar-left, .sidebar-right {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 80vw;
    max-width: var(--sidebar-width);
    height: 100dvh;
    background: var(--bg-sidebar);
    z-index: var(--z-sidebar);
    padding: var(--gap-std);
    overflow: hidden;
    box-shadow: 0 0 15px var(--bg-overlay);
    transition: transform .3s cubic-bezier(.4, 0, .2, 1);
    display: flex;
    flex-direction: column;

    &.active {
        transform: translateX(0);
    }

    @media (min-width: 1200px) {
        position: sticky;
        top: 8px;
        height: 100vh;
        width: var(--sidebar-width);
        background: transparent;
        box-shadow: none;
        transform: none !important;
        padding-top: var(--gap-std);
    }

    ul {
        list-style: none;
        padding: 0;
        margin: 0;
        
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    li {
        margin: .2rem 0;
    }

    h3 {
        margin: 0 0 .5rem;
        flex-shrink: 0;
    }

    a {
        text-decoration: none;
        color: var(--link-std);
        display: block;
        padding: 4px 8px;
        transition: all .2s ease;
        border-left: 3px solid transparent;

        &:hover {
            border-left: 3px solid var(--link-hover);
        }

        &.active {
            background-color: var(--link-active-bg);
            border-left: 3px solid var(--link-hover);
        }

        &:active {
            color: var(--link-hover);
        }
    }
}

.sidebar-left {
    left: 0;
    transform: translateX(-150%);

    @media (min-width: 1200px) {
        padding-left: clamp(16px, 3vw, 64px);
    }

    .profile {
        flex-shrink: 0;
        text-align: center;
        margin-bottom: 2rem;
        margin-top: 1rem;

        .avatar {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            object-fit: cover;
            border: 2px solid var(--border-std);
            animation: avatarGlow 3s ease-in infinite;

            @media (min-width: 1200px) {
                width: 100px;
                height: 100px;
            }
        }

        .nickname {
            margin: .5rem 0 0;
            font-size: 1.2rem;
            font-weight: bold;
            color: var(--font-heading);
        }

        .fullname {
            margin: .2rem 0;
            font-size: .9rem;
            font-style: italic;
            color: var(--font-muted);
        }

        .description {
            font-size: .85rem;
            color: var(--font-main);
            margin-top: .5rem;
        }
    }

    .articles-list {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;

        .articles-header {
            margin-top: 1rem;
            
            h3 {
                margin: 0;
                padding: 4px 8px;
                color: var(--font-heading);
            }
        }
    }
}

.sidebar-right {
    right: 0;
    transform: translateX(150%);

    @media (min-width: 1200px) {
        right: 8px;
        padding-right: clamp(16px, 3vw, 64px);
    }

    .toc {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        overflow: hidden;

        ul {
            padding-bottom: 1rem;
        }

        li {
            margin: .3rem 0;
        }

        li a {
            color: var(--font-main);
            font-size: .95rem;
            padding: 0 0 0 10px;
            position: relative;
            border-left: none;
            --toc-border-alpha: 0;

            &::before {
                content: "";
                position: absolute;
                left: 0;
                top: 0;
                bottom: 0;
                width: 3px;
                background-color: var(--link-hover);
                opacity: var(--toc-border-alpha);
                transition: opacity .1s linear;
            }

            &:hover {
                border-left: none;
                --toc-border-alpha: 1 !important;
            }

            &:active {
                background: none;
                --toc-border-alpha: 1 !important;
            }
        }
    }

    .resources {
        flex-shrink: 0;
        flex: 0 0 auto;
        margin-top: auto;
        padding-top: 1rem;
        
        li { 
            margin: .4rem 0; 
            

            a {
                display: flex;
                align-items: center;
                gap: 10px;
                padding: 0 0 0 10px;
            }

            a:hover {
                text-decoration: underline;
            }
        
            .icon {
                width: 1em;
                height: 1em;
                object-fit: contain;
            }
        
            a:hover .icon {
                color: var(--link-hover);
            }
        }
    }
}

main {
    height: 100%; 
    flex: 1;
    padding: 50px 1rem 1rem 1rem;
    
    overflow-y: auto; 
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;

    transition: transform .3s cubic-bezier(0.32, 0.72, 0, 1), border-radius .3s;
    transform-origin: center center;

    overscroll-behavior-y: auto;

    @media (min-width: 1200px) {
        padding: var(--gap-std) 2rem 2rem 2rem;
    }

    > * {
        max-width: 100%;
        margin: 0 auto;

        @media (min-width: 1200px) {
            max-width: clamp(800px, 60vw, 1200px);
        }
    }

    h1, h2, h3 {
        margin-top: 1.5rem;
        color: var(--font-heading);
    }

    h1 {
        font-size: 1.6rem;
        padding-bottom: .5rem;
        border-bottom: 1px solid var(--border-std);

        @media (min-width: 1200px) {
            font-size: 2rem;
        }
    }

    h2 {
        font-size: 1.3rem;
        margin-top: 2rem;

        @media (min-width: 1200px) {
            font-size: 1.5rem;
        }
    }

    h3 {
        font-size: 1.1rem;
        margin-top: 1.5rem;

        @media (min-width: 1200px) {
            font-size: 1.2rem;
        }
    }

    p, ul, ol, li {
        line-height: 1.7;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    p { margin: 0 0 1rem 0; }
    li { margin: .4rem 0; }

    ul, ol {
        padding-left: 1.5rem;
        margin: 1rem 0;
    }

    a {
        color: var(--link-std);
        text-decoration: underline;

        &:hover {
            color: var(--link-hover);
        }
    }

    blockquote {
        margin: 1rem 0;
        padding: .5rem .5rem .5rem 1rem;
        color: var(--font-muted);
        font-style: italic;
        background: var(--quote-bg);
        border-radius: 0 4px 4px 0;
        border-left: 5px solid rgba(var(--theme-accent-rgb), 0.2); 

        p, li { margin-inline: 0; }
    }

    img {
        max-width: 100%;
        height: auto;
        display: block;
        margin: 1rem auto;
        border-radius: var(--radius-card);
    }

    code {
        background: var(--code-inline-bg);
        color: #f1f1f1;
        padding: .2rem .4rem;
        border-radius: 4px;
        font-size: .9rem;
        font-family: var(--font-stack);
        word-break: break-word;
    }

    :not(pre) > code {
        cursor: pointer;
        position: relative;
        transition: background-color 0.2s, color 0.2s;

        &:hover {
            background-color: var(--btn-active-bg);
            color: var(--link-hover);
        }

        &.copied {
            background-color: var(--link-active-bg);
            color: #fff;
        }
    }

    pre {
        background: var(--pre-block-bg);
        padding: 8px;
        border-radius: 7px;
        overflow-x: auto;
        font-size: .8rem;
        line-height: 1.4;
        max-width: 100%;
        position: relative;
        border: 1px solid var(--pre-border);

        @media (min-width: 1200px) {
            padding: 10px;
            font-size: .9rem;
        }

        code {
            background: none;
            padding: 0;
            color: var(--pre-text-color);
            white-space: pre;
            word-break: normal;
        }

        .hljs {
            color: var(--pre-text-color);
            background: var(--pre-bg);
        }
    }
    
    .copy-btn {
        position: absolute;
        top: 5px;
        right: 5px;
        background: var(--bg-sidebar);
        border: 1px solid var(--border-std);
        color: var(--font-muted);
        border-radius: 4px;
        padding: 4px 8px;
        font-size: 0.75rem;
        font-family: inherit;
        cursor: pointer;
        transition: opacity 0.2s, background-color 0.2s, color 0.2s;
        user-select: none;

        &:hover {
            background-color: var(--link-hover);
            color: white;
            border-color: var(--link-hover);
        }

        &.copied {
            background-color: #28a745;
            border-color: #28a745;
            color: white;
        }
    }

    .table-wrapper {
        overflow-x: auto;
        margin: 1rem 0;
        max-width: 100%;
        border: 1px solid var(--table-border);
        border-radius: var(--radius-card);
        background-color: var(--bg-sidebar);
    }

    table {
        border-collapse: collapse;
        border: none;
        width: 100%;
        white-space: nowrap;

        thead th {
            background-color: var(--table-head-bg);
            color: var(--table-head-text);
            text-align: left;
            padding: .5rem;
            font-size: .85rem;
            position: sticky;
            top: 0;

            @media (min-width: 1200px) {
                padding: .8rem;
                font-size: inherit;
            }
        }

        tbody td {
            padding: .5rem;
            border-top: 1px solid var(--table-border);
            color: var(--table-body-text);
            font-size: .85rem;

            @media (min-width: 1200px) {
                padding: .8rem;
                font-size: inherit;
            }
        }

        tr:nth-child(even) {
            background-color: var(--table-stripe-bg);
        }
    }

    .article-section {
        width: 100%;
        scroll-margin-top: 60px;
        position: relative;
        z-index: 1;

        &::after {
            content: "";
            position: absolute;
            inset: -10px;
            pointer-events: none;
            z-index: -1;
            border-radius: var(--radius-card);
            background-color: transparent;
            transition: background-color 1s ease-out;
        }

        &.highlight::after {
            background-color: var(--highlight-flash);
            transition: background-color .1s ease-in;
        }
    }

    p, li {
        margin-inline: var(--text-inside-margin);
    }
}