html, body {
    height: 100%; /* Ensure body covers full height for canvas */
    margin: 0;
    overflow-x: hidden; /* Prevent horizontal scrollbar from canvas */
}

body {
    background-color: transparent; /* Make body transparent to see canvas */
    color: #e0e0e0;
    font-family: sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    position: relative; /* Needed for z-index stacking */
    z-index: 1; /* Ensure body content is above canvas */
}

#backgroundCanvas {
    position: fixed; /* Fixed position to cover viewport */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0; /* Place canvas behind everything else */
    background-color: #1a1a1a; /* Fallback background */
}

h1, h2, h3 {
    color: #00bfff; /* Deep sky blue */
    text-align: center;
    position: relative; /* Ensure text is above canvas */
    z-index: 2;
}

hdr1 {        
    color: #d19900; /* Deep sky blue */
    text-align: center;
    position: relative; /* Ensure text is above canvas */
    z-index: 2;
    font-size: 1.2em; /* Larger font size */
    margin-bottom: 20px; /* Space below header */
}

#setup {
    background-color: rgba(43, 43, 43, 0.9); /* Slightly transparent */
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    margin-bottom: 20px;
    width: 90%;
    max-width: 800px; /* Increased max-width */
    display: flex; /* Use flexbox for side-by-side layout */
    gap: 30px; /* Space between controls and preview */
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    position: relative; /* Ensure setup is above canvas */
    z-index: 2;
}

#controls {
    flex: 1; /* Allow controls to take available space */
    min-width: 280px; /* Minimum width before wrapping */
}

#previewArea {
    flex: 1; /* Allow preview to take available space */
    min-width: 250px; /* Minimum width before wrapping */
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: rgba(51, 51, 51, 0.85); /* Slightly transparent */
    padding: 15px;
    border-radius: 8px;
}

#previewVideo {
    width: 100%;
    max-width: 300px;
    height: auto;
    border: 1px solid #555;
    background-color: #000;
    border-radius: 4px;
    margin-bottom: 15px;
    transform: scaleX(-1); /* Mirror preview video */
}

#micMeter {
    width: 80%;
    height: 20px;
    background-color: #555;
    border: 1px solid #777;
    border-radius: 3px;
    overflow: hidden; /* Hide overflow of the inner bar */
    margin-top: 5px; /* Space above the meter */
}

#micLevel {
    width: 0%; /* Start with no level shown */
    height: 100%;
    background-color: #00bfff; /* Use theme color for the level */
    transition: width 0.1s linear; /* Smooth transition for level changes */
}

#previewArea label {
    margin-top: 10px; /* Space above the mic label */
    font-size: 0.9em;
    color: #bbb;
}

#previewError {
    margin-top: 10px;
    font-size: 0.9em;
}

#chatRoom {
    background-color: rgba(43, 43, 43, 0.85); /* More transparent to see background */
    padding: 20px; /* Reduced padding slightly */
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.6);
    margin-bottom: 20px;
    width: 95%; /* Wider */
    max-width: 1000px; /* Allow more width for side-by-side */
    margin-top: 20px;
    position: relative; /* Ensure chat room is above canvas */
    z-index: 2;
    display: flex; /* Use flex for centering content */
    flex-direction: column;
    align-items: center;
}

#chatRoom h2 {
    margin-bottom: 15px;
}

.input-group {
    margin-bottom: 15px;
}

label {
    display: block;
    margin-bottom: 5px;
    color: #cccccc;
}

input[type="text"], select {
    width: calc(100% - 22px);
    padding: 10px;
    border: 1px solid #555;
    background-color: #333;
    color: #e0e0e0;
    border-radius: 4px;
    font-size: 1em;
}

input[type="text"]:focus, select:focus {
    outline: none;
    border-color: #00bfff;
}

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

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

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

#hangupButton {
    background-color: #dc3545;
    width: auto; /* Don't force full width */
    padding: 10px 30px;
    margin-top: 20px;
}

#hangupButton:hover {
    background-color: #a71d2a;
}

.hidden {
    display: none !important; /* Use important to override potential conflicts */
}

.videos {
    display: flex;
    justify-content: center; /* Center video containers */
    align-items: flex-start; /* Align tops */
    flex-wrap: wrap;
    gap: 30px; /* Space between video containers */
    width: 100%; /* Take full width of chatRoom */
    margin-top: 15px;
}

.video-container {
    background-color: rgba(51, 51, 51, 0.8); /* Semi-transparent */
    padding: 10px; /* Reduced padding */
    border-radius: 8px;
    text-align: center;
    flex: 1 1 45%; /* Allow growing/shrinking, base size 45% */
    max-width: 48%; /* Ensure they stay side-by-side with gap */
    min-width: 300px; /* Minimum width before wrapping */
    display: flex;
    flex-direction: column;
    align-items: center;
}

.video-container h3 { /* Style for placeholder name */
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.1em;
    color: #ccc;
}

video {
    width: 100%; /* Fill container width */
    height: auto;
    border: 1px solid #555;
    background-color: #000;
    border-radius: 4px;
    display: block; /* Remove extra space below video */
}

#localVideo {
    transform: scaleX(-1); /* Mirror local video */
}

.video-container .controls {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    justify-content: center;
    width: 100%;
}

.video-container .controls button {
    width: auto; /* Adjust width automatically */
    padding: 8px 15px; /* Smaller padding */
    font-size: 0.9em;
    margin-top: 0; /* Remove top margin */
    background-color: #007bff;
}

.video-container .controls button.off {
    background-color: #6c757d; /* Grey when off */
}

.video-container .controls button.off:hover {
    background-color: #5a6268;
}

.name-tag {
    background: linear-gradient(45deg, #00bfff, #1e90ff);
    color: #fff;
    padding: 5px 15px;
    border-radius: 15px;
    margin-top: 10px;
    font-weight: bold;
    font-size: 1.0em;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
    display: inline-block; /* Fit content */
    opacity: 0; /* Start hidden */
    transform: translateY(10px); /* Start slightly lower */
    transition: opacity 0.5s ease-out, transform 0.5s ease-out; /* Fade/slide effect */
}

.name-tag.visible {
    opacity: 1;
    transform: translateY(0);
}

#status, #remoteUserStatus {
    text-align: center;
    margin-top: 10px; /* Adjusted margin */
    margin-bottom: 10px;
    font-style: italic;
    color: #aaa;
    width: 100%; /* Ensure it takes space */
}

#remoteUserStatus {
    /* Styles already set, just ensure it shows correctly */
}

.error {
    color: #ff4d4d;
    text-align: center;
    margin-top: 10px;
}

/* Responsive adjustments */
@media (max-width: 700px) { /* Adjust breakpoint */
    #setup {
        flex-direction: column; /* Stack controls and preview vertically */
    }
    #controls, #previewArea {
        min-width: 100%; /* Take full width when stacked */
    }
    #previewArea {
         margin-top: 20px; /* Add space when stacked */
    }
    .videos {
        flex-direction: column; /* Stack videos vertically */
        align-items: center; /* Center stacked videos */
        gap: 20px;
    }
    .video-container {
        flex-basis: 80%; /* Take more width when stacked */
        max-width: 90%;
        min-width: 280px;
    }
}