/**
 * /tools/mermaid · Mermaid 在线图表编辑器
 * 深色为默认基线，[data-theme="light"] 覆盖浅色；主题变量定义在 :root（浮层挂在 .mmd 内可继承）。
 */
:root {
    --mmd-bg: #0f1419;
    --mmd-card: #161b21;
    --mmd-card-2: #1c232b;
    --mmd-line: #33404c;
    --mmd-line-2: #465463;
    --mmd-fg: #e8edf2;
    --mmd-fg-2: #c2cbd5;
    --mmd-sub: #94a3b3;
    --mmd-faint: #8b99a8;
    --mmd-accent: #6aa9ff;
    --mmd-accent-soft: rgba(106, 169, 255, .14);
    --mmd-ok: #4ec9a0;
    --mmd-warn: #e3a008;
    --mmd-err: #f07a7a;
    --mmd-code: #0d1117;
    --mmd-shadow: 0 10px 32px rgba(0, 0, 0, .34);
    --mmd-shadow-sm: 0 2px 10px rgba(0, 0, 0, .2);
    --mmd-r: 14px;
    --mmd-r-sm: 9px;
    --mmd-editor-fs: 14px;
    --mmd-accent-fill: #1f5fd4; /* 填充专用：白字对比度 >=5:1，文字/描边仍用 --mmd-accent */
    --mmd-on-accent: #ffffff;
    /* 语义软底：状态徽章与结果提示，浅色主题另有覆盖 */
    --mmd-ok-soft: rgba(78, 201, 160, .14);
    --mmd-warn-soft: rgba(227, 160, 8, .14);
    --mmd-err-soft: rgba(240, 122, 122, .14);
    --mmd-zebra: rgba(127, 127, 127, .055);
    --mmd-shadow-md: 0 6px 20px rgba(0, 0, 0, .24);
    /* 工作台高度跟随视口：高屏不再被 640px 封顶，矮屏不低于 360px */
    --mmd-work-h: clamp(360px, calc(100dvh - 370px), 760px);
}
[data-theme="light"] {
    --mmd-accent-fill: #136ce9;
    --mmd-bg: #f5f7f9;
    --mmd-card: #ffffff;
    --mmd-card-2: #f3f6f9;
    --mmd-line: #dbe3ec;
    --mmd-line-2: #c2cfdb;
    --mmd-fg: #1b2632;
    --mmd-fg-2: #344454;
    --mmd-sub: #5d6b7a;
    --mmd-faint: #5f6b7a;
    --mmd-accent: #136ce9;
    --mmd-accent-soft: rgba(19, 108, 233, .1);
    --mmd-ok: #16845f;
    --mmd-warn: #9a6700;
    --mmd-err: #c23b3b;
    --mmd-code: #f7f9fb;
    --mmd-shadow: 0 10px 30px rgba(20, 35, 55, .12);
    --mmd-shadow-sm: 0 2px 8px rgba(20, 35, 55, .08);
    --mmd-ok-soft: rgba(22, 132, 95, .1);
    --mmd-warn-soft: rgba(154, 103, 0, .1);
    --mmd-err-soft: rgba(194, 59, 59, .09);
    --mmd-zebra: rgba(15, 20, 25, .038);
    --mmd-shadow-md: 0 6px 20px rgba(20, 35, 55, .1);
}

/* 站点 body 自带 overflow-y:scroll 会让页内 sticky 失效，交还滚动给 html */
body.page-mermaid-full { overflow: visible; }
body.page-mermaid-full .app,
body.page-mermaid-full .main-content,
body.page-mermaid-full .page-container { max-width: 100%; width: 100%; }
body.page-mermaid-full .main-content { border-right: 0; min-width: 0; }
html.mmd-side-open, body.page-mermaid-full.mmd-side-open { overflow: hidden !important; }

