:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --border: #e6e8eb;
    --text: #1f2329;
    --muted: #8a919c;
    --accent: #3b6cff;
    --accent-dark: #2a56d8;
    --shadow: 0 6px 24px rgba(23, 32, 56, 0.08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
}

[v-cloak] { display: none; }

button { font-family: inherit; }

/* ---------- 顶栏 ---------- */
.topbar {
    height: 56px;
    flex-shrink: 0;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, #4f74ff, #2f57d6);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.5px;
}

.brand-name { font-size: 15px; font-weight: 600; }

.top-actions { display: flex; align-items: center; gap: 10px; }

.btn {
    height: 34px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: #374151;
    font-size: 13px;
    cursor: pointer;
    transition: all .18s ease;
}

.btn:hover { border-color: #c8d3ea; color: var(--accent); }

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
    background: linear-gradient(135deg, #4f74ff, #2f57d6);
    border-color: transparent;
    color: #fff;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(59, 108, 255, .28);
}

.btn-primary:hover { color: #fff; filter: brightness(1.05); }

/* ---------- 导出下拉菜单 ---------- */
.export-wrap { position: relative; }

.export-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0 12px;
}

.export-btn .chevron {
    opacity: .9;
    transition: transform .18s ease;
}

.export-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 218px;
    padding: 6px;
    background: #fff;
    border: 1px solid #eceef1;
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(20, 30, 55, .16);
    z-index: 60;
    animation: menu-in .14s ease;
}

@keyframes menu-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: 36px;
    padding: 0 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #2b3038;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.menu-item:hover { background: #f5f7fb; }

.menu-icon {
    width: 16px;
    height: 16px;
    flex: none;
    color: #6b7280;
}

.menu-text { flex: 1 1 auto; }

.menu-value {
    margin-left: auto;
    color: #8a919c;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.menu-chevron {
    margin-left: 2px;
    color: #9aa1ab;
    flex: none;
}

.menu-divider {
    height: 1px;
    margin: 5px 4px;
    background: #f0f1f4;
}

.menu-item.has-submenu { position: relative; }

.submenu {
    position: absolute;
    top: -4px;
    left: 100%;
    margin-left: 4px;
    width: 130px;
    padding: 6px;
    background: #fff;
    border: 1px solid #eceef1;
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(20, 30, 55, .18);
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 5;
    animation: menu-in .12s ease;
}

