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

#canvas1 {
    border: 1px solid black;
    position: absolute;
    top: 0;
    left: 0;
    /* width: 100%; */
    height: 100%;
    background-color: #ccf;
    max-width: 100vw;
    max-height: 100vh;
}

#layer1, #layer2, #layer3, #layer4, #player {
    display: none;
}

/* ── Game layout: wide screens → side-by-side ── */
#gameContainer {
    display: none;            /* shown via JS */
    width: 100vw;
    height: 100vh;
    flex-direction: row;
    overflow: hidden;
}

#canvasContainer {
    position: relative;
    flex-shrink: 0;
    width: 100vh;
    height: 100vh;
}

#codingPanel {
    flex: 1 1 0;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ── Narrow screens: canvas on top, coding area below ── */
@media (max-width: 768px) {
    #gameContainer {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }

    #canvasContainer {
        position: relative;
        width: 100% !important;
        height: 50vh !important;
        flex-shrink: 0;
        overflow: hidden;
    }

    #canvas1 {
        position: relative;
        width: 100%;
        height: 100%;
    }

    #background {
        display: none;
    }

    #codingPanel {
        flex: 1 1 0;
        min-height: 0;
        overflow: hidden;
    }

    #editorContainer {
        flex: 1 1 0 !important;
        min-height: 0;
        overflow: hidden;
    }

    #editor {
        /* flex: 3 1 0 !important;
        height: auto !important; */
        min-height: 25vh;
        max-height: 25vh;
        width: calc ( 100% - 10px ) !important;
        overflow: scroll;
    }

    .CodeMirror {
        height: 100% !important;
        width: 100%;
    }

    #output {
        flex: 1 1 0;
        min-height: 0;
        max-height: none !important;
        overflow-y: scroll;
    }
}

/* Modal Styles */
.modal {
    display: none; /* Hidden by default */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex; /* Show when active */
}

.modal-content {
    background-color: #fff;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    text-align: center;
    min-width: 300px;
    max-width: 500px;
}

.level-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 20px;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 10px;
}

.level-item {
    padding: 8px 12px;
    background-color: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 15px;
}

.level-item:hover {
    background-color: #e8f4fd;
    border-color: #2196F3;
}

.level-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.level-title {
    font-size: 15px;
    font-weight: bold;
    color: #2196F3;
    white-space: nowrap;
}

.level-objective {
    font-size: 13px;
    color: #666;
    line-height: 1.3;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.level-btn {
    padding: 10px 16px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    margin-top: 10px;
    transition: background-color 0.3s;
}

.level-btn:hover {
    background-color: #45a049;
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

.modal-btn {
    padding: 10px 20px;
    background-color: #2196F3;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s;
}

.modal-btn:hover {
    background-color: #0b7dda;
}

.score-container {
    margin: 20px 0;
    font-size: 24px;
}

.score-section {
    margin: 10px 0;
    opacity: 0;
    transition: opacity 0.4s ease-in;
}
.score-section.visible {
    opacity: 1;
}

.score-label {
    font-size: 18px;
    color: #666;
    margin-bottom: 2px;
}

.score {
    font-size: 48px;
    font-weight: bold;
    color: #4CAF50;
    margin: 0;
}

.bonus-score-color {
    color: #FF9800;
}

.final-result {
    font-size: 36px;
    font-weight: bold;
    margin: 15px 0;
}

#endGameButtons {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}
#endGameButtons.visible {
    opacity: 1 !important;
}

.button-container {
    display: flex;
    gap: 4px;
    align-items: center;
}

.editor-stats {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
    padding: 8px 0;
}

.instructions-content {
    max-width: 600px;
    text-align: left;
}

.instructions-section {
    margin: 20px 0;
}

.instructions-section h3 {
    color: #2196F3;
    margin-bottom: 10px;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 5px;
}

.instructions-section ul {
    padding-left: 20px;
}

.instructions-section li {
    margin: 8px 0;
    line-height: 1.4;
}

#closeInstructionsButton {
    display: block;
    margin: 20px auto 0;
    padding: 12px 24px;
    background-color: #4CAF50;
    font-size: 16px;
}

.output-container {
    max-height: 50vh;
    overflow-y: auto;
}
