:root {
    --bg-light: #fafafa;
    --bg-dark: #0b0b0b;
    --transition: background 0.4s ease, color 0.3s ease;
}

html {
    height: 100%;
    background: var(--bg-light);
    color-scheme: light dark;
    transition: var(--transition);
    overflow-x: hidden;
}

html.dark {
    background: var(--bg-dark);
}

body {
    min-height: 100%;
    margin: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
    background: transparent;
    transition: var(--transition);
}

html.no-scroll, body.no-scroll {
    overflow: hidden;
    height: 100%;
}

main > h1:first-child,
article > header:first-child,
article > header > h1:first-child {
    margin-top: 0 !important;
}

button {
    background-color: var(--text-accent);
    color: var(--text-dark);
    padding: .25rem;
    border: 2px solid var(--bg-light);
    border-radius: 5px;
    outline: none;
    cursor: pointer;
}

html.dark button {
    border-color: var(--bg-dark);
}

header {
    margin-top: 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

html.dark header {
    border-color: rgba(255, 255, 255, 0.2);
}

nav, footer {
    font-family: var(--font-ui), sans-serif;
    font-size: 0.95rem;
}

nav a {
    margin-left: 1rem;
    text-decoration: none;
    color: inherit;
    font-weight: 500;
}

nav a:hover {
    color: var(--text-accent);
}

footer {
    margin-top: auto;
    text-align: center;
    font-size: 0.9rem;
    opacity: 0.7;
    padding-bottom: 2rem;
}

button.theme-toggle {
    align-self: start;
    flex-grow: 1;
    margin-left: 1rem;
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    font-size: 1.2rem;
    text-align: end;
    transition: transform 0.2s ease;
}

button.theme-toggle:hover {
    /*transform: rotate(-10deg);*/
    color: var(--text-accent);
}

html.dark .site-logo img { filter: invert(1); opacity: .9; }

@media print {
    html.dark .site-logo img { filter: none; }
}


/* === RESPONSIVE LAYOUT === */

html {
    font-size: clamp(14px, 1vw + 0.5rem, 18px);
}

/* 1. Mobile first adjustments */
#container {
    display: flex;
    justify-content: space-between;
    align-items: start;
    flex-direction: column;
    justify-items: center;
    gap: .5rem 0;
}

#sidebar {
    padding: 1rem 1.5rem .25rem 1.5rem;
    width: 100%;
}

/* Menu list */
#menu {
    list-style: none;
    padding: 0;
    margin: 0;
    display: none;
    gap: .25rem;
}

#menu.show {
    display: flex;
    flex-direction: column;
}

#menu li a {
    white-space: nowrap;
    text-decoration: none;
}

#menu li a.active {
    color: var(--text-accent-2);
}

#menu li a.active::after {
    content: '<-';
    padding-left: .25rem;
}

#menu li a:hover {
    text-decoration: underline;
}

/* Hamburger button hidden by default */
#hamburger {
    align-self: start;
    display: block;
    font-size: 1.5rem;
    background: inherit;
    border: none;
    cursor: pointer;
    color: inherit;
}

nav {
    display: flex;
    flex-direction: row;
    justify-content: end;
    align-items: end;
    flex-wrap: nowrap;
    text-align: start;
    font-size: 0.95rem;
}

/* Reduce outer spacing for small screens */
main, body > header:first-child, footer {
    padding: 0.25rem 1.5rem;
}

main > p {
    padding-left: .25rem;
    padding-right: .25rem;
}

/* 2. Larger smart phones */
@media (min-width: 430px) {

}

/* 3. Medium screens (tablets / small laptops) */
@media (min-width: 648px) {
    :root {
        --measure: 80ch;     /* reading width for main content */
        --max-width: 1000px; /* header/footer container width */
    }

    #container {
        flex-direction: row;
        justify-content: start;
    }

    #sidebar {
        position: sticky;
        flex-direction: column;
        align-items: start;
        gap: .5rem 0;
        width: auto;
        top: 0;
    }

    main {
        /*width: min(var(--measure), calc(100vw - 4rem));*/
        margin: .5rem;
        padding: 1rem 2rem 0 2rem;
    }

    footer {
        /*width: min(var(--max-width), calc(100vw - 4rem));*/
        margin: 0 auto;
    }

    div.sub-header {
        font-size: 0.95rem;
        width: min(var(--max-width), calc(100vw - 4rem));
    }

    #hamburger {
        display: none; /* show hamburger */
    }

    #menu {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        margin-top: 1rem;
    }

    button.theme-toggle {
        padding-left: 0;
        flex-grow: unset;
    }
}

/* 3. Large / high-res monitors */
@media (min-width: 1024px) {
    :root {
        --measure: 80ch;     /* reading width for main content */
        --max-width: 1200px; /* header/footer container width */
    }

    main {
        margin-bottom: 2rem;
        margin-top: 2rem;
        margin-right: calc((100vw - min(var(--max-width), calc(95vw - 4rem))) / 2);
        padding: 0 2rem;
    }

    body > header:first-child, footer {
        width: min(var(--max-width), calc(95vw - 4rem));
        margin: 0 auto;
        padding: 1rem 2rem;
    }

    #sidebar {
        margin-left: calc((100vw - min(var(--max-width), calc(95vw - 4rem))) / 2);
    }

    .w-lg-75 {
        width: 75% !important;
    }
}

/* 4. Ultra-wide (>1440px) */
@media (min-width: 1440px) {
    :root {
        --measure: 88ch;
        --max-width: 1300px;
    }

    main {
        margin-right: calc((100vw - min(var(--max-width), 92vw)) / 2);
    }

    body > header:first-child, footer {
        width: min(var(--max-width), 92vw);
    }

    #sidebar {
        margin-left: calc((100vw - min(var(--max-width), 92vw)) / 2);
    }
}