.mmd {
    --mmd-gap: 14px;
    width: 100%; max-width: 100%; box-sizing: border-box;
    padding: 18px 22px 56px; margin: 0;
    color: var(--mmd-fg); font-size: 14px; line-height: 1.6;
    scrollbar-width: thin; scrollbar-color: var(--mmd-line-2) transparent;
}
.mmd *, .mmd *::before, .mmd *::after { box-sizing: border-box; }
.mmd [hidden], .mmd-mask[hidden], .mmd-toast[hidden] { display: none !important; }
.mmd button, .mmd input, .mmd select, .mmd textarea { font-family: inherit; }
.mmd button { cursor: pointer; }
.mmd button:disabled { opacity: .5; cursor: not-allowed; }
.mmd :focus-visible { outline: 2px solid var(--mmd-accent); outline-offset: 2px; }
.mmd ::-webkit-scrollbar { width: 10px; height: 10px; }
.mmd ::-webkit-scrollbar-thumb { background: var(--mmd-line-2); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
.mmd ::-webkit-scrollbar-track { background: transparent; }

/* ============ Hero ============ */
.mmd-hero {
    display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
    background: var(--mmd-card);
    background: linear-gradient(112deg, color-mix(in srgb, var(--mmd-accent) 7%, var(--mmd-card)), var(--mmd-card) 58%);
    border: 1px solid var(--mmd-line);
    border-left: 4px solid var(--mmd-accent);
    border-radius: var(--mmd-r); padding: 16px 20px; margin-bottom: 14px;
    box-shadow: var(--mmd-shadow-sm);
}
.mmd-hero-l { display: flex; align-items: center; gap: 16px; min-width: 0; flex: 1 1 380px; }
.mmd-hero-l > div:last-child { flex: 1 1 auto; min-width: 0; }
.mmd-hero-ic {
    flex: 0 0 auto; width: 50px; height: 50px; border-radius: 14px;
    display: grid; place-items: center; font-size: 26px; font-weight: 700; color: #fff;
    background: linear-gradient(135deg, #136ce9, #38bdf8);
    box-shadow: 0 6px 18px rgba(19, 108, 233, .3);
}
.mmd-hero h1 { font-size: 21px; line-height: 1.3; margin: 0 0 4px; font-weight: 700; }
.mmd-hero p { margin: 0; color: var(--mmd-sub); font-size: 13px; max-width: 76ch; }
.mmd-hero-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.mmd-tag {
    font-size: 11.5px; padding: 2px 9px; border-radius: 999px;
    background: var(--mmd-accent-soft); color: var(--mmd-accent); border: 1px solid var(--mmd-line);
}
.mmd-hero-acts { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============ 通用按钮 ============ */
.mmd-btn, .mmd-mini, .mmd-hero-acts button {
    appearance: none; border: 1px solid var(--mmd-line-2); background: var(--mmd-card-2);
    color: var(--mmd-fg-2); border-radius: var(--mmd-r-sm);
    padding: 7px 12px; font-size: 13px; line-height: 1.35; white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s, transform .12s;
}
.mmd-btn:hover, .mmd-mini:hover, .mmd-hero-acts button:hover {
    background: var(--mmd-accent-soft); border-color: var(--mmd-accent); color: var(--mmd-accent);
}
.mmd-btn.is-primary, .mmd-bar-main #mmdRender {
    background: var(--mmd-accent-fill); border-color: var(--mmd-accent-fill); color: var(--mmd-on-accent); font-weight: 600;
}
.mmd-btn.is-primary:hover, .mmd-bar-main #mmdRender:hover { filter: brightness(1.1); color: #fff; }
.mmd-mini { padding: 4px 9px; font-size: 12px; }
.mmd-mini.is-danger { color: var(--mmd-err); }
.mmd-mini.is-danger:hover { background: rgba(240, 122, 122, .12); border-color: var(--mmd-err); }
.mmd-sep { flex: 0 0 auto; width: 1px; height: 20px; background: var(--mmd-line-2); margin: 0 2px; }
.mmd-grow { flex: 1 1 auto; min-width: 4px; }

/* ============ 工具条 ============ */
.mmd-bar {
    background: var(--mmd-card); border: 1px solid var(--mmd-line);
    border-radius: var(--mmd-r); padding: 10px 12px; margin-bottom: 14px;
    box-shadow: var(--mmd-shadow-sm);
}
.mmd-bar-main, .mmd-bar-sub { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.mmd-bar-sub { margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--mmd-line); }
.mmd-bar .mmd-btn { min-height: 32px; }
.mmd-switch { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--mmd-sub); white-space: nowrap; }
.mmd-switch input { accent-color: var(--mmd-accent); width: 15px; height: 15px; }
.mmd-badge {
    font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
    background: var(--mmd-card-2); border: 1px solid var(--mmd-line-2); color: var(--mmd-faint);
    font-family: ui-monospace, Consolas, monospace;
}
.mmd-badge.is-ok { color: var(--mmd-ok); border-color: var(--mmd-ok); background: var(--mmd-ok-soft); }
.mmd-stat { font-size: 12px; color: var(--mmd-fg-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.mmd-bar-meta { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }

/* ============ 三栏工作台 ============ */
.mmd-view-tabs { display: none; gap: 8px; margin-bottom: 12px; }
.mmd-view-tabs button {
    flex: 1 1 0; min-height: 42px; border: 1px solid var(--mmd-line-2);
    background: var(--mmd-card); color: var(--mmd-sub); border-radius: var(--mmd-r-sm); font-size: 14px;
}
.mmd-view-tabs button.is-on { background: var(--mmd-accent-fill); color: var(--mmd-on-accent); border-color: var(--mmd-accent-fill); font-weight: 600; }
.mmd-work { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: var(--mmd-gap); align-items: start; }
.mmd-side, .mmd-card { background: var(--mmd-card); border: 1px solid var(--mmd-line); border-radius: var(--mmd-r); box-shadow: var(--mmd-shadow-sm); min-width: 0; }
.mmd-side { position: sticky; top: 12px; display: flex; flex-direction: column; height: min(72vh, 720px); overflow: hidden; z-index: 5; }
.mmd-side-head { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--mmd-line); }
.mmd-side-head input { flex: 1 1 auto; min-width: 0; }
.mmd-side-close { display: none; }
.mmd-inp, .mmd-sel, .mmd-side-head input {
    appearance: none; background: var(--mmd-card-2); color: var(--mmd-fg);
    border: 1px solid var(--mmd-line-2); border-radius: var(--mmd-r-sm);
    padding: 7px 10px; font-size: 13px; min-height: 34px; width: 100%;
}
.mmd-inp:focus, .mmd-sel:focus, .mmd-side-head input:focus { border-color: var(--mmd-accent); outline: none; }
.mmd-side-tabs { display: flex; gap: 4px; padding: 9px 10px 0; }
.mmd-side-tabs button {
    flex: 1 1 0; padding: 6px 4px; font-size: 12.5px; border: 1px solid transparent;
    background: transparent; color: var(--mmd-sub); border-radius: 8px 8px 0 0; border-bottom: 2px solid var(--mmd-line);
}
.mmd-side-tabs button.is-on { color: var(--mmd-accent); border-bottom-color: var(--mmd-accent); background: var(--mmd-accent-soft); }
.mmd-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px; border-bottom: 1px solid var(--mmd-line); }
.mmd-chip {
    padding: 4px 10px; font-size: 12px; border-radius: 999px;
    border: 1px solid var(--mmd-line-2); background: var(--mmd-card-2); color: var(--mmd-sub);
}
.mmd-chip.is-on { background: var(--mmd-accent-fill); border-color: var(--mmd-accent-fill); color: var(--mmd-on-accent); }
.mmd-side-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px; contain: layout style; }
.mmd-ex-item { padding: 10px; border: 1px solid var(--mmd-line); border-radius: 10px; margin-bottom: 8px; background: var(--mmd-card-2); }
.mmd-ex-item:nth-child(even) { background: var(--mmd-zebra); }
.mmd-ex-t { font-size: 13.5px; font-weight: 600; color: var(--mmd-fg); }
.mmd-ex-d { font-size: 12px; color: var(--mmd-sub); margin-top: 3px; }
.mmd-ex-m { font-size: 11px; color: var(--mmd-faint); margin-top: 4px; font-family: ui-monospace, Consolas, monospace; }
.mmd-ex-acts { display: flex; gap: 6px; margin-top: 8px; }
.mmd-side-empty { padding: 22px 12px; text-align: center; color: var(--mmd-faint); font-size: 12.5px; }
.mmd-side-foot { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px; border-top: 1px solid var(--mmd-line); }
.mmd-side-foot button { flex: 1 1 auto; }

