.muki-floating-toc {
    position: absolute;
    left: -60px; 
    top: 0;
    width: 60px;
    padding: 15px 8px;
    z-index: 999;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    box-shadow: none;
    border: none;
    font-size: 13px;
    line-height: 1.4;
    max-height: 80vh;
    overflow-x: visible;
    transition: width 0.4s cubic-bezier(0.25, 1, 0.5, 1), 
                background-color 0.3s ease, 
                box-shadow 0.3s ease,
                padding 0.4s ease,
                transform 0s;
    transform-origin: center left;
}

.muki-floating-toc.fixed {
    position: fixed;
    top: 50% !important;
    transform: translateY(-50%) !important;
    margin-top: 0 !important;
}


.muki-toc-item {
    display: block;
    text-decoration: none;
    color: #666;
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 5px;
}

.muki-toc-line-wrap {
    display: block;
    position: relative;
    height: 16px;
}

.muki-toc-line {
    display: block;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 2px;
    background-color: #dddddd;
    margin: 0;
    border-radius: 2px;
    transition: width 0.3s ease, background-color 0.3s ease;
}

.muki-toc-text-wrap {
    position: absolute;
    left: 35px;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 10;
    pointer-events: none;
}

.muki-toc-text {
    white-space: nowrap;
    background-color: rgba(255,255,255,0.95);
    padding: 3px 8px;
    border-radius: 3px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    font-size: 12px;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: auto;
}

/* 改為以偽元素顯示層級標示，避免實際文字節點出現在 DOM */
.muki-toc-level-indicator { display: none !important; }

/* 於連結文字後方以 ::after 顯示 Hn，依父層 data-level 判斷 */
.muki-toc-text::after {
    content: attr(data-level-text);
    display: inline-block;
    font-size: 10px;
    color: #999;
    margin-left: 5px;
    font-weight: normal;
    opacity: 0.7;
    background-color: rgba(0,0,0,0.05);
    padding: 1px 4px;
    border-radius: 3px;
}

/* 預設不顯示，由父 li 的 data-level 來決定實際內容 */
.muki-toc-item[data-level="2"] .muki-toc-text { --level-text: "H2"; }
.muki-toc-item[data-level="3"] .muki-toc-text { --level-text: "H3"; }
.muki-toc-item[data-level="4"] .muki-toc-text { --level-text: "H4"; }
.muki-toc-item[data-level="5"] .muki-toc-text { --level-text: "H5"; }
.muki-toc-item[data-level="6"] .muki-toc-text { --level-text: "H6"; }

/* 使用 CSS 變數組成 content（Safari 對 attr() 限制高，改用變數確保相容性）*/
.muki-toc-text::after { content: var(--level-text, ""); }

.muki-toc-item:hover .muki-toc-text-wrap {
    opacity: 1;
    visibility: visible;
    z-index: 9999;
}

.muki-toc-item:hover {
    z-index: 1000;
}

.muki-toc-line-h2 {
    width: 25px;
    left: 0;
    height: 3px;
    background-color: #929292;
}

.muki-toc-line-h3 {
    width: 20px;
    left: 5px;
    background-color: #a8a8a8;
}

.muki-toc-line-h4 {
    width: 15px;
    left: 10px;
    background-color: #bebebe;
}

.muki-toc-line-h5 {
    width: 10px;
    left: 15px;
    background-color: #d4d4d4;
}

.muki-toc-line-h6 {
    width: 8px;
    left: 20px;
    background-color: #eaeaea;
}

.muki-toc-item:hover .muki-toc-line {
    background-color: #666;
}

.muki-toc-item.active .muki-toc-line {
    background-color: #3498db;
}

.muki-floating-toc:hover {
    width: 60px;
}

.muki-floating-toc.pinned {
    width: 350px;
    background-color: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 15px;
    transition: width 0.45s cubic-bezier(0.3, 0.7, 0.1, 1), 
                background-color 0.3s ease, 
                box-shadow 0.35s ease,
                padding 0.4s ease,
                transform 0s;
}

.muki-floating-toc.pinned .muki-toc-text-wrap {
    position: static;
    opacity: 1;
    visibility: visible;
    margin-left: 10px;
    display: block;
    transition: opacity 0.4s ease 0.1s, visibility 0s 0s;
}

.muki-floating-toc.pinned .muki-toc-text {
    background: none;
    box-shadow: none;
    padding: 0;
    white-space: normal;
    max-width: none;
    display: inline-block;
    font-size: 13px;
}

.muki-floating-toc.pinned .muki-toc-item {
    display: flex;
    align-items: start;
    padding-left: 0;
    transform: translateX(0);
    opacity: 0;
    animation: fadeInItem 0.4s ease forwards;
    animation-delay: calc(0.05s * var(--item-index, 0));
}

