.mermaid-wrap {
    position: relative;
    margin: 20px 0;
}
.mermaid {
    padding: 16px;
    overflow-x: auto;
    text-align: center;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    transition: opacity 0.2s, box-shadow 0.2s, background 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    user-select: none;
    -webkit-user-select: none;
}
.mermaid:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.mermaid:active {
    opacity: 0.85;
}
.mermaid-source {
    margin-top: 10px;
    display: none;
}

/* ---- 大图模态框 ---- */
.mermaid-modal {
    display: none;
    position: fixed;
    z-index: 9999;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: mermaidFadeIn 0.2s ease;
}
.mermaid-modal.show {
    display: flex;
}
.mermaid-modal-viewport {
    position: relative;
    background: #fff;
    border-radius: 10px;
    width: 90vw;
    height: 85vh;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
    animation: mermaidZoomIn 0.25s ease;
}
.mermaid-modal-canvas {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: center center;
    cursor: grab;
}
.mermaid-modal-canvas:active {
    cursor: grabbing;
}
.mermaid-modal-canvas svg {
    max-width: none;
    max-height: none;
}
.mermaid-modal-close {
    position: absolute;
    top: 10px;
    right: 14px;
    z-index: 10;
    font-size: 1.6rem;
    line-height: 1;
    color: #999;
    cursor: pointer;
    transition: color 0.15s;
    background: rgba(255,255,255,0.8);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.mermaid-modal-close:hover {
    color: #333;
}
.mermaid-modal-zoom {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    gap: 6px;
    background: rgba(255,255,255,0.9);
    border-radius: 6px;
    padding: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.mermaid-modal-zoom button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 10px;
    border-radius: 4px;
    color: #555;
    transition: background 0.15s;
}
.mermaid-modal-zoom button:hover {
    background: #eee;
}
.mermaid-modal-zoom .zoom-level {
    font-size: 0.8rem;
    line-height: 28px;
    min-width: 36px;
    text-align: center;
    color: #333;
}
.mermaid-modal-tip {
    position: absolute;
    bottom: 56px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    font-size: 0.75rem;
    color: #999;
    background: rgba(255,255,255,0.8);
    padding: 3px 10px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}
.mermaid-modal-viewport.loaded .mermaid-modal-tip {
    opacity: 1;
}

@keyframes mermaidFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes mermaidZoomIn {
    from { transform: scale(0.92); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

/* ---- 暗色模式 ---- */
.mermaid-dark .mermaid { background: #1e1e2e; }
.mermaid-dark .mermaid-modal-viewport { background: #1e1e2e; }
.mermaid-dark .mermaid-modal-close { background: rgba(30,30,46,0.8); color: #aaa; }
.mermaid-dark .mermaid-modal-close:hover { color: #fff; }
.mermaid-dark .mermaid-modal-zoom { background: rgba(30,30,46,0.9); }
.mermaid-dark .mermaid-modal-zoom button { color: #aaa; }
.mermaid-dark .mermaid-modal-zoom button:hover { background: #2e2e3e; }
.mermaid-dark .mermaid-modal-zoom .zoom-level { color: #ccc; }
.mermaid-dark .mermaid-modal-tip { background: rgba(30,30,46,0.8); color: #aaa; }
