/* Global Styles */
:root {
    --primary-color: #0056b3;
    --secondary-color: #004494;
    --text-color: #333;
    --bg-color: #fff;
    --sidebar-bg: #f8f9fa;
    --sidebar-border: #d0d5dd;
    --header-bg: #e8ecf1;
    --header-border: #d0d5dd;
    --code-bg: #282c34;
    --code-text: #abb2bf;
    --link-color: #0056b3;
    --link-hover: #004494;
    --toc-bg: #f8f9fa;
    --toc-border: #e0e0e0;
    --citation-bg: #f8f9fa;
    --citation-text: #555;
    --table-header-bg: #f8f9fa;
    --table-border: #e0e0e0;
    --sidebar-width: 320px;
    --header-height: 60px;
    --footer-height: 60px;
    --h4-bg: #f0f7ff;
    --h4-border: #0056b3;
    --h4-text: #0056b3;
    --sidebar-hover: #f0f7ff;
    --sidebar-active: #e1f0ff;
}

html.dark-mode {
    --primary-color: #4da3ff;
    --secondary-color: #2b87ff;
    --text-color: #e0e0e0;
    --bg-color: #1a1a1a;
    --sidebar-bg: #252525;
    --sidebar-border: #333;
    --header-bg: #252525;
    --header-border: #333;
    --code-bg: #2d2d2d;
    --code-text: #e0e0e0;
    --link-color: #4da3ff;
    --link-hover: #80bfff;
    --toc-bg: #252525;
    --toc-border: #333;
    --citation-bg: #2d2d2d;
    --citation-text: #ccc;
    --table-header-bg: #2d2d2d;
    --table-border: #444;
    --h4-bg: #2d333b;
    --h4-border: #4da3ff;
    --h4-text: #4da3ff;
    --sidebar-hover: #333;
    --sidebar-active: #2d333b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    color: var(--text-color);
    background-color: var(--bg-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
    font-size: 17px;
}

/* Header */
header {
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 1000;
    box-sizing: border-box;
    transition: background-color 0.3s, border-color 0.3s;
}

.logo {
    font-weight: bold;
    font-size: 1.2rem;
    color: var(--primary-color);
    text-decoration: none;
    display: flex;
    align-items: center;
}

.logo img {
    height: 30px;
    margin-right: 10px;
}

.nav-links {
    margin-left: auto;
    display: flex;
    gap: 20px;
    align-items: center;
}

.nav-links a {
    text-decoration: none;
    color: var(--text-color);
    font-weight: 700;
}

.nav-links a:hover {
    color: var(--primary-color);
}

/* Theme Toggle Button */
#theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 5px;
    border-radius: 50%;
    transition: background-color 0.3s;
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

#theme-toggle:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

html.dark-mode #theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Hamburger Menu Button */
.hamburger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    padding: 5px;
    border-radius: 50%;
    transition: background-color 0.3s;
    color: var(--text-color);
    margin-right: 10px;
}

.hamburger:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

html.dark-mode .hamburger:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Sidebar Close Button */
.sidebar-close {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--text-color);
    padding: 5px;
    border-radius: 50%;
    transition: background-color 0.3s;
}

.sidebar-close:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

html.dark-mode .sidebar-close:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Layout */
.container {
    display: flex;
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    padding: 20px;
    position: fixed;
    top: var(--header-height);
    left: 0;
    height: calc(100vh - var(--header-height) - var(--footer-height));
    overflow-y: auto;
    box-sizing: border-box;
    scroll-behavior: smooth;
    transition: background-color 0.3s, border-color 0.3s;
    z-index: 900;
}

/* H3 sections normal styling */
.sidebar h3 {
    font-size: 1.1rem;
    text-transform: uppercase;
    color: var(--text-color);
    opacity: 0.85;
    margin-top: 20px;
    margin-bottom: 10px;
    position: relative;
    font-weight: 600;
}

/* Main collapsible sections (Tutorials only) */
.sidebar h3.collapsible {
    cursor: pointer;
    user-select: none;
    padding-left: 20px;
}

