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

html {
    overflow-y: scroll; /* Prevent layout shift when scrollbar appears */
}

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #f9f9f9;
    --bg-code: #fafafa;
    --text-primary: #333;
    --text-secondary: #666;
    --border-color: #ccc;
    --border-color-light: #d0d0d0;
    --border-color-dark: #999;
    --hover-bg: #f0f0f0;
    --active-bg: #e0e0e0;
    --success-bg: #d4edda;
    --success-color: #155724;
    --success-border: #28a745;
    --error-bg: #f8d7da;
    --error-color: #721c24;
    --error-border: #dc3545;
    --info-bg: #d1ecf1;
    --info-color: #004085;
    --info-border: #17a2b8;
    --example-border: #666;
    --divider-bg: #e0e0e0;
    --divider-hover: #bbb;
    --divider-active: #999;
    --difficulty-easy-bg: #d4edda;
    --difficulty-easy-color: #155724;
    --difficulty-medium-bg: #fff3cd;
    --difficulty-medium-color: #856404;
    --difficulty-hard-bg: #f8d7da;
    --difficulty-hard-color: #721c24;
    --status-complete-bg: #d4edda;
    --status-complete-color: #155724;
    --status-incomplete-bg: #f8f9fa;
    --status-incomplete-color: #6c757d;
    --status-incomplete-border: #ddd;
    --code-highlight-bg: #e6e6e6;
}

html.dark-theme {
    color-scheme: dark;
}

html.dark-theme body {
    --bg-primary: #1e1e1e;
    --bg-secondary: #252525;
    --bg-tertiary: #2d2d2d;
    --bg-code: #1e1e1e;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --border-color: #404040;
    --border-color-light: #404040;
    --border-color-dark: #555;
    --hover-bg: #333;
    --active-bg: #444;
    --success-bg: #1e3a1e;
    --success-color: #90ee90;
    --success-border: #28a745;
    --error-bg: #3a1e1e;
    --error-color: #ff6b6b;
    --error-border: #dc3545;
    --info-bg: #1e2a3a;
    --info-color: #6bb6ff;
    --info-border: #17a2b8;
    --example-border: #666;
    --divider-bg: #404040;
    --divider-hover: #555;
    --divider-active: #666;
    --difficulty-easy-bg: #1e3a1e;
    --difficulty-easy-color: #90ee90;
    --difficulty-medium-bg: #3a3a1e;
    --difficulty-medium-color: #ffeb99;
    --difficulty-hard-bg: #3a1e1e;
    --difficulty-hard-color: #ff9999;
    --status-complete-bg: #1e3a1e;
    --status-complete-color: #90ee90;
    --status-incomplete-bg: #2d2d2d;
    --status-incomplete-color: #b0b0b0;
    --status-incomplete-border: #404040;
    --code-highlight-bg: #393939;
}

body {
    font-family: Arial, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 {
    font-size: 1.5em;
    font-weight: normal;
    color: var(--text-primary);
}

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

.header-link,
.theme-toggle {
    color: var(--text-primary);
    font-size: 14px;
    padding: 5px 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    border-radius: 3px;
    cursor: pointer;
}

.header-link {
    text-decoration: none;
}

.header-link:hover,
.theme-toggle:hover {
    background: var(--hover-bg);
}

.split-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 51px); /* Account for header height */
    background: var(--bg-primary);
}

/* Left Panel - Problem Display */
.left-panel {
    width: 40%;
    min-width: 250px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    overflow: hidden;
    background: var(--bg-primary);
}

.problem-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    line-height: 1.6;
    color: var(--text-primary);
}

.problem-content h2 {
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.problem-content h3 {
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 1.1em;
    color: var(--text-primary);
}

.problem-content p {
    margin-bottom: 10px;
    color: var(--text-primary);
}

.problem-content pre {
    background: var(--bg-secondary);
    padding: 10px;
    border: 1px solid var(--border-color);
    overflow-x: auto;
    margin: 10px 0;
    color: var(--text-primary);
}

.problem-content code {
    background: var(--bg-secondary);
    padding: 2px 5px;
    font-family: monospace;
    color: var(--text-primary);
}

.problem-content ul {
    margin-left: 20px;
    margin-bottom: 10px;
}

.problem-content li {
    margin-bottom: 5px;
}

.difficulty {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 0.85em;
    font-weight: bold;
    margin-left: 10px;
}

.difficulty.easy {
    background: var(--difficulty-easy-bg);
    color: var(--difficulty-easy-color);
}

.difficulty.medium {
    background: var(--difficulty-medium-bg);
    color: var(--difficulty-medium-color);
}

.difficulty.hard {
    background: var(--difficulty-hard-bg);
    color: var(--difficulty-hard-color);
}

.example-box {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--example-border);
    padding: 10px;
    margin: 10px 0;
    color: var(--text-primary);
}

