:root {
    --primary-color: #1a73e8; /* Google Blue */
    --primary-hover: #1557b0;
    --bg-color: #f8f9fa;
    --surface-color: #ffffff;
    --text-primary: #202124;
    --text-secondary: #5f6368;
    --border-color: #dadce0;
    
    /* Typography */
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --base-font-size: 16px;
    --page-max-width: 800px;
    
    /* Layout */
    --sidebar-width: 300px;
    --header-height: 60px;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: var(--base-font-size);
    overflow: hidden; /* Prevent body scroll, manage scroll internally */
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* App Bar */
.app-bar {
    height: var(--header-height);
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
    box-shadow: 0 1px 2px 0 rgba(60,64,67,0.3), 0 1px 3px 1px rgba(60,64,67,0.15);
    z-index: 10;
}

.app-bar h1 {
    font-size: 1.25rem;
    font-weight: 500;
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.icon-btn:hover {
    background-color: rgba(0,0,0,0.04);
}

/* Main Container */
.app-container {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 20;
}

.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-header {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.search-container {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.search-container input {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-container input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}

.toc-list {
    list-style: none;
    overflow-y: auto;
    flex-grow: 1;
    padding: 8px 0;
}

.toc-list li {
    padding: 8px 24px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-secondary);
    transition: background-color 0.2s, color 0.2s;
}

.toc-list li:hover {
    background-color: rgba(0,0,0,0.04);
}

.toc-list li.active {
    background-color: rgba(26, 115, 232, 0.1);
    color: var(--primary-color);
    font-weight: 500;
}

/* Overlay */
.overlay {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0,0,0,0.5);
    z-index: 15;
    opacity: 0;
    transition: opacity 0.3s;
}

/* Main Content Area */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    position: relative;
    scroll-behavior: smooth;
}

/* Pages Container (replaces the old single article flow) */
.pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding: 0;
    gap: 0;
    background-color: var(--bg-color);
}

.pages-container.horizontal-swipe {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    align-items: stretch;
    padding: 0;
    margin-top: 0;
    height: 100%;
}

.markdown-body {
    flex: 0 0 auto;
    width: 100%;
    max-width: var(--page-max-width);
    margin: 0;
    padding: 40px 24px;
    background-color: var(--surface-color);
    border-radius: 0;
    box-shadow: none;
    border-bottom: 2px dashed var(--border-color);
    transition: font-size 0.3s ease;
    transform-origin: top center;
    word-wrap: break-word;
    overflow-wrap: break-word;
    overflow-x: hidden;
}

/* Dual page configuration */
.pages-container.dual-page {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
    gap: 20px;
    padding: 24px;
    max-width: calc(var(--page-max-width) * 2);
    margin: 0 auto;
}

.pages-container.dual-page .markdown-body {
    max-width: none;
    width: 100%;
    border-bottom: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
    border-radius: 8px;
}

.pages-container.horizontal-swipe .markdown-body {
    flex: 0 0 100vw;
    scroll-snap-align: center;
    max-width: 100vw;
    margin: 0;
    box-shadow: none;
    height: 100%;
    overflow-y: auto;
    border-bottom: none;
    border-right: 1px solid var(--border-color);
}

/* Status Indicator */
.status-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    pointer-events: none;
    z-index: 100;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    color: #000;
}

.markdown-body p {
    margin-bottom: 1.2em;
    max-width: 100%;
}

.katex-display {
    overflow-x: auto;
    overflow-y: hidden;
}

/* Images within markdown */
.markdown-body img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 2em auto;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Tables within markdown */
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5em;
    font-size: 0.9em;
    display: block;
    overflow-x: auto;
    white-space: nowrap;
}

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

.markdown-body th {
    background-color: #f1f3f4;
    font-weight: 600;
}

/* Settings Bar */
.settings-bar {
    position: sticky;
    top: 0;
    background: transparent;
    display: flex;
    justify-content: flex-end;
    padding: 8px 24px;
    pointer-events: none; /* Let clicks pass through except on buttons */
}
.settings-bar button {
    pointer-events: auto;
    background: var(--surface-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    margin-left: 8px;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    max-width: var(--page-max-width);
    margin: 0 auto;
    width: 100%;
    background-color: var(--bg-color);
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    background-color: #fff;
    border-radius: 20px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    color: var(--primary-color);
    transition: background-color 0.2s;
}

.nav-btn:hover:not(:disabled) {
    background-color: #f1f3f4;
}

.nav-btn:disabled {
    color: #9aa0a6;
    cursor: not-allowed;
    box-shadow: none;
    background-color: transparent;
}

#page-indicator {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.loader {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }
    
    .overlay.open {
        display: block;
        opacity: 1;
    }

    .app-bar #menu-btn {
        display: block; /* Typically visible on mobile */
    }

    .markdown-body {
        margin: 0;
        border-radius: 0;
        min-height: calc(100vh - var(--header-height));
        padding: 24px 16px;
    }
    
    .pagination {
        padding: 16px;
    }
}

/* Desktop default states */
@media (min-width: 769px) {
    .mobile-only {
        display: none;
    }
}

/* Print Styles */
@media print {
    body {
        overflow: visible;
        background-color: #fff;
    }
    .app-bar,
    .sidebar,
    .overlay,
    .settings-bar,
    .status-indicator,
    .loader {
        display: none !important;
    }
    .app-container,
    .main-content,
    .pages-container {
        display: block !important;
        overflow: visible !important;
        height: auto !important;
    }
    .markdown-body {
        page-break-after: always;
        border: none !important;
        box-shadow: none !important;
        margin: 0 !important;
        padding: 0 !important;
        max-width: none !important;
    }
    /* Ensure no dual page grid on print */
    .pages-container.dual-page {
        display: block !important;
    }
    .pages-container.horizontal-swipe .markdown-body {
        flex: none;
        max-width: none;
        height: auto;
        overflow-y: visible;
    }
}