/* ============ 编辑器 / 预览卡片 ============ */
.mmd-card { display: flex; flex-direction: column; overflow: hidden; }
.mmd-side, .mmd-card { transition: box-shadow .18s, border-color .18s; }
.mmd-card--edit:focus-within { border-color: var(--mmd-line-2); box-shadow: var(--mmd-shadow-md); }
.mmd-card--prev { position: sticky; top: 12px; }
.mmd-card-head {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 10px 12px; border-bottom: 1px solid var(--mmd-line); background: var(--mmd-card-2);
    font-size: 13px; font-weight: 600; color: var(--mmd-fg-2);
}
.mmd-card-head .mmd-grow { flex: 1 1 auto; }
.mmd-card-head .mmd-mini { font-weight: 400; }
.mmd-card-foot {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 7px 12px; border-top: 1px solid var(--mmd-line); background: var(--mmd-card-2);
    font-size: 11.5px; color: var(--mmd-sub); min-height: 32px;
}
#mmdSvgSize { font-variant-numeric: tabular-nums; color: var(--mmd-fg-2); }
.mmd-card-foot .mmd-grow { flex: 1 1 auto; }
.mmd-editor-wrap { position: relative; flex: 1 1 auto; min-height: 0; background: var(--mmd-code); }
#mmdCode {
    display: block; width: 100%; height: var(--mmd-work-h); min-height: 340px; resize: vertical;
    border: 0; outline: none; padding: 14px 16px; background: transparent; color: var(--mmd-fg);
    font: var(--mmd-editor-fs)/1.7 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    tab-size: 4; white-space: pre; overflow: auto;
}
.mmd-card--edit.has-cm .mmd-editor-wrap { min-height: var(--mmd-work-h); }
.mmd-card--edit.has-cm #mmdCode { height: 0; min-height: 0; padding: 0; overflow: hidden; }
.mmd .CodeMirror {
    height: var(--mmd-work-h); min-height: 340px; background: var(--mmd-code); color: var(--mmd-fg);
    font: var(--mmd-editor-fs)/1.7 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}
