/* Floating TOC Styles */
html {
    scroll-behavior: smooth;
}

#ftoc-container {
    position: fixed;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* When expanded, container moves slightly right to accommodate the close button */
#ftoc-container:not(.ftoc-collapsed) {
    left: 0;
}

/* Hamburger Menu Toggle */
.ftoc-toggle {
    position: absolute;
    left: 0;
    top: 0;
    width: 20px;
    height: 50px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 0 8px 8px 0;
    box-shadow: 0 3px 12px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10001;
}

.ftoc-toggle:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46a3 100%);
    box-shadow: 0 5px 16px rgba(102, 126, 234, 0.6);
    transform: translateX(2px);
}

/* When expanded, move toggle to the right side of content */
#ftoc-container:not(.ftoc-collapsed) .ftoc-toggle {
    left: 290px;
    border-radius: 0 8px 8px 0;
    width: 10px;
    height: 50px;
}

/* Hamburger Icon */
.ftoc-hamburger {
    width: 12px;
    height: 10px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Show different icon when expanded */
#ftoc-container:not(.ftoc-collapsed) .ftoc-hamburger {
    width: 6px;
    height: 8px;
}

.ftoc-hamburger span {
    width: 100%;
    height: 2px;
    background: #ffffff;
    border-radius: 1px;
    transition: all 0.3s ease;
    transform-origin: center;
}

/* Hamburger Animation when expanded - Show arrow pointing left */
#ftoc-container:not(.ftoc-collapsed) .ftoc-hamburger span:nth-child(1) {
    transform: translateY(3px) rotate(-45deg);
    width: 4px;
}

#ftoc-container:not(.ftoc-collapsed) .ftoc-hamburger span:nth-child(2) {
    opacity: 0;
}

    #ftoc-container:not(.ftoc-collapsed) .ftoc-hamburger span:nth-child(3) {
        transform: translateY(-3px) rotate(45deg);
        width: 4px;
    }

/* Better mobile animation */
@media (max-width: 768px) {
    #ftoc-container:not(.ftoc-collapsed) .ftoc-hamburger span:nth-child(1) {
        transform: translateY(2px) rotate(-45deg);
        width: 3px;
    }
    
    #ftoc-container:not(.ftoc-collapsed) .ftoc-hamburger span:nth-child(3) {
        transform: translateY(-2px) rotate(45deg);
        width: 3px;
    }
}

/* TOC Content Container */
.ftoc-content {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%) translateX(-100%);
    width: 300px;
    max-height: 80vh;
    background: #ffffff;
    border: 1px solid #e1e5e9;
    border-left: none;
    border-radius: 0 12px 12px 0;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

/* Show content when expanded */
#ftoc-container:not(.ftoc-collapsed) .ftoc-content {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(-50%) translateX(0);
    border-left: 1px solid #e1e5e9;
    border-radius: 12px 12px 12px 0;
}

