:root {
    --bg: #f5f6fa;
    --text: #1e293b;
    --muted: #64748b;
    --surface: #ffffff;
    --outline: #e2e8f0;
    --accent: #0f62fe;
    --accent-contrast: #ffffff;
    --focus: 0 0 0 3px rgba(15, 98, 254, 0.35);
    --slide-bg: #ffffff;
    --slide-fg: #0f172a;
    --slide-title: #111827;
    --code-bg: #f6f8fb;
    --code-fg: #0f172a;
    --blockquote-bg: #f8fafc;
    --blockquote-border: #e2e8f0;
    --shadow: 0 8px 24px rgba(2, 6, 23, 0.08), 0 2px 6px rgba(2, 6, 23, 0.05);
}

[data-theme="dark"] {
    --bg: #0b1220;
    --text: #d1d5db;
    --muted: #9ca3af;
    --surface: #0f172a;
    --outline: #1f2a44;
    --accent: #60a5fa;
    --accent-contrast: #0b1220;
    --focus: 0 0 0 3px rgba(96, 165, 250, 0.35);
    --slide-bg: #0b1220;
    --slide-fg: #e5e7eb;
    --slide-title: #93c5fd;
    --code-bg: #111827;
    --code-fg: #e5e7eb;
    --blockquote-bg: #0f172a;
    --blockquote-border: #334155;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.45);
}

/* LaTeX 样式 */
.katex {
    font-size: 1.05em;
}

.katex-display {
    margin: 1.2em 0;
    overflow: auto hidden;
    padding: 0.5em 0;
}

/* 暗色主题适配 */
[data-theme="dark"] .katex {
    color: #e2e8f0;
}

[data-theme="dark"] .katex-display {
    background: transparent;
    border-radius: 8px;
    padding: 0.8em;
}


html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app {
    display: grid;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--outline);
    position: sticky;
    top: 0;
    z-index: 5;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    letter-spacing: 0.2px;
}

.logo {
    width: 28px;
    height: 28px;
    display: inline-grid;
    place-items: center;
    border-radius: 7px;
    background: linear-gradient(135deg, var(--accent) 0%, #8ab6ff 100%);
    color: var(--accent-contrast);
    font-weight: 800;
    font-size: 14px;
    box-shadow: var(--shadow);
}

.controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.control {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--outline);
    padding: 8px 10px;
    border-radius: 10px;
}

select.control-input,
button.control-btn {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: var(--surface);
    border: 1px solid var(--outline);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
}

/* 确保选择框的圆角生效 */
select.control-input {
    border-radius: 10px !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
}

/* 下拉菜单选项的样式（部分浏览器支持） */
select.control-input option {
    border-radius: 10px;
    padding: 8px 12px;
    background: var(--surface);
    color: var(--text);
}

/* 下拉菜单容器的样式（部分浏览器支持） */
select.control-input::-ms-expand {
    display: none;
    /* 隐藏 IE/Edge 的默认下拉箭头 */
}

button.control-btn.primary {
    background: var(--accent);
    color: var(--accent-contrast);
    border-color: transparent;
}

button.control-btn:hover,
select.control-input:hover {
    filter: brightness(0.98);
}

button.control-btn:focus,
select.control-input:focus {
    outline: none;
    box-shadow: var(--focus);
}

.main {
    display: grid;
    grid-template-columns: minmax(320px, 0.45fr) 1fr;
    gap: 16px;
    padding: 16px;
}

.pane {
    background: var(--surface);
    border: 1px solid var(--outline);
    border-radius: 14px;
    display: grid;
    grid-template-rows: auto 1fr;
    box-shadow: var(--shadow);
    min-height: 0;
    /* allow children to size */
}

.pane-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--outline);
    color: var(--muted);
    font-weight: 600;
}

/* 幻灯片指示器输入框样式 */
#slideIndicator {
    display: flex;
    align-items: center;
    gap: 4px;
}

#slideInput {
    width: 50px;
    padding: 2px 4px;
    border: 1px solid var(--outline);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    font-size: 12px;
    text-align: center;
    font-family: inherit;
}

#slideInput:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus);
}

#slideInput:hover {
    border-color: var(--accent);
}

.pane-body {
    min-height: 0;
    overflow: hidden;
    /* necessary for children height calc */
}

textarea#markdownInput {
    width: 100%;
    height: 100%;
    min-height: 300px;
    border: none;
    outline: none;
    resize: none;
    padding: 14px;
    box-sizing: border-box;
    font-size: 14px;
    line-height: 1.5;
    background: transparent;
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.preview-pane .pane-body {
    position: relative;
    padding: 12px;
}

.preview-container {
    position: relative;
    height: calc(100% - 44px);
    background: var(--surface);
    border: 1px solid var(--outline);
    border-radius: 12px;
    overflow: hidden;
}

.stage-wrapper {
    position: absolute;
    inset: 48px 16px 34px 16px;
    /* leave room for header/progress */
}

.stage {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1280px;
    height: 720px;
    /* 16:9 */
    transform-origin: center center;
}