.muki-floating-toc.pinned .muki-toc-item:nth-child(1) { --item-index: 1; }
.muki-floating-toc.pinned .muki-toc-item:nth-child(2) { --item-index: 2; }
.muki-floating-toc.pinned .muki-toc-item:nth-child(3) { --item-index: 3; }
.muki-floating-toc.pinned .muki-toc-item:nth-child(4) { --item-index: 4; }
.muki-floating-toc.pinned .muki-toc-item:nth-child(5) { --item-index: 5; }
.muki-floating-toc.pinned .muki-toc-item:nth-child(6) { --item-index: 6; }
.muki-floating-toc.pinned .muki-toc-item:nth-child(7) { --item-index: 7; }
.muki-floating-toc.pinned .muki-toc-item:nth-child(8) { --item-index: 8; }
.muki-floating-toc.pinned .muki-toc-item:nth-child(9) { --item-index: 9; }
.muki-floating-toc.pinned .muki-toc-item:nth-child(10) { --item-index: 10; }
.muki-floating-toc.pinned .muki-toc-item:nth-child(n+11) { --item-index: 11; }

@keyframes fadeInItem {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.muki-floating-toc.pinned .muki-toc-line-wrap {
    height: auto;
    margin-bottom: 0;
    flex-shrink: 0;
    width: 25px;
    margin-top: 7px;
}

.muki-floating-toc.pinned .muki-toc-line {
    position: relative;
    top: 0;
    transform: none;
}

.muki-toc-toolbar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.muki-floating-toc.pinned .muki-toc-toolbar {
    animation: fadeInScale 0.3s ease forwards;
}

@keyframes fadeInScale {
    from {
        opacity: 0.8;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.muki-toc-toolbar button {
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    padding: 4px;
    transition: all 0.2s ease;
    border-radius: 3px;
}

.muki-toc-toolbar button .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.muki-toc-toolbar button:hover {
    color: #3498db;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border-radius: 5px;
}

.muki-floating-toc.pinned .muki-toc-pin-button {
    color: #3498db;
    background: rgba(52, 152, 219, 0.1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border-radius: 5px;
}

.muki-floating-toc.hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.4s ease, visibility 0.4s ease, transform 0.4s ease;
}

.muki-floating-toc.no-transition {
    transition: none !important;
}

.muki-floating-toc.no-transition .muki-toc-item {
    animation: none !important;
    opacity: 1 !important;
    transform: translateX(0) !important;
}

@keyframes lineAppear {
    from {
        width: 0;
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.muki-toc-line {
    animation: lineAppear 0.5s ease forwards;
}

.muki-toc-item.located .muki-toc-line {
    background-color: #3498db;
}

@media (max-width: 782px) {
    .muki-floating-toc {
        left: -45px;
        width: 50px;
        padding: 10px 5px;
    }
    
    .muki-toc-line-h2 {
        width: 20px;
    }
    
    .muki-toc-line-h3 {
        width: 15px;
    }

    .muki-floating-toc.pinned {
        width: 240px;
    }
}

@media (max-width: 600px) {
    .muki-floating-toc {
        display: none;
    }
}

.muki-floating-toc.pinned .muki-toc-item[data-level="2"] {
    margin-left: 0;
}

.muki-floating-toc.pinned .muki-toc-item[data-level="3"] {
    margin-left: 15px;
}

.muki-floating-toc.pinned .muki-toc-item[data-level="4"] {
    margin-left: 30px;
}

.muki-floating-toc.pinned .muki-toc-item[data-level="5"] {
    margin-left: 45px;
}

.muki-floating-toc.pinned .muki-toc-item[data-level="6"] {
    margin-left: 60px;
}

.muki-floating-toc.pinned .muki-toc-item[data-level="2"] .muki-toc-text {
    font-weight: 600;
    font-size: 14px;
}

.muki-floating-toc.pinned .muki-toc-item[data-level="3"] .muki-toc-text {
    font-weight: 500;
}

.muki-floating-toc.pinned .muki-toc-item[data-level="4"] .muki-toc-text,
.muki-floating-toc.pinned .muki-toc-item[data-level="5"] .muki-toc-text,
.muki-floating-toc.pinned .muki-toc-item[data-level="6"] .muki-toc-text {
    font-weight: 400;
    color: #777;
}

.muki-toc-item.active .muki-toc-line {
    background-color: #3498db;
}

.muki-floating-toc.pinned .muki-toc-item.active .muki-toc-text {
    color: #929292;
    font-weight: 600;
} 
