body {
    font-family: sans-serif;
    margin: 0; /* Remove default margin */
    padding: 20px;
    background-color: #f4f4f4;
    color: #333;
    display: flex;
    flex-direction: column;
    align-items: center; /* Center content horizontally */
}

h1 {
    text-align: center;
    color: #2c3e50;
    width: 100%; /* Ensure h1 takes full width */
}

.main-container {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    justify-content: center;
    gap: 20px; /* Space between visualization and code area */
    width: 95%;
    max-width: 1400px; /* Adjust max width as needed */
}

.visualization-area {
    flex: 1 1 600px; /* Allow shrinking but prefer 600px width */
    min-width: 400px; /* Minimum width before wrapping */
    display: flex;
    flex-direction: column;
}

.code-explanation-area {
    flex: 1 1 400px; /* Allow shrinking but prefer 400px width */
    min-width: 350px;
    background-color: #fff;
    padding: 15px;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}


#controls {
    text-align: center;
    margin-bottom: 15px;
}

#controls button {
    padding: 8px 15px;
    margin: 5px; /* Adjust margin for smaller screens */
    cursor: pointer;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    transition: background-color 0.3s ease;
}

#controls button:disabled {
    background-color: #bdc3c7;
    cursor: not-allowed;
}

#controls button:hover:not(:disabled) {
    background-color: #2980b9;
}

#controls label {
    margin-left: 10px;
}

#speedRange {
    vertical-align: middle;
    cursor: pointer;
    max-width: 100px; /* Adjust slider width */
}

#status {
    background-color: #ecf0f1;
    padding: 10px 15px;
    border-radius: 5px;
    margin-bottom: 15px;
    border: 1px solid #bdc3c7;
    font-size: 0.9em;
}

#status p {
    margin: 4px 0;
}

#status span {
    font-weight: bold;
}

#canvas-container {
    width: 100%; /* Make canvas container responsive */
    height: 350px; /* Adjust height as needed */
    background-color: #ffffff;
    border: 1px solid #ccc;
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 15px; /* Add margin below canvas */

}

#explanation {
    margin-top: 15px;
    padding: 15px;
    background-color: #e8f6fd;
    border: 1px solid #bde0fe;
    border-radius: 5px;
    font-size: 0.9em; /* Slightly smaller font */
}

#explanation h2 {
     margin-top: 0;
    color: #1f6491;
    font-size: 1.2em;
    text-align: left;
}
#explanation p {
    margin-bottom: 10px;
}


.color-box {
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-right: 4px;
    vertical-align: middle;
    border: 1px solid #777;
}
.default { background-color: #3498db; } /* blue */
.comparing { background-color: #f39c12; } /* darker orange */
.swapping { background-color: #e74c3c; } /* red */
.sorted { background-color: #2ecc71; } /* green */

/* Code View Styles */
.code-explanation-area h2,
.code-explanation-area h3 {
     color: #2c3e50;
     text-align: center;
     margin-bottom: 10px;
}
.code-explanation-area h3 {
    margin-top: 20px; /* Space above explanation */
    border-top: 1px solid #eee;
    padding-top: 15px;
}


#code-view {
    background-color: #2d2d2d; /* Dark background for code */
    color: #cccccc; /* Light text color */
    padding: 15px;
    border-radius: 4px;
    overflow-x: auto; /* Add scroll if code is too wide */
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    line-height: 1.5;
}

#python-code span {
    display: block; /* Each line on its own line */
    transition: background-color 0.3s ease; /* Smooth highlight transition */
    padding: 2px 5px; /* Add some padding */
    border-radius: 3px;
}

/* Highlight style for the current line */
.highlighted-line {
    background-color: #4a4a4a; /* Darker highlight */
    color: #fff; /* White text for highlighted line */
    font-weight: bold;
}

#explanation-view {
    margin-top: 15px;
}

#code-explanation {
    background-color: #f0f0f0;
    border: 1px solid #ddd;
    padding: 10px;
    border-radius: 4px;
    min-height: 40px; /* Ensure some space */
    font-style: italic;
    color: #555;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
        align-items: center;
    }
    .visualization-area, .code-explanation-area {
        width: 95%; /* Take more width on smaller screens */
        flex: none; /* Disable flex sizing */
    }
    #canvas-container {
        height: 300px; /* Adjust canvas height */
    }
}