:root {
    /* Repeated colors */
    --main-bg: #141631;
    --main-text: #f3f3f7;
    --text-heading: #fff;

    --button-bg: #3f3f3f;
    --button-fg: white;
    --button-border: #b3e5fc;

    --article-bg: #242424;
    --article-text: #dcdcdc;

    --accent-blue: #7bb0ff;
    --accent-blue-light: #a3c8ff;
    --accent-gold: #e8b86d;
    --accent-blue-soft: #8cb4ff;
}

/* Base */
html,
body {
    min-height: 100vh;
    width: 100%;
    margin: 0;
    padding: 0;
}

body {
    background: var(--main-bg);
    color: var(--main-text);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

/* Scrollbars */
.scrollBarThin {
    &::-webkit-scrollbar {
        width: 8px;
    }

    &::-webkit-scrollbar-track {
        background: #1e1e1e;
    }

    &::-webkit-scrollbar-thumb {
        background-color: #555;
        border-radius: 4px;
        border: 2px solid #1e1e1e;

        &:hover {
            background-color: #777;
        }
    }

    * {
        scrollbar-width: thin;
        scrollbar-color: var(--scroll-thumb) var(--scroll-track);
    }
}

nav {
    display: flex;
    justify-content: flex-end;

    width: 100%;
    position: fixed;

    top: 0;
    z-index: 10;
    padding: 16px;

    #menu:popover-open {
        position-area: bottom right;
        padding: 0;
        gap: 2px;
        margin: 5px 16px 0 0;
        border-radius: 5px;

        background: var(--main-bg);
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        border: 1px solid white;
        user-select: none;
        width: max-content;

        a {
            background: #333;
            padding: 7px 12px;
            color: white;
            font-size: 110%;
            cursor: pointer;
            border-radius: 0;

            &:hover {
                background: #4c4c4c;
            }
        }
    }

    #menu:not(:popover-open) {
        position: initial;
        align-items: center;
        gap: 12px;
        margin: 0;
    }

    &>button {
        width: 32px;
        height: 32px;
        background: url('/menu.png');
        background-size: contain;
        border: none;
        cursor: pointer;
    }

    a {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 8px 20px;
        border-radius: 6px;
        text-decoration: none;
        font-size: 0.9rem;
        font-weight: 500;
        color: var(--main-text);
        border: 1px solid rgba(255, 255, 255, 0.12);
        transition: background 0.2s, border-color 0.2s;

        &:hover {
            background: color-mix(in srgb, var(--accent-blue) 18%, transparent);
            border-color: var(--accent-blue);
        }
    }
}

@media (min-width: 400px) {
    nav {
        position: sticky;
        background: rgba(20, 22, 49, 0.85);

        backdrop-filter: blur(12px);
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);

        &>button {
            display: none;
        }

        #menu {
            inset: auto;
            border: none;
            padding: 0;
            background: none;
            display: flex;
            flex-direction: row;
            gap: 1rem;
        }
    }
}

/* Shared button style */
button {
    background-color: var(--button-bg);
    color: var(--button-fg);
    border: 1px solid var(--button-border);
    cursor: pointer;
    border-radius: 5px;
    padding: 10px;
    text-align: center;
    transition: background 0.2s, color 0.2s, border 0.2s;
    user-select: none;

    &:hover {
        background-color: var(--accent-blue);
        color: var(--button-bg);
    }
}

/* textbook, article_index, folder_index, cource_index */
.index_container,
.thumb_container {
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1.5rem 3rem;
    max-width: 720px;
    margin: 0 auto;
    gap: 0.85rem;
    justify-content: center;
    flex-grow: 1;

    section:not(:last-of-type) {
        margin-bottom: 2rem;
    }

    h1 {
        font-weight: 700;
        color: var(--text-heading);
        margin-bottom: 1rem;
        margin-top: 0;
        font-size: 2.5rem;
        text-align: center;
    }

    a {
        display: block;
        background: color-mix(in srgb, var(--accent-blue) 10%, transparent);
        border: 1px solid rgba(255, 255, 255, 0.2);
        transition: background 0.2s, border-color 0.2s, transform 0.15s;
        text-decoration: none;
        width: 100%;
        max-width: 500px;
        color: #a0c0ff;
        padding: 15px 25px;
        margin: 0 auto;
        border-radius: 8px;
        font-size: 1.1rem;
        font-weight: 500;

        &:hover {
            background: color-mix(in srgb, var(--accent-blue) 35%, transparent);
            transform: translateY(-1px);
            color: #ffffff;
            border-color: #404680;
        }

        &[href='../'] {
            margin-top: 1rem;
            padding: 0.6rem 1.2rem;
            font-size: 1.2rem;
            border-radius: 6px;
            text-align: center;
        }
    }
}