.slide {
    width: 100%;
    height: 100%;
    background: var(--slide-bg);
    color: var(--slide-fg);
    border-radius: 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    padding: 48px 56px;
    box-sizing: border-box;
}

.slide h1,
.slide h2,
.slide h3,
.slide h4,
.slide h5,
.slide h6 {
    margin: 0 0 16px 0;
    line-height: 1.1;
    color: var(--slide-title);
}

.slide h1 {
    font-size: 56px;
    font-weight: 800;
}

.slide h2 {
    font-size: 40px;
    font-weight: 800;
}

.slide h3 {
    font-size: 32px;
    font-weight: 700;
}

.slide h4 {
    font-size: 28px;
    font-weight: 700;
}

.slide h5 {
    font-size: 24px;
    font-weight: 700;
}

.slide h6 {
    font-size: 20px;
    font-weight: 700;
}

.slide p {
    font-size: 22px;
    line-height: 1.45;
    margin: 8px 0 10px;
}

.slide ul,
.slide ol {
    font-size: 22px;
    line-height: 1.45;
    padding-left: 26px;
    margin: 8px 0 10px;
}

.slide ol {
    list-style-type: decimal;
}

.slide ol li {
    display: list-item;
}

.slide li {
    margin: 6px 0;
}

/* 任务列表样式 */
.slide ul.task-list {
    list-style: none;
    padding-left: 26px;
}

.slide li.task-item {
    display: flex;
    align-items: center;
    /* 垂直居中对齐 */
    gap: 12px;
    /* 使用 gap 属性设置 checkbox 和文字之间的间距 */
    margin: 6px 0;
    margin-left: -26px;
    /* 负边距，使整个任务项向左移动 */
    padding-left: 0;
}

.slide li.task-item input[type="checkbox"] {
    margin: 0;
    margin-left: -2px;
    /* checkbox 稍微靠左，为间距留出空间 */
    width: 18px;
    height: 18px;
    cursor: default;
    flex-shrink: 0;
    accent-color: var(--accent);
}

.slide li.task-item span {
    flex: 1;
    padding-left: 0;
    /* 确保文本从正确的位置开始 */
}

.slide li.task-item span {
    flex: 1;
}

.slide a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px dotted var(--accent);
}

.slide a:hover {
    text-decoration: underline;
}

.slide img {
    max-width: 100%;
    max-height: 60vh;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

/* 在暗色主题样式中调整代码块样式 */
[data-theme="dark"] .slide pre.code {
    background: #1a1a1a;
    color: #e2e8f0;
}

/* 暗色主题的行内代码样式 */
[data-theme="dark"] .slide code:not(pre code) {
    background: #1a1a1a;
    color: #e2e8f0;
    border-color: #334155;
}

/* 调整代码块的最大宽度，防止溢出 */
.slide pre.code {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre;
    word-wrap: normal;
    background: var(--code-bg);
    color: var(--code-fg);
    padding: 14px 16px;
    border-radius: 12px;
    font-size: 18px;
    line-height: 1.4;
    border: 1px solid var(--outline);
    white-space: pre-wrap;
    word-break: break-all;
    overflow: visible;
    max-height: none;
}

.slide pre.code code {
    background: transparent;
    border: none;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

/* 行内代码样式 - 只应用于不在 pre 内的 code 标签 */
.slide code:not(pre code) {
    background: var(--code-bg);
    color: var(--code-fg);
    padding: 2px 6px;
    border-radius: 6px;
    border: 1px solid var(--outline);
    font-size: 0.9em;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}


.slide blockquote {
    background: var(--blockquote-bg);
    border-left: 4px solid var(--blockquote-border);
    padding: 10px 14px;
    border-radius: 10px;
    margin: 8px 0 10px;
    /* 让引用块根据内容自适应大小，不限制内容显示 */
    overflow: visible;
    min-height: auto;
    /* 设置字体大小与段落一致，确保公式大小正确 */
    font-size: 22px;
}

/* Markdown 表格样式 */
.slide table.md-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 22px;
}

.slide table.md-table th,
.slide table.md-table td {
    border: 1px solid #cbd5e1;
    /* 更明显的表格边框 */
    padding: 8px 10px;
    text-align: left;
    /* 默认左对齐 */
}

.slide table.md-table th {
    background: #f1f5f9;
    /* 表头浅灰背景 */
    color: var(--slide-title);
    font-weight: 700;
}

/* 表格对齐：尊重 Markdown 对齐语法（:--- 左, :---: 中, ---: 右） */
.slide table.md-table th[align="center"],
.slide table.md-table td[align="center"] {
    text-align: center;
}

.slide table.md-table th[align="right"],
.slide table.md-table td[align="right"] {
    text-align: right;
}

/* 暗色主题的表格样式 */
[data-theme="dark"] .slide table.md-table th,
[data-theme="dark"] .slide table.md-table td {
    border: 1px solid #475569;
}

[data-theme="dark"] .slide table.md-table th {
    background: #1f2937;
    color: #e5e7eb;
}

/* Admonition blocks */
.slide .admonition {
    margin: 18px 0;
    padding: 12px 12px 10px 12px;
    overflow: hidden;
    font-size: 18px;
    border-left: 5px solid var(--accent);
    border-radius: 10px;
    box-shadow: var(--shadow);
    background: var(--surface);
}

.slide .admonition-title {
    position: relative;
    margin: -12px -12px 10px -12px !important;
    padding: 10px 12px 10px 38px;
    font-weight: 800;
    background: rgba(15, 98, 254, 0.08);
    color: var(--slide-title);
}

.slide .admonition-title::before {
    position: absolute;
    top: 50%;
    left: 14px;
    width: 12px;
    height: 12px;
    transform: translateY(-50%);
    background-color: var(--accent);
    border-radius: 50%;
    content: ' ';
}

.slide .admonition-content {
    padding-left: 4px;
}

.slide .admonition.note {
    border-color: #42b983;
}

.slide .admonition.note>.admonition-title {
    background: rgba(66, 185, 131, .12);
}

.slide .admonition.note>.admonition-title::before {
    background: #42b983;
}

.slide .admonition.tip {
    border-color: #00b8d4;
}

.slide .admonition.tip>.admonition-title {
    background: rgba(0, 184, 212, .12);
}

.slide .admonition.tip>.admonition-title::before {
    background: #00b8d4;
}

.slide .admonition.important {
    border-color: #6f42c1;
}

.slide .admonition.important>.admonition-title {
    background: rgba(111, 66, 193, .12);
}

.slide .admonition.important>.admonition-title::before {
    background: #6f42c1;
}

.slide .admonition.warning {
    border-color: #ff9100;
}

.slide .admonition.warning>.admonition-title {
    background: rgba(255, 145, 0, .12);
}

.slide .admonition.warning>.admonition-title::before {
    background: #ff9100;
}

.slide .admonition.caution {
    border-color: #d73a49;
}

.slide .admonition.caution>.admonition-title {
    background: rgba(215, 58, 73, .12);
}

.slide .admonition.caution>.admonition-title::before {
    background: #d73a49;
}

.slide .admonition>:last-child {
    margin-bottom: 0 !important;
}

/* Mermaid 图表 */
.slide .mermaid,
.slide .mermaid-render {
    width: 100%;
}

.slide .mermaid-render svg {
    width: 100%;
    height: auto;
}

.slide .subtitle {
    color: var(--muted);
    font-size: 26px;
    margin-top: -6px;
}

.preview-header {
    position: absolute;
    top: 8px;
    left: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    pointer-events: none;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--outline);
    color: var(--muted);
    font-size: 12px;
    pointer-events: auto;
}

