:root {
    --teal: #008078;
    --toc-toggle-h: 3.25rem;              /* fallback wysokości belki TOC; JS nadpisze */

    /* ——— mobile: metryki ustawiane przez JS, mierzone w układzie naturalnym (flow) ——— */
    --toc-mobile-left: auto;              /* left przycisku w flow */
    --toc-mobile-width: auto;             /* szerokość przycisku w flow */
    --toc-panel-left: auto;               /* left panelu w flow */
    --toc-panel-width: auto;              /* szerokość panelu w flow */
    --toc-panel-height: auto;             /* wysokość panelu w flow */

    /* kompensacja znikającego scrollbara okna przy body.no-scroll */
    --toc-scrollbar-comp: 0px;
}

/* =========================================================================
   ARTICLE CONTENT TYPOGRAPHY
   ======================================================================= */
.article-content p,
.article-content li {
    text-align: justify;
    text-justify: inter-word;
    hyphens: auto;
}

.article-content h2 {
    margin-top: 3rem;
    margin-bottom: 1rem;
    font-weight: 700;
}

.article-content h3 {
    margin-top: 2rem;
    margin-bottom: .75rem;
    font-weight: 600;
}

.article-content img {
    max-width: 100%;
    height: auto;
    border-radius: .5rem;
}

/* =========================================================================
   SEMANTIC BLOCKS
   ======================================================================= */
.anegdota,
.cytat,
.przestroga,
.mem,
.zwrot,
.ironialosu,
.sources,
.przyklad {
    background: #ede7de;
    border-left: 4px solid var(--teal);
    border-radius: .35rem;
    padding: 1rem 1.25rem;
    margin: 1.75rem 0;
    font-style: italic;
}

/* =========================================================================
   BACK TO TOC LINK
   ======================================================================= */
.back-to-toc {
    display: inline-block;
    margin-top: .5rem;
    font-size: .9rem;
    color: var(--teal);
}
.back-to-toc:hover { text-decoration: underline; }

/* =========================================================================
   TABLE OF CONTENTS (TOC)
   ======================================================================= */
.toc {
    background: rgba(255,255,255,.75);
    backdrop-filter: blur(2px);
    border: 1px solid rgba(0,0,0,.05);
    border-radius: .5rem;
    padding: 1rem;
    margin-bottom: 2rem;
    box-shadow: 0 2px 6px rgba(0,0,0,.05);
    -webkit-overflow-scrolling: touch;
}

.toc h2 { margin-bottom: .75rem; font-size: 1.25rem; }
.toc ul { list-style: none; padding-left: 0; margin: 0; }
.toc ul li { margin-bottom: .5rem; }
.toc ul li a { text-decoration: none; color: inherit; }
.toc ul li a:hover { text-decoration: underline; }

/* =========================================================================
   BREADCRUMB
   ======================================================================= */
.breadcrumb-container { margin-bottom: 1rem; }
.breadcrumb { padding: 0; background: transparent; margin-bottom: 0; }
.breadcrumb-item + .breadcrumb-item::before { content: "／"; color: rgba(0,0,0,0.4); padding: 0 .5em; }
.breadcrumb-item a { color: var(--teal); text-decoration: none; }
.breadcrumb-item a:hover { text-decoration: underline; }
.breadcrumb-item.active { color: rgba(0,0,0,0.6); }

/* =========================================================================
   OVERLAY for mobile sticky TOC (pod TOC, nad artykułem)
   ======================================================================= */
.toc-overlay{
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 999;         /* pod przyciskiem/panelem (1001/1002), nad treścią */
    display: none;
}
body.toc-dim .toc-overlay{ display:block; }

/* =========================================================================
   DESKTOP LAYOUT (≥ 992px)
   ======================================================================= */
