/* ===== Theme Variables ===== */
[data-theme="catppuccin"] {
    --bg-primary: #1e1e2e;
    --bg-secondary: #181825;
    --bg-tertiary: #11111b;
    --header-bg: rgba(30, 30, 46, 0.85);
    --text-primary: #cdd6f4;
    --text-secondary: #a6adc8;
    --text-muted: #6c7086;
    --accent: #89b4fa;
    --accent-hover: #74a8fc;
    --border: #313244;
    --error: #f38ba8;
    --success: #a6e3a1;
    --surface: #313244;
    --surface-hover: #45475a;
    --cm-theme: dracula;
}

[data-theme="ocean"] {
    --bg-primary: #0d1117;
    --bg-secondary: #0b0f14;
    --bg-tertiary: #090c10;
    --header-bg: rgba(13, 17, 23, 0.9);
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --text-muted: #484f58;
    --accent: #58a6ff;
    --accent-hover: #4a9bef;
    --border: #21262d;
    --error: #f85149;
    --success: #56d364;
    --surface: #21262d;
    --surface-hover: #30363d;
    --cm-theme: material-darker;
}

[data-theme="sunset"] {
    --bg-primary: #1a1423;
    --bg-secondary: #15101d;
    --bg-tertiary: #100c17;
    --header-bg: rgba(26, 20, 35, 0.9);
    --text-primary: #e0d0e8;
    --text-secondary: #b0a0b8;
    --text-muted: #6a5a72;
    --accent: #e06c75;
    --accent-hover: #d35f68;
    --border: #3a2a44;
    --error: #ff6b6b;
    --success: #98c379;
    --surface: #2a1f34;
    --surface-hover: #3a2a44;
    --cm-theme: dracula;
}

[data-theme="forest"] {
    --bg-primary: #1a2332;
    --bg-secondary: #151e2b;
    --bg-tertiary: #101924;
    --header-bg: rgba(26, 35, 50, 0.9);
    --text-primary: #d4dce8;
    --text-secondary: #a8b8c8;
    --text-muted: #5a6a7a;
    --accent: #98c379;
    --accent-hover: #88b369;
    --border: #263344;
    --error: #e06c75;
    --success: #98c379;
    --surface: #1f2d3d;
    --surface-hover: #263344;
    --cm-theme: material-darker;
}

[data-theme="midnight"] {
    --bg-primary: #0a0a0f;
    --bg-secondary: #080810;
    --bg-tertiary: #05050a;
    --header-bg: rgba(10, 10, 15, 0.95);
    --text-primary: #e8e0f0;
    --text-secondary: #b8a8c8;
    --text-muted: #5a4a6a;
    --accent: #bd93f9;
    --accent-hover: #a97de9;
    --border: #1a1a2e;
    --error: #ff79c6;
    --success: #50fa7b;
    --surface: #14142a;
    --surface-hover: #1e1e3a;
    --cm-theme: dracula;
}

[data-theme="nord"] {
    --bg-primary: #2e3440;
    --bg-secondary: #2a303c;
    --bg-tertiary: #242933;
    --header-bg: rgba(46, 52, 64, 0.9);
    --text-primary: #d8dee9;
    --text-secondary: #b0b8c8;
    --text-muted: #6a7080;
    --accent: #88c0d0;
    --accent-hover: #7ab0c0;
    --border: #3b4252;
    --error: #bf616a;
    --success: #a3be8c;
    --surface: #3b4252;
    --surface-hover: #434c5e;
    --cm-theme: monokai;
}

/* ===== Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.4s ease, color 0.3s ease;
}

/* ===== Header ===== */
.header {
    height: 56px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 10;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent);
    flex-shrink: 0;
}

.logo-text {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    white-space: nowrap;
}

.branding {
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

/* ===== Buttons ===== */
.btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
    font-family: inherit;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
}

.btn.icon-btn {
    padding: 7px;
    line-height: 0;
}

.btn.small {
    padding: 4px 10px;
    font-size: 0.78rem;
}

.btn.primary {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
    font-weight: 600;
}

.btn.primary:hover {
    background: var(--accent-hover);
    filter: brightness(1.1);
    box-shadow: 0 0 16px rgba(137, 180, 250, 0.25);
}

/* ===== Settings Panel ===== */
.settings-panel {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
}

.settings-panel.hidden {
    display: none;
}

.settings-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.settings-content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 440px;
    max-width: 90vw;
    padding: 0;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 12px;
    border-bottom: 1px solid var(--border);
}

.settings-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.settings-body {
    padding: 20px 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.setting-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.theme-option {
    background: var(--bg-primary);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    cursor: pointer;
    text-align: center;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.theme-option:hover {
    border-color: var(--text-muted);
}

.theme-option.active {
    border-color: var(--accent);
    background: var(--surface);
    box-shadow: 0 0 12px rgba(137, 180, 250, 0.15);
}

.theme-preview {
    width: 100%;
    height: 24px;
    border-radius: 6px;
    display: block;
}

.font-size-control {
    display: flex;
    align-items: center;
    gap: 16px;
}

#font-size-value {
    font-size: 0.95rem;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
    color: var(--accent);
}

/* ===== Main Container ===== */
.main-container {
    display: flex;
    flex: 1;
    height: calc(100vh - 56px);
    overflow: hidden;
}

.editor-pane,
.output-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.editor-pane {
    border-right: 1px solid var(--border);
}

.pane-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.pane-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
}

/* ===== CodeMirror ===== */
.CodeMirror {
    height: 100% !important;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 16px;
    line-height: 1.6;
}

.CodeMirror-gutters {
    border-right: 1px solid var(--border) !important;
}

/* ===== Output ===== */
.output-pane {
    background: var(--bg-secondary);
}

#output {
    flex: 1;
    padding: 16px 20px;
    margin: 0;
    overflow-y: auto;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 15px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-primary);
    transition: color 0.3s;
}

#output.error {
    color: var(--error) !important;
    font-weight: 500;
}

.output-placeholder {
    color: var(--text-muted);
    font-style: italic;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--surface-hover);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
    }

    .editor-pane {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .branding {
        display: none;
    }

    .header {
        padding: 0 12px;
    }
}