@import url('https://fonts.googleapis.com/css2?family=Old+Standard+TT:ital,wght@0,400;0,700;1,400&display=swap');

/*
 * CUSTOM CSS OVERRIDES
 *
 * This file is for customizing the appearance of your wiki.
 */

/* --- Sidebar 1.5× wider --- */
:root {
    --sidebar-width: 420px !important;
    --sidebar-right-width: 420px;
    --toc-bg: #fafafa;
}

[data-theme="dark"] {
    --toc-bg: #1e1e1e;
}

/* --- Sidebars above content plane --- */
.sidebar {
    z-index: 10;
    box-shadow: 2px 0 12px rgba(0,0,0,0.08);
}
.toc-sidebar {
    box-shadow: -2px 0 12px rgba(0,0,0,0.08);
}
[data-theme="dark"] .sidebar {
    box-shadow: 2px 0 12px rgba(0,0,0,0.3);
}
[data-theme="dark"] .toc-sidebar {
    box-shadow: -2px 0 12px rgba(0,0,0,0.3);
}

/* --- Content centered between two sidebars --- */
.content {
    margin-left: calc(var(--sidebar-width) + (100vw - var(--sidebar-width) - var(--sidebar-right-width) - var(--content-max-width)) / 2) !important;
    width: var(--content-max-width) !important;
}

/* --- Justify text & Old Standard TT font --- */
.content,
.markdown-content,
.content h1, .content h2, .content h3, .content h4, .content h5, .content h6,
.content a, .content blockquote, .content td, .content th {
    font-family: 'Old Standard TT', 'Georgia', 'Times New Roman', serif;
}

.markdown-content p,
.markdown-content li,
.content p,
.content li {
    text-align: justify;
    font-size: clamp(15px, calc(var(--content-max-width) - 96px) / 36, 24px);
}

/* --- Headings: progressive sizes, left-aligned, h6 = normal text size --- */
.content h1,
.content h2,
.content h3,
.content h4,
.content h5,
.content h6 {
    text-align: left !important;
    font-weight: 600;
    hyphens: none !important;
    word-break: normal !important;
    overflow-wrap: normal !important;
}

.content h1 { font-size: 32px; text-wrap: pretty; }
.content h2 { font-size: 28px; text-wrap: pretty; }
.content h3 { font-size: 24px; text-wrap: pretty; }
.content h4 { font-size: 20px; text-wrap: pretty; }
.content h5 { font-size: 18px; text-wrap: pretty; }
.content h6 { font-size: 16px; text-wrap: pretty; }

/* --- Section edit links [ред.] next to headings --- */
.section-edit-link {
    margin-left: 8px;
    font-size: 14px;
    font-weight: 400;
    color: var(--text-muted);
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.15s;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    font-family: inherit;
    line-height: inherit;
}
.section-edit-link:hover {
    color: var(--primary-color);
    opacity: 1;
}
.content h2:hover .section-edit-link,
.content h3:hover .section-edit-link,
.content h4:hover .section-edit-link {
    opacity: 0.6;
}

/* --- Section editor modal --- */
.section-editor-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 10001;
    align-items: center;
    justify-content: center;
}
.section-editor-overlay.active {
    display: flex;
}
.section-editor-box {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: min(800px, 90vw);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 24px rgba(0,0,0,0.2);
}
.section-editor-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.section-editor-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 0 4px;
}
.section-editor-close:hover { color: var(--text-color); }
.section-editor-close:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}
.section-editor-body {
    padding: 12px 16px;
    flex: 1;
    overflow: auto;
}
.section-editor-body textarea {
    width: 100%;
    min-height: 300px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 10px;
    font-family: 'Fira Code', Consolas, Monaco, monospace;
    font-size: 14px;
    line-height: 1.5;
    background: var(--code-bg);
    color: var(--text-color);
    resize: vertical;
    box-sizing: border-box;
}
.section-editor-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
.section-editor-btn {
    padding: 6px 16px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    font-size: 14px;
    background: var(--bg-color);
    color: var(--text-color);
}
.section-editor-btn.primary {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}
.section-editor-btn:hover { opacity: 0.85; }
.section-editor-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* --- Footnote tooltip popup --- */
.footnote-tooltip {
    position: fixed;
    z-index: 10001;
    width: auto;
    max-width: min(540px, 85vw);
    max-height: 40vh;
    overflow-y: auto;
    padding: 10px 14px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.18);
    font-family: 'Old Standard TT', 'Georgia', 'Times New Roman', serif;
    font-size: 18px;
    line-height: 1.55;
    text-align: justify;
    color: var(--text-color);
    opacity: 0;
    transition: opacity 0.15s ease;
}
.footnote-tooltip.visible {
    opacity: 1;
    pointer-events: auto;
}
.footnote-tooltip p {
    margin: 0.2em 0;
}

