/* Blockquotes */
.e-content blockquote {
    margin: 1rem 0;
    padding: 0.5rem 1rem;
    border-left: 3px solid var(--accent-color, gold);
    background-color: rgba(255, 255, 255, 0.04);
    color: var(--text-primary, #ccc);
    font-style: italic;
    border-radius: 0 4px 4px 0;
}

.e-content blockquote p {
    margin: 0.4rem 0;
}

.e-content blockquote p:first-child {
    margin-top: 0;
}

.e-content blockquote p:last-child {
    margin-bottom: 0;
}

.e-content blockquote blockquote {
    margin: 0.6rem 0;
    border-left-color: var(--text-muted, #888);
}

body.light-mode .e-content blockquote {
    background-color: rgba(0, 0, 0, 0.04);
    color: var(--text-secondary, #444);
    border-left-color: var(--accent-color, #b8860b);
}

body.light-mode .e-content blockquote blockquote {
    border-left-color: var(--text-muted-alt, #666);
}

/* Inline code */
.e-content code {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.9em;
    padding: 0.15em 0.35em;
    background-color: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    color: var(--text-primary, #fff);
}

body.light-mode .e-content code {
    background-color: rgba(0, 0, 0, 0.5);
    color: var(--text-primary-alt, #1a1a1a);
}

/* Fenced code blocks (skip the special embed / attachment / link-button
   blocks decodeEmbeds() rewrites — those are handled separately). */
.e-content pre {
    margin: 1rem 0;
    padding: 0.85rem 1rem;
    background-color: var(--bg-tertiary, #252525);
    color: var(--text-primary, #fff);
    border: 1px solid var(--border-color, #404040);
    border-radius: 6px;
    overflow-x: auto;
    line-height: 1.5;
    font-size: 0.9rem;
}

.e-content pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
    color: inherit;
    white-space: pre;
}

body.light-mode .e-content pre {
    background-color: var(--bg-tertiary-alt, #ffffff);
    color: var(--text-primary-alt, #1a1a1a);
    border-color: var(--border-color-alt, #ccc);
}

/* Backlinks ("Referenced by") */
.backlinks-section {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color, #404040);
    font-size: 0.9rem;
}

.backlinks-heading {
    margin: 0 0 0.6rem 0;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted, #888);
    font-weight: 600;
}

.backlinks-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.backlinks-item {
    margin: 0;
}

.backlinks-link {
    color: var(--text-secondary, #ccc);
    text-decoration: none;
    border-bottom: 1px dotted var(--border-color, #404040);
}

.backlinks-link:hover {
    color: var(--accent-color, gold);
    border-bottom-color: var(--accent-color, gold);
}

body.light-mode .backlinks-section {
    border-top-color: var(--border-color-alt, #ccc);
}

body.light-mode .backlinks-heading {
    color: var(--text-muted-alt, #666);
}

body.light-mode .backlinks-link {
    color: var(--text-secondary-alt, #444);
    border-bottom-color: var(--border-color-alt, #ccc);
}

body.light-mode .backlinks-link:hover {
    color: var(--accent-color-alt, #b8860b);
    border-bottom-color: var(--accent-color-alt, #b8860b);
}

/* Wikilinks */
.wikilink {
    color: var(--accent-color, #7aa2f7);
    text-decoration: none;
    border-bottom: 1px solid currentColor;
    cursor: pointer;
}

.wikilink:hover {
    opacity: 0.8;
}

.wikilink-broken {
    color: var(--text-muted, #888);
    border-bottom: 1px dashed currentColor;
    cursor: not-allowed;
    pointer-events: none;
}

body.light-mode .wikilink {
    color: var(--accent-color-alt, #b8860b);
}

body.light-mode .wikilink-broken {
    color: var(--text-muted-alt, #666);
}

/* Theme CSS Variables */
:root {
    --bg-primary: #181818;
    --bg-secondary: #303030;
    --bg-tertiary: #252525;
    --text-primary: #fff;
    --text-secondary: #ccc;
    --text-muted: #888;
    --border-color: #404040;
    --accent-color: gold;
    --accent-hover: #ffe780;

    --bg-primary-alt: #e0e0e0;
    --bg-secondary-alt: #f5f5f5;
    --bg-tertiary-alt: #ffffff;
    --text-primary-alt: #1a1a1a;
    --text-secondary-alt: #444;
    --text-muted-alt: #666;
    --border-color-alt: #ccc;
    --accent-color-alt: #b8860b;
    --accent-hover-alt: #996515;
}

/* Light mode overrides */
body.light-mode {
    --bg-primary: #e0e0e0;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #444;
    --text-muted: #666;
    --border-color: #ccc;
    --accent-color: #b8860b;
    --accent-hover: #996515;

    --bg-primary-alt: #181818;
    --bg-secondary-alt: #303030;
    --bg-tertiary-alt: #252525;
    --text-primary-alt: #fff;
    --text-secondary-alt: #ccc;
    --text-muted-alt: #888;
    --border-color-alt: #404040;
    --accent-color-alt: #b8860b;
    --accent-hover-alt: #ffe780;
}

body {
    background-color: var(--bg-primary);
    margin: 0;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    font-family: Arial, Helvetica, sans-serif;
    transition: background-color 0.3s ease, color 0.3s ease;
}

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

a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
    cursor: pointer;
}

/* Site layout: sidebar + main */
.site-layout {
    display: flex;
    min-height: 100vh;
    align-items: flex-start;
}

.site-main {
    margin: 50px;
    flex: 1;
    min-width: 0;
}

/* Sidebar — sized to content with a min/max so long page or folder names
   push it wider, but never past half the viewport. Sticky-positioned so it
   stays visible while the main content scrolls. */
.site-sidebar {
    flex-shrink: 0;
    width: max-content;
    min-width: 220px;
    max-width: 30vw;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 16px 0;
    overflow-y: auto;
    position: sticky;
    top: 0;
    align-self: stretch;
    height: 100vh;
    z-index: 1010;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Wrap long page/folder names instead of overflowing the sidebar. */
.sidebar-folder-label,
.sidebar-page-link {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.sidebar-search {
    padding: 0 12px 12px;
    position: sticky;
    top: 0;
    background-color: var(--bg-secondary);
    z-index: 1;
}

.sidebar-search-input {
    width: 100%;
    padding: 6px 10px;
    font-size: 14px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s ease;
    box-sizing: border-box;
}

.sidebar-search-input:focus {
    border-color: var(--accent-color);
}

.sidebar-search-results {
    margin-top: 8px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
}

.sidebar-search-result {
    display: block;
    padding: 6px 8px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 3px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-search-result:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    text-decoration: none;
}

.sidebar-search-result-title {
    font-size: 14px;
    font-weight: 600;
}

.sidebar-search-result-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    overflow-wrap: anywhere;
}

.sidebar-search-empty {
    padding: 6px 8px;
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
}

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

.sidebar-tree-item {
    margin: 0;
}

.sidebar-folder-row {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 15px;
    user-select: none;
    transition: background-color 0.15s ease;
}

.sidebar-folder-row:hover {
    background-color: var(--bg-tertiary);
}

.sidebar-arrow {
    width: 20px;
    font-size: 18px;
    flex-shrink: 0;
    color: var(--text-muted);
}

.sidebar-folder-icon {
    margin-right: 6px;
    font-size: 16px;
}

.sidebar-folder-label {
    font-weight: 600;
    text-transform: capitalize;
}

.sidebar-page-link {
    display: block;
    padding: 7px 12px 7px 28px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 15px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-page-link:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    text-decoration: none;
}

.sidebar-page-link.active {
    color: var(--accent-color);
    background-color: var(--bg-tertiary);
    border-left: 3px solid var(--accent-color);
    padding-left: 25px;
}

.sidebar-children .sidebar-page-link {
    padding-left: 44px;
}

.sidebar-children .sidebar-page-link.active {
    padding-left: 41px;
}

.sidebar-children .sidebar-children .sidebar-page-link {
    padding-left: 60px;
}

.sidebar-children .sidebar-children .sidebar-page-link.active {
    padding-left: 57px;
}

/* Hamburger (mobile only) */
.sidebar-hamburger {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1100;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 20px;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.sidebar-backdrop {
    display: none;
}

.image-container {
    margin-left: 5%;
    margin-right: 5%;
    margin-bottom: 20px;
}

.h-entry {
    margin-left: 5%;
    margin-right: 5%;
    margin-bottom: 20px;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    border-color: var(--border-color);
    border-style: solid;
    border-width: 1px;
    padding: 20px;
    transition: background-color 0.3s ease;
}

.h-entry h1 {
    text-align: center;
    font-size: 24pt;
}

.h-entry h2 {
    text-align: center;
    font-size: 20pt;
}

.h-entry h3,
.h-entry h4,
.h-entry h5,
.h-entry h6 {
    text-align: center;
    font-size: 18pt;
}

.h-entry p {
    font-size: 16pt;
}

.h-entry ul,
.h-entry ol {
    font-size: 16pt;
    margin: 1em 0;
    padding-left: 2em;
}

.h-entry li {
    margin-bottom: 0.5em;
    line-height: 1.5;
}

.h-entry ul li {
    list-style-type: disc;
}

.h-entry ol li {
    list-style-type: decimal;
}

.h-entry .p-author,
.h-entry .dt-published,
.h-entry .dt-updated {
    display: block;
    text-align: center;
    font-size: 14pt;
}

.embed-container {
    text-align: center;
    margin-bottom: 20px;
}

img {
    max-width: 100%;
    max-height: 400px;
}

.image-caption {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 8px;
    margin-bottom: 16px;
}

table {
    width: auto;
    border-collapse: collapse;
    margin: 16px auto;
    background-color: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    transition: background-color 0.3s ease;
}

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

th {
    background-color: var(--bg-primary);
    font-weight: bold;
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background-color: var(--border-color);
}

/* Floating footer */
.pluribus-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--bg-secondary);
    padding: 8px 20px;
    text-align: center;
    font-size: 14pt;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.pluribus-footer a {
    color: var(--accent-color);
}

.pluribus-footer a:hover {
    color: var(--accent-hover);
}

.history-link {
    cursor: pointer;
    color: var(--text-secondary);
}

.history-link:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

/* Theme toggle in footer */
.theme-toggle {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

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

/* History modal */
.history-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}

.history-modal {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.history-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.history-modal-header h3 {
    margin: 0;
    color: var(--text-primary);
}

.history-close {
    background: transparent;
    border: none;
    color: #ff4444;
    font-size: 24px;
    cursor: pointer;
}

.history-item {
    border-bottom: 1px solid var(--border-color);
    padding: 10px 0;
}

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

.history-sha {
    color: var(--accent-color);
    font-family: monospace;
}

.history-date {
    color: var(--text-muted);
    font-size: 12px;
}

.history-message {
    margin-top: 5px;
}

.history-author {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 5px;
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-changes {
    margin-top: 8px;
    padding: 8px;
    background-color: var(--bg-primary);
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
}

.history-change-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
}

.change-icon {
    width: 16px;
    text-align: center;
    font-weight: bold;
}

.change-file {
    word-break: break-all;
}

.change-added .change-icon {
    color: #4caf50;
}

.change-modified .change-icon {
    color: #ff9800;
}

.change-deleted .change-icon {
    color: #f44336;
}

.change-added .change-file {
    color: #4caf50;
}

.change-modified .change-file {
    color: var(--text-primary);
}

.change-deleted .change-file {
    color: #f44336;
    text-decoration: line-through;
}

/* Line-level diff styles */
.history-diff {
    margin-top: 4px;
    margin-left: 24px;
    padding: 4px;
    background-color: var(--bg-secondary);
    border-radius: 4px;
    overflow-x: auto;
}

.diff-line {
    display: flex;
    white-space: pre;
    line-height: 1.4;
}

.diff-prefix {
    width: 16px;
    flex-shrink: 0;
    user-select: none;
    font-weight: bold;
}

.diff-content {
    flex: 1;
}

.diff-add {
    background-color: rgba(33, 150, 243, 0.15);
    color: #2196f3;
}

.diff-del {
    background-color: rgba(244, 67, 54, 0.15);
    color: #f44336;
}

.diff-truncated {
    color: var(--text-muted);
    font-style: italic;
    margin-top: 4px;
}

/* PDF Download Button */
.pdf-download-container {
    text-align: center;
    margin: 20px 0;
}

.pdf-download-button {
    display: inline-block;
    padding: 12px 24px;
    background-color: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 16pt;
    text-decoration: none;
    transition: background-color 0.3s ease, border-color 0.3s ease, transform 0.2s ease;
}

.pdf-download-button:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
    text-decoration: none;
    transform: scale(1.02);
}

.pdf-download-button:active {
    transform: scale(0.98);
}

.pdf-icon {
    margin-right: 8px;
}

/* Link Button */
.link-button-container {
    text-align: center;
    margin: 20px 0;
}

.link-button {
    display: inline-block;
    padding: 12px 24px;
    background-color: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 16pt;
    text-decoration: none;
    transition: background-color 0.3s ease, border-color 0.3s ease, transform 0.2s ease;
}

.link-button:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
    text-decoration: none;
    transform: scale(1.02);
}

.link-button:active {
    transform: scale(0.98);
}

.link-icon {
    margin-right: 8px;
}

/* Add padding to body to account for fixed footer */
body {
    padding-bottom: 50px;
}

@media (max-width: 768px) {
    .site-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        /* Drawer can grow to fill the screen if content needs the room. */
        max-width: 100vw;
        padding-top: 60px;
        height: 100vh;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: none;
    }

    .site-sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 12px rgba(0, 0, 0, 0.3);
    }

    .sidebar-hamburger {
        display: block;
    }

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

    .sidebar-backdrop.visible {
        display: block;
    }

    .site-main {
        width: 100%;
        margin: 20px;
    }

    .h-entry {
        margin-left: 8px;
        margin-right: 8px;
    }

    .image-container {
        margin-left: 8px;
        margin-right: 8px;
    }

    .h-entry h1 {
        font-size: 16pt;
    }

    .h-entry h2 {
        font-size: 14pt;
    }

    .h-entry h3,
    .h-entry h4,
    .h-entry h5,
    .h-entry h6 {
        font-size: 12pt;
    }

    .h-entry p {
        font-size: 10pt;
    }

    .h-entry ul,
    .h-entry ol {
        font-size: 10pt;
    }

    .h-entry .p-author,
    .h-entry .dt-published,
    .h-entry .dt-updated {
        font-size: 8pt;
    }

    .pluribus-footer {
        font-size: 8pt;
    }
}

/* Math (KaTeX) — display blocks and fallback styling for unparsable LaTeX. */
.e-content .math-display {
    margin: 1rem 0;
    overflow-x: auto;
}

.e-content .katex-fallback {
    color: var(--text-muted, #b89a4d);
    border: 1px dashed var(--text-muted, #b89a4d);
    background: transparent;
}

.e-content .katex-fallback-display {
    display: block;
    padding: 0.5rem 0.75rem;
    margin: 1rem 0;
    text-align: center;
    white-space: pre-wrap;
}