/* Draggable Divider */
.divider {
    width: 5px;
    background: var(--divider-bg);
    cursor: col-resize;
    flex-shrink: 0;
}

.divider:hover {
    background: var(--divider-hover);
}

.divider.dragging {
    background: var(--divider-active);
}

/* Right Panel - Editor and Console */
.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 300px;
}

.controls {
    padding: 10px 15px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn {
    padding: 8px 16px;
    font-size: 14px;
    border: 1px solid var(--border-color-dark);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 3px;
}

.btn:hover {
    background: var(--hover-bg);
}

.btn:active {
    background: var(--active-bg);
}

.btn-run {
    font-weight: bold;
}

#status-message {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 13px;
}

.editor-container {
    flex: 1;
    overflow: hidden;
    border-bottom: 1px solid var(--border-color-light);
}

.CodeMirror {
    height: 100%;
    font-size: 14px;
    border: 1px solid var(--border-color-light) !important;
}

html.dark-theme .CodeMirror {
    background: var(--bg-code) !important;
    color: var(--text-primary) !important;
}

html.dark-theme .CodeMirror-gutters {
    background: var(--bg-secondary) !important;
    border-right: 1px solid var(--border-color) !important;
}

html.dark-theme .CodeMirror-linenumber {
    color: var(--text-secondary) !important;
}

html.dark-theme .CodeMirror-cursor {
    border-left: 1px solid var(--text-primary) !important;
}

html.dark-theme .CodeMirror-selected {
    background: rgba(255, 255, 255, 0.1) !important;
}

html.dark-theme .CodeMirror-line::selection,
html.dark-theme .CodeMirror-line > span::selection,
html.dark-theme .CodeMirror-line > span > span::selection {
    background: rgba(255, 255, 255, 0.2) !important;
}