/* --- Breadcrumbs: centered with content, always on top --- */
.breadcrumbs {
    z-index: 9999 !important;
    left: calc(var(--sidebar-width) + (100vw - var(--sidebar-width) - var(--sidebar-right-width) - var(--content-max-width)) / 2) !important;
    right: auto !important;
    width: var(--content-max-width) !important;
    box-sizing: border-box !important;
    transition: transform 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
}

/* Breadcrumbs collapse toggle */
.breadcrumbs-toggle {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 2px;
    z-index: 10;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 0 0 4px 4px;
    cursor: pointer;
    width: 22px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    font-size: 10px;
    line-height: 1;
    padding: 0;
    opacity: 0.5;
    transition: opacity 0.2s;
}
.breadcrumbs-toggle:hover {
    opacity: 1;
}
.breadcrumbs-toggle:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Collapsed breadcrumbs */
body.breadcrumbs-collapsed .breadcrumbs {
    transform: translateY(-100%) !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    overflow: hidden;
    opacity: 0;
    border-bottom: none !important;
}

/* Floating expand tab for breadcrumbs when collapsed */
.breadcrumbs-expand-tab {
    display: none;
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    top: 2px;
    z-index: 10000;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 0 0 4px 4px;
    cursor: pointer;
    width: 24px;
    height: 18px;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    font-size: 12px;
    line-height: 1;
    padding: 0;
    opacity: 0.7;
    transition: opacity 0.2s ease;
    user-select: none;
}

body.breadcrumbs-collapsed .breadcrumbs-expand-tab {
    display: flex;
}

.breadcrumbs-expand-tab:hover {
    opacity: 1;
    color: var(--primary-color);
}
.breadcrumbs-expand-tab:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

body.breadcrumbs-collapsed .content {
    padding-top: 16px !important;
}

/* Toolbar above breadcrumbs path */
.breadcrumbs-container {
    flex-direction: column !important;
    height: auto !important;
    gap: 2px !important;
    align-items: flex-start !important;
}
.breadcrumbs-path {
    order: 2;
}
.page-toolbar {
    order: 1;
    margin-left: 0 !important;
    padding-left: 0 !important;
}

/* --- Left sidebar: normal font weight, not bold --- */
.nav-item a,
.nav-item.directory > a {
    font-weight: 400 !important;
}

/* Nav arrow: clickable for navigation */
.nav-arrow {
    cursor: pointer;
    padding: 4px;
}

/* Loading state for directory fetch */
.nav-item.directory.loading > a {
    opacity: 0.5;
}

/* --- Right sidebar: table of contents --- */
.toc-sidebar {
    position: fixed;
    right: 0;
    top: 0;
    width: var(--sidebar-right-width);
    height: 100vh;
    background: var(--toc-bg);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    z-index: 100;
    padding: 24px 20px;
    box-sizing: border-box;
    font-size: 14px;
    line-height: 1.5;
    transition: transform 0.3s ease;
}

.toc-title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-color);
}

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

.toc-sidebar li {
    margin: 0;
}

.toc-sidebar a {
    display: block;
    color: var(--text-muted);
    text-decoration: none;
    padding: 4px 0;
    border-radius: 4px;
    transition: color 0.15s ease;
    overflow-wrap: break-word;
    word-break: break-word;
}

.toc-sidebar a:hover {
    color: var(--primary-color);
}
.toc-sidebar a:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.toc-sidebar a.active {
    color: var(--primary-color);
    font-weight: 500;
}

li.toc-h2 { padding-left: 0; }
li.toc-h3 { padding-left: 2ch; }
li.toc-h4 { padding-left: 4ch; }
li.toc-h5 { padding-left: 6ch; }
li.toc-h6 { padding-left: 8ch; }


/* ================================================================
   COLLAPSIBLE SIDEBARS — FLOATING TOGGLE BUTTONS
   ================================================================ */

