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

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --success-color: #16a34a;
    --success-hover: #15803d;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --danger-color: #dc2626;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 8px;
    --transition: all 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.header {
    text-align: center;
    margin-bottom: 32px;
    padding: 32px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

.editor-section,
.result-section {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

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

.form-group {
    margin-bottom: 16px;
}

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

@media (max-width: 640px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 10px 14px;
    font-size: 0.9375rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-primary);
    transition: var(--transition);
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-secondary);
}

.form-textarea {
    min-height: 300px;
    resize: vertical;
    font-family: inherit;
}

.code-area {
    font-family: 'SF Mono', 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
}

.action-buttons {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 0.9375rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
}

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

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--secondary-hover);
    color: white;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
}

.btn-icon {
    font-size: 1rem;
}

.tabs {
    display: flex;
    gap: 4px;
    background: var(--background);
    padding: 4px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.tab {
    flex: 1;
    padding: 10px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    background: var(--surface);
    color: var(--primary-color);
    box-shadow: var(--shadow);
}

.tab-content {
    display: none;
    min-height: 250px;
}

.tab-content.active {
    display: block;
}

.preview-content {
    padding: 20px;
    background: var(--background);
    border-radius: var(--radius);
    min-height: 250px;
    max-height: 400px;
    overflow-y: auto;
    font-size: 0.9375rem;
    line-height: 1.8;
}

.preview-content h1 {
    font-size: 1.75rem;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.preview-content h2 {
    font-size: 1.5rem;
    margin-top: 24px;
    margin-bottom: 12px;
}

.preview-content h3 {
    font-size: 1.25rem;
    margin-top: 20px;
    margin-bottom: 10px;
}

.preview-content p {
    margin-bottom: 12px;
}

.preview-content ul,
.preview-content ol {
    margin-bottom: 12px;
    padding-left: 24px;
}

.preview-content li {
    margin-bottom: 4px;
}

.preview-content code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.875rem;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.preview-content pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: 12px;
}

.preview-content pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

.preview-content blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text-secondary);
    font-style: italic;
}

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

.placeholder-text {
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    padding: 40px;
}

.word-count,
.reading-time {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    background: var(--background);
    padding: 4px 10px;
    border-radius: 4px;
}

.publish-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.publish-options {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 16px;
}

.form-group.inline {
    margin-bottom: 0;
    flex: 1;
    max-width: 300px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.publish-result {
    margin-top: 16px;
    padding: 16px;
    border-radius: var(--radius);
}

.publish-result.hidden {
    display: none;
}

.result-success {
    background: #dcfce7;
    border: 1px solid #86efac;
    padding: 16px;
    border-radius: var(--radius);
}

.result-success h3 {
    color: #166534;
    margin-bottom: 8px;
}

.result-success p {
    color: #15803d;
    margin-bottom: 12px;
}

.view-link {
    display: inline-block;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.view-link:hover {
    text-decoration: underline;
}

.result-error {
    background: #fee2e2;
    border: 1px solid #fca5a5;
    padding: 16px;
    border-radius: var(--radius);
}

.result-error h3 {
    color: #991b1b;
    margin-bottom: 8px;
}

.result-error p {
    color: #dc2626;
}

.footer {
    text-align: center;
    padding: 24px;
    margin-top: 32px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-overlay p {
    color: white;
    margin-top: 16px;
    font-size: 1rem;
}

.file-list-section {
    background: var(--background);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.file-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.file-list-header h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}

.file-dir-select {
    width: auto;
    padding: 6px 10px;
    font-size: 0.8125rem;
}

.file-list {
    max-height: 200px;
    overflow-y: auto;
}

.file-list .file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--surface);
    border-radius: 6px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.file-list .file-item:hover {
    background: var(--border-color);
}

.file-list .file-item:last-child {
    margin-bottom: 0;
}

.file-list .file-name {
    font-size: 0.8125rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-right: 8px;
}

.file-list .file-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-right: 8px;
}

.file-list .file-delete-btn {
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition);
}

.file-list .file-item:hover .file-delete-btn {
    opacity: 1;
}

.file-list .file-delete-btn:hover {
    background: var(--danger-color);
    color: white;
}

.file-list .loading-text {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    text-align: center;
    padding: 16px;
}

.file-list .empty-text {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    text-align: center;
    padding: 16px;
}

.file-list .error-text {
    color: var(--danger-color);
    font-size: 0.8125rem;
    text-align: center;
    padding: 16px;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 400px;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: var(--transition);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.modal-body p {
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 0.9375rem;
}

.modal-body .form-input {
    margin-bottom: 8px;
}

.modal-body .error-text {
    color: var(--danger-color);
    font-size: 0.8125rem;
    margin-top: 8px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.modal-footer .btn {
    padding: 10px 20px;
}

.image-upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    transition: var(--transition);
    background: var(--background);
}

.image-upload-area:hover {
    border-color: var(--primary-color);
}

.image-input {
    display: none;
}

.image-upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-secondary);
}

.image-upload-label:hover {
    color: var(--primary-color);
}

.upload-icon {
    font-size: 2rem;
}

.upload-progress {
    margin-top: 16px;
}

.progress-bar {
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

.uploaded-images {
    margin-top: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.uploaded-image-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.uploaded-image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.uploaded-image-item .copy-btn {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition);
}

.uploaded-image-item:hover .copy-btn {
    opacity: 1;
}

.uploaded-image-item .copy-btn:hover {
    background: var(--primary-color);
}

.uploaded-image-item .delete-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 0.875rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition);
}

.uploaded-image-item:hover .delete-btn {
    opacity: 1;
}

.uploaded-image-item .delete-btn:hover {
    background: var(--danger-color);
}

.form-hint {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

.hidden {
    display: none !important;
}

@media (max-width: 640px) {
    .container {
        padding: 16px;
    }
    
    .header {
        padding: 24px 16px;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
    
    .editor-section,
    .result-section {
        padding: 16px;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .publish-options {
        flex-direction: column;
        align-items: stretch;
    }
    
    .form-group.inline {
        max-width: none;
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        --background: #0f172a;
        --surface: #1e293b;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --border-color: #334155;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    }
    
    .preview-content code {
        background: #334155;
    }
    
    .preview-content pre {
        background: #0f172a;
    }
    
    .btn-secondary {
        background: #334155;
        color: #f1f5f9;
    }
    
    .tabs {
        background: #334155;
    }
    
    .word-count,
    .reading-time {
        background: #334155;
    }
}
