body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#toggleControlsBtn {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(20, 20, 20, 0.85);
    color: white;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 1.2rem;
    width: auto;
    margin: 0;
    font-weight: bold;
    cursor: pointer;
    z-index: 5;
    transition: background 0.3s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    display: none; /* Hidden initially because panel is open */
}

#toggleControlsBtn:hover {
    background: #007acc;
}

#controls {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(20, 20, 20, 0.85);
    color: white;
    padding: 15px;
    border-radius: 8px;
    z-index: 10;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    max-width: 300px;
    max-height: 90vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #007acc rgba(0,0,0,0.3);
}

#controls.hidden {
    transform: translateX(-120%);
    opacity: 0;
    pointer-events: none;
}

/* Custom dark theme scrollbar for Webkit browsers (Chrome, Edge, Safari) */
#controls::-webkit-scrollbar {
    width: 8px;
}
#controls::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}
#controls::-webkit-scrollbar-thumb {
    background: #007acc;
    border-radius: 4px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.panel-header h2 {
    margin: 0;
    font-size: 1.3rem;
}

#hideControlsBtn {
    background: transparent;
    width: auto;
    margin: 0;
    padding: 5px 10px;
    font-size: 1.2rem;
}

#hideControlsBtn:hover {
    background: rgba(255, 255, 255, 0.1);
}

details {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 6px;
    padding: 10px;
    border: 1px solid #333;
    margin-bottom: 10px;
}

summary {
    font-weight: bold;
    cursor: pointer;
    outline: none;
}

details[open] summary {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

details p {
    font-size: 0.85rem;
    color: #ccc;
    margin: 10px 0;
}

.control-group {
    margin: 15px 0;
    display: flex;
    flex-direction: column;
}

.control-group label {
    margin-bottom: 5px;
    font-weight: bold;
    font-size: 0.9rem;
}

button {
    padding: 10px 15px;
    cursor: pointer;
    background: #007acc;
    color: white;
    border: none;
    border-radius: 4px;
    font-weight: bold;
    width: 100%;
    margin-bottom: 10px;
    transition: background 0.2s;
}

button:hover {
    background: #005999;
}

input[type="range"], select, input[type="color"], input[type="text"], input[type="file"] {
    width: 100%;
    padding: 5px;
    box-sizing: border-box;
}

/* Pop-Out Mode Styles */
#controls.popped-out {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 15px;
    align-items: start;
    max-height: none; /* Let the window handle scrolling, no more horizontal overflow */
    overflow: visible;
}

#controls.popped-out .panel-header,
#controls.popped-out #audioInputDetails {
    grid-column: 1 / -1; /* Stretch these across the entire top row */
    margin-bottom: 0;
}

#controls.popped-out details {
    margin-bottom: 0;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.85);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #1a1a1a;
    color: white;
    padding: 25px 35px;
    border-radius: 8px;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.8);
    position: relative;
    font-size: 0.95rem;
    line-height: 1.5;
}

.modal-content h2 {
    margin-top: 0;
    color: #007acc;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    top: 10px;
    right: 15px;
}

.close:hover {
    color: white;
}

/* Mobile Responsive Tweaks */
@media (max-width: 600px) {
    #controls {
        width: calc(100% - 20px);
        max-width: none;
        top: 10px;
        left: 10px;
        padding: 10px;
        max-height: calc(100vh - 20px);
    }
    #toggleControlsBtn {
        top: 10px;
        left: 10px;
    }
    #popOutButton {
        display: none; /* Popouts are restricted on mobile devices */
    }
}