:root {
    --sidebar-width: 280px;
    --header-height: 60px;
    --primary-color: #2c5c4f;
    --accent-color: #2c5c4f;
    --sidebar-bg: var(--primary-color);
    --text-color: #ffffff;
    --content-bg: #e3dac9;
    --card-bg: #523a2e;
    --border-color: #e3dac9;
    --shadow-color: rgba(0,0,0,0.05);
}

[data-theme="dark"] {
    --primary-color: #1e1e1e;
    --sidebar-bg: var(--primary-color);
    --text-color: #e0e0e0;
    --content-bg: #121212;
    --card-bg: #1e1e1e;
    --border-color: #444;
    --shadow-color: rgba(0,0,0,0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: background-color 0.3s ease, color 0.2s ease;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    background: var(--content-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: hidden;
    touch-action: pan-y;
    -webkit-tap-highlight-color: transparent;
}

.container {
    display: flex;
    min-height: 100vh;
    position: relative;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: white;
    height: 100vh;
    position: fixed;
    padding: 20px;
    transition: transform 0.3s ease;
    z-index: 1000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.sidebar h1 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    color: var(--text-color);
}

.nav-container {
    overflow-y: auto;
    max-height: calc(100vh - 150px);
    -webkit-overflow-scrolling: touch;
}

.nav-category {
    margin-bottom: 15px;
}

.nav-category-title {
    font-weight: bold;
    display: flex;
    align-items: center;
    padding: 8px 0;
    cursor: pointer;
    color: var(--text-color);
}

.nav-category-title i {
    margin-right: 8px;
    transition: transform 0.3s;
}

.nav-category-title.collapsed i {
    transform: rotate(-90deg);
}

.nav-items {
    padding-left: 20px;
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.nav-items.collapsed {
    max-height: 0;
}

.nav-item {
    padding: 8px 0;
    cursor: pointer;
    color: rgba(255,255,255,0.8);
}

.nav-item:hover {
    color: white;
}

.content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 20px;
    transition: margin-left 0.3s;
    min-height: 100vh;
}

.menu-toggle {
    display: none;
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 10px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 900;
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 50px;
    height: 50px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.markdown-body {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 10px var(--shadow-color);
    color: var(--text-color);
    overflow-wrap: break-word;
}

.home-button {
    margin-bottom: 20px;
    padding: 10px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    font-weight: bold;
    color: white;
}

.home-button:hover {
    background: rgba(255,255,255,0.2);
}

.home-button i {
    margin-right: 8px;
    margin-left: 5px; /* Add this to move just the icon */
    transform: translateX(3px); /* Fine-tune position */
}

.nav-item i.fa-file-alt {
    margin-right: 8px;
    opacity: 0.7;
}

.nav-items .nav-item {
    padding-left: 20px;
}

.search-container {
    position: relative;
    margin: 15px 0 25px;
}

#search-input {
    width: 100%;
    padding: 10px 15px 10px 35px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: rgba(255,255,255,0.1);
    color: white;
    font-size: 14px;
}

#search-input:focus {
    outline: none;
    border-color: var(--accent-color);
    background-color: rgba(255,255,255, 0.1);
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 12px;
    color: rgba(255,255,255,0.7);
}

.search-results {
    position: absolute;
    width: 100%;
    max-height: 300px;
    overflow-y: auto;
    background: var(--sidebar-bg);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    margin-top: 5px;
    z-index: 100;
    display: none;
    -webkit-overflow-scrolling: touch;
}

.search-result-item {
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    color: var(--text-color);
}

.search-result-item:hover {
    background-color: rgba(255,255,255,0.1);
}

.search-result-item .path {
    font-size: 12px;
    color: rgba(255,255,255,0.6);
    margin-top: 3px;
}

.highlight {
    background-color: rgba(255,255,0,0.3);
    padding: 0 2px;
    border-radius: 2px;
}

.theme-switcher {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 5px;
    display: flex;
    cursor: pointer;
    z-index: 100;
}

.theme-icon {
    padding: 5px;
    border-radius: 50%;
    transition: all 0.3s ease;
    color: white;
}

.theme-icon.active {
    background: rgba(255,255,255,0.2);
}

.markdown-body img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1.5rem auto;
    border-radius: 4px;
    box-shadow: 0 2px 8px var(--shadow-color);
    background-color: rgba(255,255,255,0.05);
    padding: 4px;
}

