:root {
    --bg-color: #FDFBF6;
    /* Light Eggshell [253,251,246] */
    --text-color: #1E364E;
    /* Sleepy Teal [30,54,78] */
    --accent-purple: #A582C4;
    /* Morning Purple [165,130,196] */
    --accent-green: #639D7D;
    /* Optimistic Green [99,157,125] */
    --accent-red: #AB5050;
    /* Frozen Red [171,80,80] */
    --accent-bronze: #A5824C;
    /* Sudden Bronze [165,130,76] */
    --accent-blue: #5A82C4;
    /* Liquid Blue [90,130,196] */

    --header-height: 80px;
    --sidebar-width: 260px;
    --max-content-width: 900px;

    --font-serif: 'Inria Serif', serif;
    --font-sans: 'Inria Sans', sans-serif;
}


body.dark-mode {
    --bg-color: #1E364E;
    /* Sleepy Teal */
    --text-color: #FDFBF6;
    /* Light Eggshell */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-sans);
    line-height: 1.6;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

html,
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

pre,
code,
.math,
.katex-display {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-serif);
}

h1 {
    font-size: 2rem;
    font-weight: 700;
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

h3 {
    font-size: 1.3rem;
    font-weight: 400;
}

h4 {
    font-size: 1.2rem;
    font-weight: 400;
}

h5 {
    font-size: 1rem;
    font-weight: 300;
}

h6 {
    font-size: 0.9rem;
    font-weight: 300;
}

a {
    color: var(--text-color);
    text-decoration: none;
    transition: color 0.2s;
}

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

canvas,
img,
video,
iframe {
    max-width: 100%;
    height: auto;
}

.content-inner div {
    box-sizing: border-box;
    max-width: 100%;
}

#main-header {
    position: fixed;
    top: 0;
    width: 100%;
    height: var(--header-height);
    background-color: var(--bg-color);
    z-index: 100;
    transition: transform 0.3s ease, background-color 0.3s ease;
}

body.header-hidden #main-header {
    transform: translateY(-100%);
}

body.header-hidden .toc-nav,
body.header-hidden .sticky-date {
    transform: translateY(calc(-1 * var(--header-height)));
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
    padding: 0 40px;
    font-family: var(--font-sans);
    font-size: 1.2rem;
}

.site-logo-img {
    height: 48px;
    width: auto;
    object-fit: contain;
    border-radius: 4px;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 15px;
    text-decoration: none;
    color: var(--text-color);
}

.site-title {
    font-size: clamp(1.3rem, 4vw, 1.8rem);
    font-weight: bold;
    font-family: var(--font-serif);
}

.top-nav {
    display: flex;
    align-items: center;
}

.desktop-nav-links {
    display: flex;
    align-items: center;
    gap: 25px;
}

.top-nav button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-color);
    font-family: var(--font-sans);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 80px;
}

body[data-theme-state="system"] .theme-toggle-btn {
    color: var(--text-color);
}

body[data-theme-state="light"] .theme-toggle-btn {
    color: var(--accent-bronze);
}

body[data-theme-state="dark"] .theme-toggle-btn {
    color: var(--accent-red);
}

.theme-toggle-btn {
    transition: color 0.3s ease;
}

.mobile-sidebar-header {
    display: none;
}

#mobile-menu-btn {
    display: none;
    font-size: 2rem;
}

.header-divider {
    border: 0;
    border-top: 1px solid var(--text-color);
    opacity: 0.2;
}

.workspace-wrapper {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr var(--sidebar-width);
    height: 100vh;
}

.sidebar-left {
    border-right: 1px solid rgba(30, 54, 78, 0.1);
    padding: 0 20px 30px 20px;
    overflow-y: hidden;
}

body.dark-mode .sidebar-left {
    border-right: 1px solid var(--text-color);
}

.toc-nav {
    margin-top: calc(var(--header-height) + 30px);
    transition: transform 0.3s ease;
}

.toc-nav ul {
    list-style: none;
}

.toc-nav li {
    margin-bottom: 10px;
}

