/* CSS Variables for theming */
:root {
    /* Everforest Dark (Medium) */
    --bg-primary: #2d353b;
    --bg-secondary: #333c43;
    --bg-tertiary: #3a454a;
    --bg-hover: #475258;
    --text-primary: #d3c6aa;
    --text-secondary: #9da9a0;
    --text-muted: #859289;
    --border-color: #475258;
    --accent-color: #7fbbb3;
    --accent-hover: #83c092;
    --code-bg: #333c43;
    --link-color: #7fbbb3;
    --success-color: #a7c080;
    --warning-color: #dbbc7f;
    --error-color: #e67e80;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    --sidebar-width: 320px;
    --header-height: 60px;
    --spacing: 16px;
    --border-radius: 16px;
}

body.light-mode {
    /* Everforest Light (Medium) */
    --bg-primary: #f9f5d7;
    --bg-secondary: #f0ebd0;
    --bg-tertiary: #e6e0c2;
    --bg-hover: #dcd6bd;
    --text-primary: #5c6a72;
    --text-secondary: #66767e;
    --text-muted: #829181;
    --border-color: #e6e0c2;
    --accent-color: #3a94c5;
    --accent-hover: #35a77c;
    --code-bg: #f0ebd0;
    --link-color: #3a94c5;
    --success-color: #8da101;
    --warning-color: #dfa000;
    --error-color: #f85552;
    --shadow: 0 8px 24px rgba(92, 106, 114, 0.1);
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    overflow: hidden;
}

body {
    font-family: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: color 0.3s ease;
    position: relative;
    overflow: hidden;
}

/* Background image layer */
body::before {
    content: '';
    position: fixed;
    top: -10%;
    left: -10%;
    width: 120%;
    height: 120%;
    background-image: url('background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    filter: blur(10px);
    z-index: -2;
}

/* Semi-transparent overlay layer */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    transition: background-color 0.3s ease;
}

/* Dark theme overlay */
body.dark-mode::after {
    background-color: rgba(45, 53, 59, 0.50);
}

/* Light theme overlay */
body.light-mode::after {
    background-color: rgba(249, 245, 215, 0.50);
}