/* Nested collapsibles (C++ Tutorials, Python Tutorials inside Tutorials section) */
.sidebar ul + h3.collapsible {
    font-size: 0.95rem;
    text-transform: none;
    color: var(--h4-text);
    margin: 12px 0 8px 10px;
    margin-left: 15px;
    font-weight: 600;
    border-left: 3px solid var(--h4-border);
    background: var(--h4-bg);
    padding: 8px 10px 8px 25px;
    border-radius: 4px;
    opacity: 1;
    cursor: pointer;
    user-select: none;
}

/* UL following nested collapsible h3 should also be indented */
.sidebar ul + h3.collapsible + ul {
    margin-left: 15px;
}

.sidebar h3::before {
    content: '';
}

/* Add arrow icon only for collapsible sections */
.sidebar h3.collapsible::before {
    content: '▼';
    position: absolute;
    left: 0;
    font-size: 0.7rem;
    transition: transform 0.3s ease;
    margin-right: 8px;
}

.sidebar h3.collapsed::before {
    transform: rotate(-90deg);
}

/* Smooth transitions for collapsible content */
.sidebar h3.collapsible + ul,
.sidebar ul + h3.collapsible + ul {
    transition: opacity 0.2s ease, max-height 0.3s ease;
    overflow: hidden;
}

