:root {
    --background: #ffffff;
    --surface: #f8f9fa;
    --primary: #007bff;
    --secondary: #6c757d;
    --text: #212529;
    --textSecondary: #6c757d;
    --border: #dee2e6;
    --shadow: rgba(0,0,0,0.1);
}

[data-theme="dark"] {
    --background: #1a1a1a;
    --surface: #2d2d2d;
    --primary: #0d6efd;
    --secondary: #6c757d;
    --text: #ffffff;
    --textSecondary: #adb5bd;
    --border: #495057;
    --shadow: rgba(255,255,255,0.1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --background: #1a1a1a;
        --surface: #2d2d2d;
        --primary: #0d6efd;
        --secondary: #6c757d;
        --text: #ffffff;
        --textSecondary: #adb5bd;
        --border: #495057;
        --shadow: rgba(255,255,255,0.1);
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--background);
    color: var(--text);
    transition: background-color 0.3s ease, color 0.3s ease;
}

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

.tool-header {
    text-align: center;
    margin-bottom: 32px;
}

.tool-header h1 {
    margin: 0 0 8px 0;
    color: var(--text);
    font-size: 2.5rem;
    font-weight: 700;
}

.subtitle {
    color: var(--textSecondary);
    font-size: 1.1rem;
    margin: 0 0 16px 0;
}

.notice {
    margin-top: 16px;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 2px 8px var(--shadow);
}

.upload {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    margin: 16px 0;
    transition: all 0.3s ease;
    background: var(--background);
}

.upload:hover {
    border-color: var(--primary);
    background: var(--surface);
}

.upload p {
    margin: 0;
    color: var(--textSecondary);
    font-size: 1.1rem;
}

.row {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 16px;
}

.btn {
    padding: 12px 24px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--background);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover:not([disabled]) {
    background: var(--surface);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover:not([disabled]) {
    background: var(--primary);
    opacity: 0.9;
}

.editor {
    margin-top: 24px;
}

.editor h2 {
    color: var(--text);
    margin: 0 0 12px 0;
    font-size: 1.3rem;
    font-weight: 600;
}

.split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-top: 16px;
}

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

.col {
    display: flex;
    flex-direction: column;
}

.viewer {
    min-height: 300px;
    max-height: 500px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--background);
    padding: 16px;
    overflow-y: auto;
    font-family: Georgia, serif;
    line-height: 1.6;
    flex: 1;
}

.viewer h1, .viewer h2, .viewer h3, .viewer h4, .viewer h5, .viewer h6 {
    color: var(--text);
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

.viewer p {
    margin-bottom: 1em;
    color: var(--text);
}

.viewer table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

.viewer th, .viewer td {
    border: 1px solid var(--border);
    padding: 8px;
    text-align: left;
}

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

#editor {
    width: 100%;
    min-height: 300px;
    max-height: 500px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--background);
    color: var(--text);
    padding: 16px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    flex: 1;
}

#editor:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.1);
}

.hint {
    color: var(--textSecondary);
    text-align: center;
    margin-top: 24px;
    font-size: 0.9rem;
    padding: 8px;
    background: var(--surface);
    border-radius: 6px;
    border: 1px solid var(--border);
}

/* Scrollbar styling */
.viewer::-webkit-scrollbar,
#editor::-webkit-scrollbar {
    width: 8px;
}

.viewer::-webkit-scrollbar-track,
#editor::-webkit-scrollbar-track {
    background: var(--surface);
    border-radius: 4px;
}

.viewer::-webkit-scrollbar-thumb,
#editor::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.viewer::-webkit-scrollbar-thumb:hover,
#editor::-webkit-scrollbar-thumb:hover {
    background: var(--textSecondary);
}

/* Animation classes */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
    100% {
        opacity: 1;
    }
}

/* Responsive improvements */
@media (max-width: 768px) {
    .container {
        padding: 16px 12px;
    }

    .tool-header h1 {
        font-size: 2rem;
    }

    .panel {
        padding: 16px;
        margin-bottom: 16px;
    }

    .upload {
        padding: 24px 16px;
    }

    .split {
        gap: 16px;
    }

    .viewer,
    #editor {
        min-height: 250px;
        max-height: 400px;
    }

    .row {
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .tool-header h1 {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .btn {
        padding: 10px 16px;
        font-size: 13px;
    }
}

/* Print styles */
@media print {
    body {
        background: white;
        color: black;
    }

    .panel, .upload, .row, .hint {
        display: none;
    }

    .tool-header {
        margin-bottom: 16px;
    }

    .viewer {
        border: none;
        background: white;
        color: black;
        max-height: none;
        overflow: visible;
    }
}