html.dark-theme .cm-keyword { color: #569cd6 !important; }
html.dark-theme .cm-atom { color: #ce9178 !important; }
html.dark-theme .cm-number { color: #b5cea8 !important; }
html.dark-theme .cm-def { color: #dcdcaa !important; }
html.dark-theme .cm-variable { color: #9cdcfe !important; }
html.dark-theme .cm-variable-2 { color: #9cdcfe !important; }
html.dark-theme .cm-variable-3 { color: #4fc1ff !important; }
html.dark-theme .cm-property { color: #9cdcfe !important; }
html.dark-theme .cm-operator { color: #d4d4d4 !important; }
html.dark-theme .cm-comment { color: #6a9955 !important; }
html.dark-theme .cm-string { color: #ce9178 !important; }
html.dark-theme .cm-string-2 { color: #ce9178 !important; }
html.dark-theme .cm-meta { color: #d7ba7d !important; }
html.dark-theme .cm-qualifier { color: #4ec9b0 !important; }
html.dark-theme .cm-builtin { color: #4ec9b0 !important; }
html.dark-theme .cm-bracket { color: #da70d6 !important; }
html.dark-theme .cm-tag { color: #569cd6 !important; }
html.dark-theme .cm-attribute { color: #9cdcfe !important; }
html.dark-theme .cm-error { color: #f44747 !important; background: rgba(244, 71, 71, 0.15) !important; }
html.dark-theme .CodeMirror-matchingbracket { color: #00ff00 !important; background: rgba(0, 255, 0, 0.15) !important; }

/* Dark mode scrollbars for CodeMirror and code blocks */
html.dark-theme .CodeMirror-scroll::-webkit-scrollbar,
html.dark-theme .CodeMirror-hscrollbar::-webkit-scrollbar,
html.dark-theme .CodeMirror-vscrollbar::-webkit-scrollbar,
html.dark-theme pre::-webkit-scrollbar,
html.dark-theme .output-console::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

html.dark-theme .CodeMirror-scroll::-webkit-scrollbar-track,
html.dark-theme .CodeMirror-hscrollbar::-webkit-scrollbar-track,
html.dark-theme .CodeMirror-vscrollbar::-webkit-scrollbar-track,
html.dark-theme pre::-webkit-scrollbar-track,
html.dark-theme .output-console::-webkit-scrollbar-track {
    background: #1e1e1e;
}

html.dark-theme .CodeMirror-scroll::-webkit-scrollbar-thumb,
html.dark-theme .CodeMirror-hscrollbar::-webkit-scrollbar-thumb,
html.dark-theme .CodeMirror-vscrollbar::-webkit-scrollbar-thumb,
html.dark-theme pre::-webkit-scrollbar-thumb,
html.dark-theme .output-console::-webkit-scrollbar-thumb {
    background: #4a4a4a;
    border-radius: 4px;
    border: 2px solid #1e1e1e;
}

html.dark-theme .CodeMirror-scroll::-webkit-scrollbar-thumb:hover,
html.dark-theme .CodeMirror-hscrollbar::-webkit-scrollbar-thumb:hover,
html.dark-theme .CodeMirror-vscrollbar::-webkit-scrollbar-thumb:hover,
html.dark-theme pre::-webkit-scrollbar-thumb:hover,
html.dark-theme .output-console::-webkit-scrollbar-thumb:hover {
    background: #5a5a5a;
}

html.dark-theme .CodeMirror-hscrollbar,
html.dark-theme .CodeMirror-vscrollbar {
    background: #1e1e1e;
}

html.dark-theme .CodeMirror-scrollbar-filler {
    background: #1e1e1e;
}

.output-container {
    height: 200px;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.output-header {
    padding: 8px 15px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    font-weight: bold;
    font-size: 13px;
    color: var(--text-primary);
}

.output-console {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    font-family: monospace;
    font-size: 13px;
    background: var(--bg-code);
    color: var(--text-primary);
}

.output-info {
    color: var(--text-secondary);
}

.output-success {
    color: var(--success-color);
    background: var(--success-bg);
    padding: 5px 10px;
    margin: 3px 0;
    border-left: 3px solid var(--success-border);
}

.output-error {
    color: var(--error-color);
    background: var(--error-bg);
    padding: 5px 10px;
    margin: 3px 0;
    border-left: 3px solid var(--error-border);
}

.output-result {
    color: var(--info-color);
    background: var(--info-bg);
    padding: 5px 10px;
    margin: 3px 0;
    border-left: 3px solid var(--info-border);
}

.mobile-tabs {
    display: none;
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--border-color);
}

.mobile-tab {
    flex: 1;
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 500;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
}

.mobile-tab:active {
    background: var(--hover-bg);
}

.mobile-tab.active {
    color: var(--text-primary);
    background: var(--bg-primary);
    border-bottom-color: var(--text-primary);
    font-weight: bold;
}

@media screen and (max-width: 768px) {
    .mobile-tabs {
        display: flex;
    }
    
    .header {
        padding: 8px 15px;
    }
    
    .header h1 {
        font-size: 1.2em;
    }
    
    .header-link,
    .theme-toggle {
        font-size: 12px;
        padding: 4px 8px;
    }

    .problem-status {
        display: none;
    }
    
    .split-container {
        position: relative;
        height: calc(100vh - 51px - 48px); /* Account for header and tabs */
    }
    
    .divider {
        display: none;
    }
    
    /* Panels stack and only one shows at a time */
    .left-panel,
    .right-panel {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        min-width: 0;
        display: none;
        border: none;
    }
    
    .panel-content.active {
        display: flex;
    }
    
    .controls {
        padding: 8px 10px;
        gap: 8px;
        flex-wrap: wrap;
    }
    
    .btn {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    #status-message {
        font-size: 12px;
        width: 100%;
    }
    
    .problem-content {
        padding: 15px;
        font-size: 14px;
    }
    
    .problem-content h2 {
        font-size: 1.3em;
    }
    
    .problem-content h3 {
        font-size: 1.1em;
    }
    
    .problem-content pre {
        font-size: 12px;
        padding: 8px;
    }
    
    .CodeMirror {
        font-size: 13px;
    }
    
    .output-container {
        height: 150px;
    }
    
    .output-console {
        font-size: 12px;
        padding: 8px;
    }
}

@media screen and (max-width: 480px) {
    .header h1 {
        font-size: 1em;
    }
    
    .problem-content {
        padding: 10px;
        font-size: 13px;
    }
    
    .controls {
        padding: 6px 8px;
    }
    
    .btn {
        padding: 5px 10px;
        font-size: 12px;
    }
    
    .CodeMirror {
        font-size: 12px;
    }
    
    .output-container {
        height: 120px;
    }
}