* {
    box-sizing: border-box;
}

:root {
    --primary: #c1440e;
    --primary-soft: #fff5f0;
    --bg-color: #f5f0e8;
    --border: #e2d7c8;
    --editor-bg: #fff;
    --editor-border: #e4e4e4;
    --preview-bg: #f7f4ef;
}

body {
    margin: 0;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg-color);
    color: #2e2e2e;
}

.mdpreview-container {
    max-width: 1200px;
    margin: 0 auto;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    padding: 28px 36px;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 8px;
}

.back-home {
    position: absolute;
    left: 0;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    color: #888;
    text-decoration: none;
    background: #fafafa;
}

.back-home svg {
    width: 20px;
    height: 20px;
}

.language-switcher {
    position: absolute;
    right: 0;
}

.language-select {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 8px 10px;
}

h1 {
    margin: 0;
    color: var(--primary);
}

.subtitle {
    text-align: center;
    margin: 0 0 20px;
    color: #666;
}

.toolbar-section {
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid #ece8e1;
    border-radius: 12px;
    background: linear-gradient(180deg, #fdfcfa 0%, #f8f6f2 100%);
}

.toolbar-title {
    margin: 0 0 8px;
    font-size: 0.9rem;
    color: #666;
}

.toolbar-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.export-actions {
    display: flex;
    gap: 8px;
}

.quick-insert-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
}

.quick-group {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid #e8e4dc;
    border-radius: 10px;
    background: #fff;
}

.quick-group-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #8a7f72;
    text-transform: uppercase;
    white-space: nowrap;
    padding-right: 6px;
    border-right: 1px solid #ece8e1;
}

.quick-group-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.quick-btn {
    border: 1px solid #e4e0d8;
    background: #faf9f7;
    border-radius: 6px;
    padding: 4px 9px;
    cursor: pointer;
    font-size: 0.82rem;
    color: #444;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.quick-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-soft);
}

.panes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.pane {
    border: 1px solid #e6e6e6;
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
    display: flex;
    flex-direction: column;
    min-height: 480px;
}

.pane-editor {
    border-color: var(--editor-border);
    background: #fff;
}

.pane-preview {
    border-color: #e0dbd2;
    background: var(--preview-bg);
}

.pane-header {
    padding: 10px 14px;
    border-bottom: 1px solid #efefef;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.pane-editor .pane-header {
    background: #fff;
    border-bottom-color: var(--editor-border);
}

.pane-preview .pane-header {
    background: #ede9e3;
    border-bottom-color: #e0dbd2;
}

.pane-preview .pane-header h2 {
    color: #3a3632;
}

.pane-header h2 {
    margin: 0;
    font-size: 1rem;
}

.pane-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    border: 1px solid #dfdfdf;
    background: #fff;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.82rem;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-icon:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.editor-input {
    width: 100%;
    min-height: 420px;
    border: none;
    outline: none;
    resize: none;
    padding: 16px 18px;
    line-height: 1.7;
    font-size: 0.92rem;
    color: #2a2826;
    background: #fff;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    overflow: hidden;
    flex: 1;
}

