
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display+SC:wght@400;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Libre+Baskerville:wght@400;700&display=swap');

.katex {
    font-size: 1.15em;
}

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

:root {
    /* Light theme (default) */
    --bg-primary: #f8f9fa;
    --bg-secondary: white;
    --bg-tertiary: #f1f3f4;
    --text-primary: #202124;
    --text-secondary: #5f6368;
    --border-color: #dadce0;
    --border-light: #f1f3f4;
    --accent-color: #1a73e8;
    --accent-hover: #1557b0;
    --accent-bg: #e8f0fe;
    --hover-bg: #f8f9fa;
    --modal-overlay: rgba(0, 0, 0, 0.4);
    --shadow: 0 8px 10px 1px rgba(0, 0, 0, .14), 0 3px 14px 2px rgba(0, 0, 0, .12), 0 5px 5px -3px rgba(0, 0, 0, .2);
    --toc-bg: rgba(255, 255, 255, 0.95);
    --checkbox-border: #22c55e;
    --checkbox-border-hover: #16a34a;
    --checkbox-checked: #22c55e;
    --checkbox-shadow: rgba(34, 197, 94, 0.1);
}

[data-theme="dark"] {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --text-primary: #e6edf3;
    --text-secondary: #7d8590;
    --border-color: #30363d;
    --border-light: #21262d;
    --accent-color: #58a6ff;
    --accent-hover: #388bfd;
    --accent-bg: #1c2128;
    --hover-bg: #21262d;
    --modal-overlay: rgba(0, 0, 0, 0.6);
    --shadow: 0 8px 10px 1px rgba(0, 0, 0, .4), 0 3px 14px 2px rgba(0, 0, 0, .3), 0 5px 5px -3px rgba(0, 0, 0, .5);
    --toc-bg: rgba(22, 27, 34, 0.95);
    --checkbox-border: #30363d;
    --checkbox-border-hover: #58a6ff;
    --checkbox-checked: #22c55e;
    --checkbox-shadow: rgba(88, 166, 255, 0.1);
}

body {
    font-family: 'Libre Baskerville', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    z-index: 100;
}

.header-top {
    display: contents;
}

.header h1 {
    font-family: 'Playfair Display SC', serif;
    font-size: 22px;
    font-weight: 400;
    color: var(--text-primary);
}

.search-container {
    flex: 1;
    max-width: 400px;
    margin: 0 16px;
}

.search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    outline: none;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.2s ease;
}

.search-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 1px var(--accent-color);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.action-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s ease;
}

.action-btn:hover {
    background: var(--accent-hover);
}

.action-btn.secondary {
    background: none;
    color: var(--accent-color);
    border: 1px solid var(--border-color);
}

.action-btn.secondary:hover {
    background: var(--hover-bg);
}

.theme-toggle {
    background: none;
    color: var(--accent-color);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

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

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

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

::-webkit-scrollbar-thumb {
    background: #666;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: #444;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: #666 var(--bg-tertiary);
}

[data-theme="dark"] * {
    scrollbar-color: #444 var(--bg-tertiary);
}

.main-content {
    display: flex;
    height: calc(100vh - 73px - 53px);
}

.sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    order: 1;
}

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

.sidebar-title {
    font-family: 'Playfair Display SC', serif;
    font-size: 16px;
    font-weight: 400;
    color: var(--text-primary);
}

.add-btn {
    background: none;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    font-size: 24px;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.add-btn:hover {
    background: var(--hover-bg);
}

.chapter-item {
    border-bottom: 1px solid var(--border-light);
}

.chapter-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.95em;
    cursor: pointer;
    transition: all 0.2s ease;
    background: transparent;
    position: relative;
}

.chapter-title:hover {
    background: var(--hover-bg);
    color: var(--accent-color);
}

.chapter-title.active {
    background: var(--accent-bg);
    color: var(--accent-color);
    border-right: 3px solid var(--accent-color);
}

.chapter-main {
    display: flex;
    align-items: center;
}

.chapter-icon {
    margin-right: 8px;
    font-size: 18px;
    transition: transform 0.2s ease;
}

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