.ftoc-wrapper {
    padding: 12px 0;
    max-height: 75vh;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Add a header to the TOC */
.ftoc-wrapper::before {
    content: "📑 文章目录";
    display: block;
    padding: 0 12px 8px;
    font-weight: 600;
    font-size: 14px;
    color: #2d3748;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 8px;
}

/* Custom Scrollbar */
.ftoc-wrapper::-webkit-scrollbar {
    width: 4px;
}

.ftoc-wrapper::-webkit-scrollbar-track {
    background: #f1f3f5;
}

.ftoc-wrapper::-webkit-scrollbar-thumb {
    background: #ced4da;
    border-radius: 2px;
}

.ftoc-wrapper::-webkit-scrollbar-thumb:hover {
    background: #adb5bd;
}

/* TOC List Styles */
.ftoc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ftoc-list.level-1 {
    padding-left: 0;
}

.ftoc-list.level-2 {
    padding-left: 20px;
    border-left: 2px solid #f0f0f0;
    margin-left: 10px;
}

.ftoc-list.level-3 {
    padding-left: 20px;
    border-left: 2px solid #f0f0f0;
    margin-left: 10px;
}

.ftoc-list.level-4 {
    padding-left: 20px;
    border-left: 2px solid #f0f0f0;
    margin-left: 10px;
}

.ftoc-list.level-5 {
    padding-left: 20px;
    border-left: 2px solid #f0f0f0;
    margin-left: 10px;
}

.ftoc-list.level-6 {
    padding-left: 20px;
    border-left: 2px solid #f0f0f0;
    margin-left: 10px;
}

/* TOC Item Styles */
.ftoc-item {
    position: relative;
    margin: 0;
    padding: 2px 0;
    display: block;
}

.ftoc-item.level-1 {
    border-left: 3px solid #e9ecef;
    margin: 4px 0;
}

.ftoc-item.level-1.active {
    border-left-color: #667eea;
}

.ftoc-item.level-2,
.ftoc-item.level-3,
.ftoc-item.level-4,
.ftoc-item.level-5,
.ftoc-item.level-6 {
    margin: 1px 0;
}

/* Expand/Collapse Icon */
.ftoc-expand-icon {
    position: relative;
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 6px;
    vertical-align: middle;
    cursor: pointer;
    transition: transform 0.25s ease;
    user-select: none;
    color: #667eea;
    font-size: 10px;
    text-align: center;
    line-height: 12px;
}

.ftoc-item.expanded .ftoc-expand-icon {
    transform: rotate(90deg);
    color: #5a67d8;
}

/* Default state: collapsed */
.ftoc-item.ftoc-expandable .ftoc-expand-icon {
    transform: rotate(0deg);
}

/* TOC Link Styles */
.ftoc-link {
    display: inline-block;
    padding: 6px 10px;
    color: #495057;
    text-decoration: none;
    font-size: 13px;
    line-height: 1.4;
    border-radius: 6px;
    margin: 2px 0;
    transition: all 0.2s ease;
    position: relative;
    font-weight: 400;
    cursor: pointer;
    user-select: none;
    width: calc(100% - 20px);
    box-sizing: border-box;
}

.ftoc-item.level-1 .ftoc-link {
    font-weight: 600;
    font-size: 14px;
    color: #2d3748;
}

.ftoc-item.level-2 .ftoc-link {
    font-size: 13px;
    color: #4a5568;
    font-weight: 500;
}

.ftoc-item.level-3 .ftoc-link {
    font-size: 12px;
    color: #718096;
    font-weight: 400;
}

.ftoc-item.level-4 .ftoc-link,
.ftoc-item.level-5 .ftoc-link,
.ftoc-item.level-6 .ftoc-link {
    font-size: 11px;
    color: #a0aec0;
    font-weight: 400;
}

/* Hover Effects */
.ftoc-link:hover {
    background: linear-gradient(135deg, #f0f4ff 0%, #e8f2ff 100%);
    color: #667eea;
    transform: translateX(3px);
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.1);
}

/* Active/Current Reading Position */
.ftoc-item.active .ftoc-link {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.ftoc-item.active .ftoc-expand-icon {
    color: #ffffff;
}

/* Nested List Animation */
.ftoc-list {
    overflow: hidden;
}

.ftoc-item:not(.expanded) > .ftoc-list {
    display: none;
}

.ftoc-item.expanded > .ftoc-list {
    display: block;
}

/* Ensure level-1 list is always visible */
.ftoc-list.level-1 {
    display: block !important;
}

/* Tablet Responsive */
@media (max-width: 1024px) and (min-width: 769px) {
    .ftoc-toggle {
        width: 18px;
        height: 48px;
    }
    
    #ftoc-container:not(.ftoc-collapsed) .ftoc-toggle {
        left: 280px;
        width: 9px;
        height: 48px;
    }
    
    .ftoc-content {
        width: 280px;
    }
    
    .ftoc-hamburger {
        width: 11px;
        height: 9px;
    }
    
    #ftoc-container:not(.ftoc-collapsed) .ftoc-hamburger {
        width: 5px;
        height: 7px;
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #ftoc-container {
        top: 50%;
        transform: translateY(-50%);
        left: 0;
    }
    
    .ftoc-toggle {
        width: 18px;
        height: 45px;
        border-radius: 0 6px 6px 0;
    }
    
    #ftoc-container:not(.ftoc-collapsed) .ftoc-toggle {
        left: 260px;
        width: 8px;
        height: 45px;
        border-radius: 0 6px 6px 0;
    }
    
    .ftoc-content {
        left: 8px;
        width: 260px;
        max-height: 70vh;
        top: 50%;
        transform: translateY(-50%) translateX(-100%);
        border-radius: 0 10px 10px 0;
    }
    
    #ftoc-container:not(.ftoc-collapsed) .ftoc-content {
        transform: translateY(-50%) translateX(0);
        border-left: 1px solid #e1e5e9;
        border-radius: 10px 10px 10px 0;
    }
    
    .ftoc-link {
        font-size: 12px;
        padding: 4px 8px;
        width: calc(100% - 16px);
    }
    
    .ftoc-hamburger {
        width: 10px;
        height: 8px;
    }
    
    #ftoc-container:not(.ftoc-collapsed) .ftoc-hamburger {
        width: 4px;
        height: 6px;
    }
    
    .ftoc-wrapper::before {
        font-size: 13px;
        padding: 0 10px 6px;
    }
}

