/* ============================================================
   modal-stack.css —— Mac 风格弹窗栈
   ============================================================ */

.modal-stack-root {
    position: fixed;
    inset: 0;
    z-index: 99990;
    display: none;
    pointer-events: none;
}

.modal-stack-root.is-active {
    display: block;
}

/* ===== 背景遮罩 ===== */
.modal-stack-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: auto;
}

.modal-stack-root.is-active .modal-stack-backdrop {
    opacity: 1;
}

/* ===== 单个弹窗 ===== */
.mac-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.92);
    opacity: 0;
    background: #f8fafc;
    border-radius: 14px;
    box-shadow:
        0 30px 80px rgba(0, 0, 0, 0.35),
        0 0 0 0.5px rgba(255, 255, 255, 0.5) inset;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    pointer-events: auto;
    transition: opacity 0.2s ease, transform 0.2s ease;
    max-height: 92vh;
}

.mac-modal.is-shown {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* ===== 尺寸 ===== */
.mac-modal.size-small  { width: min(440px, 90vw);  height: auto; max-height: 60vh; }
.mac-modal.size-medium { width: min(720px, 92vw);  height: min(640px, 85vh); }
.mac-modal.size-large  { width: min(980px, 94vw);  height: min(760px, 90vh); }
.mac-modal.size-full   { width: 100vw; height: 100vh; top: 0; left: 0; transform: none !important; border-radius: 0; }
.mac-modal.size-full .mac-modal-titlebar { border-radius: 0; }

/* ===== Mac 风格标题栏 ===== */
.mac-modal-titlebar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: linear-gradient(to bottom, #f1f5f9, #e8eef7);
    border-bottom: 1px solid #dbe4f0;
    flex-shrink: 0;
    user-select: none;
    position: relative;
    min-height: 44px;
}

/* 红黄绿三圆点 */
.mac-modal-dots {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}
.mac-modal-dots .dot {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.08);
    display: inline-block;
    transition: filter 0.15s;
}
.mac-modal-dots .dot-close    { background: #ff5f57; cursor: pointer; }
.mac-modal-dots .dot-minimize { background: #febc2e; }
.mac-modal-dots .dot-maximize { background: #28c840; }
.mac-modal-dots .dot-close:hover { filter: brightness(0.85); }
.mac-modal-dots .dot-close:active { filter: brightness(0.75); }

/* ===== 彻底隐藏标题文字和多余按钮 ===== */
.mac-modal-title,
.mac-modal-mobile-close {
    display: none !important;
}

/* ===== 内容区 ===== */
.mac-modal-body {
    flex: 1;
    overflow: hidden;
    background: #ffffff;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.mac-modal-body iframe {
    border: none;
    width: 100%;
    height: 100%;
    flex: 1;
    display: block;
    background: #ffffff;
}

.mac-modal-body .modal-html {
    flex: 1;
    overflow: auto;
}

/* 加载中 */
.mac-modal-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    color: #94a3b8;
    font-size: 14px;
    gap: 10px;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 5;
}
.mac-modal-loading::before {
    content: '';
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid #e2e8f0;
    border-top-color: #3b82f6;
    animation: mac-modal-spin 0.7s linear infinite;
}
.mac-modal-loading.is-hidden {
    opacity: 0;
}
@keyframes mac-modal-spin {
    to { transform: rotate(360deg); }
}

/* ===== 多层弹窗：下层缩放 + 变暗 ===== */
.mac-modal.is-behind {
    transform: translate(-50%, -50%) scale(0.94);
    filter: brightness(0.92);
    opacity: 0.65;
    pointer-events: none;
}

/* ============================================================
   ★ 移动端适配（极致减负 + 全屏深色顶栏）
   ============================================================ */
@media (max-width: 768px) {
    /* 1. 彻底干掉手机端的毛玻璃遮罩 */
    .modal-stack-backdrop {
        background: rgba(0, 0, 0, 0.85) !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    /* 2. 弹窗本体去掉过渡动画 */
    .mac-modal {
        transition: none !important;
    }

    /* 3. 手机端直接全屏铺满 */
    .mac-modal.size-small,
    .mac-modal.size-medium,
    .mac-modal.size-large,
    .mac-modal.size-full {
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        top: 0 !important;
        left: 0 !important;
        transform: none !important;
    }

    /* ★ 4. 手机端标题栏：深色背景，让红绿灯明显 */
    .mac-modal-titlebar {
        display: flex !important;
        background: #334155 !important; 
        border-bottom: none !important;
        padding: 10px 16px;
        min-height: 50px;
    }

    .mac-modal-dots .dot {
        width: 14px;
        height: 14px;
        border: none;
    }

    .mac-modal-body {
        height: calc(100vh - 50px); 
    }
}

/* 用户偏好减少动画 */
@media (prefers-reduced-motion: reduce) {
    .mac-modal,
    .mac-modal.is-shown,
    .mac-modal.is-behind {
        transition: none !important;
    }
}

/* ============================================================
   ★ 文章目录按钮 + 面板
   ============================================================ */
.article-toc-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 99998;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: #ffffff;
    border: 1.5px solid #e2e8f0;
    border-radius: 24px;
    color: #475569;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.article-toc-btn:hover {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.3);
}

.article-toc-btn.active {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
}

.article-toc-btn .toc-icon {
    font-size: 16px;
    line-height: 1;
}

.article-toc-panel {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 99999;
    width: 280px;
    max-width: calc(100vw - 40px);
    max-height: 60vh;
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.25s ease;
}

.article-toc-panel.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.article-toc-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #eef2ff;
    font-weight: 600;
    font-size: 14px;
    color: #1e293b;
    flex-shrink: 0;
}

.article-toc-close {
    background: none;
    border: none;
    font-size: 16px;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    font-family: inherit;
    transition: all 0.15s;
}

.article-toc-close:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.article-toc-list {
    padding: 6px 0;
    overflow-y: auto;
    flex: 1;
}

.article-toc-item {
    display: block;
    padding: 6px 20px;
    font-size: 13px;
    color: #64748b;
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all 0.15s;
    line-height: 1.5;
    word-break: break-word;
}

.article-toc-item.level-3 {
    padding-left: 36px;
    font-size: 12.5px;
}

.article-toc-item:hover {
    color: #3b82f6;
    background: #f8fafc;
}

.article-toc-item.active {
    color: #3b82f6;
    font-weight: 600;
    border-left-color: #3b82f6;
    background: #eef2ff;
}

@media (max-width: 768px) {
    .article-toc-btn {
        top: 12px;
        right: 12px;
        padding: 8px 14px;
        font-size: 12px;
    }
    .article-toc-btn .toc-text {
        display: none;
    }
    .article-toc-panel {
        top: 60px;
        right: 12px;
        width: 240px;
        max-height: 50vh;
    }
}