.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--outline);
    background: var(--surface);
    display: grid;
    place-items: center;
    cursor: pointer;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease-in-out;
}

.nav-btn:hover {
    filter: brightness(0.98);
}

.nav-btn:focus {
    outline: none;
    box-shadow: var(--focus);
}

.nav-prev {
    left: 24px;
}

.nav-next {
    right: 24px;
}

/* 舞台区域悬停或按钮聚焦时显示左右导航键 */
.preview-container.nav-visible .nav-btn,
.preview-container .nav-btn:focus-visible,
.preview-container .nav-btn:hover {
    opacity: 1;
    pointer-events: auto;
}

.progressbar {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 10px;
    height: 6px;
    background: var(--outline);
    border-radius: 999px;
    overflow: hidden;
    cursor: pointer;
    transition: background 0.2s ease;
}

.progressbar:hover {
    background: color-mix(in srgb, var(--outline) 80%, var(--accent) 20%);
    height: 8px;
}

.progressbar>.fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 160ms ease-out;
}

.help-hint {
    padding: 6px 10px 0 10px;
    color: var(--muted);
    font-size: 12px;
    text-align: right;
}

@media (max-width: 1100px) {
    .main {
        grid-template-columns: 1fr;
    }

    .preview-container {
        height: 65vh;
    }
}

/* 在现有的 CSS 中添加 */
.katex-display-wrapper {
    margin: 1.2em 0;
    overflow: auto hidden;
    padding: 0.5em 0;
    text-align: center;
    /* 设置与段落相同的字体大小基准，确保块级公式与行内公式大小一致 */
    font-size: 22px;
}

/* 确保块级公式内的所有 KaTeX 元素都使用正确的字体大小 */
/* 使用像素值确保与行内公式大小一致（22px * 1.05 = 23.1px） */
/* 覆盖 KaTeX CSS 中可能存在的 1.2em 等默认设置 */
/* .katex-display-wrapper .katex,
.katex-display-wrapper .katex-display,
.katex-display-wrapper .katex-display .katex,
.katex-display-wrapper .katex * {
    font-size: 23.1px !important;
} */

/* 确保所有 KaTeX 子元素也使用正确的字体大小 */
.katex-display-wrapper .katex .katex-mathml,
.katex-display-wrapper .katex .katex-html,
.katex-display-wrapper .katex .katex-html * {
    font-size: inherit !important;
}

[data-theme="dark"] .katex-display-wrapper {
    background: transparent;
    border-radius: 8px;
    padding: 0.8em;
}