.preview-output {
    min-height: 420px;
    flex: 1;
    padding: 16px 18px;
    line-height: 1.75;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    user-select: text;
    -webkit-user-select: text;
    background: var(--preview-bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.preview-output h1,
.preview-output h2,
.preview-output h3 {
    color: #2a2826;
    line-height: 1.35;
    margin: 1.2em 0 0.5em;
}

.preview-output h1 {
    font-size: 1.55rem;
    padding-bottom: 0.3em;
    border-bottom: 1px solid #ece8e1;
}

.preview-output h2 {
    font-size: 1.25rem;
}

.preview-output h3 {
    font-size: 1.05rem;
    color: #444;
}

.preview-output p {
    margin: 0.65em 0;
}

.preview-output ul,
.preview-output ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.preview-output blockquote {
    margin: 0.8em 0;
    padding: 0.4em 0 0.4em 1em;
    border-left: 3px solid var(--primary);
    color: #555;
    background: #faf9f7;
    border-radius: 0 6px 6px 0;
}

.preview-output a {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.preview-output :not(pre) > code {
    padding: 0.15em 0.4em;
    border-radius: 4px;
    background: #f3f1ed;
    font-size: 0.88em;
    color: #8a3b12;
}

.preview-output pre {
    background: #f6f6f6;
    padding: 10px;
    border-radius: 8px;
    overflow: auto;
}

.preview-output pre code.hljs {
    display: block;
    padding: 0;
    background: transparent;
}

.preview-output .hljs-keyword,
.preview-output .hljs-selector-tag,
.preview-output .hljs-title {
    color: #8a2be2;
}

.preview-output .hljs-string,
.preview-output .hljs-attr {
    color: #0c7a43;
}

.preview-output .hljs-number,
.preview-output .hljs-literal {
    color: #b3541e;
}

.preview-output .hljs-comment {
    color: #8a8a8a;
}

.preview-output code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.copy-toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    margin: 0;
    color: #fff;
    background: rgba(33, 115, 50, 0.95);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.85rem;
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 10001;
}

.copy-toast.show {
    opacity: 1;
    transform: translateY(0);
}

.pane.fullscreen {
    position: fixed;
    inset: 12px;
    z-index: 9999;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.pane.fullscreen .editor-input {
    min-height: 0;
    flex: 1;
    height: auto;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.pane.fullscreen .preview-output {
    min-height: 0;
    flex: 1;
}

body.fullscreen-lock {
    overflow: hidden;
}

footer {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #eee;
    text-align: center;
    color: #666;
    font-size: 0.9rem;
}

@media (max-width: 900px) {
    .panes {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .pane {
        min-height: 360px;
    }

    .editor-input,
    .preview-output {
        min-height: 280px;
    }

    .toolbar-head {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .export-actions {
        width: 100%;
    }

    .export-actions .btn-icon {
        flex: 1;
    }

    .quick-insert-bar {
        gap: 8px;
    }

    .quick-group {
        width: 100%;
        flex-wrap: wrap;
        align-items: flex-start;
    }
}

@media (max-width: 600px) {
    body {
        padding: 10px;
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .mdpreview-container {
        padding: 16px 12px;
        border-radius: 12px;
    }

    .header-top {
        display: grid;
        grid-template-columns: 36px 1fr auto;
        align-items: center;
        gap: 8px;
        margin-bottom: 4px;
    }

    .back-home {
        position: static;
        width: 36px;
        height: 36px;
    }

    h1 {
        font-size: 1.2rem;
        text-align: center;
        line-height: 1.3;
        margin: 0;
    }

    .language-switcher {
        position: static;
    }

    .language-select {
        padding: 6px 8px;
        font-size: 0.85rem;
    }

    .subtitle {
        font-size: 0.9rem;
        margin-bottom: 14px;
    }

    .toolbar-section {
        padding: 10px;
        margin-bottom: 12px;
    }

    .toolbar-title {
        margin: 0;
    }

    .quick-group {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        padding: 8px;
    }

    .quick-group-label {
        border-right: none;
        border-bottom: 1px solid #ece8e1;
        padding-right: 0;
        padding-bottom: 4px;
    }

    .quick-group-buttons {
        gap: 6px;
    }

    .quick-btn {
        min-height: 34px;
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    .pane {
        min-height: 0;
        border-radius: 10px;
    }

    .pane-header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px 10px;
    }

    .pane-header h2 {
        font-size: 0.95rem;
    }

    .pane-actions {
        width: 100%;
        justify-content: stretch;
        gap: 6px;
    }

    .pane-actions .btn-icon {
        flex: 1;
        min-height: 36px;
        padding: 8px 6px;
        font-size: 0.78rem;
        text-align: center;
    }

    .editor-input,
    .preview-output {
        min-height: 220px;
        padding: 12px 14px;
        font-size: 0.9rem;
    }

    .preview-output h1 {
        font-size: 1.3rem;
    }

    .preview-output h2 {
        font-size: 1.12rem;
    }

    .preview-output h3 {
        font-size: 1rem;
    }

    .preview-output pre {
        font-size: 0.82rem;
    }

    .pane.fullscreen {
        inset: 0;
        border-radius: 0;
    }

    .copy-toast {
        left: 12px;
        right: 12px;
        bottom: max(12px, env(safe-area-inset-bottom));
        text-align: center;
    }

    footer {
        margin-top: 16px;
        padding-top: 12px;
        font-size: 0.85rem;
    }

    .footer-tools-nav {
        gap: 8px 12px;
        font-size: 0.82rem;
    }
}