.markdown-body iframe,
.markdown-body video {
    max-width: 100%;
    height: auto;
    aspect-ratio: 16/9;
    margin: 1.5rem auto;
    display: block;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    display: none;
}

.sidebar.open ~ .sidebar-overlay {
    display: block;
}

[data-theme="dark"] .markdown-body {
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .nav-item {
    color: rgba(255,255,255,0.8);
}

[data-theme="dark"] #search-input {
    border-color: var(--border-color);
}

[data-theme="dark"] .sidebar-overlay {
    background: rgba(0,0,0,0.7);
}

[data-theme="dark"] .markdown-body img {
    opacity: 0.9;
    filter: brightness(0.95) contrast(1.05);
}

@supports (-webkit-touch-callout: none) {
    .sidebar {
        height: 100%;
        min-height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .nav-container {
        max-height: calc(100vh - 150px);
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 85%;
        max-width: 300px;
        box-shadow: 5px 0 15px rgba(0,0,0,0.2);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .content {
        margin-left: 0;
        width: 100%;
        padding: 1rem;
    }

    .markdown-body {
        padding: 1.5rem;
    }

    .markdown-body img {
        margin: 1rem auto;
        max-width: 100%;
        height: auto;
    }

    body {
        touch-action: manipulation;
        -webkit-overflow-scrolling: touch;
    }

    .nav-item, .search-result-item {
        padding: 12px 0;
        min-height: 44px;
    }

    .menu-toggle {
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .swipe-area {
        position: fixed;
        top: 0;
        left: 0;
        width: 20px;
        height: 100%;
        z-index: 800;
    }
}

@media print {
    .sidebar, .menu-toggle {
        display: none !important;
    }

    .content {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .markdown-body {
        box-shadow: none;
        padding: 0 !important;
        background: transparent !important;
        color: #000 !important;
    }

    img {
        page-break-inside: avoid;
        max-width: 100% !important;
    }
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    overflow-x: auto;
    display: block;
    border: 1px solid var(--border-color);
}

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

.markdown-body th {
    background-color: rgba(255,255,255,0.05);
}

@media (max-width: 768px) {
    .markdown-body table {
        font-size: 0.875rem;
    }

    .markdown-body th, .markdown-body td {
        padding: 0.5rem;
        min-width: 100px; /* Prevents cell content from squeezing */
    }
}

.markdown-body pre {
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
    padding: 1rem;
    overflow-x: auto;
    margin: 1.5rem 0;
    font-size: 0.9rem;
    line-height: 1.5;
}

.markdown-body code {
    font-family: 'Courier New', Courier, monospace;
    background: rgba(0,0,0,0.1);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-size: 0.9em;
}

@media (max-width: 768px) {
    .markdown-body pre {
        font-size: 0.8rem;
        padding: 0.8rem;
        margin: 1rem 0;
    }

    .markdown-body code {
        font-size: 0.8em;
    }
}

/* Improved Markdown body spacing */
.markdown-body {
    line-height: 1.6;
}

/* Headings spacing */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    margin-top: 1.5em;
    margin-bottom: 0.8em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

/* Paragraph spacing */
.markdown-body p {
    margin-bottom: 1.2em;
}

/* List spacing */
.markdown-body ul,
.markdown-body ol {
    margin-bottom: 1.2em;
    padding-left: 2em;
}

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

/* Image captions/source text */
.markdown-body img + em {
    display: block;
    margin-top: -1em;
    margin-bottom: 1.5em;
    font-size: 0.9em;
    color: rgba(255,255,255,0.7);
    text-align: center;
}

/* Tables */
.markdown-body table {
    margin: 1.5em 0;
}

/* Code blocks */
.markdown-body pre {
    margin: 1.5em 0;
}

/* Horizontal rules */
.markdown-body hr {
    margin: 2em 0;
    border: 0;
    border-top: 1px solid rgba(255,255,255,0.1);
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .markdown-body {
        font-size: 0.95rem;
    }

    .markdown-body h1,
    .markdown-body h2,
    .markdown-body h3 {
        margin-top: 1.2em;
    }
}

/* Link styling */
.markdown-body a {
    color: #4facfe; /* Lighter blue */
    text-decoration: none;
    transition: color 0.2s ease;
}

.markdown-body a:hover {
    color: #3a8bf0; /* Slightly darker on hover */
    text-decoration: underline;
}

[data-theme="dark"] .markdown-body a {
    color: #5eb0ff; /* Brighter in dark mode */
}

[data-theme="dark"] .markdown-body a:hover {
    color: #7fc1ff;
}