@media (min-width: 992px) {
    .article-shell { display: flex; gap: 2rem; align-items: flex-start; }

    /* ukryj mobilny TOC */
    .toc-toggle { display: none; }
    .toc-wrapper { display: none !important; }

    /* sticky w kolumnie */
    aside .toc { position: sticky; top: 1rem; }
    .article-shell > .article-content { flex: 1 1 0; }

    /* Przyklejony: pozycja i szerokość ustawiane z JS tak, jak w flow */
    aside .toc--fixed{
        position: fixed;
        top: var(--toc-fixed-top, 1rem);
        left: var(--toc-fixed-left, auto);
        width: var(--toc-fixed-width, 250px) !important;
        z-index: 1000;
    }
}

/* =========================================================================
   MOBILE LAYOUT (≤ 991.98px)
   ======================================================================= */
@media (max-width: 991.98px) {
    .toc-wrapper{
        margin: 1rem 0;
        position: relative;
        z-index: 1000; /* musi być > overlay */
    }

    .toc-toggle{
        display: block;
        width: 100%;
        background: var(--teal);
        color: #fff;
        padding: 0.75rem 1rem;
        border-radius: .5rem;
        font-weight: 600;
        text-align: center;
        margin-bottom: 1rem;
        position: static;
        z-index: 1001;
        line-height: 1.25;
    }

    /* ——— ZAMKNIĘTY + PRZYKLEJONY ——— */
    .toc-toggle.stuckCollapsed{
        position: fixed;
        top: .5rem;
        left: calc(var(--toc-mobile-left, .5rem) - var(--toc-scrollbar-comp, 0px));
        width: var(--toc-mobile-width, auto);
        margin: 0;
        border-radius: .5rem;
        z-index: 1002;
        box-sizing: border-box;
        max-width: calc(100vw - 1rem);
        height: var(--toc-toggle-h, 3.25rem);
        display: flex; align-items: center; justify-content: center;
    }

    /* panel TOC w flow (otwarty, ale nieprzyklejony) */
    .toc-wrapper .toc{
        display: none;
        margin-bottom: 1rem;
        background: rgba(255,255,255,0.9);
        padding: 1rem;
        border-radius: .5rem;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    .toc-wrapper.open .toc{ display:block; position: static; }

    /* ——— OTWARTY + PRZYKLEJONY ——— */
    .toc-wrapper.stuckExpanded{ margin-bottom: 0; height: 0; }
    .toc-wrapper.stuckExpanded .toc-toggle{
        position: fixed;
        top: .5rem;
        left: calc(var(--toc-mobile-left, .5rem) - var(--toc-scrollbar-comp, 0px));
        width: var(--toc-mobile-width, auto);
        border-radius: .5rem;
        z-index: 1002;
        box-sizing: border-box;
        max-width: calc(100vw - 1rem);
        height: var(--toc-toggle-h, 3.25rem);
        margin-bottom: 0;
        display: flex; align-items: center; justify-content: center;
    }
    .toc-wrapper.stuckExpanded .toc{
        display: block !important;
        position: fixed !important;
        visibility: visible !important;
        top: calc(var(--toc-toggle-h, 3.25rem) + 1rem);
        left: calc(var(--toc-panel-left, .5rem) - var(--toc-scrollbar-comp, 0px));
        width: var(--toc-panel-width, auto);
        height: auto;
        min-height: calc(var(--toc-panel-height, 40vh));   /* nie pozwól się „zwinąć” */
        max-height: var(--toc-panel-height, 80vh);
        overflow-y: auto;
        overflow-x: hidden;
        background: rgba(255,255,255,0.95);
        padding: 1rem;
        border-radius: .5rem;
        z-index: 1001;
        box-sizing: border-box;
        -webkit-overflow-scrolling: touch;
        margin: 0;
    }

    /* blokada scrolla tła tylko w stanie otwarty + przyklejony */
    body.no-scroll{ overflow: hidden; }

    /* ukryj desktopowe aside na mobile */
    aside .toc{ display: none !important; }
}
