html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden; /* Hide scrollbars if content overflows */
    background-color: #1a1a1a; /* Dark background */
    display: flex;
    flex-direction: column;
    justify-content: center; /* Center content vertically */
    align-items: center; /* Center content horizontally */
    font-family: sans-serif;
    color: #eee;
}

.controls {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
    transition: opacity 0.3s ease-in-out; /* Add transition for smooth hide/show */
}

.controls.hidden-controls {
    opacity: 0;
    pointer-events: none; /* Make it non-interactive when hidden */
}

#startButton {
    padding: 15px 30px;
    font-size: 1.2em;
    cursor: pointer;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: background-color 0.3s ease;
}

#startButton:hover {
    background-color: #0056b3;
}

#startButton:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1em;
    cursor: pointer;
}

#showTilesCheckbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: #007bff;
}

.slider-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1em;
    color: #eee;
}

/* Updated style for the number input */
#fpsInput {
    width: 60px; /* Adjust width as needed */
    padding: 5px;
    font-size: 1em;
    border-radius: 5px;
    border: 1px solid #007bff;
    background-color: #333;
    color: #eee;
    text-align: center;
    -moz-appearance: textfield; /* Hide Firefox spinner buttons */
}

/* Hide Chrome/Safari/Edge spinner buttons */
#fpsInput::-webkit-outer-spin-button,
#fpsInput::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* The screenVideo is now always hidden, only used for stream capture */
#screenVideo {
    display: none; 
}

#screenCanvas {
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: calc(100vh - 80px); /* Adjust based on controls height + margin */
    display: none; /* Hidden by default until sharing starts */
    object-fit: contain; /* Conceptually, but managed by canvas drawing */
    background-color: black; /* Black background for letterboxing */
    border-radius: 8px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    cursor: grab; /* Indicate it's interactive */
}

#screenCanvas.active-share {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    box-shadow: none;
    z-index: 5;
}

/* When the canvas is active, position the controls in the corner */
body:has(#screenCanvas.active-share) .controls {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 10; /* Ensure controls are above canvas */
    margin: 0; /* Remove margin when active */
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent background for readability */
    padding: 10px 15px;
    border-radius: 8px;
}

#tileColorPopup {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.8);
    border: 1px solid #007bff;
    border-radius: 5px;
    padding: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    z-index: 20;
    pointer-events: none; /* Allow mouse events to pass through to canvas */
    transition: opacity 0.1s ease-in-out;
    min-width: 100px; /* Ensure a minimum size */
}

#tileColorPopup.hidden {
    opacity: 0;
    visibility: hidden;
}

.color-box {
    width: 20px;
    height: 20px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}