:root {
    --primary: #58A6FF;
    --primary-dim: rgba(88, 166, 255, 0.15);
    --accent: #F78166;
    --success: #3FB950;
    --danger: #F85149;
    --radius: 10px;
    --radius-sm: 6px;
    --font: 'Inter', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --transition: 180ms ease;
}

body.dark {
    --bg: #0D1117;
    --bg-card: #161B22;
    --surface: rgba(255, 255, 255, 0.04);
    --border: rgba(88, 166, 255, 0.12);
    --border-strong: rgba(88, 166, 255, 0.25);
    --text: #E6EDF3;
    --text-dim: rgba(230, 237, 243, 0.6);
    --text-muted: rgba(230, 237, 243, 0.35);
}

body.light {
    --bg: #FFFFFF;
    --bg-card: #F6F8FA;
    --surface: rgba(0, 0, 0, 0.03);
    --border: rgba(0, 0, 0, 0.1);
    --border-strong: rgba(0, 0, 0, 0.2);
    --text: #1F2328;
    --text-dim: rgba(31, 35, 40, 0.6);
    --text-muted: rgba(31, 35, 40, 0.35);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-wrap: wrap
}

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

.header-brand .logo {
    font-size: 1.3rem
}

.header-brand h1 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary)
}

.header-actions {
    display: flex;
    gap: 6px;
    align-items: center
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap
}

.btn-secondary {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text)
}

.btn-secondary:hover {
    border-color: var(--border-strong)
}

.btn-ghost {
    background: transparent;
    color: var(--text-dim)
}

.btn-ghost:hover {
    color: var(--text);
    background: var(--surface)
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.72rem
}

.editor-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    flex: 1;
    overflow: hidden
}

.pane {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--border)
}

.pane:last-child {
    border-right: none
}

.pane-header {
    padding: 8px 14px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center
}

.char-count {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted)
}

.editor {
    flex: 1;
    width: 100%;
    padding: 16px;
    border: none;
    background: var(--bg-card);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.7;
    resize: none;
    outline: none
}

.editor::placeholder {
    color: var(--text-muted)
}

.preview {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
    background: var(--bg-card);
    line-height: 1.7
}

.preview h1,
.preview h2,
.preview h3,
.preview h4 {
    margin: 1.2em 0 0.4em;
    font-weight: 600;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.3em
}

.preview h1 {
    font-size: 1.5rem
}

.preview h2 {
    font-size: 1.25rem
}

.preview h3 {
    font-size: 1.1rem;
    border: none
}

.preview p {
    margin: 0.6em 0;
    color: var(--text)
}

.preview a {
    color: var(--primary);
    text-decoration: none
}

.preview a:hover {
    text-decoration: underline
}

.preview code {
    background: var(--surface);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.85em
}

.preview pre {
    background: var(--bg) !important;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    overflow-x: auto;
    margin: 0.8em 0
}

.preview pre code {
    background: none;
    padding: 0
}

.preview blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 16px;
    margin: 0.8em 0;
    color: var(--text-dim)
}

.preview ul,
.preview ol {
    padding-left: 24px;
    margin: 0.6em 0
}

.preview li {
    margin: 0.2em 0
}

.preview table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.8em 0
}

.preview th,
.preview td {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: left;
    font-size: 0.85rem
}

.preview th {
    background: var(--surface);
    font-weight: 600
}

.preview img {
    max-width: 100%;
    border-radius: var(--radius-sm)
}

.preview hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.2em 0
}

.preview input[type="checkbox"] {
    margin-right: 6px;
    accent-color: var(--success)
}

.toc-panel {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    max-height: 200px;
    overflow-y: auto
}

.toc-panel h3 {
    font-size: 0.8rem;
    margin-bottom: 6px;
    color: var(--text-dim)
}

.toc-panel ul {
    list-style: none;
    padding: 0
}

.toc-panel li {
    padding: 2px 0
}

.toc-panel a {
    font-size: 0.75rem;
    color: var(--primary);
    text-decoration: none
}

.toc-panel a:hover {
    text-decoration: underline
}

.toc-panel .toc-h2 {
    padding-left: 12px
}

.toc-panel .toc-h3 {
    padding-left: 24px
}

::-webkit-scrollbar {
    width: 6px
}

::-webkit-scrollbar-track {
    background: transparent
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px
}

@media(max-width:768px) {
    .editor-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr
    }

    .header {
        flex-direction: column;
        align-items: flex-start
    }
}