/**
 * Table of contents
 *
 * >= 1200px — sticky rail in the right margin. It steps 2rem up from the article
 *             body, i.e. it sits 2rem below the hero's bottom edge, so readers
 *             see it without scrolling and it never touches the title or the
 *             image.
 * <  1200px — collapsible "table of contents" card above the article body.
 *             Closed by default, so it costs one row instead of pushing the
 *             article down (the open/close state is synced in default.hbs).
 *
 * Loaded on post pages only. Kept separate from article-hero.css so each can be
 * tuned/reverted on its own.
 */

/* ---------------------------------------------------------------- shared */

/* Articles without headings produce no list: don't leave an empty card/rail */
.gh-toc-panel:has(.gh-toc:empty) {
    display: none;
}

.gh-toc-panel-summary {
    display: flex;
    gap: 1.2rem;
    align-items: center;
    justify-content: space-between;
    font-size: 1.3rem;
    font-weight: 600;
    line-height: 1.5;
    color: var(--color-secondary-text, #8a8f98);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
    list-style: none;
}

.gh-toc-panel-summary::-webkit-details-marker {
    display: none;
}

.gh-toc-panel-summary::after {
    flex: 0 0 auto;
    width: 1.2rem;
    height: 1.2rem;
    content: "";
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%238a8f98' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 5.5l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 100% 100%;
    opacity: 0.9;
    transition: transform 0.2s ease;
}

.gh-toc-panel[open] > .gh-toc-panel-summary::after {
    transform: rotate(180deg);
}

.gh-toc-panel .gh-toc {
    margin-top: 0.8rem;
}

.gh-toc-panel .toc-list {
    padding: 0;
    margin: 0;
    list-style: none;
}

/* Ghost numbers nested lists in the body (`ol ol li` → a. b. c.`,
   `ol ol ol li` → i. ii. iii.`) and those rules outrank `.toc-list`. The TOC is
   a nested list too, so every level has to opt out explicitly — no markers. */
.gh-content .gh-article-toc-sidebar .toc-list,
.gh-content .gh-article-toc-sidebar .toc-list li {
    list-style: none;
}

.gh-content .gh-article-toc-sidebar .toc-list li::marker {
    content: "";
}

.gh-toc-panel .toc-list .toc-list {
    padding-left: 1.4rem;
}

.gh-toc-panel .toc-link {
    position: relative;
    display: block;
    padding: 0.4rem 0 0.4rem 1.2rem;
    font-size: 1.4rem;
    line-height: 1.6;
    color: var(--color-secondary-text, #8a8f98);
    text-decoration: none;
}

.gh-toc-panel .toc-link::before {
    top: 0.5rem;
    bottom: 0.5rem;
    left: 0;
    width: 2px;
    height: auto;
    background-color: transparent;
    border-radius: 2px;
}

/* Only the section being read gets a marker */
.gh-toc-panel .gh-toc .is-active-link::before {
    background-color: var(--ghost-accent-color, #15171a);
}

.gh-toc-panel .toc-link:hover {
    color: var(--color-darker-gray, #15171a);
    opacity: 1;
}

.gh-toc-panel .is-active-link {
    font-weight: 600;
    color: var(--color-darker-gray, #15171a);
}

.gh-toc-panel .toc-list .toc-list .toc-link {
    font-size: 1.3rem;
}

/* --------------------------------------------------- wide: sticky right rail */

@media (min-width: 1200px) {
    /* The body column starts 4rem below the hero (or below the image caption, if
       there is one). Stepping the rail 2rem up into that whitespace leaves a
       2rem gap under the image and keeps the same gap in both cases — no
       per-caption offset needed. */
    .post-template .gh-content .gh-article-toc-sidebar {
        top: -2rem;
    }

    /* The sticky element is the panel now; the inner list must not stick twice */
    .post-template .gh-content .gh-article-toc-sidebar .gh-toc {
        position: static;
    }

    .post-template .gh-content .gh-article-toc-sidebar .gh-toc-panel {
        position: sticky;
        top: 2rem;
        max-height: calc(100vh - 4rem);
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .gh-toc-panel-summary {
        padding-bottom: 0.7rem;
        border-bottom: 1px solid var(--color-light-gray, #e6e6e6);
    }

    /* Keyboard users need to see the toggle outlined */
    .post-template .gh-content .gh-article-toc-sidebar .gh-toc-panel:focus-visible {
        outline: 2px solid var(--ghost-accent-color, #15171a);
        outline-offset: 2px;
    }
}

/* ------------------------------------------- narrow: collapsible card above content */

@media (max-width: 1199px) {
    .post-template .gh-article-toc-sidebar {
        display: block;
        position: static;
        width: auto;
        max-width: none;
        padding: 0;
        margin: 0 0 2.4rem;
    }

    .gh-article-toc-sidebar .gh-toc-panel {
        padding: 1.3rem 1.8rem;
        background-color: var(--color-lighter-gray, #f6f6f6);
        border: 1px solid var(--color-light-gray, #e6e6e6);
        border-radius: 6px;
    }

    .gh-article-toc-sidebar .gh-toc-panel[open] > .gh-toc-panel-summary {
        padding-bottom: 1rem;
        border-bottom: 1px solid var(--color-light-gray, #e6e6e6);
    }

    .gh-article-toc-sidebar .gh-toc-panel .gh-toc {
        margin-top: 0.6rem;
    }

    /* Larger tap targets on touch screens */
    .gh-article-toc-sidebar .gh-toc-panel .toc-link {
        padding-top: 0.7rem;
        padding-bottom: 0.7rem;
    }
}