.mmd .CodeMirror-gutters { background: var(--mmd-card-2); border-right: 1px solid var(--mmd-line); }
.mmd .CodeMirror-linenumber { color: var(--mmd-faint); }
.mmd .CodeMirror-cursor { border-left: 2px solid var(--mmd-accent); }
.mmd .CodeMirror-selected { background: var(--mmd-accent-soft) !important; }
.mmd .CodeMirror-activeline-background { background: rgba(127, 127, 127, .06); }
.mmd .cm-keyword { color: #c792ea; font-weight: 600; }
.mmd .cm-def { color: #82aaff; }
.mmd .cm-operator { color: #f78c6c; }
.mmd .cm-string { color: #c3e88d; }
.mmd .cm-comment { color: #69798b; font-style: italic; }
.mmd .cm-meta { color: #ffcb6b; }
.mmd .cm-number { color: #f78c6c; }
.mmd .cm-bracket { color: #89ddff; }
[data-theme="light"] .mmd .cm-keyword { color: #8b3fbf; }
[data-theme="light"] .mmd .cm-def { color: #1f5fbf; }
[data-theme="light"] .mmd .cm-operator { color: #b5451b; }
[data-theme="light"] .mmd .cm-string { color: #187a45; }
[data-theme="light"] .mmd .cm-comment { color: #7a8794; }

/* ============ 预览舞台 ============ */
.mmd-stage {
    position: relative; flex: 1 1 auto; min-height: 340px; height: var(--mmd-work-h);
    overflow: auto; overscroll-behavior: contain;
    display: flex; align-items: center; justify-content: center; padding: 24px;
    background: var(--mmd-card-2);
}
.mmd[data-bg="white"] .mmd-stage { background: #ffffff; }
.mmd[data-bg="dark"] .mmd-stage { background: #12161c; }
.mmd[data-bg="grid"] .mmd-stage {
    background-color: #f2f4f7;
    background-image: linear-gradient(45deg, #d9dfe6 25%, transparent 25%, transparent 75%, #d9dfe6 75%),
        linear-gradient(45deg, #d9dfe6 25%, transparent 25%, transparent 75%, #d9dfe6 75%);
    background-size: 20px 20px; background-position: 0 0, 10px 10px;
}
.mmd-canvas { display: inline-flex; transform-origin: center center; will-change: transform; transition: transform .12s ease-out; user-select: none; -webkit-user-select: none; }
/* width/height 由 JS 按 viewBox 写成内联样式；此处绝不能写 height:auto */
.mmd-canvas svg { max-width: none !important; }
.mmd-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--mmd-faint); font-size: 13px; pointer-events: none; text-align: center; padding: 20px; }
.mmd-empty b { font-size: 15px; color: var(--mmd-sub); }
.mmd-loading {
    position: absolute; top: 12px; right: 12px; z-index: 3; padding: 5px 12px; border-radius: 999px;
    background: var(--mmd-accent); color: #fff; font-size: 12px; box-shadow: var(--mmd-shadow-sm);
}
.mmd-zoom { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; }
.mmd-zoom button { min-width: 30px; height: 28px; padding: 3px 8px; font-size: 12px; border: 1px solid var(--mmd-line-2); background: var(--mmd-card); color: var(--mmd-fg-2); border-radius: 7px; }
.mmd-zoom button:hover { border-color: var(--mmd-accent); color: var(--mmd-accent); }
.mmd-error {
    position: absolute; left: 12px; right: 12px; bottom: 44px; z-index: 4;
    display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap;
    background: rgba(180, 42, 42, .96); color: #fff; border-radius: 10px; padding: 10px 12px;
    box-shadow: var(--mmd-shadow); font-size: 12.5px;
}
#mmdErrText { flex: 1 1 240px; min-width: 0; word-break: break-word; max-height: 88px; overflow: auto; }
.mmd-error button { background: rgba(255, 255, 255, .18); color: #fff; border: 1px solid rgba(255, 255, 255, .4); border-radius: 7px; padding: 3px 9px; font-size: 12px; }

/* ============ 浮层：设置 / 分享 / 查找 ============ */
.mmd-side-mask, .mmd-mask {
    position: fixed; inset: 0; z-index: 2000; background: rgba(6, 10, 14, .6);
    display: flex; align-items: stretch; justify-content: flex-end; padding: 0;
}
.mmd-side-mask { display: none; z-index: 1900; }
.mmd-panel {
    width: min(420px, 92vw); height: 100%; overflow-y: auto; overscroll-behavior: contain;
    background: var(--mmd-card); border-left: 1px solid var(--mmd-line); box-shadow: var(--mmd-shadow);
    padding: 18px 20px 32px;
}
.mmd-panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.mmd-panel-head h2 { font-size: 17px; margin: 0; flex: 1 1 auto; }
.mmd-panel-head button { border: 1px solid var(--mmd-line-2); background: var(--mmd-card-2); color: var(--mmd-fg-2); border-radius: 8px; padding: 4px 10px; font-size: 13px; }
.mmd-panel-note { font-size: 12px; color: var(--mmd-faint); line-height: 1.7; margin: 0 0 14px; }
.mmd-sec-t { font-size: 12px; color: var(--mmd-accent); font-weight: 700; letter-spacing: .04em; margin: 18px 0 8px; padding-bottom: 5px; border-bottom: 1px dashed var(--mmd-line); }
.mmd-field { display: grid; grid-template-columns: 116px minmax(0, 1fr); align-items: center; gap: 10px; margin-bottom: 10px; }
.mmd-field > label { font-size: 12.5px; color: var(--mmd-fg-2); }
.mmd-field .mmd-sel, .mmd-field .mmd-inp { width: 100%; }
.mmd-field-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--mmd-fg-2); min-height: 34px; }
.mmd-field-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--mmd-accent); }
.mmd-panel-acts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.mmd-panel-acts button { flex: 1 1 auto; }
.mmd-find-row { display: flex; gap: 8px; margin-bottom: 10px; }
.mmd-find-row .mmd-inp { flex: 1 1 auto; }
.mmd-find-count { font-size: 12px; color: var(--mmd-faint); margin: 4px 0 12px; }
.mmd-share-url { width: 100%; min-height: 82px; resize: vertical; font: 12px/1.6 ui-monospace, Consolas, monospace; word-break: break-all; }

/* ============ 语法速查与说明 ============ */
.mmd-help, .mmd-about {
    background: var(--mmd-card); border: 1px solid var(--mmd-line); border-radius: var(--mmd-r);
    margin-top: 16px; padding: 0 18px; box-shadow: var(--mmd-shadow-sm);
}
.mmd-help > summary, .mmd-about > summary {
    list-style: none; cursor: pointer; padding: 13px 0; font-size: 14px; font-weight: 600;
    display: flex; align-items: center; gap: 8px; color: var(--mmd-fg);
}
.mmd-help > summary::-webkit-details-marker, .mmd-about > summary::-webkit-details-marker { display: none; }
.mmd-help > summary::marker, .mmd-about > summary::marker { content: ''; }
.mmd-help[open] > summary, .mmd-about[open] > summary { border-bottom: 1px solid var(--mmd-line); }
.mmd-caret { margin-left: auto; transition: transform .18s; color: var(--mmd-faint); }
.mmd-help[open] .mmd-caret, .mmd-about[open] .mmd-caret { transform: rotate(180deg); }
.mmd-help-body, .mmd-about-body { padding: 14px 0 18px; }
.mmd-snip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; contain: layout style; }
.mmd-snip { border: 1px solid var(--mmd-line); border-radius: 10px; background: var(--mmd-card-2); padding: 11px; min-width: 0; }
.mmd-snip-t { font-size: 13px; font-weight: 600; }
.mmd-snip-d { font-size: 11.5px; color: var(--mmd-sub); margin: 3px 0 7px; }
.mmd-snip-code {
    margin: 0; padding: 9px 10px; border-radius: 8px; background: var(--mmd-code);
    color: var(--mmd-fg-2); font: 11.5px/1.55 ui-monospace, Consolas, monospace;
    white-space: pre-wrap; word-break: break-word; max-height: 150px; overflow: auto;
}
.mmd-snip-acts { display: flex; gap: 6px; margin-top: 8px; }
.mmd-about-body p { margin: 0 0 8px; font-size: 12.5px; color: var(--mmd-sub); }
.mmd-about-body ul { margin: 0; padding-left: 20px; font-size: 12.5px; color: var(--mmd-sub); }
.mmd-about-body a { color: var(--mmd-accent); }

/* ============ Toast ============ */
.mmd-toast {
    position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
    z-index: 3000; max-width: min(90vw, 520px); padding: 10px 18px; border-radius: 999px;
    background: var(--mmd-accent); color: #fff; font-size: 13px; text-align: center;
    box-shadow: var(--mmd-shadow); word-break: break-word;
}
.mmd-toast.is-err { background: #c23b3b; }

/* ============ 全屏预览（原生 + 伪全屏降级） ============ */
.mmd-card--prev:fullscreen, .mmd-card--prev:-webkit-full-screen { width: 100vw; height: 100vh; border-radius: 0; }
.mmd-card--prev:fullscreen .mmd-stage, .mmd-card--prev:-webkit-full-screen .mmd-stage { height: calc(100vh - 84px); max-height: none; }
.mmd.is-fs-pseudo .mmd-card--prev {
    position: fixed; inset: 0; z-index: 2500; width: 100vw; height: 100vh; border-radius: 0;
}
.mmd.is-fs-pseudo .mmd-card--prev .mmd-stage { height: calc(100vh - 84px); max-height: none; }

/* ============ 响应式（断点降序书写，后者覆盖前者） ============
   布局分级（依据真实浏览器实测的可用列宽，不再是「屏幕越宽、每列越窄」）：
     >= 1800   三栏：示例常驻 + 源码 + 预览，源码列 >= 500px 才够写 Mermaid 源码
     1200~1799 两栏：源码 + 预览，示例收进左侧抽屉（1440 下编辑列 383px -> 约 490px）
     <= 1199   单栏 + 代码/预览页签；工具条改横向滑动带，首屏留给工作台
     <= 900 / 767 / 420 逐级收紧留白、触控目标与字号
*/
@media (min-width: 1600px) {
    .mmd { padding: 22px 30px 64px; --mmd-gap: 16px; }
    .mmd-snip-grid { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
}
/* 三栏只有在每列都能放到 500px 以上时才启用，否则反而比两栏更挤 */
@media (min-width: 1800px) {
    .mmd-work { grid-template-columns: 288px minmax(0, 1fr) minmax(0, 1.16fr); }
    #mmdSideBtn { display: none; }
    .mmd-side-mask { display: none !important; }
}
/* 抽屉模式：< 1800 示例侧栏浮出，主区宽度全部让给编辑器与预览 */
@media (max-width: 1799px) {
    .mmd-side {
        position: fixed; left: 0; top: 0; bottom: 0; z-index: 2001;
        width: min(86vw, 330px); height: 100dvh; border-radius: 0 14px 14px 0;
        transform: translateX(-102%); transition: transform .22s ease;
        padding-top: env(safe-area-inset-top, 0px);
        box-shadow: var(--mmd-shadow);
    }
    .mmd-side.is-open { transform: translateX(0); }
    .mmd-side-close { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; flex: 0 0 auto; }
    .mmd-side-mask:not([hidden]) { display: block; }
    #mmdSideBtn { display: inline-flex; }
}
@media (max-width: 1280px) {
    .mmd-bar { padding: 9px 10px; }
    .mmd-bar-meta { margin-left: auto; }
}
/* 单栏 + 页签 + 紧凑工具条 */
@media (max-width: 1199px) {
    :root { --mmd-work-h: min(64vh, 620px); }
    .mmd { padding: 14px 14px 48px; }
    .mmd-work { grid-template-columns: minmax(0, 1fr); }
    .mmd-view-tabs { display: flex; }
    /* 必须保持 positioned：.mmd-error 是 absolute，static 会让它相对页面定位而跑出预览卡 */
    .mmd-card--prev { position: relative; }
    .mmd-work[data-view="code"] .mmd-card--prev { display: none; }
    .mmd-work[data-view="prev"] .mmd-card--edit { display: none; }
    /* 窄屏 hero 原本撑到 230px+，收紧说明行数与按钮，把首屏还给工作台 */
    .mmd-hero { padding: 12px 14px; gap: 12px; }
    .mmd-hero-ic { width: 42px; height: 42px; font-size: 22px; }
    .mmd-hero h1 { font-size: 18px; }
    .mmd-hero p {
        font-size: 12.5px;
        display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
        line-clamp: 2; overflow: hidden;
    }
    .mmd-hero-acts { width: 100%; }
    .mmd-hero-acts button { flex: 1 1 0; min-height: 40px; }
    /* 两行工具条从 500px+ 降成两条 40px 横向滑动带，全部按钮仍可达，主操作前置 */
    .mmd-bar-main, .mmd-bar-sub {
        display: flex; flex-wrap: nowrap; align-items: center; gap: 6px;
        overflow-x: auto; overflow-y: hidden; padding-bottom: 5px;
        scrollbar-width: thin; overscroll-behavior-x: contain;
    }
    .mmd-bar-sub { margin-top: 8px; padding-top: 8px; }
    .mmd-bar-main > .mmd-btn, .mmd-bar-sub > .mmd-btn { flex: 0 0 auto; min-height: 40px; }
    .mmd-bar-main > .mmd-switch {
        flex: 0 0 auto; order: -1; min-height: 40px; padding: 7px 10px;
        border: 1px solid var(--mmd-line); border-radius: var(--mmd-r-sm); background: var(--mmd-card-2);
    }
    .mmd-bar-main > #mmdRender { order: -2; }
    .mmd-bar-main > .mmd-sep, .mmd-bar-main > .mmd-grow,
    .mmd-bar-sub > .mmd-grow { display: none; }
    .mmd-bar-meta {
        order: 99; position: sticky; right: 0; flex: 0 0 auto; margin-left: auto;
        background: var(--mmd-card); padding-left: 10px; margin-right: 4px;
        box-shadow: -12px 0 10px -12px var(--mmd-line-2);
    }
    .mmd-bar::after {
        content: '← 左右滑动工具条查看更多操作 →';
        display: block; margin-top: 7px; font-size: 11px;
        color: var(--mmd-faint); text-align: center;
    }
    .mmd-snip-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}
@media (max-width: 900px) {
    :root { --mmd-work-h: min(60vh, 560px); }
    .mmd { padding: 13px 13px 46px; }
    .mmd-help, .mmd-about { padding: 0 14px; }
}
@media (max-width: 767px) {
    :root { --mmd-work-h: min(56vh, 480px); }
    .mmd { padding: 12px 12px calc(40px + env(safe-area-inset-bottom, 0px)); }
    /* 不为省空间隐藏中文徽章（标签失去说明是反模式），只收紧排版 */
    .mmd-hero-tags { gap: 5px; margin-top: 7px; }
    .mmd-tag { font-size: 11px; padding: 2px 7px; }
    .mmd-hero p { font-size: 12px; -webkit-line-clamp: 2; line-clamp: 2; }
    .mmd-hero-acts { width: 100%; }
    .mmd-hero-acts button { flex: 1 1 0; min-height: 40px; }
    .mmd-bar { padding: 9px; }
    .mmd-bar-main > .mmd-btn, .mmd-bar-sub > .mmd-btn {
        min-height: 40px; padding: 8px 10px; font-size: 13px; white-space: normal;
    }
    .mmd-switch input { width: 18px; height: 18px; }
    .mmd-stat, .mmd-badge { font-size: 11px; }
    .mmd-inp, .mmd-sel, .mmd-side-head input { font-size: 16px; min-height: 40px; }
    /* textarea 与 CodeMirror 默认 14px 会让 iOS 聚焦时自动放大页面；max() 不保留用户的大字号设置 */
    #mmdCode, .mmd .CodeMirror { font-size: 16px; font-size: max(16px, var(--mmd-editor-fs)); }
    .mmd-chip, .mmd-mini { min-height: 40px; }
    .mmd-zoom button { min-height: 40px; min-width: 40px; }
    .mmd-panel { width: 100%; max-width: none; height: min(88dvh, 760px); align-self: flex-end; border-radius: 16px 16px 0 0; border-left: 0; border-top: 1px solid var(--mmd-line); padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px)); }
    .mmd-mask { align-items: flex-end; }
    .mmd-field { grid-template-columns: 104px minmax(0, 1fr); }
    .mmd-snip-grid { grid-template-columns: minmax(0, 1fr); }
    .mmd-toast { bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 420px) {
    .mmd-hero-l { gap: 10px; }
    .mmd-hero-ic { display: none; }
    .mmd-bar-main, .mmd-bar-sub { gap: 5px; }
    .mmd-card-head { padding: 8px; gap: 5px; }
    .mmd-zoom { width: 100%; margin-left: 0; justify-content: flex-end; }
    .mmd-field { grid-template-columns: minmax(0, 1fr); gap: 4px; }
}
@media (hover: none) {
    .mmd-btn:hover, .mmd-mini:hover, .mmd-hero-acts button:hover,
    .mmd-zoom button:hover, .mmd-chip:hover {
        background: var(--mmd-card-2); border-color: var(--mmd-line-2); color: var(--mmd-fg-2); transform: none;
    }
    .mmd-btn.is-primary:hover, .mmd-bar-main #mmdRender:hover,
    .mmd-chip.is-on:hover, .mmd-view-tabs button.is-on:hover {
        background: var(--mmd-accent-fill); border-color: var(--mmd-accent-fill); color: var(--mmd-on-accent);
    }
}
@media (prefers-reduced-motion: reduce) {
    .mmd *, .mmd *::before, .mmd *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
/* 打印：只输出预览图表 */
@media print {
    body.page-mermaid-full .app > *:not(.main-content) { display: none !important; }
    .mmd-hero, .mmd-bar, .mmd-view-tabs, .mmd-side, .mmd-side-mask, .mmd-mask,
    .mmd-help, .mmd-about, .mmd-toast, .mmd-card-head, .mmd-card-foot, .mmd-error { display: none !important; }
    .mmd { padding: 0; }
    .mmd-work { display: block; }
    .mmd-work[data-view="code"] .mmd-card--prev { display: flex !important; }
    .mmd-card--edit { display: none !important; }
    .mmd-card--prev { position: relative; border: 0; box-shadow: none; }
    .mmd-stage { height: auto; min-height: 0; overflow: visible; background: #fff !important; padding: 0; }
    .mmd-canvas { transform: none !important; }
    .mmd-canvas svg { width: 100% !important; max-width: 100% !important; height: auto !important; }
}