.submenu button {
    height: 32px;
    padding: 0 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #4b5563;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.submenu button:hover { background: #f5f7fb; }

.submenu button.active {
    background: #eef2ff;
    color: var(--accent);
    font-weight: 600;
}

/* ---------- 主区域 ---------- */
#app {
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.workspace {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: stretch;
    gap: 0;
}

.pane-head {
    height: 42px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: #fff;
    flex-shrink: 0;
}

.pane-title { font-size: 13px; font-weight: 600; color: #374151; }

.pane-tip { font-size: 12px; color: var(--muted); }

/* ---------- 编辑器 ---------- */
.editor-pane {
    flex: 0 0 auto;
    width: 480px;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow: hidden;
}

.pane-resizer {
    flex: 0 0 6px;
    width: 6px;
    cursor: col-resize;
    background: transparent;
    position: relative;
    z-index: 5;
    transition: background .15s ease;
}

.pane-resizer:hover,
.pane-resizer.active {
    background: rgba(59, 108, 255, .25);
}

.pane-resizer::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 36px;
    background: #d7dae0;
    border-radius: 2px;
}

.pane-resizer:hover::after,
.pane-resizer.active::after {
    background: var(--accent);
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    background: #fbfcfd;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.editor-toolbar button {
    min-width: 30px;
    height: 28px;
    padding: 0 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: #4b5563;
    font-size: 12px;
    cursor: pointer;
}

.editor-toolbar button:hover { background: #eef2ff; color: var(--accent); }

.tb-divider {
    width: 1px;
    height: 16px;
    background: var(--border);
    margin: 0 6px;
}

.md-source { display: none; }

.editor-body {
    flex: 1 1 0;
    min-height: 0;
    position: relative;
}

.editor-body .CodeMirror {
    position: absolute;
    inset: 0;
    height: auto !important;
    width: auto;
    font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    line-height: 1.75;
    background: #fff;
}

.CodeMirror-lines { padding: 12px 0; }

.CodeMirror-gutters {
    background: #fafbfc;
    border-right: 1px solid #f0f1f4;
}

.CodeMirror-linenumber { color: #c3c8d1; }

.CodeMirror-scroll { padding-right: 8px; }

.editor-status {
    height: 30px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
    background: #fff;
    flex-shrink: 0;
}

.status-right { margin-left: auto; }

/* ---------- 预览 ---------- */
.preview-pane {
    flex: 1 1 0;
    min-width: 360px;
    display: flex;
    flex-direction: column;
    background: #eef0f3;
    border-right: 1px solid var(--border);
    overflow: hidden;
    position: relative;
}

.zoom-wrap {
    flex-shrink: 0;
}

/* 底部缩放条：与左侧编辑器状态栏一致的固定底栏 */
.zoom-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 30px;
    padding: 0 16px;
    background: #fff;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: #374151;
    user-select: none;
}

.zoom-btn {
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #374151;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

.zoom-btn:hover { background: #f1f2f5; }

.zoom-slider {
    width: 110px;
    accent-color: var(--accent);
    height: 4px;
}

.zoom-value {
    position: relative;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px 6px;
    border-radius: 6px;
    cursor: pointer;
    font-variant-numeric: tabular-nums;
}

.zoom-value:hover { background: #f1f2f5; }

.zoom-caret { font-size: 10px; color: #9aa1ad; }

.zoom-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    min-width: 96px;
    padding: 6px;
    background: #fff;
    border: 1px solid #eceef1;
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(20, 30, 55, .16);
}

/* 代码块行号：float + sticky，横向滚动时吸附左侧 */
.code-ln {
    position: sticky;
    left: 0;
    float: left;
    width: 2.4em;
    margin-right: 12px;
    padding-right: 10px;
    border-right: 1px solid rgba(128, 128, 128, .25);
    background: inherit;
    color: rgba(128, 128, 128, .55);
    text-align: right;
    font: inherit;
    white-space: pre;
    user-select: none;
}

.preview-scroll {
    flex: 1 1 auto;
    overflow: auto;
    padding: 28px 24px;
    display: flex;
}

.preview-scroll > * {
    /* 四个方向 auto margin：既让卡片水平/垂直居中，
       又能阻止 flex 交叉轴 stretch 把长图卡拉到视口高度 */
    margin: auto;
}

.md-card {
    width: 440px;
    flex-shrink: 0;
    padding: 32px 28px;
    border-radius: 10px;
    background: #fff;
    box-shadow: var(--shadow);
    transition: width .18s ease, height .18s ease, background .18s ease;
}

.md-card.frame-none { border: 1px solid #eceef1; }

/* 简写图片卡片：150x150 缩略图 + 介绍文字 */
.md-fig {
    margin: 18px 0;
    text-align: center;
}

.md-fig img {
    width: 150px;
    height: 150px;
    object-fit: cover;
    border-radius: 12px;
    display: inline-block;
    box-shadow: 0 4px 14px rgba(20, 30, 55, .10);
}

.md-fig figcaption,
.md-fig .md-fig-cap {
    margin: 8px 0 0;
    font-size: 13px;
    line-height: 1.6;
    color: #6b7280;
    text-align: center;
}

/* 多页分页 */
.md-pages {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: fit-content;
    padding-bottom: 16px;
}

.md-page {
    position: relative;
    overflow: hidden;
}

.page-num {
    position: absolute;
    bottom: 12px;
    font-size: 11px;
    color: #9aa1ab;
    letter-spacing: 1px;
    pointer-events: none;
}

.page-num.num-center { left: 0; right: 0; text-align: center; }
.page-num.num-right { right: 24px; }

/* 隐藏测量容器：保持排版但不可见 */
.md-measure {
    position: absolute;
    top: 0;
    left: -9999px;
    visibility: hidden;
    pointer-events: none;
}

.md-card.frame-blue {
    border: 4px solid #4f74ff;
    outline: 3px dotted #b9c7ff;
    outline-offset: 5px;
}

.md-card.frame-green {
    border: 4px solid #23a55a;
    outline: 3px dotted #a9dcc0;
    outline-offset: 5px;
}

.md-card.frame-purple {
    border: 4px solid #8b5cf6;
    outline: 3px dotted #d8c9ff;
    outline-offset: 5px;
}

.md-card.frame-orange {
    border: 4px solid #f59e0b;
    outline: 3px dotted #fbe0b0;
    outline-offset: 5px;
}

/* ---------- Markdown 正文（预览） ---------- */
.markdown-body { word-break: break-word; }

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    color: #111827;
    line-height: 1.45;
    margin: 1.2em 0 .6em;
}

.markdown-body h1 { font-size: 1.7em; padding-bottom: .3em; border-bottom: 2px solid #eaecef; }
.markdown-body h2 { font-size: 1.38em; padding-bottom: .25em; border-bottom: 1px solid #eaecef; }
.markdown-body h3 { font-size: 1.16em; }
.markdown-body h4 { font-size: 1em; }

.markdown-body p { margin: 0 0 .9em; line-height: 1.8; }

.markdown-body ul,
.markdown-body ol { margin: 0 0 .9em; padding-left: 1.6em; }

.markdown-body li { margin: .25em 0; line-height: 1.8; }
.markdown-body li > p { margin: 0; }

.markdown-body a { color: #3b6cff; text-decoration: none; }

.markdown-body strong { font-weight: 600; color: #111827; }

.markdown-body blockquote {
    margin: 1em 0;
    padding: .6em 1em;
    color: #57606a;
    background: #f8fafc;
    border-left: 4px solid #42b983;
    border-radius: 0 4px 4px 0;
}

.markdown-body hr { border: 0; border-top: 1px solid #eaecef; margin: 1.6em 0; }

.markdown-body img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 1em auto;
    border-radius: 4px;
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    font-size: .92em;
}

.markdown-body th,
.markdown-body td {
    border: 1px solid #dfe2e5;
    padding: .45em .7em;
    text-align: left;
}

.markdown-body th { background: #f6f8fa; font-weight: 600; }

.markdown-body code {
    font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: .88em;
}

.markdown-body :not(pre) > code {
    background: #f2f3f5;
    color: #c7254e;
    padding: .15em .35em;
    border-radius: 4px;
}

.markdown-body pre {
    margin: 1em 0;
    padding: .9em 1em;
    border-radius: 8px;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 480px;
    font-size: .85em;
    line-height: 1.65;
    white-space: pre;
}

.markdown-body pre code { background: transparent; padding: 0; font-size: 1em; }

.md-card.theme-github pre { background: #f6f8fa; color: #24292f; }
.md-card.theme-monokai pre { background: #272822; color: #f8f8f2; }
.md-card.theme-atom-one-dark pre { background: #282c34; color: #abb2bf; }

/* ---------- 设置面板 ---------- */
.settings-pane {
    flex: 0 0 280px;
    width: 280px;
    background: #fff;
    overflow-y: auto;
    border-left: 1px solid var(--border);
}

.setting-group { padding: 16px 18px; border-bottom: 1px solid #f1f2f5; }

.setting-label {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
}

.setting-row { display: flex; align-items: center; gap: 10px; }

.setting-row input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
    height: 4px;
}

.setting-value {
    width: 52px;
    text-align: right;
    font-size: 12px;
    color: #4b5563;
    font-variant-numeric: tabular-nums;
}

.quick-sizes { display: flex; gap: 8px; margin-top: 10px; }

.quick-sizes button {
    flex: 1;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fafbfc;
    color: #6b7280;
    font-size: 12px;
    cursor: pointer;
}

.quick-sizes button.active {
    border-color: var(--accent);
    background: #eef2ff;
    color: var(--accent);
    font-weight: 600;
}

.size-row {
    display: flex;
    gap: 10px;
}

.size-field.disabled {
    opacity: .45;
}

.size-field {
    flex: 1;
    display: flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}

.size-field:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 108, 255, .12);
}

.size-prefix {
    padding: 0 8px;
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
}

.size-field input[type="number"] {
    flex: 1;
    min-width: 0;
    height: 34px;
    border: 0;
    outline: none;
    font-size: 13px;
    color: #374151;
    text-align: center;
    font-variant-numeric: tabular-nums;
    background: transparent;
}

.size-field input[type="number"]::-webkit-outer-spin-button,
.size-field input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.size-unit {
    padding: 0 10px 0 4px;
    font-size: 12px;
    color: var(--muted);
}

.preset-select {
    width: 100%;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: #374151;
    font-size: 13px;
    outline: none;
    cursor: pointer;
}

.preset-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 108, 255, .12);
}

select {
    width: 100%;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: #374151;
    font-size: 13px;
    outline: none;
    cursor: pointer;
}

select:focus { border-color: var(--accent); }

.frame-options { display: flex; gap: 10px; }

.frame-chip {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid transparent;
    background: #e5e7eb;
    cursor: pointer;
    position: relative;
}

.frame-chip:hover { transform: scale(1.08); }

.frame-chip.active { border-color: var(--accent); box-shadow: 0 0 0 2px #e3ebff; }

.chip-none { background: #fff; border: 1px solid #d1d5db; }
.chip-blue { background: #4f74ff; }
.chip-green { background: #23a55a; }
.chip-purple { background: #8b5cf6; }
.chip-orange { background: #f59e0b; }

.bg-options { display: flex; gap: 10px; }

.bg-chip {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
    cursor: pointer;
}

.bg-chip.active { outline: 2px solid var(--accent); outline-offset: 2px; }

.setting-notes {
    margin: 0;
    padding-left: 16px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.8;
}

/* ---------- 提示 ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 36px;
    transform: translateX(-50%);
    background: rgba(31, 35, 41, .9);
    color: #fff;
    padding: 9px 18px;
    border-radius: 8px;
    font-size: 13px;
    z-index: 50;
    animation: toast-in .2s ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

@media (max-width: 1180px) {
    .preview-pane { width: 520px; }
    .settings-pane { flex-basis: 250px; width: 250px; }
}

@media (max-width: 900px) {
    .workspace { flex-direction: column; height: auto; }
    .editor-pane { height: 46vh; }
    .preview-pane { width: 100%; height: 54vh; }
    .settings-pane { width: 100%; flex-basis: auto; }
    .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
    .workspace { height: calc(100vh - 96px); }
}