/* Remove transition delays that might cause flicker */
.sidebar * {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* H4 subsections styling with better visual separation */
.sidebar h4 {
    font-size: 1rem;
    color: var(--h4-text);
    margin: 15px 0 8px 0;
    padding-left: 10px;
    font-weight: 600;
    border-left: 3px solid var(--h4-border);
    background: var(--h4-bg);
    padding: 8px 10px;
    border-radius: 4px;
}

.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar li {
    margin-bottom: 6px;
}

.sidebar a {
    text-decoration: none;
    color: var(--text-color);
    display: block;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 1.05rem;
    transition: background-color 0.15s ease, color 0.15s ease;
    line-height: 1.5;
    will-change: background-color, color;
}

.sidebar a:hover {
    background-color: var(--sidebar-hover);
    color: var(--primary-color);
}

.sidebar a.active {
    background-color: var(--sidebar-active);
    color: var(--primary-color);
    font-weight: 500;
}

.sidebar a:focus {
    outline: none;
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    margin-right: 220px;
    margin-bottom: var(--footer-height);
    padding: 40px 45px;
    width: calc(100% - var(--sidebar-width) - 220px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.main-content > * {
    width: 100%;
    max-width: 900px;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    color: var(--primary-color);
}

/* Tutorial title links */
h1 a {
    color: inherit;
    text-decoration: none;
    transition: opacity 0.2s ease;
}

h1 a:hover {
    opacity: 0.7;
    text-decoration: underline;
}

h2 {
    font-size: 1.8rem;
    margin-top: 40px;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--table-border);
    padding-bottom: 10px;
}

h3 {
    font-size: 1.4rem;
    margin-top: 30px;
    margin-bottom: 10px;
    color: var(--text-color);
}

p {
    line-height: 1.7;
    margin-bottom: 15px;
    font-size: 1.08rem;
}

ul, ol {
    line-height: 1.7;
    margin-bottom: 15px;
    padding-left: 20px;
    font-size: 1.06rem;
}

li {
    margin-bottom: 5px;
}

/* Code Blocks */
pre {
    background-color: var(--code-bg);
    color: var(--code-text);
    padding: 0; /* Let hljs handle padding */
    border-radius: 8px;
    overflow-x: auto;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.9rem;
    border: 1px solid #3e4451;
    position: relative;
    margin: 20px 0;
}

/* Override hljs background to match pre */
.hljs {
    background: transparent !important;
    padding: 20px !important;
}

pre code {
    background-color: transparent;
    padding: 0;
    color: inherit;
}

/* Inline code */
code {
    background-color: var(--table-header-bg);
    color: #c7254e;
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-size: 90%;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

html.dark-mode code {
    color: #ff6b8b;
    background-color: #333;
}

pre code {
    background-color: transparent;
    color: inherit;
}

/* Copy button for code blocks */
.code-block-wrapper {
    position: relative;
}

.copy-button {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #4a5568;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    opacity: 0.8;
    transition: opacity 0.2s, background 0.2s;
}

.copy-button:hover {
    opacity: 1;
    background: #2d3748;
}

.copy-button.copied {
    background: #48bb78;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

th, td {
    border: 1px solid var(--table-border);
    padding: 10px;
    text-align: left;
}

th {
    background-color: var(--table-header-bg);
    font-weight: 600;
}

/* Links */
.content a {
    color: var(--link-color);
    text-decoration: none;
}

.content a:hover {
    text-decoration: underline;
    color: var(--link-hover);
}



/* Table of Contents */
.toc {
    position: fixed;
    right: 20px;
    top: calc(var(--header-height) + 20px);
    width: 240px;
    max-height: calc(100vh - var(--header-height) - 40px);
    overflow-y: auto;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: 0;
    padding: 20px;
    font-size: 0.98rem;
    transition: background-color 0.3s, border-color 0.3s;
}

.toc h4 {
    margin: 0 0 10px 0;
    font-size: 0.9rem;
    color: var(--text-color);
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc li {
    margin-bottom: 8px;
}

.toc a {
    color: var(--text-color);
    text-decoration: none;
    display: block;
    padding: 5px 10px;
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.toc a:hover {
    background: var(--sidebar-hover);
    color: var(--primary-color);
}

.toc a.active {
    background: var(--sidebar-active);
    color: var(--primary-color);
    font-weight: 600;
}

/* TOC nested heading styles */
.toc a.h3 {
    padding-left: 25px;
    font-size: 0.9rem;
}

/* Navigation buttons */
.page-navigation {
    display: flex;
    justify-content: space-between;
    margin-top: 40px;
    padding-top: 30px;
    border-top: 2px solid var(--table-border);
}

.nav-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--primary-color);
    color: white !important;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 500;
    transition: background 0.2s;
}

.nav-button:hover {
    background: var(--secondary-color);
}

.nav-button.prev::before {
    content: '←';
}

.nav-button.next::after {
    content: '→';
}

.nav-button-placeholder {
    width: 100px;
}

/* Citation Box */
.citation-box {
    background-color: var(--citation-bg);
    border-left: 4px solid var(--primary-color);
    padding: 15px 20px;
    margin: 20px 0;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.9rem;
    color: var(--citation-text);
    position: relative;
    white-space: pre-wrap;
    word-wrap: break-word;
    border-radius: 0 4px 4px 0;
}

/* Footer */
footer {
    background-color: var(--sidebar-bg);
    border-top: 1px solid var(--sidebar-border);
    text-align: center;
    padding: 20px;
    color: #666;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 1000;
}

footer p {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        display: none;
        position: fixed;
        top: var(--header-height);
        left: -100%;
        width: 280px;
        height: calc(100vh - var(--header-height));
        z-index: 1001;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
        border-radius: 0 8px 8px 0;
    }
    .sidebar.sidebar-open {
        display: block;
        left: 0;
    }
    .sidebar-close {
        display: block !important;
    }
    .sidebar-backdrop {
        display: none;
        position: fixed;
        top: var(--header-height);
        left: 0;
        width: 100%;
        height: calc(100vh - var(--header-height));
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    .sidebar-backdrop.show {
        display: block;
        opacity: 1;
    }
    .main-content {
        margin-left: 0;
        margin-right: 0;
        padding: 20px;
        width: 100%;
    }
    .toc {
        display: none;
    }
    footer {
        margin-left: 0;
    }
    .hamburger {
        display: block;
    }
    .nav-links {
        gap: 15px;
    }
    header {
        padding: 0 15px;
    }
    .logo {
        font-size: 1.1rem;
    }
    .logo img {
        height: 25px;
    }
    h1 {
        font-size: 2rem;
    }
    h2 {
        font-size: 1.5rem;
    }
    .nav-links a {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 100%;
        border-radius: 0;
        box-shadow: none;
    }
    .nav-links {
        flex-wrap: wrap;
        gap: 10px;
    }
    .nav-links a {
        font-size: 0.8rem;
    }
    .hamburger {
        font-size: 1.3rem;
    }
    #theme-toggle {
        font-size: 1rem;
    }
    .main-content {
        padding: 15px;
    }
    h1 {
        font-size: 1.8rem;
    }
    h2 {
        font-size: 1.3rem;
    }
    p, ul, ol {
        font-size: 1rem;
    }
}
