/* ============================================
   Table of Contents — polished card
   Applies to .toc-container blocks in any content.
   Works with the site's existing heading-anchor system.
   ============================================ */

body .toc-container {
    position: relative;
    background: linear-gradient(135deg, #fff 0%, #fff 55%, #faf5ff 100%);
    border: 1px solid rgba(92,38,152,0.15);
    border-radius: 16px;
    padding: 24px 28px 22px 32px;
    margin: 28px auto 25px;
    box-shadow: 0 1px 3px rgba(17,24,39,0.04), 0 10px 30px rgba(17,24,39,0.06);
    overflow: hidden;
    max-width: 1000px;
}

/* Left accent bar */
body .toc-container::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    background: linear-gradient(180deg, #7c3aed, #5c2698);
}

/* ===== Title ===== */
body .toc-container .toc-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1em;
    font-weight: 800;
    margin: 0 0 16px;
    padding: 0;
    color: #1f2937;
    line-height: 1.2;
    letter-spacing: 0.01em;
    border: none;
    font-family: inherit;
    cursor: default;
}
body .toc-container .toc-title::before {
    content: '';
    display: inline-block;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #5c2698);
    background-image:
        linear-gradient(135deg, #7c3aed, #5c2698),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round'%3E%3Cline x1='8' y1='6' x2='21' y2='6'/%3E%3Cline x1='8' y1='12' x2='21' y2='12'/%3E%3Cline x1='8' y1='18' x2='21' y2='18'/%3E%3Cline x1='3' y1='6' x2='3.01' y2='6'/%3E%3Cline x1='3' y1='12' x2='3.01' y2='12'/%3E%3Cline x1='3' y1='18' x2='3.01' y2='18'/%3E%3C/svg%3E");
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.5' stroke-linecap='round'%3E%3Cline x1='8' y1='6' x2='21' y2='6'/%3E%3Cline x1='8' y1='12' x2='21' y2='12'/%3E%3Cline x1='8' y1='18' x2='21' y2='18'/%3E%3Cline x1='3' y1='6' x2='3.01' y2='6'/%3E%3Cline x1='3' y1='12' x2='3.01' y2='12'/%3E%3Cline x1='3' y1='18' x2='3.01' y2='18'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 14px 14px;
    background-color: #5c2698;
    box-shadow: 0 4px 12px rgba(92,38,152,0.35);
}

/* Toggle button (shown on mobile) */
body .toc-container .toc-toggle {
    display: none;
    margin-left: auto;
    background: rgba(92,38,152,0.08);
    border: 1px solid rgba(92,38,152,0.15);
    border-radius: 8px;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #5c2698;
    padding: 0;
    transition: transform 0.3s, background 0.2s;
    flex-shrink: 0;
}
body .toc-container .toc-toggle:hover {
    background: rgba(92,38,152,0.15);
}
body .toc-container .toc-toggle svg {
    width: 16px;
    height: 16px;
}
body .toc-container.is-collapsed .toc-toggle {
    transform: rotate(-90deg);
}

/* ===== List ===== */
body .toc-container .toc-list {
    list-style: none !important;
    counter-reset: toc-counter;
    margin: 0 !important;
    padding: 0 !important;
    columns: 3;
    column-gap: 28px;
    max-width: unset;
    overflow: hidden;
    /* Explicit max-height — required for iOS Safari. Can't animate from 0 to auto. */
    max-height: 3000px;
    opacity: 1;
    visibility: visible;
    transition: max-height 0.4s ease, opacity 0.25s ease, visibility 0s linear 0s;
}
body .toc-container.is-collapsed .toc-list {
    max-height: 0 !important;
    opacity: 0;
    visibility: hidden;
    margin-bottom: -12px !important;
    transition: max-height 0.35s ease, opacity 0.25s ease, visibility 0s linear 0.35s;
}

body .toc-container .toc-list > li {
    counter-increment: toc-counter;
    position: relative;
    list-style: none !important;
    padding: 0 0 0 34px;
    margin: 0 0 8px;
    break-inside: avoid;
    line-height: 1.45;
}
body .toc-container .toc-list > li::before {
    content: counter(toc-counter);
    position: absolute;
    left: 0;
    top: 2px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(92,38,152,0.1);
    color: #5c2698;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    transition: background 0.2s, color 0.2s, transform 0.2s;
}

body .toc-container .toc-list > li a {
    display: inline-block;
    color: #374151;
    text-decoration: none;
    font-size: 0.94em;
    font-weight: 500;
    padding: 3px 0;
    border-bottom: 1px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}
body .toc-container .toc-list > li a:hover {
    color: #5c2698;
    border-bottom-color: rgba(92,38,152,0.4);
}
body .toc-container .toc-list > li:hover::before {
    background: #5c2698;
    color: #fff;
    transform: scale(1.08);
}

/* Active (current) section */
body .toc-container .toc-list > li.is-active > a {
    color: #5c2698;
    font-weight: 700;
}
body .toc-container .toc-list > li.is-active::before {
    background: linear-gradient(135deg, #7c3aed, #5c2698);
    color: #fff;
    box-shadow: 0 3px 10px rgba(92,38,152,0.4);
}

/* ===== Smooth-scroll offset for heading targets ===== */
/* Accounts for site's sticky header height */
html {
    scroll-behavior: smooth;
}
.sclv-content h2[id],
.sclv-content h3[id],
.entry-content h2[id],
.entry-content h3[id],
.space-page-content h2[id],
.space-page-content h3[id] {
    scroll-margin-top: 90px;
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    body .toc-container .toc-list,
    body .toc-container .toc-toggle,
    body .toc-container .toc-list > li::before,
    body .toc-container .toc-list > li a {
        transition: none !important;
    }
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
    body .toc-container {
        padding: 20px 20px 16px 24px;
    }
    body .toc-container .toc-title {
        font-size: 1em;
        margin-bottom: 12px;
    }
    body .toc-container .toc-toggle {
        display: inline-flex;
    }
    body .toc-container .toc-list {
        columns: 1;
    }
    body .toc-container .toc-list > li {
        padding-left: 30px;
        margin-bottom: 6px;
    }
    body .toc-container .toc-list > li::before {
        width: 22px;
        height: 22px;
        font-size: 10px;
    }
    body .toc-container .toc-list > li a {
        font-size: 0.9em;
    }
}

@media (max-width: 480px) {
    body .toc-container {
        padding: 16px 16px 14px 20px;
        border-radius: 14px;
    }
}
