/* assets/css/playground.css */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #111;
    color: #fff;
    font-family: "Inter", sans-serif;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    background: #1e1e1e;
    padding: 6px 12px;
    /* font-weight: bold; */
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
    flex-wrap: wrap; 
    line-height: 1.2;
     border: none;
     border-radius: 6px;
     transition: 0.2s;
    text-decoration: none;
    font-size: 14px;
    flex-wrap: wrap;
    
}



/* --- Container Layout --- */

.editor-container {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    overflow: auto;
}

.code-area {
    flex: 1 1 50%;
    min-width: 320px;
    background: #1a1a1a;
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 8px;
    overflow-y: auto;
}

.preview-area {
    flex: 1 1 50%;
    min-width: 320px;
    background: #fff;
    color: #000;
    border-left: 2px solid #333;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

iframe {
    flex: 1;
    width: 100%;
    border: none;
}

/* Base styles for the CodeMirror editors and sections */
.section {
    background: #111;
    border: 1px solid #333;
    border-radius: 8px;
    overflow: hidden;
    flex: 1; /* Default: Share space equally on desktop */
    display: flex;
    flex-direction: column;
}

.section label {
    padding: 8px;
    background: #222;
    font-size: 14px;
    border-bottom: 1px solid #333;
}

/* --- Buttons and UI Elements --- */

.buttons {
    display: flex;
    gap: 10px;
    padding: 10px;
    background: #1e1e1e;
    justify-content: center;
    flex-wrap: wrap;
    position: sticky;
    top: 50px;
    z-index: 9;
}

.buttons button, .header-link {
    padding: 8px 14px;
    background: #0a84ff;
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    transition: 0.2s;
    text-decoration: none;
    line-height: 1.2;
    font-size: 14px;
}

.buttons button:hover, .header-link:hover {
    background: #0066cc;
}

.primary-btn {
    background: #28a745 !important;
}
.primary-btn:hover {
    background: #1e7e34 !important;
}

.error-log {
    background: #ff4c4c;
    color: #fff;
    padding: 6px 10px;
    font-size: 13px;
    display: none;
    text-align: center;
    position: sticky;
    top: 100px;
    z-index: 8;
}

.theme-toggle {
    background: transparent !important;
    border: 1px solid #444 !important;
    color: white !important;
    padding: 6px 12px !important;
    border-radius: 6px !important;
    cursor: pointer;
    transition: 0.2s;
}

.theme-toggle:hover {
    background: #333 !important;
}


/* ========================================================= */
/* 🔑 MOBILE OPTIMIZATION (Max-width 768px) */
/* ========================================================= */
@media (max-width: 768px) {
    
    /* 1. Stack Editor and Preview Vertically */
    .editor-container {
        flex-direction: grid;
    }
    
    /* 2. SWAP ORDER: Preview is now at the top of the entire stack */
    .preview-area {
        order: -1; /* Forces preview to the top */
        flex: 1 1 100%;
        min-width: unset;
        height: 50vh; /* Ensure the preview has good screen space */
        border-left: none; /* Remove side border on mobile */
    }

    /* Code area moves below the preview */
    .code-area {
        order: 1; 
        flex: 1 1 100%;
        min-width: unset;
        /* No min-height here, as the content sections will define the height */
        min-height: unset; 
    }
    
    /* 3. DEFINE SECTION HEIGHTS & REMOVE FLEX SHARE */
    /* This ensures all three editor sections stack vertically and are visible upon scrolling */
    .section {
        flex: unset; /* Stops sections from sharing space equally */
        height: 30vh; /* Give each editor section a fixed, usable height */
    }
    
    /* 4. COMPACT HEADER ELEMENTS */
    header {
        padding: 10px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    header > div:first-child {
        width: 100%;
        justify-content: space-between;
        gap: 5px;
    }

    header .header-link {
        font-size: 12px;
        padding: 4px 8px;
    }
    
    header span:last-child {
        display: none;
    }
    
    /* 5. TIGHTER BUTTONS */
    .buttons {
        top: unset;
        position: static;
        justify-content: space-around;
        gap: 5px;
        padding: 8px;
    }
    
    .buttons button {
        flex-grow: 1; 
        padding: 6px 8px;
        font-size: 12px;
    }

    /* 6. CodeMirror Height fix */
    .CodeMirror {
        height: 100% !important; 
    }

    .section label {
        padding: 5px 8px;
        font-size: 12px;
    }
}