/* Desktop transition for left sidebar */
@media (min-width: 951px) {
    .sidebar {
        transition: transform 0.3s ease;
    }
}

/* --- Left sidebar collapse --- */
body.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
}

/* --- Right TOC sidebar collapse --- */
body.toc-collapsed .toc-sidebar {
    transform: translateX(100%);
}

/* ================================================================
   FLOATING TOGGLE BUTTONS (fixed, always on top, independent)
   ================================================================ */

/* --- Left sidebar toggle --- */
.sidebar-toggle-float {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%) translateX(var(--sidebar-width));
    z-index: 2000;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-left: none;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    width: 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    padding: 0;
    margin: 0;
    transition: transform 0.3s ease, background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    user-select: none;
    opacity: 1;
}

.sidebar-toggle-float:hover {
    background: var(--primary-color);
    color: #fff;
    box-shadow: 2px 0 14px rgba(0,0,0,0.2);
}
.sidebar-toggle-float:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Move to screen edge when sidebar collapsed */
body.sidebar-collapsed .sidebar-toggle-float {
    transform: translateY(-50%) translateX(0);
    border-left: 1px solid var(--border-color);
    border-radius: 0 8px 8px 0;
}

/* --- Right TOC toggle --- */
.toc-toggle-float {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%) translateX(calc(-1 * var(--sidebar-right-width)));
    z-index: 2000;
    background: var(--toc-bg);
    border: 1px solid var(--border-color);
    border-right: none;
    border-radius: 8px 0 0 8px;
    cursor: pointer;
    width: 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    padding: 0;
    margin: 0;
    transition: transform 0.3s ease, background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: -2px 0 8px rgba(0,0,0,0.1);
    user-select: none;
    opacity: 1;
}

.toc-toggle-float:hover {
    background: var(--primary-color);
    color: #fff;
    box-shadow: -2px 0 14px rgba(0,0,0,0.2);
}
.toc-toggle-float:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Move to screen edge when TOC collapsed */
body.toc-collapsed .toc-toggle-float {
    transform: translateY(-50%) translateX(0);
    border-right: 1px solid var(--border-color);
    border-radius: 8px 0 0 8px;
}


/* --- Footnotes: hide separator line --- */
.footnotes > hr {
    display: none;
}

/* --- Mobile TOC: hidden on desktop, visible on mobile --- */
.mobile-toc-btn,
.mobile-toc-overlay {
    display: none;
}

/* ================================================================
   RESPONSIVE
   ================================================================ */

@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .toc-sidebar,
    .sidebar-toggle-float,
    .toc-toggle-float,
    .breadcrumbs,
    .breadcrumbs-toggle,
    .breadcrumbs-expand-tab,
    .footnote-tooltip,
    .section-edit-link {
        transition: none !important;
    }
}

/* --- Narrow screens: hide TOC, keep left sidebar --- */
@media (max-width: 1200px) {
    .toc-sidebar {
        display: none !important;
    }
    .toc-toggle-float {
        display: none !important;
    }
    .content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: none !important;
        padding-left: 48px !important;
        padding-right: 48px !important;
    }
}