/* Header */
.header {
    position: fixed;
    top: var(--spacing);
    left: var(--spacing);
    right: var(--spacing);
    height: var(--header-height);
    background-color: rgba(51, 60, 67, 0.85);
    border: 1px solid rgba(71, 82, 88, 0.4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 1000;
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border-radius: var(--border-radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

body.light-mode .header {
    background-color: rgba(240, 235, 208, 0.85);
    border: 1px solid rgba(230, 224, 194, 0.4);
    box-shadow: 0 8px 32px rgba(92, 106, 114, 0.12);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.site-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.site-icon {
    width: 2.25rem;
    height: 2.25rem;
    object-fit: contain;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background-color 0.2s;
}

.menu-toggle:hover {
    background-color: var(--bg-hover);
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.theme-toggle:hover {
    background-color: var(--bg-hover);
    border-color: var(--text-muted);
}

.dark-mode .sun-icon { display: block; }
.dark-mode .moon-icon { display: none; }
.light-mode .sun-icon { display: none; }
.light-mode .moon-icon { display: block; }

/* Main Container */
.main-container {
    display: flex;
    margin-top: calc(var(--header-height) + var(--spacing) * 2);
    min-height: calc(100vh - var(--header-height) - var(--spacing) * 3);
    padding: 0;
    gap: 0;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: calc(var(--header-height) + var(--spacing) * 2);
    left: var(--spacing);
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height) - var(--spacing) * 3);
    background-color: rgba(51, 60, 67, 0.85);
    border: 1px solid rgba(71, 82, 88, 0.4);
    transition: transform 0.3s ease;
    z-index: 100;
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border-radius: var(--border-radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body.light-mode .sidebar {
    background-color: rgba(240, 235, 208, 0.85);
    border: 1px solid rgba(230, 224, 194, 0.4);
    box-shadow: 0 8px 32px rgba(92, 106, 114, 0.12);
}

.sidebar-scroll-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid rgba(71, 82, 88, 0.3);
    background-color: rgba(51, 60, 67, 0.90);
    z-index: 10;
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    flex-shrink: 0;
}

body.light-mode .sidebar-header {
    background-color: rgba(240, 235, 208, 0.90);
    border-bottom: 1px solid rgba(230, 224, 194, 0.3);
}

.search-input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.tree-nav {
    padding: 0.5rem 0;
}

.tree-nav .loading {
    padding: 1rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Tree Item Styles */
.tree-item {
    user-select: none;
}

.tree-item-header {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
    gap: 0.5rem;
}

.tree-item-header:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.tree-item-header.active {
    background-color: var(--bg-tertiary);
    color: var(--accent-color);
    border-left-color: var(--accent-color);
}

.tree-item-header.folder {
    font-weight: 600;
}

.tree-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.tree-icon.expanded {
    transform: rotate(90deg);
}

.tree-icon svg {
    width: 14px;
    height: 14px;
}

.file-icon {
    flex-shrink: 0;
    font-size: 1rem;
}

.tree-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.875rem;
}

.tree-children {
    display: none;
    padding-left: 1rem;
}

.tree-children.expanded {
    display: block;
}

/* Content Area */
.content {
    position: fixed;
    top: calc(var(--header-height) + var(--spacing) * 2);
    left: calc(var(--sidebar-width) + var(--spacing) * 2);
    right: var(--spacing);
    height: calc(100vh - var(--header-height) - var(--spacing) * 3);
    background-color: rgba(51, 60, 67, 0.85);
    border: 1px solid rgba(71, 82, 88, 0.4);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border-radius: var(--border-radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

body.light-mode .content {
    background-color: rgba(240, 235, 208, 0.85);
    border: 1px solid rgba(230, 224, 194, 0.4);
    box-shadow: 0 8px 32px rgba(92, 106, 114, 0.12);
}

.content-scroll-wrapper {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2rem;
}

.markdown-body {
    max-width: 900px;
    margin: 0 auto;
}

/* Welcome Screen */
.welcome {
    text-align: center;
    padding: 4rem 2rem;
}

.welcome h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--accent-color), var(--success-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome p {
    color: var(--text-secondary);
    font-size: 1.125rem;
    margin-bottom: 2rem;
}

.quick-start {
    text-align: left;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2rem;
    max-width: 600px;
    margin: 0 auto;
}

.quick-start h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.quick-start ul {
    list-style: none;
    padding: 0;
}

.quick-start li {
    padding: 0.5rem 0;
    padding-left: 1.5rem;
    position: relative;
    color: var(--text-secondary);
}

.quick-start li::before {
    content: "→";
    position: absolute;
    left: 0;
    color: var(--accent-color);
}

/* Markdown Styles */
.markdown-body h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
    color: var(--text-primary);
}

.markdown-body h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.markdown-body h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    font-weight: 600;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.markdown-body p {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

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

.markdown-body a:hover {
    text-decoration: underline;
}

.markdown-body ul, .markdown-body ol {
    margin-bottom: 1rem;
    padding-left: 2rem;
}

.markdown-body li {
    margin-bottom: 0.5rem;
}

.markdown-body blockquote {
    border-left: 4px solid var(--accent-color);
    padding: 0.5rem 1rem;
    margin: 1rem 0;
    background-color: var(--bg-secondary);
    border-radius: 0 6px 6px 0;
    color: var(--text-secondary);
}

.markdown-body hr {
    border: none;
    height: 2px;
    background-color: var(--border-color);
    margin: 2rem 0;
}

.markdown-body strong {
    font-weight: 600;
    color: var(--text-primary);
}

.markdown-body em {
    font-style: italic;
}

/* Code Blocks */
.markdown-body code {
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.875em;
}

.markdown-body :not(pre) > code {
    background-color: var(--bg-tertiary);
    padding: 0.2em 0.4em;
    border-radius: 4px;
    color: var(--accent-color);
}

.markdown-body pre {
    background-color: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    overflow-x: auto;
    margin: 1rem 0;
}

.markdown-body pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: 0.875rem;
    line-height: 1.5;
}

/* Tables */
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    overflow-x: auto;
    display: block;
}

.markdown-body th, .markdown-body td {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    text-align: left;
}

.markdown-body th {
    background-color: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-primary);
}

.markdown-body tr:nth-child(even) {
    background-color: var(--bg-secondary);
}

/* Images */
.markdown-body img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1rem 0;
}

/* Task Lists */
.markdown-body input[type="checkbox"] {
    margin-right: 0.5rem;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Loading Animation */
@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

/* Responsive */
@media (max-width: 1024px) {
    .content {
        padding: 1.5rem;
    }
}

@media (max-width: 768px) {
    :root {
        --spacing: 8px;
        --border-radius: 12px;
    }

    .menu-toggle {
        display: flex;
    }

    .sidebar {
        transform: translateX(calc(-100% - var(--spacing)));
        left: var(--spacing);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    }

    .content {
        position: fixed;
        left: var(--spacing);
        right: var(--spacing);
        padding: 1.5rem 1rem;
    }

    .site-title {
        font-size: 1rem;
    }

    .site-icon {
        width: 1.25rem;
        height: 1.25rem;
    }

    .welcome h1 {
        font-size: 1.75rem;
    }

    .quick-start {
        padding: 1.5rem;
    }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 99;
    backdrop-filter: blur(4px);
}

.sidebar-overlay.active {
    display: block;
}

/* Back to top button styling space */
.back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background-color: var(--accent-color);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    z-index: 50;
}

.back-to-top.visible {
    display: flex;
}

.back-to-top:hover {
    background-color: var(--accent-hover);
    transform: translateY(-2px);
}

/* Print styles */
@media print {
    .header, .sidebar, .back-to-top {
        display: none !important;
    }
    
    .content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    
    .markdown-body {
        max-width: 100% !important;
    }
}