.thumb_container {
    * {
        margin: 0;
        padding: 0;
    }

    section {
        display: flex;
        flex-direction: column;
        gap: 0.85rem;
    }

    h1 {
        font-size: 2rem;
        padding-bottom: 0.75rem;
        border-bottom: 2px solid #fff8;
        text-align: left;
    }

    a {
        border-radius: 10px;
        padding: 1.25rem 1.5rem;
        color: inherit;
        max-width: none;

        &:hover {
            border-color: rgba(120, 130, 255, 0.35);
        }

        h2 {
            font-size: 1.15rem;
            font-weight: 600;
            color: var(--text-heading);
            margin-bottom: 0.35rem;
        }

        div {
            font-size: 0.92rem;
            color: #b0b4cc;
            margin-bottom: 0.5rem;
            line-height: 1.45;
        }

        span {
            display: inline-block;
            font-size: 0.78rem;
            color: #7a7e9e;
            margin-right: 1rem;

            b {
                color: #c8cce8;
                font-weight: 500;
            }
        }
    }
}

body:has(calc) {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

body:is(.article_index) {
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1.5rem 3rem;
    max-width: 720px;
    margin: 0 auto;
    gap: 0.85rem;

    h1 {
        font-weight: 700;
        color: var(--text-heading);
        margin-bottom: 1rem;
    }

    a {
        display: block;
        background: color-mix(in srgb, var(--accent-blue) 10%, transparent);
        border: 1px solid rgba(255, 255, 255, 0.2);
        transition: background 0.2s, border-color 0.2s, transform 0.15s;
        text-decoration: none;

        &:hover {
            background: color-mix(in srgb, var(--accent-blue) 35%, transparent);
            transform: translateY(-1px);
        }

        &[href='../'] {
            margin-top: 1rem;
            padding: 0.6rem 1.2rem;
            font-size: 1.2rem;
            border-radius: 6px;
            text-align: center;
        }
    }
}

body:is(.article_index, .course_index) {
    * {
        margin: 0;
        padding: 0;
    }

    h1 {
        font-size: 2rem;
        padding-bottom: 0.75rem;
        border-bottom: 2px solid #fff8;
    }

    a {
        border-radius: 10px;
        padding: 1.25rem 1.5rem;
        color: inherit;

        &:hover {
            border-color: rgba(120, 130, 255, 0.35);
        }

        h2 {
            font-size: 1.15rem;
            font-weight: 600;
            color: var(--text-heading);
            margin-bottom: 0.35rem;
        }

        div {
            font-size: 0.92rem;
            color: #b0b4cc;
            margin-bottom: 0.5rem;
            line-height: 1.45;
        }

        span {
            display: inline-block;
            font-size: 0.78rem;
            color: #7a7e9e;
            margin-right: 1rem;

            b {
                color: #c8cce8;
                font-weight: 500;
            }
        }
    }
}

body:has(article) {
    background: var(--article-bg);
    color: var(--article-text);
    line-height: 1.5;

    article {
        max-width: 740px;
        margin: 0 auto;
        padding: 2.5rem 1.5rem 4rem;

        >section {
            background: #2c2c2c;
            border: 1px solid #3a3a3a;
            border-radius: 8px;
            padding: 1.2rem 1.4rem;
            margin-bottom: 1.6rem;

            &:last-of-type {
                margin-bottom: 0;
            }
        }
    }

    h1 {
        color: var(--text-heading);
        font-weight: 300;
        font-size: 2rem;
        margin: 0 0 1.8rem;
        padding-bottom: 0.6rem;
        border-bottom: 1px solid #444;
    }

    h2 {
        color: var(--accent-gold);
        font-size: 1.3rem;
        font-weight: 600;
        margin: 0 0 0.6rem;
    }

    h3 {
        color: var(--accent-blue-soft);
        font-size: 1.02rem;
        font-weight: 600;
        margin: 1.5rem 0 0.4rem;
    }

    h4 {
        margin: 1.5rem 0 0.4rem;
    }

    p {
        margin: 0.4rem 0;
    }

    p:has(img) {
        display: flex;
        flex-direction: column;

        img {
            margin: auto;
        }
    }

    ul,
    ol {
        padding-left: 1.4rem;
        margin: 0.3rem 0 0.7rem;
    }

    li {
        margin-bottom: 0.25rem;

        &::marker {
            color: var(--accent-gold);
        }
    }

    b {
        color: #eee;
        font-weight: 600;
    }

    #calculator>section>div {
        margin: auto;
        min-width: min(512px, 90%);
        max-width: min-content;
    }

    code {
        border: 1px solid #777;
        background: #333;
        padding: 5px;
        display: flex;
        gap: 25px;
        justify-content: space-between;
        font-family: monospace;
        align-items: center;
        overflow-x: auto;
        white-space: nowrap;
        margin-bottom: 5px;

        button {
            font-family: Consolas, monospace;
            padding: 5px;
        }
    }

    dialog:not(#calc_dialog) {
        background: var(--article-bg);
        color: var(--article-text);
        border: 1px solid #505050;
        border-radius: 10px;
        padding: 0.5rem 2rem 0;
        max-width: 680px;
        width: 95vw;
        box-shadow: 0 20px 60px rgba(0, 0, 0, .55);

        h1 {
            text-align: center;
            font-weight: 600;
            color: var(--accent-gold);
            border-bottom: 1px solid #444;
            padding-bottom: 0.5rem;
            margin-bottom: 1rem;
        }

        button {
            margin: 15px auto;
            display: block;
            width: fit-content;
        }

        &::backdrop {
            background: rgba(0, 0, 0, .65);
            backdrop-filter: blur(3px);
        }
    }

    #calc_dialog {
        width: 95dvw;
        max-width: 1000px;
        height: 95dvh;
        padding: 0;
        border: 1px solid #505050;
        background-color: #000;
        outline: none;

        &[open] {
            display: flex;
        }

        &::backdrop {
            background: rgba(0, 0, 0, .65);
            backdrop-filter: blur(3px);
        }

        iframe {
            width: 100%;
            height: 100%;
            border: none;
        }

        /* close button */
        button {
            position: absolute;
            right: 0;
            margin: 5px;
            font-weight: bold;
            line-height: 1;
            border: none;
        }
    }

    table {
        border-collapse: collapse;
        font-size: 14px;
        margin: 1rem auto;

        th,
        td {
            border: 1px solid #ddd;
            padding: 10px 12px;
        }

        tr:nth-child(even) {
            background-color: #333;
        }
    }

    .exercise_buttons {
        padding: 5px;
        display: flex;
        gap: 15px;
    }


    /* ── exercises ── */
    #exercises>ol>li {
        margin-bottom: 1rem;
        padding: 0.6rem 0;
        border-bottom: 1px solid #383838;
    }

    #exercises>ol>li:last-child {
        border-bottom: none;
    }
}

