/* ---- Rail ---- */

.uh-toc {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 90;
    display: none;
    max-height: 70vh;
    padding: 14px 0 14px 18px;
}

@media (min-width: 992px) {
    .uh-toc:not([hidden]) {
        display: block;
    }
}

.uh-toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 9px;
    max-height: inherit;
    overflow-y: auto;
    scrollbar-width: none;
}

.uh-toc-list::-webkit-scrollbar {
    display: none;
}

/* ---- Item ---- */

.uh-toc-link {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-color);
    text-decoration: none;
}

.uh-toc-bar {
    display: block;
    flex: none;
    height: 2px;
    background-color: currentColor;
    opacity: var(--t-emph-faint);
    transition: width 0.18s ease, opacity 0.18s ease;
}

.uh-toc-h2 .uh-toc-bar { width: 26px; }
.uh-toc-h3 .uh-toc-bar { width: 18px; }
.uh-toc-h4 .uh-toc-bar { width: 11px; }

.uh-toc-link.is-active .uh-toc-bar {
    opacity: var(--t-emph-strong);
    width: 34px;
}

.uh-toc .uh-toc-text {
    font: var(--t-label);
    text-transform: uppercase;
    letter-spacing: var(--t-track-label);
    opacity: 0;
    max-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.18s ease, max-width 0.22s ease;
}

/* ---- Inline ---- */

@media (min-width: 992px) {
    .uh-toc-inline {
        display: none;
    }
}

.uh-toc-inline {
    border-top: 1px solid var(--text-color);
    border-bottom: 1px solid var(--text-color);
    padding: 16px 18px 18px 0;
    margin-bottom: clamp(24px, 6vw, 40px);
}

.uh-toc-inline-heading {
    font: var(--t-label);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: var(--t-track-label);
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.uh-toc-inline-heading::-webkit-details-marker {
    display: none;
}

.uh-toc-inline-heading::after {
    content: "";
    flex: none;
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
    transition: transform 0.2s ease;
}

.uh-toc-inline[open] .uh-toc-inline-heading {
    margin-bottom: 18px;
}

.uh-toc-inline[open] .uh-toc-inline-heading::after {
    transform: translateY(2px) rotate(-135deg);
}

.uh-toc-inline .uh-toc-list {
    gap: 12px;
    max-height: none;
    overflow: visible;
    padding-left: 0;
}

.uh-toc-inline .uh-toc-item {
    margin-bottom: 0;
}

.uh-toc-inline .uh-toc-link {
    align-items: flex-start;
    text-decoration: none;
}

.uh-toc-inline .uh-toc-bar {
    margin-top: 0.6em;
}

.uh-toc-inline .uh-toc-text {
    font: var(--t-label);
    font-weight: 700;
    line-height: 1.35;
    text-transform: uppercase;
    letter-spacing: var(--t-track-label);
    opacity: var(--t-emph);
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.uh-toc-inline .uh-toc-link.is-active .uh-toc-text {
    opacity: var(--t-emph-strong);
}

/* ---- Back to contents ---- */

.uh-toc-back {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin-top: clamp(20px, 5vw, 32px);
    padding: 14px 0;
    border: 0;
    border-top: 1px solid var(--text-color);
    background: none;
    color: var(--text-color);
    font: var(--t-label);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: var(--t-track-label);
    text-align: left;
    cursor: pointer;
}

.uh-toc-back::before {
    content: "";
    flex: none;
    width: 8px;
    height: 8px;
    border-left: 2px solid currentColor;
    border-top: 2px solid currentColor;
    transform: translateY(2px) rotate(45deg);
}

@media (min-width: 992px) {
    .uh-toc-back {
        display: none;
    }
}

/* ---- Expanded ---- */

.uh-toc:hover .uh-toc-text,
.uh-toc:focus-within .uh-toc-text {
    opacity: var(--t-emph);
    max-width: 30ch;
}

.uh-toc:hover .uh-toc-link.is-active .uh-toc-text,
.uh-toc:focus-within .uh-toc-link.is-active .uh-toc-text {
    opacity: var(--t-emph-strong);
}

.uh-toc:hover .uh-toc-link:hover .uh-toc-text {
    opacity: var(--t-emph-strong);
}

.uh-toc-link:focus-visible {
    outline: 2px solid var(--text-color);
    outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
    .uh-toc-inline-heading::after,
    .uh-toc-bar,
    .uh-toc-text {
        transition: none;
    }
}