.file-list {
    list-style: none;
    padding: 0;
    margin: 0;
    background: var(--bg-primary);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.file-list.expanded {
    max-height: 500px;
}

.file-item {
    padding: 12px 20px 12px 45px;
    color: var(--text-secondary);
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.file-item:hover {
    background: var(--hover-bg);
    color: var(--accent-color);
    border-left-color: var(--accent-color);
}

.file-item.active {
    background: var(--hover-bg);
    color: var(--accent-color);
    border-left-color: var(--accent-color);
    font-weight: 500;
}

.file-item::before {
    content: "📄";
    position: absolute;
    left: 25px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8em;
    opacity: 0.6;
}

.file-actions {
    display: none;
    gap: 4px;
}

.file-item:hover .file-actions {
    display: flex;
}

.file-action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 2px;
    font-size: 16px;
    transition: all 0.2s ease;
}

.file-action-btn:hover {
    background: var(--hover-bg);
    color: var(--accent-color);
}

.content-area {
    flex: 1;
    background: var(--bg-secondary);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    max-width: calc(100% - 560px);
    /* Account for both sidebars */
    order: 2;
}

.markdown-content {
    flex: 1;
    width: 100%;
    padding: 40px;
    font-family: "Libre Baskerville", serif;
}

.markdown-content h1 {
    font-family: 'Playfair Display SC', serif;
    font-size: 2.5em;
    margin-bottom: 1em;
    color: var(--text-primary);
    text-align: center;
}

.markdown-content h2 {
    font-family: 'Playfair Display SC', serif;
    font-size: 1.8em;
    margin: 1.5em 0 0.8em;
    color: var(--accent-color);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.markdown-content h3 {
    font-family: 'Playfair Display SC', serif;
    font-size: 1.5em;
    margin: 1.2em 0 0.6em;
    color: var(--accent-hover);
}

.markdown-content p {
    line-height: 1.8;
    margin-bottom: 1.2em;
    text-align: justify;
    font-size: 1.3em;
}

.markdown-content ul {
    list-style: circle;
    margin: 1.3em 0;
    padding-left: 2em;
}

.markdown-content li {
    margin: 0.6em 0;
    line-height: 1.7;
    font-size: 1.3em;
}

.markdown-content code {
    background: var(--bg-tertiary);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: monospace;
    color: var(--accent-color);
}

.markdown-content pre {
    background: var(--bg-tertiary);
    padding: 1.5em;
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid var(--border-color);
    margin: 1.5em 0;
    position: relative;
}

.markdown-content pre code {
    background: none;
    padding: 0;
    font-size: 0.95em;
    line-height: 1.5;
    color: var(--text-primary);
    font-family: 'Consolas', 'Monaco', 'Andale Mono', monospace;
}

.markdown-content pre code p {
    margin: 0;
    color: var(--accent-color);
}

.markdown-code-lang {
    font-size: 1em;
    color: var(--text-secondary);
    position: absolute;
    top: 0;
    left: 10px;
    max-width: 120px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    padding: 4px 8px;
    z-index: 2;
    pointer-events: none;
    border-radius: 0 0 6px 6px;
}

.markdown-code-comment {
    color: var(--text-secondary);
    font-style: italic;
}

.copy-button {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, background-color 0.2s ease;
}

.markdown-content pre:hover .copy-button {
    opacity: 1;
}

.copy-button:hover {
    background: var(--hover-bg);
    color: var(--accent-color);
}

.copy-button.copied {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.markdown-content a {
    color: var(--accent-color);
    text-decoration: none;
}

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

.toc {
    width: 280px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    position: static;
    max-height: none;
    height: calc(100vh - 73px - 53px);
    box-shadow: none;
    border-radius: 0;
    order: 3;
}

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

.toc-title {
    font-family: 'Playfair Display SC', serif;
    font-size: 16px;
    font-weight: 400;
    color: var(--text-primary);
}

.toc-content {
    padding: 0;
}

.toc-item {
    border-bottom: 1px solid var(--border-light);
}

.toc-item:last-child {
    border-bottom: none;
}

.toc-link {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.95em;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.toc-link:hover {
    background: var(--hover-bg);
    color: var(--accent-color);
    border-left-color: var(--accent-color);
}

.toc-link .material-icons {
    margin-right: 12px;
    font-size: 18px;
    color: var(--text-secondary);
    transition: color 0.2s ease;
}

.toc-link:hover .material-icons {
    color: var(--accent-color);
}

.toc-link.h3-link {
    padding-left: 45px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

.toc-link.h3-link .material-icons {
    font-size: 16px;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-overlay);
    z-index: 2000;
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-secondary);
    border-radius: 8px;
    width: 500px;
    max-width: 90vw;
    box-shadow: var(--shadow);
}

.modal-header {
    padding: 24px 24px 20px;
    border-bottom: 1px solid var(--border-light);
}

.modal-title {
    font-family: 'Playfair Display SC', serif;
    font-size: 18px;
    font-weight: 400;
    color: var(--text-primary);
}

.modal-body {
    padding: 20px 24px;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    outline: none;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: border-color 0.2s ease;
}

.form-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 1px var(--accent-color);
}

.drag-area {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 40px 20px;
    text-align: center;
    background: var(--bg-tertiary);
    transition: all 0.3s ease;
    cursor: pointer;
}

.drag-area.drag-over {
    border-color: var(--accent-color);
    background: var(--accent-bg);
}

.drag-area-content {
    color: var(--text-secondary);
}

.drag-area-content h3 {
    margin-bottom: 8px;
    color: var(--text-primary);
}

.modal-actions {
    padding: 16px 24px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    border-top: 1px solid var(--border-light);
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btn-primary {
    background: var(--accent-color);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--accent-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--hover-bg);
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-secondary);
}

.empty-state h3 {
    margin-bottom: 8px;
    font-weight: 400;
    font-size: 18px;
    color: var(--text-primary);
}

.hidden {
    display: none !important;
}

.file-item.hidden,
.chapter-item.hidden {
    display: none;
}

/* Custom checkbox styling */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--checkbox-border);
    border-radius: 4px;
    background: var(--bg-secondary);
    cursor: pointer;
    position: relative;
    margin-right: 8px;
    vertical-align: middle;
    transition: all 0.2s ease;
}