/* --- Mobile (< 950px) --- */
@media (max-width: 950px) {
    /* Hide floating sidebar/toc toggle buttons */
    .sidebar-toggle-float,
    .toc-toggle-float,
    .sidebar-expand-tab,
    .toc-expand-tab,
    .breadcrumbs-expand-tab,
    .breadcrumbs-toggle {
        display: none !important;
    }

    /* Disable custom sidebar collapse — use original hamburger */
    body.sidebar-collapsed .sidebar {
        transform: none;
    }
    body.sidebar-collapsed .breadcrumbs {
        left: 47px !important;
        right: 0 !important;
        width: auto !important;
    }

    /* Content full-width */
    body.sidebar-collapsed .content,
    body.toc-collapsed .content,
    body.sidebar-collapsed.toc-collapsed .content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* Hide breadcrumbs on mobile */
    .breadcrumbs {
        display: none !important;
    }

    /* Content: balanced padding, no space for breadcrumbs */
    .content {
        padding: 8px 12px 16px 12px !important;
    }

    /* Section editor: full-width modal */
    .section-editor-box {
        width: 96vw;
        max-height: 90vh;
    }
    .section-editor-body textarea {
        min-height: 200px;
        font-size: 16px;
    }

    /* Headings: smaller on mobile */
    .content h1 { font-size: 24px !important; }
    .content h2 { font-size: 20px !important; }
    .content h3 { font-size: 18px !important; }
    .content h4 { font-size: 16px !important; }
    .content h5 { font-size: 15px !important; }
    .content h6 { font-size: 14px !important; }

    /* Body text: fixed size on mobile */
    .markdown-content p,
    .content p {
        font-size: 15px !important;
    }

    /* TOC floating button for mobile */
    .mobile-toc-btn {
        display: flex;
        position: fixed;
        right: calc(12px + env(safe-area-inset-right, 0px));
        bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        z-index: 2000;
        background: var(--primary-color);
        color: #fff;
        border: none;
        border-radius: 50%;
        cursor: pointer;
        width: 48px;
        height: 48px;
        align-items: center;
        justify-content: center;
        font-size: 22px;
        box-shadow: 0 4px 16px rgba(0,0,0,0.25);
        user-select: none;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-toc-btn:active {
        opacity: 0.85;
    }
    .mobile-toc-btn:focus-visible {
        outline: 2px solid var(--primary-color);
        outline-offset: 3px;
    }

    /* TOC modal overlay */
    .mobile-toc-overlay {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.45);
        z-index: 10001;
        align-items: center;
        justify-content: center;
        touch-action: manipulation;
    }
    .mobile-toc-overlay.active {
        display: flex;
    }
    .mobile-toc-panel {
        background: var(--bg-color);
        border-radius: 12px;
        width: 90vw;
        max-height: 80vh;
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: 20px;
        box-shadow: 0 4px 24px rgba(0,0,0,0.3);
    }
    .mobile-toc-title {
        font-weight: 600;
        font-size: 18px;
        margin-bottom: 16px;
        padding-bottom: 10px;
        border-bottom: 1px solid var(--border-color);
        color: var(--text-color);
    }
    .mobile-toc-panel ul {
        list-style: none;
        padding: 0;
        margin: 0;
    }
    .mobile-toc-panel li {
        margin: 0;
        padding: 6px 0;
    }
    .mobile-toc-panel a {
        display: block;
        color: var(--text-muted);
        text-decoration: none;
        padding: 4px 8px;
        border-radius: 4px;
    font-size: 18px;
    }
    .mobile-toc-panel a:hover,
    .mobile-toc-panel a:active {
        color: var(--primary-color);
        background: var(--hover-bg);
    }
    .mobile-toc-panel a:focus-visible {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
    }
    .mobile-toc-h2 {}
    .mobile-toc-h3 { padding-left: 16px; }
    .mobile-toc-h4 { padding-left: 32px; }
    .mobile-toc-h5 { padding-left: 44px; }
    .mobile-toc-h6 { padding-left: 52px; }
}

/* --- Super heading (:::super-heading) --- */
.super-heading {
    font-size: 48px;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    font-family: 'Old Standard TT', 'Georgia', 'Times New Roman', serif;
    margin: 1.5em 0 0.5em;
    color: var(--text-color);
}
@media (max-width: 950px) {
    .super-heading { font-size: 32px; }
}

/* --- Epigraph (:::epigraph) --- */
.epigraph {
    margin-left: 50%;
    font-family: 'Old Standard TT', 'Georgia', 'Times New Roman', serif;
    font-size: inherit;
    line-height: inherit;
    color: var(--text-color);
    text-align: justify;
    padding-left: 1em;
    border-left: 2px solid var(--border-color);
}

/* --- Blockquote: transparent bg, left padding only --- */
.content blockquote {
    padding: 0 1em;
    background: transparent;
}
.content blockquote > p:first-child {
    margin-top: 0;
}
.content blockquote > p:last-child {
    margin-bottom: 0;
}

/* --- Skip link for keyboard nav --- */
.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    z-index: 100000;
    padding: 8px 16px;
    background: var(--primary-color);
    color: #fff;
    text-decoration: none;
    font-size: 14px;
}
.skip-link:focus {
    top: 0;
}

/* --- Scroll margin for heading anchors --- */
*[id] {
    scroll-margin-top: 80px;
}

/* --- Footnotes: prevent overflow, proper padding --- */
.footnotes {
    max-width: 100%;
    box-sizing: border-box;
    padding-left: 0;
    margin-left: 0;
}
.footnotes ol {
    padding-left: 1.5em;
}
.footnotes a {
    word-break: break-all;
    overflow-wrap: break-word;
}
