* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
    color: #202124;
    background: #f3f5f7;
    overflow-x: hidden;
}

button,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    width: 100%;
    max-width: 100vw;
    height: 100vh;
    min-height: 640px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow-x: hidden;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 14px 22px;
    background: #ffffff;
    border-bottom: 1px solid #dde3ea;
}

.topbar h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.2;
    letter-spacing: 0;
}

.topbar p {
    margin: 3px 0 0;
    color: #6b7280;
    font-size: 13px;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.ghost-link,
.text-button,
.secondary-button,
.primary-button,
.icon-button {
    border-radius: 6px;
    border: 1px solid #cfd8e3;
    background: #ffffff;
    color: #263445;
    min-height: 36px;
    padding: 0 12px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.primary-button {
    background: #16794c;
    border-color: #16794c;
    color: #ffffff;
    font-weight: 700;
}

.secondary-button:hover,
.text-button:hover,
.icon-button:hover,
.ghost-link:hover {
    background: #f7fafc;
}

.primary-button:hover {
    background: #12643f;
}

.icon-button[aria-pressed="true"] {
    background: #111827;
    border-color: #111827;
    color: #ffffff;
}

.workbench {
    min-width: 0;
    max-width: 100vw;
    min-height: 0;
    display: grid;
    grid-template-columns: 292px minmax(0, 1fr);
    overflow: hidden;
}

.theme-sidebar {
    min-width: 0;
    min-height: 0;
    background: #ffffff;
    border-right: 1px solid #dde3ea;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    padding: 12px;
}

.theme-sidebar__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #4b5563;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 10px;
}

.theme-list {
    min-width: 0;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 2px 3px 2px 0;
}

.theme-group {
    min-width: 0;
}

.theme-group__head {
    width: 100%;
    min-width: 0;
    min-height: 34px;
    border: none;
    border-radius: 6px;
    background: #eef3f7;
    color: #314155;
    display: grid;
    grid-template-columns: 16px minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px;
    padding: 0 8px;
    text-align: left;
}

.theme-group__head:hover {
    background: #e6eef5;
}

.theme-group__caret,
.theme-group__count {
    color: #64748b;
    font-size: 12px;
    font-weight: 700;
}

.theme-group__name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 800;
}

.theme-group__body {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding-top: 7px;
}

.theme-group.collapsed .theme-group__body {
    display: none;
}

.theme-card {
    width: 100%;
    flex: none;
    min-height: 42px;
    border: 1px solid #d8e0e8;
    background: #ffffff;
    border-radius: 8px;
    padding: 0 10px;
    text-align: left;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
}

.theme-card:hover {
    border-color: #9ab2cc;
    background: #f8fbff;
}

.theme-card.active {
    border-color: #16794c;
    box-shadow: 0 0 0 2px rgba(22, 121, 76, 0.14);
}

.theme-card__name {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
    color: #1f2937;
    line-height: 1.25;
}

.theme-card__meta {
    display: block;
    min-width: 0;
    max-width: 92px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #6b7280;
    font-size: 12px;
    line-height: 1.25;
    text-align: right;
}

.workspace {
    width: 100%;
    max-width: none;
    min-width: 0;
    height: 100%;
    display: grid;
    grid-template-columns: minmax(360px, 0.92fr) minmax(420px, 1.08fr);
    gap: 14px;
    padding: 14px;
    min-height: 0;
    overflow: hidden;
}

.editor-pane,
.preview-pane {
    min-width: 0;
    min-height: 0;
    background: #ffffff;
    border: 1px solid #dde3ea;
    border-radius: 8px;
    display: grid;
    grid-template-rows: auto 1fr auto;
    overflow: hidden;
}

.pane-head {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid #e5ebf0;
    font-weight: 700;
}

.pane-head small {
    display: block;
    margin-top: 2px;
    color: #6b7280;
    font-weight: 500;
}

.pane-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #6b7280;
    font-size: 13px;
    font-weight: 500;
}

.text-button {
    min-height: 30px;
    padding: 0 9px;
    font-size: 13px;
}

#markdownInput {
    min-width: 0;
    width: 100%;
    height: 100%;
    resize: none;
    border: none;
    outline: none;
    padding: 16px;
    font-family: "SF Mono", Consolas, Monaco, "Courier New", monospace;
    font-size: 14px;
    line-height: 1.65;
    color: #172033;
    background: #fcfdff;
}

.warnings {
    border-top: 1px solid #f2d7a6;
    background: #fff8e6;
    color: #7a4f01;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.5;
}

.warnings.hidden,
.toast.hidden {
    display: none;
}

.preview-shell {
    min-width: 0;
    min-height: 0;
    overflow: auto;
    background: #edf1f5;
    padding: 20px;
}

.wechat-preview-render {
    max-width: 740px;
    min-height: 100%;
    margin: 0 auto;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 8px 28px rgba(15, 23, 42, 0.12);
    overflow: hidden;
}

.preview-shell.dark-preview {
    background: #0f172a;
}

.preview-shell.dark-preview .wechat-preview-render {
    background: #111827 !important;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.38);
}

.preview-shell.dark-preview .wechat-preview-render,
.preview-shell.dark-preview .wechat-preview-render section,
.preview-shell.dark-preview .wechat-preview-render p,
.preview-shell.dark-preview .wechat-preview-render li,
.preview-shell.dark-preview .wechat-preview-render td,
.preview-shell.dark-preview .wechat-preview-render h1,
.preview-shell.dark-preview .wechat-preview-render h2,
.preview-shell.dark-preview .wechat-preview-render h3,
.preview-shell.dark-preview .wechat-preview-render h4,
.preview-shell.dark-preview .wechat-preview-render h5,
.preview-shell.dark-preview .wechat-preview-render h6 {
    background-color: #111827 !important;
    color: #d1d5db !important;
    border-color: #374151 !important;
}

.preview-shell.dark-preview .wechat-preview-render blockquote,
.preview-shell.dark-preview .wechat-preview-render pre,
.preview-shell.dark-preview .wechat-preview-render table,
.preview-shell.dark-preview .wechat-preview-render th {
    background-color: #1f2937 !important;
    color: #e5e7eb !important;
    border-color: #4b5563 !important;
}

.preview-shell.dark-preview .wechat-preview-render a,
.preview-shell.dark-preview .wechat-preview-render strong {
    color: #93c5fd !important;
}

.preview-shell.dark-preview .wechat-preview-render code {
    background-color: #1f2937 !important;
    color: #fca5a5 !important;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    background: #111827;
    color: #ffffff;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.28);
    z-index: 20;
}

@media (max-width: 980px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .top-actions {
        justify-content: flex-start;
    }

    .workspace {
        grid-template-columns: 1fr;
    }

    .editor-pane,
    .preview-pane {
        min-height: 520px;
    }
}

@media (max-width: 780px) {
    .app-shell {
        height: auto;
        min-height: 100vh;
    }

    .workbench {
        grid-template-columns: 1fr;
        overflow: visible;
    }

    .theme-sidebar {
        border-right: none;
        border-bottom: 1px solid #dde3ea;
        max-height: 280px;
    }

    .workspace {
        height: auto;
        overflow: visible;
    }
}

@media (max-width: 620px) {
    .topbar,
    .theme-sidebar {
        padding-left: 12px;
        padding-right: 12px;
    }

    .workspace {
        padding: 10px;
    }

    .top-actions > * {
        flex: 1 1 auto;
    }

    .theme-card {
        min-height: 42px;
    }
}