/* Add some visual enhancements */
.ftoc-item {
    transition: all 0.2s ease;
    border-radius: 6px;
}

.ftoc-item:hover {
    background: rgba(102, 126, 234, 0.05);
    transform: translateX(2px);
}

/* Add visual separator for level-1 items */
.ftoc-item.level-1:not(:last-child) {
    border-bottom: 1px solid #f7fafc;
    padding-bottom: 8px;
    margin-bottom: 8px;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .ftoc-toggle {
        background: linear-gradient(135deg, #553c9a 0%, #2d3748 100%);
        box-shadow: 0 3px 12px rgba(85, 60, 154, 0.5);
    }
    
    .ftoc-toggle:hover {
        background: linear-gradient(135deg, #553c9a 0%, #1a202c 100%);
        box-shadow: 0 5px 16px rgba(85, 60, 154, 0.7);
    }
    
    .ftoc-content {
        background: #1a202c;
        border-color: #2d3748;
        color: #e2e8f0;
    }
    
    .ftoc-wrapper::before {
        color: #e2e8f0;
        border-bottom-color: #2d3748;
    }
    
    .ftoc-hamburger span {
        background: #e2e8f0;
    }
    
    .ftoc-item.level-1 .ftoc-link {
        color: #f7fafc;
    }
    
    .ftoc-item.level-2 .ftoc-link {
        color: #e2e8f0;
    }
    
    .ftoc-item.level-3 .ftoc-link {
        color: #cbd5e0;
    }
    
    .ftoc-item.level-4 .ftoc-link,
    .ftoc-item.level-5 .ftoc-link,
    .ftoc-item.level-6 .ftoc-link {
        color: #a0aec0;
    }
    
    .ftoc-link:hover {
        background: linear-gradient(135deg, #2d3748 0%, #4a5568 100%);
        color: #90cdf4;
    }
    
    .ftoc-item.active .ftoc-link {
        background: linear-gradient(135deg, #553c9a 0%, #2d3748 100%);
        color: #ffffff;
    }
    
    .ftoc-item:hover {
        background: rgba(45, 55, 72, 0.3);
    }
    
    .ftoc-item.level-1:not(:last-child) {
        border-bottom-color: #2d3748;
    }
    
    .ftoc-list.level-2,
    .ftoc-list.level-3,
    .ftoc-list.level-4,
    .ftoc-list.level-5,
    .ftoc-list.level-6 {
        border-left-color: #2d3748;
    }
    
    .ftoc-wrapper::-webkit-scrollbar-track {
        background: #2d3748;
    }
    
    .ftoc-wrapper::-webkit-scrollbar-thumb {
        background: #4a5568;
    }
}