body.course_index {
    course {
        display: none;
    }

    section {
        flex-direction: column;
        width: 100%;

        &:not(:first-of-type) {
            margin-top: 2rem;
        }

        h2 {
            margin-bottom: 16px;
        }

        a {
            margin-bottom: 10px;
        }
    }
}

body.course {
    &>*:not(course) {
        display: none;
        padding: 0 16px;
        max-width: 900px;
        margin-left: auto;
        margin-right: auto;
    }
}

body.hide_all {
    &>* {
        display: none;
    }
}

/* Media Queries */
@media (max-width: 768px) {
    nav a {
        padding: 6px 14px;
        font-size: 0.82rem;
    }
}

@media (max-width: 640px) {
    body:has(article) {
        article {
            padding: 1.5rem 1rem 3rem;
        }

        dialog {
            padding: 0.5rem 1rem 0;
        }

        article>section {
            padding: 1rem !important;
        }

        h1 {
            font-size: 1.6rem;
        }
    }
}

@media (max-width: 460px) {
    body:has(article) {
        padding: 0.5rem 0.4rem 1rem;

        dialog {
            padding: 0.5rem 0.4rem 0;
        }

        article>section {
            padding: 0.6rem 0.4rem !important;

            h2 {
                text-align: center;
            }
        }
    }
}

@media (max-width: 370px) {
    .index_container {
        padding: 0.5rem 0.5rem 1rem;

        h1 {
            text-align: center;
            font-size: 2rem;
            margin-bottom: 0.5rem;
        }
    }
}