:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f4f7f9;
    --text-primary: #222222;
    --text-secondary: #555555;
    --border-color: #dce3e8;
    --editor-bg: #ffffff;
    --editor-text: #1a1a1a;
    --header-bg: #ffffff;
    --button-bg: #007bff;
    --button-text: #ffffff;
    --link-color: #007bff;
    --icon-color: #555555;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --cm-theme-light: 'material-lighter';
    --header-height: 60px;
}

body.dark-mode {
    --bg-primary: #1a1a1a;
    --bg-secondary: #252525;
    --text-primary: #e0e0e0;
    --text-secondary: #aaaaaa;
    --border-color: #3a3a3a;
    --editor-bg: #202020;
    --editor-text: #e0e0e0;
    --header-bg: #1f1f1f;
    --button-bg: #0d6efd;
    --button-text: #ffffff;
    --link-color: #4dabf7;
    --icon-color: #aaaaaa;
    --shadow-color: rgba(255, 255, 255, 0.1);
    --cm-theme-dark: 'material-darker';
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
                 Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    height: var(--header-height);
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 4px var(--shadow-color);
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

header nav {
    display: flex;
    align-items: center;
    gap: 15px;
}

.theme-switch-wrapper {
    display: flex;
    align-items: center;
}
.theme-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}
.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    z-index: 1;
}
input:checked + .slider {
    background-color: var(--button-bg);
}
input:checked + .slider:before {
    transform: translateX(24px);
}
.slider .icon {
    color: var(--bg-primary);
    font-size: 12px;
    transition: opacity 0.4s ease;
    z-index: 0;
}
.slider .sun { opacity: 1; }
.slider .moon { opacity: 0; }
input:checked + .slider .sun { opacity: 0; }
input:checked + .slider .moon { opacity: 1; color: #f1c40f; }

/* --- Main Playground Layout --- */
.playground {
    display: flex;
    flex-direction: row;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
    position: relative;
}

/* --- Divider --- */
.divider {
    width: 12px; /* wider for easier grabbing */
    min-width: 6px;
    height: 100%;
    min-height: 100px;
    background: var(--border-color);
    cursor: ew-resize;
    z-index: 2;
    transition: background 0.2s;
    position: relative;
    /* Add hit area for easier grabbing */
    margin-left: -6px;
    margin-right: -6px;
}
.divider:hover,
.divider.dragging {
    background: #007bff;
}

/* --- Code Editors Section --- */
.code-editors {
    flex: 1 1 50%;
    min-width: 100px;
    max-width: 90vw;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    overflow: hidden;
    transition: border-color 0.3s ease;
}

.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-bottom: 1px solid var(--border-color);
    transition: border-color 0.3s ease;
    position: relative;
}
.editor-container:last-child {
    border-bottom: none;
}
.editor-container label {
    padding: 8px 12px;
    font-weight: 500;
    font-size: 0.9rem;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
    flex-shrink: 0;
}
.editor-container label i {
    color: var(--icon-color);
    font-size: 1rem;
    transition: color 0.3s ease;
}
.html-container label i { color: #e34c26; }
.css-container label i { color: #264de4; }
.js-container label i { color: #f0db4f; }
body.dark-mode .js-container label i { color: #f0db4f; }

textarea[id$="-code"] {
    display: none;
}
.CodeMirror {
    font-family: 'Fira Code', Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
    font-size: 0.95rem;
    line-height: 1.5;
    height: 100%;
    flex-grow: 1;
    position: absolute;
    top: 38px;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
}
.editor-container {
    position: relative;
    display: flex;
    flex-direction: column;
}

/* --- Preview Section --- */
.preview-container {
    flex: 1 1 50%;
    min-width: 100px;
    max-width: 90vw;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.preview-container h2 {
    padding: 8px 12px;
    font-weight: 500;
    font-size: 0.9rem;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
    flex-shrink: 0;
}
.preview-container h2 i {
    color: var(--icon-color);
    font-size: 1rem;
    transition: color 0.3s ease;
}
#preview-frame {
    flex-grow: 1;
    border: none;
    background-color: var(--bg-primary);
    width: 100%;
    height: 100%;
    transition: background-color 0.3s ease;
}
@media (max-width: 768px) {
    .playground {
        flex-direction: column;
        height: auto;
    }
    .code-editors {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        height: 50vh;
        display: flex;
        flex-direction: column;
    }
    .divider {
        width: 100%;
        height: 12px;
        min-width: 0;
        min-height: 6px;
        cursor: ns-resize;
        margin: -6px 0;
    }
    .editor-container {
        min-height: 80px;
        flex-basis: 33.33%;
    }
    .CodeMirror {
        top: 38px;
    }
    .preview-container {
        height: 50vh;
    }
    header h1 {
        font-size: 1.2rem;
    }
    header nav {
        gap: 10px;
    }
}
