* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
    background: linear-gradient(135deg, #8596b1 0%, #232b3a 100%);
    background-attachment: fixed;
    background-repeat: no-repeat;
    color: #fff;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    position: relative;
}

body {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

#video-room {
    height: calc(100vh - 80px);
    width: 100vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0;
    padding-bottom: 70px;
    padding-top: 80px;
    box-sizing: border-box;
    position: absolute;
    top: 0;
    left: 0;
}

#videos-container {
    width: 100%;
    height: 100%;
    display: grid;
    gap: 8px;
    justify-content: center;
    align-items: center;
    padding: 5px;
    box-sizing: border-box;
    flex: 1;
    place-items: center;
}

.grid-cols-1 { grid-template-columns: 1fr; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid-cols-5 { grid-template-columns: repeat(5, 1fr); }
.grid-rows-1 { grid-template-rows: 1fr; }
.grid-rows-2 { grid-template-rows: repeat(2, 1fr); }
.grid-rows-3 { grid-template-rows: repeat(3, 1fr); }
.grid-rows-4 { grid-template-rows: repeat(4, 1fr); }
.grid-rows-5 { grid-template-rows: repeat(5, 1fr); }

/* Responsive grid layout depending on number of videos */
#videos-container.one {
    grid-template-columns: 1fr;
}
#videos-container.two {
    grid-template-columns: repeat(2, 1fr);
}
#videos-container.three {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: 1fr 1fr;
}
#videos-container.four {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
}
#videos-container.five, #videos-container.six {
    grid-template-columns: repeat(3, 1fr);
}
#videos-container.seven, #videos-container.eight, #videos-container.nine {
    grid-template-columns: repeat(3, 1fr);
}

/* Mobile-first responsive */
@media (max-width: 480px) {
    #video-room {
        padding: 0;
        padding-bottom: 60px;
        padding-top: 80px;
    }
    #videos-container {
        gap: 4px;
        padding: 3px;
    }
}

@media (max-width: 768px) {
    #videos-container {
        gap: 6px;
        padding: 4px;
    }
}

.video-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #232b3a;
    border-radius: 8px;
    box-shadow: 0 2px 8px 0 rgba(0,0,0,0.3);
    transition: border 0.18s;
    overflow: visible;
}
.cam-off-img {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 80%;
    height: 80%;
    object-fit: contain;
    margin: auto;
    background: #232b3a;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    border-radius: 12px;
    pointer-events: none;
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
    background: #232b3a;
    transition: border 0.18s;
}
.video-username {
    position: absolute;
    bottom: -10px;
    left: 12px;
    padding: 3px 10px;
    background: rgba(0, 0, 0, 0.88);
    color: #fff;
    font-size: 12px;
    border-radius: 5px;
    pointer-events: none;
    letter-spacing: 0.02em;
    max-width: 70%;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 0.3em;
}
.video-username span:first-child {
    margin-right: 0.7em;
}
.video-overlay {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 3;
    font-size: 1.6rem;
    color: #fff;
    text-shadow: 0 2px 6px rgba(0,0,0,0.35);
    display: flex;
    gap: 4px;
    align-items: center;
}
.overlay-mic, .overlay-cam {
    display: none;
}
.overlay-mic.show, .overlay-cam.show {
    display: block;
}


video.speaking {
    border: 5px solid #e53935;
    box-shadow: 0 0 0 4px rgba(229,57,53,0.12);
}

#login-form {
    background: rgba(35, 43, 58, 0.95);
    display: flex;
    flex-flow: wrap;
    position: fixed;
    justify-content: space-around;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding: 10px;
    box-sizing: border-box;
    backdrop-filter: blur(10px);
    height: auto;
    max-height: 80px;
    overflow: hidden;
}
#login-form input {
    padding: 5px;
    font-size: 1rem;
    border: 1px solid #bbb;
    border-radius: 4px;
    width: 35%;
}
#login-form button {
    padding: 5px 16px;
    background: #35c351;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}
#login-form button:hover {
    background: #29853b;
}

#controls {
    position: fixed;
    bottom: 0px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255,255,255,0.98);
    padding: 10px 24px;
    border-top-left-radius: 25px;
    border-top-right-radius: 25px;
    box-shadow: 0px 8px 14px -10px;
    display: flex;
    gap: 20px;
    z-index: 10;
}
#controls button {
    background: #fff;
    color: #1976d2;
    border: 1.5px solid #1976d2;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border 0.2s;
}
#controls button:hover {
    background: #1976d2;
    color: #fff;
    border-color: #1976d2;
}


#login-form input {
    padding: 5px;
    font-size: 1rem;
    border: 1px solid #bbb;
    border-radius: 4px;
    width: 35%;
}
#login-form button {
    padding: 5px;
    background: #35c351;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}
#login-form button:hover {
    background: #29853b;
}
#controls {
    position: fixed;
    bottom: 0px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(35, 43, 58, 0.95);
    backdrop-filter: blur(10px);
    padding: 12px 20px;
    border-top-left-radius: 25px;
    border-top-right-radius: 25px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    display: flex;
    gap: 12px;
    align-items: center;
    z-index: 1000;
    max-width: calc(100vw - 2rem);
    box-sizing: border-box;
}
#controls button {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(5px);
}

#controls button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

#controls button.on {
    background: rgba(76, 175, 80, 0.8);
    border-color: #4caf50;
    color: #fff;
}

#controls button.off {
    background: rgba(244, 67, 54, 0.8);
    border-color: #f44336;
    color: #fff;
}

@media (max-width: 480px) {
    #controls {
        bottom: 0px;
        padding: 8px 12px;
        gap: 8px;
    }
    #controls button {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
}