input[type="checkbox"]:hover {
    border-color: var(--checkbox-border-hover);
    box-shadow: 0 0 0 2px var(--checkbox-shadow);
}

input[type="checkbox"]:checked {
    background: var(--checkbox-checked);
    border-color: var(--checkbox-checked);
}

input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 12px;
    font-weight: bold;
}

input[type="checkbox"]:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

input[type="checkbox"]:disabled:hover {
    border-color: var(--checkbox-border);
    box-shadow: none;
}

.footer {
    width: 100%;
    text-align: center;
    padding: 16px 24px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.85rem;
    border-top: 1px solid var(--border-color);
    font-family: 'Libre Baskerville', serif;
}

.footer a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.3s ease;
    margin-left: 16px;
}

.footer a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.footer .container {
    display: flex;
    justify-content: center;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.footer .footer-left {
    display: flex;
    align-items: center;
}

.footer .footer-left p {
    margin: 0;
    display: flex;
    align-items: center;
}

.footer .footer-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.edit-toggle {
    display: inline-flex;
    align-items: center;
    margin-left: 16px;
}

.edit-toggle.hidden {
    display: none;
}

.toggle-switch {
    position: relative;
    width: 30px;
    height: 16px;
    background: var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.toggle-switch.active {
    background: var(--accent-color);
}

.toggle-slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.toggle-switch.active .toggle-slider {
    transform: translateX(14px);
}

@media (max-width: 1200px) and (min-width: 769px) {
    .toc {
        display: none;
    }

    .content-area {
        max-width: calc(100% - 280px);
        /* Only account for left sidebar */
    }
}

@media (max-width: 768px) {
    body {
        overflow: auto;
    }

    .header {
        flex-direction: column;
        gap: 12px;
        padding: 12px 16px;
    }

    .header-top {
        display: flex;
        align-items: center;
        gap: 16px;
        width: 100%;
    }

    .header-actions {
        width: 100%;
        justify-content: center;
        margin-left: 0;
    }

    .main-content {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 73px - 53px);
    }

    .toc {
        display: block !important;
        /* Force show on mobile */
        width: 100%;
        height: auto;
        max-height: none;
        /* Remove height restriction */
        min-height: auto;
        /* Remove minimum height */
        border-left: none;
        border-bottom: 2px solid var(--border-color);
        order: 1;
        /* Move to top */
        overflow-y: visible;
        /* No scrollbar */
    }

    .content-area {
        width: 100%;
        max-width: 100%;
        height: auto;
        min-height: 50vh;
        order: 2;
        /* Keep in middle */
        overflow-y: visible;
        border-bottom: 2px solid var(--border-color);
    }

    .sidebar {
        width: 100%;
        height: auto;
        max-height: 40vh;
        min-height: 200px;
        border-right: none;
        border-top: 2px solid var(--border-color);
        order: 3;
        /* Move to bottom */
        overflow-y: auto;
    }

    .header h1 {
        font-size: 18px;
    }

    .search-container {
        max-width: 200px;
    }

    .markdown-content {
        padding: 20px;
    }

    /* Mobile-specific TOC styling */
    .toc-header {
        background: var(--bg-tertiary);
        margin: 0;
        padding: 16px 20px;
    }

    .toc-title {
        font-size: 14px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    /* Mobile-specific sidebar styling */
    .sidebar-header {
        background: var(--bg-tertiary);
        margin: 0;
        padding: 16px 20px;
        border-bottom: 1px solid var(--border-color);
    }

    .sidebar-title {
        font-size: 14px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
}