.toc-nav a {
    color: var(--text-color);
    opacity: 0.8;
}

.toc-nav a:hover {
    opacity: 1;
    color: var(--accent-green);
}

.content-center {
    overflow-y: auto;
    scroll-behavior: smooth;
    scroll-padding-top: 20px;
}

.content-inner {
    display: flex;
    flex-direction: column;
    min-height: 100%;

    max-width: var(--max-content-width);
    margin: 0 auto;
    padding: calc(var(--header-height) + 20px) 60px 10px 60px;
}

.content-inner p,
.content-inner li {
    line-height: 1.7;
    margin-bottom: 1.2rem;
}

.sidebar-right {
    border-left: 1px solid rgba(30, 54, 78, 0.1);
    padding: 0 20px 30px 20px;
    overflow-y: hidden;
}

.sticky-date {
    margin-top: calc(var(--header-height) + 20px);
    font-family: var(--font-serif);
    font-weight: 600;
    opacity: 0.7;
    text-align: right;
    transition: transform 0.3s ease;
}

footer {
    margin-top: auto;
    text-align: center;
    opacity: 0.6;
    font-size: 0.9rem;
}

footer hr {
    border: 0;
    border-top: 1px solid var(--text-color);
    margin: 0 0 20px 0;
    opacity: 0.2;
}

@media (max-width: 1024px) {

    .workspace-wrapper {
        display: block;
    }

    .sidebar-left,
    .sidebar-right {
        display: none;
    }

    #mobile-menu-btn {
        display: block;
    }

    .content-center {
        height: calc(100vh);
        padding-top: var(--header-height);
    }

    .content-inner {
        width: 100%;
        margin: 0;
        box-sizing: border-box;
        padding-left: 20px;
        padding-right: 20px;
    }


    .sidebar-left.mobile-active {
        display: block;
        position: fixed;
        top: var(--header-height);
        left: 0;
        width: 100%;
        height: calc(100vh - var(--header-height));
        background-color: var(--bg-color);
        z-index: 99;
        border-right: none;
    }

    .desktop-nav-links {
        display: none !important;
    }

    .mobile-sidebar-header {
        display: block !important;
        margin-bottom: 20px;
    }

    .mobile-sidebar-header a {
        display: block;
        font-family: var(--font-sans);
        font-size: 1.1rem;
        padding: 12px 0;
        color: var(--text-color);
        border-bottom: 1px solid rgba(30, 54, 78, 0.1);
    }

    body.dark-mode .mobile-sidebar-header a {
        border-bottom-color: rgba(253, 251, 246, 0.1);
    }

    .mobile-sidebar-header .theme-toggle-btn {
        background: none;
        border: none;
        cursor: pointer;
        color: var(--text-color);
        font-family: inherit;
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100%;
        padding: 10px 0;
        margin-top: 5px;
        font-size: 1.1rem;
    }

    .mobile-sidebar-header hr {
        border: 0;
        border-top: 2px solid var(--text-color);
        opacity: 0.5;
        margin: 10px 0 20px 0;
    }

    body.header-hidden .toc-nav,
    body.header-hidden .sticky-date {
        transform: none !important;
    }

    .toc-nav {
        margin-top: 0 !important;
    }

    .header-container {
        padding-left: 20px !important;
        padding-right: 10px !important;
    }
}

.main-chapter {
    font-weight: normal;
}

.main-chapter.active {
    font-family: var(--font-sans);
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--accent-purple);
}

.sub-toc {
    list-style: none;
    margin-top: 5px;
    margin-left: 5px;
    padding-left: 10px;
}

body.dark-mode .sub-toc {
    border-left-color: rgba(253, 251, 246, 0.1);
}

.sub-toc li {
    margin-bottom: 8px;
    font-family: var(--font-serif);
    font-size: 0.9rem;
    font-weight: 500;
}

.sub-toc a {
    opacity: 0.7;
}

.sub-toc a:hover {
    opacity: 1;
    color: var(--accent-green);
}