body {
    font-family: sans-serif;
    line-height: 1.6;
    padding: 20px;
    background-color: #f4f4f4;
}

h1, h3 {
    text-align: center;
    color: #333;
}

.container {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.controls {
    flex: 1;
    min-width: 250px;
}

.previews {
    flex: 2;
    display: flex;
    gap: 15px;
    flex-wrap: wrap; /* Allow previews to wrap on smaller screens */
}

.preview-box {
    border: 1px solid #ccc;
    padding: 10px;
    background-color: #eee;
    text-align: center;
    flex: 1; /* Distribute space equally */
    min-width: 200px; /* Ensure minimum width */
}

#imagePreview, #binaryCanvas {
    max-width: 100%; /* Make images responsive */
    max-height: 300px;
    display: block; /* Remove extra space below image */
    margin: 10px auto; /* Center image */
    border: 1px solid #ddd;
}

#processCanvas {
    display: none; /* Hide the canvas used only for processing */
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

input[type="file"],
input[type="range"] {
    margin-bottom: 15px;
    width: calc(100% - 10px); /* Adjust width */
}

button {
    display: block;
    width: 100%;
    padding: 10px 15px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    margin-top: 10px;
    transition: background-color 0.3s ease;
}

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

button:hover:not(:disabled) {
    background-color: #0056b3;
}

#result {
    margin-top: 20px;
    padding: 10px;
    background-color: #e9ecef;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-weight: bold;
    min-height: 40px; /* Ensure space for messages */
    word-wrap: break-word; /* Prevent long messages from overflowing */
}
#calculationInfo {
    margin-top: 10px;
    font-size: 0.9em;
    color: #555;
}

.threshold-control p {
    margin-top: -10px; /* Adjust spacing */
    margin-bottom: 15px;
    font-size: 0.85em;
    color: #666;
}

/* Optional Plot Styling */
.plot-container {
    width: 100%; /* Take full width below previews */
    max-width: 500px; /* Limit plot size */
    height: 400px;
    margin: 20px auto; /* Center the plot */
    padding: 15px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 5px;
}

#plotCanvas {
    width: 100%;
    height: 100%;
}